SpinSystem#

A SpinSystem holds the spin Hamiltonian parameters of one species (EasySpin’s Sys): electron and nuclear spins, g, zero-field splitting, hyperfine and quadrupole tensors with their frames, line widths and strains. Every simulator takes one, or a list of them for multi-component spectra.

Units: energies and couplings in MHz, fields in mT, Euler angles in radians.

class torchspin.SpinSystem(S, g=None, gFrame=None, D=None, D_=None, DFrame=None, B=None, BFrame=None, Nucs=<factory>, n=None, A=None, A_=None, AFrame=None, ee=None, ee2=None, eeFrame=None, gnscale=None, sigma=None, sigmaFrame=None, Q=None, QFrame=None, nn=None, nnFrame=None, lw=None, lwpp=None, HStrain=None, gStrain=None, AStrain=None, DStrain=None, gAStrainCorr=1.0, DStrainCorr=0.0, weight=1.0, Abund=None, initState=None, tdm=None, tcorr=None, logtcorr=None, Diff=None, logDiff=None, T1=None, T2=None, lwEndor=None, Potential=None, DiffGlobal=None, TransRates=None, TransProb=None, Orientations=None, L=None, gL=None, soc=None, CF1=None, CF2=None, CF3=None, CF4=None, CF5=None, CF6=None, CF7=None, CF8=None, CF9=None, CF10=None, CF11=None, CF12=None, Ham=None, H0Extra=None, HStrainL=None, _Ieff=None)[source]#

Spin system: spins, interactions and broadenings (EasySpin Sys).

A SpinSystem holds everything the Hamiltonian builders and simulators need: electron spins S, nuclei Nucs (and optional orbital angular momenta L), interaction tensors with their frames, line widths and strains, and simulator-specific fields (dynamics, relaxation, component weight). Only S is required.

Inputs may be scalars, nested lists, NumPy arrays or torch tensors; the constructor normalizes the tensor fields to torch.float64 tensors of a canonical shape (listed below as “stored as”), converting EasySpin shorthands such as axial [g_perp, g_par] or [D, E]. Tensors are converted without copying or detaching, so a field that requires grad stays on the autograd graph (pepper_autograd, esfit). Assigning a field after construction (sys.g = ...) normalizes it the same way.

Conventions: energies, couplings and strains in MHz; magnetic fields and field-domain line widths in mT; Euler angles in radians ([alpha, beta, gamma], rotation from the molecular frame to the tensor’s principal frame, torchspin.erot() convention); nElectrons = len(S), nNuclei = len(Nucs), nPairs = nElectrons*(nElectrons-1)/2 (pairs ordered (1,2), (1,3), …, (2,3), …). “Full tensors” are 3x3 blocks stacked along axis 0.

