From e50602787cdbf488cf829ca293c9b9f359aa36f8 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 30 Mar 2014 20:53:57 +0200 Subject: check_hkl: Add L-test --- src/ambigator.c | 5 -- src/check_hkl.c | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ambigator.c b/src/ambigator.c index 75744199..d49607a9 100644 --- a/src/ambigator.c +++ b/src/ambigator.c @@ -79,11 +79,6 @@ static void show_help(const char *s) ); } -#define SERIAL(h, k, l) ((((h)+512)<<20) + (((k)+512)<<10) + ((l)+512)) -#define GET_H(serial) ((((serial) & 0x3ff00000)>>20)-512) -#define GET_K(serial) ((((serial) & 0x000ffc00)>>10)-512) -#define GET_L(serial) (((serial) & 0x000003ff)-512) - struct flist { int n; diff --git a/src/check_hkl.c b/src/check_hkl.c index db41fac5..9c78a42a 100644 --- a/src/check_hkl.c +++ b/src/check_hkl.c @@ -60,11 +60,133 @@ static void show_help(const char *s) " --sigma-cutoff= Discard reflections with I/sigma(I) < n.\n" " --nshells= Use resolution shells or bins.\n" " --wilson Calculate a Wilson plot\n" +" --ltest Perform an L-test (for twinning)\n" " --shell-file= Write results table to .\n" +" --ignore-negs Ignore reflections with negative intensities.\n" +" --zero-negs Set negative intensities to zero.\n" "\n"); } +static int add_ltest(RefList *list, double i1, int *bins, int nbins, + double step, const SymOpList *sym, double *lt, double *l2t, + signed int h1, signed int k1, signed int l1, + signed int h2, signed int k2, signed int l2) +{ + Reflection *refl; + double i2, L; + int bin; + + if ( SERIAL(h1, k1, l1) > SERIAL(h2, k2, l2) ) return 0; + + refl = find_refl(list, h2, k2, l2); + if ( refl == NULL ) { + signed int h, k, l; + if ( !find_equiv_in_list(list, h2, k2, l2, sym, &h, &k, &l) ) { + return 0; + } + refl = find_refl(list, h, k, l); + } + + i2 = get_intensity(refl); + L = (i1-i2) / (i1+i2); + + bin = fabs(L)/step; + if ( (bin < 0) || (isnan(L)) ) { + bin = 0; + } else if ( bin >= nbins ) { + bin = nbins-1; + } + bins[bin]++; + + *lt += fabs(L); + *l2t += pow(L, 2.0); + + return 1; +} + + +static void l_test(RefList *list, UnitCell *cell, const SymOpList *sym, + double rmin_fix, double rmax_fix, int nbins, + const char *filename) +{ + Reflection *refl; + RefListIterator *iter; + int *bins; + FILE *fh; + int npairs, i; + double tot; + double lt = 0.0; + double l2t = 0.0; + const double step = 1.0/nbins; + int hd, kd, ld; + const char cen = cell_get_centering(cell); + + bins = malloc(nbins*sizeof(int)); + if ( bins == NULL ) return; + + for ( i=0; i = %.3f (ideal untwinned %.3f, twinned %.3f)\n", + lt/npairs, 1.0/2.0, 3.0/8.0); + STATUS(" = %.3f (ideal untwinned %.3f, twinned %.3f)\n", + l2t/npairs, 1.0/3.0, 1.0/5.0); + + fh = fopen(filename, "w"); + if ( fh == NULL ) return; + tot = 0.0; + fprintf(fh, " |L| N(|L|) untwinned twinned\n"); + fprintf(fh, "%.3f %7.3f %9.3f %7.3f\n", 0.0, tot, 0.0, 0.0); + for ( i=0; i 0) ) { + STATUS("Discarded %i reflections because they had negative " + "intensities.\n", nneg); + } + + if ( zeronegs && (nneg > 0) ) { + STATUS("Set %i negative intensities to zerp\n", nneg); + } + if ( wilson ) { if ( !have_nshells ) nshells = 50; wilson_plot(list, cell, sym, rmin_fix, rmax_fix, nshells, shell_file); + } else if ( ltest ) { + if ( !have_nshells ) nshells = 50; + if ( !ignorenegs && !zeronegs ) { + ERROR("For the L-test you must specify either" + "--ignore-negs or --zero-negs.\n"); + return 1; + } + l_test(list, cell, sym, rmin_fix, rmax_fix, nshells, + shell_file); } else { plot_shells(list, cell, sym, rmin_fix, rmax_fix, nshells, shell_file); -- cgit v1.2.3