1 Introduction

Teaching magnetic resonance for NMR or EPR spectroscopy, magnetic resonance imaging (MRI), or spin-based quantum computing revolves around understanding the concept of spin and its manipulation through magnetic fields. Describing spin in a way that is both tangible and physically correct is challenging, because as a fundamentally quantum mechanical property, it does not survive into the macroscopic world the way mass or electrical charge do. The matter is further complicated by the historically grown comparison of spin to rotational momentum in three dimensions, in which a spin with the quantum number s is depicted as a three-dimensional vector that can assume \(2s+1\) quantised orientations with respect to a given axis defined by the measurement. For the simplest case of a spin with \(s=\frac{1}{2}\), this leads to the picture of a double cone oriented parallel and antiparallel to the z axis, but with no defined x or y component. Contrary to this model, spin is also depicted as a vector that can point in any direction on a Bloch sphere. Neither picture is complete and free from contradiction. In reality, spin arises from special relativity as an invariant under Lorentz transformation between a spatial coordinate and time (while rotational momentum arises from a Lorentz transformation between two spatial coordinates). Thus, as an inherently four-dimensional object of spacetime, the case can be made that spin should not be represented in three dimensions at all [1], as it inevitably leads to a limited and misleading representation of reality. However, initial understanding of spin is undoubtedly aided by providing graphical depictions and by following the historical development. Furthermore, the magnetic moment as the observable through which spin is detected in NMR, EPR and MRI has a three-dimensional vector representation. That correspondence justifies the use of the vector model, although care should be taken that a clear distinction between spin and the derived magnetic moment is made.

Ultimately, any vector representation of magnetic resonance in three dimensions is bound to fail when describing experiments involving coherence transfer. Efforts have been made to express higher order coherences through vectors [2], which help to illustrate the relationship between coupled spins in a spin state, but fail to provide a means to introduce interactions or propagators. Coherence transfer is at the core of most modern 2D NMR experiments that are routinely performed today. For a student or scholar, learning magnetic resonance therefore involves un-learning previously acquired concepts as much as learning new ones, as one progresses from several vector models to the product operator formalism and the density operators of statistical quantum mechanics. Understanding the limitations of each model becomes as important as comprehending the model itself. To this end, a simulation tool that compares different descriptions of spin and allows to isolate and understand each operation in the spin system is of immense value for both students and advanced scholars.

This paper discusses the development and advances of one of these tools, Insensitive (Incredible Nuclear Spin EvolutioN SImulation Tool Intended for Visual Education) [3], over the past 12 years. It is one among several efforts to simulate NMR experiments, including SpinDrops [4], PJNMR [5], the Virtual NMR Spectrometer [6], and the simulation modules of commercial NMR software packages like Bruker’s TopSpin. A special mention should be given to Spinach, which provides Matlab routines to simulate research-grade experiments for large, realistic spin systems with a high degree of optimisation and accuracy [7,8,9], but requires a high level of prior knowledge and relatively sophisticated computational hardware. Insensitive pursues a different aim by providing an opportunity to control each step during the simulation of the NMR experiment in isotropic solution, from setting up a simple spin system to processing a 2D spectrum, at the cost of optimisation. It is intended to lead students from getting acquainted with spin dynamics and magnetic resonance spectroscopy to understanding complex pulse sequences and processing techniques. It is written in a low-level language to be independent from costly software packages like Matlab and does not require the user to have any knowledge of computer programming. Insensitive runs on all major operating systems, including Microsoft Windows, Apple macOS, and Linux, as is illustrated in the Figures of this paper. The core components, capabilities and limitations of the program have been presented in a previous paper [3]. Hence, the present discussion focusses on the advances that Insensitive has made in the past 10 years, with examples to illustrate how the program can be used productively in teaching and self-study.

2 Methods

Insensitive was written in C using the GLib library and GTK+ 3.0 toolkit for the graphical interface. As such, it was completely rewritten from an earlier code base in Objective-C using the Cocoa framework for Apple Macintosh computers [3]. The simulation was implemented based on the density matrix of the spin ensemble using the Basic Linear Algebra Subprograms (BLAS) and Linear Algebra Package (LAPACK) libraries [10, 11]. Fourier transformations are performed using the FFTW3 Fourier transformation routines [12].

