torchspin.lft.dlsd5#

DLSD5: low-spin d5 (t2g^5) g values <-> ligand field, differentiable (Telser’s DLSD5).

Ported from telser-tools (telser_tools_diff.dlsd5), with the same bases, axes and sign conventions as telser_tools.dlsd5 (McGarvey, Coord. Chem. Rev. 1998, 170, 75). Every continuous input may carry gradients, with leading batch dimensions where noted.

Units#

DLSD5 works in units of the spin-orbit constant xi: Delta/xi, V/xi and E0/xi are dimensionless ratios, as are g, k, the orbital coefficients and beta. The exact Hamiltonian (t2g_hamiltonian(), solve_t2g_hole()) takes the crystal-field matrix and xi in any one energy unit and returns energies in that unit (xi=1, the default, is DLSD5’s convention). Multiply a ratio by xi in the unit you want, e.g. delta * lft.units.convert_energy(xi_cm, 'cm^-1', 'MHz'). Angles (the trigonal twist) are in radians; degrees=True takes Telser-style input.

Contents#

Forward, exact Hamiltonian: t2g_hamiltonian() (H = CF (x) 1 + xi L.S in (xy, xz, yz) x (alpha, beta)), solve_t2g_hole() (-> HoleState: abs(g) principal values, g g^T, det g, the three Kramers-doublet energies and the hole orbital populations), tetragonal_cf(), trigonal_cf(). The hole is the HIGHEST doublet, a projector computed with torchspin.lft._linalg.ground_manifold on -H, so the derivative is exact at the Kramers degeneracy; g g^T = 2 tr(P mu_i P mu_j) and det g = -4i tr(P mu_x P mu_y P mu_z) are gauge invariant.

Forward, McGarvey closed forms: g_from_abc(), ligand_field_from_abc(), abc_to_ABC(), ABC_to_abc(), trigonal_g_from_coefficients(), trigonal_delta_from_coefficients(), epi_from_twist(), from_complex_coefficients(), from_real_coefficients() (both signs of the third coefficient; DLSD5’s normalization and the axis relabeling are decided on detached values), trigonal_from_coefficients().

Inverse (g -> ligand field), every branch: tetragonal_from_g() and trigonal_from_g() run the NumPy solver (copied into torchspin.lft._engines.dlsd5) on DETACHED values; its discrete outcomes (which branches, which sign/permutation of g, which relabeling) are taken as given. The derivative is attached to each converged branch by the implicit-function theorem (implicit_attach()): with unknowns x and data theta solving F(x, theta) = 0:

x = x* - J^-1 (F(x*, theta) - F(x*, theta).detach()),     J = dF/dx at x* (detached)

which has the value x* exactly and the derivative dx/dtheta = -J^-1 dF/dtheta, in reverse and forward mode (torch.autograd.forward_ad; not under torch.func transforms, since the solver runs in NumPy).

  • tetragonal: x = (a, b, c, k), F = (g_from_abc(a, b, c, k) - s o P g, a^2 + b^2 + c^2 - 1), where s o P g is the signed, permuted assignment of the input abs(g) that the branch reproduces.

  • trigonal: x = k (fix=”beta”) or beta (fix=”k”), F = g_perp(at(x), bt(x), …) + abs(g_perp), with at^2 from g_par. theta = (g_par, g_perp, the fixed beta or k).

Derived quantities (Delta/xi, V/xi, E0/xi, weights, epi) follow by plain autograd. At a branch where J is singular (a fold of the g map) no derivative exists: the result is inf/nan.

Not ported: the DLSD5 CLI and reports. HoleState.g_axes and the signed g matrix of the NumPy version are gauge dependent; use ggT and g_det.

Examples

The two tetragonal/rhombic branches for g = 2.62, 2.38, 1.60 (telser-tools’ DLSD5 quick start), with derivatives with respect to the g values:

>>> import torch
>>> from torchspin.lft import dlsd5
>>> g = torch.tensor([2.62, 2.38, 1.60], dtype=torch.float64, requires_grad=True)
>>> branches = dlsd5.tetragonal_from_g(*g)
>>> for b in branches:
...     print(b.numpy.label, round(b.delta.item(), 4), round(b.v.item(), 4), round(b.k.item(), 4))
#1 (gz = -g3) 0.3069 0.0994 1.1689
#2 (gz = +g3) 2.9743 0.9625 0.895
>>> (dDelta_dg,) = torch.autograd.grad(branches[1].delta, g)

The forward check: the exact t2g Hamiltonian of branch 2 (Delta = 3, V = 1, k = 0.9, in units of xi) gives g close to the input:

>>> st = dlsd5.solve_t2g_hole(dlsd5.tetragonal_cf(3.0, 1.0), k=0.9)
>>> [round(x, 3) for x in st.g_principal.tolist()]
[1.605, 2.378, 2.624]
torchspin.lft.dlsd5.BETA_OCT = 0.5773502691896258#

Octahedral beta = 1/sqrt3 (no t2g/eg mixing), the trigonal default.

torchspin.lft.dlsd5.ABC_to_abc(A, B, C)[source]#

Real-orbital coefficients (xy, yz, xz) = (A, B, C) -> (d+1, xy, d-1) = (a, b, c).

class torchspin.lft.dlsd5.CoefficientSolution(a, b, c, k, g, delta, v, e0, numpy)[source]#

Forward result for one sign of the third coefficient (from_complex_coefficients(), from_real_coefficients()).

Variables:
  • c (a, b,) – Hole coefficients of (d+1, xy, d-1) after normalization and relabeling.

  • k (Tensor) – Orbital reduction factor.

  • g (Tensor, shape (3,)) – Signed (gx, gy, gz).

  • e0 (delta, v,) – Delta/xi, V/xi, E0/xi.

  • numpy (object) – The NumPy solution.

a: Tensor#

Alias for field number 0

b: Tensor#

Alias for field number 1

c: Tensor#

Alias for field number 2

k: Tensor#

Alias for field number 3

g: Tensor#

Alias for field number 4

delta: Tensor#

Alias for field number 5

v: Tensor#

Alias for field number 6

e0: Tensor#

Alias for field number 7

numpy: object#

Alias for field number 8

class torchspin.lft.dlsd5.HoleState(g_principal, ggT, g_det, doublet_energies, hole_weights, projector, gap)[source]#

The t2g^5 hole (highest) Kramers doublet of CF + xi L.S (solve_t2g_hole()).

Variables:
  • g_principal (Tensor, shape (..., 3)) – Principal values abs(g), ascending.

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

  • g_det (Tensor, shape (...)) – det g; its sign (g_sign_product) is the only g sign EPR can reach.

  • doublet_energies (Tensor, shape (..., 3)) – The three Kramers-doublet energies, ascending, in the unit of the crystal field.

  • hole_weights (Tensor, shape (..., 3)) – Hole populations of (xy, xz, yz).

  • projector (Tensor, shape (..., 6, 6)) – Projector onto the hole doublet.

  • gap (Tensor, shape (...)) – Gap from the hole doublet down to the next one (the derivative scales as 1/gap).

g_principal: Tensor#

Alias for field number 0

ggT: Tensor#

Alias for field number 1

g_det: Tensor#

Alias for field number 2

doublet_energies: Tensor#

Alias for field number 3

hole_weights: Tensor#

Alias for field number 4

projector: Tensor#

Alias for field number 5

gap: Tensor#

Alias for field number 6

property g_sign_product: Tensor[source]#

Sign of det g (detached).

property hole_energy: Tensor[source]#

Energy of the hole (highest) doublet, doublet_energies[..., -1].

class torchspin.lft.dlsd5.TetragonalBranch(a, b, c, k, g, delta, v, e0, weights, perm, sign, numpy)[source]#

One converged solution of tetragonal_from_g(), with tensors attached to the input g.

Variables:
  • c (a, b,) – Hole coefficients of (d+1, xy, d-1).

  • k (Tensor) – Orbital reduction factor.

  • g (Tensor, shape (3,)) – Signed (gx, gy, gz) of the solution.

  • e0 (delta, v,) – Delta/xi, V/xi and E0/xi (units of xi).

  • weights (Tensor, shape (3,)) – (xy, yz, xz) populations (A^2, B^2, C^2).

  • sign (perm,) – Map from the solution’s (gx, gy, gz) to the input: g_sol[i] = sign[i] * abs(g_in[perm[i]]).

  • numpy (object) – The NumPy TetragonalSolution (label, ground_doublet, notes, …).