Parameters:
  • S (float or list of float) – Electron spin quantum numbers, one per electron spin, positive multiples of 1/2, e.g. 0.5 or [0.5, 1.0]. Stored as a list of float.

  • g (float or array_like or Tensor, optional) – Electron g tensors (dimensionless). Accepted: a scalar (isotropic, every electron); [g1, g2, ...] or (nElectrons, 1) (one isotropic value per electron); [gx, gy, gz] (principal values, every electron); (nElectrons, 2) axial [g_perp, g_par] rows (for one electron also the flat [g_perp, g_par]); (nElectrons, 3) principal values; (3*nElectrons, 3) full tensors. Stored as (nElectrons, 3) or (3*nElectrons, 3). Default None: isotropic free-electron g (torchspin.GFREE) for every electron, or zero when Ham contains a linear Zeeman term ('110'/'112').

  • gFrame (array_like, shape (nElectrons, 3), optional) – Euler angles (rad) of the g principal frames; [a, b, c] for one electron spin. Default None or empty: zero.

  • D (float or array_like or Tensor, optional) – Zero-field splitting (MHz), needs S >= 1. Accepted: a scalar D (E = 0, every electron); for one electron [D], [D, E] or [Dxx, Dyy, Dzz]; (nElectrons, 1) rows of D; (nElectrons, 2) rows of [D, E]; (nElectrons, 3) principal values; (3*nElectrons, 3) full tensors; for four or more electrons a flat list of one D per electron. [D, E] becomes the principal values [-D/3 + E, -D/3 - E, 2D/3]. For two or three electrons a flat list of 2 or 3 values is ambiguous and raises. Stored as (nElectrons, 3) or (3*nElectrons, 3). Default None: no zero-field splitting.

  • D_ (array_like, shape (nElectrons, 2), optional) – Alternative to D: [D, E/D] per electron (MHz, dimensionless), or the same values as a flat list. Converted to D.

  • DFrame (array_like, shape (nElectrons, 3), optional) – Euler angles (rad) of the D principal frames, as gFrame.

  • B (list of array_like, optional) – Even-rank Stevens zero-field coefficients (MHz): B[0] is rank 2, B[1] rank 4, B[2] rank 6, each of shape (nElectrons, 2k+1) with columns q = k, k-1, ..., -k; None entries are skipped. The rank-2 entry is ignored when D is given (validate rejects nonzero D together with nonzero B[0]). Default None.

  • BFrame (list of array_like, optional) – Euler angles (rad) per entry of B: (nElectrons, 3), or (3,) for the first electron. Default None (no rotation).

  • Nucs (str or list of str, default []) – Nuclei: isotopes ('1H', '14N', '63Cu'), elements in natural abundance ('Cu') or custom mixtures ('(63,65)Cu', with Abund). A comma-separated string '14N,1H' is split. Elements and mixtures are expanded into isotopologues by pepper, garlic and chili (module torchspin.isotopologues, Options.IsoCutoff).

  • n (int or list of int, optional) – Number of equivalent nuclei per Nucs entry (same isotope, same isotropic coupling), positive integers. Supported by garlic and by pepper with Method='perturb*'/'hybrid'; pepper’s matrix method and chili raise for n > 1. Default None: 1 each.

  • A (float or array_like or Tensor, optional) – Hyperfine couplings (MHz). Accepted: a scalar (isotropic, every nucleus and electron); for one electron [A1, A2, ...] (one isotropic value per nucleus) or [Ax, Ay, Az] (every nucleus; with three nuclei a flat triple is one value per nucleus); (nNuclei, nElectrons) isotropic, (nNuclei, 2*nElectrons) axial [A_perp, A_par] and (nNuclei, 3*nElectrons) principal values (one 3-block per electron); (3*nNuclei, 3*nElectrons) full tensors. A flat list is one nucleus (e.g. [A_e1, A_e2] for two electrons). Stored as (nNuclei, 3*nElectrons) or (3*nNuclei, 3*nElectrons). Default None: zero (with nuclei). Giving A, AFrame, Q or QFrame without Nucs raises.

  • A_ (array_like, optional) – Alternative to A in spherical form per nucleus and electron: [aiso], [aiso, T] or [aiso, T, rho] (MHz), one row per nucleus; principal values aiso + T*[-1, -1, 2] + rho*[-1, 1, 0]. A scalar is aiso of one nucleus.

  • AFrame (array_like, shape (nNuclei, 3*nElectrons), optional) – Euler angles (rad) of the hyperfine principal frames, one 3-block per electron; for one electron [a, b, c] applies to every nucleus. Default None or empty: zero.

  • ee (float or array_like or Tensor, optional) – Electron-electron exchange/dipolar couplings (MHz), H = S1 . J . S2 per pair. Accepted: a scalar (isotropic, every pair); one isotropic value per pair ([J] for one pair, (nPairs, 1)); [Jx, Jy, Jz] (every pair; for three pairs a flat triple is read this way); (nPairs, 3) principal values; (3*nPairs, 3) full tensors. Default None: zero.

  • ee2 (float or array_like, optional) – Isotropic biquadratic exchange (MHz), one value per pair, adds ee2 * (S1 . S2)**2. Default None: zero.

  • eeFrame (array_like, shape (nPairs, 3), optional) – Euler angles (rad) of the ee principal frames; [a, b, c] applies to every pair. Default None: zero.

  • gnscale (float or array_like, shape (nNuclei,), optional) – Scale factor of each nuclear g factor (dimensionless); a scalar applies to every nucleus. Default None: 1.

  • sigma (float or array_like, optional) – Chemical-shielding factor of the nuclear Zeeman term, which is built as gn * muN * B . sigma . I, so 1 means no shielding (EasySpin convention, not 1 - sigma). A scalar, one value per nucleus, [sx, sy, sz] (every nucleus; with three nuclei a flat triple is one value per nucleus), (nNuclei, 3) principal values or (3*nNuclei, 3) full tensors. Default None: ones.

  • sigmaFrame (array_like, shape (nNuclei, 3), optional) – Euler angles (rad) of the sigma principal frames. Default zero.

  • Q (float or array_like or Tensor, optional) – Nuclear quadrupole couplings (MHz), for nuclei with I >= 1 (zero otherwise). Accepted: one e2qQ/h per nucleus (eta = 0); (nNuclei, 2) rows of [e2qQ/h, eta]; (nNuclei, 3) principal values; (3*nNuclei, 3) full tensors. [e2qQ/h, eta] becomes e2qQ/h / (4I(2I-1)) * [-1 + eta, -1 - eta, 2]. Default None: no quadrupole interaction.

  • QFrame (array_like, shape (nNuclei, 3), optional) – Euler angles (rad) of the Q principal frames. Default zero.

  • nn (float or array_like, optional) – Nucleus-nucleus couplings (MHz), per nuclear pair: a scalar, one isotropic value per pair, [Jx, Jy, Jz], (nNucPairs, 3) principal values or (3*nNucPairs, 3) full tensors. Default None: zero.

  • nnFrame (array_like, shape (nNucPairs, 3), optional) – Euler angles (rad) of the nn principal frames. Default zero.

  • lw (float or array_like, optional) – Line width [GaussianFWHM, LorentzianFWHM], in mT for field sweeps and in MHz for frequency sweeps. A scalar or [x] is [x, 0]; [[G, L]] is [G, L]; other sizes raise. A 2-element list or tensor is kept as given (tensors keep their graph). Default None: [0.0, 0.0] (no broadening) unless lwpp is given.

  • lwpp (float or array_like, optional) – Alternative to lw: peak-to-peak widths of the first-derivative lines [Gaussian, Lorentzian], same units and shapes. Converted by get_lw() with the factors sqrt(2 ln 2) (Gaussian) and sqrt(3) (Lorentzian). Giving both lw and lwpp raises.

  • HStrain (float or array_like, optional) – Gaussian frequency-domain strain FWHM (MHz) along the molecular x, y, z axes. One value is [x, x, x], two are [x, x, y], three are kept (any shape), empty is no strain; other counts raise. Stored as shape (3,). Default None.

  • gStrain (float or array_like, optional) – g strain FWHM (dimensionless, g units) along the g principal axes, one row per electron: (nElectrons, 1|2|3) with [x] -> [x, x, x] and [x, y] -> [x, x, y]; a flat list is one electron; a scalar or [x, y, z] applies to every electron. Not with full g tensors; for several electrons not in frequency sweeps. Stored as (nElectrons, 3). Default None.

  • AStrain (float or array_like, optional) – Hyperfine strain FWHM (MHz) of the first nucleus along its AFrame axes, shapes as HStrain. One electron spin only (raises otherwise). See KNOWN_LIMITATIONS.md, “AStrain — EasySpin’s effective-mI model, followed deliberately (0.9.25)”. Default None.

  • DStrain (float or array_like, optional) – D and E strain FWHM (MHz), one row [FWHM_D, FWHM_E] per electron (1 to 3 columns; one column is [FWHM_D, 0], a third column is dropped). One row or a scalar applies to every electron; for four or more electrons a flat list is one FWHM_D per electron. Empty is no strain. Stored as (nElectrons, 2). Default None.

  • gAStrainCorr (float, default 1.0) – Correlation of g and A strain: +1 correlated, -1 anticorrelated.

  • DStrainCorr (float or list of float, default 0.0) – Correlation coefficient between the D and E strains, in [-1, 1], one per electron (a scalar applies to every electron). Stored as a list.

  • weight (float, default 1.0) – Relative weight of this component when a list of spin systems is simulated (pepper, garlic, chili, saffron); multiplied by the isotopologue abundances.

  • Abund (list, optional) – Abundances for the custom isotope mixtures in Nucs: one array (or None for a non-mixture) per nucleus, or a flat array for a single nucleus. Default None.

  • initState (tuple or str or array_like, optional) – Non-equilibrium initial state instead of Boltzmann populations (pepper matrix method, spidyan, saffron): (pops, basis) or (rho, basis) with basis one of 'zerofield', 'eigen', 'xyz', 'coupled', 'uncoupled'; a density matrix in the uncoupled product basis; 'T0' or 'singlet'. See torchspin.initstate. Default None.

  • tdm (str or array_like, optional) – Transition dipole moment direction in the molecular frame for photoselection (Experiment.lightBeam, pepper): a string such as 'x', 'xz', '-y', a 3-vector or [phi, theta] (rad). Default None.

  • tcorr (float, optional) – Rotational correlation time in s (chili, cardamom, and garlic’s fast-motion regime). chili’s slow-motion solver also accepts 2 or 3 values (axial or rhombic). Default None.

  • logtcorr (float, optional) – log10(tcorr / s), alternative to tcorr. Default None.

  • Diff (float or array_like, optional) – Rotational diffusion rate in s^-1, alternative to tcorr (tcorr = 1/(6 Diff)); chili, cardamom and garlic (fast-motion regime, isotropic only). Default None.

  • logDiff (float or array_like, optional) – log10(Diff / s^-1). Default None.

  • T1 (float, optional) – Longitudinal and transverse relaxation times in microseconds (pulse simulators saffron, spidyan). Default None (no relaxation).

  • T2 (float, optional) – Longitudinal and transverse relaxation times in microseconds (pulse simulators saffron, spidyan). Default None (no relaxation).

  • lwEndor (float, optional) – ENDOR line width FWHM in MHz (saffron; required for Mims ENDOR). Default None.

  • Potential (array_like, optional) – Orienting potential: rows [L, M, K, lambda] (chili, cardamom), or a 3-D grid (cardamom). Default None.

  • DiffGlobal (float or array_like, optional) – Global rotational diffusion rate in s^-1 (cardamom). Default None.

  • TransRates (array_like, shape (nStates, nStates), optional) – Jump-model transition rate matrix (s^-1) or transition probability matrix (cardamom). Default None.

  • TransProb (array_like, shape (nStates, nStates), optional) – Jump-model transition rate matrix (s^-1) or transition probability matrix (cardamom). Default None.

  • Orientations (array_like, optional) – Euler angles (rad) of each jump-model state, (nStates, 3) or (3, nStates) (cardamom). Default None.

  • L (float or list of float, optional) – Orbital angular momentum quantum numbers, one per OAM; OAM i couples to electron i through soc. Default None.

  • gL (float or list of float, optional) – Orbital g factors, one per OAM. Default None: 1.0 each.

  • soc (array_like, shape (nElectrons, nOrders), optional) – Spin-orbit coupling (MHz); row i couples electron i and OAM i as soc[i,0] (S.L) + soc[i,1] (S.L)**2 + .... A flat list is one row. Default None.

  • CF1 (array_like, shape (nL, 2k+1), optional) – Crystal-field Stevens coefficients of rank k (MHz) per OAM, columns q = k, ..., -k; rank must not exceed 2L (validate). Default None.

  • ... (array_like, shape (nL, 2k+1), optional) – Crystal-field Stevens coefficients of rank k (MHz) per OAM, columns q = k, ..., -k; rank must not exceed 2L (validate). Default None.

  • CF12 (array_like, shape (nL, 2k+1), optional) – Crystal-field Stevens coefficients of rank k (MHz) per OAM, columns q = k, ..., -k; rank must not exceed 2L (validate). Default None.

  • Ham (dict, optional) – Higher-order Zeeman terms (McGavin-Tennant-Weil), keys '{lB}{lS}{l}' (orders in field and spin and coupling rank, e.g. '112'; EasySpin’s 'Ham112' is accepted and stored as '112'), values (nElectrons, 2l+1) coefficient arrays. A linear term ('110'/'112') replaces g (giving both raises). Field orders 2 and 3 enter the resonance search only with Options(QuadraticZeeman=True); perturbation methods raise. See KNOWN_LIMITATIONS.md, “Higher-order Zeeman terms (Sys.Ham*): deliberate deviation from EasySpin (0.6.7, 0.9.8, 0.9.13)”. Default None.

  • H0Extra (list of tuple, optional) – Extra field-independent Hamiltonian terms [(coeff, op), ...], added as sum(coeff * op) (MHz) by torchspin.ham(). coeff is a real scalar (float or 0-d tensor, may require grad); op an (nStates, nStates) Hermitian matrix in the full basis in torchspin.sop() order (electrons, nuclei, OAMs). Not an EasySpin field. Not with isotope mixtures or n > 1; solvers that do not use ham() (perturbation theory, hybrid, garlic, chili, fastmotion, cardamom, saffron’s fast algorithm, nucspinrmv/keep/add) raise. See KNOWN_LIMITATIONS.md, “Simulator — extra field-independent operators (Sys.H0Extra) (0.7.2)”. Default None.

  • HStrainL (float or array_like, shape (3,), optional) – Lorentzian counterpart of HStrain (MHz FWHM along the molecular axes, a scalar is expanded, non-negative): the width of a line is sqrt(sum_k (HStrainL_k n_k)**2) for a field along n, drawn as a Lorentzian. pepper and pepper_autograd only; cannot be combined with the Gaussian strains. Not an EasySpin field. See KNOWN_LIMITATIONS.md, “Simulator — Lorentzian strain, SpinSystem.HStrainL (0.7.7)”. Default None.

