sample#
Import: ad_hoc_diffractometer.sample
A Sample bundles together everything that is specific to one crystal mounted on the diffractometer:
a name (also used as the dict key in AdHocDiffractometer.samples)
a Lattice (crystal structure → B matrix)
a ReflectionList (geometry-specific orienting reflections)
U and UB matrices (orientation, computed later)
- A SampleDict is a guarded ordered dict that:
only accepts Sample values (no None, no arbitrary objects)
prevents removing or replacing the currently active sample unless a different sample has first been selected as active
The diffractometer owns a SampleDict and keeps one sample active. All reflection operations via AdHocDiffractometer.add_reflection() target the active sample’s ReflectionList.
Typical usage:
g = psic()
g.sample # -> Sample(name='test', ...)
g.samples # -> SampleDict with 'test'
g.add_sample("silicon", Lattice(a=5.4310))
g.sample = "silicon" # set active sample by name
g.add_reflection("r1", hkl=(1,1,1), angles={...}) # -> silicon's reflections
Classes#
One crystal sample mounted on a diffractometer. |
|
Guarded ordered dict of Sample objects. |
Module Contents#
- class ad_hoc_diffractometer.sample.Sample(name: str, lattice: Lattice, reflections: ReflectionList, U: ndarray | None = None, UB: ndarray | None = None, parent=None)[source]#
Import:
ad_hoc_diffractometer.sample.SampleOne crystal sample mounted on a diffractometer.
- Parameters:
name (str) – Unique label, matching the key in
AdHocDiffractometer.samples.lattice (Lattice) – Crystal lattice; provides the B matrix.
reflections (ReflectionList) – Geometry-specific reflection collection. Must be constructed with the owning geometry’s stage names as
valid_stages.U (numpy.ndarray or None) – 3×3 crystal orientation matrix. None until computed.
UB (numpy.ndarray or None) – 3×3 UB = U @ B matrix. None until computed.
Notes
U and UB are set by the U/UB computation routines. They are stored here so that each sample carries its own orientation independently.
- U = None#
- UB = None#
- classmethod from_dict(d: dict, parent=None) Sample[source]#
Reconstruct a
Samplefrom a dict produced byto_dict().- Parameters:
d (dict) – Must contain
"name","lattice","reflections"."U"and"UB"are optional (defaultNone).parent (AdHocDiffractometer or None) – Geometry to attach as the parent back-reference.
- Return type:
- lattice#
- name#
- parent = None#
- reflections#
- class ad_hoc_diffractometer.sample.SampleDict(active_ref: list[str])[source]#
Import:
ad_hoc_diffractometer.sample.SampleDictGuarded ordered dict of Sample objects.
- Enforces two invariants:
Every value must be a Sample instance — no None, no arbitrary objects.
The currently active sample cannot be removed or replaced.
The active sample name is tracked via a reference to a one-element list
[active_name]shared with the owning AdHocDiffractometer, so changes to the active selection are always visible here.Direct reassignment of the underlying container (
g._samples = something) is blocked by making_samplesa read-only property on AdHocDiffractometer.