a: Tensor#

Alias for field number 0

b: Tensor#

Alias for field number 1

c: Tensor#

Alias for field number 2

k: Tensor#

Alias for field number 3

g: Tensor#

Alias for field number 4

delta: Tensor#

Alias for field number 5

v: Tensor#

Alias for field number 6

e0: Tensor#

Alias for field number 7

weights: Tensor#

Alias for field number 8

perm: tuple[int, int, int]#

Alias for field number 9

sign: tuple[float, float, float]#

Alias for field number 10

numpy: object#

Alias for field number 11

property ABC[source]#

Real-orbital coefficients (xy, yz, xz) of the hole.

class torchspin.lft.dlsd5.TrigonalBranch(at, bt, k, beta, g_perp, g_par, delta, epi, numpy)[source]#

One converged solution of trigonal_from_g().

Variables:
  • bt (at,) – Hole coefficients of the trigonal basis.

  • beta (k,) – Orbital reduction factor and t2g/eg mixing coefficient (one of them was fixed).

  • g_par (g_perp,) – Signed g values of the solution.

  • delta (Tensor) – Delta/xi.

  • epi (Tensor or None) – E_pi/xi, only with a nonzero twist.

  • numpy (object) – The NumPy solution (label, …).

at: Tensor#

Alias for field number 0

bt: Tensor#

Alias for field number 1

k: Tensor#

Alias for field number 2

beta: Tensor#

Alias for field number 3

g_perp: Tensor#

Alias for field number 4

g_par: Tensor#

Alias for field number 5

delta: Tensor#

Alias for field number 6

epi: Tensor | None#

Alias for field number 7

numpy: object#

Alias for field number 8

torchspin.lft.dlsd5.abc_to_ABC(a, b, c)[source]#

Hole coefficients (d+1, xy, d-1) = (a, b, c) -> real-orbital (xy, yz, xz) = (A, B, C) (McGarvey eq. 10).

torchspin.lft.dlsd5.epi_from_twist(delta, phi, degrees=False)[source]#

Pi-bonding parameter from the trigonal twist: E_pi/xi = Delta / (3 sin 2 phi).

delta is Delta/xi; phi the ligand twist angle in radians (degrees with degrees=True) (Dolder et al. 2003).

torchspin.lft.dlsd5.from_complex_coefficients(a, b, k, standardize=True)[source]#

The (+c, -c) solutions from the d+1 (a) and dxy (b) coefficients.

DLSD5 option G/tetragonal/a. a, b are normalized as DLSD5 does (the third coefficient follows from normalization); k is the orbital reduction factor; standardize relabels axes as tetragonal_from_g(). Scalar inputs. Returns a pair of CoefficientSolution.

torchspin.lft.dlsd5.from_real_coefficients(A, B, k, standardize=True)[source]#

The (+C, -C) solutions from the dxy (A) and dyz (B) coefficients.

DLSD5 option G/tetragonal/A; otherwise as from_complex_coefficients(). Returns a pair of CoefficientSolution.

torchspin.lft.dlsd5.g_from_abc(a, b, c, k)[source]#

Signed g values from the hole coefficients (McGarvey eq. 4).

Parameters:
  • a (float or Tensor) – Coefficients of d+1, xy and d-1 (normalized: a^2 + b^2 + c^2 = 1).

  • b (float or Tensor) – Coefficients of d+1, xy and d-1 (normalized: a^2 + b^2 + c^2 = 1).

  • c (float or Tensor) – Coefficients of d+1, xy and d-1 (normalized: a^2 + b^2 + c^2 = 1).

  • k (float or Tensor) – Orbital reduction factor.

Returns:

torch.Tensor, shape (…, 3) – Signed (gx, gy, gz).

Return type:

Tensor

torchspin.lft.dlsd5.implicit_attach(F, x_star, theta)[source]#

