Skip to content

Commit f83c7f1

Browse files
Clean clutter
1 parent e42956e commit f83c7f1

File tree

2 files changed

+72
-40
lines changed

2 files changed

+72
-40
lines changed

command_line/ssx_index.py

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
process_includes=True,
7575
).fetch(phil.parse(program_defaults_phil_str))
7676

77+
7778
def _index_one(experiment, refl, params, method_list, expt_no):
7879
elist = ExperimentList([experiment])
7980
for method in method_list:
@@ -82,11 +83,15 @@ def _index_one(experiment, refl, params, method_list, expt_no):
8283
try:
8384
idxr.index()
8485
except (DialsIndexError, AssertionError) as e:
85-
logger.info(f"Image {expt_no+1}: Failed to index with {method} method, error: {e}")
86+
logger.info(
87+
f"Image {expt_no+1}: Failed to index with {method} method, error: {e}"
88+
)
8689
if method == method_list[-1]:
8790
return None, None, expt_no
8891
else:
89-
logger.info(f"Image {expt_no+1}: Indexed {idxr.refined_reflections.size()}/{refl.size()} spots with {method} method.")
92+
logger.info(
93+
f"Image {expt_no+1}: Indexed {idxr.refined_reflections.size()}/{refl.size()} spots with {method} method."
94+
)
9095
return idxr.refined_experiments, idxr.refined_reflections, expt_no
9196

9297

@@ -100,8 +105,12 @@ def run_with_disabled_logs(fn, fnargs):
100105
log2 = logging.getLogger("dials.algorithms.refinement.refiner")
101106
log3 = logging.getLogger("dials.algorithms.indexing.stills_indexer")
102107
log4 = logging.getLogger("dials.algorithms.indexing.nave_parameters")
103-
log5 = logging.getLogger("dials.algorithms.indexing.basis_vector_search.real_space_grid_search")
104-
log6 = logging.getLogger("dials.algorithms.indexing.basis_vector_search.combinations")
108+
log5 = logging.getLogger(
109+
"dials.algorithms.indexing.basis_vector_search.real_space_grid_search"
110+
)
111+
log6 = logging.getLogger(
112+
"dials.algorithms.indexing.basis_vector_search.combinations"
113+
)
105114
log7 = logging.getLogger("dials.algorithms.indexing.indexer")
106115
with LoggingContext(log1, level=logging.ERROR):
107116
with LoggingContext(log2, level=logging.ERROR):
@@ -117,20 +126,20 @@ def run_with_disabled_logs(fn, fnargs):
117126
# Calculate necessary quantities
118127
for refl, experiment in zip(reflections, experiments):
119128
elist = ExperimentList([experiment])
120-
refl["imageset_id"] = flex.int(
121-
refl.size(), 0
122-
) # needed for centroid_px_to_mm
129+
refl["imageset_id"] = flex.int(refl.size(), 0) # needed for centroid_px_to_mm
123130
refl.centroid_px_to_mm(elist)
124131
refl.map_centroids_to_reciprocal_space(elist)
125132

126-
if (params.indexing.max_cell is Auto) and (not params.indexing.known_symmetry.unit_cell):
133+
if (params.indexing.max_cell is Auto) and (
134+
not params.indexing.known_symmetry.unit_cell
135+
):
127136
max_cells = []
128137
for refl in reflections:
129138
try:
130139
max_cells.append(find_max_cell(refl).max_cell)
131140
except (DialsIndexError, AssertionError):
132141
pass
133-
logger.info(f"Setting max cell to {max(max_cells):.1f} "+ u"\u212B")
142+
logger.info(f"Setting max cell to {max(max_cells):.1f} " + "\u212B")
134143
params.indexing.max_cell = max(max_cells)
135144

136145
n_strong = np.array([table.size() for table in reflections])
@@ -147,7 +156,14 @@ def run_with_disabled_logs(fn, fnargs):
147156

