torchspin.lft.dpn#

DPN: differentiable complete-basis p^n ligand-field Hamiltonian, levels, and doublet g tensor.

H = A n(n-1)/2 + F2 (c2 + n(n-1)/25) + alpha L^2 + sum_ab V[a, b] E_real[a, b]
  • zeta sum_i l_i.s_i + mu_B B . (k L + g_e S)

in the full basis of C(6, n) Slater determinants (Telser’s DPN, via telser-tools), n = 0..6 (no hole formalism: p^n and p^(6-n) are computed directly). Every parameter may be a tensor carrying gradients, with leading batch dimensions.

F2 is the Slater integral F^2 (DPN’s “F2”, not the Condon-Shortley F_2 = F^2/25). The diagonal is measured from the configuration’s e-e barycenter: A = F^0 - 2 F^2/25 (the average repulsion of one p-p pair) defaults to 0, which reproduces DPN’s absolute energies. For p^2: 3P = -3/25 F2, 1D = +3/25 F2, 1S = +12/25 F2.

Ligand fields are real symmetric 3x3 matrices in the real-orbital basis (px, py, pz) (DPN’s order, geometric phase convention): crystal_field() (Ds, Dr), orbital_energies(), the AOM (aom_from_angles(), aom_from_frames(), aom_isotropic(), aom()), and to_m_basis(). These are p-shell constructors; torchspin.lft.aom and torchspin.lft.crystal_field are the d-shell ones.

Units#

Energy-valued inputs (F2, zeta, alpha, A, the ligand field V / V_m) and energy-valued outputs are in units (default 'MHz'; 'cm^-1', 'GHz', 'K', 'eV' via torchspin.lft.units). The magnetic field is in mT. The orbital reduction k is dimensionless. AOM bonding parameters pass straight through to the matrix (it is in their unit). Angles in radians (degrees=True for Telser-style input). Internally cm^-1.

>>> from torchspin.lft import dpn
>>> E = dpn.levels(2, F2=46000.0, zeta=28.0, units='cm^-1', relative=True)   # C I 2p2
>>> [round(float(x), 1) for x in E[[0, 1, 4, 9, 14]]]
[0.0, 14.1, 42.0, 11068.1, 27628.1]
>>> V = dpn.aom_isotropic([[0.0, 0.0, 1.0]], 1000.0)                            # one axial sigma donor
>>> g = dpn.g_tensor(1, zeta=300.0, V=V, units='cm^-1')

DPN’s own matrix#

dpn_hamiltonian() reproduces what the compiled DPN / DPNFIT diagonalize: the hole route for n > 3 (with -V and -abs(zeta)), the mirror-image AOM for p^1/p^2, the dropped <+-1|V|0> elements of the AOM (finding DPN-01), DPN’s vs DPNFIT’s hole signs, and DPNFIT’s Zeeman defect (DPNFIT-01). It defaults to DPN’s own constants (DPN_CONSTANTS).

Not ported: the DPN input reader, report and term-basis printout, and DPN’s EPR / optical transition probabilities (phase dependent).

torchspin.lft.dpn.DPN_CONSTANTS = (0.00046686437, 2.002319304386, 0.69503877)#

DPN’s own constants (DPN.F ll. 69-71, DPNIO.F l. 41; the same as DDN’s), mu_B in cm^-1 per mT.

class torchspin.lft.dpn.Constants(mu_b, g_e, k_b)[source]#

Physical constants used by the d^n Hamiltonian.

Variables:
  • mu_b (float) – Bohr magneton over h c, in cm^-1 per mT.

  • g_e (float) – Free-electron g value (dimensionless).

  • k_b (float) – Boltzmann constant over h c, in cm^-1 per K.

mu_b: float#

Alias for field number 0

g_e: float#

Alias for field number 1

k_b: float#

Alias for field number 2

class torchspin.lft.dpn.GTensor(ggT, principal, g, gap)[source]#

Effective spin-1/2 g tensor of the lowest doublet (returned by g_tensor()).

Variables:
  • ggT (Tensor, shape (..., 3, 3)) – g g^T in the molecular frame.

  • principal (Tensor, shape (..., 3)) – Principal g values (square roots of the eigenvalues of ggT), ascending.

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

  • gap (Tensor, shape (...)) – Energy from the doublet to the next state, in the units of the call. Gradients of g scale as 1/gap: check that it is large.

ggT: Tensor#

Alias for field number 0

principal: Tensor#

