From 047de43215f81782deb73c9b6afeeb30b1aa7f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20M=C3=BCller?= Date: Fri, 9 Sep 2011 13:33:16 -0300 Subject: [PATCH] =?UTF-8?q?Adi=C3=A7=C3=A3o=20dinamica=20de=20elementos=20?= =?UTF-8?q?e=20canvas=20para=20perfil=20de=20concentra=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Edict.py | 20 +++++------ Elements.py | 4 +-- Eprop.py | 3 ++ Ewindow.py | 93 +++++++++++++++++++++++++++++++++++++++++++++++ OpenFlatus.py | 95 +++++++++++++++++++++++++++++++------------------ distribution.py | 70 ++++++++++++++++++++++++++++++++++++ spectro.py | 48 +++++++++++++++---------- teste.py | 8 +++++ 8 files changed, 276 insertions(+), 65 deletions(-) create mode 100644 Ewindow.py create mode 100644 distribution.py create mode 100644 teste.py diff --git a/Edict.py b/Edict.py index 4d335fa..ccce28a 100644 --- a/Edict.py +++ b/Edict.py @@ -1,14 +1,14 @@ from numpy import * -SLOT = dict(ELEa = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), - ELEb = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), - ELEc = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), - ELEd = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), - ELEe = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), - ELEf = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), - ELEg = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), - ELEh = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), - ELEi = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), - ELEj = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), +SLOT = dict(e0 = dict(name = "New", symbol = "Hf", mass = 178.00, Z = 72, dist = [1./3.]*200 + [0.]*1800, control = 1), + e1 = dict(name = "New", symbol = "O", mass = 16.00, Z = 8, dist = [2./3.]*200 + [0.]*1800, control = 1), + e2 = dict(name = "New", symbol = "Si", mass = 28.00, Z = 14, dist = [0.]*200 + [1.]*1800, control = 1), + e3 = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), + e4 = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), + e5 = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), + e6 = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), + e7 = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), + e8 = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), + e9 = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), ELEk = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), ELEl = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), ELEm = dict(name = "New", symbol = "-", mass = 0.00, Z = 0, dist = zeros((1000), float), control = 0), diff --git a/Elements.py b/Elements.py index 12684a9..84d448f 100644 --- a/Elements.py +++ b/Elements.py @@ -3,13 +3,13 @@ from Edict import * from PTE import * from Eprop import * -def elemw(elewindow): +def elemw(elewindow, window): #################################################### # Button building on received frame co1 = lambda: PTable(SLOT['ELEa'], bu1) - co1a = lambda: atomsubmenu(SLOT['ELEa'], bu1) + co1a = lambda: atomsubmenu(SLOT['ELEa'], bu1, window) bu1 = tk.Menubutton(elewindow, text=SLOT['ELEa']['symbol'], width=3, height=1, relief='raised') m1 = tk.Menu(bu1) bu1.config(menu=m1) diff --git a/Eprop.py b/Eprop.py index 988914c..3e0574e 100644 --- a/Eprop.py +++ b/Eprop.py @@ -144,6 +144,9 @@ def atomsubmenu(elem, but): L6b.pack() L6c = tk.Label(F6, text = 'Concentration factor (0 to 1)', width=25) L6c.pack() + + plot_dist(elem, window) + subnume.mainloop() def cmdspecial(): diff --git a/Ewindow.py b/Ewindow.py new file mode 100644 index 0000000..103e7da --- /dev/null +++ b/Ewindow.py @@ -0,0 +1,93 @@ +import Tkinter as tk +from PTE import * + +Edict = list() +Ebuttons = list() +i=0 + +points = [] +spline = 0 +tag1 = "theline" + +####################################### +# Element callback +def elem_callback(edict , ebutton, frm): + #plot_dist(edict, frm) + PTable(edict , ebutton) + +####################################### +# Element addition + +def ewin_build(window): + + def create(): + global i, Edict, Ebuttons + Edict.insert(i, dict(name = "New", symbol = "Hf", mass = 178.00, Z = 72, dist = [1./3.]*200 + [0.]*1800, control = 0)) + Ebuttons.insert(i, tk.Button(Eframe,text=i,width=1,height=1, command=lambda i=i : elem_callback(Edict[i] , Ebuttons[i], Dframe))) + Ebuttons[i].pack(side='left') + i=i+1 + + but = tk.Button(window, command=create, text='Add element', bd=2, height=2,width=7) + but.pack() + but.place(anchor='n', y=5, x=44) + +####################################### +# Element Frames + + Label1 = tk.LabelFrame(window, text = 'Elements', relief='raised', bd=2) + Label1.pack() + + Label2 = tk.LabelFrame(window, text = 'Distribution', bd=1) + Label2.pack() + Label2.place(anchor='w', y=210) + + Eframe = tk.Canvas(Label1) + Eframe.pack(fill='both',expand=0) + + Dframe = tk.Frame(Label2) + Dframe.pack() + +####################################### +# Canvas callback + def point(event): + Distcanvas.create_oval(event.x, event.y, event.x+1, event.y+1, fill="black") + points.append(event.x) + points.append(event.y) + return points + + def canxy(event): + print event.x, event.y + + def graph(event): + global theline + Distcanvas.create_line(points, tags="theline") + + def toggle(event): + global spline + if spline == 0: + Distcanvas.itemconfigure(tag1, smooth=1) + spline = 1 + elif spline == 1: + Distcanvas.itemconfigure(tag1, smooth=0) + spline = 0 + print event.x, event.y + return spline + +####################################### +# Drawing Canvas + + Distcanvas = tk.Canvas(Dframe, bg="white", width=600, height= 300) + #Distcanvas.configure(cursor="crosshair") + Distcanvas.grid_columnconfigure(999, weight = 1) + Distcanvas.grid_rowconfigure(999, weight = 1) + Distcanvas.pack() + Distcanvas.bind("", point) + Distcanvas.bind("", graph) + Distcanvas.bind("", toggle) + +####################################### +# Init + create() + print Distcanvas.grid_size() + +####################################### diff --git a/OpenFlatus.py b/OpenFlatus.py index 68469a3..3233a8e 100644 --- a/OpenFlatus.py +++ b/OpenFlatus.py @@ -1,14 +1,14 @@ # -*- coding: iso-8859-15 -*- import Tkinter as tk -from Elements import * +from Ewindow import * from numpy import * -from pylab import * from spectro import * +import sys ####################################### # Initial parameters -param = dict(dedx=287. ,Theta_out=70., dW2dx=35000., E0= 100000., Theta_in=0., FWHM0=300.) +param = dict(dedx=192. ,Theta_out=70., dW2dx=20740., E0= 100000., Theta_in=0., FWHM0=180.) ionb = dict(Z=1, mass=1.0079) ####################################### @@ -16,6 +16,7 @@ ionb = dict(Z=1, mass=1.0079) # Defines parameters def init_calc(): + global modelvar param['dedx'] = float(Entrydedx.get()) param['dW2dx'] = float(EntrydW2dx.get()) param['Theta_out'] = float(EntryT_out.get()) @@ -26,47 +27,46 @@ def init_calc(): ionb['Z'] = float(EntryionZ.get()) data=spectro_espalhamento(float(EntryEmin.get()),float(EntryEmax.get()),20) - #data.addelements2(['profHf.dat','profO.dat'],param,0.9,'gaussiana',0.01) - data.sweepelements(param, 'gaussiana', ionb) + data.sweepelements(param, str(modelvar.get()), ionb) data.plot() ####################################### # Main window root = tk.Tk() -root.minsize(385,355) +root.minsize(385,260) root.title('Open Flatus') - -Label1 = tk.Label(root, text = 'Elements', relief='raised', bd=2) -Label1.grid(column=0, row=9) -Label2 = tk.Label(root, text = 'Parameters', relief='raised', bd=2) -Label2.grid(column=0, row=0) -Label3 = tk.Label(root, text = 'Ion parameters', relief='raised', bd=2) -Label3.grid(column=0, row=2) - -CalcButton = tk.Button(root, text = 'Calculate', command = init_calc, bd=4, width=20, height=4) -CalcButton.grid(column=10, row=10) +root.geometry('385x260+200+400') ####################################### -# Frames - -Eframe = tk.Frame(root) -Eframe.grid(column=0, row=10) - -Pframel = tk.Frame(root) -Pframel.grid(column=0, row=1, sticky='w') -Pframee = tk.Frame(root) -Pframee.grid(column=0, row=1, sticky='e') +# Elements window -Iframel = tk.Frame(root, width=8) -Iframel.grid(column=0, row=3, sticky='w') -Iframee = tk.Frame(root, width=12) -Iframee.grid(column=0, row=3, sticky='e') +ewin = tk.Tk() +ewin.minsize(600,400) +ewin.title('Elements') +ewin.geometry('600x400+600+400') ####################################### -# Elements callback - -elemw(Eframe) +# Frames +MasterFrame1 = tk.Frame(root) +MasterFrame1.pack(side='left') + +Label2 = tk.LabelFrame(MasterFrame1, text = 'Parameters', relief='raised', bd=2) +Label2.pack(side='top') +Label3 = tk.LabelFrame(MasterFrame1, text = 'Ion parameters', relief='raised', bd=2) +Label3.pack(side='left') +Label4 = tk.LabelFrame(root, text = 'Energy loss model', relief='raised', bd=2) +Label4.pack(side='right') + +Pframel = tk.Frame(Label2) +Pframel.pack(side='left') +Pframee = tk.Frame(Label2) +Pframee.pack(side='right') + +Iframel = tk.Frame(Label3, width=8) +Iframel.pack(side='left') +Iframee = tk.Frame(Label3, width=12) +Iframee.pack(side='right') ####################################### # Parameters @@ -104,7 +104,7 @@ EntryT_in.pack() EntryE0.pack() EntryFWHM0.pack() EntryEmin.pack() -EntryEmax.pack() +EntryEmax.pack() #Ion Labelionmass = tk.Label(Iframel, width=8, text='Mass') @@ -123,13 +123,40 @@ EntryT_out.insert(0,param['Theta_out']) EntryT_in.insert(0,param['Theta_in']) EntryE0.insert(0,param['E0']) EntryFWHM0.insert(0,param['FWHM0']) -EntryEmin.insert(0,50000) +EntryEmin.insert(0,70000) EntryEmax.insert(0,100000) Entryionmass.insert(0, ionb['mass']) EntryionZ.insert(0, ionb['Z']) ####################################### +# Energy loss models + +modelvar = tk.StringVar() +R1 = tk.Radiobutton(Label4, text="Gaussian", variable=modelvar, value='gaussiana') +R1.pack() +R2 = tk.Radiobutton(Label4, text="Bessel", variable=modelvar, value='bessel') +R2.pack() + +####################################### + +CalcButton = tk.Button(Label4, text = 'Calculate', command = init_calc, bd=4, width=20, height=4) +CalcButton.pack() + +ExitButton = tk.Button(Label4, text = 'Exit', command = sys.exit, bd=4, width=20, height=2) +ExitButton.pack(side='bottom') + +####################################### +# Elements callback + +ewin_build(ewin) + +####################################### + +data=spectro_espalhamento(float(EntryEmin.get()),float(EntryEmax.get()),20) +data.sweepelements(param, 'bessel', ionb) +data.plot() root.mainloop() +ewin.mainloop() ####################################### diff --git a/distribution.py b/distribution.py new file mode 100644 index 0000000..2078a52 --- /dev/null +++ b/distribution.py @@ -0,0 +1,70 @@ +from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg +import matplotlib, sys +matplotlib.use('TkAgg') +from numpy import arange, sin, pi +from matplotlib.figure import Figure +from Tkinter import * +from pylab import * + +def plot_dist(ELEM, window): + + points = [] + + spline = 0 + + tag1 = "theline" + + def point(event): + c.create_oval(event.x, event.y, event.x+1, event.y+1, fill="black") + points.append(event.x) + points.append(event.y) + return points + + def canxy(event): + print event.x, event.y + + def graph(event): + global theline + c.create_line(points, tags="theline") + + + def toggle(event): + global spline + if spline == 0: + c.itemconfigure(tag1, smooth=1) + spline = 1 + elif spline == 1: + c.itemconfigure(tag1, smooth=0) + spline = 0 + return spline + + + c = Canvas(window, bg="white", width=600, height= 400) + + c.configure(cursor="crosshair") + + c.pack() + + c.bind("", point) + + c.bind("", graph) + + c.bind("", toggle) + + + + + + + +''' f = Figure(figsize=(5,4), dpi=100) + a = f.add_subplot(111) + t = arange(0.0,20.0,0.01) + s = ELEM['dist'] + a.plot(t,s) + + dataPlot = FigureCanvasTkAgg(f, master=window) + dataPlot.show() + dataPlot.get_tk_widget().pack(side='left', fill=BOTH, expand=1)''' +#------------------------------------------------------------------------------- + diff --git a/spectro.py b/spectro.py index 07ae7f6..e80375d 100644 --- a/spectro.py +++ b/spectro.py @@ -4,19 +4,24 @@ from Edict import * PI=math.pi +def CSRf(Z1, Z2, Ein, M1, M2, Theta): + if M1 < M2: + return ((Z1*Z2*4.8e-20*1e8)/(4*Ein))**2 * sin(Theta)**-4 * (sqrt(1-((M1/M2)*sin(Theta))**2)+cos(Theta))**2 / sqrt(1-((M1/M2)*sin(Theta))**2) + else: + return 0 + ## funcoes usadas pela classe spectro def gaussian(e, Em, sigma): # Funcao que retorna uma gaussiana centrada em Em e largura sigma return exp((-(e-Em)**2)/(2.*sigma))/sqrt(2.*PI*sigma) -def modbesselp(e, param,x): +def modbessel(e, alpha, m, x, kE0): # Funcao que retorna a perda de energia de acordo com a funcao # modificada de bessel do primeiro tipo de ordem 1 - # **** NAO FUNCIONA!! **** - alpha=2.*param['dedx']/param['dW2dx'] - m = alpha * param['dedx'] - lbd=m*x*alpha - return (lbd*exp(-m*x-alpha*e)/(sqrt(lbd*e)))*i1(2.*sqrt(lbd*e)) + # N FUNCIONA! + lbd = m*alpha*x + #print lbd*exp((-m*x-alpha*(e-kE0))/1000)*i1(2*sqrt(lbd*(e-kE0)/1000))/(sqrt(lbd*(e-kE0)/1000 +.0000001)) + return lbd*exp((-m*x-alpha*(e-kE0))/1000)*i1(2*sqrt(lbd*(e-kE0)/1000))/(sqrt(lbd*(e-kE0)/1000 +.0000001)) ## Definindo classe referente a objetos de espectro de espalhamento class spectro_espalhamento: @@ -25,11 +30,11 @@ class spectro_espalhamento: self.e = arange(Emin, Emax, EPasso) self.Y= e*0. - def addbessel(self,param,peso,x): + def addbessel(self, peso, alpha, m, x, kE0): # Adiciona uma funcao modificada de bessel do primeiro tipo: # energia media Em, com variancia sigma com o peso dado - self.Y=self.Y+peso*modbesselp(self.e, param, x) - + #self.Y=self.Y +peso*modbesselp(self.e, Em, sigma, dedx, dw2dx, x) + self.Y=self.Y +peso*modbessel(self.e, alpha, m, x, kE0) def addgauss(self,Em,sigma,peso): # Adiciona uma gaussiana ao spectro: @@ -38,7 +43,7 @@ class spectro_espalhamento: def plot(self): # Plota o spectro - plot(self.e,self.Y) + plt.plot(self.e,self.Y) suptitle('Signal received', fontsize=12) xlabel("Enegy (eV)") ylabel("Yield") @@ -61,20 +66,25 @@ class spectro_espalhamento: else: passo = 0.01 c = SLOT[ATOM]['dist'] - x = arange(0,10,0.01) + x = arange(0,20,passo) self.setparam(param) Theta_s = PI - (self.Theta_in + self.Theta_out)*PI/180 mt = SLOT[ATOM]['mass'] mi = ion['mass'] + k = ( (sqrt (mt**2+mi**2*(sin(Theta_s)**2)) + mi*cos(Theta_s) ) / (mi+mt) )**2 - k = ( (sqrt(mt**2+mi**2*(sin(Theta_s)**2)) + mi*cos(Theta_s)) / (mi+mt) )**2 - - for i in x: - sigma=i*self.dW2dx*(k**2/cos(self.Theta_in*PI/180.)+1/cos(self.Theta_out*PI/180.))+self.sigma0 - Em = k*self.E0-i*self.dedx*(k/cos(self.Theta_in*PI/180.) + 1/cos(self.Theta_out*PI/180.)) + + for i in [0.1]: #x: + sigma=i*self.dW2dx*(k**2./cos(self.Theta_in*PI/180.)+1./cos(self.Theta_out*PI/180.))+self.sigma0 + Em = k*self.E0 - i*self.dedx*(k/cos(self.Theta_in*PI/180.) + 1/cos(self.Theta_out*PI/180.)) + CS = CSRf(ion['Z'], SLOT[ATOM]['Z'], Em, ion['mass'], SLOT[ATOM]['mass'], Theta_s) if modelo == 'gaussiana': - self.addgauss(Em, sigma, c[int(i/passo)]*k) - if modelo == 'bessel': - self.addbessel(param, c[i*100]*k,x) + self.addgauss(Em, sigma, c[int(i/passo)]*k*CS) + elif modelo == 'bessel': + print Em + alpha = (2.* param['dedx']/10. * Em ) / ((param['dW2dx']/10.) *(sigma/i)) + m = alpha * param['dedx']/10. * Em + self.addbessel(c[int(i/passo)]*k*CS, alpha, m, i,k*self.E0) + diff --git a/teste.py b/teste.py new file mode 100644 index 0000000..3d0ff28 --- /dev/null +++ b/teste.py @@ -0,0 +1,8 @@ +from Ewindow import * + +root = tk.Tk() +root.maxsize(800,600) + +ewin_build(root) + +root.mainloop() -- 2.22.0