/* * compare_hkl.c * * Compare reflection lists * * (c) 2006-2010 Thomas White * * Part of CrystFEL - crystallography with a FEL * */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include "utils.h" #include "sfac.h" #include "reflections.h" #include "statistics.h" #include "symmetry.h" /* Number of bins for Luzzati plot */ #define NBINS (10) static void show_help(const char *s) { printf("Syntax: %s [options] \n\n", s); printf( "Compare intensity lists.\n" "\n" " -h, --help Display this help message.\n" " -o, --output= Specify output filename for correction factor.\n" " -y, --symmetry= The symmetry of both the input files.\n" " -p, --pdb= PDB file to use (default: molecule.pdb).\n" "\n"); } static void plot_luzzati(const double *ref1, const double *ref2, ReflItemList *items, double scale, UnitCell *cell) { double num[NBINS]; double den[NBINS]; double rmin, rmax, rstep; int i; FILE *fh; if ( cell == NULL ) { ERROR("Need the unit cell to plot the Luzzati plot.\n"); return; } fh = fopen("luzzati.dat", "w"); if ( fh == NULL ) { ERROR("Couldn't open 'luzzati.dat'\n"); return; } for ( i=0; ih; k = it->k; l = it->l; res = 2.0*resolution(cell, h, k, l); if ( res > rmax ) rmax = res; if ( res < rmin ) rmin = res; } rstep = (rmax-rmin) / NBINS; for ( i=0; ih; k = it->k; l = it->l; res = 2.0*resolution(cell, h, k, l); bin = (res-rmin)/rstep; i1 = lookup_intensity(ref1, h, k, l); i2 = scale * lookup_intensity(ref2, h, k, l); num[bin] += pow(i1 - i2, 2.0); den[bin] += pow(i1, 2.0); } for ( i=0; ih; k = it->k; l = it->l; if ( !find_unique_equiv(i2, h, k, l, sym, &he, &ke, &le) ) { //STATUS("%i %i %i not matched (%f nm).\n", h, k, l, // 1.0/(2.0*resolution(cell, h, k, l)/1e9)); continue; } val1 = lookup_intensity(ref1, h, k, l); val2 = lookup_intensity(ref2, he, ke, le); set_intensity(ref2_transformed, h, k, l, val2); set_intensity(out, h, k, l, val1/val2); add_item(icommon, h, k, l); } ncom = num_items(icommon); STATUS("%i,%i reflections: %i in common\n", num_items(i1), num_items(i2), ncom); R1 = stat_r1_ignore(ref1, ref2_transformed, icommon, &scale); STATUS("R1(F) = %5.4f %% (scale=%5.2e) (ignoring negative intensities)\n", R1*100.0, scale); R1 = stat_r1_zero(ref1, ref2_transformed, icommon, &scale); STATUS("R1(F) = %5.4f %% (scale=%5.2e) (zeroing negative intensities)\n", R1*100.0, scale); R2 = stat_r2(ref1, ref2_transformed, icommon, &scale_r2); STATUS("R2(I) = %5.4f %% (scale=%5.2e)\n", R2*100.0, scale_r2); R1i = stat_r1_i(ref1, ref2_transformed, icommon, &scale); STATUS("R1(I) = %5.4f %% (scale=%5.2e)\n", R1i*100.0, scale); Rdiff = stat_rdiff_ignore(ref1, ref2_transformed, icommon, &scale); STATUS("Rdiff(F) = %5.4f %% (scale=%5.2e) (ignoring negative intensities)\n", Rdiff*100.0, scale); Rdiff = stat_rdiff_zero(ref1, ref2_transformed, icommon, &scale); STATUS("Rdiff(F) = %5.4f %% (scale=%5.2e) (zeroing negative intensities)\n", Rdiff*100.0, scale); pearson = stat_pearson_i(ref1, ref2_transformed, icommon); STATUS("Pearson r(I) = %5.4f\n", pearson); pearson = stat_pearson_f_ignore(ref1, ref2_transformed, icommon); STATUS("Pearson r(F) = %5.4f (ignoring negative intensities)\n", pearson); pearson = stat_pearson_f_zero(ref1, ref2_transformed, icommon); STATUS("Pearson r(F) = %5.4f (zeroing negative intensities)\n", pearson); if ( config_luzzati ) { plot_luzzati(ref1, ref2_transformed, icommon, scale_r2, cell); } if ( outfile != NULL ) { write_reflections(outfile, icommon, out, NULL, NULL, cell); } return 0; }