Skip to content

Commit

Permalink
Added more typehints for beam.py. Added empty PolychromaticBeam const…
Browse files Browse the repository at this point in the history
…ructor at the Python level. Fixed typo in Beam.from_dict.
  • Loading branch information
toastisme committed Aug 3, 2023
1 parent 1f3c257 commit 4312daf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/dxtbx/dxtbx_model_ext.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ from scitbx.array_family import shared as flex_shared
# Attempt to use the stub typing for flex-inheritance
from scitbx.array_family.flex import FlexPlain

from dxtbx_model_ext import Probe # type: ignore

# TypeVar for the set of Experiment models that can be joint-accepted
# - profile, imageset and scalingmodel are handled as 'object'
TExperimentModel = TypeVar(
Expand Down Expand Up @@ -113,6 +115,8 @@ class Beam(BeamBase):
@staticmethod
def from_dict(data: Dict) -> Beam: ...
def to_dict(self) -> Dict: ...
@staticmethod
def get_probe_from_name(name: str) -> Probe: ...

class PolychromaticBeam(Beam):
@overload
Expand Down
12 changes: 5 additions & 7 deletions src/dxtbx/model/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class BeamFactory:
@staticmethod
def from_phil(
params: libtbx.phil.scope_extract,
reference: Beam | PolychromaticBeam = None,
reference: Beam | PolychromaticBeam | None = None,
) -> Beam | PolychromaticBeam:
"""
Convert the phil parameters into a beam model
Expand Down Expand Up @@ -136,10 +136,8 @@ def from_dict(dict: dict, template: dict = None) -> Beam | PolychromaticBeam:
joint.update(dict)

# Create the model from the joint dictionary
if "probe" in joint:
joint["probe"] = joint["probe"]
else:
joint["probe"] = Beam.get_probe_name(Probe.xray)
if "probe" not in joint:
joint["probe"] = "x-ray"
if joint.get("__id__") == "polychromatic":
return PolychromaticBeam.from_dict(joint)

Expand Down Expand Up @@ -187,7 +185,7 @@ def make_polychromatic_beam(
polarization_fraction: float = 0.5,
flux: float = 0.0,
transmission: float = 1.0,
probe=Probe.xray,
probe: Probe = Probe.xray,
deg: bool = True,
) -> PolychromaticBeam:
return PolychromaticBeam(
Expand All @@ -214,7 +212,7 @@ def make_polarized_beam(
sigma_divergence: float = None,
flux: float = None,
transmission: float = None,
probe=Probe.xray,
probe: Probe = Probe.xray,
) -> Beam:
assert polarization
assert 0.0 <= polarization_fraction <= 1.0
Expand Down
1 change: 1 addition & 0 deletions src/dxtbx/model/boost_python/beam.cc
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ namespace dxtbx { namespace model { namespace boost_python {

class_<PolychromaticBeam, std::shared_ptr<PolychromaticBeam>, bases<Beam> >(
"PolychromaticBeam")
.def(init<const PolychromaticBeam &>())
.def("__init__",
make_constructor(
&make_PolychromaticBeam, default_call_policies(), (arg("direction"))))
Expand Down

0 comments on commit 4312daf

Please sign in to comment.