148157
def index_all(experiments, reflections, params):
149158
n_found = 0
150-
overall_summary_header = ["Image", "expt_id", "n_indexed", "RMSD_X", "RMSD_Y", "RMSD_dPsi"]
159+
overall_summary_header = [
160+
"Image",
161+
"expt_id",
162+
"n_indexed",
163+
"RMSD_X",
164+
"RMSD_Y",
165+
"RMSD_dPsi",
166+
]
151167

152168
futures = []
153169
results = defaultdict(list)
@@ -160,12 +176,10 @@ def index_all(experiments, reflections, params):
160176
) as pool:
161177
for i, (expt, refl) in enumerate(zip(experiments, reflections)):
162178
futures.append(
163-
pool.submit(
164-
_index_one, expt, refl, params, method_list, i
165-
)
179+
pool.submit(_index_one, expt, refl, params, method_list, i)
166180
)
167181
for future in concurrent.futures.as_completed(futures):
168-
idx_expts, idx_refl, index= future.result()
182+
idx_expts, idx_refl, index = future.result()
169183
if idx_expts:
170184
results_order = np.append(results_order, [index])
171185
ids_map = dict(idx_refl.experiment_identifiers())
@@ -175,18 +189,20 @@ def index_all(experiments, reflections, params):
175189
calx, caly, calz = selr["xyzcal.px"].parts()
176190
obsx, obsy, obsz = selr["xyzobs.px.value"].parts()
177191
delpsi = selr["delpsical.rad"]
178-
rmsd_x = flex.mean((calx - obsx) ** 2)**0.5
179-
rmsd_y = flex.mean((caly - obsy) ** 2)**0.5
180-
rmsd_z = flex.mean(((delpsi) * RAD2DEG) ** 2)**0.5
192+
rmsd_x = flex.mean((calx - obsx) ** 2) ** 0.5
193+
rmsd_y = flex.mean((caly - obsy) ** 2) ** 0.5
194+
rmsd_z = flex.mean(((delpsi) * RAD2DEG) ** 2) ** 0.5
181195
n_id_ = calx.size()
182196
n_indexed = f"{n_id_}/{n_strong[index]} ({100*n_id_/n_strong[index]:2.1f}%)"
183-
results[index].append([
184-
path.split("/")[-1],
185-
n_indexed,
186-
f"{rmsd_x:.3f}",
187-
f"{rmsd_y:.3f}",
188-
f" {rmsd_z:.4f}",
189-
])
197+
results[index].append(
198+
[
199+
path.split("/")[-1],
200+
n_indexed,
201+
f"{rmsd_x:.3f}",
202+
f"{rmsd_y:.3f}",
203+
f" {rmsd_z:.4f}",
204+
]
205+
)
190206
n_found += len(ids_map.keys())
191207
tables_list.append(idx_refl)
192208
elist = ExperimentList()
@@ -199,7 +215,7 @@ def index_all(experiments, reflections, params):
199215
scan=jexpt.scan,
200216
goniometer=jexpt.goniometer,
201217
crystal=jexpt.crystal,
202-
imageset=jexpt.imageset[index:index+1],
218+
imageset=jexpt.imageset[index : index + 1],
203219
)
204220
)
205221
expts_list.append(elist)
@@ -219,7 +235,9 @@ def index_all(experiments, reflections, params):
219235
table.experiment_identifiers()[k + n_tot] = v
220236
n_tot += len(ids_map.keys())
221237
indexed_reflections.extend(table)
222-
indexed_reflections.assert_experiment_identifiers_are_consistent(indexed_experiments)
238+
indexed_reflections.assert_experiment_identifiers_are_consistent(
239+
indexed_experiments
240+
)
223241

224242
# Add a few extra useful items to the summary table.
225243
rows = []
@@ -233,14 +251,19 @@ def index_all(experiments, reflections, params):
233251
for j, cryst in enumerate(results[k]):
234252
cryst.insert(1, total)
235253
if show_lattices:
236-
cryst.insert(1, j+1)
254+
cryst.insert(1, j + 1)
237255
rows.append(cryst)
238256
total += 1
239257

