-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
68 lines (56 loc) · 2.01 KB
/
index.py
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
import logging
import copy
import time
from dials.array_family import flex
from dials.algorithms.indexing.indexer import Indexer
logger = logging.getLogger()
from simemc import utils
def index(phil, experiments, reflections, greedy=True):
"""
:param phil: path to a stills_process phil file
:param experiments: experiments list with crystal models
:param reflections: strong spot reflections (observed, not necessarilly indexed)
:return:
"""
params = utils.stills_process_params_from_file(phil)
st = time.time()
logger.info("*" * 80)
logger.info("Indexing Strong Spots")
logger.info("*" * 80)
params = copy.deepcopy(params)
params.refinement.parameterisation.scan_varying = False
if greedy:
params.indexing.index_assignment.simple.hkl_tolerance = 0.5 # go for broke!
params.indexing.refinement_protocol.mode = "repredict_only" # no more refinement from dials
idxr = Indexer.from_parameters(
reflections,
experiments,
known_crystal_models=experiments.crystals(),
params=params,
)
idxr.index()
logger.info("indexed from known orientation")
indexed = idxr.refined_reflections
experiments = idxr.refined_experiments
filtered_sel = flex.bool(len(indexed), True)
for expt_id in range(len(experiments)):
for idx in set(
indexed["miller_index"].select(indexed["id"] == expt_id)
):
sel = (indexed["miller_index"] == idx) & (indexed["id"] == expt_id)
if sel.count(True) > 1:
filtered_sel = filtered_sel & ~sel
filtered = indexed.select(filtered_sel)
logger.info(
"Filtered duplicate reflections, %d out of %d remaining",
len(filtered),
len(indexed),
)
print(
"Filtered duplicate reflections, %d out of %d remaining"
% (len(filtered), len(indexed))
)
indexed = filtered
logger.info("")
logger.info("Time Taken = %f seconds", time.time() - st)
return experiments, indexed