vibe-sketcherDocumentation

vibesketcher.document.diffraction_model

Powder patterns stored in a document: the diffraction_patterns records (#207).

A measured record keeps what vibesketcher.document.measured_patterns.read_measured() read: the SHA-256 and size of the original bytes, the stated axis, intensity unit and wavelength, the instrument fields and header lines exactly as given, and the points. The original bytes themselves are not kept; the digest names them.

A calculated record keeps a vibesketcher.document.diffraction.calculate() result of one periodic structure with that structure’s digest (structure_sha256). It is stale once the structure changes or is removed; stale records are listed as such and refused by the overlay and export writers (vibesketcher.document.diffraction_store). The structure reference is deliberately not required to resolve: removing a structure leaves its patterns stale rather than making the document invalid.

The records are additive: a document without patterns serialises as before.

Module Attributes

MAX_PATTERNS

Stored patterns one document may hold.

MAX_STORED_POINTS

Points one stored pattern may hold (the reader accepts more; storing refuses).

MAX_DOCUMENT_POINTS

Points all stored patterns of a document may hold together.

MAX_STORED_REFLECTIONS

Reflections one stored calculated pattern may hold.

Functions

check_patterns(patterns)

Refuse duplicate ids and more points than MAX_DOCUMENT_POINTS in all.

Classes

DiffractionPattern(*, id, kind[, label, ...])

A measured or calculated powder pattern stored in the document.

MeasuredSource(*, file_name, sha256, bytes, ...)

Provenance of a measured import, as read; nothing is inferred.

vibesketcher.document.diffraction_model.MAX_PATTERNS = 32

Stored patterns one document may hold.

vibesketcher.document.diffraction_model.MAX_STORED_POINTS = 200000

Points one stored pattern may hold (the reader accepts more; storing refuses).

vibesketcher.document.diffraction_model.MAX_DOCUMENT_POINTS = 1000000

Points all stored patterns of a document may hold together.

vibesketcher.document.diffraction_model.MAX_STORED_REFLECTIONS = 20000

Reflections one stored calculated pattern may hold.

class vibesketcher.document.diffraction_model.MeasuredSource(*, file_name, sha256, bytes, encoding, format, instrument=<factory>, sample=None, header=<factory>, columns=None)[source]

Bases: _Strict

Provenance of a measured import, as read; nothing is inferred.

Parameters:
  • file_name (Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=255, pattern=None, ascii_only=None)])

  • sha256 (Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=None, pattern=^[0-9a-f]{64}$, ascii_only=None)])

  • bytes (Annotated[int, Ge(ge=0)])

  • encoding (Literal['utf-8', 'latin-1'])

  • format (Literal['xy', 'csv'])

  • instrument (Annotated[dict[str, Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=500, pattern=None, ascii_only=None)]], MaxLen(max_length=64)])

  • sample (Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=500, pattern=None, ascii_only=None)] | None)

  • header (Annotated[list[Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=500, pattern=None, ascii_only=None)]], MaxLen(max_length=200)])

  • columns (Annotated[list[Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=80, pattern=None, ascii_only=None)]] | None, MaxLen(max_length=8)])

file_name: Annotated[str, StringConstraints(min_length=1, max_length=255)]
sha256: _Sha256
bytes: int
encoding: Literal['utf-8', 'latin-1']
format: Literal['xy', 'csv']
instrument: dict[str, Annotated[str, StringConstraints(max_length=500)]]
sample: _Line | None
header: list[_Line]
columns: list[Annotated[str, StringConstraints(max_length=80)]] | None
model_config = {'extra': 'forbid', 'populate_by_name': True, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class vibesketcher.document.diffraction_model.DiffractionPattern(*, id, kind, label=None, axis, intensity_unit, wavelength_angstrom=None, x=<factory>, intensity=<factory>, esd=None, measured=None, structure=None, structure_sha256=None, result=None, stored_at_revision)[source]

Bases: _Strict

A measured or calculated powder pattern stored in the document.

Parameters:
  • id (Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=None, pattern=^[A-Za-z][A-Za-z0-9_-]{0,63}$, ascii_only=None)])

  • kind (Literal['measured', 'calculated'])

  • label (Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=500, pattern=None, ascii_only=None)] | None)

  • axis (Literal['two_theta_deg', 'd_angstrom', 'q_inv_angstrom'])

  • intensity_unit (Literal['counts', 'counts_per_second', 'arbitrary', 'relative'])

  • wavelength_angstrom (Annotated[float | None, Gt(gt=0.01), Le(le=100), AllowInfNan(allow_inf_nan=False)])

  • x (Annotated[list[Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[AllowInfNan(allow_inf_nan=False)])]], MaxLen(max_length=200000)])

  • intensity (Annotated[list[Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[AllowInfNan(allow_inf_nan=False)])]], MaxLen(max_length=200000)])

  • esd (Annotated[list[Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[AllowInfNan(allow_inf_nan=False)])]] | None, MaxLen(max_length=200000)])

  • measured (MeasuredSource | None)

  • structure (Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=None, pattern=^[A-Za-z][A-Za-z0-9_-]{0,63}$, ascii_only=None)] | None)

  • structure_sha256 (Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=None, pattern=^[0-9a-f]{64}$, ascii_only=None)] | None)

  • result (dict[str, JsonValue] | None)

  • stored_at_revision (Annotated[int, Ge(ge=0)])

id: _Identifier
kind: Literal['measured', 'calculated']
label: _Line | None
axis: PatternAxis
intensity_unit: Literal['counts', 'counts_per_second', 'arbitrary', 'relative']
wavelength_angstrom: float | None
x: list[_Finite]
intensity: list[_Finite]
esd: list[_Finite] | None
measured: MeasuredSource | None
structure: _Identifier | None
structure_sha256: _Sha256 | None
result: dict[str, JsonValue] | None
stored_at_revision: int
model_config = {'extra': 'forbid', 'populate_by_name': True, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

vibesketcher.document.diffraction_model.check_patterns(patterns)[source]

Refuse duplicate ids and more points than MAX_DOCUMENT_POINTS in all.

Parameters:

patterns (list[DiffractionPattern])

Return type:

None