/* * 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) ) { 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(ref1, ref2_transformed, icommon, &scale); STATUS("R1 = %5.4f %% (scale=%5.2e)\n", R1*100.0, scale); R2 = stat_r2(ref1, ref2_transformed, icommon, &scale_r2); STATUS("R2 = %5.4f %% (scale=%5.2e)\n", R2*100.0, scale_r2); Rdiff = stat_rdiff(ref1, ref2_transformed, icommon, &scale); STATUS("Rdiff = %5.4f %% (scale=%5.2e)\n", Rdiff*100.0, scale); pearson = stat_pearson(ref1, ref2_transformed, icommon); STATUS("Pearson r = %5.4f\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; }