tesliper.datawork.spectra

Functions that deal with spectra and spectral data.

Functions

calculate_average(values, populations)

Calculates weighted average of values, where populations are used as weights.

calculate_spectra(frequencies, intensities, ...)

Calculates spectrum for each individual conformer.

convert_band(value, from_genre, to_genre)

Convert one representation of band to another.

count_imaginary(frequencies)

Finds number of imaginary frequencies of each conformer.

find_imaginary(frequencies)

Finds all conformers with imaginary frequency values.

find_offset(ax, ay, bx, by[, upscale])

Finds value, by which the spectrum should be shifted along x-axis to best overlap with the first spectrum.

find_scaling(a, b)

Find factor by which values b should be scaled to best match values a.

gaussian(intensities, frequencies, abscissa, ...)

Gaussian fitting function for spectra calculation.

idx_offset(a, b)

Calculate offset by which b should be shifted to best overlap with a.

lorentzian(intensities, frequencies, ...)

Lorentzian fitting function for spectra calculation.

unify_abscissa(ax, ay, bx, by[, upscale])

Interpolate one of the given spectra to have the same points density as the other given spectrum.

tesliper.datawork.spectra.count_imaginary(frequencies: numpy.ndarray)[source]

Finds number of imaginary frequencies of each conformer.

Parameters

frequencies – List of conformers’ frequencies. Array with one dimension is interpreted as list of frequencies for single conformer.

Returns

Number of imaginary frequencies of each conformer.

Return type

numpy.ndarray

Raises

ValueError – If input array has more than 2 dimensions.

tesliper.datawork.spectra.find_imaginary(frequencies: numpy.ndarray)[source]

Finds all conformers with imaginary frequency values.

Parameters

frequencies – List of conformers’ frequencies.

Returns

List of the indices of conformers with imaginary frequency values.

Return type

numpy.ndarray

Raises

ValueError – If input array has more than 2 dimensions.

tesliper.datawork.spectra.gaussian(intensities: numpy.ndarray, frequencies: numpy.ndarray, abscissa: numpy.ndarray, width: Union[int, float]) numpy.ndarray[source]

Gaussian fitting function for spectra calculation.

Parameters
  • intensities – Appropriate values extracted from gaussian output files.

  • frequencies – Frequencies extracted from gaussian output files.

  • abscissa – List of wavelength/wave number points on spectrum x axis.

  • width – Number representing half width of peak at 1/e its maximum height.

Returns

List of calculated intensity values.

Return type

numpy.ndarray

Raises

ValueError – If given width is not greater than zero. If intensities and frequencies are not of the sane shape.

tesliper.datawork.spectra.lorentzian(intensities: numpy.ndarray, frequencies: numpy.ndarray, abscissa: numpy.ndarray, width: Union[int, float]) numpy.ndarray[source]

Lorentzian fitting function for spectra calculation.

Parameters
  • intensities – Appropriate values extracted from gaussian output files.

  • frequencies – Frequencies extracted from gaussian output files.

  • abscissa – List of wavelength/wave number points on spectrum x axis.

  • width – Number representing half width of peak at half its maximum height.

Returns

List of calculated intensity values.

Return type

numpy.ndarray

Raises

ValueError – If given width is not greater than zero. If intensities and frequencies are not of the same shape.

tesliper.datawork.spectra.calculate_spectra(frequencies: numpy.ndarray, intensities: numpy.ndarray, abscissa: numpy.ndarray, width: Union[int, float], fitting: Callable[[numpy.ndarray, numpy.ndarray, numpy.ndarray, float], numpy.ndarray])[source]

Calculates spectrum for each individual conformer.

Parameters
  • frequencies – List of conformers’ frequencies in cm^(-1). Should be of shape (number _of_conformers, number_of_frequencies).

  • intensities – List of calculated signal intensities for each conformer. Should be of same shape as frequencies.

  • abscissa – List of points on x axis in output spectrum in cm^(-1).

  • width (int or float) – Number representing peak width in cm^(-1), used by fitting function.

  • fitting (function) – Function, which takes intensities, frequencies, abscissa, hwhm as parameters and returns numpy.array of calculated spectrum points.

Returns

Array of intensity values for each conformer.

Return type

numpy.ndarray

Raises

ValueError – If given width is not greater than zero. If intensities and frequencies are not of the same shape.

