/* * compare_hkl.c * * Compare reflection lists * * Copyright © 2012 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: * 2010-2012 Thomas White * * This file is part of CrystFEL. * * CrystFEL is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * CrystFEL is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with CrystFEL. If not, see . * */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include #include #include "utils.h" #include "statistics.h" #include "symmetry.h" #include "reflist-utils.h" /* Number of bins for plot of resolution shells */ #define NBINS (10) enum r_shell { R_SHELL_NONE, R_SHELL_R1I, R_SHELL_R1F, R_SHELL_RSPLIT, }; static enum r_shell get_r_shell(const char *s) { if ( strcasecmp(s, "r1i") == 0 ) return R_SHELL_R1I; if ( strcasecmp(s, "r1f") == 0 ) return R_SHELL_R1F; if ( strcasecmp(s, "rsplit") == 0 ) return R_SHELL_RSPLIT; ERROR("Unknown R-factor '%s' - try '--shells=rsplit', or --help for" " more possibilities.\n", s); exit(1); } 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, --ratio= Specify output filename for ratios.\n" " -y, --symmetry= The symmetry of both the input files.\n" " -p, --pdb= PDB file to use.\n" " --shells= Plot this figure of merit in resolution shells.\n" " Choose from: 'Rsplit', 'R1f' and 'R1i'.\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(RefList *list1, RefList *list2, double scale, UnitCell *cell, double rmin_fix, double rmax_fix, enum r_shell config_shells) { double num[NBINS]; int cts[NBINS]; unsigned int measurements[NBINS]; unsigned int measured[NBINS]; double total_vol, vol_per_shell; double rmins[NBINS]; double rmaxs[NBINS]; double snr[NBINS]; double rmin, rmax; int i; Reflection *refl1; RefListIterator *iter; FILE *fh; double den; int ctot, nout; if ( cell == NULL ) { ERROR("Need the unit cell to plot resolution shells.\n"); return; } for ( i=0; i 0.0 ) rmin = rmin_fix; if ( rmax_fix > 0.0 ) rmax = rmax_fix; /* Calculate the resolution bins */ total_vol = pow(rmax, 3.0) - pow(rmin, 3.0); vol_per_shell = total_vol / NBINS; rmins[0] = rmin; for ( i=1; irmins[j]) && (d<=rmaxs[j]) ) { bin = j; break; } } /* Outside resolution range? */ if ( bin == -1 ) { nout++; continue; } refl2 = find_refl(list2, h, k, l); if ( refl2 == NULL ) continue; i1 = get_intensity(refl1); i2 = get_intensity(refl2); f1 = i1 > 0.0 ? sqrt(i1) : 0.0; f2 = i2 > 0.0 ? sqrt(i2) : 0.0; switch ( config_shells ) { case R_SHELL_RSPLIT : num[bin] += fabs(i1 - scale*i2); den += i1 + scale*i2; break; case R_SHELL_R1I : num[bin] += fabs(i1 - scale*i2); den += i1; break; case R_SHELL_R1F : num[bin] += fabs(f1 - scale*f2); den += f1; break; default : break; } ctot++; cts[bin]++; } if ( nout ) { STATUS("Warning; %i reflections outside resolution range.\n", nout); } fh = fopen("shells.dat", "w"); if ( fh == NULL ) { ERROR("Couldn't open 'shells.dat'\n"); return; } switch ( config_shells ) { case R_SHELL_RSPLIT : fprintf(fh, "1/d centre Rsplit / %%\n"); break; case R_SHELL_R1I : fprintf(fh, "1/d centre R1(I) / %%\n"); break; case R_SHELL_R1F : fprintf(fh, "1/d centre R1(F) ignoring -ves / %%\n"); break; default : fprintf(fh, "1/d centre 0.0\n"); break; } for ( i=0; i