diff --git a/newsfragments/2818.misc b/newsfragments/2818.misc new file mode 100644 index 0000000000..4af7cc7e64 --- /dev/null +++ b/newsfragments/2818.misc @@ -0,0 +1 @@ +``dials.correlation_matrix``: Don't apply further sigma correction on scaled data diff --git a/src/dials/algorithms/correlation/analysis.py b/src/dials/algorithms/correlation/analysis.py index e6e8210181..13b326961a 100644 --- a/src/dials/algorithms/correlation/analysis.py +++ b/src/dials/algorithms/correlation/analysis.py @@ -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 @@ -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: """ diff --git a/src/dials/algorithms/symmetry/__init__.py b/src/dials/algorithms/symmetry/__init__.py index 57613186c9..be4eaad027 100644 --- a/src/dials/algorithms/symmetry/__init__.py +++ b/src/dials/algorithms/symmetry/__init__.py @@ -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. @@ -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 @@ -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) diff --git a/src/dials/algorithms/symmetry/cosym/__init__.py b/src/dials/algorithms/symmetry/cosym/__init__.py index e8829961d4..eda697e5b7 100644 --- a/src/dials/algorithms/symmetry/cosym/__init__.py +++ b/src/dials/algorithms/symmetry/cosym/__init__.py @@ -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: @@ -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"] diff --git a/src/dials/algorithms/symmetry/laue_group.py b/src/dials/algorithms/symmetry/laue_group.py index cd50d0bb76..d018a74d4c 100644 --- a/src/dials/algorithms/symmetry/laue_group.py +++ b/src/dials/algorithms/symmetry/laue_group.py @@ -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. @@ -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() diff --git a/src/dials/command_line/cosym.py b/src/dials/command_line/cosym.py index f98b98a6bd..097bcc2335 100644 --- a/src/dials/command_line/cosym.py +++ b/src/dials/command_line/cosym.py @@ -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]) @@ -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): diff --git a/src/dials/command_line/symmetry.py b/src/dials/command_line/symmetry.py index 9485f27f10..c584d5450e 100644 --- a/src/dials/command_line/symmetry.py +++ b/src/dials/command_line/symmetry.py @@ -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 ] @@ -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)