ComPlat / chemotion_ELN

Electronic Lab Notebook
https://www.chemotion.net
GNU Affero General Public License v3.0
125 stars 51 forks source link

NMR processing with spectral editor - only first scan displayed?!? #1826

Open schatzsc opened 7 months ago

schatzsc commented 7 months ago

The 1H NMR spectrum uploaded to Chemotion and displayed with the spectrum editor does not match with what's shown in TopSpin:

The following two figures show the spectrum and an enlarge view thereof in TopSpin, with the spectrum featuring a large broad signal at around 12 ppm from an NH or OH group:

figure1

figure2

However, in the internal spectrum viewer of Chemotion, this feature is notably absent and also the baseline looks more noisy:

figure3

A related problem was already observed for 195Pt NMR as reported previously in

Issue 1685

We suspect that the spectrum editor only displays the first of regularly (in our 1H NMR settings) 32 scans instead of averaging over all scans, which would explain the higher background noise and poor quality of the 195Pt NMR in Chemotion in contrast to TopSpin.

The full Bruker file folder of the example above is attached below:

12.zip

baolanlequang commented 7 months ago

Hi @schatzsc ,

In your zip file, there is a processed file that you can select to work by using the dropdown menu on the top of modal

Screenshot from 2024-03-20 15-29-51

For your inquiry about why our spectra editor produces shows a little different compared with the one in Topspin, the answer is we are using a baseline corrector algorithm which is described in this article.

schatzsc commented 7 months ago

@baolanlequang Thank you very much for the suggestion, but the "processed" file is only there since we wanted to check if the Chemotion Spectrum Editor and TopSpin results are the same - ideally we want to process the whole NMR exclusively in the ELN only.

About the baseline correction - I still consider this as a bug if the algorithm removes peaks which are clearly there and associated with protons in the compound that are just broader than normal due to H/D exchange with solvent, like OH or NH protons which are quite common in our compounds.

The minimum would be an option to switch the baseline correction off.

schatzsc commented 7 months ago

@baolanlequang Furthermore, can you positively confirm that all scans of a NMR spectrum recording are averaged and displayed in the NMR instead of just the first or last one?!?

PiTrem commented 6 months ago

@schatzsc in the example zip, provided the fid contains the 96k TD points and is the sum of the aquired scans as it is usually the case if I recall properly with Bruker (single scans are not individually recorded).

chemspectra-app is using nmrglue for nmr processing and will applied a set of basic processing steps :

those can be quickly reproduced in a jupyter notebook:

import scipy
import numpy as np
!python -m pip install git+https://github.com/jjhelmus/nmrglue
import nmrglue as ng

dic, data = ng.bruker.read('./12/11')
print("The data has {0} dimensions and has NP {1} \nwhich are of type {2}."
.format(data.ndim, data.shape, data.dtype))

processed_data = data
num_pts = processed_data.shape[-1]
# https://nmrglue.readthedocs.io/en/latest/reference/generated/nmrglue.fileio.bruker.remove_digital_filter.html#nmrglue.fileio.bruker.remove_digital_filter
processed_data = ng.bruker.remove_digital_filter(dic, processed_data)
print(" NP {0} \n".format(processed_data.shape[-1]))
processed_data = ng.proc_base.zf_size(processed_data, num_pts )

# fft
processed_data = ng.proc_base.fft(processed_data)

# Phase
# https://nmrglue.readthedocs.io/en/latest/reference/generated/nmrglue.process.proc_autophase.autops.html#nmrglue.process.proc_autophase.autops
data_am = ng.process.proc_autophase.autops(processed_data, 'acme') #, -30, 360)  # phase correction
data_pm = ng.process.proc_autophase.autops(processed_data, 'peak_minima')#,-30, 360)  # phase correction

processed_data = data_am if (data_am.min() > data_pm.min()) else data_pm

# Linear (first-order) baseline correction  
# https://nmrglue.readthedocs.io/en/latest/reference/generated/nmrglue.process.proc_bl.base.html?highlight=baseline#nmrglue.process.proc_bl.base
 processed_data = ng.process.proc_bl.baseline_corrector(processed_data, wd=20)

processed_data = ng.proc_base.di(processed_data) 
processed_data = ng.proc_base.rev(processed_data) 
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(processed_data)

It s currently not planned to implement functions in chemspectra that would give the user leverage on those default settings. (If one needs to (re)process the raw nmr data, NMRium should be used.

@nicolejung ?

schatzsc commented 6 months ago

@PiTrem Thank you very much for the detailed explanation of NMR processing and the direct link to the relevant source code fragment.

Still, I would consider an approach that removes a legit peak (like the feature around 12 ppm in the example above) as a bug, in particular since this is not immediately obvious to non-expert users.

Possibly, part of the processing is also what is messing up the quality of the 195Pt NMR, which is usually much more noisy than 1H or 13C due to significantly lower sensitivity.

schatzsc commented 6 months ago

NMRium has similar problems with 195Pt NMR as the internal spectrum editor, see new post in issue https://github.com/ComPlat/chemotion_ELN/issues/1685