Alias for field number 1

g: Tensor#

Alias for field number 2

gap: Tensor#

Alias for field number 3

class torchspin.lft.dpn.PnOperators(n, pairs, coulomb_bary, exc_m, lf_real, so, L, S, L2, S2, term_projectors, defect_terms)[source]#

Torch constants of p^n (nd = C(6, n) determinants), returned by pn_operators().

Variables:
  • n (int) – Number of p electrons.

  • pairs (int) – n(n-1)/2, the coefficient of A on the diagonal.

  • coulomb_bary (Tensor, shape (nd, nd), float64) – F^2 coefficient measured from the barycenter, c2 + n(n-1)/25.

  • exc_m (Tensor, shape (3, 3, nd, nd), float64) – Excitation operators E[m, m'] in the m = -1, 0, 1 basis.

  • lf_real (Tensor, shape (3, 3, nd, nd), complex128) – E_real[a, b] in the real-orbital basis (px, py, pz).

  • S2 (so, L2,) – sum_i l_i.s_i, L^2 and S^2.

  • S (L,) – Total orbital and spin angular momentum.

  • term_projectors (Tensor, shape (nterms, nd, nd), float64) – Projectors onto the free-ion terms, DPN term order.

  • defect_terms (Tensor, shape (nterms,), bool) – Terms with L = 0 or S = 0 (DPNFIT’s Zeeman defect).

  • size (int) – Property: nd.

  • terms (list) – Property: the free-ion terms (label, L, S) in DPN order.

class torchspin.lft.dpn.PnSystem(n, *, units='MHz', constants=TORCHSPIN_CONSTANTS, device='cpu')[source]#

A p^n ion with cached operators.

PnSystem(n).levels(...), .g_tensor(...), .hamiltonian(...) and .zeeman_operators(k) call the module functions with the cached operators; units and constants set here are the defaults of every call (override per call).

Parameters:
  • n (int) – Number of p electrons, 0 to 6.

  • units (str, default 'MHz') – Default energy unit.

  • constants (Constants, default TORCHSPIN_CONSTANTS) – Default constants.

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

Variables:
  • size (int) – Basis size C(6, n).

  • terms (list) – Free-ion terms in DPN order.

Examples

>>> from torchspin.lft import dpn
>>> ion = dpn.PnSystem(3, units='cm^-1')
>>> ion.size, ion.levels(F2=40000.0).shape
(20, torch.Size([20]))
torchspin.lft.dpn.aom(ligands, device=None)[source]#

p-shell AOM ligand field from torchspin.lft.ligand_field.Ligand objects.

Uses the ligands’ angles (radians) and e_sigma, e_pi_x, e_pi_y.

Parameters:
  • ligands (iterable of Ligand) – The ligands; an empty iterable gives a zero field.

  • device (str or device, optional) – Device of the result.

Returns:

torch.Tensor, shape (3, 3) – Real-orbital field (px, py, pz) in the unit of the bonding parameters.

Raises:

ValueError – If a ligand has nonzero e_delta_x2y2 or e_delta_xy (p orbitals have no delta bonding; DPNFIT accepts NLAM = 5 and silently corrupts the field, finding DPNFIT-03).

Return type:

Tensor

torchspin.lft.dpn.aom_from_angles(theta, phi, psi, e, degrees=False)[source]#

p-shell AOM ligand field from per-ligand Euler angles.

Frame R = Rz(phi) Ry(theta) Rz(psi) (torchspin.lft.ligand_field.rotation()). DPN’s “pi-c (x)” and “pi-s (y)” are e_pi_x and e_pi_y.

Parameters:
  • theta (array_like or Tensor, shape (..., nlig)) – Ligand angles, radians unless degrees.

  • phi (array_like or Tensor, shape (..., nlig)) – Ligand angles, radians unless degrees.

  • psi (array_like or Tensor, shape (..., nlig)) – Ligand angles, radians unless degrees.

  • e (array_like or Tensor, shape (..., nlig, 3)) – (e_sigma, e_pi_x, e_pi_y), any energy unit.

  • degrees (bool, default False) – Angles in degrees.

Returns:

torch.Tensor, shape (…, 3, 3) – Real-orbital field (px, py, pz) in the unit of e.

Return type:

Tensor

torchspin.lft.dpn.aom_from_frames(R, e)[source]#

p-shell AOM ligand field from ligand frames.

V = sum_L e_sigma z'z'^T + e_pi_x x'x'^T + e_pi_y y'y'^T.

Parameters:
  • R (Tensor, shape (..., nlig, 3, 3)) – Ligand frames, columns x', y', z' (z' from metal to ligand).

  • e (array_like or Tensor, shape (..., nlig, 3)) – Bonding parameters (e_sigma, e_pi_x, e_pi_y), any energy unit.

