/* * rejection.c * * Crystal rejection for scaling * * Copyright © 2012-2018 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: * 2010-2018 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 "crystal.h" #include "reflist.h" #include "rejection.h" #include "cell-utils.h" #include "post-refinement.h" static double mean_intensity(RefList *list) { Reflection *refl; RefListIterator *iter; double total = 0.0; int n = 0; for ( refl = first_refl(list, &iter); refl != NULL; refl = next_refl(refl, iter) ) { total += get_intensity(refl); n++; } return total/n; } /* Reject really obvious outliers */ void early_rejection(Crystal **crystals, int n) { int i; double m = 0.0; double mean_m; FILE *fh = fopen("reject.dat", "w"); int n_flag = 0; for ( i=0; icontrib_crystals[0]), h, k, l); /* Mean of contributions */ refl_sum = 0.0; for ( j=0; jn_contrib; j++ ) { double Ii, G, B; if ( c->contrib_crystals[j] == exclude ) { continue; } G = crystal_get_osf(c->contrib_crystals[j]); B = crystal_get_Bfac(c->contrib_crystals[j]); Ii = get_intensity(c->contribs[j]); /* Total (multiplicative) correction factor */ Ii *= 1.0/G * exp(B*res*res) * get_lorentz(c->contribs[j]) / get_partiality(c->contribs[j]); refl_sum += Ii; nc++; } if ( nc < 2 ) continue; refl_mean = refl_sum / nc; /* Variance of contributions */ refl_sumsq = 0.0; for ( j=0; jn_contrib; j++ ) { double Ii, G, B; if ( c->contrib_crystals[j] == exclude ) { continue; } G = crystal_get_osf(c->contrib_crystals[j]); B = crystal_get_Bfac(c->contrib_crystals[j]); Ii = get_intensity(c->contribs[j]); /* Total (multiplicative) correction factor */ Ii *= 1.0/G * exp(B*res*res) * get_lorentz(c->contribs[j]) / get_partiality(c->contribs[j]); refl_sumsq += (Ii-refl_mean)*(Ii-refl_mean); /* (nc already summed above) */ } refl_var = refl_sumsq/(nc-1.0); refl_var /= (nc/2.0); all_sum_var += refl_var; n++; total_contribs += nc; double w = 1.0; wSum += w; wSum2 += w*w; double meanOld = mean; mean = meanOld + (w/wSum) * (refl_mean - meanOld); S += w * (refl_mean - meanOld) * (refl_mean - mean); } sig2E = all_sum_var / n; sig2Y = S / (wSum - 1.0); if ( pnref != NULL ) { *pnref = n; } return (sig2Y - 0.5*sig2E) / (sig2Y + 0.5*sig2E); } static void check_deltacchalf(Crystal **crystals, int n, RefList *full) { double cchalf; int i; int nref; double *vals; double mean, sd; cchalf = calculate_cchalf(full, full, NULL, &nref); STATUS("Overall CChalf = %f (%i reflections)\n", cchalf*100.0, nref); vals = malloc(n*sizeof(double)); if ( vals == NULL ) { ERROR("Not enough memory for deltaCChalf check\n"); return; } for ( i=0; i max_B ) { crystal_set_user_flag(crystals[i], PRFLAG_BIGB); } if ( crystal_get_user_flag(crystals[i]) == 0 ) n_acc++; } show_duds(crystals, n); if ( n_acc < 2 ) { ERROR("Not enough crystals left to proceed (%i). Sorry.\n", n_acc); exit(1); } }