Relaxation is treated either phenomenologically by directly applying exponential dampening to the density matrix elements according to the parameters \(T_1\) and \(T_2\), or through a dipolar coupling mechanism using the Bloembergen–Purcell–Pound model as described by to Ernst, Bodenhausen, and Wokaun [13, 14]. Decoupling is executed by applying a \(180^\circ\) pulse to the selected spin types in the middle of each simulated time evolution step involving scalar coupling interactions. Spin locks are implemented by rotating the coordinate system by \(90^\circ\) around the y axis during free evolution of the spin system and relaxing towards equal population of spin states as opposed to a Boltzmann distribution. Pulsed field gradients are realised by splitting the spin ensemble into 201 slices, each of which being represented by a separate density matrix [15].

Insensitive can be compiled on any modern Posix-compatible operating system using the commands ./configure && make && sudo make install from the root of the source tree. For Microsoft Windows and Apple macOS pre-compiled packages are available for Intel 64-bit processors. The Windows version was compiled using the MSYS2 ucrt64 build environment. The macOS Version was compiled using JHBuild in the GTK-OSX modulesets. Further information can be obtained from the projects GitHub page at https://www.github.com/klausboldt/insensitive/.

3 Discussion

The simulation of the NMR experiment in Insensitive is divided into four modules and comprises setting up a spin system, manipulating the spin state, recording and running a pulse sequence, and acquiring and processing a spectrum. All simulation is based on a density matrix that describes the spin state at the level of the spin ensemble. In addition, a separate simulation animates the behaviour of an individual spin under free precession or the influence of a radio-frequency field.

Insensitive comes with a hypertext tutorial that introduces the basic concepts and pulse sequences of NMR spectroscopy, as well as providing a user manual. Despite that, it is highly recommended to use the program in combination with a textbook on NMR. Spin Dynamics by Malcolm Levitt [16], Understanding NMR Spectroscopy by James Keeler [17], and Principles of NMR Spectroscopy: An Illustrated Guide by David P. Goldenberg [18] have been used extensively while writing Insensitive.

3.1 Setting Up a Spin System

Fig. 1
figure 1

A spin system of up to 4 spins and 2 spin types (I and S) can be set up. The energy diagram to the right shows the relative energy eigenvalues and allowed single-quantum transitions

Insensitive allows to define up to four spins and two possible spin types, I and S, in accordance with the conventions of most textbooks. This represents an abstraction from a real, molecular system. The values for the gyromagnetic ratio of I and S spins can be selected from a list of common spin-\(\frac{1}{2}\) nuclei (see Fig. 1). Natural abundance is not considered and each spin type is assumed to be present with 100% purity. The Zeeman splitting in Insensitive is given relatively to the spin type with the larger gyromagetic ratio, so that the amplitude of a single spin of that type at thermal equilibrium is normalised to one. Each spin type is observed in its own rotating frame, so that the Larmor frequencies shown in the simulation are the offset frequencies \(\Omega =\omega -\omega ^0\) with respect to the transmitter frequency offset \(\Omega ^0=0\) Hz. This reduces the complexity of the simulation, shifts the attention to the general interactions and allows precession to be easily observed in the vector representation.

The interactions of the simulated spin system are defined by the scalar and dipolar coupling constants J and b and the distance r between spins. The latter two quantities are redundant and can be calculated from one another. They determine the relaxation rate and the strength of magnetisation transfer via the nuclear Overhauser effect (NOE) only if dipolar relaxation is activated.

On the right side of the window, the spin system is displayed as an energy level diagram showing the relative energies (black horizontal lines), allowed single-spin transitions (red double arrows) [19] and state labels (e.g. \(\alpha _1\beta _2\)). If strong coupling effects are considered, the relative strength of the transitions is reflected by the transparency of the transition arrow. Under strong coupling conditions (\(J_{12}\approx |\Omega _1-\Omega _2|\)) the states mix and cannot be labelled using the individual contributing spin states \(\alpha\) (spin up) and \(\beta\) (spin down). Hence, if strong coupling is activated, the states are labelled \(\psi _n\) with \(n=1,2,...\) in the order of increasing energy. Magnetically equivalent spins are labelled using the singlet–triplet basis (e.g. \(S_0\), \(T_{-1}\), \(T_0\), and \(T_{+1}\) for a two-spin system) if strong coupling effects are included in the simulation.

