From 9049678c51e42eb5a5ef84cb94bc6f8a00e591f4 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 1 Feb 2013 17:59:35 +0100 Subject: WIP on new indexing pipeline logic --- libcrystfel/src/index.c | 196 +++++++++++++++++++----------------------------- libcrystfel/src/index.h | 57 +++++++------- 2 files changed, 107 insertions(+), 146 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/index.c b/libcrystfel/src/index.c index 7d912902..fd4384d7 100644 --- a/libcrystfel/src/index.c +++ b/libcrystfel/src/index.c @@ -3,12 +3,12 @@ * * Perform indexing (somehow) * - * Copyright © 2012 Deutsches Elektronen-Synchrotron DESY, - * a research centre of the Helmholtz Association. + * Copyright © 2012-2013 Deutsches Elektronen-Synchrotron DESY, + * a research centre of the Helmholtz Association. * Copyright © 2012 Lorenzo Galli * * Authors: - * 2010-2012 Thomas White + * 2010-2013 Thomas White * 2010-2011 Richard Kirian * 2012 Lorenzo Galli * @@ -52,16 +52,6 @@ #include "cell-utils.h" -/* Base class constructor for unspecialised indexing private data */ -IndexingPrivate *indexing_private(IndexingMethod indm) -{ - struct _indexingprivate *priv; - priv = calloc(1, sizeof(struct _indexingprivate)); - priv->indm = indm; - return priv; -} - - static const char *maybes(int n) { if ( n == 1 ) return ""; @@ -71,7 +61,7 @@ static const char *maybes(int n) IndexingPrivate **prepare_indexing(IndexingMethod *indm, UnitCell *cell, const char *filename, struct detector *det, - double nominal_photon_energy) + double nominal_photon_energy, float *ltl) { int n; int nm = 0; @@ -83,22 +73,23 @@ IndexingPrivate **prepare_indexing(IndexingMethod *indm, UnitCell *cell, for ( n=0; nindm ) { + switch ( priv[n]->indm & INDEXING_METHOD_MASK ) { case INDEXING_NONE : free(priv[n]); @@ -136,6 +127,11 @@ void cleanup_indexing(IndexingPrivate **priv) reax_cleanup(priv[n]); break; + default : + ERROR("Don't know how to clean up indexing method %i\n", + priv[n]->indm); + break; + } n++; @@ -166,9 +162,14 @@ void map_all_peaks(struct image *image) } -void index_pattern(struct image *image, UnitCell *cell, IndexingMethod *indm, - int cellr, int verbose, IndexingPrivate **ipriv, - int config_insane, const float *ltl) +static void try_indexer(struct image *image, IndexingMethod indm, + IndexingPrivate *ipriv) +{ +} + + +void index_pattern(struct image *image, + IndexingMethod *indms, IndexingPrivate **iprivs) { int i; int n = 0; @@ -176,102 +177,46 @@ void index_pattern(struct image *image, UnitCell *cell, IndexingMethod *indm, if ( indm == NULL ) return; map_all_peaks(image); - image->indexed_cell = NULL; + image->crystals = NULL; + image->n_crystals = 0; - while ( indm[n] != INDEXING_NONE ) { + while ( indms[n] != INDEXING_NONE ) { - image->ncells = 0; - - /* Index as appropriate */ - switch ( indm[n] ) { - - case INDEXING_NONE : - return; - - case INDEXING_DIRAX : - run_dirax(image); - break; - - case INDEXING_MOSFLM : - run_mosflm(image, cell); - break; - - case INDEXING_REAX : - reax_index(ipriv[n], image, cell); - break; - - } - if ( image->ncells == 0 ) { - n++; - continue; - } - - for ( i=0; incells; i++ ) { - - UnitCell *new_cell = NULL; - UnitCell *cand = image->candidate_cells[i]; - - if ( verbose ) { - STATUS("--------------------\n"); - STATUS("Candidate cell %i (before matching):\n", - i); - cell_print(image->candidate_cells[i]); - STATUS("--------------------\n"); - } - - /* Match or reduce the cell as appropriate */ - switch ( cellr ) { - - case CELLR_NONE : - new_cell = cell_new_from_cell(cand); - break; - - case CELLR_REDUCE : - new_cell = match_cell(cand, cell, verbose, - ltl, 1); - break; - - case CELLR_COMPARE : - new_cell = match_cell(cand, cell, verbose, - ltl, 0); - break; - - case CELLR_COMPARE_AB : - new_cell = match_cell_ab(cand, cell); - break; + if ( try_indexer(image, indms[n], iprivs[i]) ) break; + n++; - } + } +} - /* No cell? Move on to the next candidate */ - if ( new_cell == NULL ) continue; - /* Sanity check */ - image->indexed_cell = new_cell; - if ( !config_insane && !peak_sanity_check(image) ) { - cell_free(new_cell); - image->indexed_cell = NULL; - continue; - } +/* 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; +} - goto done; /* Success */ - } +/* Set the indexer flags for "raw mode" ("--cell-reduction=none") */ +static IndexingMethod set_raw(IndexingMethod a) +{ + /* Disable all unit cell checks */ + a &= ~(INDEXING_CHECK_CELL_COMBINATIONS | INDEXING_CHECK_CELL_AXES); + return a; +} - for ( i=0; incells; i++ ) { - cell_free(image->candidate_cells[i]); - image->candidate_cells[i] = NULL; - } - /* Move on to the next indexing method */ - n++; +/* Set the indexer flags for "bad mode" ("--insane) */ +static IndexingMethod set_bad(IndexingMethod a) +{ + /* Disable the peak check */ + return a & ~INDEXING_CHECK_PEAKS; +} - } -done: - for ( i=0; incells; i++ ) { - /* May free(NULL) if all algorithms were tried and no success */ - cell_free(image->candidate_cells[i]); - } +/* Set the indexer flags for "axes mode" ("--cell-reduction=compare") */ +static IndexingMethod set_axes(IndexingMethod a) +{ + return (a & ~INDEXING_CHECK_COMBINATIONS) | INDEXING_CHECK_CELL_AXES; } @@ -281,25 +226,38 @@ IndexingMethod *build_indexer_list(const char *str, int *need_cell) char **methods; IndexingMethod *list; int tmp; + int nmeth = 0; if ( need_cell == NULL ) need_cell = &tmp; *need_cell = 0; - n = assplode(str, ",", &methods, ASSPLODE_NONE); + n = assplode(str, ",-", &methods, ASSPLODE_NONE); list = malloc((n+1)*sizeof(IndexingMethod)); + *nmeth = -1; /* So that the first method is #0 */ for ( i=0; i + * 2010-2013 Thomas White * 2010 Richard Kirian * 2012 Lorenzo Galli * @@ -53,20 +53,25 @@ * An enumeration of all the available indexing methods. **/ typedef enum { - INDEXING_NONE, - INDEXING_DIRAX, - INDEXING_MOSFLM, - INDEXING_REAX, -} IndexingMethod; + INDEXING_NONE = 0, + + /* The core indexing methods themselves */ + INDEXING_DIRAX = 1, + INDEXING_MOSFLM = 2, + INDEXING_REAX = 3, + + /* Bits at the top of the IndexingMethod are flags which modify the + * behaviour of the indexer, at the moment just by adding checks. */ + INDEXING_CHECK_CELL_COMBINATIONS = 256, + INDEXING_CHECK_CELL_AXES = 512, + INDEXING_CHECK_PEAKS = 1024, + +} IndexingMethod; -/* Cell reduction methods */ -enum { - CELLR_NONE, - CELLR_REDUCE, - CELLR_COMPARE, - CELLR_COMPARE_AB, -}; +/* This defines the bits in "IndexingMethod" which are used to represent the + * core of the indexing method */ +#define INDEXING_METHOD_MASK (0xff) /** @@ -75,24 +80,22 @@ enum { * This is an opaque data structure containing information needed by the * indexing method. **/ -typedef struct _indexingprivate IndexingPrivate; +typedef void *IndexingPrivate; -extern IndexingPrivate *indexing_private(IndexingMethod indm); +extern IndexingMethod *build_indexer_list(const char *str, int *need_cell); extern IndexingPrivate **prepare_indexing(IndexingMethod *indm, UnitCell *cell, - const char *filename, - struct detector *det, - double nominal_photon_energy); - -extern void map_all_peaks(struct image *image); + const char *filename, + struct detector *det, + double nominal_photon_energy, + float *ltl); -extern void index_pattern(struct image *image, UnitCell *cell, - IndexingMethod *indm, int cellr, int verbose, - IndexingPrivate **priv, int config_insane, - const float *ltl); +extern void index_pattern(struct image *image, + IndexingMethod *indms, IndexingPrivate **iprivs); extern void cleanup_indexing(IndexingPrivate **priv); -extern IndexingMethod *build_indexer_list(const char *str, int *need_cell); +/* For indexing methods to call */ +extern IndexingPrivate *indexing_private(IndexingMethod indm); #endif /* INDEX_H */ -- cgit v1.2.3