torchspin.lft.dsoxf#

DSOXF: one free-ion term (2S+1)L of d^n or f^n in a crystal field, differentiable.

The Hamiltonian of Telser’s DSOXF (via telser-tools), in its |m_L m_S> basis (m_L outer, both descending):

H = H_CF + s abs(lambda) L.S + rho SS + mu_B B . (s_L k L + g_e S)

for the d and f shells, high and low spin (low-spin d4/d5 as the fictitious L~ = 1 term), Oh/Td, cubic/axial/rhombic and tetragonal/trigonal fields, with both conventions ('corrected', the default, or 'dsoxf' = the compiled program). SS = -[(L.S)^2 + L.S/2 - L(L+1)S(S+1)/3] is the Abragam-Bleaney spin-spin term (zero for S < 1).

For a fixed configuration and discrete setting, H_CF is linear in the crystal-field parameters (CF_PARAMETERS: dq, ds, dt4 (= Delta4 = -Dt), v2, v4 for d; b4, b6, b20 … b66 for f, as DSOXF reads them). The matrices are probed once from the NumPy model (torchspin.lft._engines.dsoxf.DsoxfModel) and checked for linearity, so the Stevens operators, DSOXF’s scalings (B2X, B4X, F_kq), the symmetry selection and the whole sign table keep one definition. lam is a magnitude: lambda_eff = s abs(lambda) with the sign s that the program chooses (d abs(lambda)/d lambda := +1 at 0).

Units#

Energy-valued inputs (lam, rho and every crystal-field parameter) and energy-valued outputs (H, energies, doublet energies) are in units (default 'MHz'; 'cm^-1', 'GHz', 'K', 'eV', …; see torchspin.lft.units). The magnetic field is in mT (DSOXF itself takes gauss), temperatures in K. k, g values and occupancies are dimensionless; transition moments abs(<i|mu.b1|j>)**2 are in mu_B^2. Level tolerances (tol) are in cm^-1 whatever units is. Internally everything is cm^-1.

Gauge#

Per-state quantities (<S>, occupancies, abs(<i|mu|j>)**2) depend on the arbitrary basis inside a degenerate level, exactly as in DSOXF, and have no derivative there; their sums over the level (level_matrix(E) @ x, level_sum(), Solution.level_transition_moments()) are gauge-invariant and differentiable. Kramers-doublet g tensors use the doublet projector.

Not ported: DSOXF’s legacy EPR probabilities ((sum_a abs(<i|S_a|j>))**2, a sum of moduli that depends on eigenvector phases and is not smooth; telser-tools finding DSOXF-05), the listing and spin-magnitude cutoffs, the input-file reader and the printed report.

Examples

Cu(II), d9, tetragonally elongated (telser-tools’ DSOXF quick start): the ground Kramers doublet has g_perp = 2.069 and g_par = 2.421.

>>> import torch
>>> from torchspin.lft import dsoxf
>>> s = dsoxf.DsoxfSystem("d", 9, symmetry="axial", units="cm^-1", lam=830.0, dq=1200.0,
...                       ds=2000.0, dt4=-500.0, k=(0.8, 0.8, 0.8))
>>> sol = s.solve()
>>> [round(e, 2) for e in sol.relative[::2].tolist()]
[0.0, 10392.24, 12010.6, 15304.75, 16176.33]
>>> [round(g, 4) for g in sol.kramers_g()[0].principal.tolist()]
[2.0686, 2.0686, 2.4212]

Derivatives flow from every continuous parameter, here Ds at a field of 300 mT along z:

>>> ds = torch.tensor(2000.0, dtype=torch.float64, requires_grad=True)
>>> sol = s.solve(field=(0.0, 0.0, 300.0), ds=ds)
>>> (dE,) = torch.autograd.grad(sol.energies[2], ds)
>>> sol.energies.shape, sol.spin_expectation().shape, sol.orbital_occupancies().shape
(torch.Size([10]), torch.Size([10, 3]), torch.Size([10, 5]))
torchspin.lft.dsoxf.LEVEL_TOL = 1e-06#

DSOXF’s level criterion for Kramers doublets and level sums (cm^-1, chained).

class torchspin.lft.dsoxf.DoubletG(energy, principal, ggT, g)[source]#

g tensor of one Kramers doublet.

