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
SpinSystemholds everything the Hamiltonian builders and simulators need: electron spinsS, nucleiNucs(and optional orbital angular momentaL), interaction tensors with their frames, line widths and strains, and simulator-specific fields (dynamics, relaxation, component weight). OnlySis required.Inputs may be scalars, nested lists, NumPy arrays or torch tensors; the constructor normalizes the tensor fields to
torch.float64tensors 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.5or[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). DefaultNone: isotropic free-electron g (torchspin.GFREE) for every electron, or zero whenHamcontains 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. DefaultNoneor 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). DefaultNone: 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 toD.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 columnsq = k, k-1, ..., -k;Noneentries are skipped. The rank-2 entry is ignored whenDis given (validaterejects nonzeroDtogether with nonzeroB[0]). DefaultNone.BFrame (list of array_like, optional) – Euler angles (rad) per entry of
B:(nElectrons, 3), or(3,)for the first electron. DefaultNone(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', withAbund). A comma-separated string'14N,1H'is split. Elements and mixtures are expanded into isotopologues by pepper, garlic and chili (moduletorchspin.isotopologues,Options.IsoCutoff).n (int or list of int, optional) – Number of equivalent nuclei per
Nucsentry (same isotope, same isotropic coupling), positive integers. Supported by garlic and by pepper withMethod='perturb*'/'hybrid'; pepper’s matrix method and chili raise forn > 1. DefaultNone: 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). DefaultNone: zero (with nuclei). GivingA,AFrame,QorQFramewithoutNucsraises.A_ (array_like, optional) – Alternative to
Ain spherical form per nucleus and electron:[aiso],[aiso, T]or[aiso, T, rho](MHz), one row per nucleus; principal valuesaiso + T*[-1, -1, 2] + rho*[-1, 1, 0]. A scalar isaisoof 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. DefaultNoneor empty: zero.ee (float or array_like or Tensor, optional) – Electron-electron exchange/dipolar couplings (MHz),
H = S1 . J . S2per 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. DefaultNone: zero.ee2 (float or array_like, optional) – Isotropic biquadratic exchange (MHz), one value per pair, adds
ee2 * (S1 . S2)**2. DefaultNone: zero.eeFrame (array_like, shape (nPairs, 3), optional) – Euler angles (rad) of the
eeprincipal frames;[a, b, c]applies to every pair. DefaultNone: 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, so1means no shielding (EasySpin convention, not1 - 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. DefaultNone: ones.sigmaFrame (array_like, shape (nNuclei, 3), optional) – Euler angles (rad) of the
sigmaprincipal 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/hper nucleus (eta = 0);(nNuclei, 2)rows of[e2qQ/h, eta];(nNuclei, 3)principal values;(3*nNuclei, 3)full tensors.[e2qQ/h, eta]becomese2qQ/h / (4I(2I-1)) * [-1 + eta, -1 - eta, 2]. DefaultNone: 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. DefaultNone: zero.nnFrame (array_like, shape (nNucPairs, 3), optional) – Euler angles (rad) of the
nnprincipal 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). DefaultNone:[0.0, 0.0](no broadening) unlesslwppis 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 byget_lw()with the factorssqrt(2 ln 2)(Gaussian) andsqrt(3)(Lorentzian). Giving bothlwandlwppraises.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,). DefaultNone.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). DefaultNone.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)”. DefaultNone.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). DefaultNone.gAStrainCorr (float, default 1.0) – Correlation of g and A strain:
+1correlated,-1anticorrelated.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 (orNonefor a non-mixture) per nucleus, or a flat array for a single nucleus. DefaultNone.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)withbasisone of'zerofield','eigen','xyz','coupled','uncoupled'; a density matrix in the uncoupled product basis;'T0'or'singlet'. Seetorchspin.initstate. DefaultNone.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). DefaultNone.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 totcorr. DefaultNone.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). DefaultNone.logDiff (float or array_like, optional) –
log10(Diff / s^-1). DefaultNone.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). DefaultNone.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). DefaultNone.L (float or list of float, optional) – Orbital angular momentum quantum numbers, one per OAM; OAM
icouples to electronithroughsoc. DefaultNone.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
icouples electroniand OAMiassoc[i,0] (S.L) + soc[i,1] (S.L)**2 + .... A flat list is one row. DefaultNone.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 exceed2L(validate). DefaultNone.... (array_like, shape (nL, 2k+1), optional) – Crystal-field Stevens coefficients of rank k (MHz) per OAM, columns
q = k, ..., -k; rank must not exceed2L(validate). DefaultNone.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 exceed2L(validate). DefaultNone.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') replacesg(giving both raises). Field orders 2 and 3 enter the resonance search only withOptions(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)”. DefaultNone.H0Extra (list of tuple, optional) – Extra field-independent Hamiltonian terms
[(coeff, op), ...], added assum(coeff * op)(MHz) bytorchspin.ham().coeffis a real scalar (float or 0-d tensor, may require grad);opan(nStates, nStates)Hermitian matrix in the full basis intorchspin.sop()order (electrons, nuclei, OAMs). Not an EasySpin field. Not with isotope mixtures orn > 1; solvers that do not useham()(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)”. DefaultNone.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 issqrt(sum_k (HStrainL_k n_k)**2)for a field alongn, 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)”. DefaultNone.
- 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 (DandD_,AandA_,lwandlwpp,gand a linearHamterm), forA/Qdata withoutNucs, for negativeHStrainL, and for an invalidH0Extraterm.TypeError – If
H0Extrais not a list of(coeff, op)pairs.
See also
Experiment,Options,torchspin.ham,torchspin.pepper,torchspin.garlicNotes
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, “SpinSysteminput shapes follow EasySpin (0.9.15)” and “SpinSystemfield assignment normalizes (0.8.7)”.Examples
A nitroxide; axial
Agiven 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 Spins: list[float][source]#
electrons first, then nuclei, then OAMs.
- Type:
All spin quantum numbers
- get_lw()[source]#
Return the line width as
[GaussianFWHM, LorentzianFWHM].lwas stored if it is set; otherwiselwppconverted from peak-to-peak to FWHM (as EasySpin’s validatespinsys.m):Gaussian:
lw = lwpp * sqrt(2 ln 2), about1.177 * lwpp;Lorentzian:
lw = lwpp * sqrt(3), about1.732 * lwpp.
- Returns:
list –
[GaussianFWHM, LorentzianFWHM]in the units oflw/lwpp(mT for field sweeps, MHz for frequency sweeps). The entries are floats or 0-d tensors (tensors keep their autograd graph).- Return type:
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 nonzeroQ, known isotopes, non-negative line widths and strains,DStrainCorrin[-1, 1],gAStrainCorr= +-1, positivetcorr/Diff/T1/T2, exclusive pairs (tcorr/logtcorr,Diff/logDiff, nonzeroDandB[0]), symmetric fullQblocks and crystal-field ranksk <= 2L. Partial port of EasySpin’svalidatespinsys.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.