diff options
author | Thomas White <taw@physics.org> | 2017-09-15 15:46:37 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2017-09-15 15:46:37 +0200 |
commit | 5ca956f67456831501cf413259790eec6d6c6c1f (patch) | |
tree | 7ae69fb902f78af2828d4bbd4609a934c0a09dc7 /libcrystfel/src/index.c | |
parent | f6de9f595620b5d4a1ecf3d8d6d4cde9b3c179e0 (diff) | |
parent | ca0d7a9e1982b55ae3891d8dbe7f05a79ed3e7f1 (diff) |
Merge branch 'tom/index'
Diffstat (limited to 'libcrystfel/src/index.c')
-rw-r--r-- | libcrystfel/src/index.c | 276 |
1 files changed, 151 insertions, 125 deletions
diff --git a/libcrystfel/src/index.c b/libcrystfel/src/index.c index 644ea31f..8c1f52e5 100644 --- a/libcrystfel/src/index.c +++ b/libcrystfel/src/index.c @@ -61,6 +61,7 @@ struct _indexingprivate { + IndexingFlags flags; UnitCell *target_cell; float tolerance[4]; @@ -72,6 +73,38 @@ struct _indexingprivate }; +static const char *onoff(int a) +{ + if ( a ) return "on"; + return "off"; +} + + +static void show_indexing_flags(IndexingFlags flags) +{ + char check[64]; + + assert( !((flags & INDEXING_CHECK_CELL_COMBINATIONS) + && (flags & INDEXING_CHECK_CELL_AXES)) ); + strcpy(check, onoff(flags & (INDEXING_CHECK_CELL_COMBINATIONS | INDEXING_CHECK_CELL_AXES))); + if ( flags & INDEXING_CHECK_CELL_AXES ) { + strcat(check, " (axis permutations only)"); + } + if ( flags & INDEXING_CHECK_CELL_COMBINATIONS ) { + strcat(check, " (axis combinations)"); + } + STATUS(" Check unit cell parameters: %s\n", check); + STATUS(" Check peak alignment: %s\n", + onoff(flags & INDEXING_CHECK_PEAKS)); + STATUS(" Refine indexing solutions: %s\n", + onoff(flags & INDEXING_REFINE)); + STATUS(" Multi-lattice indexing (\"delete and retry\"): %s\n", + onoff(flags & INDEXING_MULTI)); + STATUS(" Retry indexing: %s\n", + onoff(flags & INDEXING_RETRY)); +} + + static int debug_index(struct image *image) { Crystal *cr = crystal_new(); @@ -159,7 +192,7 @@ static void *prepare_method(IndexingMethod *m, UnitCell *cell, IndexingPrivate *setup_indexing(const char *method_list, UnitCell *cell, struct detector *det, float *ltl, - int no_refine, const char *options, + IndexingFlags flags, const char *options, struct taketwo_options *ttopts) { int i, n; @@ -178,10 +211,30 @@ IndexingPrivate *setup_indexing(const char *method_list, UnitCell *cell, for ( i=0; i<n; i++ ) { methods[i] = get_indm_from_string(method_strings[i]); if ( methods[i] == INDEXING_ERROR ) { + ERROR("----- Notice -----\n"); + ERROR("The way indexing options are used has changed in this CrystFEL version.\n"); + ERROR("To disable prediction refinement ('norefine'), use --no-refine.\n"); + ERROR("To check cell axes only ('axes'), use --no-cell-combinations.\n"); + ERROR("To disable all unit cell checks ('raw'), use --no-check-cell.\n"); + ERROR("To disable indexing retry ('noretry'), use --no-retry.\n"); + ERROR("Multi-lattice indexing ('multi') is now the default: " + "use --no-multi to disable it.\n"); + ERROR("------------------\n"); free(methods); return NULL; } - if ( no_refine ) methods[i] &= ~INDEXING_REFINE; + } + + if ( cell == NULL ) { + if ( (flags & INDEXING_CHECK_CELL_COMBINATIONS) + || (flags & INDEXING_CHECK_CELL_COMBINATIONS) ) + { + ERROR("WARNING: Forcing --no-cell-combinations " + "and --no-check-cell because you didn't " + "provide a unit cell.\n"); + flags &= ~INDEXING_CHECK_CELL_COMBINATIONS; + flags &= ~INDEXING_CHECK_CELL_AXES; + } } ipriv = malloc(sizeof(struct _indexingprivate)); @@ -212,6 +265,7 @@ IndexingPrivate *setup_indexing(const char *method_list, UnitCell *cell, ipriv->methods = methods; ipriv->n_methods = n; + ipriv->flags = flags; if ( cell != NULL ) { ipriv->target_cell = cell_new_from_cell(cell); @@ -222,6 +276,8 @@ IndexingPrivate *setup_indexing(const char *method_list, UnitCell *cell, ipriv->ttopts = ttopts; + show_indexing_flags(flags); + return ipriv; } @@ -308,6 +364,36 @@ void map_all_peaks(struct image *image) } +static int check_cell(IndexingFlags flags, Crystal *cr, UnitCell *target, + float *tolerance) +{ + if ( (flags & INDEXING_CHECK_CELL_COMBINATIONS) + || (flags & INDEXING_CHECK_CELL_AXES) ) + { + UnitCell *out; + int reduce; + + if ( flags & INDEXING_CHECK_CELL_COMBINATIONS ) + { + reduce = 1; + } else { + reduce = 0; + } + + out = match_cell(crystal_get_cell(cr), + target, 0, tolerance, reduce); + + if ( out == NULL ) { + return 1; + } + + cell_free(crystal_get_cell(cr)); + crystal_set_cell(cr, out); + } + return 0; +} + + /* Return non-zero for "success" */ static int try_indexer(struct image *image, IndexingMethod indm, IndexingPrivate *ipriv, void *mpriv) @@ -354,53 +440,86 @@ static int try_indexer(struct image *image, IndexingMethod indm, } + /* For all the crystals found this time ... */ for ( i=0; i<r; i++ ) { - Crystal *cr = image->crystals[image->n_crystals-i-1]; + int j; + int this_crystal = image->n_crystals - i - 1; + + /* ... starting at the end of the (complete) list ... */ + Crystal *cr = image->crystals[this_crystal]; + crystal_set_image(cr, image); crystal_set_user_flag(cr, 0); crystal_set_profile_radius(cr, 0.02e9); crystal_set_mosaicity(cr, 0.0); - /* Prediction refinement if requested */ - if ( indm & INDEXING_REFINE ) { + assert( !((ipriv->flags & INDEXING_CHECK_CELL_COMBINATIONS) + && (ipriv->flags & INDEXING_CHECK_CELL_AXES)) ); - UnitCell *out; + /* Pre-refinement unit cell check if requested */ + if ( check_cell(ipriv->flags, cr, ipriv->target_cell, + ipriv->tolerance) ) + { + crystal_set_user_flag(cr, 1); + n_bad++; + continue; + } + /* Prediction refinement if requested */ + if ( ipriv->flags & INDEXING_REFINE ) + { if ( refine_prediction(image, cr) ) { crystal_set_user_flag(cr, 1); n_bad++; continue; } + } - if ( (indm & INDEXING_CHECK_CELL_COMBINATIONS) - || (indm & INDEXING_CHECK_CELL_AXES) ) - { + /* After refinement unit cell check if requested */ + if ( check_cell(ipriv->flags, cr, ipriv->target_cell, + ipriv->tolerance) ) + { + crystal_set_user_flag(cr, 1); + n_bad++; + continue; + } - /* Check that the cell parameters are still - * within the tolerance */ - out = match_cell(crystal_get_cell(cr), - ipriv->target_cell, 0, - ipriv->tolerance, 0); + /* Peak alignment check if requested */ + if ( ipriv->flags & INDEXING_CHECK_PEAKS ) + { + if ( !peak_sanity_check(image, &cr, 1) ) { + crystal_set_user_flag(cr, 1); + n_bad++; + continue; + } + } - if ( out == NULL ) { - crystal_set_user_flag(cr, 1); - n_bad++; - } + /* Don't do similarity check if this crystal is bad */ + if ( crystal_get_user_flag(cr) ) continue; - cell_free(out); + /* Check if cell is too similar to existing ones */ + for ( j=0; j<this_crystal; j++ ) { - } + Crystal *that_cr = image->crystals[j]; + /* Don't do similarity check against bad crystals */ + if ( crystal_get_user_flag(that_cr) ) continue; + + if ( compare_cells(crystal_get_cell(cr), + crystal_get_cell(that_cr), + 0.1, deg2rad(5.0), NULL) ) + { + crystal_set_user_flag(cr, 1); + } } } - remove_flagged_crystals(image); - - if ( n_bad == r ) return 0; + n_bad = remove_flagged_crystals(image); + assert(r >= n_bad); - return r; + return r - n_bad; } @@ -490,14 +609,15 @@ static int delete_explained_peaks(struct image *image, Crystal *cr) * * Returns false for "try again", true for "no, stop now" */ -static int finished_retry(IndexingMethod indm, int r, struct image *image) +static int finished_retry(IndexingMethod indm, IndexingFlags flags, + int r, struct image *image) { if ( r == 0 ) { /* Indexing failed on the previous attempt. Maybe try again * after poking the peak list a bit */ - if ( indm & INDEXING_RETRY ) { + if ( flags & INDEXING_RETRY ) { /* Retry with fewer peaks */ return delete_weakest_peaks(image->features); } else { @@ -510,13 +630,10 @@ static int finished_retry(IndexingMethod indm, int r, struct image *image) /* Indexing succeeded on previous attempt. Maybe try again * after deleting the explained peaks */ - if ( indm & INDEXING_MULTI ) { - /* Remove "used" spots and try for - * another lattice */ + if ( flags & INDEXING_MULTI ) { + /* Remove "used" spots and try for another lattice */ Crystal *cr; cr = image->crystals[image->n_crystals-1]; - STATUS("WARNING: Multi-lattice indexing does not work" - " well in this version.\n"); return delete_explained_peaks(image, cr); } else { return 1; @@ -525,6 +642,7 @@ static int finished_retry(IndexingMethod indm, int r, struct image *image) } } + void index_pattern(struct image *image, IndexingPrivate *ipriv) { index_pattern_2(image, ipriv, NULL); @@ -559,7 +677,8 @@ void index_pattern_2(struct image *image, IndexingPrivate *ipriv, int *ping) ipriv, ipriv->engine_private[n]); success += r; ntry++; - done = finished_retry(ipriv->methods[n], r, image); + done = finished_retry(ipriv->methods[n], ipriv->flags, + r, image); if ( ntry > 5 ) done = 1; if ( ping != NULL ) (*ping)++; @@ -583,39 +702,6 @@ void index_pattern_2(struct image *image, IndexingPrivate *ipriv, int *ping) } -/* 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; -} - - -/* Set the indexer flags for "bad mode" ("--insane) */ -static IndexingMethod set_bad(IndexingMethod a) -{ - /* Disable the peak check */ - return a & ~INDEXING_CHECK_PEAKS; -} - - -/* Set the indexer flags for "axes mode" ("--cell-reduction=compare") */ -static IndexingMethod set_axes(IndexingMethod a) -{ - return (a & ~INDEXING_CHECK_CELL_COMBINATIONS) - | INDEXING_CHECK_CELL_AXES; -} - - -/* 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) { @@ -703,18 +789,6 @@ char *indexer_str(IndexingMethod indm) if ( (indm & INDEXING_METHOD_MASK) == INDEXING_SIMULATION ) return str; - 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 { @@ -727,24 +801,6 @@ char *indexer_str(IndexingMethod indm) strcat(str, "-nocell"); } - if ( indm & INDEXING_RETRY ) { - strcat(str, "-retry"); - } else { - strcat(str, "-noretry"); - } - - if ( indm & INDEXING_MULTI ) { - strcat(str, "-multi"); - } else { - strcat(str, "-nomulti"); - } - - if ( indm & INDEXING_REFINE ) { - strcat(str, "-refine"); - } else { - strcat(str, "-norefine"); - } - return str; } @@ -813,18 +869,6 @@ IndexingMethod get_indm_from_string(const char *str) method = INDEXING_DEBUG; return method; - } else if ( strcmp(bits[i], "raw") == 0) { - method = set_raw(method); - - } else if ( strcmp(bits[i], "bad") == 0) { - method = set_bad(method); - - } else if ( strcmp(bits[i], "comb") == 0) { - method = set_comb(method); /* Default */ - - } else if ( strcmp(bits[i], "axes") == 0) { - method = set_axes(method); - } else if ( strcmp(bits[i], "latt") == 0) { method = set_lattice(method); @@ -837,24 +881,6 @@ IndexingMethod get_indm_from_string(const char *str) } else if ( strcmp(bits[i], "nocell") == 0) { method = set_nocellparams(method); - } else if ( strcmp(bits[i], "retry") == 0) { - method |= INDEXING_RETRY; - - } else if ( strcmp(bits[i], "noretry") == 0) { - method &= ~INDEXING_RETRY; - - } else if ( strcmp(bits[i], "multi") == 0) { - method |= INDEXING_MULTI; - - } else if ( strcmp(bits[i], "nomulti") == 0) { - method &= ~INDEXING_MULTI; - - } else if ( strcmp(bits[i], "refine") == 0) { - method |= INDEXING_REFINE; - - } else if ( strcmp(bits[i], "norefine") == 0) { - method &= ~INDEXING_REFINE; - } else { ERROR("Bad list of indexing methods: '%s'\n", str); return INDEXING_ERROR; |