Returns:

torch.Tensor, shape (…, 3, 3) – Real-orbital field (px, py, pz) in the unit of e.

Return type:

Tensor

torchspin.lft.dpn.aom_isotropic(n, e_sigma, e_pi=0.0)[source]#

p-shell AOM ligand field from bond vectors with cylindrical pi bonding.

V = sum_L e_sigma n n^T + e_pi (I - n n^T); smooth in n everywhere (no Euler angles).

Parameters:
  • n (array_like or Tensor, shape (..., nlig, 3)) – Metal-to-ligand bond vectors (normalized here).

  • e_sigma (float or array_like or Tensor) – Bonding parameters, broadcast against (…, nlig); e_pi default 0.

  • e_pi (float or array_like or Tensor) – Bonding parameters, broadcast against (…, nlig); e_pi default 0.

Returns:

torch.Tensor, shape (…, 3, 3) – Real-orbital field (px, py, pz) in the unit of e_sigma.

Return type:

Tensor

Examples

>>> from torchspin.lft import dpn
>>> dpn.aom_isotropic([[0.0, 0.0, 1.0]], 1000.0).diagonal().tolist()
[0.0, 0.0, 1000.0]
torchspin.lft.dpn.crystal_field(Ds=0.0, Dr=0.0)[source]#

Ballhausen-style axial (Ds) and rhombic (Dr) p-shell ligand field (DPNIO.F ll. 235-237).

In the |m> basis: <+-1|V|+-1> = Ds, <0|V|0> = -2 Ds, <1|V|-1> = Dr; in real orbitals diag(Ds - Dr, Ds + Dr, -2 Ds). A cubic field does not split p orbitals (no Dq).

Parameters:
  • Ds (float or Tensor, default 0.0) – Axial and rhombic parameters (any energy unit; broadcast).

  • Dr (float or Tensor, default 0.0) – Axial and rhombic parameters (any energy unit; broadcast).

Returns:

torch.Tensor, shape (…, 3, 3), float64 – Real-orbital field (px, py, pz) in the unit of Ds/Dr.

Return type:

Tensor

Examples

>>> from torchspin.lft import dpn
>>> dpn.crystal_field(Ds=100.0, Dr=10.0).diagonal().tolist()
[90.0, 110.0, -200.0]
torchspin.lft.dpn.dpn_hamiltonian(n, *, F2=0.0, zeta=0.0, V=None, k=(1.0, 1.0, 1.0), alpha=0.0, field=None, lf_type='X', program='dpn', drop_o21=True, zeeman_defect=None, units='MHz', constants=DPN_CONSTANTS, device='cpu')[source]#

The matrix DPN (program='dpn') or DPNFIT ('dpnfit') diagonalizes.

Reproduces the compiled programs (module docstring). For n > 3 this is the p^(6-n) hole problem with -V and -abs(zeta) (DPN flips only the real part of the |m> field, DPNFIT all of it), so the basis size is C(6, 6 - n) (= C(6, n)).

Parameters:
  • n (int) – Number of p electrons, 0 to 6.

  • F2 (float or Tensor, default 0.0) – Slater F^2, spin-orbit constant (enters as abs(zeta)) and Trees correction, in units.

  • zeta (float or Tensor, default 0.0) – Slater F^2, spin-orbit constant (enters as abs(zeta)) and Trees correction, in units.

  • alpha (float or Tensor, default 0.0) – Slater F^2, spin-orbit constant (enters as abs(zeta)) and Trees correction, in units.

  • V (array_like or Tensor, shape (..., 3, 3), optional) – Real-orbital ligand field (px, py, pz) in units.

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

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

  • lf_type ({'X', 'A', 'P'}, default 'X') – As internal_m_matrix() (crystal field, AOM, orbital energies).

  • program ({'dpn', 'dpnfit'}, default 'dpn') – Which program to reproduce.

  • drop_o21 (bool, default True) – Drop the <+-1|V|0> AOM elements (DPN-01).

  • zeeman_defect (bool, optional) – Remove the diagonal B_z Zeeman elements of terms with L = 0 or S = 0 (DPNFIT-01). Default None: True for program='dpnfit'.

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

  • constants (Constants, default DPN_CONSTANTS) – DPN’s own constants.

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