Attach implicit-function derivatives to a root of F(x, theta) = 0.

Parameters:
  • F (callable) – F(x, theta) -> residuals of shape (N,) for unknowns x of shape (N,); built from plain differentiable torch operations.

  • x_star (Tensor, shape (N,)) – A root (detached here).

  • theta (Tensor) – The data the root depends on (may require grad).

Returns:

torch.Tensor, shape (N,) – Equal to x_star in value, with derivative dx/dtheta = -(dF/dx)^-1 dF/dtheta in reverse and forward mode. Singular dF/dx gives inf/nan derivatives.

Return type:

Tensor

torchspin.lft.dlsd5.ligand_field_from_abc(a, b, c)[source]#

Ligand field implied by the hole wavefunction.

Parameters:
  • a (float or Tensor) – Coefficients of d+1, xy and d-1.

  • b (float or Tensor) – Coefficients of d+1, xy and d-1.

  • c (float or Tensor) – Coefficients of d+1, xy and d-1.

Returns:

torch.Tensor, shape (…, 3) – (Delta/xi, V/xi, E0/xi); inf/nan where b = 0 or a^2 = c^2.

Return type:

Tensor

torchspin.lft.dlsd5.solve_t2g_hole(cf, k=1.0, xi=1.0)[source]#

Exact hole (highest) Kramers doublet of CF + xi L.S and its g tensor.

The Zeeman operator is mu = k L + 2 S.

Parameters:
  • cf (array_like or Tensor, shape (..., 3, 3)) – Real symmetric crystal field in (xy, xz, yz) (tetragonal_cf(), trigonal_cf()).

  • k (float or Tensor, default 1.0) – Orbital reduction factor (Zeeman term only).

  • xi (float or Tensor, default 1.0) – Spin-orbit constant in the unit of cf (1: DLSD5’s units of xi).

Returns:

HoleState – Batched over the leading dimensions of cf, k and xi.

Return type:

HoleState

torchspin.lft.dlsd5.t2g_hamiltonian(cf, xi=1.0)[source]#

t2g^5 Hamiltonian H = CF (x) 1_2 + xi L.S.

Parameters:
  • cf (array_like or Tensor, shape (..., 3, 3)) – Real symmetric crystal field in (xy, xz, yz).

  • xi (float or Tensor, default 1.0) – Spin-orbit constant in the unit of cf (1: DLSD5’s units of xi).

Returns:

torch.Tensor, shape (…, 6, 6), complex128 – In (xy, xz, yz) x (alpha, beta), in the unit of cf and xi.

Return type:

Tensor

torchspin.lft.dlsd5.tetragonal_cf(delta, v)[source]#

Tetragonal/rhombic t2g crystal field diag(Delta, V/2, -V/2) in (xy, xz, yz).

Parameters:
  • delta (float or Tensor) – Delta = E(xy) relative to the xz/yz barycenter, V = E(xz) - E(yz); any one energy unit (units of xi in DLSD5). Broadcast against each other.

  • v (float or Tensor) – Delta = E(xy) relative to the xz/yz barycenter, V = E(xz) - E(yz); any one energy unit (units of xi in DLSD5). Broadcast against each other.

Returns:

torch.Tensor, shape (…, 3, 3), float64 – In the unit of delta and v.

Return type:

Tensor

torchspin.lft.dlsd5.tetragonal_from_g(g1, g2, g3, mode='mcgarvey', standardize=True, max_iter=2000)[source]#

Every branch of DLSD5’s tetragonal/rhombic inverse, differentiable in the g values.

Parameters:
  • g1 (float or 0-d torch.Tensor) – The three g values; only their magnitudes are used.

  • g2 (float or 0-d torch.Tensor) – The three g values; only their magnitudes are used.

  • g3 (float or 0-d torch.Tensor) – The three g values; only their magnitudes are used.

  • mode ({'mcgarvey', 'dlsd5', 'all'}, default 'mcgarvey') – 'mcgarvey' (alias 'dlsd5'): McGarvey’s two assignments (g1 >= g2 >= g3 required); 'all': every assignment and sign pattern.

  • standardize (bool, default True) – Relabel axes so that abs(V/Delta) <= 2/3.

  • max_iter (int, default 2000) – Iteration cap of the NumPy solver.

