torchspin.lft.ddnloop#

DDNLOOP: d^n levels and EPR transitions over field, angle and parameter scans.

Torch port of the numerical core of Josh Telser’s DDNLOOP (via telser-tools, telser_tools_diff.ddnloop), built on torchspin.lft.ddn. For every scan point (field magnitude B, polar angle theta, azimuth phi) the complete d^n Hamiltonian with the field B (sin t cos p, sin t sin p, cos t) is diagonalized (batched over the scan), and DDNLOOP’s quantities are returned as tensors (data for Zeeman and angle diagrams; plots are separate):

  • level energies;

  • Boltzmann factors exp(-(E_i - E_0)/kT), normalized (default) or as DDNLOOP prints them;

  • for the requested pairs (i, j): transition energies E_j - E_i, probabilities (the B1-averaged full magnetic dipole abs(<i|B1.(k L + g_e S)|j>)**2, in mu_B^2), the same summed over the degenerate members of each level, population factors p_i - p_j, DDNLOOP’s microwave weights and g_obs = (E_j - E_i)/(mu_B B).

Every parameter (B, C, A, F^k, zeta, k, alpha, the ligand field V or whatever builds it, such as AOM bond vectors), the temperature and the scan variables themselves may carry gradients.

Units#

Energy-valued inputs (B, C, A, zeta, alpha, slater, V) and the returned energies and transition energies are in units (default 'MHz'; 'cm^-1', 'GHz', 'K', 'eV'). Fields in mT, angles in radians (degrees=True for Telser-style input), temperature in K, microwave frequency in GHz. Probabilities are in mu_B^2, g_obs and populations are dimensionless.

>>> import torch
>>> from torchspin import lft
>>> V = lft.crystal_field(Dq=1500.0, Ds=300.0, Dt=50.0)
>>> res = lft.ddnloop.field_scan(1, torch.linspace(0, 1000, 101), theta=0.3, V=V, zeta=154.0,
...                              units='cm^-1', pairs=[(0, 1)], temperature=4.2, mw_freq=9.5)
>>> res.energies.shape, res.g_obs.shape
(torch.Size([101, 10]), torch.Size([101, 1]))

Gauge. The per-pair probability abs(<i|O|j>)**2 (what DDNLOOP prints) depends on the arbitrary basis inside a degenerate level and has no derivative there: at B > 0 the Zeeman term lifts the Kramers degeneracies, but levels the field leaves degenerate (S = 0 orbital multiplets at special orientations, every level at B = 0) make the per-pair value basis dependent. level_probabilities sums abs(<a|O|b>)**2 over a in level(i), b in level(j) (= tr(P_I O P_J O^+), gauge-invariant and differentiable everywhere off accidental crossings); it equals the per-pair value wherever both levels are non-degenerate. Levels are decided on detached energies with torchspin.lft._linalg.degeneracy_mask.

Not ported (DDN-reproduction conventions of telser-tools’ Options): EPRTRANS (spin-only, eigenvector-phase dependent probabilities, finding DDNLOOP-01), DDN’s hole problem, constants and absolute energy scale (ddn_model), the doubled Boltzmann factor of the population factor (DDNLOOP-03), the 1e-10 output thresholds, the input reader, the listing and the plot. DDN’s mirror-image ligand field (DDNLOOP-02) is available as mirror_image() to apply to V by hand.

class torchspin.lft.ddnloop.LoopResult(theta, phi, fields, directions, energies, vectors, populations, pairs, transition_energies, probabilities, level_probabilities, population_factors, mw_weights, g_obs, units)[source]#

DDNLOOP’s quantities over a scan of shape S (returned by scan()).

Entries are None when not requested: without temperature the populations and population factors, without mw_freq the microwave weights, without pairs every pair quantity. DDNLOOP lists g_obs only with a microwave frequency; here it is always returned with pairs.

