Skip to content

Commit

Permalink
dials.import: individually select models from reference expt
Browse files Browse the repository at this point in the history
  • Loading branch information
dwpaley committed Aug 7, 2020
1 parent 3ceefdf commit 511a407
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 3 deletions.
27 changes: 24 additions & 3 deletions command_line/dials_import.py
Expand Up @@ -123,6 +123,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"
Expand Down Expand Up @@ -261,9 +279,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):
Expand Down
73 changes: 73 additions & 0 deletions test/command_line/test_import.py
Expand Up @@ -7,6 +7,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)
Expand Down

0 comments on commit 511a407

Please sign in to comment.