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#

Sample

One crystal sample mounted on a diffractometer.

SampleDict

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.Sample

One 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 Sample from a dict produced by to_dict().

Parameters:
  • d (dict) – Must contain "name", "lattice", "reflections". "U" and "UB" are optional (default None).

  • parent (AdHocDiffractometer or None) – Geometry to attach as the parent back-reference.

Return type:

Sample

lattice#
name#
parent = None#
reflections#
to_dict() dict[source]#

Return a JSON-serialisable dict representing this sample.

Returns:

Keys: "name" (str), "lattice" (lattice dict), "reflections" (reflection-list dict), "U" (3×3 list or None), "UB" (3×3 list or None).

Return type:

dict

class ad_hoc_diffractometer.sample.SampleDict(active_ref: list[str])[source]#

Import: ad_hoc_diffractometer.sample.SampleDict

Guarded ordered dict of Sample objects.

Enforces two invariants:
  1. Every value must be a Sample instance — no None, no arbitrary objects.

  2. 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 _samples a read-only property on AdHocDiffractometer.

_guard_active(name: str, action: str) None[source]#
static _guard_type(value: object) None[source]#
clear() None[source]#
items()[source]#
keys()[source]#
pop(name: str, *args) Sample[source]#
values()[source]#