hqs_nmr.postprocessing

NMR spectra postprocessing routines.

Functions

adapt_spectrum_by_j_coupling(...)

Adapt a spectrum with respect to a shift in a J-coupling.

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.

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_ppm[, ...])

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_ppm: 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_ppm – 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.j_coupling_adaptation_parameters(result_greens_function: NMRResultGreensFunction1D, result_eom_greens_function: NMRResultGreensFunction1D, result_eom_correction_greens_function: NMRResultGreensFunction1D) dict[str, Any]

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. (Green's)

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

  • function.

Returns:

A dictionary with all necessary parameters.

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, dict[str, Any]]

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 a dictionary with all necessary parameters to perform a J-coupling adaptation.

hqs_nmr.postprocessing.adapt_spectrum_by_j_coupling(delta_j_coupling: float, rediscretized_omegas_rad_per_s: ndarray, rediscretized_omegas_ppm: ndarray, broadening_rad_per_s: float | ndarray, sz_terms_rad_per_s: ndarray, greens_function: ndarray, eom_greens_function: ndarray, eom_correction_greens_function: ndarray) ndarray

Adapt a spectrum with respect to a shift in a J-coupling.

Which J-coupling is shifted depends on the EOM correction Green’s function.

Parameters:
  • delta_j_coupling – Shift of the J-coupling.

  • rediscretized_omegas_rad_per_s – Rediscretized frequency range in rad per s.

  • rediscretized_omegas_ppm – Rediscretized frequency range in ppm.

  • broadening_rad_per_s – Artificial broadening (half of the fwhm) in rad per s. If a vector is handed over a spin-dependent broadening is assumed.

  • sz_terms_rad_per_s – Array with the coefficients of the I^z terms in the Hamiltonian.

  • greens_function – The spin contributions of the Green’s function to be adapted.

  • eom_greens_function – The spin contributions of the EOM Green’s function associated with

  • function. (the standard Green's)

  • eom_correction_greens_function – The spin contributions of the EOM correction Green’s

  • function.

Returns:

The normalized Green’s function spin contributions with the adapted J-coupling taken into account.