aiida_cif2j.workflows.utils module¶
Utility functions for AiiDA CIF2J workflows.
- aiida_cif2j.workflows.utils.collinear_magnetic_moments(structure: MagneticStructureData) dict[str, float]¶
Build a signed, scalar initial-magnetic-moment dict, keyed by kind name.
Works around MagneticStructureData.is_collin_mag() (upstream) misclassifying antiparallel, same-axis (antiferromagnetic) structures as non-collinear: supplying this dict explicitly as initial_magnetic_moments bypasses that detection entirely.
For each kind, take kind.magmom (a cartesian 3-tuple; AttributeError if unset is treated as the zero vector, matching the defensive pattern already used by detect_magnetic_elements). The first non-zero moment encountered fixes a reference axis (its unit vector); every subsequent kind’s signed value is +magnitude if its moment has non-negative dot product with that axis, -magnitude otherwise.
Only ever called when the caller has already committed to SpinType.COLLINEAR; it never raises or warns on apparently non-collinear input (multiple unrelated axes) – it reports the sign relative to the first-encountered axis regardless. Re-validating genuine collinearity here would mean re-implementing a corrected is_collin_mag(), which is out of scope for a narrow workaround.
- Parameters:
structure (MagneticStructureData) – The structure to read per-kind magnetic moments from.
- Returns:
A signed scalar moment, in Bohr magnetons, for each kind name in structure. Suitable for passing as initial_magnetic_moments to *.get_builder_from_protocol.
- Return type:
dict[str, float]
- aiida_cif2j.workflows.utils.total_magnetization(structure: MagneticStructureData, moments: dict[str, float]) float¶
Compute QE’s SYSTEM tot_magnetization (net) from a signed per-kind moments.
Sums moments[site.kind_name] over every site (not every kind), so a kind occupied by several sites is automatically weighted by its atom count.
- Parameters:
structure (MagneticStructureData) – The structure whose sites are summed over.
moments (dict[str, float]) – A signed scalar moment for each kind name in structure, as returned by collinear_magnetic_moments (or an equivalent caller-supplied dict).
- Returns:
The net total magnetic moment of structure.
- Return type:
float
- aiida_cif2j.workflows.utils.validate_chemical_symbols(value: List | None, _) str | None¶
Validate a list of elements.