Variables:
  • nL (nElectrons, nNuclei,) – Number of electron spins, nuclei and orbital angular momenta.

  • gn (I,) – Nuclear spins and nuclear g factors from Nucs.

  • Spins (list of float) – All spin quantum numbers: electrons, nuclei, OAMs.

  • nStates (int) – Hilbert-space dimension prod(2s + 1).

  • fullnn (fullg, fullD, fullA, fullee, fullsigma, fullQ,) – Whether the field is stored as full 3x3 tensors.

Raises:
  • ValueError – On construction, for a tensor field whose shape matches none of the accepted forms (g, D, D_, A, A_, AFrame, gFrame, DFrame, ee, ee2, eeFrame, Q, QFrame, lw, lwpp, HStrain, AStrain, gStrain, DStrain, DStrainCorr, n), for alternative fields given together (D and D_, A and A_, lw and lwpp, g and a linear Ham term), for A/Q data without Nucs, for negative HStrainL, and for an invalid H0Extra term.

  • TypeError – If H0Extra is not a list of (coeff, op) pairs.

Notes

The constructor checks shapes only. validate() performs further physical checks (spin values, S >= 1 for D, I >= 1 for Q, signs of widths, CF ranks); the simulators do not call it. Which fields a simulator reads, ignores or rejects is listed in that simulator’s docstring. See KNOWN_LIMITATIONS.md, “SpinSystem input shapes follow EasySpin (0.9.15)” and “SpinSystem field assignment normalizes (0.8.7)”.

