Skip to content

Commit

Permalink
Enabled find_max_cell to work with tof data.
Browse files Browse the repository at this point in the history
  • Loading branch information
toastisme committed Mar 19, 2024
1 parent 3f63f63 commit 63e8028
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
20 changes: 20 additions & 0 deletions src/dials/algorithms/indexing/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,25 @@ def find_max_cell(self):
self.params.max_cell = params.multiplier * max(uc_params[:3])
logger.info("Using max_cell: %.1f Angstrom", self.params.max_cell)
else:

convert_reflections_z_to_deg = True
all_tof_experiments = False
for expt in self.experiments:
if expt.scan is not None and expt.scan.has_property(
"time_of_flight"
):
all_tof_experiments = True
elif all_tof_experiments:
raise ValueError(
"Cannot find max cell for ToF and non-ToF experiments at the same time"
)

if all_tof_experiments:
if params.step_size < 100:
logger.info("Setting default ToF step size to 500 usec")
params.step_size = 500
convert_reflections_z_to_deg = False

self.params.max_cell = find_max_cell(
self.reflections,
max_cell_multiplier=params.multiplier,
Expand All @@ -952,6 +971,7 @@ def find_max_cell(self):
filter_ice=params.filter_ice,
filter_overlaps=params.filter_overlaps,
overlaps_border=params.overlaps_border,
convert_reflections_z_to_deg=convert_reflections_z_to_deg,
).max_cell
logger.info("Found max_cell: %.1f Angstrom", self.params.max_cell)

Expand Down
2 changes: 2 additions & 0 deletions src/dials/algorithms/indexing/max_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def find_max_cell(
filter_ice=True,
filter_overlaps=True,
overlaps_border=0,
convert_reflections_z_to_deg=True,
):
logger.debug("Finding suitable max_cell based on %i reflections", len(reflections))
# Exclude potential ice-ring spots from nearest neighbour analysis if needed
Expand Down Expand Up @@ -63,6 +64,7 @@ def find_max_cell(
percentile=nearest_neighbor_percentile,
histogram_binning=histogram_binning,
nn_per_bin=nn_per_bin,
convert_reflections_z_to_deg=convert_reflections_z_to_deg,
)
except AssertionError as e:
raise DialsIndexError("Failure in nearest neighbour analysis:\n" + str(e))
Expand Down
18 changes: 11 additions & 7 deletions src/dials/algorithms/indexing/nearest_neighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(
percentile=None,
histogram_binning="linear",
nn_per_bin=5,
convert_reflections_z_to_deg=True,
):
self.tolerance = tolerance # Margin of error for max unit cell estimate
from scitbx.array_family import flex
Expand All @@ -28,7 +29,10 @@ def __init__(
else:
entering_flags = flex.bool(reflections.size(), True)
rs_vectors = reflections["rlp"]
phi_deg = reflections["xyzobs.mm.value"].parts()[2] * (180 / math.pi)

z = reflections["xyzobs.mm.value"].parts()[2]
if convert_reflections_z_to_deg:
z = z * (180 / math.pi)

d_spacings = flex.double()
# nearest neighbor analysis
Expand All @@ -38,16 +42,16 @@ def __init__(
sel_imageset = reflections["imageset_id"] == imageset_id
if sel_imageset.count(True) == 0:
continue
phi_min = flex.min(phi_deg.select(sel_imageset))
phi_max = flex.max(phi_deg.select(sel_imageset))
d_phi = phi_max - phi_min
n_steps = max(int(math.ceil(d_phi / step_size)), 1)
z_min = flex.min(z.select(sel_imageset))
z_max = flex.max(z.select(sel_imageset))
d_z = z_max - z_min
n_steps = max(int(math.ceil(d_z / step_size)), 1)

for n in range(n_steps):
sel_step = (
sel_imageset
& (phi_deg >= (phi_min + n * step_size))
& (phi_deg < (phi_min + (n + 1) * step_size))
& (z >= (z_min + n * step_size))
& (z < (z_min + (n + 1) * step_size))
)

for entering in (True, False):
Expand Down

0 comments on commit 63e8028

Please sign in to comment.