Spinach is an open-source software package for numerical simulation of time-domain spin dynamics in magnetic resonance. It is written in MATLAB and is used for simulations in nuclear magnetic resonance (NMR), electron paramagnetic resonance (EPR), magnetic resonance imaging (MRI), dynamic nuclear polarization (DNP), magic angle spinning (MAS), spin chemistry, and quantum optimal control. The package was introduced in 2011 in the Journal of Magnetic Resonance as a library for simulating spin dynamics in large spin systems. Subsequent publications describe its use for large-scale magnetic resonance simulations, including reduced state-space calculations, Fokker-Planck treatment of spatial dynamics, quantum mechanical MRI simulation, and optimal control calculations. The source code is maintained in a public GitHub repository and distributed under the MIT License. The name of the package whimsically refers to the physical concept of spin and to Popeye the Sailor who, in the eponymous comic books, becomes stronger after consuming spinach.
History Spinach was developed for simulations in which the conventional direct product Hilbert space description of multi-spin systems becomes intractable due to the exponential complexity scaling. The 2011 paper describes a library that uses reduced Liouville space basis sets and sparse matrix methods to simulate liquid-state NMR experiments for systems with more than forty spins on a desktop workstation. Subsequent development added modules for spatial dynamics, MRI, tensor trains, and optimal control. A 2016 article described Fokker-Planck formalism implementation in Spinach, in which spatial dynamics (sample spinning, diffusion, and flow) can coexist with spin dynamics. A 2019 Science Advances paper reported quantum-mechanical MRI simulations of coupled spin systems with three-dimensional diffusion, flow, chemical kinetics, and relaxation.
Computational approach
Spinach implements magnetic resonance spectroscopy and imaging simulations by solving the equation of motion for the density matrix ρ ( t ) {\displaystyle \mathbf {\rho } \left(t\right)} in the time domain:
where the Liouvillian superoperator L ( t ) {\displaystyle \mathbf {L} \left(t\right)} is a sum of the Hamiltonian commutation superoperator H ( t ) {\displaystyle \mathbf {H} \left(t\right)} , relaxation superoperator R {\displaystyle \mathbf {R} } , kinetics superoperator K {\displaystyle \mathbf {K} } , and potentially other terms that govern spatial dynamics and coupling to other degrees of freedom:
Computational efficiency is achieved through the use of reduced state spaces, sparse matrix arithmetic, on-the-fly trajectory analysis, and dynamic parallelization.
Functionality As of 2026, Spinach is cited in over 600 academic publications. According to the documentation and academic papers citing its features, the most recent version 2.12 of the package performs:
Time-domain nuclear magnetic resonance (NMR) simulations of: Standard NMR experiments (DEPT, COSY, NOESY, HSQC, TOCSY, etc.). Protein and nucleic acid NMR experiments (HNCA, HNCOCA, HNCO, etc.). Magic angle spinning NMR experiments (CP-MAS, MQMAS, WISE, etc.). Experiments involving residual dipolar coupling and other residual order effects. Zero- and ultra-low field experiments, including Earth's field NMR. Nuclear quadrupole resonance, including overtone NMR. Time-domain magnetic resonance imaging (MRI) simulations, including: Standard and user-specified imaging sequences. Diffusion coefficient and diffusion tensor imaging. Three-dimensional point-resolved NMR spectroscopy. Ultrafast spatially encoded NMR spectroscopy. Time-domain electron spin resonance (ESR) simulations of: Standard pulsed ESR experiments (HYSCORE, ENDOR, ESEEM, etc.). Pulsed dipolar spectroscopy (DEER, RIDME, etc.). Dynamic nuclear polarization for static and spinning samples. Spinach contains an implementation the gradient ascent pulse engineering (GRAPE) algorithm for quantum optimal control. The documentation and the book describing the optimal control module of the package list the following features:
L-BFGS quasi-Newton and Newton-Raphson GRAPE optimizers. Spin system trajectory analysis by coherence and correlation order. Spectrogram analysis of the pulse waveform. Prefixes, suffixes, keyholes, and freeze masks. Stroboscopic steady states and steady orbits as control targets. Optimization of cooperative pulses and phase cycles. Waveform penalty functionals and instrument response. Dissipative background evolution generators and control operators are supported, as well as ensemble control over distributions in common instrument calibration parameters, such as control channel power and offset. Common models of spin relaxation (Redfield theory, stochastic Liouville equation, Lindblad theory) and chemical kinetics are supported, and a library of powder averaging grids is included with the package.
See also Magnetic resonance Nuclear magnetic resonance spectroscopy Electron paramagnetic resonance Quantum optimal control List of quantum chemistry and solid-state physics software
References
External links Official website Spinach source repository at GitHub Spinach Documentation Wiki



