OpenFlatus.py 10.6 KB
Newer Older
1
2
3
# -*- coding: iso-8859-15 -*-

import Tkinter as tk
4
from Ewindow import *
5
6
from calc import *
from spec import *
7

Matheus Müller's avatar
Matheus Müller committed
8
##############################################################################
9
10
# Arbitrary parameters to define dictionaries
param = dict(dedx=250. ,Theta_out=70., dW2dx=26500., E0= 100000, Theta_in=0., FWHM0=250.)
11
ionb = dict(Z=1, mass=1.0079)
12
OFlabentries = list()
13
14
15
16
17
18
Plot = dict()
Plotbuttons = list()
j = 0
Pcontrol = 0
doseold = 6.6e36 
FT = True
19

20
##############################################################################
Matheus Müller's avatar
Matheus Müller committed
21
##############################################################################
22
23
24
# Main window

root = tk.Tk()
25
root.minsize(800,720)
26
root.title('Open Flatus')
27
root.geometry('800x720+200+400')
28

Matheus Müller's avatar
Matheus Müller committed
29
##############################################################################
30
31
32
# Frames
MasterFrame1 = tk.Frame(root)
MasterFrame1.pack(side='left')
Matheus Müller's avatar
Matheus Müller committed
33
34
MasterFrame2 = tk.Frame(root)
MasterFrame2.pack(side='top')
35

36
37
Label0 = tk.LabelFrame(MasterFrame1, text = 'Experiment', relief='raised', bd=2)
Label0.pack(side='top')
38
39
40
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)
Matheus Müller's avatar
Matheus Müller committed
41
42
43
Label3.pack(side='top')
Label4 = tk.LabelFrame(MasterFrame1, text = 'Energy loss model', relief='raised', bd=2)
Label4.pack(side='top')
44
45
46
47
Label5 = tk.LabelFrame(MasterFrame1, text = 'Graphical parameters', relief='raised', bd=2)
Label5.pack(side='top')
Label6 = tk.LabelFrame(MasterFrame1, text = 'Curve Selection', relief='raised', bd=2)
Label6.pack(side='top')
Matheus Müller's avatar
Matheus Müller committed
48
49
50
51

# Elements frame
Label1 = tk.Frame(MasterFrame2)
Label1.pack(side='top')
52
53
54
55
56
57

Pframel = tk.Frame(Label2)
Pframel.pack(side='left')
Pframee = tk.Frame(Label2)
Pframee.pack(side='right')

58
59
60
61
62
Gframel = tk.Frame(Label5)
Gframel.pack(side='left')
Gframee = tk.Frame(Label5)
Gframee.pack(side='right')

63
Iframel = tk.Frame(Label3)
64
Iframel.pack(side='left')
65
Iframee = tk.Frame(Label3)
66
Iframee.pack(side='right')
67

68
Dframe = tk.Frame(MasterFrame2, bd=2)
69
Dframe.pack(side='bottom',fill='both', expand=1)
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

##############################################################################
##############################################################################
# Controle de Plots - Inicio                                                 #
##############################################################################
# Embedded distribution

f = plt.figure()
a = f.add_subplot(111)

embedded_frame = tk.Frame(Dframe)
embedded_frame.pack(side='bottom',fill='both', expand=1)
    
dataPlot = FigureCanvasTkAgg(f, master=embedded_frame)
dataPlot.get_tk_widget().pack(side='top', fill='both', expand=1)

xx = arange(0, 100)       		  
temp, = a.plot(xx, xx*0, 'blue', lw=0.9)
xlabel('Depth (nm)')
ylabel('Concentration factor')
ylim([0,1])

##############################################################################
# Figura do plot de perda de energia

f2 = plt.figure()
xlabel('Energy (eV)')
ylabel('Yield')

##############################################################################
pltbutfrm = tk.Frame(Label6)
pltbutfrm.pack(side='bottom')
pltbutfrm2 = tk.Frame(Label6)
pltbutfrm2.pack(side='bottom')
pltbutfrm3 = tk.Frame(Label6)
pltbutfrm3.pack(side='bottom')

def plot_select(j, button):
    global Pcontrol, Plot
    button[Pcontrol]['relief']='raised'
    Pcontrol = j
    button[j]['relief']='sunken'

def add_plot():
    global j, Plot, Plotbuttons
    Plot[j], = plot(xx, xx*0, lw=0.9, label = '%s' %j)
    Plotbuttons.insert(j, tk.Button(pltbutfrm, text=j, width=1, height=1, command = lambda j=j : plot_select(j,Plotbuttons) ) )
    Plotbuttons[j].grid(column = ((len(Plotbuttons)-1)%5), row = int(math.floor((len(Plotbuttons)-1)/5)))
    j = j + 1

