diff --git a/command_line/dials_import.py b/command_line/dials_import.py index 7ac7a76004..bc4da492b5 100644 --- a/command_line/dials_import.py +++ b/command_line/dials_import.py @@ -126,6 +126,24 @@ def _pickle_load(fh): .help = "If True, assert the reference geometry is similar to" "the image geometry" + use_beam_reference = True + .type = bool + .expert_level = 2 + .help = "If True, the beam from reference_geometry will override " + "the beam from the image headers." + + use_gonio_reference = True + .type = bool + .expert_level = 2 + .help = "If True, the goniometer from reference_geometry will override " + "the goniometer from the image headers." + + use_detector_reference = True + .type = bool + .expert_level = 2 + .help = "If True, the detector from reference_geometry will override " + "the detector from the image headers." + allow_multiple_sequences = True .type = bool .help = "If False, raise an error if multiple sequences are found" @@ -264,9 +282,12 @@ def __call__(self, imageset): ), "Reference detector model does not match input detector model" # Set beam and detector - imageset.set_beam(self.reference.beam) - imageset.set_detector(self.reference.detector) - imageset.set_goniometer(self.reference.goniometer) + if self.params.input.use_beam_reference: + imageset.set_beam(self.reference.beam) + if self.params.input.use_detector_reference: + imageset.set_detector(self.reference.detector) + if self.params.input.use_gonio_reference: + imageset.set_goniometer(self.reference.goniometer) return imageset def load_reference_geometry(self, params): diff --git a/newsfragments/1371.feature b/newsfragments/1371.feature new file mode 100644 index 0000000000..25424d45e0 --- /dev/null +++ b/newsfragments/1371.feature @@ -0,0 +1,3 @@ +``dials.import``: When using ``reference_models=``, individual +components of the model can be excluded with ``use_beam_reference=``, +``use_gonio_reference=`` and ``use_detector_reference=``. diff --git a/test/command_line/test_import.py b/test/command_line/test_import.py index a2f282b437..17172f10ad 100644 --- a/test/command_line/test_import.py +++ b/test/command_line/test_import.py @@ -8,6 +8,79 @@ from dxtbx.serialize import load +@pytest.mark.parametrize("use_beam", ["True", "False"]) +@pytest.mark.parametrize("use_gonio", ["True", "False"]) +@pytest.mark.parametrize("use_detector", ["True", "False"]) +def test_reference_individual(dials_data, tmpdir, use_beam, use_gonio, use_detector): + + expected_beam = {"True": 3, "False": 0.9795} + expected_gonio = { + "True": (7, 8, 9, 4, 5, 6, 1, 2, 3), + "False": (1, 0, 0, 0, 1, 0, 0, 0, 1), + } + expected_detector = {"True": "Fake panel", "False": "Panel"} + + # Find the image files + image_files = dials_data("centroid_test_data").listdir("centroid*.cbf", sort=True) + + # Create an experiment with some faked geometry items + fake_phil = """ + geometry { + beam.wavelength = 3 + detector.panel.name = "Fake panel" + goniometer.fixed_rotation = 7,8,9,4,5,6,1,2,3 + } + """ + tmpdir.join("fake.phil").write(fake_phil) + fake_result = procrunner.run( + ["dials.import", "fake.phil", "output.experiments=fake_geometry.expt"] + + image_files, + working_directory=tmpdir, + ) + assert not fake_result.returncode and not fake_result.stderr + assert tmpdir.join("fake_geometry.expt").check(file=1) + + # Write an import phil file + import_phil = """ + input { + reference_geometry = fake_geometry.expt + check_reference_geometry = False + use_beam_reference = %s + use_gonio_reference = %s + use_detector_reference = %s + } + """ % ( + use_beam, + use_gonio, + use_detector, + ) + tmpdir.join("test_reference_individual.phil").write(import_phil) + + result = procrunner.run( + [ + "dials.import", + "test_reference_individual.phil", + "output.experiments=reference_geometry.expt", + ] + + image_files, + working_directory=tmpdir, + ) + assert not result.returncode and not result.stderr + assert tmpdir.join("reference_geometry.expt").check(file=1) + + experiments = load.experiment_list(tmpdir.join("reference_geometry.expt").strpath) + assert experiments[0].identifier != "" + imgset = experiments[0].imageset + + beam = imgset.get_beam() + goniometer = imgset.get_goniometer() + detector = imgset.get_detector() + + assert beam.get_wavelength() == expected_beam[use_beam] + assert goniometer.get_fixed_rotation() == expected_gonio[use_gonio] + assert detector[0].get_name() == expected_detector[use_detector] + + def test_multiple_sequence_import_fails_when_not_allowed(dials_data, tmpdir): # Find the image files image_files = dials_data("centroid_test_data").listdir("centroid*.cbf", sort=True)