A Python package for simulating nonequilibrium magnetization of magnetic molecules under a time-varying external magnetic field, based on a generalized Lindblad quantum master equation.
Magnetic molecules — including transition metal complexes and lanthanide-based complexes — are open quantum systems due to their coupling to lattice vibrations (phonons). This spin-phonon coupling governs magnetization relaxation and limits quantum coherence times. Under a time-varying external magnetic field, as in pulsed-field magnetometry, the spin system is driven out of thermal equilibrium and its dynamics cannot be captured by equilibrium methods alone.
qdmag implements the generalized Lindblad quantum master equation of Saito et al. [1] to simulate this nonequilibrium magnetization. It supports long-time evolution up to a few milliseconds through a staircase approximation and an effective Hamiltonian scheme for large spin systems.
- Spin Hamiltonian formalism including:
- Magnetic exchange interaction (isotropic, anisotropic, antisymmetric, and symmetric parts of the full exchange coupling tensor J)
- Zero-field splitting (ZFS) via extended Stevens operators up to 12th order
- Zeeman interaction with an external magnetic field
- Four supported magnetic field profiles B(t):
- Linear sweep: B(t) = a·t
- Piecewise linear
- Cubic spline fit to experimental pulse data
- Sinusoidal: B(t) = B₀ sin(ωt)
- Two time-propagation methods:
- Staircase approximation for numerically stable long-time propagation (millisecond timescales)
- Fourth-order Runge–Kutta (RK4) for high-accuracy short-time propagation
- Effective Hamiltonian construction for large spin systems, reducing the full Hilbert space dimension N = Πᵢ(2Sᵢ+1) to a computationally feasible subspace of thermally relevant states
- Powder averaging over random molecular orientations using Lebedev + Gauss-Legendre quadrature (up to 1118 orientations)
- Liouville form of the quantum master equation for efficient matrix-based time propagation
- HDF5-based I/O for density matrix storage, retrieval, and file management
git clone https://github.com/shuanglongliu/qdmag.gitAdd the directory that contains qdmag to the evironment variable PYTHONPATH.
- Python 3.x
- NumPy
- SciPy (quadrature weights, spline fitting, matrix exponential, and Euler angle transformations)
- h5py (HDF5 I/O for density matrix storage and retrieval)
- pandas (tabular output of magnetization and level population time series)
- matplotlib (optional; sparsity visualization and quadrature point plots)
The spin Hamiltonian has three terms:
Exchange interaction:
The 3×3 exchange coupling matrix J can be decomposed into isotropic, traceless anisotropic, antisymmetric, and symmetric off-diagonal parts.
Zero-field splitting:
where
Zeeman term:
The magnetic field is assumed to be along the
The generalized Lindblad equation reads:
where the dissipator
The continuous B(t) profile is replaced by a staircase function. Within each step the Hamiltonian is constant and the propagator has the exact closed-form solution:
This maintains numerical stability for time steps orders of magnitude larger than those required by Runge–Kutta methods, making millisecond simulations feasible.
For large multinuclear systems where the full Hilbert space dimension N = Πᵢ(2Sᵢ+1) is too large, an effective Hamiltonian of dimension n ≪ N is constructed by selecting thermally relevant basis states. The basis states are chosen as the lowest-energy eigenstates of isotropic exchange interaction with a perturbative Zeeman term for each value of the total
For powder samples, the net magnetization is averaged over all molecular orientations:
using Lebedev quadrature for the first two Euler angles (α, β) and Gauss-Legendre quadrature for the third (γ). Quadrature points and weights are saved to a text file for inspection and record.
Three case studies are included to demonstrate the package:
| System | Description | Hilbert space |
|---|---|---|
| Ho(pzdo)₄ | Mononuclear Ho³⁺ complex, J = 8, ZFS up to 12th order | Full (17 states) |
| Spin-1/2 dimer | Two coupled S = 1/2 spins, four exchange coupling types | Full (4 states) |
| (CH₆N₃)₂MnCl₄ | Mn trimer, S = 5/2 local spins | Effective (16 or 26 states from full 216) |
All input parameters are loaded from an input.yaml file in the working directory. Example input files can be found in the examples/ folder.
python tool_staircase.py The tool_staircase.py script must be run in the same directory as the input file. This script and other useful scripts can be found in the tools/ directory. See the Tools section below for brief descriptions of each script.
The time step dt should be chosen to converge the magnetization. A practical starting point is dt = 0.0001 T / sweep_rate. Decreasing dt until the result no longer changes is recommended.
The tools/ directory contains standalone utility scripts for common tasks. Each script reads input parameters from an input.yaml file in the working directory via read_input().
Runs the quantum master equation using the staircase approximation. This is the primary solver for long-time (millisecond-scale) dynamics. The initial density matrix can be set from thermal equilibrium or loaded from an existing HDF5 file to continue a prior run.
lio.evolve_rho() # scheme taken from the 'method' key of input.yamlThe time-integration scheme is chosen by the optional method key in the third dynamics block of input.yaml, either staircase (default) or RK4.
The propagator that applies exp(L*deltat) at each stair is chosen by the optional exp_propagator key in the same block:
exp_propagator |
Method |
|---|---|
Pade (default) |
Full matrix exponential, scaling-and-squaring Padé. Cost independent of deltat, but L must fit in memory |
Taylor |
Action of the exponential by truncated Taylor series (expm_multiply). Cost grows with ||L*deltat|| |
Krylov |
Arnoldi projection onto a Krylov subspace. Cost grows with ||L*deltat||; uses L only through matrix-vector products |
Taylor_sparse, Krylov_sparse |
As above, but L is built and held in sparse CSR format |
Krylov also accepts krylov_m (subspace dimension, default 30) and krylov_tol (default 1e-10). An unrecognized name raises at construction, and method: RK4 requires a dense L so it rejects the _sparse variants.
Keep the default Pade for production runs: the alternatives only overtake it for ||L*deltat||_1 below roughly 1e4, and a typical deltat = 1e4 ps is far above that.
Runs the quantum master equation using the fourth-order Runge–Kutta (RK4) method. Suitable for short-time, high-accuracy propagation. Shares the same interface as tool_staircase.py, including the option to restart from a saved density matrix. Passing method explicitly overrides the method key of input.yaml, so this script always runs RK4.
lio.evolve_rho(method="RK4")Both solvers read their output controls from the optional fourth dynamics block in input.yaml (save_mag, save_rho, save_drdt, and the corresponding nt_mag/nt_rho/nt_drdt save intervals). The block, and every key within it, may be omitted, falling back to defaults that save only the magnetization at roughly 100 points over [tmin, tmax].
Computes the equilibrium magnetization M(B) as a function of applied field. Supports both the full Hilbert space and the reduced effective basis. Output is written to output/M-B.csv.
Computes and saves the Zeeman energy level diagram — eigenvalues of the spin Hamiltonian as a function of applied field. Supports both the full and effective Hilbert spaces.
Diagonalizes the spin Hamiltonian at a fixed field (default:
Computes and saves the expectation values of individual spin operators
Computes the state composition of the eigenstates in terms of the effective basis states at a specified field.
Computes the thermal equilibrium occupation probabilities of the effective basis states over a range of magnetic field values at a given temperature.
Validates the physical conditions of the density matrix skip-th time point to reduce I/O overhead.
Transforms the density matrix between representations. Converts
Generates and saves Lebedev quadrature points and weights for powder averaging. The average needs only two angles: with the field along the global points_and_weights.txt. The angles are in degrees both in the file and in the returned array. Optional visualization of the sampled directions is available via matplotlib.
HDF5 file utilities: estimates the file size for a given simulation (time duration, time step, and density matrix dimension), combines two sequential HDF5 output files into one, and inspects the contents of an existing HDF5 file.
Diagnostic tool for examining the magnitude of the Liouville superoperator
Diagnostic tool for checking whether the Hamiltonian commutes with itself over time. Checks (1) if the time-independent part $\hat{H}\text{ex} + \hat{H}\text{ZFS}$ commutes with the instantaneous Zeeman term [tmin, tmax]. Useful for checking whether the eigenbasis stays fixed during the pulse (e.g., for an isotropic g-tensor with the field along a fixed axis).
Evolves the spin state using a classical rate equation (transition rate matrix approach) instead of the full quantum master equation. Uses the staircase approximation for time propagation and computes the magnetization from the resulting level populations. Useful as a computationally cheap reference or sanity check.
Utility for convergence testing of the staircase time step. Automatically generates input.yaml files and SLURM job scripts for a series of calculations with systematically varied step sizes
This work is supported by the Center for Molecular Magnetic Quantum Materials (M2QM), an Energy Frontier Research Center (EFRC) funded by the U.S. Department of Energy, Office of Science, Basic Energy Sciences under Award DE-SC0019330.
[1] K. Saito, S. Takesue, and S. Miyashita, Energy transport in the integrable system in contact with various types of phonon reservoirs, Phys. Rev. E 61, 2397 (2000).
[2] H. Nakano and S. Miyashita, Magnetization Process of Nanoscale Iron Cluster, J. Phys. Soc. Jpn. 70, 2151–2157 (2001).
[3] S. Liu, X. Chen, A. Cupo, J. N. Fry, and H.-P. Cheng, qdmag: A Python package for simulating nonequilibrium magnetization using quantum master equations, to be submitted to J. Comput. Phys. (2026).