tesliper.datawork.spectra.calculate_average(values: Union[Sequence[Union[int, float]], numpy.ndarray], populations: Union[Sequence[Union[int, float]], numpy.ndarray]) numpy.ndarray[source]

Calculates weighted average of values, where populations are used as weights.

Parameters
  • values – List of values for each conformer, should be of shape (N, M), where N is number of conformers and M is number of values.

  • populations – List of conformers’ populations, should be of shape (N,) where N is number of conformers. Should add up to 1.

Returns

weighted arithmetic mean of values given.

Return type

numpy.ndarray

Raises

ValueError – If parameters of non-matching shape were given.

tesliper.datawork.spectra.idx_offset(a: Sequence[Union[int, float]], b: Sequence[Union[int, float]]) int[source]

Calculate offset by which b should be shifted to best overlap with a. Both a and b should be sets of points, interpreted as spectral data. Returned offset is a number of data points, by which b should be moved relative to a, to get the best overlap of given spectra.

Parameters
  • ay values of the first spectrum.

  • by values of the second spectrum.

Returns

Offset, in number of data points, by which spectrum b should be shifted to best match spectrum a. Positive value means it should be shifted to the right and negative value means it should be shifted to the left of a.

Return type

int

Notes

The best overlap is found by means of cross-correlation of given spectra.

tesliper.datawork.spectra.unify_abscissa(ax: Sequence[Union[int, float]], ay: Sequence[Union[int, float]], bx: Sequence[Union[int, float]], by: Sequence[Union[int, float]], upscale: bool = True) Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

Interpolate one of the given spectra to have the same points density as the other given spectrum.

Which spectra should be interpolated is determined based on the density of points of both spectra, by default more loosely spaced spectrum is interpolated to match spacing of the other spectrum. This may be changed by passing upscale=False to the function call.

Parameters
  • ax – Abscissa of the first spectrum.

  • ay – Values of the first spectrum.

  • bx – Abscissa of the second spectrum.

  • by – Values of the second spectrum.

  • upscale – If interpolation should be done on more loosely spaced spectrum (default). When set to False, spectrum with lower resolution will be treated as reference.

Returns

Spectra, one unchanged and one interpolated, as a tuple of numpy arrays of x and y values. I.e. tuple(ax, ay, new_bx, new_by) or tuple(new_ax, new_ay, bx, by), depending on values of upscale parameter.

Return type

tuple of np.arrays of numbers

tesliper.datawork.spectra.find_offset(ax: Sequence[Union[int, float]], ay: Sequence[Union[int, float]], bx: Sequence[Union[int, float]], by: Sequence[Union[int, float]], upscale: bool = True) float[source]

Finds value, by which the spectrum should be shifted along x-axis to best overlap with the first spectrum. If resolution of spectra is not identical, one of them will be interpolated to match resolution of the other one. By default interpolation is done on the lower-resolution spectra. This can be changed by passing upscale = False to function call.

Parameters
  • ax – Abscissa of the first spectrum.

  • ay – Values of the first spectrum.

  • bx – Abscissa of the second spectrum.

  • by – Values of the second spectrum.

  • upscale – If interpolation should be done on more loosely spaced spectrum (default). When set to False, spectrum with lower resolution will be treated as reference for density of data points.

Returns

Value, by which second spectrum should be shifted, in appropriate units.

Return type

float

tesliper.datawork.spectra.find_scaling(a: Sequence[Union[int, float]], b: Sequence[Union[int, float]]) float[source]

Find factor by which values b should be scaled to best match values a.

Parameters
  • ay values of the first spectrum.

  • by values of the second spectrum.

Returns

Scaling factor for b values.

Return type

float

Notes

If scaling factor cannot be reasonably given, i.e. when b is an empty list or list of zeros or NaNs, 1.0 is returned. Values lower than 1% of maximum are ignored.

tesliper.datawork.spectra.convert_band(value: Union[float, numpy.ndarray], from_genre: str, to_genre: str) Union[float, numpy.ndarray][source]

Convert one representation of band to another.

Parameters
  • value – Value(s) to convert.

  • from_genre – Genre specifying a representation of band of input data. Should be one of: ‘freq’, ‘wavelen’, ‘ex_en’.

  • to_genre – Genre specifying a representation of band, to which you want to convert. Should be one of: ‘freq’, ‘wavelen’, ‘ex_en’.

Returns

Requested representation of bands. If from_genre is same as to_genre, then simply value is returned.

Return type

float or np.ndarray