Variables:
  • phi (theta,) – Field direction angles in radians.

  • fields (Tensor, shape S) – Field magnitudes in mT.

  • directions (Tensor, shape S + (3,)) – Unit field directions.

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

  • vectors (Tensor, shape S + (N, N)) – Eigenvectors as columns.

  • populations (Tensor or None, shape S + (N,)) – Boltzmann factors (normalized to sum 1, or DDNLOOP’s exp(-(E_i - E_0)/kT)).

  • pairs (tuple of (int, int)) – 0-based pairs (i, j), i < j; P = len(pairs).

  • transition_energies (Tensor or None, shape S + (P,)) – E_j - E_i in units.

  • probabilities (Tensor or None, shape S + (P,)) – Per-pair probabilities in mu_B^2 (basis dependent inside degenerate levels).

  • level_probabilities (Tensor or None, shape S + (P,)) – Probabilities summed over degenerate members (gauge invariant).

  • population_factors (Tensor or None, shape S + (P,)) – p_i - p_j.

  • mw_weights (Tensor or None, shape S + (P,)) – DDNLOOP’s microwave weights P W^2 / (W^2 + (nu - nu_mw)^2) with W = MW_WIDTH_FRACTION * nu_mw (2 %), from the per-pair probability.

  • g_obs (Tensor or None, shape S + (P,)) – (E_j - E_i) / (mu_B B), dimensionless; NaN at B = 0.

  • units (str) – Canonical energy unit of energies and transition_energies.

  • relative (Tensor, shape S + (N,)) – Property: energies with the ground state of every scan point at 0.

theta: Tensor#

Alias for field number 0

phi: Tensor#

Alias for field number 1

fields: Tensor#

Alias for field number 2

directions: Tensor#

Alias for field number 3

energies: Tensor#

Alias for field number 4

vectors: Tensor#

Alias for field number 5

populations: Tensor | None#

Alias for field number 6

pairs: tuple[tuple[int, int], ...]#

Alias for field number 7

transition_energies: Tensor | None#

Alias for field number 8

probabilities: Tensor | None#

Alias for field number 9

level_probabilities: Tensor | None#

Alias for field number 10

population_factors: Tensor | None#

Alias for field number 11

mw_weights: Tensor | None#

Alias for field number 12

g_obs: Tensor | None#

Alias for field number 13

units: str#

Alias for field number 14

property relative: Tensor[source]#

Energies with the ground state of every scan point at 0.

torchspin.lft.ddnloop.MW_WIDTH_FRACTION = 0.02#

DDNLOOP’s microwave weight is P W^2 / (W^2 + (nu - nu_mw)^2) with W = 2 % of nu_mw.

torchspin.lft.ddnloop.angle_scan(n, field, theta, phi=0.0, *, mesh=True, **kw)[source]#

Angle-diagram data: scan() at a fixed field magnitude over directions.

Parameters:
  • n (int or DnOperators) – Number of d electrons or cached operators.

  • field (float or Tensor) – Field magnitude in mT.

  • theta (array_like or Tensor) – Directions (radians unless degrees=True); phi defaults to 0.

  • phi (array_like or Tensor) – Directions (radians unless degrees=True); phi defaults to 0.

  • mesh (bool, default True) – True: scan shape (n_theta, n_phi) from 1-D theta and phi. False: theta and phi are broadcast (e.g. a path through orientation space).

  • **kw – Further keywords of scan().

Returns:

LoopResult

Return type:

LoopResult

Examples

>>> import torch
>>> from torchspin import lft
>>> res = lft.ddnloop.angle_scan(1, 350.0, torch.linspace(0, 90, 7), [0.0, 45.0], degrees=True,
...                              V=lft.crystal_field(Dq=1500.0, Ds=300.0), zeta=154.0, units='cm^-1')
>>> res.energies.shape
torch.Size([7, 2, 10])
torchspin.lft.ddnloop.directions(theta, phi, *, degrees=False)[source]#

Unit field directions (sin t cos p, sin t sin p, cos t).

Parameters:
  • theta (float or array_like or Tensor) – Polar and azimuthal angles, broadcast together; radians unless degrees.

  • phi (float or array_like or Tensor) – Polar and azimuthal angles, broadcast together; radians unless degrees.

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

Returns:

torch.Tensor, shape broadcast(theta, phi) + (3,), float64 – Unit vectors in the molecular frame.

Return type:

Tensor

Examples

>>> from torchspin import lft
>>> lft.ddnloop.directions(90.0, 0.0, degrees=True).round(decimals=6).tolist()
[1.0, 0.0, 0.0]
torchspin.lft.ddnloop.exact_probabilities(elements, dirs, h1mode=0.0)[source]#

