hqs_nmr.postprocessing

NMR spectra postprocessing routines.

Functions

adapt_spectrum_by_j_coupling_shift_eta(...)

Adapt a spectrum with respect to a change in j-couplings, shift and eta.

broaden_the_broadenings(broadening_scalings, ...)

Broaden the peaks of the Green's function using spline fit.

create_new_molecule(molecule_parameters, ...)

Create a new molecular NMR parameter representation, with adapted shifts.

fit_spline_to_vector_function()

Fit spline to real or complex vector function.

get_fitted_greens_function(greens_function)

Calculate a spline fit of a Green's function after rediscretizing the frequencies.

get_j_coupling_adaptation_parameters(...)

Determine all parameters needed to adapt a Green's function with respect to some J-coupling.

prepare_j_coupling_adaptation(...)

Calculate the Green's function and all parameters needed to perform a J-coupling adaptation.

prepare_shifting(greens_function[, ...])

Prepare splines and rediscretized frequency points for shifting the shifts.

rediscretize_frequency_range(omegas[, ...])

Rediscretize the frequency range for the spline fits.

shift_greens_function(shifts, ...)

Shift Green's function using spline fit.

hqs_nmr.postprocessing.prepare_shifting(greens_function: NMRGreensFunction1D, num_omegas_spline: int = 2000, offset: float = 1e-12, zero_pad_range: tuple[float, float] | None = None, zero_pad_nums: tuple[int, int] = (5, 5)) tuple[ndarray, list[CubicSpline], list[CubicSpline]]

Prepare splines and rediscretized frequency points for shifting the shifts.

Note that shifting is expected to occur within the bounds of the frequency range given by the calculated Green’s function. If shifting beyond these limits is required, please provide a value for ‘zero_pad_range’ to set the desired spectrum limits. For 1H spectra we recommend a value of (-2., 15.).

Parameters:
  • greens_function – Green’s function calculated using hqs_nmr.

  • num_omegas_spline – Number of frequency points added to the rediscretized.

  • 2000. (frequencies. Defaults to)

  • offset – Small factor to avoid division by zero. Defaults to 1e-12.

  • zero_pad_range – The lower and upper limit (in ppm) for padding the spectrum. Note that the original spectrum’s frequency range must lie within these bounds. Therefore, pad_range represents the new edges of the padded spectrum. Defaults to ‘None’.

  • zero_pad_nums – Number of points padded to the edges of the spectrum given as (before, after), where ‘before’ corresponds to the number of points inserted in the beginning of the array, and ‘after’ represents the number of points appended to the array. Defaults to (5, 5).

Returns:

Original omegas with added linear discretization in ppm. splines_real: List with splines fitting the real part entries of the Green’s function. splines_complex: List with splines fitting the imaginary part entries of the Green’s function.

Return type:

rediscretized_omegas_ppm

hqs_nmr.postprocessing.shift_greens_function(shifts: ndarray, greens_function: NMRGreensFunction1D, rediscretized_omegas_ppm: ndarray, splines_real: list[CubicSpline], splines_imag: list[CubicSpline], number_relevant_spins: int) NMRSpectrum1D

Shift Green’s function using spline fit.

Parameters:
  • shifts – The shifts of the magnetic shifts.

  • greens_function – Green’s function that is supposed to be shifted.

  • rediscretized_omegas_ppm – Rediscretized frequency points in ppm.

  • splines_real – Splines for the real part of the Green’s function.

  • splines_imag – Splines for the imaginary part of the Green’s function.

  • number_relevant_spins – Number of times the homo-isotope appears in the molecule.

Returns:

Normalized and shifted spectrum.

hqs_nmr.postprocessing.broaden_the_broadenings(broadening_scalings: ndarray, greens_function: NMRGreensFunction1D, rediscretized_omegas_ppm: ndarray, splines_real: list[CubicSpline], splines_imag: list[CubicSpline], number_relevant_spins: int) NMRSpectrum1D

Broaden the peaks of the Green’s function using spline fit.

Parameters:
  • broadening_scalings – Vector with scaling factors for the broadenings of the individual spin contributions.

  • greens_function – Green’s function that is supposed to be broadened.

  • rediscretized_omegas_ppm – Rediscretized frequency points in ppm.

  • splines_real – Splines for the real part of the Green’s function.

  • splines_imag – Splines for the imaginary part of the Green’s function.

  • number_relevant_spins – Number of times the homo-isotope appears in the molecule.

Returns:

Normalized and shifted spectrum.

hqs_nmr.postprocessing.rediscretize_frequency_range(omegas: ndarray, num_omegas_spline: int = 2000) ndarray

Rediscretize the frequency range for the spline fits.

Add an additional linear discretization to the current distribution.

Parameters:
  • omegas – Frequency discretization without the linear discretization.

  • num_omegas_spline – Minimal number of points in the linear discretization.

Returns.:

Vector with new discretization.