Returns:

list – One entry per branch: a TetragonalBranch when it converged with a defined ligand field, otherwise the bare NumPy solution (no solution, b = 0, a^2 = c^2).

Raises:

ValueError – If the g values are not scalars (the branch structure is per point), or as the NumPy solver raises for invalid input.

Return type:

list[TetragonalBranch | object]

torchspin.lft.dlsd5.trigonal_cf(delta)[source]#

Trigonal t2g crystal field Delta (|a1><a1| - 1/3) (octahedral beta).

a1 = (xy + xz + yz)/sqrt(3), so E(a1) - E(e) = Delta.

Parameters:

delta (float or Tensor, shape (...)) – Trigonal splitting in any energy unit.

Returns:

torch.Tensor, shape (…, 3, 3), float64 – In (xy, xz, yz), in the unit of delta.

Return type:

Tensor

torchspin.lft.dlsd5.trigonal_delta_from_coefficients(at, bt, beta)[source]#

Trigonal splitting Delta/xi = E(a1) - E(e) from the hole coefficients at, bt and beta.

torchspin.lft.dlsd5.trigonal_from_coefficients(at, k, beta=BETA_OCT)[source]#

Trigonal g values and splitting for both signs of bt.

Parameters:
  • at (float or Tensor) – Hole coefficient, abs(at) <= 1; bt = +-sqrt(1 - at^2).

  • k (float or Tensor) – Orbital reduction factor.

  • beta (float or torch.Tensor, default BETA_OCT) – t2g/eg mixing coefficient.

Returns:

torch.Tensor, shape (…, 2, 3) – Rows for bt > 0 and bt < 0, columns (g_perp, g_par, Delta/xi).

Return type:

Tensor

torchspin.lft.dlsd5.trigonal_from_g(g_par, g_perp, *, fix='beta', beta=BETA_OCT, k=1.0, twist=None, degrees=False, max_iter=100)[source]#

Both branches (g_par < 0, g_par > 0) of DLSD5’s trigonal inverse, differentiable.

Parameters:
  • g_par (float or 0-d torch.Tensor) – Measured g values (magnitudes are used).

  • g_perp (float or 0-d torch.Tensor) – Measured g values (magnitudes are used).

  • fix ({'beta', 'k'}, default 'beta') – Which parameter is held fixed; the other is solved for.

  • beta (float or torch.Tensor, default BETA_OCT) – t2g/eg mixing coefficient used when fix='beta'.

  • k (float or Tensor, default 1.0) – Orbital reduction factor used when fix='k'.

  • twist (float or Tensor, optional) – Ligand twist angle phi (radians; degrees with degrees=True); with a nonzero twist each branch carries E_pi/xi (Dolder et al. 2003).

  • degrees (bool, default False) – Angle unit of twist.

  • max_iter (int, default 100) – Iteration cap of the NumPy solver.

Returns:

list – TrigonalBranch per converged branch, differentiable in g_par, g_perp, the fixed parameter and twist; the bare NumPy solution otherwise.

Return type:

list[TrigonalBranch | object]

Examples

>>> from torchspin.lft import dlsd5
>>> for b in dlsd5.trigonal_from_g(1.75, 1.10):
...     print(b.numpy.label, round(float(b.k), 3), round(float(b.delta), 3))
#1 (g_par < 0) 0.494 -0.324
#2 (g_par > 0) -0.8 2.332
torchspin.lft.dlsd5.trigonal_g_from_coefficients(at, bt, k, beta)[source]#

Signed trigonal g values from the hole coefficients.

Parameters:
  • at (float or Tensor) – Hole coefficients of the trigonal basis (at^2 + bt^2 = 1).

  • bt (float or Tensor) – Hole coefficients of the trigonal basis (at^2 + bt^2 = 1).

  • k (float or Tensor) – Orbital reduction factor.

  • beta (float or Tensor) – t2g/eg mixing coefficient (BETA_OCT = 1/sqrt(3): no mixing).

Returns:

torch.Tensor, shape (…, 2) – Signed (g_perp, g_par).

Return type:

Tensor