ham#

torchspin.ham(sys, B0=None, dtype=torch.complex128, device='cpu')[source]#

Spin Hamiltonian matrix (or field-independent parts + moment operators).

Parameters:
  • sys (SpinSystem) – Spin system.

  • B0 (list | Tensor | None) – Static magnetic field vector in mT, shape (3,). If given, returns the full Hamiltonian H = H0 - |B0| * muzL. If None, returns (H0, mux, muy, muz).

  • dtype (dtype) – Output dtype. Default torch.complex128.

  • device (str) – PyTorch device string.

Returns:

  • H – If B0 is given — full Hamiltonian (MHz), shape (nStates, nStates).

  • (H0, mux, muy, muz) – If B0 is None — field-independent Hamiltonian and the three magnetic-dipole-moment operators (MHz and MHz/mT respectively), each of shape (nStates, nStates).

Return type:

Tensor | tuple

Notes

The sign convention follows EasySpin:

H = H0 - B0[0]*mux - B0[1]*muy - B0[2]*muz
  = H0 - norm(B0) * muzL

where muzL is the magnetic-moment operator projected along B0. The nuclear Zeeman has a POSITIVE contribution to mux/muy/muz (opposite sign to electron Zeeman internally, but combined here with the same convention: H = H0 - B · μ_total).