def multiplet(v, I, J, r): #La simulacion tan famosa que ya conoces min_x = v - 20 max_x = v + 20 td = Multiplet(v, I, [(J, r)]) grafica = mplplot(td.peaklist(), points=1000, w=0.5, limits=(min_x, max_x)) return grafica
def test_default_limits(self): m1 = Multiplet(100, 1, [(10, 2)]) m2 = Multiplet(80, 1, [(10, 2)], w=1.0) spectrum = Spectrum([m1, m2], vmin=0.0, vmax=200.0) vmin, vmax = spectrum.default_limits() assert vmin == 20 assert vmax == 160
def archiv_txt (v, I, J, r): td = Multiplet(v , I, [(J, r)]) grafica = mplplot(td.peaklist(), points=1000) intensidades = (grafica[1]) no_datos = len(grafica[1]) intensidades1 = [] for i in range (len(intensidades)): intensidades1.append(round(intensidades[i], 6)) #Datos en x Hz = (grafica[0]) min_Hz = (Hz[0]) max_Hz = (Hz[no_datos - 1]) oracion1 = f"Number of data points : {no_datos} \n" oracion2 = f"Chemical shift range (ppm) : 1 1\n" oracion3 = f"Chemical shift range (Hz) : {min_Hz} {max_Hz}\n" #escritura del archivo para guardar los datos f = open('multiplete7.slc','w') f.write(oracion1) f.write(oracion2) f.write(oracion3) for i in range (len(intensidades1)): f.write(str(intensidades1[i])+"\n") f.close()
def test_Spectrum_instantiates_with_multiplet(self): m1 = Multiplet(100, 1, [(10, 2)]) m2 = Multiplet(80, 1, [(10, 2)]) s = Spectrum([m1, m2]) expected_peaklist = sorted([(110, 0.25), (100, 0.5), (90, 0.5), (80, 0.5), (70, 0.25)]) result = s.peaklist() assert np.array_equal(expected_peaklist, result)
def test_instantiates(self, td): v, I, J = td td_multiplet = Multiplet(v, I, J, 1.5) assert td_multiplet.v == 1200.0 assert td_multiplet.I == 2 assert td_multiplet.J == [(7.1, 2), (1.1, 1)] assert td_multiplet.w == 1.5 expected_peaklist = [(1192.35, 0.25), (1193.45, 0.25), (1199.45, 0.5), (1200.55, 0.5), (1206.55, 0.25), (1207.65, 0.25)] assert np.allclose(td_multiplet.peaklist(), expected_peaklist)
def test_add(self, dummy_multiplet): m1 = Multiplet(100, 1, [(10, 2)]) m2 = Multiplet(80, 1, [(10, 2)]) result = m1 + m2 # assert 1 == 1 expected_peaklist = sorted([(110, 0.25), (100, 0.5), (90, 0.5), (80, 0.5), (70, 0.25)]) assert np.array_equal(result.peaklist(), expected_peaklist) with pytest.raises(TypeError): _ = m1 + 3
def test_add_and_eq(self): m1 = Multiplet(100, 1, [(10, 2)]) m2 = Multiplet(80, 1, [(10, 2)]) s = Spectrum([m1, m2]) s2 = m1 + m2 assert s == s2 s3 = m1 + m1 + m2 + m2 # test for more than two objects being added expected_peaklist = sorted([(110, 0.5), (100, 1), (90, 1), (80, 1), (70, 0.5)]) assert np.allclose(s3.peaklist(), expected_peaklist) with pytest.raises(TypeError): _ = s + 1
def test_iadd(self): m1 = Multiplet(100, 1, [(10, 2)]) m2 = Multiplet(80, 1, [(10, 2)]) m3 = Multiplet(40, 1, [(10, 2)]) spectrum = Spectrum([m1, m2]) spectrum += m3 expected_peaklist = sorted([(110, 0.25), (100, 0.5), (90, 0.5), (80, 0.5), (70, 0.25), (50, 0.25), (40, 0.5), (30, 0.25)]) assert np.allclose(expected_peaklist, spectrum.peaklist()) spectrum2 = Spectrum([m1]) spectrum += spectrum2 assert spectrum._components == [m1, m2, m3, m1]
def test_add(self): m1 = Multiplet(100, 1, [(10, 2)]) m2 = Multiplet(80, 1, [(10, 2)]) m3 = Multiplet(40, 1, [(10, 2)]) subspectrum = m1 + m2 spectrum = subspectrum + m3 spectrum2 = m3 + subspectrum assert spectrum._components == [m1, m2, m3] assert spectrum2._components == [m3, m1, m2] expected_peaklist = sorted([(110, 0.25), (100, 0.5), (90, 0.5), (80, 0.5), (70, 0.25), (50, 0.25), (40, 0.5), (30, 0.25)]) assert np.allclose(expected_peaklist, spectrum.peaklist()) assert np.allclose(expected_peaklist, spectrum2.peaklist())
def test_extract_components(): m1 = Multiplet(100, 1, [(10, 2)]) m2 = Multiplet(80, 1, [(10, 2)]) m3 = Multiplet(40, 1, [(10, 2)]) print(m1, m2, m3) subspectrum = Spectrum([m1, m2]) subcomponents = extract_components(subspectrum) assert subcomponents == [m1, m2] spectrum = Spectrum([subspectrum, m3]) components = extract_components(spectrum) assert components == [m1, m2, m3] spectrum2 = Spectrum([m3, subspectrum]) components2 = extract_components(spectrum2) assert components2 == [m3, m1, m2]
def test_lineshape(self): m1 = Multiplet(100, 1, [(10, 2)]) m2 = Multiplet(80, 1, [(10, 2)], w=1.0) # also test w # also test vmin/vmax work spectrum = Spectrum([m1, m2], vmin=0.0, vmax=200.0) x = np.linspace(0.0, 200.0, 1000) y1 = add_lorentzians(x, m1.peaklist(), m1.w) y2 = add_lorentzians(x, m2.peaklist(), m2.w) y_sum = [sum(i) for i in zip(y1, y2)] spec_x, spec_y = spectrum.lineshape(points=1000) assert np.allclose(spec_x, x) assert np.allclose(spec_y, y_sum)
def nmr_sim (v, I, J, r): td = Multiplet(v , I, [(J, r)]) grafica = mplplot(td.peaklist(), points=1000) return grafica
def trasladar(ys, n): # delta = xs[n] tam = len(ys) + n y_new = np.zeros(tam) for i in range( 0, tam ): if i < len(ys): y_new[i] += ys[i] if i >= n: y_new[i] += -ys[i-n] return y_new for i in range (len(ref)): # 1200 Hz, 2H, td, J= 7.1, 1.1 Hz td = Multiplet(1200 , 1, [(ref[i], 1)]) #aqui entra en juego ref grafica = mplplot(td.peaklist(), points=1000) #para crear el archivo de texto intensidades = (grafica[1]) * 10000 no_datos = len(grafica[1]) intensidades1 = [] for i in range (len(intensidades)): intensidades1.append(round(intensidades[i], 6)) Hz = (grafica[0]) min_Hz = (Hz[0]) max_Hz = (Hz[no_datos - 1]) oracion1 = f"Number of data points : {no_datos} \n"
""" Este es el intento crudo de conjuncion de la simulacion con nmrsim con el copy paste del programa J Doubling de Federico del Rio """ import numpy as np from nmrsim import Multiplet from nmrsim.plt import mplplot import matplotlib.pyplot as plt import numpy as np import csv from scipy.signal import argrelextrema # 1200 Hz, 2H, td, J= 7.1, 1.1 Hz td = Multiplet(1200.0, 1, [(7.1, 1)]) print(td.v) print(td.I) print(td.J) grafica = mplplot(td.peaklist()) #para cuando quiero recuperar la imagen del multiplete plt.plot(grafica[0], grafica[1]) plt.xlabel("Frecuencia (Hz)") plt.ylim(0,1) plt.show() #para crear el archivo de texto intensidades = (grafica[1]) * 10000 no_datos = len(grafica[1]) intensidades1 = []
for i in range( 0, tam ): if i < len(ys): y_new[i] += ys[i] if i >= n: y_new[i] += -ys[i-n] return y_new for i in range (len(ref)): # v = 1200 Hz, I = intensidad, J = cte. acoplamiento, r = vecinos v = 1200.0 min_x = v - 20 max_x = v + 20 td = Multiplet(v , 1, [(ref[i], 1)]) #aqui entra en juego ref grafica = mplplot(td.peaklist(), points=1000, limits= (min_x, max_x)) #para crear el archivo de texto intensidades = (grafica[1]) * 10000 no_datos = len(grafica[1]) intensidades1 = [] for i in range (len(intensidades)): intensidades1.append(round(intensidades[i], 6)) Hz = (grafica[0]) min_Hz = (Hz[0]) max_Hz = (Hz[no_datos - 1]) oracion1 = f"Number of data points : {no_datos} \n"
def test_eq(self, dummy_multiplet): m1 = Multiplet(100, 1, [(10, 2)]) m2 = m1 * 2 m3 = m2 / 2 assert m1 is not m3 assert m1 == m3
def test_add_appends_to_components(self): m1 = Multiplet(100, 1, [(10, 2)]) m2 = Multiplet(80, 1, [(10, 2)]) s = Spectrum([m1]) s2 = s + m2 assert s2._components == [m1, m2]
import numpy as np from nmrsim import Multiplet from nmrsim.plt import mplplot import matplotlib.pyplot as plt import numpy as np from scipy.signal import argrelextrema v = 1200.0 J = 1.0 # 1200 Hz, 2H, td, J= 7.1, 1.1 Hz td = Multiplet(v, 1, [(J, 1)]) print(td.v) print(td.I) print(td.J) min_x = v - 20 max_x = v + 20 grafica = mplplot(td.peaklist(), points=1000, w=0.5, limits=(min_x, max_x)) #para cuando quiero recuperar la imagen del multiplete plt.plot(grafica[0], grafica[1]) plt.xlabel("Frecuencia (Hz)") plt.ylim(0, 1) plt.show() #para crear el archivo de texto intensidades = (grafica[1]) * 10000 no_datos = len(grafica[1]) intensidades1 = []
#crear el Json def escritura_json (x): nombre = f"W_{x}Hz.json" with open(nombre, 'w') as archivo: json.dump(Jota_0_5Hz, archivo) #print("Archivo exportado con éxito") return for i in range (len(jotas)): # v = 1200 Hz, I = intensidad, J = cte. acoplamiento, r = vecinos J = jotas[i] v = 1200.0 min_x = v - 20 max_x = v + 20 td = Multiplet(v , 1, [(J, 1)]) #aqui entra en juego jotas grafica = mplplot(td.peaklist(), points=1000, w =1.5, limits= (min_x, max_x)) #para crear el archivo de texto intensidades = (grafica[1]) * 10000 #aqui lo multiplico x10000 por que si no me da valores bien pequeños, pero si lo ves innecesario piedes quitarlo no_datos = len(grafica[1]) intensidades1 = [] #creo esta lista por que como ves en el buclesito de abajo, guardo los valores hasta 6 cifras para no hacer el archivo de texto bien pesado for i in range (len(intensidades)): intensidades1.append(round(intensidades[i], 6)) Hz = (grafica[0])# Son los valores en x (Hz)de la simulacion que nos daba grafica, y grafica[1] son los valores en y de esa simulacion (intensidades) min_Hz = (Hz[0]) max_Hz = (Hz[no_datos - 1]) oracion1 = f"Number of data points : {no_datos} \n"
def dummy_multiplet(td): return Multiplet(*td)
def multiplet (v, I, J, r): #La simulacion tan famosa que ya conoces td = Multiplet(v , I, [(J, r)]) grafica = mplplot(td.peaklist(), points=1000, w=0.5, limits=[]) return grafica