Variables:
  • energy (Tensor) – Mean energy of the doublet, in the solution’s units (0 if no energies were given).

  • principal (Tensor, shape (..., 3)) – Principal values abs(g), ascending.

  • ggT (Tensor, shape (..., 3, 3)) – g g^T (gauge-invariant).

  • g (Tensor, shape (..., 3, 3)) – (g g^T)^(1/2), symmetric, with exact gradients at axial g.

energy: Tensor#

Alias for field number 0

principal: Tensor#

Alias for field number 1

ggT: Tensor#

Alias for field number 2

g: Tensor#

Alias for field number 3

class torchspin.lft.dsoxf.DsoxfOperators(shell, code, term, L, S, nl, ns, cf, LS, SS, Lv, Sv, so_sign, zeeman_sign)[source]#

Constant operators of one DSOXF configuration and discrete setting (energies in cm^-1).

Built and cached by dsoxf_operators(); N = nl * ns is the size of the |m_L m_S> basis.

Variables:
  • shell (str) – 'd' or 'f'.

  • code (int) – DSOXF’s configuration number (see dsoxf_operators()).

  • term (str) – Free-ion term, e.g. '2D'; '3P~'/'2P~' for the low-spin L~ = 1 terms.

  • L (int) – Orbital quantum number of the term.

  • S (float) – Spin quantum number of the term.

  • ns (nl,) – Orbital (2L+1) and spin (2S+1) dimensions.

  • cf (Tensor, shape (18, N, N), float64) – Crystal-field operators in CF_PARAMETERS order: H_CF = sum_p value_p cf[p] (parameters inactive in this setting have zero matrices).

  • SS (LS,) – L.S and the spin-spin (rho) operator (zero for S < 1).

  • Sv (Lv,) – Orbital and spin angular-momentum vectors.

  • so_sign (float) – The sign s of lambda_eff = s abs(lambda).

  • zeeman_sign (float) – s_L, the sign of the orbital Zeeman term (-1 for the corrected L~ = 1 terms).

property size: int[source]#

Basis size n = nl * ns.

property device: device[source]#

Device of the operator tensors.

class torchspin.lft.dsoxf.DsoxfSystem(shell='d', code=1, *, geometry='Oh', symmetry='cubic', axis='tetragonal', conventions='corrected', units='MHz', constants=TORCHSPIN_CONSTANTS, device='cpu', **params)[source]#

One DSOXF configuration with stored parameter values and cached operators.

Parameters:
  • shell (str) – The configuration and discrete setting, as dsoxf_operators().

  • code (int) – The configuration and discrete setting, as dsoxf_operators().

  • geometry (str) – The configuration and discrete setting, as dsoxf_operators().

  • symmetry (str) – The configuration and discrete setting, as dsoxf_operators().

  • axis (str) – The configuration and discrete setting, as dsoxf_operators().

  • conventions (str) – The configuration and discrete setting, as dsoxf_operators().

  • units (str, default 'MHz') – Energy unit of the stored parameters, of per-call overrides and of every returned energy; fixed for the system.

  • constants (Constants, optional) – Physical constants, default torchspin.lft.ddn.TORCHSPIN_CONSTANTS.

  • device (str or device, default 'cpu') – Device of the operators.

  • **params – Stored defaults: lam (abs(lambda), default 0), rho (default 0), k (default (1, 1, 1)) and any of CF_PARAMETERS (default 0), energies in units.

Raises:

TypeError – For an unknown parameter name (also for per-call overrides).

Examples

>>> import torch
>>> from torchspin.lft import dsoxf
>>> s = dsoxf.DsoxfSystem("f", 1, symmetry="axial", axis="trigonal", units="cm^-1",
...                       lam=600.0, b4=2000.0, b6=800.0)
>>> s.ops.term, s.size
('2F', 14)
>>> E = s.levels(b20=torch.tensor(300.0), relative=True)   # keyword overrides per call
>>> E.shape
torch.Size([14])
classmethod from_model(model, *, units='MHz', constants=TORCHSPIN_CONSTANTS, device='cpu')[source]#

Build from a DSOXF model object holding Telser’s cm^-1 values.

model is torchspin.lft._engines.dsoxf.DsoxfModel or telser-tools’ DsoxfModel; its energies are converted from cm^-1 to units.

property size: int[source]#

Basis size (2L+1)(2S+1).

parameters(**kw)[source]#

Stored parameters updated with the keyword overrides kw (raises TypeError for unknown names).

hamiltonian(field=None, **kw)[source]#

Hamiltonian (n, n) in self.units; field in mT, keywords override the stored parameters (hamiltonian()).

levels(field=None, relative=False, **kw)[source]#

