From 6d9bb7021a02efb881314bf8cbcb551e8eac4aaa Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 18 May 2015 15:38:41 +0200 Subject: partialator: Add cross-validation pobs/pcalc graph --- src/partialator.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) (limited to 'src/partialator.c') diff --git a/src/partialator.c b/src/partialator.c index e17331e0..9815695f 100644 --- a/src/partialator.c +++ b/src/partialator.c @@ -50,6 +50,8 @@ #include #include #include +#include +#include #include "version.h" #include "post-refinement.h" @@ -322,6 +324,90 @@ static void show_duds(Crystal **crystals, int n_crystals) } +/* Flag a random 5% of reflections */ +static void select_free_reflections(RefList *list, gsl_rng *rng) +{ + Reflection *refl; + RefListIterator *iter; + + for ( refl = first_refl(list, &iter); + refl != NULL; + refl = next_refl(refl, iter) ) + { + set_flag(refl, random_flat(rng, 1.0) > 0.95); + } +} + + +static void write_to_pgraph(FILE *fh, RefList *list, RefList *full, Crystal *cr, + int fr) +{ + Reflection *refl; + RefListIterator *iter; + double G = crystal_get_osf(cr); + double B = crystal_get_Bfac(cr); + UnitCell *cell = crystal_get_cell(cr); + + for ( refl = first_refl(list, &iter); + refl != NULL; + refl = next_refl(refl, iter) ) + { + signed int h, k, l; + double pobs, pcalc; + double res, corr, Ipart; + Reflection *match; + + if ( !get_flag(refl) ) continue; /* Not free-flagged */ + + get_indices(refl, &h, &k, &l); + res = resolution(cell, h, k, l); + if ( 2.0*res > crystal_get_resolution_limit(cr) ) continue; + + match = find_refl(full, h, k, l); + if ( match == NULL ) continue; + + /* Calculated partiality */ + pcalc = get_partiality(refl); + + /* Observed partiality */ + corr = exp(-G) * exp(B*res*res) * get_lorentz(refl); + Ipart = get_intensity(refl) * corr; + pobs = Ipart / get_intensity(match); + + fprintf(fh, "%5i %4i %4i %4i %8.4f %8.3f %8.3f\n", + fr, h, k, l, 2*res/1e9, pcalc, pobs); + + } +} + + +static void write_pgraph(RefList *full, Crystal **crystals, int n_crystals, + int iter) +{ + FILE *fh; + char tmp[256]; + int i; + + snprintf(tmp, 256, "pgraph-iter%i.dat", iter); + + fh = fopen(tmp, "w"); + if ( fh == NULL ) { + ERROR("Failed to open '%s'\n", tmp); + return; + } + + fprintf(fh, " fr h k l 1/d(nm) pcalc pobs\n"); + + for ( i=0; i