Spinach library
Using Spinach
Spinach may be downloaded to your computer, and to Matlab-capable NMRBox nodes, using the links below (but note the Matlab version requirements in the next section):
Version 2.10.1 (Apr 2025, documentation)
Version 2.9.2
Version 2.8
Version 2.7
To access the latest developer version, clone the following GitHub repositories:
Spinach: https://github.com/IlyaKuprov/Spinach
DEERNet: https://github.com/IlyaKuprov/DEERNet
Please do not use the developer version without a good reason. The source code for HNCA signal identification networks (PyRuv8) is here.
System requirements
Spinach requires at least Matlab 2024b Update 7. Later versions of Matlab are to be considered unstable at the moment – a major recent architecture transition within Matlab itself means that MathWorks will spend the next few years fixing bugs. The following toolboxes are required:
- Parallel Computing Toolbox
- Optimization Toolbox
- Deep Learning Toolbox
- Reinforcement Learning Toolbox
- Statistics and Machine Learning Toolbox
- Mapping Toolbox
Spinach needs a minimum of 2 GB of RAM per CPU core for basic simulations and protein work (HSQC, HNCO, etc.), and a minimum of 2 GB of RAM per amino acid for advanced protein work (NOESY, TROSY, etc.).
New features
Initial condition parameters.rho0 in powder.m wrapper may now be a function handle taking three Euler angles. R1 and R2 relaxation rates in the extended T1/T2 model can also now be function handles returning the rate as a function of the three Euler angles. This is useful for exotic orientation-dependent initial conditions and relaxation mechanisms, for example in optically hyperpolarised materials (collaboration with Guinevere Mathies).
Optimal control module now supports arbitrary cascades of instrumental distortions and ensembles of their parameters (see the recent paper by Uluk Rasulov for details). Several common filter functions have been pre-programmed. Hilbert space (by Maxi Keitel) and wavefunction space (by Callum Musselwhite) GRAPE optimisations are now supported.
New steady state solver returning the stationary state under repeated application of the user-specified dissipative propagator. The new function (steady.m) normally finds the steady state in a few matrix-vector multiplications; this accelerates some types of DNP simulations by orders of magnitude (collaboration with Guinevere Mathies).
New central transition convenience functions for half-integer spins: irreducible spherical tensor expansion (ct2ist.m) and central transition selective operators (centrans.m). Central transitions may now be chosen as state and operator descriptors in calls to operator.m and state.m functions (collaboration with Marina Carravetta).
Roadmap context function for multi-orientation experiments has been eliminated, it is now a special case of the powder context function (powder.m). Magic angle spinning context function (singlerot.m) has been rewritten to accommodate conventional Hilbert space MAS simulations using rotor period discretisation (collaboration with Maxi Keitel).
Improvements in parallel efficiency, GPU efficiency, and memory efficiency across the code. Major parallel loops (powder average, Hamiltonian construction, etc.) now print progress reports to the console. An option was added to disable parallel evaluation of Redfield superoperator components, this is useful in large cases when the parallel route runs out of memory. Single step function (step.m) no longer computes matrix exponentials in Hilbert space and instead sums a sparse commutator series. A pair of code includes has been added that allows disabling of GPU arithmetic in a particular code block even if the user had turned on the global GPU switch. Spinach can now cache previously seen operators and Hamiltonians on disk – when they are encountered again, they are read from the disk and not recomputed.
Visualisation and plotting improvements: interaction tensor visualisers can now draw atom numbers and labels in 3D plots, microfluidic mesh plotters are faster, state analysis plots and optimal control status plots are more informative. Rotation behaviour has been improved for 3D plots.
A new function that generates singlet-triplet basis product states in four-spin subsystems (collaboration with Thomas Theis). New function that returns singlet, triplet, and quartet states in spin-1 pairs and the associated ortho-deuteration examples (collaboration with Anakin Aden, Theresa Hune, and Stefan Gloeggler).
New Chebyshev autophasing function (autophase.m) for 1D NMR spectra. Apodisation function (apodisation.m) has been rewritten completely, it is now more flexible and easier to use.
Protein import function now offers a choice of three literature eigenvalue sets for the amide nitrogen CSA. Missing assignments are now printed to the console in red. Additional deuteration options have been added (collaboration with Hari Arthanari, Abhinav Dubey, and Kevin Alexander).
Over 50 additional example files to a current total of 622, all reported bugs fixed. A standard system specification function for a Diels-Alder cycloaddition reaction of acrylonitrile to cyclopentadiene (collaboration with Anupama Acharya).
Improvements in parallel efficiency of optimal control calculations, particularly with Newton-Raphson optimisers (collaboration with David Goodwin). Spectrograms and slice flip angle reporting in GRAPE diagnostics. New ensemble control modalities: transmitter offsets and couplings, supporting multiple distributed variables. New optimal control examples and an option of saving a video file of the diagnostics window during the optimisation process. Event list compiler that converts multi-event and multi-channel pulse sequences into pulse shapes with a fixed transmitter frequency.
A new highly characterised standard spin system: allyl pyruvate (collaboration with Anupama Acharya and Yael Ben-Tal).
Hyperbolic secant waveform function. Chirped pulse generation function now supports adaptively sampled chirps and refuses to generate chirps that violate Nyquist-Shannon conditions (collaboration with Guinevere Mathies). Shaped pulse function now supports high-order Lie quadratures (collaboration with Uluk Rasulov and Anupama Acharya). Heterodyne function (collaboration with Anupama Acharya).
New cross-polarisation pulse sequences for MAS NMR and new pulsed DNP experiments with many examples from published work (collaboration with Guinevere Mathies).
New convenience functions: non-linear contour spacing, isotope substitution function that scales all relevant interactions, non-commuting part removal, matrix trace removal, indefinite Tikhonov solver, adiabatic elimination, spherical tensor expansion for central transition operators of quadrupolar nuclei.
Numerical efficiency improvements in field-swept ESR spectra calculations and time-domain ENDOR simulations. Eigenfields solver now supports Rayleigh-Schrodinger perturbation theory.
Experimental support for bosonic degrees of freedom (electromagnetic cavity modes and phonon modes) with a few examples (collaboration with Aharon Blank and Moamen Jbara).
A new kernel context, infrastructure, and visualisation functions for microfluidic simulations that have diffusion, flow, and spin-independent chemical kinetics occurring at the same time as quantum mechanical spin dynamics. Spinach can import 2D meshes and stationary flow velocity maps from COMSOL, and run time-domain magnetohydrodynamics. Collaboration with Anupama Acharya, Sylwia Barker, Yael Ben-Tal, Malcolm Levitt, and Marcel Utz.
Better DEERNet background quantification, plotting, and parameter output; effective dimension range for the background signal is now user-selectable. DEERNet was uptrained against infinite databases (by Jake Keeley), and to handle edge cases identified by Bela Bode, Daniella Goldfarb, Gunnar Jeschke, Nina Kubatova, and Janet Lovett (data included in the example set). Improved handling of sparsely sampled DEER and RIDME datasets.
Better handling of time-dependent drifts, dissipative drifts, and dissipative control operators in the optimal control module. Spinach now detects unreachable destinations and hopeless initial guesses. Collaboration with Uluk Rasulov.
Reaction generators for non-linear spin-independent chemical kinetics. Linear kinetics equilibration function now supports multiple independent reaction networks and detects situations where the equilibrium is not constrained. Collaboration with Anupama Acharya.
More kernel contexts now compute the thermal equilibrium state on user request. Runtime applicability checks are now performed for Redfield type relaxation theories.
RDC/RCSA/RNQI handling extended to situations when different chemical exchange compartments have different order matrices (collaboration with Stuart Elliott, Thomas Eykyn, and Philip Kuchel).
New pulse sequences: FSLG-HETCOR, CP-Acquire, TPPM-DNP, BEAM-DNP, and WISE (all implemented by Guinevere Mathies), E.COSY (collaboration with Anupama Acharya, Yael Ben-Tal, and Malcolm Levitt).
Improved multi-GPU management, memory management, and parallelisation efficiency, particularly in Hamiltonian construction, Redfield theory and optimal control. An option to bind specific GPUs to specific Matlab worker processes manually. Technical support from MathWorks is gratefully acknowledged.
Better NMRBox integration (collaboration with NMRBox team, particularly Jeff Hoch, Mark Maciejewski, and Adam Schuyler).
New example files: for TGRAPE (by Guinevere Mathies), Lie and RKMK integrators (by Anupama Acharya), relaxation theory, time-domain Mims and Davies ENDOR simulations, optimal control (by Uluk Rasulov), DEERNet (by Jake Keeley and Tajwar Choudhury), solid state DNP pulse sequences (by Guinevere Mathies), 2D EXSY data fitting (collaboration with Philip Kuchel, Dmitry Shishmarev, and Bruno Linclau).
New numerical infrastructure functions: regularised Newton-Raphson Tikhonov solver with a positivity constraint, forward linear prediction, state-dependent Runge-Kutta-Munthe-Kaas integrators (by Anupama Acharya).
New convenience and plotting functions: Cartesian specifications for operators and states (previously only spherical tensors were available), index extraction from labels, nearest spin finder, input structure merging, 2D stack plots.
RIDME spectroscopy data processing in DEERNet, including examples. A large number of other examples for DEERNet in general. Better neural networks, better background and modulation depth quantification, better graphical output. Collaboration with the co-authors of this paper with special thanks to Gunnar Jeschke.
A large number of liquid state DNP simulation examples from the recent papers (link, link) by Maria Grazia Concilio and Thomas Orlando (link) in collaboration with Lucio Frydman, Markus Hiller, and Murari Sundararajan.
NMR/EPR probe RLC circuit response simulation for shaped pulses, a collaboration with Uluk Rasulov.
A large number of NOVEL DNP (paper). TOP DNP (paper), and XiX DNP (paper) simulations in the solid state, kindly provided by Guinevere Mathies group.
Efficiency and memory management improvements in parallel runs on multi-GPU systems. The recommended GPUs for Spinach are FP64-capable cards, such as NVidia Titan V, Quadro GV100, Tesla V100, and Tesla A100.
Variable time slices, slice duration optimisation, curvilinear waveform parametrisation, piecewise-linear and piecewise-quadratic waveform options, and other improvements in the Optimal Control module. A collaboration with Anupama Acharya and Uluk Rasulov.
R-sequence generator and compiler functions for simulation of solid state NMR experiments. A collaboration with Marina Carravetta and Eddie Dib.
Additional analytical Redfield relaxation theory functions and examples in the Textbook Module.
Calculation and fitting functions for residual dipolar couplings, including situations when different isotope pairs are present simultaneously. A collaboration with Andras Boeszoermenyi and Hari Arthanari.
2D and 3D EPI and DEPI MRI pulse sequences (written by Ahmed Allami), 2D INADEQUATE sequence (written by Theresa Hune and Christian Griesinger), triple-channel PANSY sequence (written by Andrew Porter), and zero-field NQR sequence (written by Lewis Robertson).
Many additional examples, including chemical exchange under MAS in an NQI system (with Umit Akbey), solvent exchange repolarisation (with Mihajlo Novakovic, Maria Grazia Concilio, and Lucio Frydman), and zero-field NQR spectroscopy (with Lewis Robertson). A radical rewrite of the entire example set for the Optimal Control module.
Many conference, workshop, and summer school tutorial instruction sheets (see the tutorials folder in the Spinach distribution). Topics include: getting started, TROSY simulations, pulse sequence benchmarking, solid state NMR simulation, time-domain EPR simulation, and training DEERNet neural networks.
Many new numerical infrastructure functions (Arnoldi orthogonalisation, DCT algorithm for Chebyshev expansions, EFG tensor visualisation, Lorentzian convolution, trapezium propagator derivatives, their auxiliary matrices, etc.)
- DEERNet 2: neural networks trained on infinite databases, support for sparsely sampled DEER traces, support for Gd(III) DEER, modulation depth quantification, a much expanded example and validation set. Collaboration with the co-authors of this paper.
- Improvements in operator generation, basis set generation, and memory efficiency in large-scale simulations. Some contributions from Stefan Stoll.
- Improvements to the efficiency of the MD trajectory to relaxation superoperator conversion module. Collaboration with Jim Prestegard.
- Examples and scripts for cross-correlated DNP simulations. Collaboration with Maria Grazia Concilio and Lucio Frydman.
- New functions and examples for the Textbook Module, new interaction convention specification support.
- Product quadrature functions for time- and state-dependent evolution generators in the Liouville – von Neumann equation.
- Much improved hyperfine and chemical shielding tensor visualisation functionality.
- Eigenfields solver and Voitlander integrator for field-swept experiment simulation. Miscellaneous associated numerical infrastructure, such as Hermite splines.
- Weblab convention import for nuclear quadrupolar interactions, additional quadrupolar NMR examples from Umit Akbey.
- General Rayleigh-Schrodinger and Van Vleck perturbation theory functions.
- Spherical quadrature grid generators for igloo, Fibonacci, and triangular type grids. Voronoi tessellation and visualisation functions, basic spherical grid construction and analysis functions.
- Steady state DNP solvers; Spinach automatically accounts for all DNP mechanisms that exist within the chosen formalism. Collaboration with Maria Grazia Concilio and Lucio Frydman.
- Wider neural networks in DEERNet, network descrambling functionality, bootstrap and Jacobian error analysis. Collaboration with Jake Amey, Jake Keeley, Tajwar Choudhury, Akiva Feintuch, Gunnar Jeschke, and Daniella Goldfarb.
- Standalone relaxation superoperator thermalisation module (inhomogeneous master equation and Di Bari – Levitt formalism) and MD trajectory to Redfield matrix conversion module. Collaboration with Jim Prestegard.
- New NMR pulse sequences: CT-COSY, CT-HSQC, HCCH-COSY, HCCH-TOCSY, HCANH, HNCACO, HNCA. Collaboration with Matt Walker.
- More flexible ZULF module, including quadrature detection option. Collaboration with Thomas Theis.
- Posterior Redfield limit validity checks for Redfield relaxation superoperators. Collaboration with Maria Grazia Concilio, Lucio Frydman, and Jim Prestegard.
- New numerical infrastructure functions: RSPT, Blicharski products, su(2)/so(3) representation reduction, Lorentz group generators, triplet states, SVD truncation, commutator analysis, etc. Some contributions from Stefan Stoll.
- New functions in the textbook module: CSA and DD relaxation rates.
- Import and simulation of 1D and 2D JEOL pulse sequences. Led by Maria Grazia Concilio.
- A large number of efficiency, cluster scalability, and GPU management improvements. Collaboration with Maria Grazia Concilio and Jos Martin at MathWorks.
- Support for Markov State Model simulations with linear compexity scaling for both liquid and solid state magnetic resonance simulations.
- Major parallel efficiency improvements (collaboration with Maria Grazia Concilio at Southampton, and Alison Eele, Jos Martin, and Raymond Norris at MathWorks). Much improved parallelisation control and profiling functionality when running on MDCS clusters.
- Optimal control module now supports wire distance modulation in magic angle spinning optimisations (collaboration with Marina Carravetta with good advice from Steffen Glaser). Some examples of MAS NMR optimal control simulations are now provided.
- COLOC (collaboration with Bud MacAulay) and PSYCOSY (collaboration with Alan Kenwright) pulse sequences added to the liquid state NMR module.
- iDOSY-ZS and one-shot DOSY pulse sequences added to the spatially encoded NMR module (collaboration with Maria Grazia Concilio and Gareth Morris).
- Absolute zero temperature now supported in the equilibrium function.
- Lots of numerical efficiency improvements, documentation improvements, and fixing of minor annoyances throughout the code.
- Performance and memory footprint improvements (collaboration with Jos Martin at MathWorks) for MRI and spatially encoded NMR simulations, particularly on GPUs. NVidia Titan V cards are much recommended. Spinach has been tested and optimised for cluster MDCS deployments with hundreds of worker processes.
- New liquid state NMR pulse sequences: INEPT, DEPT, DEPTQ, PANSY-COSY, INADEQUATE, HMBC (by Andrew Porter and Bud Macaulay). Multiple-quantum correlation sequences (by Maria Grazia Concilio).
- New solid state NMR pulse sequences (RESPIRATION-CP by Venkata Subbarao Redrouthu) and examples (overtone, CPMAS, CPMAS with chemical exchange, by Marina Carravetta, Phil Williamson, and Maria Grazia Concilio).
- New MRI and spatially encoded NMR functionality: ultrafast MQ (by Maria Grazia Concilio), better MRI examples (by Ahmed Allami), gradient tilting support at the kernel level and improved MRI plotting (by Maria Grazia Concilio). Spatial grid accuracy analysis function.
- Optimal control module extended to support time-dependent drift Hamiltonians, prefix and suffix pulse sequences, keyhole functions, interval-selective optimisation, and optimisation checkpoints (collaboration with Marina Carravetta, Phil Williamson, Jack Saywell, Tim Freegarde, and David Goodwin).
- New relaxation-driven NMR pulse sequences: HOESY, SAT-REC, INV-REC (by Zak El-Machachi). Extra analytical examples and textbook cases for relaxation theory.
- CPU and GPU support for polyadic arithmetic. Polyadic object can buffer additions and multiplications. The kernel transparently supports polyadic evolution generators.
- Eigenfields and eigentracks calculation for field-swept experiments.
- SIFTER and RIDME pulse sequences and examples by Alice Bowen. RYDMR experiment now uses full Zeeman Hamiltonian that includes nuclear Zeeman interactions and catches nuclear Zeeman resonances.
- An option to re-calculate the thermal equilibrium for each orientation in the powder context.
- Spin system data import from GISSMO files.
- Faster REPULSION grid generation by Fred Mentink-Vigier.
- Improved isotope dilution functionality and new standard large spin system (cyprinol) by Bud Macaulay.
- Vast amounts of additional documentation, stability improvements, and console reporting improvements.
- DEERNet – a neural network toolkit for DEER data processing (collaboration with Steve Worswick, James Spencer, and Gunnar Jeschke).
- Stability, scalability, performance, and memory footprint improvements.
- Optimal control module syntax has been streamlined (collaboration with David Goodwin, Jack Saywell, and Tim Freegarde).
- Additional examples in the pseudocontact shift module (collaboration with Liza Suturina).
- Ensemble control examples in the optimal control module (collaboration with David Goodwin, Jack Saywell, and Tim Freegarde).
- Optimal control under magic angle spinning (collaboration with Marina Carravetta and Yusuke Nishiyama).
- Dead time option in the optimal control module (collaboration with Marina Carravetta and Yusuke Nishiyama).
- A function that computes Sorensen bounds under complete controllability assumption.
- Additional examples of spatially encoded NMR pulse sequences (collaboration with Maria Grazia Concilio).
- Echo detection option in the pulse-acquire experiment.
- Analytical DEER function now supports exchange interaction.
- MQMAS pulse sequence and example files (collaboration with Marina Carravetta).
- An interface for Bruker Xepr software (collaboration with David Goodwin and Will Myers).
- A huge amount of additional documentation.
- Much faster symmetry treatment, particularly in systems with multiple non-Abelian symmetry groups.
- Kernel-wide support for spherical rank 1 interactions (such as antisymmetric CSA), including relaxation theory.
- Kernel-wide support for high spherical rank zero-field splitting, including relaxation theory.
- Polyadic representation option for large Kronecker products – many operations may be carried out without opening them.
- PRESS, DWI, EPI, and DPFGSE pulse sequences and examples in the imaging module (collaboration with Ahmed Allami).
- TROSY relaxation theory examples.
- An option to add magnetisation pumping (e.g. CIDNP or SABRE) terms to the relaxation superoperator.
- Arbitrary pulse timing grids, major improvements in parallel efficiency, and ensemble control options in the optimal control module.
- A huge amount of additional documentation.
