From da7099fb56730ab89ce9642c2caf090e7b902c72 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 13 Feb 2014 11:58:25 +0100 Subject: pattern_sim: Add --template --- src/pattern_sim.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 13 deletions(-) diff --git a/src/pattern_sim.c b/src/pattern_sim.c index f23be972..a747cd72 100644 --- a/src/pattern_sim.c +++ b/src/pattern_sim.c @@ -54,6 +54,7 @@ #include "reflist.h" #include "reflist-utils.h" #include "pattern_sim.h" +#include "stream.h" static void show_help(const char *s) @@ -90,6 +91,7 @@ static void show_help(const char *s) " -s, --sample-spectrum= Use N samples from spectrum. Default 3.\n" " -x, --spectrum= Type of spectrum to simulate.\n" " --background= Add N photons of Poisson background (default 0).\n" +" --template= Take orientations from stream .\n" ); } @@ -251,6 +253,8 @@ int main(int argc, char *argv[]) int nsamples = 3; gsl_rng *rng; int background = 0; + char *template_file = NULL; + Stream *st = NULL; /* Long options */ const struct option longopts[] = { @@ -276,6 +280,7 @@ int main(int argc, char *argv[]) {"min-size", 1, NULL, 3}, {"max-size", 1, NULL, 4}, {"background", 1, NULL, 5}, + {"template", 1, NULL, 6}, {0, 0, NULL, 0} }; @@ -375,6 +380,10 @@ int main(int argc, char *argv[]) } break; + case 6 : + template_file = strdup(optarg); + break; + case 0 : break; @@ -406,6 +415,19 @@ int main(int argc, char *argv[]) } } + if ( template_file != NULL ) { + if ( config_randomquat ) { + ERROR("You cannot use -r and --template together.\n"); + return 1; + } + st = open_stream_for_read(template_file); + if ( st == NULL ) { + ERROR("Failed to open stream.\n"); + return 1; + } + free(template_file); + } + if ( sym_str == NULL ) sym_str = strdup("1"); sym = get_pointgroup(sym_str); /* sym_str is used below */ @@ -583,23 +605,62 @@ int main(int argc, char *argv[]) } - /* Read quaternion from stdin */ - if ( config_randomquat ) { - orientation = random_quaternion(rng); + if ( st == NULL ) { + + if ( config_randomquat ) { + orientation = random_quaternion(rng); + } else { + orientation = read_quaternion(); + } + + STATUS("Orientation is %5.3f %5.3f %5.3f %5.3f\n", + orientation.w, orientation.x, + orientation.y, orientation.z); + + if ( !quaternion_valid(orientation) ) { + ERROR("Orientation modulus is not zero!\n"); + return 1; + } + + cell = cell_rotate(input_cell, orientation); + } else { - orientation = read_quaternion(); - } - STATUS("Orientation is %5.3f %5.3f %5.3f %5.3f\n", - orientation.w, orientation.x, - orientation.y, orientation.z); + struct image image; + int i; + Crystal *cr; - if ( !quaternion_valid(orientation) ) { - ERROR("Orientation modulus is not zero!\n"); - return 1; - } + image.det = NULL; + + /* Get data from next chunk */ + if ( read_chunk(st, &image) ) break; - cell = cell_rotate(input_cell, orientation); + free(image.filename); + image_feature_list_free(image.features); + + if ( image.n_crystals == 0 ) continue; + + cr = image.crystals[0]; + cell = crystal_get_cell(cr); + + if ( image.n_crystals > 1 ) { + ERROR("Using the first crystal only.\n"); + } + + for ( i=1; i