1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
/*
* index.c
*
* Perform indexing (somehow)
*
* (c) 2006-2011 Thomas White <taw@physics.org>
* (c) 2010 Richard Kirian <rkirian@asu.edu>
*
* Part of CrystFEL - crystallography with a FEL
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <assert.h>
#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"
/* Base class constructor for unspecialised indexing private data */
static IndexingPrivate *indexing_private(IndexingMethod indm)
{
struct _indexingprivate *priv;
priv = calloc(1, sizeof(struct _indexingprivate));
priv->indm = indm;
return priv;
}
IndexingPrivate **prepare_indexing(IndexingMethod *indm, UnitCell *cell,
const char *filename, struct detector *det,
double nominal_photon_energy)
{
int n;
int nm = 0;
IndexingPrivate **iprivs;
while ( indm[nm] != INDEXING_NONE ) nm++;
STATUS("Preparing %i indexing methods.\n", nm);
iprivs = malloc((nm+1) * sizeof(IndexingPrivate *));
for ( n=0; n<nm; n++ ) {
switch ( indm[n] ) {
case INDEXING_NONE :
ERROR("Tried to prepare INDEXING_NONE!\n");
break;
case INDEXING_DIRAX :
iprivs[n] = indexing_private(indm[n]);
break;
case INDEXING_MOSFLM :
iprivs[n] = indexing_private(indm[n]);
break;
}
}
iprivs[n] = NULL;
return iprivs;
}
void cleanup_indexing(IndexingPrivate **priv)
{
int n = 0;
if ( priv == NULL ) return; /* Nothing to do */
while ( priv[n] != NULL ) {
switch ( priv[n]->indm ) {
case INDEXING_NONE :
free(priv[n]);
break;
case INDEXING_DIRAX :
free(priv[n]);
break;
case INDEXING_MOSFLM :
free(priv[n]);
break;
}
n++;
}
}
void map_all_peaks(struct image *image)
{
int i;
/* Map positions to 3D */
for ( i=0; i<image_feature_count(image->features); i++ ) {
struct imagefeature *f;
struct rvec r;
f = image_get_feature(image->features, 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;
}
}
void index_pattern(struct image *image, UnitCell *cell, IndexingMethod *indm,
int cellr, int verbose, IndexingPrivate **ipriv,
int config_insane)
{
int i;
int n = 0;
if ( indm == NULL ) return;
map_all_peaks(image);
while ( indm[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;
}
if ( image->ncells == 0 ) {
n++;
continue;
}
for ( i=0; i<image->ncells; i++ ) {
UnitCell *new_cell = NULL;
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(image
->candidate_cells[i]);
break;
case CELLR_REDUCE :
new_cell = match_cell(image->candidate_cells[i],
cell, verbose, 1);
break;
case CELLR_COMPARE :
new_cell = match_cell(image->candidate_cells[i],
cell, verbose, 0);
break;
}
/* No cell? Move on to the next candidate */
if ( new_cell == NULL ) continue;
/* Sanity check */
if ( !config_insane &&
!peak_sanity_check(image, new_cell, 0, 0.1) ) {
cell_free(new_cell);
continue;
}
image->indexed_cell = new_cell;
goto done; /* Success */
}
for ( i=0; i<image->ncells; i++ ) {
cell_free(image->candidate_cells[i]);
image->candidate_cells[i] = NULL;
}
/* Move on to the next indexing method */
n++;
}
done:
for ( i=0; i<image->ncells; i++ ) {
/* May free(NULL) if all algorithms were tried and no success */
cell_free(image->candidate_cells[i]);
}
}
IndexingMethod *build_indexer_list(const char *str, int *need_cell)
{
int n, i;
char **methods;
IndexingMethod *list;
*need_cell = 0;
n = assplode(str, ",", &methods, ASSPLODE_NONE);
list = malloc((n+1)*sizeof(IndexingMethod));
for ( i=0; i<n; i++ ) {
if ( strcmp(methods[i], "dirax") == 0) {
list[i] = INDEXING_DIRAX;
} else if ( strcmp(methods[i], "mosflm") == 0) {
list[i] = INDEXING_MOSFLM;
} else {
ERROR("Unrecognised indexing method '%s'\n",
methods[i]);
return NULL;
}
free(methods[i]);
}
free(methods);
list[i] = INDEXING_NONE;
return list;
}
|