Returns:

torch.Tensor, shape (…, nd, nd), complex128 – In units.

Raises:

ValueError – If program is not 'dpn' or 'dpnfit'.

Return type:

Tensor

torchspin.lft.dpn.field_vector(B0, theta=0.0, phi=0.0, degrees=False)[source]#

Field vector of magnitude B0 along polar angle theta and azimuth phi.

Parameters:
  • B0 (float or array_like or Tensor) – Field magnitude (any field unit; the simulators take mT).

  • theta (float or array_like or Tensor, default 0.0) – Direction, radians unless degrees. Broadcast with B0.

  • phi (float or array_like or Tensor, default 0.0) – Direction, radians unless degrees. Broadcast with B0.

  • degrees (bool, default False) – Angles in degrees.

Returns:

torch.Tensor, shape broadcast + (3,), float64 – B0 (sin t cos p, sin t sin p, cos t).

Return type:

Tensor

Examples

>>> from torchspin.lft import dpn
>>> dpn.field_vector(350.0, 90.0, 90.0, degrees=True).round(decimals=6).tolist()
[0.0, 350.0, 0.0]
torchspin.lft.dpn.g_tensor(n, *, k=(1.0, 1.0, 1.0), units='MHz', constants=TORCHSPIN_CONSTANTS, device='cpu', **kw)[source]#

Zero-field effective spin-1/2 g tensor of the lowest doublet of p^n.

(g g^T)_ij = 2 tr(P mu_i P mu_j) with P the projector onto the two lowest states.

Parameters:
  • n (int or PnOperators) – Number of p electrons (0 to 6) or cached operators.

  • k (array_like or Tensor, shape (..., 3), default (1.0, 1.0, 1.0)) – Orbital reduction factors.

  • units (str, default 'MHz') – Energy unit of the Hamiltonian keywords and of gap.

  • constants (Constants, default TORCHSPIN_CONSTANTS) – g_e of the moment operator.

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

  • **kw – Keywords of hamiltonian() except field.

Returns:

torchspin.lft.ddn.GTensor – ggT, principal (ascending), g and gap (units).

Raises:
Return type:

GTensor

Notes

Meaningful for odd n (Kramers doublets) or any isolated ground doublet; check gap (for p^3 the 4S ground quartet splits only by second-order effects).

Examples

p^1 with one axial sigma donor (cm^-1):

>>> from torchspin.lft import dpn
>>> V = dpn.aom_isotropic([[0.0, 0.0, 1.0]], 1000.0)
>>> res = dpn.g_tensor(1, zeta=300.0, V=V, units='cm^-1')
>>> res.principal.shape
torch.Size([3])
torchspin.lft.dpn.hamiltonian(n, *, F2=0.0, zeta=0.0, A=0.0, alpha=0.0, V=None, V_m=None, k=(1.0, 1.0, 1.0), field=None, units='MHz', constants=TORCHSPIN_CONSTANTS, device='cpu')[source]#

Complex Hermitian p^n Hamiltonian in the full determinant basis.

Parameters:
  • n (int or PnOperators) – Number of p electrons (0 to 6) or cached operators.

  • F2 (float or Tensor, default 0.0) – Slater integral F^2 (DPN’s “F2”, not F_2 = F^2/25), in units.

  • zeta (float or Tensor, default 0.0) – One-electron spin-orbit coupling constant, in units.

  • A (float or Tensor, default 0.0) – F^0 - 2 F^2/25, a uniform shift A n(n-1)/2; 0 reproduces DPN’s absolute energies. In units.

  • alpha (float or Tensor, default 0.0) – Trees correction (coefficient of L^2), in units.

  • V (array_like or Tensor, shape (..., 3, 3), optional) – Real symmetric ligand field in the real-orbital basis (px, py, pz), in units.

  • V_m (array_like or Tensor, shape (..., 3, 3), optional) – A ligand field given directly in the m = -1, 0, 1 basis (complex; need not be time-even), in units.

  • k (array_like or Tensor, shape (..., 3), default (1.0, 1.0, 1.0)) – Orbital reduction factors; enter only the Zeeman term.

  • field (array_like or Tensor, shape (..., 3), optional) – Magnetic field vector in mT. Default None: zero field.

  • units (str, default 'MHz') – Energy unit of the inputs and the result ('MHz', 'GHz', 'cm^-1', 'K', 'eV', …).

  • constants (Constants, default TORCHSPIN_CONSTANTS) – mu_B and g_e.

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