Ascending energies (n,) in self.units; field in mT, keywords override the stored parameters (levels()).

solve(field=None, **kw)[source]#

Diagonalize at field (mT) with keyword overrides; returns a Solution (solve()).

zeeman_operators(k=None)[source]#

Moment operators (3, n, n) in mu_B for k (default: the stored k).

class torchspin.lft.dsoxf.Solution(ops, field, energies, vectors, mu, units, constants)[source]#

Eigenstates of one DSOXF Hamiltonian (returned by solve() and DsoxfSystem.solve()).

Variables:
  • ops (DsoxfOperators) – Configuration operators.

  • energies (Tensor, shape (N,)) – Ascending eigenvalues in units.

  • vectors (Tensor, shape (N, N), complex128) – Eigenvector columns in the |m_L m_S> basis.

  • mu (Tensor, shape (3, N, N), complex128) – Magnetic-moment operator in mu_B.

  • field (array_like or None) – Field vector in mT, or None.

  • units (str) – Energy unit of energies.

  • constants (Constants) – Physical constants used.

property relative: Tensor[source]#

Energies relative to the ground state, in units.

levels(tol=1e-5)[source]#

Group states into degenerate levels.

Parameters:

tol (float, default 1e-5) – DSOXF’s chained criterion in cm^-1, applied to detached energies.

Returns:

list of (torch.Tensor, list of int) – (energy of the first member, state indices) per level, ascending.

Return type:

list[tuple[Tensor, list[int]]]

level_sum(x, tol=LEVEL_TOL)[source]#

Per-state x summed over each degenerate level (level_sum(); tol in cm^-1).

spin_expectation()[source]#

<S> per state, shape (N, 3).

spin_along_field()[source]#

<S . h> per state, h the unit field vector (DSOXF’s “<S para>”); h = z at zero field.

ml_occupancies()[source]#

m_L weights per state, shape (N, 2L+1) (ml_occupancies()).

orbital_occupancies(kind='real')[source]#

Real-orbital weights per state, shape (N, 2L+1) (orbital_occupancies()).

g_tensor(states=(0, 1))[source]#

g of the doublet spanned by states (default the lowest two); use at zero field. Returns DoubletG.

kramers_g(tol=LEVEL_TOL)[source]#

g of every doubly degenerate level (zero field).

Parameters:

tol (float, default LEVEL_TOL) – Level tolerance in cm^-1.

Returns:

list of DoubletG – One entry per two-fold level, ascending in energy.

Return type:

list[DoubletG]

field_g(i, j)[source]#

DSOXF’s g(obs) of the pair of states i, j.

g(obs) = (E_j - E_i) / (mu_B abs(B)) with the energies in cm^-1 and mu_B in cm^-1/mT.

Raises:

ValueError – If the solution has no field or a zero field.

populations(temperature)[source]#

Boltzmann factors exp(-(E_i - E_0) / k_B T) per state.

temperature in K (float or tensor). DSOXF’s “relative population”: not normalized.

transition_moments(b1=None)[source]#

Squared transition moments abs(<i|mu . b1|j>)**2 in mu_B^2, shape (N, N).

b1 is the microwave-field direction; default the static-field direction (parallel mode; z at zero field).

level_transition_moments(b1=None, tol=LEVEL_TOL)[source]#

Transition moments summed over the members of both levels (gauge-invariant).

abs(<I|mu . b1|J>)**2 in mu_B^2, shape (N, N); b1 as transition_moments(), tol in cm^-1.

torchspin.lft.dsoxf.doublet_g(V, mu, idx, E=None)[source]#

g tensor of the doublet spanned by two eigenvectors.

(g g^T)_ij = 2 tr(P mu_i P mu_j) with P the doublet projector, so the result is gauge-invariant. Meaningful at zero field.

Parameters:
  • V (Tensor, shape (..., N, N)) – Eigenvectors as columns.

  • mu (Tensor, shape (..., 3, N, N)) – Moment operators in mu_B.

  • idx (sequence of int) – The two column indices of the doublet.

  • E (Tensor, shape (..., N), optional) – Energies, for the energy field.

Returns:

DoubletG

Return type:

DoubletG

torchspin.lft.dsoxf.dsoxf_operators(shell='d', code=1, *, geometry='Oh', symmetry='cubic', axis='tetragonal', conventions='corrected', device='cpu')[source]#

Cached constant operators of one DSOXF configuration and discrete setting.