B1-averaged transition probabilities from matrix elements.

Parameters:
  • elements (Tensor, shape (..., 3, P)) – <i|mu_k|j> (pair_elements()), in mu_B.

  • dirs (array_like or Tensor, shape (..., 3)) – Unit directions n of the static field.

  • h1mode (float, default 0.0) – Excitation mode: 0 perpendicular, (abs(M)**2 - abs(n.M)**2)/2 (the mean over B1 normal to B0); < 0 parallel abs(n.M)**2; > 0 perpendicular + h1mode times parallel.

Returns:

torch.Tensor, shape (…, P), float64 – Probabilities in mu_B^2.

Return type:

Tensor

torchspin.lft.ddnloop.field_scan(n, fields, theta=0.0, phi=0.0, **kw)[source]#

Zeeman-diagram data: scan() over field magnitudes at a fixed direction.

Parameters:
  • n (int or DnOperators) – Number of d electrons or cached operators.

  • fields (array_like or Tensor) – Field magnitudes in mT.

  • theta (float or Tensor, default 0.0) – Field direction (radians unless degrees=True).

  • phi (float or Tensor, default 0.0) – Field direction (radians unless degrees=True).

  • **kw – Further keywords of scan().

Returns:

LoopResult

Return type:

LoopResult

Examples

>>> import torch
>>> from torchspin import lft
>>> res = lft.ddnloop.field_scan(1, torch.linspace(0, 1000, 11), theta=0.3,
...                              V=lft.crystal_field(Dq=1500.0, Ds=300.0, Dt=50.0),
...                              zeta=154.0, units='cm^-1', pairs=[(0, 1)])
>>> res.transition_energies.shape, bool(res.g_obs[0, 0].isnan())
(torch.Size([11, 1]), True)
torchspin.lft.ddnloop.level_probabilities(energies, pmat, pi, pj)[source]#

Transition probabilities summed over the degenerate members of each level.

sum_{a in level(i), b in level(j)} pmat[a, b]: gauge invariant and differentiable off accidental crossings; equal to pmat[i, j] where both levels are nondegenerate. Levels are decided on detached energies.

Parameters:
  • energies (Tensor, shape (..., N)) – Ascending energies (any unit).

  • pmat (Tensor, shape (..., N, N)) – Per-pair probabilities (pair_probability_matrix()).

  • pi (sequence of int) – 0-based state indices of the pairs.

  • pj (sequence of int) – 0-based state indices of the pairs.

Returns:

torch.Tensor, shape (…, P), float64 – Summed probabilities in the unit of pmat.

Return type:

Tensor

torchspin.lft.ddnloop.mirror_image(V)[source]#

DDN’s internal real-orbital field (DDNLOOP-02), the mirror image y -> -y of V.

DDN works with the complex conjugate of V in the |m> basis, which is the field of the ligand set reflected through the xz plane (the xy and yz rows and columns change sign). Apply it to V by hand to reproduce DDN’s numbers for a general field direction. Linear, so gradients pass.

Parameters:

V (array_like or Tensor, shape (..., 5, 5)) – Real-orbital ligand field (x2-y2, xy, xz, yz, z2), any energy unit.

Returns:

torch.Tensor, shape (…, 5, 5), float64 – The mirrored field, same unit.

Return type:

Tensor

torchspin.lft.ddnloop.pair_elements(vectors, mu, pi, pj)[source]#

Matrix elements <i|mu_k|j> for selected state pairs.

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

  • mu (Tensor, shape (3, N, N)) – Operators (e.g. torchspin.lft.ddn.zeeman_operators()).

  • pi (sequence of int) – 0-based state indices of the pairs (same length P).

  • pj (sequence of int) – 0-based state indices of the pairs (same length P).

Returns:

torch.Tensor, shape (…, 3, P), complex – The matrix elements, in the unit of mu (mu_B for the moment).

Return type:

Tensor

torchspin.lft.ddnloop.pair_probability_matrix(vectors, mu, dirs, h1mode=0.0)[source]#

Transition probability of every state pair (the per-pair DDNLOOP quantity).

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

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

  • dirs (array_like or Tensor, shape (..., 3)) – Unit directions of the static field.

  • h1mode (float, default 0.0) – Excitation mode, as exact_probabilities().

