diff --git a/ILP/caffeinesynthesis.py b/ILP/caffeinesynthesis.py index 047ebe8..e1b32a7 100644 --- a/ILP/caffeinesynthesis.py +++ b/ILP/caffeinesynthesis.py @@ -47,13 +47,16 @@ VERTICES2 = { VERTICES = ['Xanthine', 'p_{0,0}', 'p_{0,1}', 'p_{0,2}', 'p_{0,3}', 'p_{0,4}', 'p_{0,5}', 'Caffeine'] NMRLIKELYHOODS = [0.0, 0.2, 0.7, 0.1, 0.1, 0.2, 0.7, 0.0] +NMRLIKELYHOODS1 = [0.75, 0.66, 0.66, 0.89, 0.66, 0.86, 0.79, 0.65] +NMRLIKELYHOODS2 = [0.58, 0.75, 0.71, 0.91, 0.75, 0.76, 0.85, 0.82] + FIXED_FLOWS = { 1: 1, 14: 1, } -def build_model(name, hyperedges, vertices, nmrlikelihoods, excluded_support=None): +def build_model(name, hyperedges, vertices, nmrlikelihoods, excluded_support=None): model = Model(name) x = {e_id: model.addVar(vtype=GRB.INTEGER, lb=0, name=f"x_{e_id}") for e_id in hyperedges} diff --git a/ILP/nmrSimilarity.py b/ILP/nmrSimilarity.py index 5d23bf7..05db247 100644 --- a/ILP/nmrSimilarity.py +++ b/ILP/nmrSimilarity.py @@ -1,5 +1,7 @@ #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 @@ -102,13 +104,13 @@ C17XANTHINE = { } 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]), + 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]), } @@ -148,29 +150,50 @@ C137XANTHINE = { } 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]), + 1: ([155.7], [1]), #166 + 2: ([148.8], [1]), #159 + 3: ([107.7], [1]), #118 + 4: ([152.2], [1]), #163 + 5: ([143.0], [1]), #154 + 6: ([27.2], [1]), #38 + 7: ([29.1], [1]), #40 + 8: ([32.9], [1]), #44 } +CCAFFEINEADJUSTED = { + 1: ([166.7], [1]), #166 + 2: ([159.8], [1]), #159 + 3: ([118.7], [1]), #118 + 4: ([163.2], [1]), #163 + 5: ([154.0], [1]), #154 + 6: ([38.2], [1]), #38 + 7: ([40.1], [1]), #40 + 8: ([44.9], [1]), #44 +} 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]), + 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]), @@ -226,7 +249,7 @@ def bin_array(spectra, highest_ppm, lowest_ppm, bin_width): normalizedbin = np.divide(bin, np.sum(bin)) return normalizedbin -def define_border_values(spectraref, spectranew): +def define_border_values(spectraref, spectranew, bin_width): shifts = [] for _,(shift,_) in spectraref.items(): shifts.append(shift[0]) @@ -234,43 +257,70 @@ def define_border_values(spectraref, spectranew): shifts.append(shift[0]) highest_ppm = math.ceil(max(shifts)) lowest_ppm = math.floor(min(shifts)) + 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) + 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) + 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(): - positive = 0 - negative = 0 - bad_binwidth = [] - - '''for i in [0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.5, 3.0, 3.5, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0, 25.0, 30.0, 35.0]: - print(similarity_nmr(CNMR1, CNMR2, i), i) - if(similarity_nmr(CCAFFEINE2, CCAFFEINE, i) - similarity_nmr(CPARAXANTHINE, CCAFFEINE, i) < 0): - negative += 1 - bad_binwidth.append(i) - else: - positive += 1 - print(f'Wrong similarity result: {negative} and Right similarity result: {positive}') - print(bad_binwidth)''' - for i in np.arange(0.01, 0.07, 0.01): + spectrumref = CNMR1 + spectrafalse = [CXANTHINE, C1XANTHINE, C3XANTHINE, C7XANTHINE, C1XANTHINE, C17XANTHINE, C37XANTHINE, C137XANTHINE] + likelihood = [] + for spectrumtrue in spectrafalse: + #errorlist = {} + errorlist = [] + for correctionvalue in range(8, 16): + 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 + error = 0 + total = 0 + for spectrumfalse in spectrafalse: + positive = 0 + negative = 0 + bad_binwidth = [] + for i in np.arange(0.1, 3.9, 0.1): #Irgendwie hat 0.99999999999 einen Fehler den 1.0 nicht hat + truesimilarity = similarity_nmr(spectrumtrue, spectrumrefcorrected, i) + falsesimilarity = similarity_nmr(spectrumfalse, spectrumrefcorrected, i) + #print(truesimilarity) + #print(falsesimilarity) + if(truesimilarity - falsesimilarity < 0 or truesimilarity == 0): + negative += 1 + bad_binwidth.append(i) + else: + positive += 1 + total += 1 + #print(f'Wrong similarity result: {negative} and Right similarity result: {positive}') + #print(bad_binwidth) + error += negative + #errorlist[correctionvalue] = error + errorlist.append(error) + likelihood.append(round((total - min(errorlist))/total, 2)) + print(likelihood) + '''for i in np.arange(0.01, 0.07, 0.01): print(f'Increment i: {i}') print(similarity_nmr(HNMR1, HNMR2, i)) print(similarity_nmr(H1XANTHINE, HNMR1, i)) print(similarity_nmr(H3XANTHINE, HNMR1, i)) print(similarity_nmr(H7XANTHINE, HNMR1, i)) - + ''' if __name__ == "__main__": main() \ No newline at end of file