Parameters:
  • shell ({'d', 'f'}, default 'd') – Electron shell.

  • code (int, default 1) – DSOXF’s configuration number. d: 1 … 9 (high spin, d^n), -4 … -7 (low spin d4 … d7; -4 and -5 are the fictitious L~ = 1 terms); f: 1 … 13.

  • geometry ({'Oh', 'Td'}, default 'Oh') – ‘Td’ reverses the sign of every crystal-field parameter.

  • symmetry ({'cubic', 'axial', 'rhombic'}, default 'cubic') – Which crystal-field parameters act, as DSOXF reads them. d shell: cubic dq; axial adds ds, dt4; rhombic adds v2, v4. f shell: cubic b4, b6; axial adds b20, b40, b60 and b44, b64 (tetragonal) or b43, b63, b66 (trigonal); rhombic adds b22, b42, b62. Inactive parameters are ignored.

  • axis ({'tetragonal', 'trigonal'}, default 'tetragonal') – Quantization axis: z along C4 or along C3.

  • conventions ({'corrected', 'dsoxf'}, default 'corrected') – ‘corrected’ fixes the signs of the L~ = 1 spin-orbit and orbital-Zeeman terms, the F-term rank-2 terms and low-spin d7 (telser-tools findings DSOXF-01 to -03); ‘dsoxf’ reproduces the compiled program.

  • device (str or device, default 'cpu') – Device of the operator tensors.

Returns:

DsoxfOperators – Cached per (setting, device); unit-free (cm^-1).

Raises:

ValueError – For an unknown shell/code, geometry, symmetry, axis or conventions.

Return type:

DsoxfOperators

Examples

>>> from torchspin.lft import dsoxf
>>> ops = dsoxf.dsoxf_operators("d", 7, symmetry="axial")
>>> ops.term, ops.size, tuple(ops.cf.shape)
('4F', 28, (18, 28, 28))
torchspin.lft.dsoxf.hamiltonian(ops, *, lam=0.0, rho=0.0, k=(1.0, 1.0, 1.0), field=None, units='MHz', constants=TORCHSPIN_CONSTANTS, **cf)[source]#

DSOXF Hamiltonian as a complex Hermitian matrix.

Parameters:
  • ops (DsoxfOperators) – Configuration operators (dsoxf_operators()).

  • lam (float or Tensor, default 0.0) – Magnitude abs(lambda) of the spin-orbit constant, in units; the sign is chosen by the configuration (ops.so_sign).

  • rho (float or Tensor, default 0.0) – Spin-spin parameter in units (acts only for S >= 1).

  • k (array_like or Tensor, shape (..., 3), default (1, 1, 1)) – Orbital reduction factors (Zeeman term only).

  • field (array_like or Tensor, shape (..., 3), optional) – Magnetic field vector in mT; None (default) = zero field.

  • units (str, default 'MHz') – Energy unit of the energy inputs and of the result.

  • constants (Constants, optional) – Physical constants, default torchspin.lft.ddn.TORCHSPIN_CONSTANTS.

  • **cf (float or Tensor) – Crystal-field parameters, any of CF_PARAMETERS (default 0), in units; which act depends on the setting (dsoxf_operators()).

  • gradients. (Every value may be a tensor with leading batch dimensions and)

Returns:

torch.Tensor, shape (…, N, N), complex128 – H in units.

Raises:
  • TypeError – For a keyword that is not one of CF_PARAMETERS.

  • ValueError – For an unknown units.

Return type:

Tensor

torchspin.lft.dsoxf.level_matrix(E, tol=LEVEL_TOL, units='MHz')[source]#

Indicator matrix of degenerate levels.

Parameters:
  • E (Tensor, shape (..., N)) – Ascending energies in units.

  • tol (float, default LEVEL_TOL (1e-6)) – Level tolerance in cm^-1: states are chained into one level while abs(E[i+1] - E[i]) <= tol.

  • units (str, default 'MHz') – Unit of E.

Returns:

torch.Tensor, shape (…, N, N) – 1 where states i and j belong to the same level, else 0 (decided on detached energies). level_matrix(E) @ x sums a per-state quantity over each level (gauge-invariant), and D @ M @ D sums a pair quantity over both levels.

Return type:

Tensor

torchspin.lft.dsoxf.level_sum(E, x, tol=LEVEL_TOL, units='MHz')[source]#

Sum a per-state quantity over each state’s degenerate level.

