Datatypes

Datatypes in NMR

Molecular NMR parameters, spectra and calculation results are stored in python objects in the HQS NMR Tool. These data structures are as follows.

NMRParameters

The NMRParameters Pydantic datatype is defined in the hqs_nmr_parameters repository and holds the reduced set of molecular spin parametersrequired for a NMR calculation,

  • shifts (list[float]): List of chemical shifts in ppm for every nucleus in the system that has NMR parameters.
  • isotopes (list[Isotope]): List of isotopes for every nucleus, in the same ordering as shifts. The NamedTuple Isotope has the two attributes mass_number and symbol.
  • j_couplings (list[tuple[tuple[int, int], float]]): List containing pairs of atomic indices and the associated J-coupling values. The atomic indices refer to the ordering in the shifts and isotopes lists.

This data is accessed as attributes of the class instance:

from hqs_nmr_parameters import examples
nmr_parameters = examples.molecule_parameters["C10H7Br"].spin_system()
print(type(nmr_parameters))        # NMRParameters
print(nmr_parameters.shifts)
print(nmr_parameters.isotopes)
print(nmr_parameters.j_couplings)

NMRParameters objects are used as an input when calculating a spectrum using the calculate_spectrum method.

Spectrum

The Spectrum datatype holds a NMR spectrum comprising

  • half_width_ppm (float): Artificial broadening in ppm,

  • omegas (np.ndarray[float]): Frequencies in ppm,

  • values (np.ndarray[float]): Individual spin contributions to the spectrum. The values are a numpy array where each row holds the contribution of the corresponding spin, i.e.:

spectrum.values[0,:]

holds the contribution of the first spin (index 0). The total spectrum that would be measured experimentally can be calculated using

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

The Spectrum object is per default returned by the calculate_spectrum method used to calculate NMR spectra.

Greensfunction

The Greensfunction datatype holds the complex Green's function, of which the imaginary part corresponds to the NMR spectral function.

  • half_width_ppm (float): Artificial broadening in ppm,

  • omegas (np.ndarray[float]): Frequencies in ppm,

  • values (np.ndarray[complex]): Individual spin contributions to the Green's function. The values are a numpy array where each row holds the contribution of the corresponding spin, i.e.:

spectrum.values[0,:]

holds the contribution of the first spin (index 0). The total spectrum that would be measured experimentally can be calculated using

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

The Greensfunction object is returned by the calculate_spectrum method, if the flag calc_greens_function is set to True.

Serialization (Saving and Loading)

The datatypes described above have a common interface for data serialization. There exists a function called to_json common to all classes, that can take a class object and a file name (with or without the full path) to store the data as a JSON file. For example, if we have an object called spectrum of the data class Spectrum and want to save it as specrum_data.json:

from hqs_nmr.datatypes import to_json
to_json(spectrum, "spectrum_data.json")

There is also the inverse method from_json to load the data again. It needs as additional information the type of class the JSON file has stored, e.g.,

from hqs_nmr.datatypes import from_json, Spectrum
spectrum = from_json(Spectrum, "spectrum_data.json")