3.2 Manipulating the Spin State

Fig. 2
figure 2

Insensitive displays the current spin state as a vector model, density matrix, and string of product operators and allows to manipulate it by applying pulses, elements of free precession, and pulsed field gradients. The left vector plot shows the spin trajectory after applying a 90\(^\circ\) off-resonance E-BURP 2 pulse

The heart of Insensitive is the Spin State module, in which the three models for the spin state, the vector model, density matrix \(\hat{\rho }\), and product operators, are shown alongside each other for the current spin system and state (see Fig. 2). The spin state can be manipulated my applying a radio-frequency (rf) pulse, a period of free evolution (comprising of precession, scalar coupling, and relaxation, which can also be applied separately), a pulsed field gradient along the z direction of the \(\textbf{B}_0\) field, and spectrum acquisition. There are also functions to undo the last applied step, and to return the system to a state of thermal equilibrium. The parameters for the operations are taken from the settings panel on the right side of the screen.

The simulated spin state is directly shown as the matrix representation of the density operator, scaled in such a way that each spin of the spin type with the larger gyromagnetic ratio is represented by an excess population of 1. The matrix elements that correspond to observable coherences are coloured (green and red to identify the complex conjugate values of the Hermitian matrix). Alternatively to a numerical matrix, the matrix elements can be shown graphically, with excess population displayed as blue bars and coherences as a vector in a complex unit circle.

The product operators that describe the spin state are displayed below the vector model and density matrix. They can be expressed in either the cartesian basis or the spherical tensor basis. Insensitive helps in understanding the product operator formalism [2, 20] in two ways: First as a description of spin states, for which the coefficients \(c=\textrm{tr}(\hat{\rho }\hat{\Omega })\) are directly calculated as the trace of the matrix product of the density matrix \(\hat{\rho }\) with the respective product operator \(\hat{\Omega }\). To get a direct comparison of a specific product operator with its representation as a vector or density matrix, the spin state can be set to an arbitrary linear combination of product operators using the Matrix Composer window. Any operation can then be performed on the isolated state as it would be on the full set of states. This can be used, e.g. to demonstrate the coherence transfer between a pair of coupled spins.

However, the product operators not only describe states, but also propagators. Therefore, Insensitive has a command line that understands product operators in a way that intuitively matches the way they are written in textbooks. For example, \(\texttt{90\, I1x}\) applies the pulse operator for a \(90^\circ\) pulse around the x axis to spin 1 of the spin system, leading to the operation

$$\begin{aligned} \hat{I}_{1z} \xrightarrow {\quad \pi /2\,\hat{I}_{1x}\quad } -\hat{I}_{1y}. \end{aligned}$$

The operator assumes that the preceding, numerical argument is given in units of degrees, but also accepts \(\texttt{pi/2}\) for \(90^\circ\), \(\texttt{pi}\) for \(180^\circ\), and \(\texttt{3pi/2}\) for \(270^\circ\). If no argument is given, a \(90^\circ\) pulse is issued.

Similarly, the command \(\texttt{0.5\, I1z}\) applies the operator for precession under the influence of the external magnetic field to spin 1 for the duration \(t=0.5\) s.

$$\begin{aligned} -\hat{I}_{1y} \xrightarrow {\quad t\,\hat{I}_{1z}\quad } -\cos {(\Omega _1t)}\hat{I}_{1y}+\sin {(\Omega _1t)}\hat{I}_{1x}. \end{aligned}$$

It is important to note that the units of time for free precession are scaled to make the animation didactically useful, not to match the much faster real, physical process. Hence, a spin with a Larmor frequency \(\Omega =1\) Hz performs a rotation of \(360^\circ\) after precessing for 1 s (as observed from the rotating frame of reference). If no preceding coefficient is given, the delay time is taken from the settings panel.