def rmv_plot():
    global j, Plot, Plotbuttons, Pcontrol
    if j > 1:
        j = j-1
        for a in range(Pcontrol+1,j+1):
            Plot[a-1] = Plot[a]
            Plotbuttons[a-1].configure(text = Plotbuttons[a]['text'])

        del Plot[j]
        Plotbuttons[j].destroy()
        del Plotbuttons[j]

        if Pcontrol == j:
            Pcontrol = Pcontrol -1
            Plotbuttons[Pcontrol]['relief']='sunken'
    plot_select(0, Plotbuttons)

baddplt = tk.Button(pltbutfrm2, command=add_plot, text='Add Plot', bd=1, height=1,width=7, pady='4')
baddplt.pack(side='left')
brmvplt = tk.Button(pltbutfrm2, command=rmv_plot, text='Remove Plot', bd=1, height=1,width=9, pady='4')
brmvplt.pack(side='left')

##############################################################################
# Controle de Plots - Fim                                                    #
##############################################################################
Matheus Müller's avatar
Matheus Müller committed
145
##############################################################################
146
# Parameters
147
148
149
150
151
152
153
154
155
156
157
# Labels // Entries numbers:
# 0 // 9 = dedx
# 1 // 10 = dW2dx
# 2 // 11 = theta out
# 3 // 12 = theta in
# 4 // 13 = FWHM0
# 5 // 14 = Energy min
# 6 // 15 = Energy max
# 7 // 16 = Energy step
# 8 // 17 = Depht step

158
159
160
161
162
163
164
165
166
167
168
OFlabentries.insert(0, tk.Label(Pframel, width=13, text='dƐ/dx (eV/nm)', pady=2))
OFlabentries.insert(1, tk.Label(Pframel, width=13, text='dω²/dx (eV²/nm)', pady=2))
OFlabentries.insert(2, tk.Label(Pframel, width=13, text='θ out (°)', pady=2))
OFlabentries.insert(3, tk.Label(Pframel, width=13, text='θ in (°)', pady=2))
OFlabentries.insert(4, tk.Label(Pframel, width=13, text='FWHM0 (eV)', pady=2))
OFlabentries.insert(5, tk.Label(Pframel, width=13, text='Emin (eV)', pady=2))
OFlabentries.insert(6, tk.Label(Pframel, width=13, text='Emax (eV)', pady=2))
OFlabentries.insert(7, tk.Label(Pframel, width=13, text='Estep (eV)', pady=2))
OFlabentries.insert(8, tk.Label(Pframel, width=13, text='Depth step (nm)', pady=2))
OFlabentries.insert(24, tk.Entry(Gframee, width=10))
OFlabentries.insert(25, tk.Label(Gframel, width=12, text='Dose', pady=2))
169

170
# Entries
171
for n in arange(9,18):
172
    OFlabentries.insert(n, tk.Entry(Pframee, width=10))
173
174

#Ion
175
176
177
178
# Labels // Entries numbers:
# 18 // 21 = Initial Energy
# 19 // 22 = mass
# 20 // 23 = Z (atomic number)
179
180
181
OFlabentries.insert(18, tk.Label(Iframel, width=13, text='Energy (KeV)'))
OFlabentries.insert(19, tk.Label(Iframel, width=13, text='Mass'))
OFlabentries.insert(20, tk.Label(Iframel, width=13, text='Z'))
182
183

for n in arange(21,24):
184
    OFlabentries.insert(n, tk.Entry(Iframee, width=10))
185
186

for n in range(26):
187
    OFlabentries[n].pack()
188

189
##############################################################################
190
# Initial values
191
192
193
194
195
196
197
198
199
200
201
202
203

OFlabentries[9].insert(0,param['dedx'])
OFlabentries[10].insert(0,param['dW2dx'])
OFlabentries[11].insert(0,param['Theta_out'])
OFlabentries[12].insert(0,param['Theta_in'])
OFlabentries[13].insert(0,param['FWHM0'])
OFlabentries[14].insert(0,70000)
OFlabentries[15].insert(0,100000) 
OFlabentries[16].insert(0,20) 
OFlabentries[17].insert(0,0.01) 
OFlabentries[21].insert(0,param['E0'])
OFlabentries[22].insert(0, ionb['mass'])
OFlabentries[23].insert(0, ionb['Z'])
204
OFlabentries[24].insert(0, "6.6e36")
205

Matheus Müller's avatar
Matheus Müller committed
206
##############################################################################
207
208
209
# Energy loss models

