httk.atomistic.models.cell¶
Submodules¶
- httk.atomistic.models.cell.api
- httk.atomistic.models.cell.backend
- httk.atomistic.models.cell.cell
- httk.atomistic.models.cell.like
- httk.atomistic.models.cell.numeric
- httk.atomistic.models.cell.numeric_view
- httk.atomistic.models.cell.params
- httk.atomistic.models.cell.params_view
- httk.atomistic.models.cell.plain
- httk.atomistic.models.cell.plain_view
- httk.atomistic.models.cell.record
- httk.atomistic.models.cell.view
- httk.atomistic.models.cell.view_base
Attributes¶
Classes¶
Abstract base class for the canonical cell interface. |
|
Abstract base class for all backends of cell data. |
|
A crystallographic cell: its basis, the 3x3 matrix of cell vectors, held exactly. |
|
A plain-numpy presentation of a |
|
A view presenting an underlying cell backend as a |
|
Backend for a cell backed by cell parameters |
|
A view presenting an underlying cell backend as cell parameters. |
|
Backend for a cell backed by a raw 3x3 list or tuple of numbers (or any 3x3 vector-like). |
|
A view presenting an underlying cell backend as the raw 3x3 basis matrix of floats. |
|
A view presenting an underlying cell backend as a |
|
Abstract base class for all views of cell data. |
Package Contents¶
- class httk.atomistic.models.cell.CellAPI[source]¶
Bases:
abc.ABCAbstract base class for the canonical cell interface.
It declares the exact accessors that every cell backend produces from its own native representation and every cell view builds its presentation from: the
basisof 3x3 lattice vectors (scale * unscaled_basis), the positivescale, and theunscaled_basis. All three are exact httk-core vectors; this is the single interchange format, with no pairwise conversion between backends.- property basis: httk.core.SurdVector¶
- Abstractmethod:
Return the scaled lattice vectors.
- property scale: httk.core.SurdScalar¶
- Abstractmethod:
Return the positive factor applied to
unscaled_basis.
- property unscaled_basis: httk.core.SurdVector¶
- Abstractmethod:
Return the lattice vectors before applying
scale.
- property precision: fractions.Fraction | None¶
How precisely the basis was stated, as an absolute length, or
Noneif unknown.A backend that knows its source’s precision overrides this; one that does not — a bare matrix of numbers with no provenance — inherits
None.- Returns:
The absolute basis precision, or
Nonewhen it is unknown.- Return type:
fractions.Fraction | None
- property periodicity: tuple[bool, bool, bool]¶
Which of the three basis rows is a genuine lattice translation.
A backend that knows its periodicity overrides this; one that does not inherit
(True, True, True). A cell described only by six lattice parameters or a bare matrix is interpreted as a fully periodic crystal.
- metric()[source]¶
Return the exact Gram matrix of the scaled basis.
- Returns:
The Gram matrix of the cell vectors.
- Return type:
- property lengths: tuple[httk.core.SurdScalar, Ellipsis]¶
Return exact lengths where representable, with a deterministic rational fallback otherwise.
- Returns:
The three cell-vector lengths.
- Return type:
tuple[httk.core.SurdScalar, Ellipsis]
- property angles: tuple[fractions.Fraction, Ellipsis]¶
Return
(alpha, beta, gamma)exactly where representable, with a deterministic rational fallback otherwise.- Returns:
The crystallographic angles in degrees.
- Return type:
tuple[fractions.Fraction, Ellipsis]
- property volume: httk.core.SurdScalar¶
Return the exact absolute determinant of the basis.
- Returns:
The cell volume.
- Raises:
ValueError – If the cell is not periodic in all three directions.
- Return type:
- class httk.atomistic.models.cell.CellBackend(backend, **hints)[source]¶
Bases:
httk.core.Backend[CellBackend],httk.atomistic.models.cell.api.CellAPIAbstract base class for all backends of cell data.
Concrete backends carry a native representation and produce the canonical 3x3
basisdeclared byCellAPIfrom it.- backend_classes: ClassVar[list[type[httk.core.Backend[Any]]]]¶
- class httk.atomistic.models.cell.Cell(basis, scale=1, precision=None, periodicity=None)[source]¶
Bases:
httk.atomistic.models.cell.backend.CellBackendA crystallographic cell: its basis, the 3x3 matrix of cell vectors, held exactly.
The lattice vectors are the rows of
basis. Internally a Cell factors that basis into a positiveSurdScalarscaletimes anunscaled_basis(aSurdVectorof shape(3, 3)), withbasis == scale * unscaled_basis. The split lets an overall length factor be carried symbolically: a hexagonal cell of lattice parameteraand ratioc/ais the exactunscaledrows(1, 0, 0),(-1/2, sqrt(3)/2, 0),(0, 0, c/a)scaled bya— so thesqrt(3)stays exact regardless ofa. A cell built from an absolute basis simply hasscale == 1.Numbers embed exactly: rationals (and rational-valued floats) stay rational, and a
SurdVectorbasis keeps its radicals. Derived quantities retain exact forms where the underlying operation stays in the supported exact fields, including the usual metric-rational crystallographic case:lengthsusesqrt_of()for rational squared row lengths when the rational radicand is a perfect square or stays below the deterministic small-radicand threshold,angles(degrees) use the exact reverse-Nivenacos_degrees()where possible,volumecomes from the exact determinant, andmetricis the exact Gram matrix, which may itself contain surds. For larger rational or irrational squared lengths,lengths/anglesfall back to a deterministic rational approximation (documented per accessor). Exact accessors return vector objects — render them with.to_floats()(nested plain-float lists, numpy-free),float(...)on scalars,numeric()(true numpy arrays), or a view of your choice.A cell also records its
periodicity, which defaults to periodic in all three directions. Where it is not, the basis stops being purely a lattice and becomes partly a coordinate frame: seeperiodicityfor what that means andperiodic_measurefor the quantity that replacesvolume.- Parameters:
basis (httk.core.VectorLike) – The three cell vectors, one per row.
scale (Any) – The positive factor separated from
basis.precision (Any) – The absolute precision carried from the source, if known.
periodicity (Any) – Flags identifying which basis rows are lattice translations.
- property scale: httk.core.SurdScalar¶
The overall (strictly positive) length factor.
- Returns:
The factor applied to
unscaled_basis.- Return type:
- property unscaled_basis: httk.core.SurdVector¶
The 3x3 cell vectors before applying
scale.- Returns:
The unscaled lattice vectors.
- Return type:
- property basis: httk.core.SurdVector¶
The 3x3 lattice vectors
scale * unscaled_basis.- Returns:
The scaled lattice vectors.
- Return type:
- property precision: fractions.Fraction | None¶
How precisely this basis was stated, as an absolute length, or
Noneif unknown.In the same units as the basis itself, so for ordinary crystallographic data it is an ångström. Derived from the source’s written digits and any stated uncertainty — a CIF cell edge of
5.6402(3)is precise to3e-4, not to the1e-4its four decimals alone would suggest.Nonemeans unknown, which is not the same as exact. It is what a cell built by hand or from a bare matrix reports.- Returns:
The absolute precision, or
Nonewhen it is unknown.- Return type:
fractions.Fraction | None
- property periodicity: tuple[bool, bool, bool]¶
Which of the three basis rows is a genuine lattice translation.
(True, True, True)— the default, and what every ordinary crystal is. A slab is(True, True, False), a nanowire has oneTrue, and an isolated molecule is(False, False, False).A row flagged
Falseis not a lattice vector. It is only a frame: it says what a fractional coordinate means along that direction, and nothing more. Coordinates there are unbounded — freely below 0 or above 1 — and are never wrapped into[0, 1). There is no vacuum and no padding involved, so making that row a unit vector simply means the coordinate along it is a length in the basis’s units.This is the same notion, in the same order, as OPTIMADE’s
dimension_types.
- property nperiodic_dimensions: int¶
How many of the three directions are periodic.
- Returns:
The number of periodic directions.
- Return type:
- numeric()[source]¶
Return a plain-numpy presentation of this cell.
- Returns:
The numpy-backed presentation.
- Raises:
ImportError – If numpy is unavailable.
- Return type:
- metric()[source]¶
Return the exact, potentially surd-valued Gram matrix
matrix * matrix^T.- Returns:
The Gram matrix of the cell vectors.
- Return type:
- property lengths: tuple[httk.core.SurdScalar, Ellipsis]¶
The lengths of the three cell vectors (the scaled row norms).
Exact via
sqrt_of()when the row’s squared length is a perfect-square rational or a rational with numerator times denominator at most10**18. Larger rational radicands and irrational squared lengths use a deterministic rational approximation at_FALLBACK_PREC.- Returns:
The three cell-vector lengths.
- Return type:
tuple[httk.core.SurdScalar, Ellipsis]
- property angles: tuple[fractions.Fraction, Ellipsis]¶
The cell angles
(alpha, beta, gamma)in degrees, as exactFractionvalues.Following the crystallographic convention,
alphais the angle between rowsbandc,betabetweenaandc, andgammabetweenaandb. Angles are scale-independent, so they are computed from the unscaled basis. The cosine is formed exactly in the surd field and reversed through the Niven table (acos_degrees()) for an exact answer; a non-Niven angle falls back to a deterministicacos()at_FALLBACK_PREC.- Returns:
(alpha, beta, gamma)in degrees.- Return type:
tuple[fractions.Fraction, Ellipsis]
- property volume: httk.core.SurdScalar¶
The cell volume, the exact absolute determinant of
basis.Defined only for a fully periodic cell, and raises
ValueErrorotherwise. For anything less, the determinant mixes real lattice vectors with frame vectors, so it is not a volume: it changes when a frame vector is rescaled, even though nothing about the material did. Any density or packing fraction derived from it would inherit that. Seeperiodic_measurefor the quantity that is defined.- Returns:
The absolute determinant of the basis.
- Raises:
ValueError – If the cell is not periodic in all three directions.
- Return type:
- property periodic_measure: httk.core.SurdScalar¶
The size of the repeating unit, whatever its dimension.
A volume for a crystal, an area for a slab, a length for a nanowire. For a fully non-periodic cell there is no repeating unit and this is the empty product,
1, which is dimensionless rather than a length of any kind.Exact in the crystallographic case. The 3D case is the determinant and needs no square root at all; the 2D and 1D cases take the same square root that
lengthsdoes, so they are exact whenever the squared measure is a rational with a small radicand and fall back to a deterministic rational approximation otherwise.- Returns:
The measure of the periodic sublattice.
- Return type:
- type httk.atomistic.models.cell.CellLike = httk.atomistic.models.cell.backend.CellBackend | httk.atomistic.models.cell.view_base.CellViewBase | httk.atomistic.models.cell.cell.Cell | httk.core.VectorLike[source]¶
- class httk.atomistic.models.cell.NumericCell(cell)[source]¶
A plain-numpy presentation of a
Cell.Where a
Cellholds its geometry exactly (aSurdVectorbasis, exactSurdScalarlengths/volume, exactFractionangles), aNumericCellmirrors that interface but returns plain numpy numbers — afloat64numpy.ndarrayfor every vector and a plainfloatfor every scalar — for callers who do not need exact arithmetic and just want numpy arrays.The presentation is numpy-backed, so constructing a
NumericCellrequires numpy (thehttk-atomistic[numpy]extra) and raisesImportErroreagerly when it is unavailable. The exact object is always one hop away viaexact.- Parameters:
cell (httk.atomistic.models.cell.like.CellLike) – The cell or cell-like object to present.
- property scale: float¶
The overall length factor.
- Returns:
The scale as a floating-point value.
- Return type:
- property precision: float | None¶
The cell precision, or
Noneif unknown.- Returns:
The absolute precision as a floating-point value.
- Return type:
float | None
- property periodicity: tuple[bool, bool, bool]¶
Which of the three basis rows is a genuine lattice translation.
- property nperiodic_dimensions: int¶
How many of the three directions are periodic.
- Returns:
The number of periodic directions.
- Return type:
- property unscaled_basis: httk.core.NumericVector¶
The 3x3 cell vectors before applying
scale.- Returns:
The unscaled lattice vectors as floating-point values.
- Return type:
- property basis: httk.core.NumericVector¶
The 3x3 lattice vectors
scale * unscaled_basis.- Returns:
The scaled lattice vectors as floating-point values.
- Return type:
- property lengths: httk.core.NumericVector¶
The three cell-vector lengths.
- Returns:
The lengths as floating-point values.
- Return type:
- property angles: httk.core.NumericVector¶
The cell angles
(alpha, beta, gamma)in degrees.- Returns:
The angles as floating-point values.
- Return type:
- property volume: float¶
The cell volume.
- Returns:
The volume as a floating-point value.
- Raises:
ValueError – If the exact cell is not periodic in all three directions.
- Return type:
- metric()[source]¶
The Gram matrix
basis * basis^T.- Returns:
The Gram matrix as floating-point values.
- Return type:
- property exact: httk.atomistic.models.cell.cell.Cell¶
The exact cell this presentation wraps.
- Returns:
The exact cell.
- Return type:
- class httk.atomistic.models.cell.CellNumericView(obj, **hints)[source]¶
Bases:
httk.atomistic.models.cell.view_base.CellViewBase,httk.atomistic.models.cell.numeric.NumericCellA view presenting an underlying cell backend as a
NumericCell.This view is a genuine
NumericCell, so it can be passed anywhere one is accepted. Its exactCellis built lazily from the backend on first access, preserving the scale/unscaled split. Like aNumericCellit requires numpy (raisingImportErrorotherwise).- Parameters:
obj (httk.atomistic.models.cell.like.CellLike) – The cell-like object to present.
**hints (Any) – Backend-selection hints.
- unwrap()[source]¶
Return the raw object behind the backend.
- Returns:
The unwrapped source object.
- Return type:
Any
- class httk.atomistic.models.cell.CellParams(obj, **hints)[source]¶
Bases:
httk.atomistic.models.cell.backend.CellBackendBackend for a cell backed by cell parameters
(a, b, c, alpha, beta, gamma).The native representation is a flat length-6 vector-like of the cell-vector lengths
a/b/cand the anglesalpha/beta/gammain degrees, stored as exactFractionvalues (parsed viaany_to_fraction()). The exactbasisis derived lazily and cached using the standard crystallographic orientation convention (first cell vector along x, second in the xy-plane); for the common Niven angles it is exact (radicals intact). Since parameters carry no separate length factor,scaleis the exact1andunscaled_basis == basis. Parameters carry neither orientation nor periodicity, so a cell → parameters → cell round-trip reproduces lengths and angles, and reproduces volume only for a fully periodic source. Reconstruction uses the fully periodic default and therefore discards any non-3D periodicity as well as the original orientation.unwrapreturns the original raw object.- Parameters:
obj (Any) – The six cell parameters in crystallographic order.
**hints (Any) – Backend-selection hints.
- property basis: httk.core.SurdVector¶
Return the basis derived from the stored parameters.
- Returns:
The standard-orientation cell vectors.
- Return type:
- property scale: httk.core.SurdScalar¶
Return the unit scale factor.
- Returns:
The factor applied to
unscaled_basis.- Return type:
- property unscaled_basis: httk.core.SurdVector¶
Return the parameter-derived basis before scaling.
- Returns:
The cell vectors.
- Return type:
- property lengths: tuple[httk.core.SurdScalar, Ellipsis]¶
Return the natively stored cell-vector lengths.
- Returns:
The exact stored
a,b, andclengths.- Return type:
tuple[httk.core.SurdScalar, Ellipsis]
- property angles: tuple[fractions.Fraction, Ellipsis]¶
Return the natively stored cell angles in degrees.
- Returns:
The exact stored
alpha,beta, andgammaangles.- Return type:
tuple[fractions.Fraction, Ellipsis]
- property params: tuple[fractions.Fraction, Ellipsis]¶
The stored
(a, b, c, alpha, beta, gamma)in degrees.- Returns:
The exact cell parameters.
- Return type:
tuple[fractions.Fraction, Ellipsis]
- class httk.atomistic.models.cell.CellParamsView(obj, **hints)[source]¶
Bases:
httk.atomistic.models.cell.view_base.CellViewBase,tupleA view presenting an underlying cell backend as cell parameters.
This view is a genuine flat 6-tuple
(a, b, c, alpha, beta, gamma)with the angles in degrees, built eagerly and immutable, with the elements also available as the named propertiesa/b/c/alpha/beta/gamma. Parameters carry no orientation, so converting a cell to parameters is lossy: reconstructing a cell from this view reproduces the lengths and angles, and reproduces volume only for a fully periodic source. The reconstruction inherits the fully periodic default, so this view discards the source periodicity as well as the original cell-vector orientation.- Parameters:
obj (httk.atomistic.models.cell.like.CellLike) – The cell-like object to present.
**hints (Any) – Backend-selection hints.
- property a: float¶
The length of the first cell vector.
- Returns:
The first vector length.
- Return type:
- property b: float¶
The length of the second cell vector.
- Returns:
The second vector length.
- Return type:
- property c: float¶
The length of the third cell vector.
- Returns:
The third vector length.
- Return type:
- property alpha: float¶
The angle between the second and third cell vectors, in degrees.
- Returns:
The alpha angle.
- Return type:
- property beta: float¶
The angle between the first and third cell vectors, in degrees.
- Returns:
The beta angle.
- Return type:
- property gamma: float¶
The angle between the first and second cell vectors, in degrees.
- Returns:
The gamma angle.
- Return type:
- class httk.atomistic.models.cell.PlainCell(obj, **hints)[source]¶
Bases:
httk.atomistic.models.cell.backend.CellBackendBackend for a cell backed by a raw 3x3 list or tuple of numbers (or any 3x3 vector-like).
The native representation is preserved verbatim (one cell vector per row); the exact
SurdVectorbasisis built lazily and cached. This representation carries no separate length factor, soscaleis the exact1andunscaled_basis == basis.unwrapreturns the original raw object.- Parameters:
obj (Any) – The raw 3x3 basis representation.
**hints (Any) – Backend-selection hints.
- property basis: httk.core.SurdVector¶
Return the raw basis in the canonical representation.
- Returns:
The cell vectors.
- Return type:
- property scale: httk.core.SurdScalar¶
Return the unit scale factor.
- Returns:
The factor applied to
unscaled_basis.- Return type:
- property unscaled_basis: httk.core.SurdVector¶
Return the basis before scaling.
- Returns:
The cell vectors.
- Return type:
- class httk.atomistic.models.cell.PlainCellView(obj, **hints)[source]¶
Bases:
httk.atomistic.models.cell.view_base.CellViewBase,tupleA view presenting an underlying cell backend as the raw 3x3 basis matrix of floats.
This view is a genuine tuple of three cell-vector rows (the scaled lattice vectors rendered to floats from the exact
basis), built eagerly and immutable.- Parameters:
obj (httk.atomistic.models.cell.like.CellLike) – The cell-like object to present.
**hints (Any) – Backend-selection hints.
- class httk.atomistic.models.cell.CellView(obj, **hints)[source]¶
Bases:
httk.atomistic.models.cell.view_base.CellViewBase,httk.atomistic.models.cell.cell.CellA view presenting an underlying cell backend as a
Cell.This view is a genuine
Cell, so it can be passed anywhere a Cell is accepted. Its state is built lazily on first access from the backend.- Parameters:
obj (httk.atomistic.models.cell.like.CellLike) – The cell-like object to present.
**hints (Any) – Backend-selection hints.
- unwrap()[source]¶
Return the raw object behind the backend.
- Returns:
The unwrapped source object.
- Return type:
Any
- class httk.atomistic.models.cell.CellViewBase[source]¶
Bases:
httk.core.View[httk.atomistic.models.cell.backend.CellBackend]Abstract base class for all views of cell data.