Finally, the longitudinal two-spin order product operator \(\texttt{2I1zI2z}\) applies the scalar coupling operation exclusively to the addressed spins, in this case spin 1 and spin 2, again for the delay time t:

$$\begin{aligned} -\hat{I}_{1y} \xrightarrow {\quad \pi J_{12}t\,2\hat{I}_{1z}\hat{I}_{2z}\quad } -\cos {(\pi J_{12}t)}\hat{I}_{1y}+\sin {(\pi J_{12}t)}2\hat{I}_{1x}\hat{I}_{2z}. \end{aligned}$$

Coupling between other spins are addressed in a similar manner, e.g. \(\texttt{2I2zS3z}\) for the coupling interaction between spin 2 (of type I) and spin 3 (of type S), and \(\texttt{4I1zI2zS3z}\) for coupling between three spins. A longitudinal two-spin order operator of the form \(2\hat{I}_{jz}\hat{I}_{kz}\) describes interactions only in the weak coupling regime. To include strong coupling effects, all cartesian components need to be considered in the product operator, e.g. as the product \(2\hat{\textbf{I}}_j\cdot \hat{\textbf{I}}_k=2(\hat{I}_{jx}\hat{I}_{kx}+\hat{I}_{jy}\hat{I}_{ky}+\hat{I}_{jz}\hat{I}_{kz})\). For spins 1 and 2 of type I, this is written as \(\texttt{2I1.I2}\) on the command line.

A condensed form of the operators can be used to apply a propagator to all spins of type I \(\texttt{(Ix, Iy, Iz, IzIz, I.I)}\), type S \(\texttt{(Sx, Sy, Sz, SzSz, S.S)}\), and all spins \(\texttt{(IzSz, I.S)}\). Apart from numerical arguments, Insensitive also correctly interprets \(\texttt{1/2J12}\) as a delay time of \(1/(2J_{12})\), i.e. the reciprocal value of twice the coupling constant between spin 1 and spin 2, which turns transversal into antiphase magnetisation. (Similarly, the denominators 3J, 4J, and 8J can be used, too.) In addition to product operators, the command line accepts a number of commands for acquisition and processing that are based on the Bruker TopSpin command language.

Insensitive has several steps of sophistication in the simulation of the spin dynamics, in reflectance of the different levels of knowledge that the user may have acquired. Relaxation via dipolar coupling of spins can be activated to simulate the effects of NOE at a slightly higher computational cost. If switched off, Insensitive falls back to a simple, phenomenological relaxation via exponential decays of the longitudinal and transverse magnetisation with the decay constants \(T_1\) and \(T_2\). In the same manner, as discussed in the previous paragraph, J-coupling can be applied with or without taking strong coupling effects into account, by activating a checkbox or using the appropriate operator. While a beginner might want to ignore strong coupling, an advanced user can use Insensitive to demonstrate and isolate the effect of strong coupling on polarisation transfer. Under the influence of the strong coupling operator, precession and scalar coupling can no longer be separated, because the coupling propagator exchanges magnetisation between the spins, depending of the relative phase of the coupled spin coherences [3]. To prevent unphysical behaviour of the simulation, the separate application of chemical shift and coupling operations are disabled if strong coupling effects are enabled. This does not affect the application of individual product operators on the command line, which is aimed at more experienced users who may wish to discuss that effect and the resulting artefacts.

Fig. 3
figure 3

The time domain and frequency domain of a shaped pulse can be viewed in the Pulse Shape window

Similarly, an rf-pulse with a certain flip angle \(\beta\) and phase \(\phi\) may be applied to all spins, or only to selected spins, which can be chosen individually or by type, using the settings panel. Alternatively, the pulse can be applied for a certain duration t with a strength \(\gamma B_1\) and at a frequency \(\Omega ^0\), which will lead to realistic off-resonance effects and first order phase shifts. A number of pulse shapes can be employed, including rectangle, Gauss, and sinc functions, BURP pulses, and a DANTE pulse train of rectangular pulses (see Fig. 3). The pulse shape and excitation profile can be viewed and adjusted using the Pulse Shape window. Hence, there is a simplified, but unphysical way to simulate a selective pulse, as well as fully realistic pulse profiles. Even at an advanced level, artificially applying pulses only to selected spins offers a great way of isolating and highlighting the response (see Fig. 2).

