Spynach

Spin dynamics in Python: the Spinach kernel and EasySpin's simulators, reimplemented and verified against the originals.

Portrait of Spinoza rendered as a two-dimensional 1H-13C correlation spectrum: coloured cross peaks on a black background with the 1D projections along the top and right edges
Any resemblance to living or dead personalities is purely accidental. Fig. credits to Florin Teleanu.
Spinach port

spynach

The Spinach spin dynamics kernel in Python, stage by stage, with Spinach's names, parameters and tolerances.

Liquid-state NMR in Hilbert and Liouville space, restricted bases, anisotropic interactions with powder averaging, Redfield relaxation, magic angle spinning, COSY, NOESY and HSQC. Verified against Spinach 2.13 at every stage.

EasySpin port

epreasy

The simulators of EasySpin in Python, with EasySpin's interface: spin systems as dicts with EasySpin's field names, mT and MHz.

cw EPR of powders, crystals and solutions, least-squares fitting, ENDOR, magnetometry, slow motion, and pulse EPR (ESEEM, HYSCORE, Mims ENDOR). Verified against EasySpin 6.0.15 on every simulator.

Extras

ctps and tooling

What originated here: coherence transfer pathway selection with phase cycles, gradients and non-ideal pulses, cogwheel cycle search, and the verification tooling behind both ports.

Every pathway a sequence allows, ranked and drawn in an interactive explorer; parity harnesses and timed comparisons against MATLAB; executable guides; this browser playground.

No MATLAB licence needed. Pip-installable packages that slot into the scientific Python stack, run on any machine, in Colab, or in this browser.

Verified, not eyeballed. Every ported stage is compared with reference data computed by Spinach or EasySpin itself, with tolerances that are stated, measured and published.

Readable kernels, ready for accelerators. The algorithms in plain Python with NumPy and SciPy, hot loops behind one backend adapter, and documentation whose code runs in the test suite.

Install

Two packages, one install

Python 3.11 or newer. The distribution installs spynach, epreasy and ctps; the fast extra adds Numba, which threads the sparse kernels of Spynach and compiles EasySpin's, docs and test the notebooks and the test suite.

pip install "spynach @ git+https://github.com/ajerschow/spynach.git"

# or, for the notebooks and tests
git clone https://github.com/ajerschow/spynach.git
cd spynach && pip install -e ".[docs,test,fast]"

The first guide of each port starts from an installed package: Hilbert space for Spinach users, EPR spin systems with epreasy for EasySpin users. Nothing to install: the playground runs both ports in Pyodide, and the Colab notebook installs Spynach and plots a two-spin spectrum. In a container whose CPU quota is below its visible core count, set OPENBLAS_NUM_THREADS to the quota.

Credits

With thanks

Spynach derives from Spinach 2.13 (Ilya Kuprov and co-workers, MIT licence) and EPReasy from EasySpin 6.0.15 (Stefan Stoll and co-workers, MIT licence); both attributions are kept in LICENSE. The translation from MATLAB to Python was carried out largely by an AI coding agent working under the direction of Alexej Jerschow, who set the goals and reviewed the results; correctness rests on the test suites against the originals' reference data.

Grateful to Claude for the amazing work, and to Ilya Kuprov for encouragement and for suggesting the catchy name. Contributors: Florin Teleanu, for the Spinach scripts in user_ml/ that became two of the comparison cases and for the figure above; Moritz Zaiss (MRsources), for the browser playground. The list is kept in the README.