hqs_nmr.utils

Helper routines for nmr spectra calculations.

Functions

check_local_su2(cluster_size, solver_settings)

Check in a simple way, if local SU2 symmetry could be helpful.

guess_frequency_window_ppm(isotopes, shifts, ...)

Obtain a guess for a frequency window for a molecule.

guess_spectrum(isotopes, shifts, ...[, ...])

Obtain a guess for a frequency window for a molecule.

lorentzian_broadening_from_fwhm(fwhm)

Broadening of lorentzian is half of the fwhm.

lorentzian_broadening_from_spin_parameters(...)

Estimate the Lorentzian broadening from spin parameters.

nmr_rescale_frequencies(omegas, values[, ...])

Rediscretize the frequency axis in NumStep frequency points.

non_normalized_values(correlator)

Evaluate non normalized spectrum given a correlator.

normalize_correlator(omegas, correlator[, ...])

Normalize a correlator w.r.t.

reduce_contributions_to_relevant_spins(...)

Check if only the spins associated with the homoisotope should be evaluated or all spins.

simplify_spin_expression(expression, num_spins)

Simplify a fermions expression into a normalized expression containing only spin operators.

hqs_nmr.utils.check_local_su2(cluster_size: int, solver_settings: NMRSolverSettings) bool

Check in a simple way, if local SU2 symmetry could be helpful.

This check does not search for groups, but just checks, if local SU2 symmetry could at all be beneficial. Further checks are done in the actual solver routine.

Parameters:
  • cluster_size – Size of the cluster.

  • solver_settings – NMRSolverSettings object storing information on the clustering and solver method.

Returns:

If local SU2 should be exploited True, otherwise False.

hqs_nmr.utils.guess_frequency_window_ppm(isotopes: list[Isotope], shifts: npt.ArrayLike, homoisotope: Isotope) tuple[float, float]

Obtain a guess for a frequency window for a molecule.

Parameters:
  • isotopes – List of isotopes; each given as Isotope(mass, symbol).

  • shifts – List of chemical shifts in parts-per-million (ppm).

  • homoisotope – Isotope specified as Isotope(mass, symbol) to define the frequency (w=gamma*field) of the rotating frame. For example, Isotope(1, ‘H’).

Returns:

Suggested (omega_min, omega_max) in ppm.

hqs_nmr.utils.guess_spectrum(isotopes: list[Isotope], shifts: npt.ArrayLike, homoisotope: Isotope, broadening_ppm: float, frequency_window_ppm: tuple[float, float] | None = None, broadening_scaling_factor: float = 250.0, number_frequency_points: int = 500) tuple[np.ndarray, np.ndarray]

Obtain a guess for a frequency window for a molecule.

Parameters:
  • isotopes – List of isotopes, each specified as Isotope(mass, element).

  • shifts – List of chemical shifts in parts per million (ppm).

  • homoisotope – Isotope specified as Isotope(mass, symbol) to define the frequency (w=gamma*field) of the rotating frame. For example, Isotope(1, ‘H’).

  • broadening_ppm – Broadening in ppm.

  • frequency_window_ppm – Optional upper and lower bound of user defined energy window in ppm.

  • broadening_scaling_factor – Scaling factor of broadening_ppm to include frequencies, where potential multiplet peaks could be. Defaults to 250.

  • number_frequency_points – Number of frequency points for the estimated spectrum. Defaults to 500.

Returns:

omegas and values

hqs_nmr.utils.lorentzian_broadening_from_fwhm(fwhm: float) float

Broadening of lorentzian is half of the fwhm.

Parameters:

fwhm – Full width half maximum.

Returns:

Broadening of the Lorentzian in same unit as fwhm.

hqs_nmr.utils.lorentzian_broadening_from_spin_parameters(isotopes: list[Isotope], j_couplings: list[tuple[tuple[int, int], float]], homoisotope: Isotope) float

Estimate the Lorentzian broadening from spin parameters.

Parameters:
  • isotopes – List of isotopes for every nucleus, in the same ordering as shifts. Every isotope is defined as Isotope(mass, symbol).

  • j_couplings – List containing J-coupling constants between nuclei. It contains tuples of pairs of integers and the associated coupling value, representing the respective nuclei indices (via their positions in the isotopes lists, starting counting with 0).

  • homoisotope – Isotope specified as Isotope(mass, symbol) to define the frequency (w=gamma*field) of the rotating frame. For example, Isotope(1, ‘H’).

Returns:

The broadening in rad / s.

hqs_nmr.utils.nmr_rescale_frequencies(omegas: ndarray, values: ndarray, number_steps: int = 100, limit: float = 0.0008) ndarray

Rediscretize the frequency axis in NumStep frequency points.

Perform an equal area partitioning of values. values should be >= 0.

Parameters:
  • omegas – Original reference frequencies.

  • values – Reference spectral values.

  • number_steps – Number of frequency points.

  • limit – Portion of spectrum to be skipped for defining the start and end point.

Returns:

An array with number_steps frequency points of the spectral function for each frequency.

hqs_nmr.utils.non_normalized_values(correlator: ndarray) ndarray

Evaluate non normalized spectrum given a correlator.

Parameters:

correlator – Correlator from which to evaluate the non normalized spectrum.

Returns:

Non normalized spectral values

hqs_nmr.utils.normalize_correlator(omegas: ndarray, correlator: ndarray, number_relevant_spins: int | None = None) ndarray

Normalize a correlator w.r.t. the number of times the homoisotope appears in the molecule.

If correlator is a Green’s function only normalize with respect to its imaginary part.

Parameters:
  • omegas – Frequencies at which the correlator was evaluated.

  • correlator – Correlator which is supposed to be normalized.

  • number_relevant_spins – Number of times the homoisotope appears in the molecule.

Returns:

Normalized correlator.

hqs_nmr.utils.reduce_contributions_to_relevant_spins(spin_contributions: list[int], molecule_parms: NMRParameters, homoisotope: Isotope, solver_settings: NMRSolverSettings) list[int]

Check if only the spins associated with the homoisotope should be evaluated or all spins.

This function adapts the list of spin contributions accordingly.

Parameters:
  • spin_contributions – List with indices of spin contributions that are supposed to be calculated.

  • molecule_parms – The molecular isotopes, shifts and J-coupling values.

  • homoisotope – Isotope specified as Isotope(mass, symbol) to define the frequency (w=gamma*field) of the rotating frame. Defaults to Isotope(1, ‘H’).

  • solver_settings – NMRSolverSettings object storing information on the cluster and solver methods. If None, the default solver parameters are used. Defaults to None.

Returns:

When solver_settings.only_relevant_spins is True (default), spin contributions list without spin indices of a different isotope than the homoisotope are returned. Otherwise the unaltered spin contributions.

hqs_nmr.utils.simplify_spin_expression(expression: fermions.ExpressionSpinful, num_spins: int, threshold: float = 1e-05) fermions.ExpressionSpinful

Simplify a fermions expression into a normalized expression containing only spin operators.

Args.:

expression: Expression to be converted. num_spins: number of spins in the expression. threshold: Threshold for the normalization.

Returns:

Simplified expression.