3.3 Recording a Pulse Sequence

Fig. 4
figure 4

A pulse sequence can be recorded and applied to the spin system as a whole or step-wise. This way, 2D spectrum acquisition with variable delay times, phase cycling, and amplitude modulation can be employed. The figure is a composition of two images, showing both the phase cycling table and the coherence pathway in the bottom half of the window

The operations on the spin system (pulses, free evolution, pulsed field gradients, and acquisition) can be recorded as a pulse sequence and applied to arbitrary spin systems, either in its entirety or step-wise (see Fig. 4). That offers the possibility to acquire two-dimensional spectra with a variable evolution time, include phase cycles for coherence pathway selection, and acquire amplitude-modulated datasets using the States, TPPI, or States-TPPI methods.

Insensitive is able to calculate the coherence transfer pathways for the currently loaded pulse sequence and spin system. These are derived directly from the product operators in the spherical tensor basis and, if the recorded pulse sequence ends with data acquisition, are filtered for n-type single-quantum coherences on the detection channel, as is customary for these graphs. In most cases, the coherence pathways will appear more crowded than the versions found in textbooks. This is due to the crucial dependence of the pathway selection on matching the delay times in the pulse sequence with the Larmor frequencies of the spin system. Only for a matched set of parameters an idealised textbook transfer pathway will be achieved that singles out the signals relevant for the respective experiment, e.g. cross peaks in a COSY-like spectrum. Insensitive is currently not able to predict these conditions. For a spin system consisting of p spins and a pulse sequence with n pulses there exist \((2p+1)^n\) possible coherence pathways, which need to be summed over all phase cycles. That calculation is currently done by brute force and, hence, for large systems and especially for long pulse sequences, Insensitive may be slow to display a result or not perform the calculation if the number of pathways exceeds a set threshold.

3.4 Processing a Spectrum

Fig. 5
figure 5

Insensitive can simulate 1D and 2D spectra and offers a wide range of standard functions for processing and analysis, including phase correction, apodisation, tilting, symmetrisation, peak picking, and processing of DOSY spectra. The graph shows an AMX spin system with random jitter and strong coupling enabled

Insensitive can acquire one- and two-dimensional spectra with a maximal resolution of \(4096\times 128\) data points, not counting zero filling. That enables the user to study the central aspects of spectrum processing, including the effects of dwell time and number of data points on the spectral resolution and spectral width, apodisation through a number of common window functions, phase correction, and tilting and symmetrising a 2D spectrum (see Fig. 5).

Two methods are available to introduce noise, through a random jitter of the spin states, i.e. random variation of the Larmor frequencies of simulated spin system, and as random noise that is added on top of the acquired data. The latter can be added to any one-dimensional spectrum after acquisition, while the former is directly associated with the behaviour of the spin system. It is encoded in the FID and proportional to the signal strength, i.e. it does not appear in the tail of the FID and cannot be reduced through apodisation. The spectrum data can be exported in a number of formats, including CSV, JCAMP-DX, and PNG bitmap, for use in presentations or documents outside the program itself, or to train spectrum processing with third-party software.

Fig. 6
figure 6

Steps towards a clean COSY spectrum: A With no phase cycling the spectrum is overlayed with a 1D spectrum as a result of \(T_1\) relaxation during the variable delay time. B The spectrum is mirrored at the centre of the indirect frequency domain if two phase cycles are used, due to a lack of quadrature detection. C A phase-twisted n-type spectrum is obtained using 4 phase cycles. D A pure-phase spectrum can be acquired using the States method. E Pure absorption-mode magnitude spectra can be calculated from the phase-twisted spectra using a Lorentz–Gauss pseudo-echo transformation. F The DQF-COSY experiment yields pure absorption-mode peaks

