0
].get_pixel_size()
-
# do outlier rejection?
+
## Weighting strategy
+
+
# check incompatible weighting strategy
+
if params.weighting_strategy.override in ["stills", "external_deltapsi"]:
+
msg = (
+
'The "{}" weighting strategy is not compatible with ' "scan refinement"
+
).format(params.weighting_strategy.override)
+
raise DialsRefineConfigError(msg)
+
if params.outlier.algorithm in ("null", None):
outlier_detector = None
else:
-
if do_stills:
-
colnames = ["x_resid", "y_resid"]
-
params.outlier.block_width = None
-
else:
-
colnames = ["x_resid", "y_resid", "phi_resid"]
+
colnames = ["x_resid", "y_resid", "phi_resid"]
from dials.algorithms.refinement.outlier_detection import (
CentroidOutlierFactory,
)
@@ -338,36 +415,87 @@
Source code for dials.algorithms.refinement.reflection_manager
params, colnames
)
- # override default weighting strategy?
- weighting_strategy = None
- if params.weighting_strategy.override == "statistical":
- from dials.algorithms.refinement.weighting_strategies import (
- StatisticalWeightingStrategy,
- )
+ weighting_strategy = ReflectionManagerFactory.get_weighting_strategy_override(
+ params
+ )
- weighting_strategy = StatisticalWeightingStrategy()
- elif params.weighting_strategy.override == "stills":
- from dials.algorithms.refinement.weighting_strategies import (
- StillsWeightingStrategy,
- )
+ return refman(
+ reflections=reflections,
+ experiments=experiments,
+ nref_per_degree=params.reflections_per_degree,
+ max_sample_size=params.maximum_sample_size,
+ min_sample_size=params.minimum_sample_size,
+ close_to_spindle_cutoff=params.close_to_spindle_cutoff,
+ scan_margin=params.scan_margin,
+ outlier_detector=outlier_detector,
+ weighting_strategy_override=weighting_strategy,
+ )
-
weighting_strategy = StillsWeightingStrategy(
-
params.weighting_strategy.delpsi_constant
+
+
+
[docs]
+
@staticmethod
+
def laue_manager(
+
experiments: ExperimentList,
+
reflections: flex.reflection_table,
+
params: libtbx.phil.scope_extract,
+
) -> LaueReflectionManager:
+
+
all_tof_experiments = False
+
for expt in 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 refine ToF and non-ToF experiments at the same time"
+
)
+
+
if all_tof_experiments:
+
refman = TOFReflectionManager
+
else:
+
refman = LaueReflectionManager
+
+
## Outlier detection
+
if params.outlier.algorithm in ("auto", libtbx.Auto):
+
params.outlier.algorithm = "mcd"
+
if params.outlier.sauter_poon.px_sz is libtbx.Auto:
+
# get this from the first panel of the first detector
+
params.outlier.sauter_poon.px_sz = experiments.detectors()[0][
+
0
+
].get_pixel_size()
+
+
if params.outlier.algorithm in ("null", None):
+
outlier_detector = None
+
else:
+
colnames = ["x_resid", "y_resid"]
+
params.outlier.block_width = None
+
from dials.algorithms.refinement.outlier_detection import (
+
CentroidOutlierFactory,
)
-
elif params.weighting_strategy.override == "external_deltapsi":
-
from dials.algorithms.refinement.weighting_strategies import (
-
ExternalDelPsiWeightingStrategy,
+
+
outlier_detector = CentroidOutlierFactory.from_parameters_and_colnames(
+
params, colnames
)
-
weighting_strategy = ExternalDelPsiWeightingStrategy()
+
## Weighting strategy
+
+
if params.weighting_strategy.override == "statistical":
+
params.weighting_strategy.override = "statistical_laue"
elif params.weighting_strategy.override == "constant":
-
from dials.algorithms.refinement.weighting_strategies import (
-
ConstantWeightingStrategy,
-
)
+
params.weighting_strategy.override = "constant_laue"
+
+
if params.weighting_strategy.override is not None:
+
if params.weighting_strategy.override not in [
+
"constant_laue",
+
"statistical_laue",
+
]:
+
raise ValueError(
+
f"{params.weighting_strategy.override} not compatible with Laue data"
+
)
-
weighting_strategy = ConstantWeightingStrategy(
-
*params.weighting_strategy.constants, stills=do_stills
-
)
+
weighting_strategy = ReflectionManagerFactory.get_weighting_strategy_override(
+
params
+
)
return refman(
reflections=reflections,
@@ -379,7 +507,49 @@
Source code for dials.algorithms.refinement.reflection_manager
scan_margin=params.scan_margin,
outlier_detector=outlier_detector,
weighting_strategy_override=weighting_strategy,
+ wavelength_weight=params.weighting_strategy.wavelength_weight,
)
+
+
+
+
[docs]
+
@staticmethod
+
def get_weighting_strategy_override(
+
params: libtbx.phil.scope_extract,
+
) -> weighting_strategies.StatisticalWeightingStrategy | weighting_strategies.ConstantWeightingStrategy:
+
+
if params.weighting_strategy.override == "statistical":
+
return weighting_strategies.StatisticalWeightingStrategy()
+
+
elif params.weighting_strategy.override == "stills":
+
return weighting_strategies.StillsWeightingStrategy(
+
params.weighting_strategy.delpsi_constant
+
)
+
+
elif params.weighting_strategy.override == "external_deltapsi":
+
return weighting_strategies.ExternalDelPsiWeightingStrategy()
+
+
elif params.weighting_strategy.override == "constant":
+
return weighting_strategies.ConstantWeightingStrategy(
+
*params.weighting_strategy.constants
+
)
+
+
elif params.weighting_strategy.override == "constant_stills":
+
return weighting_strategies.ConstantStillsWeightingStrategy(
+
*params.weighting_strategy.constants
+
)
+
+
elif params.weighting_strategy.override == "statistical_laue":
+
return weighting_strategies.LaueStatisticalWeightingStrategy(
+
params.weighting_strategy.wavelength_weight,
+
)
+
+
elif params.weighting_strategy.override == "constant_laue":
+
return weighting_strategies.LaueMixedWeightingStrategy(
+
params.weighting_strategy.wavelength_weight,
+
)
+
+
return None
@@ -680,7 +850,11 @@
Source code for dials.algorithms.refinement.reflection_manager
nrefs
= sample_size = len(isel)
# set sample size according to nref_per_degree (per experiment)
-
if exp.scan and self._nref_per_degree:
+
if (
+
exp.scan
+
and exp.scan.has_property("oscillation")
+
and self._nref_per_degree
+
):
sequence_range_rad = exp.scan.get_oscillation_range(deg=False)
width = abs(sequence_range_rad[1] - sequence_range_rad[0]) * RAD2DEG
if self._nref_per_degree is libtbx.Auto:
@@ -829,6 +1003,16 @@
Source code for dials.algorithms.refinement.reflection_manager
self._reflections = self._reflections.select(sel)
return self._reflections
+
+
+
+
[docs]
+
def update_residuals(self):
+
x_obs, y_obs, phi_obs = self._reflections["xyzobs.mm.value"].parts()
+
x_calc, y_calc, phi_calc = self._reflections["xyzcal.mm"].parts()
+
self._reflections["x_resid"] = x_calc - x_obs
+
self._reflections["y_resid"] = y_calc - y_obs
+
self._reflections["phi_resid"] = phi_calc - phi_obs
@@ -909,6 +1093,301 @@
Source code for dials.algorithms.refinement.reflection_manager
logger.info(dials.util.tabulate(rows, header) + "\n")