Spinach (software)

Spinach
DeveloperIlya Kuprov (lead developer)
Release2011
Stable release
2.13 / 22 September 2026
Written inMATLAB, C++
Operating systemMicrosoft Windows, macOS, Linux
Available inEnglish
TypeMagnetic resonance simulation
LicenseMIT License
Websitespindynamics.org
Repositorygithub.com/IlyaKuprov/Spinach

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

250 MHz ECOSY NMR spectrum of strychnine alkaloid simulated using Spinach.

Spinach implements magnetic resonance spectroscopy and imaging simulations by solving the equation of motion for the density matrix 𝝆(t) in the time domain:

βˆ‚βˆ‚t𝝆(t)=βˆ’i𝐋(t)𝝆(t)⇓𝝆(t+dt)=exp⁑[βˆ’i𝐋(t)dt]𝝆(t)

where the Liouvillian superoperator 𝐋(t) is a sum of the Hamiltonian commutation superoperator 𝐇(t), relaxation superoperator 𝐑, kinetics superoperator 𝐊, and potentially other terms that govern spatial dynamics and coupling to other degrees of freedom:

𝐋(t)=𝐇(t)+i𝐑+i𝐊+...

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:

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:

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