Examples

A nitroxide; axial A given as [A_perp, A_par]:

>>> from torchspin import SpinSystem
>>> sys = SpinSystem(S=0.5, g=[2.0088, 2.0061, 2.0027],
...                  Nucs='14N', A=[[20.0, 95.0]], lw=0.5)
>>> sys.g.shape, sys.A.tolist(), sys.lw
(torch.Size([1, 3]), [[20.0, 20.0, 95.0]], [0.5, 0.0])
>>> sys.nStates
6

A triplet with [D, E] in MHz, stored as principal values:

>>> trip = SpinSystem(S=1, D=[300.0, 30.0])
>>> [round(v, 1) for v in trip.D[0].tolist()]
[-70.0, -130.0, 200.0]

Assigning a field normalizes it:

>>> trip.HStrain = 10.0
>>> trip.HStrain.tolist()
[10.0, 10.0, 10.0]
property nElectrons: int[source]#

Number of electron spins, len(S).

property nNuclei: int[source]#

Number of nuclei, len(Nucs) (an element or mixture counts once).

property I: list[float][source]#

Nuclear spin quantum numbers (derived from Nucs).

property gn: list[float][source]#

Nuclear g-factors (derived from Nucs).

property nL: int[source]#

Number of orbital angular momenta.

property Spins: list[float][source]#