Between the Pulse Sequence and Spectrum module, it is easy to develop all that is necessary to reproduce and process a routine 2D NMR experiment like the COSY spectrum. This example is also described in detail in the tutorial that comes with the program. Between understanding the spin trajectory of the pulse sequence and a useful spectrum further steps are necessary that benefit greatly from hands-on visualisation, in particular the use of phase cycling as a means of getting rid of spectral artefacts. These include a superimposed 1D spectrum at the centre of the indirect frequency domain axis as a consequence of spin relaxation during the variable delay time followed by the second \(\pi /2\) pulse, and a mirrored spectrum due to the lack of quadrature detection in the indirect time domain (see Fig. 6A, B). For the removal of each artefact the number of phase cycles and, hence, the acquisition time and number of data points doubles. Finally, one is left with a COSY spectrum with mixed-phase peaks (Fig. 6C). It can be turned into a pure-phase, amplitude-modulated spectrum by using the States or TPPI acquisition methods (Fig. 6D), or processed further by apodisation (e.g. using a pseudo-echo transformation [13], Fig. 6E), calculation of a magnitude spectrum, and symmetrisation. Further simplification of the spectrum can be achieved by more sophisticated experiment such as a double quantum filtered or z-filtered COSY (Fig. 6F).

3.5 The Vector Model: From Single Spins to a Spin Ensemble

In the vector model, z magnetisation is aligned in parallel to the \(\textbf{B}_0\) field, although spin is often introduced as having a quantised orientation, with a vector tilted at an angle to the principal axis and precessing on the surface of a double cone (in the case of a spin-1/2). That apparent contradiction is easily resolved through the distinction between single spins and a spin ensemble, in which the average x and y components are zero. Already at the single-spin level, the uncertainty of the angular momentum in the x and y plane leads to a vanishing magnetic moment perpendicular to the z axis at thermal equilibrium, so hardly anyone who is familiar with NMR gives this a second thought. However, the transition from single spins to the ensemble deserves attention, because it often poses a challenge when the apparent correspondence between spin and a well-defined three-dimensional vector property gives rise to misconceptions that get carried well beyond the beginner level.

A major difficulty in grasping the intricacies and limitations of the vector model lies in the fact that the depiction depends strongly on the assumption of measurement. In the presence of a \(\textbf{B}_0\) field the measurement defines the z axis and the wave function collapses into one of two possible eigenstates \(\alpha\) or \(\beta\), while no definite statement can be made about the x and y components. Hence, the vector model takes the form of the double cone picture. The issue of a vector representation of spin has been discussed by Williamson, who argues in favour of a uniform vector model, in which individual spins are represented by vectors in a Bloch sphere that can assume any orientation in space, corresponding to an arbitrary coherent superposition of the \(\alpha\) and \(\beta\) state [21]. This picture has the advantage that the propagation of the individual spin vectors directly corresponds to that of the ensemble average. The translation from the eigenstates of a single spin to the macroscopic magnetic moment becomes trivial. However, the picture violates an important postulate of quantum mechanics: the way the model depicts the superposition states fundamentally cannot be observed by an experiment. Since it was the departure from a mechanical model that caused the breakthrough in quantum mechanics (the transition from Bohr’s planetary model of the atom to the abstract state space of Born and Heisenberg), it has didactic value to insist on only depicting measurable quantities, including their uncertainty. Thus, the preference for a vector model depends on the rigour with which one chooses to treat certain aspects of quantum mechanics.

Fig. 7
figure 7

A The Single Spins module, which animates the precession of individual spins in the double cone model under the influence of the \(\textbf{B}_0\) and \(\textbf{B}_1\) fields. The image shows a snapshot of the nutation of the magnetisation vector in the laboratory frame, with an exaggerated tilting due to the \(\textbf{B}_1\) field. The red shaded surface represents a single spin with uncertainty of the x, y and z components, the blue vector is the resulting magnetsation. B The linearly polarised rf-pulse can be split in two opposite, circular polarised components. Only one component can be in resonance with the spin’s Larmor frequency. In the rotating frame, this component appears static

