diff --git a/hkl/configuration.py b/hkl/configuration.py index ab2e6310..163553b2 100644 --- a/hkl/configuration.py +++ b/hkl/configuration.py @@ -33,7 +33,6 @@ import datetime import json -import math import pathlib import typing from dataclasses import asdict @@ -215,25 +214,6 @@ def validate(self, dc_obj): _check_range(value, AX_MIN, AX_MAX, f"real-space axis {axis}") # do not validate 'flag' (not used in hklpy) - def find(self, sample): - """Find this reflection in the sample's reflections. Return None if not found.""" - - def equal(a, b): - return math.isclose(a, b, abs_tol=EQUAL_TOLERANCE) - - for sref in sample._sample.reflections_get(): - rdict = sample._get_reflection_dict(sref) - # fmt: off - matches = [ - equal(rdict["reflection"][axis], self.reflection[axis]) - for axis in self.reflection - ] + [ - equal(rdict["wavelength"], self.wavelength) - ] - # fmt: on - if False not in matches: - return sref - @dataclass class DCSample: @@ -295,9 +275,6 @@ def write(self, diffractometer): # temporarily, change the wavelength w0 = diffractometer.calc.wavelength w1 = rdict["wavelength"] - refl = reflection.find(sample) - if refl is not None: - sample.remove_reflection(refl) try: diffractometer.calc.wavelength = w1 r = sample.add_reflection(*args) @@ -568,6 +545,11 @@ def restore(self, data, clear=True, restore_constraints=True): If ``True`` (default), remove any previous configuration of the diffractometer and reset it to default values before restoring the configuration. + + If ``False``, sample reflections will be append with all reflections + included in the configuration data for that sample. Existing + reflections will not be changed. The user may need to edit the + list of reflections after ``restore(clear=False)``. restore_constraints *bool*: If ``True`` (default), restore any constraints provided. diff --git a/hkl/tests/test_restore_reflections.py b/hkl/tests/test_restore_reflections.py index 41de081d..7d4bd103 100644 --- a/hkl/tests/test_restore_reflections.py +++ b/hkl/tests/test_restore_reflections.py @@ -36,13 +36,14 @@ def test_issue289(e4cv): s_444 = silicon.add_reflection(4, 4, 4, (34, 134, 54, 64)) silicon.compute_UB(s_440, s_444) - assert len(main.reflections) == 2 - assert len(kryptonite.reflections) == 2 - assert len(silicon.reflections) == 2 - assert len(vibranium.reflections) == 2 + n_saved_reflections = 2 + assert len(main.reflections) == n_saved_reflections + assert len(kryptonite.reflections) == n_saved_reflections + assert len(silicon.reflections) == n_saved_reflections + assert len(vibranium.reflections) == n_saved_reflections # same test, using diffractometer sample dictionary now. for sample in e4cv.calc._samples.values(): - assert len(sample.reflections) == 2, f"{sample.name=}" + assert len(sample.reflections) == n_saved_reflections, f"{sample.name=}" assert len(e4cv.calc._samples) == 4 agent = DiffractometerConfiguration(e4cv) @@ -57,4 +58,4 @@ def test_issue289(e4cv): assert len(e4cv.calc._samples) == 4 for sample in e4cv.calc._samples.values(): - assert len(sample.reflections) == 2 + assert len(sample.reflections) == 2 * n_saved_reflections