electrons first, then nuclei, then OAMs.

Type:

All spin quantum numbers

property nStates: int[source]#

Total Hilbert space dimension.

property fullg: bool[source]#

True if g is given as full 3×3 matrices.

property fullD: bool[source]#

True if D is given as full 3×3 matrices.

property fullA: bool[source]#

True if A is given as full 3×3 matrices per nucleus per electron.

property fullee: bool[source]#

True if ee is given as full 3×3 matrices.

property fullsigma: bool[source]#

True if sigma is given as full 3×3 matrices.

property fullQ: bool[source]#

True if Q is given as full 3×3 matrices.

property fullnn: bool[source]#

True if nn is given as full 3×3 matrices.

get_lw()[source]#

Return the line width as [GaussianFWHM, LorentzianFWHM].

lw as stored if it is set; otherwise lwpp converted from peak-to-peak to FWHM (as EasySpin’s validatespinsys.m):

  • Gaussian: lw = lwpp * sqrt(2 ln 2), about 1.177 * lwpp;

  • Lorentzian: lw = lwpp * sqrt(3), about 1.732 * lwpp.

Returns:

list – [GaussianFWHM, LorentzianFWHM] in the units of lw/lwpp (mT for field sweeps, MHz for frequency sweeps). The entries are floats or 0-d tensors (tensors keep their autograd graph).

