diff options
author | Thomas White <taw@physics.org> | 2013-02-12 02:16:44 -0800 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2013-02-12 02:16:44 -0800 |
commit | a9d289c5c9c5c3491b8ecd6580c381a423094734 (patch) | |
tree | 8b438263b69d4b28bcc84eb5f2f8c547ef2055cd /libcrystfel/src | |
parent | 9b7274a5b5d8a241277d61e980a8ddf922ebf293 (diff) |
Improve handling of indexing methods
Diffstat (limited to 'libcrystfel/src')
-rw-r--r-- | libcrystfel/src/beam-parameters.h | 8 | ||||
-rw-r--r-- | libcrystfel/src/dirax.c | 12 | ||||
-rw-r--r-- | libcrystfel/src/dirax.h | 2 | ||||
-rw-r--r-- | libcrystfel/src/image.h | 3 | ||||
-rw-r--r-- | libcrystfel/src/index.c | 127 | ||||
-rw-r--r-- | libcrystfel/src/index.h | 12 | ||||
-rw-r--r-- | libcrystfel/src/mosflm.c | 15 | ||||
-rw-r--r-- | libcrystfel/src/mosflm.h | 2 | ||||
-rw-r--r-- | libcrystfel/src/reax.c | 10 | ||||
-rw-r--r-- | libcrystfel/src/reax.h | 13 | ||||
-rw-r--r-- | libcrystfel/src/stream.c | 1 |
11 files changed, 168 insertions, 37 deletions
diff --git a/libcrystfel/src/beam-parameters.h b/libcrystfel/src/beam-parameters.h index 8212811b..de777deb 100644 --- a/libcrystfel/src/beam-parameters.h +++ b/libcrystfel/src/beam-parameters.h @@ -3,11 +3,11 @@ * * Beam parameters * - * Copyright © 2012 Deutsches Elektronen-Synchrotron DESY, - * a research centre of the Helmholtz Association. + * Copyright © 2013-2013 Deutsches Elektronen-Synchrotron DESY, + * a research centre of the Helmholtz Association. * * Authors: - * 2010,2012 Thomas White <taw@physics.org> + * 2010,2012-2013 Thomas White <taw@physics.org> * 2012 Chunhong Yoon * * This file is part of CrystFEL. @@ -34,6 +34,8 @@ #include <config.h> #endif +struct beam_params; + #include "hdf5-file.h" struct beam_params diff --git a/libcrystfel/src/dirax.c b/libcrystfel/src/dirax.c index fc185fd4..e6ff36b1 100644 --- a/libcrystfel/src/dirax.c +++ b/libcrystfel/src/dirax.c @@ -626,27 +626,31 @@ int run_dirax(struct image *image, IndexingPrivate *ipriv) } -IndexingPrivate *dirax_prepare(IndexingMethod indm, UnitCell *cell, +IndexingPrivate *dirax_prepare(IndexingMethod *indm, UnitCell *cell, const char *filename, struct detector *det, struct beam_params *beam, float *ltl) { struct dirax_private *dp; int need_cell = 0; - if ( indm & INDEXING_CHECK_CELL_COMBINATIONS ) need_cell = 1; - if ( indm & INDEXING_CHECK_CELL_AXES ) need_cell = 1; + if ( *indm & INDEXING_CHECK_CELL_COMBINATIONS ) need_cell = 1; + if ( *indm & INDEXING_CHECK_CELL_AXES ) need_cell = 1; if ( need_cell && (cell == NULL) ) { ERROR("DirAx needs a unit cell for this set of flags.\n"); return NULL; } + /* Flags that DirAx knows about */ + *indm &= INDEXING_METHOD_MASK | INDEXING_CHECK_CELL_COMBINATIONS + | INDEXING_CHECK_CELL_AXES | INDEXING_CHECK_PEAKS; + dp = malloc(sizeof(struct dirax_private)); if ( dp == NULL ) return NULL; dp->ltl = ltl; dp->template = cell; - dp->indm = indm; + dp->indm = *indm; return (IndexingPrivate *)dp; } diff --git a/libcrystfel/src/dirax.h b/libcrystfel/src/dirax.h index 9e746a1b..6be8451a 100644 --- a/libcrystfel/src/dirax.h +++ b/libcrystfel/src/dirax.h @@ -37,7 +37,7 @@ extern int run_dirax(struct image *image, IndexingPrivate *ipriv); -extern IndexingPrivate *dirax_prepare(IndexingMethod indm, +extern IndexingPrivate *dirax_prepare(IndexingMethod *indm, UnitCell *cell, const char *filename, struct detector *det, struct beam_params *beam, float *ltl); diff --git a/libcrystfel/src/image.h b/libcrystfel/src/image.h index 91950e76..3739c01f 100644 --- a/libcrystfel/src/image.h +++ b/libcrystfel/src/image.h @@ -42,6 +42,7 @@ #include "detector.h" #include "reflist.h" #include "crystal.h" +#include "index.h" /* Structure describing a feature in an image */ @@ -79,6 +80,7 @@ typedef struct _imagefeaturelist ImageFeatureList; * * Crystal **crystals; * int n_crystals; + * IndexingMethod indexed_by; * * struct detector *det; * struct beam_params *beam; @@ -128,6 +130,7 @@ struct image { Crystal **crystals; int n_crystals; + IndexingMethod indexed_by; struct detector *det; struct beam_params *beam; /* The nominal beam parameters */ diff --git a/libcrystfel/src/index.c b/libcrystfel/src/index.c index 28f33388..f65265ae 100644 --- a/libcrystfel/src/index.c +++ b/libcrystfel/src/index.c @@ -65,20 +65,26 @@ IndexingPrivate **prepare_indexing(IndexingMethod *indm, UnitCell *cell, for ( n=0; n<nm; n++ ) { + int i; + IndexingMethod in; + + in = indm[n]; + switch ( indm[n] & INDEXING_METHOD_MASK ) { case INDEXING_DIRAX : - iprivs[n] = dirax_prepare(indm[n], cell, filename, det, + iprivs[n] = dirax_prepare(&indm[n], cell, filename, det, beam, ltl); break; case INDEXING_MOSFLM : - iprivs[n] = mosflm_prepare(indm[n], cell, filename, det, + iprivs[n] = mosflm_prepare(&indm[n], cell, filename, det, beam, ltl); break; case INDEXING_REAX : - iprivs[n] = reax_prepare(cell, filename, det, beam); + iprivs[n] = reax_prepare(&indm[n], cell, filename, det, + beam, ltl); break; default : @@ -90,6 +96,25 @@ IndexingPrivate **prepare_indexing(IndexingMethod *indm, UnitCell *cell, if ( iprivs[n] == NULL ) return NULL; + STATUS("Prepared indexing method %i: %s\n", + n, indexer_str(indm[n])); + + if ( in != indm[n] ) { + ERROR("Note: flags were altered to take into account " + "the limitations of the indexing method.\n"); + } + + for ( i=0; i<n; i++ ) { + if ( indm[i] == indm[n] ) { + ERROR("Duplicate indexing method.\n"); + ERROR("Have you specified some flags which " + "aren't accepted by one of your " + "chosen indexing methods?\n"); + return NULL; + } + } + + } iprivs[n] = NULL; @@ -160,7 +185,7 @@ void map_all_peaks(struct image *image) /* Return non-zero for "success" */ static int try_indexer(struct image *image, IndexingMethod indm, - IndexingPrivate *ipriv) + IndexingPrivate *ipriv) { switch ( indm & INDEXING_METHOD_MASK ) { @@ -206,14 +231,8 @@ void index_pattern(struct image *image, n++; } -} - -/* Set the default indexer flags. May need tweaking depending on the method */ -static IndexingMethod defaults(IndexingMethod a) -{ - return a | INDEXING_CHECK_CELL_COMBINATIONS | INDEXING_CHECK_PEAKS - | INDEXING_USE_LATTICE_TYPE; + image->indexed_by = indms[n]; } @@ -242,6 +261,14 @@ static IndexingMethod set_axes(IndexingMethod a) } +/* Set the indexer flags for "combination mode" ("--cell-reduction=reduce") */ +static IndexingMethod set_comb(IndexingMethod a) +{ + return (a & ~INDEXING_CHECK_CELL_AXES) + | INDEXING_CHECK_CELL_COMBINATIONS; +} + + /* Set the indexer flags for "use no lattice type information" */ static IndexingMethod set_nolattice(IndexingMethod a) { @@ -249,6 +276,71 @@ static IndexingMethod set_nolattice(IndexingMethod a) } +/* Set the indexer flags for "use lattice type information" */ +static IndexingMethod set_lattice(IndexingMethod a) +{ + return a | INDEXING_USE_LATTICE_TYPE; +} + + +char *indexer_str(IndexingMethod indm) +{ + char *str; + + str = malloc(32); + if ( str == NULL ) { + ERROR("Failed to allocate string.\n"); + return NULL; + } + str[0] = '\0'; + + switch ( indm & INDEXING_METHOD_MASK ) { + + case INDEXING_NONE : + strcpy(str, "none"); + return str; + + case INDEXING_DIRAX : + strcpy(str, "dirax"); + break; + + case INDEXING_MOSFLM : + strcpy(str, "mosflm"); + break; + + case INDEXING_REAX : + strcpy(str, "reax"); + break; + + default : + ERROR("Unrecognised indexing method %i\n", indm); + strcpy(str, "(unknown)"); + break; + + } + + if ( indm & INDEXING_CHECK_CELL_COMBINATIONS ) { + strcat(str, "-comb"); + } else if ( indm & INDEXING_CHECK_CELL_AXES ) { + strcat(str, "-axes"); + } else { + strcat(str, "-raw"); + } + + if ( !(indm & INDEXING_CHECK_PEAKS) ) { + strcat(str, "-bad"); + } + + if ( indm & INDEXING_USE_LATTICE_TYPE ) { + strcat(str, "-latt"); + } else { + strcat(str, "-nolatt"); + } + + return str; +} + + IndexingMethod *build_indexer_list(const char *str) { int n, i; @@ -263,14 +355,13 @@ IndexingMethod *build_indexer_list(const char *str) for ( i=0; i<n; i++ ) { if ( strcmp(methods[i], "dirax") == 0) { - list[++nmeth] = defaults(INDEXING_DIRAX); + list[++nmeth] = INDEXING_DEFAULTS_DIRAX; } else if ( strcmp(methods[i], "mosflm") == 0) { - list[++nmeth] = defaults(INDEXING_MOSFLM); + list[++nmeth] = INDEXING_DEFAULTS_MOSFLM; } else if ( strcmp(methods[i], "reax") == 0) { - /* ReAx doesn't need any cell check */ - list[++nmeth] = set_raw(defaults(INDEXING_REAX)); + list[++nmeth] = INDEXING_DEFAULTS_REAX; } else if ( strcmp(methods[i], "none") == 0) { list[++nmeth] = INDEXING_NONE; @@ -282,9 +373,15 @@ IndexingMethod *build_indexer_list(const char *str) } else if ( strcmp(methods[i], "bad") == 0) { list[nmeth] = set_bad(list[nmeth]); + } else if ( strcmp(methods[i], "comb") == 0) { + list[nmeth] = set_comb(list[nmeth]); /* Default */ + } else if ( strcmp(methods[i], "axes") == 0) { list[nmeth] = set_axes(list[nmeth]); + } else if ( strcmp(methods[i], "latt") == 0) { + list[nmeth] = set_lattice(list[nmeth]); + } else if ( strcmp(methods[i], "nolatt") == 0) { list[nmeth] = set_nolattice(list[nmeth]); diff --git a/libcrystfel/src/index.h b/libcrystfel/src/index.h index a54691b4..7d6656d5 100644 --- a/libcrystfel/src/index.h +++ b/libcrystfel/src/index.h @@ -38,11 +38,22 @@ #endif +#include "beam-parameters.h" #include "cell.h" #include "image.h" #include "detector.h" +#define INDEXING_DEFAULTS_DIRAX (INDEXING_DIRAX | INDEXING_CHECK_PEAKS \ + | INDEXING_CHECK_CELL_COMBINATIONS) + +#define INDEXING_DEFAULTS_MOSFLM (INDEXING_MOSFLM | INDEXING_CHECK_PEAKS \ + | INDEXING_CHECK_CELL_COMBINATIONS \ + | INDEXING_USE_LATTICE_TYPE) + +#define INDEXING_DEFAULTS_REAX (INDEXING_REAX | INDEXING_USE_LATTICE_TYPE \ + | INDEXING_CHECK_PEAKS) + /** * IndexingMethod: * @INDEXING_NONE: No indexing to be performed @@ -84,6 +95,7 @@ typedef enum { typedef void *IndexingPrivate; extern IndexingMethod *build_indexer_list(const char *str); +extern char *indexer_str(IndexingMethod indm); extern IndexingPrivate **prepare_indexing(IndexingMethod *indm, UnitCell *cell, const char *filename, diff --git a/libcrystfel/src/mosflm.c b/libcrystfel/src/mosflm.c index 98d4280d..22606fa4 100644 --- a/libcrystfel/src/mosflm.c +++ b/libcrystfel/src/mosflm.c @@ -798,28 +798,33 @@ int run_mosflm(struct image *image, IndexingPrivate *ipriv) } -IndexingPrivate *mosflm_prepare(IndexingMethod indm, UnitCell *cell, +IndexingPrivate *mosflm_prepare(IndexingMethod *indm, UnitCell *cell, const char *filename, struct detector *det, struct beam_params *beam, float *ltl) { struct mosflm_private *mp; int need_cell = 0; - if ( indm & INDEXING_CHECK_CELL_COMBINATIONS ) need_cell = 1; - if ( indm & INDEXING_CHECK_CELL_AXES ) need_cell = 1; - if ( indm & INDEXING_USE_LATTICE_TYPE ) need_cell = 1; + if ( *indm & INDEXING_CHECK_CELL_COMBINATIONS ) need_cell = 1; + if ( *indm & INDEXING_CHECK_CELL_AXES ) need_cell = 1; + if ( *indm & INDEXING_USE_LATTICE_TYPE ) need_cell = 1; if ( need_cell && (cell == NULL) ) { ERROR("MOSFLM needs a unit cell for this set of flags.\n"); return NULL; } + /* Flags that MOSFLM knows about */ + *indm &= INDEXING_METHOD_MASK | INDEXING_CHECK_CELL_COMBINATIONS + | INDEXING_CHECK_CELL_AXES | INDEXING_CHECK_PEAKS + | INDEXING_USE_LATTICE_TYPE; + mp = malloc(sizeof(struct mosflm_private)); if ( mp == NULL ) return NULL; mp->ltl = ltl; mp->template = cell; - mp->indm = indm; + mp->indm = *indm; return (IndexingPrivate *)mp; } diff --git a/libcrystfel/src/mosflm.h b/libcrystfel/src/mosflm.h index 4bb26afc..a87232b6 100644 --- a/libcrystfel/src/mosflm.h +++ b/libcrystfel/src/mosflm.h @@ -40,7 +40,7 @@ extern int run_mosflm(struct image *image, IndexingPrivate *ipriv); -extern IndexingPrivate *mosflm_prepare(IndexingMethod indm, UnitCell *cell, +extern IndexingPrivate *mosflm_prepare(IndexingMethod *indm, UnitCell *cell, const char *filename, struct detector *det, struct beam_params *beam, float *ltl); diff --git a/libcrystfel/src/reax.c b/libcrystfel/src/reax.c index f454503c..3460a4f2 100644 --- a/libcrystfel/src/reax.c +++ b/libcrystfel/src/reax.c @@ -1084,7 +1084,7 @@ void reax_index(IndexingPrivate *pp, struct image *image, UnitCell *cell) } -IndexingPrivate *reax_prepare(IndexingMethod indm, UnitCell *cell, +IndexingPrivate *reax_prepare(IndexingMethod *indm, UnitCell *cell, const char *filename, struct detector *det, struct beam_params *beam, float *ltl) { @@ -1100,6 +1100,12 @@ IndexingPrivate *reax_prepare(IndexingMethod indm, UnitCell *cell, p = calloc(1, sizeof(*p)); if ( p == NULL ) return NULL; + /* Flags that ReAx knows about */ + *indm &= INDEXING_METHOD_MASK | INDEXING_CHECK_PEAKS; + + /* Flags that ReAx requires */ + *indm |= INDEXING_USE_LATTICE_TYPE; + p->angular_inc = deg2rad(1.0); /* Reserve memory, over-estimating the number of directions */ @@ -1160,7 +1166,7 @@ IndexingPrivate *reax_prepare(IndexingMethod indm, UnitCell *cell, p->r_plan = fftw_plan_dft_2d(p->cw, p->ch, p->r_fft_in, p->r_fft_out, 1, FFTW_MEASURE); - p->indm = indm; + p->indm = *indm; return (IndexingPrivate *)p; } diff --git a/libcrystfel/src/reax.h b/libcrystfel/src/reax.h index af383e29..657a2cdf 100644 --- a/libcrystfel/src/reax.h +++ b/libcrystfel/src/reax.h @@ -33,15 +33,16 @@ #include <config.h> #endif +#include "index.h" #include "cell.h" #include "beam-parameters.h" #include "detector.h" #ifdef HAVE_FFTW -extern IndexingPrivate *reax_prepare(UnitCell *cell, const char *filename, - struct detector *det, - struct beam_params *beam); +extern IndexingPrivate *reax_prepare(IndexingMethod *indm, UnitCell *cell, + const char *filename, struct detector *det, + struct beam_params *beam, float *ltl); extern void reax_cleanup(IndexingPrivate *pp); @@ -49,9 +50,9 @@ extern int reax_index(struct image *image, IndexingPrivate *p); #else /* HAVE_FFTW */ -static IndexingPrivate *reax_prepare(UnitCell *cell, const char *filename, - struct detector *det, - struct beam_params *beam) +static IndexingPrivate *reax_prepare(IndexingMethod *indm, UnitCell *cell, + const char *filename, struct detector *det, + struct beam_params *beam, float *ltl) { return NULL; } diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c index 842c90b9..692a860a 100644 --- a/libcrystfel/src/stream.c +++ b/libcrystfel/src/stream.c @@ -199,6 +199,7 @@ void write_chunk(Stream *st, struct image *i, struct hdfile *hdfile, fprintf(st->fh, CHUNK_START_MARKER"\n"); fprintf(st->fh, "Image filename: %s\n", i->filename); + fprintf(st->fh, "indexed_by = %s\n", indexer_str(i->indexed_by)); if ( i->det != NULL ) { |