Parameters:
  • E (Tensor, shape (..., N)) – Ascending energies in units.

  • x (Tensor, shape (..., N) or (..., N, m)) – Per-state quantity.

  • tol (float, default LEVEL_TOL) – Level tolerance in cm^-1.

  • units (str, default 'MHz') – Unit of E.

Returns:

torch.Tensor – Same shape as x; entry i is the sum over the level containing state i.

Return type:

Tensor

torchspin.lft.dsoxf.levels(ops, *, relative=False, units='MHz', **kw)[source]#

Eigenvalues of the DSOXF Hamiltonian.

Parameters:
  • ops (DsoxfOperators) – Configuration operators.

  • relative (bool, default False) – Subtract the lowest eigenvalue (ground state at 0).

  • units (str, default 'MHz') – Energy unit of the inputs and of the result.

  • **kw – lam, rho, k, field (mT), constants and crystal-field parameters, as hamiltonian().

Returns:

torch.Tensor, shape (…, N), float64 – Ascending energies in units. A degenerate eigenvalue gets its level’s mean derivative.

Return type:

Tensor

torchspin.lft.dsoxf.ml_occupancies(V, ops)[source]#

Weights of the m_L components of eigenvectors.

Parameters:
  • V (Tensor, shape (..., N, N)) – Eigenvectors as columns.

  • ops (DsoxfOperators) – Configuration operators.

Returns:

torch.Tensor, shape (…, N, 2L+1) – sum over m_S of abs(c(m_L, m_S))**2, columns m_L = L ... -L.

Return type:

Tensor

torchspin.lft.dsoxf.orbital_occupancies(V, ops, kind='real')[source]#

Weights of the real orbitals in eigenvectors; each row sums to 1.

Parameters:
  • V (Tensor, shape (..., N, N)) – Eigenvectors as columns.

  • ops (DsoxfOperators) – Configuration operators.

  • kind ({'real', 'general', 'cubic'}, default 'real') – L = 2: ignored, columns D_ORBITALS. L = 3: 'general' (F_GENERAL_ORBITALS) or 'cubic' (F_CUBIC_ORBITALS).

Returns:

torch.Tensor, shape (…, N, 2L+1) – Real-orbital weights per eigenvector.

Return type:

Tensor

torchspin.lft.dsoxf.solve(ops, *, field=None, k=(1.0, 1.0, 1.0), units='MHz', constants=TORCHSPIN_CONSTANTS, **kw)[source]#

Diagonalize the DSOXF Hamiltonian.

Parameters:
  • ops (DsoxfOperators) – Configuration operators.

  • field (array_like or Tensor, shape (3,), optional) – Field vector in mT.

  • k (array_like, shape (3,), default (1, 1, 1)) – Orbital reduction factors.

  • units (str, default 'MHz') – Energy unit of the inputs and of the solution.

  • constants (Constants, optional) – Physical constants.

  • **kw – lam, rho and crystal-field parameters, as hamiltonian().

Returns:

Solution – Eigenvalues and eigenvectors with degenerate-safe derivatives.

Return type:

Solution

torchspin.lft.dsoxf.spin_expectation(V, ops)[source]#

Spin expectation values of eigenvectors.

Parameters:
  • V (Tensor, shape (..., N, N)) – Eigenvectors as columns, in the |m_L m_S> basis.

  • ops (DsoxfOperators) – Configuration operators.

Returns:

torch.Tensor, shape (…, N, 3) – <S_x>, <S_y>, <S_z> of every eigenvector (gauge dependent inside degenerate levels).

Return type:

Tensor

torchspin.lft.dsoxf.transition_moments(V, mu, b1)[source]#

Squared transition moments abs(<i|mu . b1|j>)**2.

Parameters:
  • V (Tensor, shape (..., N, N)) – Eigenvectors as columns.

  • mu (Tensor, shape (..., 3, N, N)) – Moment operators in mu_B (zeeman_operators()).

  • b1 (array_like or Tensor, shape (..., 3)) – Microwave-field direction (not normalized here).

Returns:

torch.Tensor, shape (…, N, N) – In mu_B^2 (gauge dependent inside degenerate levels; see level_matrix()).

Return type:

Tensor

torchspin.lft.dsoxf.zeeman_operators(ops, k=(1.0, 1.0, 1.0), constants=TORCHSPIN_CONSTANTS)[source]#

Magnetic-moment operators mu / mu_B = s_L k_i L_i + g_e S_i.

Parameters:
Returns:

torch.Tensor, shape (…, 3, N, N), complex128 – The x, y, z components in units of mu_B.

Return type:

Tensor