Source code for httk.atomistic.models.sites.plain_view

"""
A view presenting any sites backend as a raw Nx3 tuple of reduced coordinates.
"""

from typing import Any, Self

from httk.core import unwrap

from httk.atomistic.models._vector_guards import to_float_tuples
from httk.atomistic.models.sites.backend import SitesBackend
from httk.atomistic.models.sites.like import SitesLike
from httk.atomistic.models.sites.view_base import SitesViewBase


[docs] class PlainSitesView(SitesViewBase, tuple): r""" A view presenting an underlying sites backend as a raw Nx3 matrix of floats. This view is a genuine tuple of reduced-coordinate rows (rendered to floats from the exact ``reduced_coords``), built eagerly and immutable. :param obj: The sites-like object to present. :param \**hints: Backend-selection hints. """ _backend: SitesBackend def __new__(cls, obj: SitesLike, **hints: Any) -> Self: if isinstance(obj, cls): return obj backend = cls._prepare_backend(obj, hints) instance = super().__new__(cls, to_float_tuples(backend.reduced_coords)) instance._backend = backend return instance def __init__(self, obj: SitesLike, **hints: Any) -> None: super().__init__()
[docs] def unwrap(self) -> Any: """Return the raw object behind the backend. :return: The unwrapped source object. """ return unwrap(self._backend)
[docs] def unview(self) -> tuple[tuple[float, ...], ...]: """Return the presented coordinates as a plain tuple. :return: The reduced-coordinate rows. """ # The view IS its presentation tuple; shed to a plain tuple (rows shared). return tuple(self)