modelvar = tk.StringVar()
210
modelvar.set('bessel')
211
212
213
214
R1 = tk.Radiobutton(Label4, text="Gaussian", variable=modelvar, value='gaussiana')
R1.pack()
R2 = tk.Radiobutton(Label4, text="Bessel", variable=modelvar, value='bessel')
R2.pack()
215
R2.select()
216

Matheus Müller's avatar
Matheus Müller committed
217
##############################################################################
218
# Line shape/Convolve gaussian checkbox
Matheus Müller's avatar
Matheus Müller committed
219
220

LSvar = tk.IntVar()
221
LSvar.set(1)
222
CGvar = tk.IntVar()
223
CGvar.set(1)
Matheus Müller's avatar
Matheus Müller committed
224
225
C1 = tk.Checkbutton(Label4, text="Use Line Shape", variable=LSvar)
C1.pack()
226
C1.select()
227
C2 = tk.Checkbutton(Label4, text="Resolution Convolve", variable=CGvar, width=21)
228
229
C2.pack()
C2.select()
Matheus Müller's avatar
Matheus Müller committed
230

231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
##############################################################################
# Load experiment data

def loadexp():
    arquivo = tkFileDialog.askopenfilename()
    amostra = np.loadtxt(arquivo)
    xxx= amostra[:,0]*1000
    ccc=amostra[:,1]

    plot (xxx, ccc, 'r.')
    show()

##############################################################################
# Adjust graphic

def adjust():
    fraction = float(OFlabentries[24].get())/doseold
    newdata = temp.ydata*fraction
    temp.set_ydata(newdata)
    doseold = float(OFlabentries[24].get())
    show()

##############################################################################
# Calculation callback
# Get parameters

def init_calc():
    global modelvar, FT
    param['dedx'] = float(OFlabentries[9].get())
    param['dW2dx'] = float(OFlabentries[10].get())
    param['Theta_out'] = float(OFlabentries[11].get())
    param['Theta_in'] = float(OFlabentries[12].get())
    param['E0'] = float(OFlabentries[21].get())
    param['FWHM0'] = float(OFlabentries[13].get())
    ionb['mass'] = float(OFlabentries[22].get())
    ionb['Z'] = float(OFlabentries[23].get())      
    espectro = spectro(int(float(OFlabentries[21].get())/float(OFlabentries[16].get())), int(OFlabentries[16].get()))         		 
 
    LSi = int(LSvar.get())
    CGi = int(CGvar.get())

    if int(modevar.get()) == 0:
        if int(distvar.get()) == 1:
274
            calc(param, str(modelvar.get()), ionb, OFlabentries, LSi, CGi, 'draw', espectro, OFlabentries[14].get(), Plot, f2, FT, Plotbuttons, Pcontrol)
275
        elif int(distvar.get()) == 0:
276
            calc(param, str(modelvar.get()), ionb, OFlabentries, LSi, CGi, 'layer', espectro, OFlabentries[14].get(), Plot, f2, FT, Plotbuttons, Pcontrol)
277
278
279
280
281
282

    elif int(modevar.get()) == 1:
        pass #spectroRNA(param, str(modelvar.get()), ionb, OFlabentries, int(LSvar.get()), int(CGvar.get()), temp)

    FT = False

Matheus Müller's avatar
Matheus Müller committed
283
##############################################################################
284
# Calculate and Exit buttons
285

286
287
288
289
290
291
292
293
294
295
CalcButton = tk.Button(pltbutfrm3, text = 'Calculate Energy Loss', command = init_calc, bd=4, width=19, height=2)
CalcButton.pack(side='bottom')

##############################################################################
# Grahical parameters buttons

Adjbut = tk.Button(Gframee, text = 'Adjust', command = init_calc, width=8)
Databut = tk.Button(Gframel, text = 'Exp Data', command = loadexp, width=6)
Adjbut.pack()
Databut.pack()
296

297
##############################################################################
Matheus Müller's avatar
Matheus Müller committed
298
##############################################################################
299
300
# Elements callback

Matheus Müller's avatar
Matheus Müller committed
301
modevar = tk.IntVar()
Matheus Müller's avatar
Matheus Müller committed
302
modevar.set(0)
Matheus Müller's avatar
Matheus Müller committed
303
distvar = tk.IntVar()
Matheus Müller's avatar
Matheus Müller committed
304
distvar.set(1)
305
ewin_build(Label1, OFlabentries, root, CalcButton, distvar, modevar, Label0, temp, f, a)
306

Matheus Müller's avatar
Matheus Müller committed
307
##############################################################################
308

309
310
add_plot()
plot_select(0,Plotbuttons)
311
312
root.mainloop()

Matheus Müller's avatar
Matheus Müller committed
313
##############################################################################
314
##############################################################################