hqs_nmr.postprocessing.fit_spline_to_vector_function(parameters: ndarray, vector_function: ndarray[tuple[Any, ...], dtype[floating]]) list[CubicSpline]
hqs_nmr.postprocessing.fit_spline_to_vector_function(parameters: ndarray, vector_function: ndarray[tuple[Any, ...], dtype[complexfloating]]) tuple[list[CubicSpline], list[CubicSpline]]

Fit spline to real or complex vector function.

Parameters:
  • parameters – Parameters at which the vector function was evaluated.

  • vector_function – Values of the vector function.

Returns:

If the vector function is real, it returns one list with a spline associated with each vector function entry, otherwise it returns one list for the real and one for the complex part.

hqs_nmr.postprocessing.create_new_molecule(molecule_parameters: MolecularData | NMRParameters, shifts_of_Jz_ppm: ndarray) NMRParameters

Create a new molecular NMR parameter representation, with adapted shifts.

Parameters:
  • molecule_parameters – Molecular NMR parameters that should be adapted.

  • shifts_of_Jz_ppm – Shifts of the magnetic shifts in ppm.

Returns:

Molecular NMR parameters with the adapted shifts.

hqs_nmr.postprocessing.get_fitted_greens_function(greens_function: NMRGreensFunction1D, num_omegas_spline: int = 2000, offset: float = 1e-12) tuple[ndarray, ndarray]

Calculate a spline fit of a Green’s function after rediscretizing the frequencies.

Parameters:
  • greens_function – Green’s function to fit.

  • num_omegas_spline – Number of frequency points added to the rediscretized frequencies.

  • 2000. (Defaults to)

  • offset – Small factor to avoid division by zero when fitting the Green’s function.

  • 1e-12. (Defaults to)

Returns:

Rediscretized frequency range and fitted Green’s function.

hqs_nmr.postprocessing.get_j_coupling_adaptation_parameters(result_greens_function: NMRResultGreensFunction1D, result_eom_greens_function: NMRResultGreensFunction1D, result_eom_correction_greens_function: NMRResultGreensFunction1D) JCouplingAdaptationParameters

Determine all parameters needed to adapt a Green’s function with respect to some J-coupling.

Note that all Green’s functions used here should be non normalized.

Parameters:
  • result_greens_function – Green’s function that should be adapted.

  • result_eom_greens_function – EOM Green’s function associated with the standard NMR Green’s function.

  • result_eom_correction_greens_function – EOM Green’s function to correct the standard NMR Green’s function.

Returns:

parameters needed for the adaption.

Return type:

JCouplingAdaptationParameters

hqs_nmr.postprocessing.prepare_j_coupling_adaptation(molecule_parameters: MolecularData | NMRParameters, calculation_parameters: NMRCalculationParameters, adaptation_indices: tuple[int, int] | list[tuple[int, int]]) tuple[NMRResultGreensFunction1D, JCouplingAdaptationParameters]

Calculate the Green’s function and all parameters needed to perform a J-coupling adaptation.

Parameters:
  • molecule_parameters – The molecular data/NMR parameters of the molecule, which should be adapted.

  • calculation_parameters – The NMR calculation parameters as defined for a standard NMR Green’s function calculation.

  • adaptation_indices – Tuple or list of tuple of all J-coupling which are supposed to be adapted at once.

Returns:

The result of a standard Green’s function calculation using the input parameters and the parameters to perform a J-coupling adaptation.

hqs_nmr.postprocessing._gf_from_splines_of_inv(omegas: ndarray, splines_real: list[Callable], splines_imag: list[Callable], shifts: ndarray) ndarray

Evaluates the Green’s function from the splines of its inverse.

Parameters:
  • omegas (np.ndarray) – frequencies at which to evaluate the correlator in ppm.

  • splines_real (list[Callable]) – splines of the real part of the inverse Green’s function.

  • splines_imag (list[Callable]) – splines of the imag part of the inverse Green’s function.

  • shifts (np.ndarray) – shifts to apply in ppm.

Returns:

evaluated Green’s function.

Return type:

np.ndarray

hqs_nmr.postprocessing.adapt_spectrum_by_j_coupling_shift_eta(delta_j_coupling: float, delta_eta: float, delta_shifts: ndarray, omegas_ppm: ndarray, j_coupling_adaptation_parameters: JCouplingAdaptationParameters) ndarray

Adapt a spectrum with respect to a change in j-couplings, shift and eta.

Parameters:
  • delta_j_coupling – The shift in the J-coupling in Hz.

  • delta_eta – The shift in the eta parameter in Hz.

  • delta_shifts – The shifts in ppm.

  • omegas_ppm – The frequencies at which to evaluate the correlator in ppm.

  • j_coupling_adaptation_parameters – Object storing all parameters necessary for the adaption process.

Returns:

The normalized Green’s function spin contributions with the adapted j-couplings, shifts and eta taken into account.

Return type:

(np.ndarray)