NMRPy / nmrpy

A Python module for processing NMR spectra.
BSD 3-Clause "New" or "Revised" License
20 stars 10 forks source link

Deconvolution #5

Open AdriennR opened 10 months ago

AdriennR commented 10 months ago

Hi, So I have been trying to deconvolve some 1D spectra and it works nicely, but usually when deconvolution is done, or other types of fittings, you can fix some of your parameters, like the peak position or the integrals or the linewidth. The same is true e.g. in ssnake. How can I do this here, because if I got it right, in the peaks and ranger, also with the frac_gauss I give the initial values for the fitting that are all going to be modified, and this can be a bit problematic in case the peaks are small or when I actually want to follow the change of peak intensities upon the change of some parameters (and sometimes the peaks become very small, so the program will compensate by making them very large.

jmrohwer commented 10 months ago

The only parameters that can be changed here are the optimization method, the frac_gauss and whether to use multiprocessing or not. See: https://nmrpy.readthedocs.io/en/latest/data_objects.html#nmrpy.data_objects.FidArray.deconv_fids

The peak position is taken from the peak list. The ranges give the range over which the deconvolution optimization is carried out. You could play around with selecting a separate range for every peak or combining them in various ways. See for example the documentation where we've selected two ranges for 4 peaks, with the one range containing 3 peaks, and the other range only 1 peak. For each range, the deconvolution is carried out separately, but if there is more than 1 peak in a range, these peaks are all deconvoluted together. How to do this best depends how close the peaks are and if they overlap.

It is not possible to fix the integrals or the linewidth, these are outputs of the deconvolution process.

You are of course welcome to dig into the source code and adapt this to your own needs :smile:

AdriennR commented 10 months ago

Hi, Do you know if I can get the chemical shift and linewidth values after optimisation? Thank you.

jmrohwer commented 10 months ago

From the source:

    fid._deconvoluted_peaks()
        """This is a list of lists of peak parameters with the order [offset, gauss_sigma, lorentz_hwhm, amplitude, frac_gauss]:

            offset: spectral offset

            gauss_sigma: Gaussian sigma

            lorentz_hwhm: Lorentzian half-width-at-half-maximum

            amplitude: height of peak

            frac_gauss: fraction of peak to be Gaussian (Lorentzian fraction is 1-frac_gauss)
         """