Skip to content

Commit

Permalink
Add Laue experiment type (cctbx#733)
Browse files Browse the repository at this point in the history
* Add Laue experiment type
  • Loading branch information
toastisme committed Jul 11, 2024
1 parent 5a09f9a commit 532c403
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 2 deletions.
1 change: 1 addition & 0 deletions newsfragments/733.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add Laue experiment type.
4 changes: 4 additions & 0 deletions src/dxtbx/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,10 @@ def all_tof(self):
"""Check if all the experiments are time-of-flight"""
return all(exp.get_type() == ExperimentType.TOF for exp in self)

def all_laue(self):
"""Check if all the experiments are Laue experiments"""
return all(exp.get_type() == ExperimentType.LAUE for exp in self)

def to_dict(self):
"""Serialize the experiment list to dictionary."""

Expand Down
3 changes: 2 additions & 1 deletion src/dxtbx/model/boost_python/experiment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ namespace dxtbx { namespace model { namespace boost_python {
enum_<ExperimentType>("ExperimentType")
.value("STILL", STILL)
.value("ROTATION", ROTATION)
.value("TOF", TOF);
.value("TOF", TOF)
.value("LAUE", LAUE);

class_<Experiment>("Experiment")
.def(init<std::shared_ptr<BeamBase>,
Expand Down
11 changes: 10 additions & 1 deletion src/dxtbx/model/experiment.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

namespace dxtbx { namespace model {

enum ExperimentType { ROTATION = 1, STILL = 2, TOF = 3 };
enum ExperimentType { ROTATION = 1, STILL = 2, TOF = 3, LAUE = 4 };

/**
* A class to represent what's in an experiment.
Expand Down Expand Up @@ -156,6 +156,15 @@ namespace dxtbx { namespace model {
if (scan_ && scan_->contains("time_of_flight")) {
return TOF;
}

if (beam_) {
dxtbx::model::BeamBase &beam_base_ref = *beam_;
PolychromaticBeam *beam = dynamic_cast<PolychromaticBeam *>(&beam_base_ref);
if (beam != nullptr) {
return LAUE;
}
}

if (!goniometer_ || !scan_ || scan_->is_still()) {
return STILL;
} else {
Expand Down
88 changes: 88 additions & 0 deletions tests/model/test_experiment_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from dxtbx.imageset import ImageSetFactory
from dxtbx.model import (
Beam,
BeamFactory,
Crystal,
Detector,
Experiment,
Expand All @@ -26,6 +27,11 @@
Scan,
ScanFactory,
)

try:
from ..dxtbx_model_ext import Probe
except ModuleNotFoundError:
from dxtbx_model_ext import Probe # type: ignore
from dxtbx.model.experiment_list import ExperimentListDict, ExperimentListFactory


Expand Down Expand Up @@ -786,10 +792,22 @@ def test_experiment_type():
# Specifically test the bug from dxtbx#4 triggered by ending on 0°
experiment.scan = Scan((1, 1800), (-90, 0.05))
assert experiment.get_type() == ExperimentType.ROTATION

experiment.beam = BeamFactory.make_polychromatic_beam(
direction=(0, 0, -1),
sample_to_source_distance=(100),
probe=Probe.xray,
wavelength_range=(1, 10),
)

assert experiment.get_type() == ExperimentType.LAUE

experiment.scan = ScanFactory.make_scan_from_properties(
(1, 10), properties={"time_of_flight": list(range(10))}
)
assert experiment.get_type() == ExperimentType.TOF

experiment.beam = Beam()
experiment.scan = ScanFactory.make_scan_from_properties(
(1, 10), properties={"other_property": list(range(10))}
)
Expand Down Expand Up @@ -1184,3 +1202,73 @@ def test_from_templates(dials_data):
assert len(expts) == 1
assert expts[0].imageset.get_template() == str(template)
assert len(expts[0].imageset) == 45


def test_experiment_list_all():
experiments = ExperimentList()
for i in range(3):
experiments.append(Experiment())

assert experiments.all_stills()
experiments[0].goniometer = Goniometer()
assert experiments.all_stills()
experiments[1].goniometer = Goniometer()
experiments[2].goniometer = Goniometer()
assert experiments.all_stills()

experiments[0].beam = BeamFactory.make_polychromatic_beam(
direction=(0, 0, -1),
sample_to_source_distance=(100),
probe=Probe.xray,
wavelength_range=(1, 10),
)
assert not experiments.all_stills()
experiments[1].beam = BeamFactory.make_polychromatic_beam(
direction=(0, 0, -1),
sample_to_source_distance=(100),
probe=Probe.xray,
wavelength_range=(1, 10),
)
experiments[2].beam = BeamFactory.make_polychromatic_beam(
direction=(0, 0, -1),
sample_to_source_distance=(100),
probe=Probe.xray,
wavelength_range=(1, 10),
)
assert experiments.all_laue()

experiments[0].beam = Beam()
assert not experiments.all_laue()
experiments[1].beam = Beam()
experiments[2].beam = Beam()
assert experiments.all_stills()

experiments[0].scan = Scan((1, 1000), (0, 0.05))
assert not experiments.all_stills()
experiments[1].scan = Scan((1, 1000), (0, 0.05))
experiments[2].scan = Scan((1, 1000), (0, 0.05))
assert experiments.all_rotations()

experiments[0].scan = ScanFactory.make_scan_from_properties(
(1, 10), properties={"time_of_flight": list(range(10))}
)
assert not experiments.all_rotations()
experiments[1].scan = ScanFactory.make_scan_from_properties(
(1, 10), properties={"time_of_flight": list(range(10))}
)
experiments[2].scan = ScanFactory.make_scan_from_properties(
(1, 10), properties={"time_of_flight": list(range(10))}
)
assert experiments.all_tof()

experiments[0].scan = ScanFactory.make_scan_from_properties(
(1, 10), properties={"other_property": list(range(10))}
)
assert not experiments.all_tof()
experiments[1].scan = ScanFactory.make_scan_from_properties(
(1, 10), properties={"other_property": list(range(10))}
)
experiments[2].scan = ScanFactory.make_scan_from_properties(
(1, 10), properties={"other_property": list(range(10))}
)
assert experiments.all_stills()

0 comments on commit 532c403

Please sign in to comment.