Return type:

list[float]

Examples

>>> from torchspin import SpinSystem
>>> [round(v, 3) for v in SpinSystem(S=0.5, lwpp=[1.0, 1.0]).get_lw()]
[1.177, 1.732]
validate()[source]#

Check the spin system for physical consistency.

Checks the quantum numbers (S positive multiples of 1/2, L non-negative), tensor and frame shapes, S >= 1 for a nonzero D, I >= 1 for a nonzero Q, known isotopes, non-negative line widths and strains, DStrainCorr in [-1, 1], gAStrainCorr = +-1, positive tcorr/Diff/T1/T2, exclusive pairs (tcorr/logtcorr, Diff/logDiff, nonzero D and B[0]), symmetric full Q blocks and crystal-field ranks k <= 2L. Partial port of EasySpin’s validatespinsys.m.

The constructor checks only shapes; the simulators do not call this method, so call it explicitly to catch physically invalid input.

Raises:

ValueError – On the first problem found.

Examples

>>> from torchspin import SpinSystem
>>> SpinSystem(S=1.0, D=[300.0, 30.0]).validate()
>>> SpinSystem(S=0.5, D=300.0).validate()
Traceback (most recent call last):
    ...
ValueError: D tensor is nonzero for electron 0 with S=0.5, but ZFS requires S >= 1.

See also

TorchSpin — EPR Simulation Quickstart builds spin systems step by step. Helpers that derive new systems from an existing one are listed under Spin systems.