/* * get_hkl.c * * Small program to write out a list of h,k,l,I values given a structure * * (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" static void show_help(const char *s) { printf("Syntax: %s [options]\n\n", s); printf( "Write idealised intensity lists.\n" "\n" " -h, --help Display this help message.\n" "\n" " -t, --template= Only include reflections mentioned in file.\n" " --poisson Simulate Poisson samples.\n" " --twin Generate twinned data.\n" " -o --output= Output filename (default: stdout).\n"); } static double *template_reflections(double *ref, const char *filename, unsigned int *counts) { char *rval; double *out; FILE *fh; fh = fopen(filename, "r"); if ( fh == NULL ) { return NULL; } out = new_list_intensity(); do { char line[1024]; double val; int r; signed int h, k, l; rval = fgets(line, 1023, fh); r = sscanf(line, "%i %i %i", &h, &k, &l); if ( r != 3 ) continue; val = lookup_intensity(ref, h, k, l); set_intensity(out, h, k, l, val); if ( counts != NULL ) { set_count(counts, h, k, l, 1); } } while ( rval != NULL ); fclose(fh); return out; } /* Apply Poisson noise to all reflections */ static void noisify_reflections(double *ref) { signed int h, k, l; for ( h=-INDMAX; hreflections); counts = new_list_count(); if ( template != NULL ) { ref = template_reflections(ideal_ref, template, counts); if ( ref == NULL ) { ERROR("Couldn't read template file!\n"); return 1; } } else { ref = ideal_ref; for ( h=-INDMAX; h<=INDMAX; h++ ) { for ( k=-INDMAX; k<=INDMAX; k++ ) { for ( l=-INDMAX; l<=INDMAX; l++ ) { set_count(counts, h, k, l, 1); } } } } if ( config_noisify ) noisify_reflections(ref); if ( config_twin ) { STATUS("Twinning...\n"); for ( h=-INDMAX; h<=INDMAX; h++ ) { for ( k=-INDMAX; k<=INDMAX; k++ ) { for ( l=-INDMAX; l<=INDMAX; l++ ) { if ( lookup_count(counts, h, k, l) != 0 ) { double a, b; a = lookup_intensity(ideal_ref, h, k, l); b = lookup_intensity(ideal_ref, k, h, -l); set_intensity(ref, h, k, l, (a+b)/2.0); STATUS("%i %i %i\n", h, k, l); } } } } } write_reflections(output, NULL, ref, 1, mol->cell); return 0; }