240-
return indexed_experiments, indexed_reflections, tabulate(rows, overall_summary_header)
258+
return (
259+
indexed_experiments,
260+
indexed_reflections,
261+
tabulate(rows, overall_summary_header),
262+
)
241263

242-
indexed_experiments, indexed_reflections, summary = \
243-
run_with_disabled_logs(index_all, (experiments, reflections, params))
264+
indexed_experiments, indexed_reflections, summary = run_with_disabled_logs(
265+
index_all, (experiments, reflections, params)
266+
)
244267

245268
# print some clustering information
246269
crystal_symmetries = [
@@ -254,13 +277,11 @@ def index_all(experiments, reflections, params):
254277
clusters, cluster_axes = ucs.ab_cluster(
255278
5000, log=None, write_file_lists=False, doplot=False
256279
)
257-
logger.info("\nUnit cell clustering analysis\n"+unit_cell_info(clusters))
258-
logger.info("\nSummary of images sucessfully indexed\n"+summary)
280+
logger.info("\nUnit cell clustering analysis\n" + unit_cell_info(clusters))
281+
logger.info("\nSummary of images sucessfully indexed\n" + summary)
259282

260283
n_images = len(set(e.imageset.get_path(0) for e in indexed_experiments))
261-
logger.info(
262-
f"{indexed_reflections.size()} spots indexed on {n_images} images"
263-
)
284+
logger.info(f"{indexed_reflections.size()} spots indexed on {n_images} images")
264285

265286
# combine beam and detector models if not already
266287
if (len(indexed_experiments.detectors())) > 1 or (

command_line/ssx_inspect.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121

2222
logger = logging.getLogger("dials")
2323

24-
phil_scope = phil.parse("""
24+
phil_scope = phil.parse(
25+
"""
2526
d_min = None
2627
.type = float
2728
threshold_i_over_sigma = None
2829
.type = float
29-
""")
30+
"""
31+
)
32+
3033

3134
def inspect(experiments, reflections, params):
3235

@@ -37,7 +40,7 @@ def inspect(experiments, reflections, params):
3740
return
3841
I = reflections["intensity.sum.value"]
3942
sig = reflections["intensity.sum.variance"] ** 0.5
40-
Ioversig = I/sig
43+
Ioversig = I / sig
4144
images = []
4245

4346
for (id_, identifier) in dict(reflections.experiment_identifiers()).items():
@@ -46,7 +49,11 @@ def inspect(experiments, reflections, params):
4649
expt = (experiments.identifiers() == identifier).iselection()[0]
4750
images.append(experiments[expt].imageset.get_path(0).split("/")[-1])
4851

49-
header = ["image", "expt_id", ("I/sigma" + f" (d_min={params.d_min})" if params.d_min else "I/sigma")]
52+
header = [
53+
"image",
54+
"expt_id",
55+
("I/sigma" + f" (d_min={params.d_min})" if params.d_min else "I/sigma"),
56+
]
5057
rows = []
5158

5259
for i, (image, Iovers) in enumerate(zip(images, Ioversig_per_crystal)):
@@ -56,7 +63,11 @@ def inspect(experiments, reflections, params):
5663

5764
if params.threshold_i_over_sigma:
5865
logger.info(f"Integrated images with I/sigma > {params.threshold_i_over_sigma}")
59-
header = ["image", "expt_id", ("I/sigma" + f" (d_min={params.d_min})" if params.d_min else "I/sigma")]
66+
header = [
67+
"image",
68+
"expt_id",
69+
("I/sigma" + f" (d_min={params.d_min})" if params.d_min else "I/sigma"),
70+
]
6071
rows = []
6172

6273
for i, (image, Iovers) in enumerate(zip(images, Ioversig_per_crystal)):

0 commit comments

Comments
 (0)