From a2bb3a864af159a0bcd9db808e89a3743981b108 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 16 Nov 2010 12:08:43 +0100 Subject: Move 'characterisation' stuff to a new program, check_hkl --- src/check_hkl.c | 367 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 367 insertions(+) create mode 100644 src/check_hkl.c (limited to 'src/check_hkl.c') diff --git a/src/check_hkl.c b/src/check_hkl.c new file mode 100644 index 00000000..449dfa87 --- /dev/null +++ b/src/check_hkl.c @@ -0,0 +1,367 @@ +/* + * 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 *ref1, 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 den; + double rmin, rmax; + signed int h, k, l; + int i; + int ctot; + 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; + + possible[bin]++; + + } + } + } + free(counted); + + /* Characterise the first data set (only) */ + 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]++; + measurements[bin] += lookup_count(counts, h, k, l); + snr[bin] += (lookup_intensity(ref1, h, k, l) / + lookup_intensity(sigma, h, k, l)); + snr_total += (lookup_intensity(ref1, h, k, l) / + lookup_intensity(sigma, h, k, l)); + nmeas++; + nmeastot += lookup_count(counts, h, k, l); + + } + 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); + } + + 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; +} -- cgit v1.2.3