httk.atomistic.models.formula¶
Submodules¶
- httk.atomistic.models.formula.anonymous
- httk.atomistic.models.formula.anonymous_string
- httk.atomistic.models.formula.anonymous_view
- httk.atomistic.models.formula.api
- httk.atomistic.models.formula.backend
- httk.atomistic.models.formula.composition
- httk.atomistic.models.formula.composition_view
- httk.atomistic.models.formula.diagnostics
- httk.atomistic.models.formula.formula
- httk.atomistic.models.formula.formula_string
- httk.atomistic.models.formula.formula_view
- httk.atomistic.models.formula.like
- httk.atomistic.models.formula.notation
- httk.atomistic.models.formula.plain
- httk.atomistic.models.formula.prototype
- httk.atomistic.models.formula.record
- httk.atomistic.models.formula.structure
- httk.atomistic.models.formula.view_base
Classes¶
Store a strictly canonical OPTIMADE anonymous chemical formula. |
|
Wrap a canonical anonymous formula held as a plain string. |
|
Present a complete composition as an eager canonical anonymous formula. |
|
Abstract base class for the canonical chemical-formula interface. |
|
Abstract base class for all backends of chemical-formula data. |
|
Store an immutable projected composition and its formula diagnostics. |
|
Present any chemical-formula backend as a lazy composition. |
|
Record a non-fatal issue encountered while projecting composition. |
|
Store a strictly canonical reduced chemical formula. |
|
Wrap a canonical reduced formula held as a plain string. |
|
Present a complete composition as an eager canonical reduced formula. |
|
Abstract base class for all views of chemical-formula data. |
Functions¶
|
Return the unbounded OPTIMADE anonymous symbol for a zero-based index. |
|
Parse a strictly canonical OPTIMADE anonymous chemical formula. |
|
Parse a strictly canonical reduced OPTIMADE chemical formula. |
|
Return the least common integer coefficients for exact elemental ratios. |
|
Render descending-sorted integer counts using OPTIMADE anonymous symbols. |
|
Render element symbols and reduced integer coefficients in the given order. |
|
Return canonical anonymous coefficients, or |
|
Return canonical reduced coefficients, or |
Package Contents¶
- class httk.atomistic.models.formula.AnonymousFormula(backend, **hints)[source]¶
Bases:
httk.atomistic.models.formula.backend.ChemicalFormulaBackend,strStore a strictly canonical OPTIMADE anonymous chemical formula.
- Parameters:
formula – The canonical anonymous formula text.
- property amounts: tuple[tuple[str, fractions.Fraction], Ellipsis]¶
Return the anonymous coefficients as exact amounts.
- class httk.atomistic.models.formula.AnonymousFormulaString(obj, **hints)[source]¶
Bases:
httk.atomistic.models.formula.backend.ChemicalFormulaBackendWrap a canonical anonymous formula held as a plain string.
- Parameters:
obj (str) – The canonical anonymous formula text.
**hints (Any) – Backend-selection hints.
- property amounts: tuple[tuple[str, fractions.Fraction], Ellipsis]¶
Return the anonymous coefficients as exact amounts.
- class httk.atomistic.models.formula.AnonymousFormulaView(obj, **hints)[source]¶
Bases:
httk.atomistic.models.formula.view_base.ChemicalFormulaViewBase,httk.atomistic.models.formula.anonymous.AnonymousFormulaPresent a complete composition as an eager canonical anonymous formula.
- Parameters:
obj (httk.atomistic.models.formula.like.ChemicalFormulaLike) – The chemical-formula-like object to present.
**hints (Any) – Backend-selection hints.
- property amounts¶
Return the presented amounts using anonymous labels.
- property uncertainties¶
Return the presented amount precisions using anonymous labels.
- property complete¶
Return whether the presented composition is complete.
- property exact¶
Return whether the presented amounts are exact.
- property normalized¶
Return whether the presented composition is normalized.
- property normalization_status¶
Return the presented composition’s normalization status.
- property diagnostics¶
Return diagnostics associated with the presented composition.
- property is_anonymous¶
Return whether this formula uses anonymous labels.
- class httk.atomistic.models.formula.ChemicalFormulaAPI[source]¶
Bases:
abc.ABCAbstract base class for the canonical chemical-formula interface.
The concrete defaults keep backends that do not have provenance for optional formula metadata interoperable without requiring them to implement every accessor.
- property amounts: tuple[tuple[str, fractions.Fraction], Ellipsis]¶
- Abstractmethod:
Ordered
(label, exact amount)pairs for this chemical formula.Labels are element symbols in alphabetical order unless
is_anonymous, in which case they are OPTIMADE anonymous symbols in canonical (descending-coefficient) order.
- property is_anonymous: bool¶
Whether the formula labels are OPTIMADE anonymous symbols.
A backend that carries anonymous notation overrides this; a backend without that distinction inherits
False.
- property uncertainties: tuple[tuple[str, fractions.Fraction | None], Ellipsis]¶
Per-amount absolute uncertainties, or
Nonewhere exactness is unstated.
- property normalization_status: str¶
The formula’s normalization status derived from exactness and normalization.
- property diagnostics: tuple[httk.atomistic.models.formula.diagnostics.CompositionDiagnostic, Ellipsis]¶
Non-fatal structured diagnostics associated with the formula.
- class httk.atomistic.models.formula.ChemicalFormulaBackend(backend, **hints)[source]¶
Bases:
httk.core.Backend[ChemicalFormulaBackend],httk.atomistic.models.formula.api.ChemicalFormulaAPIAbstract base class for all backends of chemical-formula data.
Concrete backends carry a native representation and produce the canonical chemical-formula accessors declared by
ChemicalFormulaAPIfrom it.- backend_classes: ClassVar[list[type[httk.core.Backend[Any]]]]¶
- class httk.atomistic.models.formula.Composition(amounts, uncertainties=None, complete=True, exact=None, normalized=True, normalization_status=None, diagnostics=())[source]¶
Bases:
httk.atomistic.models.formula.backend.ChemicalFormulaBackendStore an immutable projected composition and its formula diagnostics.
- Parameters:
amounts (collections.abc.Mapping[str, Any] | collections.abc.Iterable[tuple[str, Any]]) – The projected elemental amounts in symbol order.
uncertainties (collections.abc.Mapping[str, Any] | collections.abc.Iterable[tuple[str, Any]] | None) – The corresponding amount precisions, if known.
complete (bool) – Whether the projection contains no unknown elemental content.
exact (bool | None) – Whether all projected amounts are exact.
normalized (bool) – Whether all contributing probabilities and concentrations normalize.
normalization_status (str | None) – The combined normalization status.
diagnostics (collections.abc.Iterable[httk.atomistic.models.formula.diagnostics.CompositionDiagnostic]) – The non-fatal issues found during projection.
- amounts: tuple[tuple[str, fractions.Fraction], Ellipsis] = ()¶
Ordered
(label, exact amount)pairs for this chemical formula.Labels are element symbols in alphabetical order unless
is_anonymous, in which case they are OPTIMADE anonymous symbols in canonical (descending-coefficient) order.
- uncertainties: tuple[tuple[str, fractions.Fraction | None], Ellipsis] = ()¶
Per-amount absolute uncertainties, or
Nonewhere exactness is unstated.
- normalization_status: str = 'exact'¶
The formula’s normalization status derived from exactness and normalization.
- diagnostics: tuple[httk.atomistic.models.formula.diagnostics.CompositionDiagnostic, Ellipsis] = ()¶
Non-fatal structured diagnostics associated with the formula.
- property amount_mapping: collections.abc.Mapping[str, fractions.Fraction]¶
Return the projected amounts as a read-only mapping.
- property uncertainty_mapping: collections.abc.Mapping[str, fractions.Fraction | None]¶
Return the projected amount precisions as a read-only mapping.
- property elements_ratios: tuple[fractions.Fraction, Ellipsis]¶
Return the projected amounts normalized by their total.
- class httk.atomistic.models.formula.CompositionView(obj, **hints)[source]¶
Bases:
httk.atomistic.models.formula.view_base.ChemicalFormulaViewBase,httk.atomistic.models.formula.composition.CompositionPresent any chemical-formula backend as a lazy composition.
- Parameters:
obj (httk.atomistic.models.formula.like.ChemicalFormulaLike) – The chemical-formula-like object to present.
**hints (Any) – Backend-selection hints.
- property amounts: tuple[tuple[str, fractions.Fraction], Ellipsis]¶
Return the lazily materialized elemental amounts.
- property uncertainties: tuple[tuple[str, fractions.Fraction | None], Ellipsis]¶
Return the lazily materialized amount precisions.
- property diagnostics: tuple[httk.atomistic.models.formula.diagnostics.CompositionDiagnostic, Ellipsis]¶
Return diagnostics associated with the presented composition.
- unwrap()[source]¶
Return the raw object behind the backend.
- Returns:
The unwrapped source object.
- Return type:
Any
- class httk.atomistic.models.formula.CompositionDiagnostic[source]¶
Record a non-fatal issue encountered while projecting composition.
- Parameters:
code – The stable diagnostic code.
message – The human-readable diagnostic message.
subject – The composition subject involved, if any.
total – The calculated total, if applicable.
width – The precision width used for the diagnostic, if applicable.
- total: fractions.Fraction | None = None¶
- width: fractions.Fraction | None = None¶
- class httk.atomistic.models.formula.ChemicalFormula(backend, **hints)[source]¶
Bases:
httk.atomistic.models.formula.backend.ChemicalFormulaBackend,strStore a strictly canonical reduced chemical formula.
- Parameters:
formula – The alphabetical formula text with greatest common divisor one.
- property amounts: tuple[tuple[str, fractions.Fraction], Ellipsis]¶
Return the formula coefficients as exact amounts.
- class httk.atomistic.models.formula.FormulaString(obj, **hints)[source]¶
Bases:
httk.atomistic.models.formula.backend.ChemicalFormulaBackendWrap a canonical reduced formula held as a plain string.
- Parameters:
obj (str) – The canonical reduced formula text.
**hints (Any) – Backend-selection hints.
- property amounts: tuple[tuple[str, fractions.Fraction], Ellipsis]¶
Return the formula coefficients as exact amounts.
- class httk.atomistic.models.formula.ChemicalFormulaView(obj, **hints)[source]¶
Bases:
httk.atomistic.models.formula.view_base.ChemicalFormulaViewBase,httk.atomistic.models.formula.formula.ChemicalFormulaPresent a complete composition as an eager canonical reduced formula.
- Parameters:
obj (httk.atomistic.models.formula.like.ChemicalFormulaLike) – The chemical-formula-like object to present.
**hints (Any) – Backend-selection hints.
- property amounts¶
Return the presented elemental amounts.
- property uncertainties¶
Return the presented amount precisions.
- property complete¶
Return whether the presented composition is complete.
- property exact¶
Return whether the presented amounts are exact.
- property normalized¶
Return whether the presented composition is normalized.
- property normalization_status¶
Return the presented composition’s normalization status.
- property diagnostics¶
Return diagnostics associated with the presented composition.
- property is_anonymous¶
Return whether this formula uses anonymous labels.
- httk.atomistic.models.formula.anonymous_symbol(index)[source]¶
Return the unbounded OPTIMADE anonymous symbol for a zero-based index.
- Parameters:
index (int) – The non-negative zero-based symbol index.
- Returns:
The generated anonymous symbol.
- Raises:
ValueError – If
indexis not a non-negative integer.- Return type:
- httk.atomistic.models.formula.parse_anonymous_formula(text)[source]¶
Parse a strictly canonical OPTIMADE anonymous chemical formula.
- httk.atomistic.models.formula.parse_reduced_formula(text)[source]¶
Parse a strictly canonical reduced OPTIMADE chemical formula.
The reduced and anonymous grammars are disjoint by construction: an anonymous label may have an arbitrary lowercase tail, while an element symbol has at most one.
- httk.atomistic.models.formula.reduced_coefficients(ratios)[source]¶
Return the least common integer coefficients for exact elemental ratios.
- Parameters:
ratios (collections.abc.Sequence[fractions.Fraction]) – The exact elemental ratios in their desired output order.
- Returns:
The reduced integer coefficients, or
Nonefor an empty sequence.- Return type:
- httk.atomistic.models.formula.render_anonymous(counts)[source]¶
Render descending-sorted integer counts using OPTIMADE anonymous symbols.
- Parameters:
counts (collections.abc.Sequence[int]) – The coefficients in descending order.
- Returns:
The canonical anonymous formula text.
- Return type:
- httk.atomistic.models.formula.render_reduced(coefficients)[source]¶
Render element symbols and reduced integer coefficients in the given order.
- Parameters:
coefficients (collections.abc.Sequence[tuple[str, int]]) – The element and coefficient pairs to render.
- Returns:
The canonical reduced formula text.
- Return type:
- httk.atomistic.models.formula.try_parse_anonymous(text)[source]¶
Return canonical anonymous coefficients, or
Nonewhen text is not one.
- httk.atomistic.models.formula.try_parse_reduced(text)[source]¶
Return canonical reduced coefficients, or
Nonewhen text is not one.
- class httk.atomistic.models.formula.ChemicalFormulaViewBase[source]¶
Bases:
httk.core.View[httk.atomistic.models.formula.backend.ChemicalFormulaBackend]Abstract base class for all views of chemical-formula data.