Skip to content

Commit

Permalink
Don't apply sigma correction to scaled data in cosym (dials#2818)
Browse files Browse the repository at this point in the history
Changes apply to running dials.symmetry, dials.cosym or dials.correlation_matrix on scaled data.
  • Loading branch information
jbeilstenedmands authored Nov 25, 2024
1 parent 1ca8c85 commit a36bd41
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions newsfragments/2818.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``dials.correlation_matrix``: Don't apply further sigma correction on scaled data
9 changes: 8 additions & 1 deletion src/dials/algorithms/correlation/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ def __init__(
if params is None:
params = phil_scope.extract()
self.params = params

# if all datasets have been through scaling, a decision about error models has
# been made, so don't apply any further sigma correction
apply_sigma_correction = not all(s for s in experiments.scaling_models())

self._reflections = []
self.ids_to_identifiers_map = ids_to_identifiers_map

Expand Down Expand Up @@ -147,7 +152,9 @@ def __init__(
self.params.__inject__("lattice_symmetry_max_delta", 0.0)
self.params.__inject__("best_monoclinic_beta", True)

self.cosym_analysis = CosymAnalysis(self.datasets, self.params)
self.cosym_analysis = CosymAnalysis(
self.datasets, self.params, apply_sigma_correction=apply_sigma_correction
)

def _merge_intensities(self, datasets: list) -> list:
"""
Expand Down
5 changes: 4 additions & 1 deletion src/dials/algorithms/symmetry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(
relative_length_tolerance=None,
absolute_angle_tolerance=None,
best_monoclinic_beta=True,
apply_sigma_correction=True,
):
"""Initialise a symmetry_base object.
Expand All @@ -69,6 +70,7 @@ def __init__(
best_monoclinic_beta (bool): If True, then for monoclinic centered cells, I2
will be preferred over C2 if it gives a less oblique cell (i.e. smaller
beta angle).
apply_sigma_correction (bool): If True, correct SDs by "typical" SD factors.
"""
self.input_intensities = intensities

Expand Down Expand Up @@ -127,7 +129,8 @@ def __init__(
self.dataset_ids = self.dataset_ids.select(sel)

# Correct SDs by "typical" SD factors
self._correct_sigmas(sd_fac=2.0, sd_b=0.0, sd_add=0.03)
if apply_sigma_correction:
self._correct_sigmas(sd_fac=2.0, sd_b=0.0, sd_add=0.03)
self._normalise(normalisation)
self._resolution_filter(d_min, min_i_mean_over_sigma_mean, min_cc_half)

Expand Down
9 changes: 8 additions & 1 deletion src/dials/algorithms/symmetry/cosym/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,13 @@ class CosymAnalysis(symmetry_base, Subject):
the presence of an indexing ambiguity.
"""

def __init__(self, intensities, params, seed_dataset: Optional[int] = None):
def __init__(
self,
intensities,
params,
seed_dataset: Optional[int] = None,
apply_sigma_correction=True,
):
"""Initialise a CosymAnalysis object.
Args:
Expand Down Expand Up @@ -175,6 +181,7 @@ def __init__(self, intensities, params, seed_dataset: Optional[int] = None):
relative_length_tolerance=None,
absolute_angle_tolerance=None,
best_monoclinic_beta=params.best_monoclinic_beta,
apply_sigma_correction=apply_sigma_correction,
)
Subject.__init__(
self, events=["optimised", "analysed_symmetry", "analysed_clusters"]
Expand Down
2 changes: 2 additions & 0 deletions src/dials/algorithms/symmetry/laue_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(
relative_length_tolerance=None,
absolute_angle_tolerance=None,
best_monoclinic_beta=True,
apply_sigma_correction=True,
):
"""Initialise a LaueGroupAnalysis object.
Expand Down Expand Up @@ -77,6 +78,7 @@ def __init__(
relative_length_tolerance=relative_length_tolerance,
absolute_angle_tolerance=absolute_angle_tolerance,
best_monoclinic_beta=best_monoclinic_beta,
apply_sigma_correction=apply_sigma_correction,
)

self._estimate_cc_sig_fac()
Expand Down
13 changes: 11 additions & 2 deletions src/dials/command_line/cosym.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def __init__(self, experiments, reflections, params=None):
params = phil_scope.extract()
self.params = params

# if all datasets have been through scaling, a decision about error models has
# been made, so don't apply any further sigma correction
apply_sigma_correction = not all(s for s in experiments.scaling_models())

reference_intensities = None
if self.params.reference:
wl = np.mean([expt.beam.get_wavelength() for expt in experiments])
Expand Down Expand Up @@ -191,10 +195,15 @@ def __init__(self, experiments, reflections, params=None):
# The purpose of the reference is to help the clustering, not guarantee the indexing solution.
datasets.append(reference_intensities)
self.cosym_analysis = CosymAnalysis(
datasets, self.params, seed_dataset=len(datasets) - 1
datasets,
self.params,
seed_dataset=len(datasets) - 1,
apply_sigma_correction=apply_sigma_correction,
)
else:
self.cosym_analysis = CosymAnalysis(datasets, self.params)
self.cosym_analysis = CosymAnalysis(
datasets, self.params, apply_sigma_correction=apply_sigma_correction
)

@property
def experiments(self):
Expand Down
5 changes: 5 additions & 0 deletions src/dials/command_line/symmetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ def symmetry(experiments, reflection_tables, params=None):
input data and filtering settings e.g partiality_threshold"""
)

# if all datasets have been through scaling, a decision about error models has
# been made, so don't apply any further sigma correction
apply_sigma_correction = not all(s for s in experiments.scaling_models())

datasets = [
ma.as_anomalous_array().merge_equivalents().array() for ma in datasets
]
Expand All @@ -417,6 +421,7 @@ def symmetry(experiments, reflection_tables, params=None):
relative_length_tolerance=params.relative_length_tolerance,
absolute_angle_tolerance=params.absolute_angle_tolerance,
best_monoclinic_beta=params.best_monoclinic_beta,
apply_sigma_correction=apply_sigma_correction,
)
logger.info("")
logger.info(result)
Expand Down

0 comments on commit a36bd41

Please sign in to comment.