Spin potential
NEP_Spin extends the NEP4 formalism to a local
energy surface that depends on both atomic positions and Cartesian spin
vectors. The total energy is the only learned scalar output. Atomic forces,
virials, magnetic forces, and spin torques are derivatives of this same energy
and are not produced by independent response networks.
The current format uses nep, format_version 1, and model nep_spin
with spin_version 1 and named parameter and scaler blocks. It uses the
order/compression (O/C) descriptor described below. An optional zbl field adds a spin-independent
universal ZBL term. Flexible ZBL (zbl 0 0) is not supported.
spin_version identifies the descriptor and parameter-layout
contract, independently of the file syntax version and spin_order.
Every spin_cutoff value must be positive and no larger than the ordinary NEP radial cutoff. This constraint applies to both training input and model files; different spin cutoffs per atom type are supported within this bound.
Energy model
For atom \(i\), the ordinary structural descriptor \(\boldsymbol{q}^{i,\mathrm{str}}\) is concatenated with a magnetic descriptor \(\boldsymbol{q}^{i,\mathrm{spin}}\):
After componentwise scaling, this vector enters the same one-hidden-layer, element-dependent neural network used by ordinary NEP4. The total energy is
where \(\boldsymbol{r}_i\) is the position, \(\boldsymbol{s}_i\) is a
Cartesian magnetic-moment vector in Bohr magnetons (muB), \(Z_i\) denotes the atom type, and
\(E^0_{Z_i}\) is a fitted per-type energy baseline. The ZBL term is present
when ZBL is enabled and contains no spin dependence. The reference energies
use the shared energy_reference convention.
This architecture allows the nonlinear network to combine structural and
magnetic coordinates. Therefore, spin_order describes the hierarchy of
primitive magnetic contractions supplied to the network; it is not the body
order of the final energy.
Spin3 radial channels
Let
be the minimum-image unit vector from center atom \(i\) to neighbor \(j\). For each compressed radial channel \(c=1,\ldots,C\), Spin3 forms the type-dependent edge weight
where
and
Thus spin_compress controls a shared latent radial rank rather than selecting individual Hamiltonian terms. All contraction families use the same \(C\) radial channels.
Canonical edge-moment bank
Spin3 organizes each neighbor edge into a canonical collection of scalar, vector, rank-2, and product-tensor objects. Define the symmetric traceless product
The implementation stores this tensor in five orthonormal components,
For each center \(i\) and channel \(c\), the neighbor reduction builds the following moment bank:
The last two objects have 15 and 3 components, respectively. Together with the scalar and vector entries above, each radial channel has a 38-component canonical moment state. Most density-derived descriptor coordinates are scalar contractions of this bank; the moments themselves are not passed directly to the neural network. Direct one-edge sums and same-edge channel-pair accumulators are reduced separately.
O/C contraction hierarchy
The hierarchy is nested: at fixed \(C\), every order-1 coordinate is a prefix of order 2, and every order-2 coordinate is a prefix of order 3. Representative exact contractions are listed below.
Order 1 contains local and direct-edge magnetic information such as
When joint spin–orbit channels with \(l_\mathrm{max}=2\) are enabled, order 1 also contains the rank-2 contractions
and
Order 2 adds edge powers, density norms, and correlations between two magnetic density legs. Examples include
and
For a radial-channel pair \(c\leq d\), Spin3 keeps same-edge and distinct-neighbor correlations separately:
This separation prevents a two-density contraction from conflating repeated use of one neighbor edge with a correlation between distinct neighbors.
Spin3 additionally resolves the distinct-neighbor exchange by spatial angular rank. Define
For every \(c\leq d\), the new coordinates are
The subtraction removes the repeated-edge contribution, while the \(3/2\) factor compensates the norm of the rank-2 STF representation. These blocks distinguish angular exchange environments that have the same scalar distinct-neighbor contraction.
Joint spin–orbit contractions use four learned radial-leg mixing matrices \(A^{(\alpha)}\in\mathbb{R}^{C\times C}\). For any moment family \(\boldsymbol{\rho}\), a projected leg is
This permits non-collinear contraction legs while retaining one shared radial seam. Representative order-2 joint invariants are
and
where \([\mathcal{A},\mathcal{B}]=\mathcal{A}\mathcal{B}-
\mathcal{B}\mathcal{A}\) and axial maps the resulting antisymmetric tensor
to an axial vector.
Order 3 adds dot-gated and triple-density contractions. Its direct-edge member is
while representative joint contractions include scalar triple products such as
These coordinates supply a symmetry-respecting polynomial basis to a nonlinear energy model. They do not assign a fixed exchange, DMI, anisotropy, or other spin-Hamiltonian coefficient to any individual descriptor channel.
Symmetries
All Spin3 descriptor coordinates are even under global time reversal,
With spin_soc 0, the spatial vectors and spin vectors may be rotated
independently and the descriptor is invariant under both rotations. With
spin_soc 1, the extra channels are invariant under a joint orthogonal
transformation of the lattice vectors and axial spin vectors,
The spin_type selection defines independent spin coordinates and magnetic descriptor centers. All neighbor types enter geometric moment sums within the spin cutoff. The reader sets excluded types’ effective spins to zero and ignores their magnetic-force labels, so their contributions to moments containing neighbor spins vanish while geometric contributions remain. Original energy and atomic-force labels are retained; input files are unchanged.
Model dimensions
Let \(P=C(C+1)/2\), \(I_X\) be 1 when condition \(X\) is true and 0 otherwise, and define
For \(L=l_\mathrm{max}\) and \(S=\texttt{spin\_soc}\), the order-1 Spin3 dimension is
The order-2 increment is
and the order-3 increment is
Therefore \(D_2=D_1+\Delta D_2\) and
\(D_3=D_2+\Delta D_3\). For the common \(L=2\), spin_soc 1 shape,
O2-C2 has 43 magnetic coordinates and O3-C2 has 55. The implementation limits
the magnetic part to 96 coordinates and requires the combined structural and
magnetic dimension to satisfy \(D_\mathrm{str}+D_\mathrm{spin}\leq199\).
With the ordinary structural defaults, \(D_\mathrm{str}=42\); the default
O3-C2-L2-SOC1 shape therefore gives \(42+55=97\) total coordinates.
The trainable magnetic descriptor parameters comprise \(9C N_\mathrm{typ}^2\) radial coefficients and, for Spin3, \(4C^2\) radial-leg mixing coefficients. These are optimized together with the neural-network parameters by SNES.
Descriptor scaling
Structural coordinates retain the ordinary inverse-range scaler. Magnetic coordinates use \(1/\max(\operatorname{RMS}(q),\operatorname{range}(q),1)\), without centering. Their gain is therefore never larger than one, including for a constant or initially unresolved magnetic channel.
Fresh training computes scaling from ordinary training structures using a fixed, non-degenerate reference parameter vector, independent of the SNES search mean and RNG. Nonconstant spin projection matrices keep descriptor channels distinct. Response-only frames do not enter this calculation. Prediction, restart, and explicit scaler import reuse the stored normalization instead.
Restart behavior
Spin restart restores the scaler from the matching nep.txt. See
import_q_scaler for automatic restoration and
fresh scaler-only import. The two files must have compatible architecture and
element order, and the scaler must be finite and positive.
nep.restart stores the search distribution and energy_reference in the
shared restart format, while nep.txt stores a selected candidate model.
The search mean and that candidate need not predict the same values. Restart
does not rescale parameters or substitute the candidate for the search mean.
A restart begins a new requested generation segment and resets RNG initialization. The restart file does not store global generation progress; it is not an exact replay of an uninterrupted trajectory.
Energy derivatives
The atomic force and the unmasked magnetic derivative are defined by
For an atom type enabled by spin_type, the public magnetic force is \(\boldsymbol{M}_k=\widetilde{\boldsymbol{M}}_k\). Excluded types have no independent spin coordinate; their public magnetic force is zero by convention. They still receive atomic forces from the positional derivative of the full energy, including magnetic geometric environments.
Writing \(q^i_\nu\) for either a structural or magnetic descriptor component, the chain rule gives
The implementation first evaluates \(\partial U_i/\partial q^i_\nu\) through the neural network and then applies the analytical vector–Jacobian product of every Spin3 contraction, moment reduction, and radial basis function. The same position derivative produces the full per-atom virial. No finite-difference force path is used.
The spin torque used for training diagnostics is
ZBL contributes to energy, atomic force, and virial but not to magnetic force or torque because it is spin independent.
Spin loss terms
Spin training augments the ordinary NEP loss with magnetic-force and torque RMSE terms,
where \(N_\mathrm{m}\) counts labeled active spins and \(N_\mathrm{tau}\) counts only those with \(|\boldsymbol{s}_i|^2 > 10^{-20}\,\mu_\mathrm{B}^2\),
The magnetic-force loss always includes all three Cartesian components and
includes zero spins. Both the torque-error sum and its count exclude spins at
or below the squared-magnitude threshold, evaluated in double precision.
To supervise only spin rotation, set lambda_m 0 and a positive lambda_tau.
For nonzero spins, the squared torque error equals the squared transverse magnetic-force
error multiplied by \(|\boldsymbol{s}_i|^2\).
Grouped magnetic response
For a grouped rotation path with coordinate \(\theta\), the response generator evaluated for frame \(n\) is
The grouped response loss first centers \(G_n\) within each group. Each
group contributes equally to the centered-curve Huber loss, independent of its
number of scan points. Each group’s uncentered target-response RMS, floored
at \(10^{-6}\), normalizes its shape term and a second Huber term comparing
group means; the mean term is multiplied by 0.25. response_coordinate
defines the path derivative but does not add a separate reliability weight.
The group coordinate is explicit because Cartesian spin snapshots alone do
not determine their path ordering or parameterization. The trainer sorts each
group and derives
\(\partial\boldsymbol{s}/\partial\theta\) from the final constrained-DFT
spins with second-order, three-point nonuniform weights applied to sphere-log
angular displacements and separate magnitude differences. This preserves
longitudinal moment relaxation without injecting the radial chord error of
Cartesian interpolation into constant-length rotations. Stencils must resolve
angular separations below pi. Atom types excluded by spin_type are
masked from the derived tangent. At zero moment, the tangent uses Cartesian
differences. Constant-rate great-circle rotations are differentiated exactly
apart from floating-point rounding; other paths retain the finite-stencil
approximation. Antipodal samples require intermediate frames. Input labels
and group metadata are specified in response.xyz; the loss weight is
set by lambda_spin_response.
Spin3 uses the shared SNES lifecycle: generation zero prepares training scalers and uses regularization-only fitness. Physical losses are evaluated from the next generation. All magnetic descriptor orders participate throughout training.
Model formats and input
Header in |
Training mode |
Description |
|---|---|---|
|
|
Current block format with |
See spin_version and the neighboring spin_* keyword
pages for descriptor configuration. See train.xyz and test.xyz for ordinary
training labels and response.xyz for grouped-response input.
Training specialization
With nep_compile 1, training specializes both the structural NEP kernels
and the magnetic density, descriptor contraction and force kernels for the
selected Spin layout. The magnetic kernels share their formulas with the
native path. If runtime compilation is unavailable, native kernels remain
available. Compilation adds startup time, so very short runs may be slower;
nep_compile 0 disables specialization. Prediction uses the native path.