Insensitive addresses the translation from single spins to a spin ensemble by providing a separate Single Spin window, in which a single spin-1/2 on resonance with the rf-pulse is simulated in the double cone picture (see Fig. 7A). The program offers a choice of three conditions: a homogeneous \(\textbf{B}_0\) field, irradiation with an rf-pulse (time-dependent \(\textbf{B}_1\) field), and an absence of any magnetic field. All conditions can be viewed from the laboratory or rotating frame. The angular momentum uncertainty is either displayed via an adjustable number n of individual vectors (between 1 and 1000) or as a shading of the cone surface as the limit of \(n\rightarrow \infty\). It needs to be emphasised that this picture represents a single spin through many hypothetical, simultaneous measurements, not a spin ensemble or repeated measurements of the same spin. Otherwise, it would suggest that the orientation of a vector on the surface of that cone in all three spatial directions can be known.

Application of a weak \(\textbf{B}_1\) field perturbs the external magnetic field. In the laboratory frame, the rf-pulse is circularly polarised. That causes a slight, periodic tumbling of the total magnetic field and, hence, the orientation of the double cone as defined by the measurement conditions, i.e. the total magnetic field \(\textbf{B}_0+\textbf{B}_1\). This tumbling motion is exaggerated in Insensitive for clarity. The perturbation leads the spin to relax to a new and continuously changing eigenstate. At all times the picture must comply with circular uncertainty inequalities,

$$\begin{aligned} \Delta I_x\,\Delta I_y&\geqslant \frac{\hbar }{2}\,|\langle I_z\rangle |, \nonumber \\ \Delta I_z\,\Delta I_x&\geqslant \frac{\hbar }{2}\,|\langle I_y\rangle |, \nonumber \\ \Delta I_y\,\Delta I_z&\geqslant \frac{\hbar }{2}\,|\langle I_x\rangle |, \end{aligned}$$
(1)

i.e. as the definition of the x and y components increases, the z component must assume higher uncertainty, resulting in a coherent superposition state. Effectively, that exerts a force on the spin that causes the nutation of the magnetisation vector.

In the rotating frame, the precession of the spin due to the \(\textbf{B}_0\) field is cancelled, which effectively removes the external field from the picture and, at the same time, turns the resonant, circularly polarised \(\textbf{B}_1\) field into a static field (see Fig. 7B). Hence, when switching to the rotating frame, Insensitive shows the eigenfunctions of the \(\hat{I}_x\) operator as a double cone oriented along the (static) \(\textbf{B}_1\) field. The \(\alpha\) state of the \(\hat{I}_z\) operator becomes a superposition state and the effect of the pulse is the precession of the spin state around the x axis.

It is important to emphasise that the orientation of any double cone depends on the measurement conditions, which are generally arbitrary, but are conventionally defined in NMR by the \(\textbf{B}_0\) field of the spectrometer. The double cones do not rotate around the axis of the \({\textbf {B}}_1\)-field. Instead, the excess population (in terms of the eigenstates of the \(\hat{I}_z\) operator) is converted from \(|\alpha \rangle\) to \(|\beta \rangle\) via a coherent superposition \(\frac{1}{\sqrt{2}}|\alpha \rangle +\frac{1}{\sqrt{2}}\beta \rangle\). As long as the expectation value has a defined orientation in the x,y plane, the component perpendicular to that must be completely uncertain. This can be clearly observed in Insensitive in that the red shading of the spin uncertainty (Fig. 7A) always covers (at least) half of the unit sphere under measurement.

If both the \(\textbf{B}_0\) and \(\textbf{B}_1\) fields are turned off, Insensitive reverts to a depiction of freely oriented vectors in a Bloch sphere, with a preference for alignment in one direction based on the adustable value for the thermal energy kT. This is didactically preferred to no depiction at all, although that would be the physically accurate way in the absence of a magnetic field.

3.6 Limitations

The Single Spin window also addressed a disadvantage of treating the NMR experiment on the level of the density matrix, which is that any distribution of states within an ensemble of like spins is averaged. The most obvious example is the refocussing of coherences by a spin echo after transverse relaxation. The loss of coherence is not encoded in a time-reversible manner. Hence, the only way to run the CPMG experiment in a meaningful way is by simulating the dephasing via a set of spins with slightly different Larmor frequencies. While the Single Spin window does not provide the possibility to apply refocussing pulses, it animates the effects of longitudinal (\(T_1\)) and transverse (\(T_2\)) relaxation on the expectation value of the individual spin.

