309 lines
8.5 KiB
Python
309 lines
8.5 KiB
Python
#Binning mostly for broader peaks?
|
||
#0.66 für H und 8.4 für C bei anderen TMS Werten
|
||
#Gute 13C Ergebnisse für alles +11 ppm: Im Vergeich mit Coffein haben alle disubstituierten bei wenigen Hohen Werten falsche Zuordnung, bei mono und nicht substituierten sogar keine Falsche zuornung (0.1 bis 5 mit 0.1 Schritten)
|
||
#+11 nicht universell, aber 9 bis 13 bei allen sweet spot
|
||
|
||
import math
|
||
import numpy as np
|
||
|
||
#Xanthine
|
||
HXANTHINE = {
|
||
1: ([7.31], [1]),
|
||
2: ([8.79], [1]),
|
||
3: ([7.07], [1]),
|
||
4: ([6.97], [1]),
|
||
}
|
||
CXANTHINE = {
|
||
1: ([151.03], [1]),
|
||
2: ([155.64], [1]),
|
||
3: ([112.57], [1]),
|
||
4: ([152.87], [1]),
|
||
5: ([138.61], [1]),
|
||
}
|
||
|
||
#1-Methylxanthine
|
||
H1XANTHINE = {
|
||
1: ([7.28], [1]),
|
||
2: ([8.79], [1]),
|
||
3: ([3.39], [3]),
|
||
4: ([7.25], [1]),
|
||
}
|
||
C1XANTHINE = {
|
||
1: ([153.13], [1]),
|
||
2: ([157.91], [1]),
|
||
3: ([112.28], [1]),
|
||
4: ([150.37], [1]),
|
||
5: ([137.88], [1]),
|
||
6: ([30.18], [1]),
|
||
}
|
||
|
||
#3-Methylxanthine
|
||
H3XANTHINE = {
|
||
1: ([3.49], [3]),
|
||
2: ([7.07], [1]),
|
||
3: ([7.34], [1]),
|
||
4: ([8.84], [1]),
|
||
}
|
||
C3XANTHINE = {
|
||
1: ([153.46], [1]),
|
||
2: ([155.00], [1]),
|
||
3: ([112.87], [1]),
|
||
4: ([154.78], [1]),
|
||
5: ([138.12], [1]),
|
||
6: ([31.34], [1]),
|
||
}
|
||
|
||
#7-Methylxanthine
|
||
H7XANTHINE = {
|
||
1: ([6.89], [1]),
|
||
2: ([3.81], [3]),
|
||
3: ([7.04], [1]),
|
||
4: ([6.98], [1]),
|
||
}
|
||
C7XANTHINE= {
|
||
1: ([151.13], [1]),
|
||
2: ([157.10], [1]),
|
||
3: ([113.78], [1]),
|
||
4: ([153.94], [1]),
|
||
5: ([143.18], [1]),
|
||
6: ([36.69], [1]),
|
||
}
|
||
|
||
#Theophylline
|
||
H13XANTHINE = {
|
||
1: ([3.37], [3]),
|
||
2: ([7.32], [1]),
|
||
3: ([3.53], [3]),
|
||
4: ([8.84], [1]),
|
||
}
|
||
C13XANTHINE = {
|
||
1: ([155.40], [1]),
|
||
2: ([156.89], [1]),
|
||
3: ([112.36], [1]),
|
||
4: ([152.62], [1]),
|
||
5: ([137.43], [1]),
|
||
6: ([32.05], [1]),
|
||
7: ([29.23], [1]),
|
||
}
|
||
|
||
#Paraxanthine
|
||
H17XANTHINE = {
|
||
1: ([3.84], [3]),
|
||
2: ([7.04], [1]),
|
||
3: ([3.32], [3]),
|
||
4: ([7.16], [1]),
|
||
}
|
||
C17XANTHINE = {
|
||
1: ([153.04], [1]),
|
||
2: ([158.80], [1]),
|
||
3: ([113.44], [1]),
|
||
4: ([1651.81], [1]),
|
||
5: ([142.72], [1]),
|
||
6: ([36.80], [1]),
|
||
7: ([28.59], [1]),
|
||
}
|
||
|
||
CPARAXANTHINE = {
|
||
1: ([26.7], [1]),
|
||
2: ([32.9], [1]),
|
||
3: ([151.1], [1]),
|
||
4: ([106.5], [1]),
|
||
5: ([147.4], [1]),
|
||
6: ([155.3], [1]),
|
||
7: ([143.0], [1]),
|
||
}
|
||
|
||
|
||
#Theobromine
|
||
H37XANTHINE = {
|
||
1: ([3.83], [3]),
|
||
2: ([7.09], [1]),
|
||
3: ([3.45], [3]),
|
||
4: ([6.99], [1]),
|
||
}
|
||
C37XANTHINE = {
|
||
1: ([153.39], [1]),
|
||
2: ([156.49], [1]),
|
||
3: ([114.14], [1]),
|
||
4: ([155.92], [1]),
|
||
5: ([142.73], [1]),
|
||
6: ([30.96], [1]),
|
||
7: ([36.70], [1]),
|
||
}
|
||
|
||
#Caffeine
|
||
H137XANTHINE = {
|
||
1: ([7.07], [1]),
|
||
2: ([3.49], [3]),
|
||
3: ([3.86], [3]),
|
||
4: ([3.35], [3]),
|
||
}
|
||
C137XANTHINE = {
|
||
1: ([155.29], [1]),
|
||
2: ([158.29], [1]),
|
||
3: ([113.66], [1]),
|
||
4: ([153.86], [1]),
|
||
5: ([142.13], [1]),
|
||
6: ([31.72], [1]),
|
||
7: ([36.86], [1]),
|
||
8: ([28.80], [1]),
|
||
}
|
||
|
||
CCAFFEINE = {
|
||
1: ([155.7], [1]),
|
||
2: ([148.8], [1]),
|
||
3: ([107.7], [1]),
|
||
4: ([152.2], [1]),
|
||
5: ([143.0], [1]),
|
||
6: ([27.2], [1]),
|
||
7: ([29.1], [1]),
|
||
8: ([32.9], [1]),
|
||
}
|
||
|
||
CCAFFEINE2 = {
|
||
1: ([27.7], [1]),
|
||
2: ([29.3], [1]),
|
||
3: ([33.1], [1]),
|
||
4: ([151.0], [1]),
|
||
5: ([148.1], [1]),
|
||
6: ([106.6], [1]),
|
||
7: ([154.5], [1]),
|
||
8: ([142.8], [1]),
|
||
}
|
||
|
||
C137XANTHINEADJUSTED = {
|
||
1: ([155.62], [1]),
|
||
2: ([158.29], [1]),
|
||
3: ([113.66], [1]),
|
||
4: ([153.86], [1]),
|
||
5: ([142.13], [1]),
|
||
6: ([31.72], [1]),
|
||
7: ([36.86], [1]),
|
||
8: ([28.8], [1]),
|
||
}
|
||
|
||
#Experimental 7-Methylxanthine nmr
|
||
#Secundary source 11.52, 3.81
|
||
HNMR1= {
|
||
1: ([10.85], [1]),
|
||
2: ([11.50], [1]),
|
||
3: ([3.82], [3]),
|
||
4: ([7.88], [1]),
|
||
}
|
||
|
||
CNMR1= {
|
||
1: ([155.85], [1]),
|
||
2: ([151.35], [1]),
|
||
3: ([149.30], [1]),
|
||
4: ([143.01], [1]),
|
||
5: ([106.90], [1]),
|
||
6: ([33.03], [1]),
|
||
}
|
||
|
||
|
||
|
||
#Experimental Theobromine nmr
|
||
HNMR2 = {
|
||
1: ([11.10], [1]),
|
||
2: ([3.33], [3]),
|
||
3: ([3.84], [3]),
|
||
4: ([7.97], [1]),
|
||
}
|
||
|
||
CNMR2 = {
|
||
1: ([154.9], [1]),
|
||
2: ([149.8], [1]),
|
||
3: ([107.1], [1]),
|
||
4: ([151.0], [1]),
|
||
5: ([142.8], [1]),
|
||
6: ([29.3], [1]),
|
||
7: ([33.9], [1]),
|
||
}
|
||
|
||
#Combination of methyl group and base purine rings from two papers
|
||
CNMR3 = {
|
||
1: ([154.9], [1]),
|
||
2: ([150.0], [1]),
|
||
3: ([108.1], [1]),
|
||
4: ([153.1], [1]),
|
||
5: ([142.6], [1]),
|
||
6: ([29.3], [1]),
|
||
7: ([33.9], [1]),
|
||
}
|
||
|
||
def overlap(listref, listnew):
|
||
twoleft = np.sum(np.multiply(np.concatenate((listref, [0, 0])), np.concatenate(([0, 0], listnew))))
|
||
oneleft = np.sum(np.multiply(np.concatenate((listref, [0])), np.concatenate(([0], listnew))))
|
||
neutral = np.sum(np.multiply(listref,listnew))
|
||
oneright = np.sum(np.multiply(np.concatenate(([0], listref)), np.concatenate((listnew, [0]))))
|
||
tworight = np.sum(np.multiply(np.concatenate(([0, 0], listref)), np.concatenate((listnew, [0, 0]))))
|
||
overlap = (oneleft + oneright)* 0.5 + neutral
|
||
return overlap
|
||
|
||
def bin_array(spectra, highest_ppm, lowest_ppm, bin_width):
|
||
binnumber = math.ceil((highest_ppm - lowest_ppm)/bin_width)
|
||
bin = [0] * binnumber
|
||
for peak in spectra:
|
||
(shift, height) = spectra[peak]
|
||
binindex = math.floor((shift[0] - lowest_ppm) / bin_width)
|
||
bin[binindex] += height[0]
|
||
normalizedbin = np.divide(bin, np.sum(bin))
|
||
return normalizedbin
|
||
|
||
def define_border_values(spectraref, spectranew, bin_width):
|
||
shifts = []
|
||
for _,(shift,_) in spectraref.items():
|
||
shifts.append(shift[0])
|
||
for _,(shift,_) in spectranew.items():
|
||
shifts.append(shift[0])
|
||
highest_ppm = math.ceil(max(shifts)) + bin_width
|
||
lowest_ppm = math.floor(min(shifts)) - bin_width
|
||
#lowest_ppm = min(shifts) - bin_width/2 #Worse result. None of the previously wrong (except 0.6) become right
|
||
return (lowest_ppm, highest_ppm)
|
||
|
||
def similarity_nmr(spectraref, spectranew, bin_width):
|
||
#Maximize likelihood or minimize Deviation
|
||
#Values for two spectra and optimize largest for both different?
|
||
#Spectra in Nodes to allow maximize overlapp with both spectra or one spectra.
|
||
#5.4.2 Eliminating X–H signals from 1H NMR spectra
|
||
lowest_ppm, highest_ppm = define_border_values(spectraref, spectranew, bin_width)
|
||
binref = bin_array(spectraref, highest_ppm, lowest_ppm, bin_width)
|
||
binnew = bin_array(spectranew, highest_ppm, lowest_ppm, bin_width)
|
||
crosscorr = overlap(binref, binnew)
|
||
refselfcorr = overlap(binref, binref)
|
||
newselfcorr = overlap(binnew, binnew)
|
||
simidx = crosscorr / math.sqrt(refselfcorr * newselfcorr)
|
||
return(simidx)
|
||
|
||
def correction(spectra, corretionppm):
|
||
newspectra = {}
|
||
for id, (shift, height) in spectra.items():
|
||
shiftvalue = shift[0]
|
||
adjustedshift = shiftvalue + corretionppm
|
||
newspectra[id] = ([adjustedshift], height)
|
||
return newspectra
|
||
|
||
def main():
|
||
spectrumref = CNMR3
|
||
#1H-NMR Spectra ignoriert, da meiste H sauer, da an N gebunden
|
||
#spectra = [HXANTHINE, H1XANTHINE, H3XANTHINE, H7XANTHINE, H1XANTHINE, H17XANTHINE, H37XANTHINE, H137XANTHINE]
|
||
spectra = [CXANTHINE, C1XANTHINE, C3XANTHINE, C7XANTHINE, C1XANTHINE, C17XANTHINE, C37XANTHINE, C137XANTHINE]
|
||
spectranames = ["XANTHINE", "1XANTHINE", "3XANTHINE", "7XANTHINE", "1XANTHINE", "17XANTHINE", "37XANTHINE", "137XANTHINE"]
|
||
likelihood = []
|
||
for spectrumtrue in spectra:
|
||
similaritybycorrection = []
|
||
#Paper Chemical reviews Carbons bound to Heavy atoms (TMS) to high -> this could be reason for too high values.
|
||
correctionvalues = [2.63] #np.arange(0, 1.51, 0.01) #for C tested np.arange(-0.37, 7.64, 0.1) 0, 2.63, 1 (for CNMR3), 1.5 (true for all ref, 8.37 + 1.5 for the precision), 1 (good for first, ok for second, third because only 7 better/equal but for first much higher) np.arange(-1.5, 1.49, 0.01) (only for first), for H 0 (not good), np.arange(-0.26, 0.34, 0.01), -0.06 for first, second never first either 17 or caf higher np.arange(-0.15, 0.16, 0.01) good measure
|
||
for correctionvalue in correctionvalues:
|
||
spectrumrefcorrected = correction(spectrumref, correctionvalue) #CCAFFEINE 11 (klappt hier sehr gut) CCAFFEINE2 12 CPARAXANTHINE 10 CNMR1 9, 10 o 11 (sehr gut) CNMR2 10 o 11
|
||
similaritylist = []
|
||
binwidthlist = np.arange(0.1, 3.9, 0.1)
|
||
for i in binwidthlist:
|
||
similaritylist.append(similarity_nmr(spectrumtrue, spectrumrefcorrected, i))
|
||
similaritymean = sum(similaritylist) / len(similaritylist)
|
||
similaritybycorrection.append(similaritymean)
|
||
likelihood.append(round(sum(similaritybycorrection)/len(similaritybycorrection), 2))
|
||
print(likelihood)
|
||
|
||
if __name__ == "__main__":
|
||
main() |