Source code for mag4.constants

"""Physical constants and shared data structures."""

from __future__ import annotations

from collections import namedtuple

#: Boltzmann constant in meV / K.
KB_MEV: float = 0.08617333262

#: Default tolerance (Å) for merging equivalent M–M distances into the same J shell.
DIST_EQUIV_TOL: float = 0.01


CrystalData = namedtuple(
    "CrystalData",
    [
        "cell",            # [a, b, c, alpha, beta, gamma]
        "all_species",     # list of groups; each group = list of [label, x, y, z, _, gid]
        "target_species",  # the magnetic group within all_species
        "nb_species",      # list of multiplicities per group
        "total_atoms",     # total atom count + 1 (legacy convention)
        "elements",        # list of element symbols, group order
        "lattice_matrix",  # 3x3 ndarray, columns = a, b, c (Cartesian)
        "lattice_vectors", # 3x3 ndarray, rows = a, b, c (Cartesian)
    ],
)


Dimer = namedtuple(
    "Dimer",
    ["idx_a", "idx_b", "label_a", "label_b", "distance", "coupling_name"],
)


FourStateConfig = namedtuple(
    "FourStateConfig",
    [
        "idx",            # unique sequential integer
        "coupling_name",  # e.g. "J1"
        "state_label",    # "uu", "dd", "ud", "du"
        "spin_vector",    # tuple of +1/-1 for all magnetic atoms
        "dimer",          # Dimer namedtuple
    ],
)


_config_counter: int = 0


[docs] def next_config_idx() -> int: """Monotonically increasing integer used to tag :class:`FourStateConfig`.""" global _config_counter _config_counter += 1 return _config_counter
[docs] def reset_config_counter() -> None: """Reset the global counter — useful when running several pipelines in one process.""" global _config_counter _config_counter = 0