In general, the density matrix approach in combination with the aim to let the user interact with as many steps of the simulation as possible reduces the options for optimisation. Insensitive is limited by the \(2^n\) exponential scaling law of the operator space [7], which explains the limitation to a maximum of four spins. At the current state of development, computationally demanding simulations like dipolar relaxation, gradients, and the calculation of coherence pathways take time. A DOSY experiment (stegp1s) for a spin system consisting of three spins with dipolar coupling enabled and \(1024\times 128\) complex data points took 50 min to compute on the development system (Ubuntu Linux 20.04 LTS, 3.2 GHz Intel Core i7 CPU), while the amplitude-modulated COSY spectrum (cosyph) shown in Fig. 5 completed in 20–30 s.

3.7 Uses of Insensitive in the Classroom

Insensitive can be employed for teaching in different ways. The program works well with a screen resolution of \(1024\times 768\) pixels, which is suitable for most projectors. Thus, it can be used to illustrate a lecture with animations rather than static images, or to quickly adapt a presentation to questions from the audience. Examples where Insensitive can significantly enhance a presentation are showing the dependence between pulse length and shape, excitation profile, and spin trajectory in a grapefruit plot (see Figs. 2 and 3), and the Single Spin window (Fig. 7A).

Insensitive can also be a very effective tool during self-study, either in conjunction with attending a lecture course or alone with a textbook. Here, Insensitive provides helpful hands-on experience if the user varies parameters and directly observes the resulting behaviour of either the spin system or the spectrum, or tests the effect of product operators. Insensitive can also help understand different means of data representation by offering alternative ways of displaying the same state; e.g. the vector diagram can be shown with individual vectors for each coherence. In this representation, pure antiphase magnetisation appears as two opposing vectors in the x,y plane, because the complex values of density matrix elements for single-quantum coherences and populations are directly translated into vectors. If one chooses to display magnetic moments instead, pure antiphase magentisation collapses to zero, because in this case the vectors are calculated from the (observable) expectation values for x, y, and z magnetisation of each spin, which are all zero for that state. Finally, the magnetisation can also be displayed as one cumulative vector per spin type, which directly yields the intensity of the FID if viewed from the x or y direction.

Insensitive can also be integrated into assignments or exercises, e.g. to develop phase cycling tables for a pulse sequence. The software comes with a collection of example files for spin systems, pulse programs, and corresponding spectra. To this end, the ability to execute pulse sequences step-by-step is extremely useful. Apart from the COSY spectrum discussed in Sect. 3.4, the INEPT sequence and its variations (phase cycled INEPT, refocused INEPT) is an excellent example of a recurring building block at which many concepts of NMR can be discussed, like antiphase magnetisation, coherence transfer, signal enhancement, and spin echoes.

4 Conclusion

Insensitive is a simulation of the NMR experiment for spin-1/2 in isotropic solution, written for didactic purposes. Since its original publication in 2011, it has gained significant capabilities that allow a scholar of NMR spectroscopy to simulate and understand all steps of the experiment, starting from the structure of a spin system via manipulating the spin state to designing and understanding pulse sequences and acquiring and processing one- and two-dimensional spectra. Significant improvements have been made in simulating physically accurate pulses, pulsed field gradients, recording pulse sequences, and obtaining 2D spectra, including pure phase spectra using the States and TPPI approaches. A simulation of the basic two cone model for individual spins has been added to help make the transition from the basic textbook model for spin to the description via statistical quantum mechanics. The advantages and disadvantages of using such a vector model have been discussed herein.

The program is published as open-source and libre software and is available for download from https://www.github.com/klausboldt/insensitive/. It can be compiled on most modern Unix-like operating systems (Linux, FreeBSD, etc.) or downloaded as pre-compiled binary files for Microsoft Windows and Apple macOS (for 64-bit Intel processors). Insensitive is still in active development. While it is largely complete and usable, it may contain bugs or be unstable. As a project with a single developer, some of these errors may not not show up in the development systems. Any bug reports and feedback to the corresponding author are greatly appreciated.