/* * index.c * * Perform indexing (somehow) * * Copyright © 2012-2013 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * Copyright © 2012 Lorenzo Galli * * Authors: * 2010-2013 Thomas White * 2010-2011 Richard Kirian * 2012 Lorenzo Galli * * This file is part of CrystFEL. * * CrystFEL is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * CrystFEL is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with CrystFEL. If not, see . * */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include "image.h" #include "utils.h" #include "peaks.h" #include "dirax.h" #include "mosflm.h" #include "detector.h" #include "index.h" #include "index-priv.h" #include "reax.h" #include "geometry.h" #include "cell-utils.h" static const char *maybes(int n) { if ( n == 1 ) return ""; return "s"; } IndexingPrivate **prepare_indexing(IndexingMethod *indm, UnitCell *cell, const char *filename, struct detector *det, struct beam_params *beam, float *ltl) { int n; int nm = 0; IndexingPrivate **iprivs; while ( indm[nm] != INDEXING_NONE ) nm++; STATUS("Preparing %i indexing method%s.\n", nm, maybes(nm)); iprivs = malloc((nm+1) * sizeof(IndexingPrivate *)); for ( n=0; nfeatures); /* Map positions to 3D */ for ( i=0; ifeatures, i); if ( f == NULL ) continue; r = get_q(image, f->fs, f->ss, NULL, 1.0/image->lambda); f->rx = r.u; f->ry = r.v; f->rz = r.w; } } /* Return non-zero for "success" */ static int try_indexer(struct image *image, IndexingMethod indm, IndexingPrivate *ipriv) { switch ( indm & INDEXING_METHOD_MASK ) { case INDEXING_NONE : break; case INDEXING_DIRAX : return run_dirax(image, ipriv); break; case INDEXING_MOSFLM : return run_mosflm(image, ipriv); break; case INDEXING_REAX : return reax_index(image, ipriv); break; default : ERROR("Unrecognised indexing method: %i\n", indm); break; } return 0; } void index_pattern(struct image *image, IndexingMethod *indms, IndexingPrivate **iprivs) { int n = 0; if ( indms == NULL ) return; map_all_peaks(image); image->crystals = NULL; image->n_crystals = 0; while ( indms[n] != INDEXING_NONE ) { if ( try_indexer(image, indms[n], iprivs[n]) ) break; 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; } /* 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; } IndexingMethod *build_indexer_list(const char *str) { int n, i; char **methods; IndexingMethod *list; int tmp; int nmeth = 0; 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