Returns:

torch.Tensor, shape (…, N, N), float64 – Probabilities in mu_B^2 (basis dependent inside degenerate levels).

Return type:

Tensor

torchspin.lft.ddnloop.parameter_scan(n, name, values, *, field=None, relative=False, units='MHz', **params)[source]#

Energy levels for a series of values of one Hamiltonian parameter (correlation diagram).

Parameters:
  • n (int or DnOperators) – Number of d electrons or cached operators.

  • name (str) – Parameter to scan: 'B', 'C', 'A', 'zeta' or 'alpha' (values shape (m,)), 'k' ((m, 3)) or 'V' ((m, 5, 5)).

  • values (array_like or Tensor) – The m values, in units for energies.

  • field (array_like or Tensor, shape (3,), optional) – Field vector in mT, the same for every value. Default None.

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

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

  • **params – The other (fixed) Hamiltonian keywords of torchspin.lft.ddn.hamiltonian().

Returns:

torch.Tensor, shape (m, N), float64 – Ascending levels in units for each value.

Raises:
  • ValueError – If name cannot be scanned or values has the wrong number of dimensions.

  • TypeError – If name is also passed as a keyword.

Return type:

Tensor

Examples

>>> from torchspin import lft
>>> E = lft.ddnloop.parameter_scan(2, 'B', [600.0, 800.0, 1000.0], C=3200.0, units='cm^-1')
>>> E.shape
torch.Size([3, 45])
torchspin.lft.ddnloop.scan(n, *, fields, theta=0.0, phi=0.0, mesh=False, degrees=False, pairs=None, temperature=None, normalized_populations=True, h1mode=0.0, mw_freq=None, units='MHz', constants=TORCHSPIN_CONSTANTS, device='cpu', **params)[source]#

Levels and transitions of d^n over a scan of field magnitude and direction.

For every scan point the full d^n Hamiltonian with the field fields * (sin t cos p, sin t sin p, cos t) is diagonalized (batched).

Parameters:
  • n (int or DnOperators) – Number of d electrons (0 to 10) or cached operators.

  • fields (float or array_like or Tensor) – Field magnitudes in mT.

  • theta (float or array_like or Tensor, default 0.0) – Field direction, radians (degrees with degrees=True).

  • phi (float or array_like or Tensor, default 0.0) – Field direction, radians (degrees with degrees=True).

  • mesh (bool, default False) – False: fields, theta and phi are broadcast together to the scan shape S. True: they must be 1-D (or scalars) and are meshed as DDNLOOP loops them, S = (n_theta, n_phi, n_field) (theta outermost; reshape(-1) gives DDNLOOP’s listing order).

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

  • pairs (sequence of (int, int) or 'all', optional) – 0-based state pairs (i, j), i < j, for the transition quantities. Default None: none.

  • temperature (float or Tensor, optional) – Temperature in K for Boltzmann populations. Default None: none.

  • normalized_populations (bool, default True) – Normalize the Boltzmann factors to sum 1; False gives DDNLOOP’s printed exp(-(E_i - E_0)/kT).

  • h1mode (float, default 0.0) – Excitation mode: 0 perpendicular, < 0 parallel, > 0 perpendicular + h1mode times parallel.

  • mw_freq (float or Tensor, optional) – Microwave frequency in GHz for DDNLOOP’s microwave weights.

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

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

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

  • **params – Hamiltonian keywords of torchspin.lft.ddn.hamiltonian(): B, C, A, zeta, V, k, alpha, slater.

Returns:

LoopResult

Raises:
  • TypeError – For a keyword that is not a Hamiltonian parameter.

  • ValueError – If mesh=True with multi-dimensional inputs, or for invalid pairs (not 'all', or not 0 <= i < j < N).

Return type:

LoopResult

Examples

>>> import torch
>>> from torchspin import lft
>>> res = lft.ddnloop.scan(1, fields=torch.linspace(0, 500, 6), theta=torch.tensor([0.0, 1.0]),
...                        mesh=True, V=lft.crystal_field(Dq=1500.0, Ds=300.0), zeta=154.0,
...                        units='cm^-1', pairs='all')
>>> res.energies.shape, res.probabilities.shape
(torch.Size([2, 1, 6, 10]), torch.Size([2, 1, 6, 45]))