Source code for httk.atomistic.entries.moments
"""Serve structure site moments as Cartesian JSON values."""
from functools import cache
from typing import Any
from httk.core import PropertyDefinition
from httk.atomistic.entries.definitions import load_httk_definitions
__all__ = ["MOMENT_PROPERTY_KEYS", "moment_definitions", "moment_properties"]
[docs]
MOMENT_PROPERTY_KEYS: dict[str, str] = {"_httk_site_moments": "site_moments"}
@cache
[docs]
def moment_definitions() -> dict[str, PropertyDefinition]:
"""Load the vendored site-moment property definition.
:return: The definition keyed by ``_httk_site_moments``.
"""
return load_httk_definitions(MOMENT_PROPERTY_KEYS)
[docs]
def moment_properties(structure: Any) -> dict[str, Any]:
"""Project non-collinear site moments as Cartesian JSON values.
:param structure: The structure to project, or ``None`` for an empty entry.
:return: The ``_httk_site_moments`` value, or ``None`` when unavailable or collinear.
"""
values: dict[str, Any] = {name: None for name in MOMENT_PROPERTY_KEYS}
if structure is None:
return values
values["_httk_site_moments"] = structure.cartesian_site_moments_floats()
return values