Commit 6f03c13b authored by Matheus Müller's avatar Matheus Müller

Desenho de perfil na janela principal, com draw, shift, scale, normalize e clear.

Problemas para mostrar o perfil, somente apos primeiro uso do botao direito funciona normal
parent d3c0e4cb
......@@ -3,6 +3,7 @@ import Tkinter as tk
from PTE import *
from pylab import *
from layers import *
from profile import *
from numpy import zeros
import os
import tkFileDialog
......@@ -18,6 +19,7 @@ Edict = dict()
Ebuttons = list()
Labentrys = list()
Frames = list()
Control = dict(drawing=False, shifting=False, scaling=False, x=0., y=0.)
i = 0
Econtrol = 0
......@@ -53,16 +55,15 @@ def elem_select(i, button, grafico, f, a, t):
Labentrys[10].insert(0, Edict[int(Econtrol)]['LineShape'])
Labentrys[11].insert(0, Edict[int(Econtrol)]['profundidademax'])
Edict[i]['dist'] = np.loadtxt(Edict[i]['symbol']+".prof")
grafico.set_xdata(range(len(Edict[i]['dist'])))
grafico.set_ydata(Edict[i]['dist'])
grafico.set_xdata(Edict[i]['dist'].axisdepth())
grafico.set_ydata(Edict[i]['dist'].data)
t.set_text('%s' %Edict[i]['symbol'])
a.relim()
a.autoscale_view()
a.set_ylim(0,1)
a.set_xlim(0,Edict[int(Econtrol)]['profundidademax'])
f.canvas.draw()
##############################################################################
##############################################################################
# Init
def ewin_build(window, OFlabentries, mainwindow, calcbutton, distvar, modevar, Labelframe, grafico, f, a):
......@@ -72,7 +73,7 @@ def ewin_build(window, OFlabentries, mainwindow, calcbutton, distvar, modevar, L
# Element addition
def create():
global i, Edict, Ebuttons
Edict[i]=dict(name="New Element",symbol="Hf",mass=178.,Z=72,dist=zeros(int(10./float(OFlabentries[17].get()))),LineShape=200.,profundidademax=2.)
Edict[i]=dict(name="New Element",symbol="Hf",mass=178.,Z=72,dist=profile(200,0.01),LineShape=200.,profundidademax=2.)
Ebuttons.insert(i, tk.Button(Eframe, text=i, width=1, height=1, command = lambda i=i : elem_select(i,Ebuttons,grafico,f,a,t)) )
Ebuttons[i].grid(row = ((len(Ebuttons)-1)%6), column = int(math.floor((len(Ebuttons)-1)/6)))
i = i+1
......@@ -94,14 +95,8 @@ def ewin_build(window, OFlabentries, mainwindow, calcbutton, distvar, modevar, L
if Econtrol == i:
Econtrol = Econtrol -1
Ebuttons[Econtrol]['relief']='sunken'
elem_select(0, Ebuttons, grafico, f)
##############################################################################
# Hotkeys
elem_select(0, Ebuttons, grafico, f, a, t)
#cidclick = f.canvas.mpl_connect('button_press_event', key_4)
#cidmotion = f.canvas.mpl_connect('motion_notify_event', key_5)
#cidrelease = f.canvas.mpl_connect('button_release_event', key_6)
##############################################################################
# Element Frames
......@@ -134,9 +129,9 @@ def ewin_build(window, OFlabentries, mainwindow, calcbutton, distvar, modevar, L
Labentrys[4].configure(text = 'Line Shape α - %f' %Edict[i]['LineShape'])
Edict[i]['profundidademax'] = float(Labentrys[11].get())
Labentrys[5].configure(text = 'Max Depht - %f' %Edict[i]['profundidademax'])
Edict[i]['dist'] = np.loadtxt(Edict[i]['symbol']+".prof")
Edict[i]['dist'].resize(int(100*Edict[i]['profundidademax']))
elem_select(i,Ebuttons,grafico,f,a,t)
for i in range(3):
Frames.insert(i, tk.Frame(Labelprop) )
......@@ -175,19 +170,99 @@ def ewin_build(window, OFlabentries, mainwindow, calcbutton, distvar, modevar, L
Labentrys.insert(4, tk.Label(Frames[3], width=23, pady=2, text='Line Shape α - %f' %Edict[int(Econtrol)]['LineShape']) )
Labentrys.insert(5, tk.Label(Frames[3], width=23, pady=2, text='Max Depht - %f' %Edict[int(Econtrol)]['profundidademax']) )
for i in arange(6, 13):
Labentrys.insert(i, tk.Entry(Frames[4], width=17) )
for j in arange(6, 13):
Labentrys.insert(j, tk.Entry(Frames[4], width=17) )
Labentrys.insert(13, tk.Label(Frames[3], width=23, pady=2, text='Resonance energy') )
for i in range(14):
Labentrys[i].pack()
for j in range(14):
Labentrys[j].pack()
# Declaration of interpolation and distribution method variables
methodvar = tk.StringVar()
methodvar.set('step')
##############################################################################
# Distribution Hotkeys #
##############################################################################
def cursor_draw_click(event):
global Econtrol
if event.inaxes != a.axes: return
if event.button == 1:
Control['drawing']=True
elif event.button == 2:
Control['scaling']=True
elif event.button == 3:
Control['shifting']=True
Control['x'] = float(event.xdata)
Control['y'] = float(event.ydata)
if Control['y'] > 1:
Control['y'] = 1.
def cursor_draw_motion(event):
global Econtrol
if event.inaxes != a.axes: return
if Control['drawing']:
Edict[Econtrol]['dist'].drawline(Control['x'], float(event.xdata), Control['y'], float(event.ydata))
Control['x'] = float(event.xdata)
Control['y'] = float(event.ydata)
elif Control['scaling']:
Edict[Econtrol]['dist'].soma(float(event.ydata) - Control['y'])
Control['y'] = float(event.ydata)
elif Control['shifting']:
Edict[Econtrol]['dist'].shiftx(Control['x'],float(event.xdata))
Control['x'] = float(event.xdata)
grafico.set_xdata(Edict[Econtrol]['dist'].axisdepth())
grafico.set_ydata(Edict[Econtrol]['dist'].data)
f.canvas.draw()
def cursor_draw_release(event):
Control['drawing']=False
Control['scaling']=False
Control['shifting']=False
def abrupt(event):pass
def smooth(event): # N funciona
global Econtrol
Edict[Econtrol]['dist'].smooth(5)
f.canvas.draw()
def normalize(event):
global Econtrol, i
Normalizator = list()
for j in range(i):
for k in range(Edict[j]['dist'].size):
if k >= len(Normalizator):
Normalizator.insert(k,0.)
Normalizator[k] = Normalizator[k] + Edict[j]['dist'].data[k]
for j in range(i):
for k in range(Edict[j]['dist'].size):
if Normalizator [k] > 0:
Edict[j]['dist'].data[k] = Edict[j]['dist'].data[k]/Normalizator[k]
f.canvas.draw()
del Normalizator
def clear(event):
global Econtrol
Edict[Econtrol]['dist'].clear()
f.canvas.draw()
f.canvas.mpl_connect('button_press_event', cursor_draw_click)
f.canvas.mpl_connect('motion_notify_event', cursor_draw_motion)
f.canvas.mpl_connect('button_release_event', cursor_draw_release)
mainwindow.bind_all("<Alt-KeyPress-a>", abrupt)
mainwindow.bind_all("<Alt-KeyPress-s>", smooth)
mainwindow.bind_all("<Alt-KeyPress-n>", normalize)
mainwindow.bind_all("<Alt-KeyPress-c>", clear)
##############################################################################
# #
##############################################################################
# Load/Save sample
def LOADSAMPLE():
......@@ -199,13 +274,13 @@ def ewin_build(window, OFlabentries, mainwindow, calcbutton, distvar, modevar, L
for n in arange(21,25):
OFlabentries[n].delete(0,'end')
OFlabentries[n].insert(0,float(arquivo.readline()))
f = loadtxt(arquivo.name + '.elm', dtype="string")
els = f[:, 0]
eln = f[:, 1]
elm = f[:, 2]
elz = f[:, 3]
LSs = f[:, 4]
eld = f[:, 5]
fil = loadtxt(arquivo.name + '.elm', dtype="string")
els = fil[:, 0]
eln = fil[:, 1]
elm = fil[:, 2]
elz = fil[:, 3]
LSs = fil[:, 4]
eld = fil[:, 5]
Edict.clear()
for n in range(len(Ebuttons)):
Ebuttons[n].destroy()
......@@ -223,7 +298,7 @@ def ewin_build(window, OFlabentries, mainwindow, calcbutton, distvar, modevar, L
Ebuttons[n]['text'] = str(els[n])
shutil.copy(arquivo.name + '-' + Edict[n]['symbol'] + '.dat' , Edict[n]['symbol']+'.dat')
shutil.copy(arquivo.name + '-' + Edict[n]['symbol'] + '.prof' , Edict[n]['symbol']+'.prof')
elem_select(0,Ebuttons,grafico, f)
elem_select(0,Ebuttons,grafico, f, a, t)
arquivo.close()
def SAVESAMPLE():
......@@ -369,13 +444,14 @@ def ewin_build(window, OFlabentries, mainwindow, calcbutton, distvar, modevar, L
Rrrna = tk.Radiobutton(Labelframe, text="Resonant RNA", variable=modevar, value=1, width=20, command=lambda i=i :changemode2())
Rrrna.pack()
##############################################################################
##############################################################################
# Init
Rions.invoke()
RDra.invoke()
RS.select()
Ebuttons[0].invoke()
elem_select(0,Ebuttons,grafico, f, a, t)
##############################################################################
No preview for this file type
......@@ -66,7 +66,7 @@ Iframee = tk.Frame(Label3)
Iframee.pack(side='right')
Dframe = tk.Frame(MasterFrame2, bd=2)
Dframe.pack(side='bottom')
Dframe.pack(side='bottom',fill='both', expand=1)
##############################################################################
##############################################################################
......
......@@ -4,5 +4,6 @@ Tkinter
scipy
numpy
pylab
shutil (to save files)
To run simply type on the terminal >> python OpenFlatus.py
......@@ -85,7 +85,6 @@ def calc(p, modelo, ion, OFlabentries, LScontrol, CGausscontrol, metodo, espectr
# É multiplicada pelo passo para manter a escala do gráfico independente do mesmo.
# Bessel:
# Ainda falta incluir a delta de Dirac na origem
# Existe um valor máximo em energia no qual a função de Bessel pode ser computada em função
# da precisão numérica. Uma possível solução pode ser trabalhar em outras unidades que não
# resultem em argumentos tão grandes para a função exponencial.
......
......@@ -11,16 +11,21 @@ class profile:
self.xmin = 0.
self.xmax = N*x
self.stepsize = x
self.data = ones(N)
self.data = zeros(N)
self.size = N
self.contam = 0.
def axisdepth(self):
return arange(self.contam, self.size*self.stepsize, self.stepsize)
return arange(self.contam, self.size*self.stepsize+self.contam, self.stepsize)
def clear(self):
self.data = zeros(self.size)
def soma(self, qt):
for j in range(self.size):
if self.data[j] > 0:
self.data[j] = self.data[j] + qt
def resize(self, size):
N = self.size
M = size
......@@ -34,6 +39,18 @@ class profile:
self.size = M
self.xmax = M*self.stepsize
def shiftx(self, x, x2):
self.data = list(self.data)
if x < x2:
for y in arange(int(x/self.stepsize), int(x2/self.stepsize)):
self.data.insert(y,0)
self.data.pop()
elif x > x2: # funciona mal
for y in arange(int(x2/self.stepsize), int(self.xmax/self.stepsize)):
if y < self.size-1:
self.data[y] = self.data[y+1]
self.data[self.size-1] = 0
def setcontam(self, newcontam):
delta = newcontam-self.contam
dx = math.ceil(delta/self.stepsize)
......@@ -63,23 +80,23 @@ class profile:
if (xb < 0):
xb = 0
if (xa < xb):
for i in arange(math.floor(xa/stepsize), math.floor(xb/stepsize)):
for i in arange(math.floor(xa/stepsize), math.floor(xb/stepsize),1):
if (i > math.floor(contam/stepsize)):
a = (cb - ca) / (xb - xa)
b = -a*xa + ca
conc = a*(1.*i*stepsize) + b
if (conc < 0):
conc = 0.
self.data[i] = conc;
self.data[int(i)] = conc;
if (xb < xa):
for i in arange(math.floor(xb/stepsize), math.floor(xa/stepsize)):
for i in arange(math.floor(xb/stepsize), math.floor(xa/stepsize),1):
if (i > math.floor(contam/stepsize)):
a = (ca - cb) / (xa - xb)
b = -a*xb + cb
conc = a*(1.*i*stepsize) + b
if(conc < 0):
conc = 0
self.data[i] = conc
self.data[int(i)] = conc
def adderfc(self, qtd, sigma):
xsigma = self.xmax
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment