From b1564832546574c2c1d1037a93dfa069ec68740d Mon Sep 17 00:00:00 2001 From: davidmcdonagh Date: Tue, 28 May 2024 10:34:17 +0100 Subject: [PATCH] Fix imageviewer for tof data when including integrated reflections. Filter out reflections with bounding boxes outside of detectors rather than truncating them. Allow for user defined sigma_b and sigma_m in tof integration. Integrate all predicted spots by default rather than just those observed. --- .../gaussian_rs/bbox_calculator.h | 4 +++ .../command_line/simple_tof_integrate.py | 27 ++++++++++++++----- .../util/image_viewer/spotfinder_frame.py | 5 ++-- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/dials/algorithms/profile_model/gaussian_rs/bbox_calculator.h b/src/dials/algorithms/profile_model/gaussian_rs/bbox_calculator.h index 8c90549ae0..7a669fa99c 100644 --- a/src/dials/algorithms/profile_model/gaussian_rs/bbox_calculator.h +++ b/src/dials/algorithms/profile_model/gaussian_rs/bbox_calculator.h @@ -462,6 +462,10 @@ namespace dials { if (z1 > max_z) { z1 = max_z; } + if (z0 > z1) { + z0 = -1; + z1 = 0; + } int6 bbox(x0, x1, y0, y1, z0, z1); DIALS_ASSERT(bbox[1] > bbox[0]); diff --git a/src/dials/command_line/simple_tof_integrate.py b/src/dials/command_line/simple_tof_integrate.py index 6d253797e9..ea526f614c 100644 --- a/src/dials/command_line/simple_tof_integrate.py +++ b/src/dials/command_line/simple_tof_integrate.py @@ -23,6 +23,9 @@ from dials.algorithms.integration.report import IntegrationReport, ProfileModelReport from dials.algorithms.profile_model.gaussian_rs import GaussianRSProfileModeller from dials.algorithms.profile_model.gaussian_rs import Model as GaussianRSProfileModel +from dials.algorithms.profile_model.gaussian_rs.calculator import ( + ComputeEsdBeamDivergence, +) from dials.algorithms.shoebox import MaskCode from dials.array_family import flex from dials.command_line.integrate import process_reference @@ -64,6 +67,12 @@ .help = "Use integration by profile fitting using a Gaussian" "convoluted with back-to-back exponential functions" } +sigma_b = 0.01 + .type = float + .help = "Used to calculate xy bounding box of predicted reflections" +sigma_m = 3 + .type = float + .help = "Used to calculate z bounding box of predicted reflections" keep_shoeboxes = False .type = bool .help = "Retain shoeboxes in output reflection table" @@ -592,10 +601,9 @@ def run_simple_integrate(params, experiments, reflections): matched, reflections, unmatched = predicted_reflections.match_with_reference( reflections ) - sel = predicted_reflections.get_flags(predicted_reflections.flags.reference_spot) - predicted_reflections = predicted_reflections.select(sel) - if "idx" in reflections: - predicted_reflections["idx"] = reflections["idx"] + # if "idx" in reflections: + # predicted_reflections["idx"] = reflections["idx"] + # sel = predicted_reflections.get_flags(predicted_reflections.flags.reference_spot) """ Create profile model and add it to experiment. @@ -606,9 +614,13 @@ def run_simple_integrate(params, experiments, reflections): used_in_ref = reflections.get_flags(reflections.flags.used_in_refinement) model_reflections = reflections.select(used_in_ref) + sigma_b = ComputeEsdBeamDivergence( + experiment.detector, model_reflections, centroid_definition="s1" + ).sigma() + # sigma_m in 3.1 of Kabsch 2010 - sigma_m = 3 - sigma_b = 0.01 + sigma_m = params.sigma_m + sigma_b = 0.001 # The Gaussian model given in 2.3 of Kabsch 2010 for idx, experiment in enumerate(experiments): experiments[idx].profile = GaussianRSProfileModel( @@ -625,9 +637,12 @@ def run_simple_integrate(params, experiments, reflections): predicted_reflections.compute_bbox(experiments) x1, x2, y1, y2, t1, t2 = predicted_reflections["bbox"].parts() + predicted_reflections = predicted_reflections.select(t1 > 0) + x1, x2, y1, y2, t1, t2 = predicted_reflections["bbox"].parts() predicted_reflections = predicted_reflections.select( t2 < experiments[0].sequence.get_image_range()[1] ) + predicted_reflections.compute_d(experiments) predicted_reflections.compute_partiality(experiments) diff --git a/src/dials/util/image_viewer/spotfinder_frame.py b/src/dials/util/image_viewer/spotfinder_frame.py index 86a8ad5c67..529f3de5ca 100644 --- a/src/dials/util/image_viewer/spotfinder_frame.py +++ b/src/dials/util/image_viewer/spotfinder_frame.py @@ -14,6 +14,7 @@ from cctbx import crystal, uctbx from cctbx.miller import index_generator from dxtbx.imageset import ImageSet +from dxtbx.model import Scan from dxtbx.model.detector_helpers import get_detector_projection_2d_axes from dxtbx.model.experiment_list import ExperimentList, ExperimentListFactory from libtbx.utils import flat_list @@ -2005,7 +2006,7 @@ def _basis_vector_overlay_data(self, i_expt, i_frame, experiment): beam = imageset.get_beam() gonio = imageset.get_goniometer() still = scan is None or gonio is None - if not still: + if not still and isinstance(scan, Scan): phi = scan.get_angle_from_array_index( i_frame - imageset.get_array_range()[0], deg=True ) @@ -2029,7 +2030,7 @@ def _basis_vector_overlay_data(self, i_expt, i_frame, experiment): for i, h in enumerate(((1, 0, 0), (0, 1, 0), (0, 0, 1))): r = A * matrix.col(h) * self.settings.basis_vector_scale - if still: + if still or not isinstance(scan, Scan): s1 = matrix.col(beam.get_unit_s0()) + r else: r_phi = r.rotate_around_origin(axis, phi, deg=True)