NMR spectra calculations

calculate_spectrum

For most use cases the calculate_spectrum function should be sufficient to perform NMR spectra calculations. By default, it uses the clustering approach discussed in the solver chapter. This approach is exact for molecules smaller than the specified maximum cluster size (set by default to 12) and for larger systems still extremely accurate, while also being very fast.

For a quick introduction to this method you can just read on, however, for a proper walkthrough of all the customization options check out the example notebooks.

calculate_spectrum takes as input an object of datatype NMRParameters, which stores the molecular isotopes, shifts and J-coupling values, and a second of type NMRCalculationParameters, which stores all parameters necessary to specify a NMR spectrum calculation.

You can calculate the spectrum for one of the example molecules simply as follows:

from hqs_nmr.calculate import calculate_spectrum
from hqs_nmr.datatypes import NMRCalculationParameters
from hqs_nmr_parameters.examples import molecules

# Obtain example molecule of datatype NMRParameters.
molecule_parms = molecules["C10H7Br"].spin_system()

# Define the calculation parameters.
calculation_parms = NMRCalculationParameters(frequency_MHz=500)

# Calculate the spectrum.
nmr_result = calculate_spectrum(
    molecule_parms,
    calculation_parms
)

nmr_result is now an object of datatype NMRResultSpectrum1D and stores the calculated spectrum as well as the input to the calculation. The spectrum could now be plotted as follows:

import numpy as np
import matplotlib.pyplot as plt

summed_spectrum = np.sum(nmr_result.spectrum.values, axis=0)

plt.plot(nmr_result.spectrum.omegas_ppm, summed_spectrum, linewidth=0.3, label="spectrum")
plt.title("C10H7Br")
plt.xlabel("$\\delta$ [ppm]")
plt.legend()
plt.show()

calculate_greens_function

The calculate_greens_function method behaves in the exact same way as calculate_spectrum with the only difference that the full Green's function is calculated instead of just the spectral function. It returns an object of datatype NMRResultGreensFunction1D. To get the full spectrum one can simply call:

from hqs_nmr.calculate import calculate_greens_function

nmr_result = calculate_greens_function(
    molecule_parms,
    calculation_parms
)

summed_spectrum = np.sum(
    - np.imag(nmr_result.spectrum.values), axis=0
)

However, typically the need to calculate the Green's function only arises, if some sort of post-processing needs to be performed.