/* * check_hkl.c * * Characterise 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 plot of resolution shells */ #define NBINS (10) static void show_help(const char *s) { printf("Syntax: %s [options] \n\n", s); printf( "Characterise an intensity list.\n" "\n" " -h, --help Display this help message.\n" " -y, --symmetry= The symmetry of both the input files.\n" " -p, --pdb= PDB file to use (default: molecule.pdb).\n" " --rmin= Fix lower resolution limit for --shells (m^-1).\n" " --rmax= Fix upper resolution limit for --shells (m^-1).\n" "\n"); } static void plot_shells(const double *ref, ReflItemList *items, UnitCell *cell, const char *sym, unsigned int *counts, const double *sigma, double rmin_fix, double rmax_fix) { double num[NBINS]; int cts[NBINS]; int possible[NBINS]; unsigned int *counted; unsigned int measurements[NBINS]; unsigned int measured[NBINS]; double total_vol, vol_per_shell; double rmins[NBINS]; double rmaxs[NBINS]; double snr[NBINS]; double mean[NBINS]; double var[NBINS]; double rmin, rmax; signed int h, k, l; int i; FILE *fh; double snr_total = 0; int nmeas = 0; int nmeastot = 0; int nout = 0; if ( cell == NULL ) { ERROR("Need the unit cell to plot resolution shells.\n"); return; } fh = fopen("shells.dat", "w"); if ( fh == NULL ) { ERROR("Couldn't open 'shells.dat'\n"); return; } for ( i=0; ih; k = it->k; l = it->l; d = resolution(cell, h, k, l) * 2.0; if ( d > rmax ) rmax = d; if ( d < rmin ) rmin = d; } STATUS("1/d goes from %f to %f nm^-1\n", rmin/1e9, rmax/1e9); /* Widen the range just a little bit */ rmin -= 0.001e9; rmax += 0.001e9; /* Fixed resolution shells if needed */ if ( rmin_fix > 0.0 ) rmin = rmin_fix; if ( rmax_fix > 0.0 ) rmax = rmax_fix; total_vol = pow(rmax, 3.0) - pow(rmin, 3.0); vol_per_shell = total_vol / NBINS; rmins[0] = rmin; for ( i=1; irmins[i]) && (d<=rmaxs[i]) ) { bin = i; break; } } if ( bin == -1 ) continue; get_asymm(h, k, l, &hs, &ks, &ls, sym); if ( lookup_count(counted, hs, ks, ls) ) continue; set_count(counted, hs, ks, ls, 1); possible[bin]++; } } } free(counted); /* Calculate means */ for ( i=0; ih; k = it->k; l = it->l; d = resolution(cell, h, k, l) * 2.0; bin = -1; for ( j=0; jrmins[j]) && (d<=rmaxs[j]) ) { bin = j; break; } } if ( bin == -1 ) { nout++; continue; } measured[bin]++; mean[bin] += lookup_intensity(ref, h, k, l); } for ( i=0; ih; k = it->k; l = it->l; d = resolution(cell, h, k, l) * 2.0; val = lookup_intensity(ref, h, k, l); esd = lookup_sigma(sigma, h, k, l); bin = -1; for ( j=0; jrmins[j]) && (d<=rmaxs[j]) ) { bin = j; break; } } if ( bin == -1 ) { nout++; continue; } if ( !isfinite(val/esd) ) continue; /* measured[bin] was done earlier */ measurements[bin] += lookup_count(counts, h, k, l); snr[bin] += val / esd; snr_total += val / esd; nmeas++; nmeastot += lookup_count(counts, h, k, l); var[bin] += pow(val-mean[bin], 2.0); } STATUS("overall = %f\n", snr_total/(double)nmeas); STATUS("%i measurements in total.\n", nmeastot); STATUS("%i reflections in total.\n", nmeas); if ( nout ) { STATUS("Warning; %i reflections outside resolution range.\n", nout); } fprintf(fh, "1/d centre # refs Possible Compl " "Meas Red SNR Std dev Mean\n"); for ( i=0; ih; k = it->k; l = it->l; val = lookup_intensity(ref, h, k, l); sig = lookup_sigma(esd, h, k, l); if ( val < 3.0 * sig ) { rej++; ig = 1; } d = 0.5/resolution(cell, h, k, l); if ( d > 55.0e-10 ) ig = 1; //if ( d < 15.0e-10 ) ig = 1; //if ( ig ) continue; add_item(good_items, h, k, l); } plot_shells(ref, items, cell, sym, cts, esd, rmin_fix, rmax_fix); return 0; }