Returns:

torch.Tensor, shape (…, nd, nd), complex128 – In units, nd = C(6, n).

Raises:

ValueError – If n is not an integer from 0 to 6 or units is unknown.

Return type:

Tensor

Examples

>>> from torchspin.lft import dpn
>>> dpn.hamiltonian(2, F2=46000.0, zeta=28.0, units='cm^-1').shape
torch.Size([15, 15])
torchspin.lft.dpn.internal_m_matrix(V, lf_type='X', drop_o21=True, np_=1)[source]#

The electron-picture |m> field DPN/DPNFIT enter for a (geometric) real-orbital field.

Parameters:
  • V (array_like or Tensor, shape (..., 3, 3)) – Real-orbital ligand field (px, py, pz).

  • lf_type ({'X', 'A', 'P'}, default 'X') – DPN’s ligand-field type: 'X' crystal field and 'P' orbital energies give the geometric matrix; 'A' (AOM) gives, for p^1/p^2 (np_ 1 or 2), the complex conjugate (mirror image y -> -y; p^3 is geometric) and, with drop_o21, <1|V|0> = <0|V|-1> = 0 (finding DPN-01).

  • drop_o21 (bool, default True) – Drop those AOM elements, as DPN does.

  • np_ (int, default 1) – DPN’s NP (n for n <= 3, else 6 - n).

Returns:

torch.Tensor, shape (…, 3, 3), complex128 – The |m> matrix (m = -1, 0, 1), in the unit of V.

Return type:

Tensor

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

Ascending energy levels of p^n.

Parameters:
  • n (int or PnOperators) – Number of p electrons (0 to 6) or cached operators.

  • relative (bool, default False) – Put the ground state at 0.

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

  • **kw – Keywords of hamiltonian().

Returns:

torch.Tensor, shape (…, nd), float64 – Eigenvalues in units, ascending.

Return type:

Tensor

Notes

The gradient of a degenerate eigenvalue is that of its level’s mean (exact for the Kramers and orbital degeneracies of p^n).

Examples

Spin-orbit splitting of the 2P term of p^1 is 1.5 zeta:

>>> from torchspin.lft import dpn
>>> E = dpn.levels(1, zeta=100.0, units='cm^-1', relative=True)
>>> [round(float(x), 6) for x in E]
[0.0, 0.0, 150.0, 150.0, 150.0, 150.0]
torchspin.lft.dpn.orbital_energies(e)[source]#

Diagonal real-orbital ligand field from p-orbital energies (DPN option P).

Parameters:

e (array_like or Tensor, shape (..., 3)) – (E(px), E(py), E(pz)), any energy unit.

Returns:

torch.Tensor, shape (…, 3, 3)

Return type:

Tensor

torchspin.lft.dpn.pn_operators(n, device='cpu')[source]#

Cached torch operators of p^n on device.

Parameters:
  • n (int) – Number of p electrons, 0 to 6.

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

Returns:

PnOperators

Raises:

ValueError – If n is not an integer from 0 to 6.

Return type:

PnOperators

Examples

>>> from torchspin.lft import dpn
>>> dpn.pn_operators(2).size
15
torchspin.lft.dpn.to_m_basis(V)[source]#

Convert a real-orbital (px, py, pz) matrix to the m = -1, 0, 1 basis, U V U^+.

Parameters:

V (array_like or Tensor, shape (..., 3, 3)) – Real-orbital matrix, any unit.

Returns:

torch.Tensor, shape (…, 3, 3), complex128

Return type:

Tensor

torchspin.lft.dpn.zeeman_operators(n, k=(1.0, 1.0, 1.0), constants=TORCHSPIN_CONSTANTS, device='cpu')[source]#

Magnetic moment operators in Bohr magnetons, k_i L_i + g_e S_i.

Parameters:
  • n (int or PnOperators) – Number of p electrons (0 to 6) or cached operators.

  • k (array_like or Tensor, shape (..., 3), default (1.0, 1.0, 1.0)) – Orbital reduction factors (dimensionless).

  • constants (Constants, default TORCHSPIN_CONSTANTS) – Supplies g_e.

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

Returns:

torch.Tensor, shape (…, 3, nd, nd), complex128

Return type:

Tensor