spinCIF¶
Read and write SpinForge's supported subset of the draft spinCIF format.
scif
¶
Write spin-symmetry-adapted magnetic structures as spinCIF (.scif) files.
Follows the draft spinCIF dictionary (COMCIFS/spinCIF, core_spin.dic).
A spinCIF file describes a magnetic structure under its spin space group
(SSG) instead of a magnetic space group: each symmetry operation carries an
independent spin-space operation (_space_group_symop_spin_operation.uvw)
next to its spatial part (.xyzt), and moments are given in an explicitly
defined spin basis (_atom_site_spin_moment.axis_u/v/w).
Conventions used by this writer:
- The spin basis is the orthonormal crystal-Cartesian frame x || a, z || c*
(y completing a right-handed set), declared via
_space_group_spin.transform_spinframe_P_abc(the unit vectors written as linear combinations of the lattice vectors; the tag every COMCIFS reference file uses, for interoperability with readers tuned to them). - The nontrivial SSG operations are written in the supercell setting of the
:class:
~spinforge.configuration.SpinSymmetryAdaptedStructure; the spin translation coset goes into the optional_space_group_symop_spin_latticeloop. - The trivial spin-only group is not listed as operations (per the spec);
it enters through
_space_group_spin.collinear_direction_xyz/_space_group_spin.coplanar_perp_uvw, filled from thespinspg.spin.SpinOnlyGroupthe structure was enumerated with. SpinCifWriter.from_structurepreserves constituent chemistry and accepts the explicitspin_rotationused for sampled moments, independently of an MSG object. The Structure'smagneticflag distinguishes an absent magnetic declaration from an explicitly zeromagmom.- The reader preserves separate constituent rows, including coincident rows with different moments. Occupancies and occupied-atom moments remain separate; a mean-site moment requires weighting constituent moments by occupancy once.
The dictionary is explicitly preliminary upstream ("all dictionary aspects
and file formats are subject to change"): the targeted revision is pinned as
:data:SPINCIF_REVISION and stamped into every written file, so keep this
writer aligned with https://github.com/COMCIFS/spinCIF when it evolves.
SPINCIF_REVISION
module-attribute
¶
Revision of the draft spinCIF dictionary this writer targets.
The upstream dictionary is preliminary and may change; bump this together with any format adjustments. The revision is stamped into every written file.
SpinCifReader
¶
SpinCifReader(text: str, *, symprec: float = 0.0001, mag_symprec: float | None = None, atol: float | None = None)
Read a spinCIF string written by :class:SpinCifWriter.
Attributes:
| Name | Type | Description |
|---|---|---|
operations, spin_lattice |
Rows of the |
|
sites |
|
|
site_occupancies |
Occupancy keyed by atom-site label, defaulting to one when absent. |
|
site_moment_subspaces |
Coefficient matrices from |
|
lattice |
:class: |
|
spin_basis |
Unit vectors of the declared spin basis as rows (Cartesian, in the
lattice's own frame); moments expand as |
|
collinear_direction_xyz, coplanar_perp_uvw |
The spin-only tag values, |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The spinCIF content. |
required |
symprec
|
float
|
Absolute fractional-position tolerance for expanding each constituent's
orbit. This also supplies the default for |
0.0001
|
mag_symprec
|
float | None
|
Absolute occupied-atom moment tolerance for consistency within an orbit.
Defaults to |
None
|
atol
|
float | None
|
Absolute tolerance for orthogonality of the normalized spin frame.
Defaults to |
None
|
collinear_direction_xyz
instance-attribute
¶
coplanar_perp_uvw
instance-attribute
¶
lattice
instance-attribute
¶
lattice = Lattice.from_parameters(*(float(block.data[f'_cell_length_{name}']) for name in 'abc'), *(float(block.data[f'_cell_angle_{name}']) for name in ('alpha', 'beta', 'gamma')))
operations
instance-attribute
¶
site_occupancies
instance-attribute
¶
site_occupancies = {label: float(occupancy) for label, occupancy in zip(labels, block.data.get('_atom_site_occupancy', ['1'] * len(labels)), strict=True)}
sites
instance-attribute
¶
sites = [(label, symbol, np.array([float(fx), float(fy), float(fz)]), moments.get(label, np.zeros(3)), int(multiplicity)) for label, symbol, fx, fy, fz, multiplicity in zip(*site_columns, strict=True)]
spin_basis
instance-attribute
¶
spin_basis = _read_spin_basis(block, text, np.array(self.lattice.matrix), atol=symprec if atol is None else atol)
spin_lattice
instance-attribute
¶
expanded_operations
¶
expanded_operations() -> list[SymmetryOperation]
Products of the spin-lattice and operation loops (the full listed group).
from_file
classmethod
¶
from_file(filename: str | PathLike[str], *, symprec: float = 0.0001, mag_symprec: float | None = None, atol: float | None = None) -> SpinCifReader
get_structure
¶
Expand the asymmetric unit into the full magnetic structure.
Each expanded constituent remains a separate row with its original
species and occupancy, including coincident rows with different moments.
magmom is the Cartesian occupied-atom vector in the read lattice's
frame. magnetic records the presence of a moment row, including an
explicit zero. No occupancy averaging or normalization is applied.
Raises if an orbit disagrees with its declared multiplicity, transforms inconsistently, or pymatgen cannot preserve a constituent's species and occupancy exactly.
SpinCifWriter
¶
SpinCifWriter(sas: SpinSymmetryAdaptedStructure, nssg: NontrivialSpinSpaceGroup, magnetic_moments: NDArrayFloat, *, spin_only_group: SpinOnlyGroup, spin_rotation: NDArrayFloat | None = None, data_name: str = 'spinforge', parent_space_group_type: SpaceGroupType | None = None, site_occupancies: Sequence[float] | NDArrayFloat | None = None, atol: float = 1e-05)
A pymatgen-style writer for spinCIF (draft COMCIFS core_spin.dic).
Mirrors :class:spinforge.mcif.MCifWriter: str(writer) returns the
spinCIF text and writer.write_file(path) writes it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sas
|
SpinSymmetryAdaptedStructure
|
Spin-symmetry-adapted structure providing the supercell and the
moment basis (used for the |
required |
nssg
|
NontrivialSpinSpaceGroup
|
The nontrivial spin space group the structure was generated from, in the primitive input-cell setting. |
required |
spin_only_group
|
SpinOnlyGroup
|
The trivial spin-only group the structure was enumerated with; its
type and axis fill |
required |
magnetic_moments
|
NDArrayFloat
|
Cartesian moments per occupied selected magnetic atom, shape
|
required |
spin_rotation
|
NDArrayFloat | None
|
Orthogonal 3 by 3 matrix taking intrinsic spins to spatial Cartesian
spins. Moments must already include this rotation, as |
None
|
site_occupancies
|
Sequence[float] | NDArrayFloat | None
|
Fractional occupancy per supercell site ( |
None
|
data_name
|
str
|
CIF data block name. |
'spinforge'
|
parent_space_group_type
|
SpaceGroupType | None
|
Parent (nonmagnetic) space-group type; written as
|
None
|
atol
|
float
|
Tolerance for spin-space and translation checks (coefficient
snapping, orthogonality) and absolute legacy occupancy comparisons.
Site matching uses the supercell's own symprec via
:meth: |
1e-05
|
from_oriented
classmethod
¶
from_oriented(sas: SpinSymmetryAdaptedStructure, nssg: NontrivialSpinSpaceGroup, structure: Structure, msg: MagneticSpaceSubgroup, *, spin_only_group: SpinOnlyGroup, data_name: str = 'spinforge', parent_space_group_type: SpaceGroupType | None = None, site_occupancies: Sequence[float] | NDArrayFloat | None = None, symprec: float = 0.0001, mag_symprec: float | None = None, atol: float = 1e-05) -> SpinCifWriter
Writer for one (structure, msg) pair from generate_oriented.
Takes the moments from the structure's magmom site property and
conjugates the spin parts of the SSG operations by the MSG rotation
msg.Q that generate_oriented applied to them.
from_structure
classmethod
¶
from_structure(sas: SpinSymmetryAdaptedStructure, nssg: NontrivialSpinSpaceGroup, structure: Structure, *, spin_only_group: SpinOnlyGroup, symprec: float, spin_rotation: NDArrayFloat | None = None, mag_symprec: float | None = None, data_name: str = 'spinforge', parent_space_group_type: SpaceGroupType | None = None, atol: float = 1e-05) -> SpinCifWriter
Write full chemistry from constituent rows matched to the SSA sites.
symprec bounds Cartesian position and lattice matching. Coincident
constituent rows share a physical site, and their selected moments must
agree within mag_symprec (defaulting to atol). The optional
boolean magnetic property defaults to true; false requires zero.
A mixed row applies its moment and flag to all constituents. Chemistry
and magnetic flags must agree exactly across each SSG orbit.
An explicit mag_symprec is an absolute moment tolerance for both
the SSA residual and spin-only-group checks. When omitted, these checks
retain the array constructor's moment-scale-relative atol policy.