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

import Tkinter as tk
4
from Ewindow import *
5
from numerical import *
6
import sys
7

8
##############################################################################
9
# Arbitrary parameters to declare dictionaries
10
param = dict(dedx=192. ,Theta_out=70., dW2dx=20740., E0= 100000., Theta_in=0., FWHM0=180.)
11
ionb = dict(Z=1, mass=1.0079)
12
OFlabentries = list()
13
init=0
14

15
##############################################################################
16
# Calculation callback
17
# Get parameters
18 19

def init_calc():
20
    global modelvar
21 22 23 24 25 26 27 28
    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())      
29

30 31
    for i in range(len(Edict)):
        Edict[i]['dist'] = np.loadtxt(Edict[i]['symbol']+".prof")
32

33
    spectro(param, str(modelvar.get()), ionb, OFlabentries, int(LSvar.get()), int(CGvar.get()))
34

35
##############################################################################
36 37 38
# Main window

root = tk.Tk()
39
root.minsize(700,500)
40
root.title('Open Flatus')
41
root.geometry('700x500+200+400')
42

43
##############################################################################
44 45 46
# Frames
MasterFrame1 = tk.Frame(root)
MasterFrame1.pack(side='left')
47 48
MasterFrame2 = tk.Frame(root)
MasterFrame2.pack(side='top')
49 50 51 52

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)
53 54 55 56 57 58 59
Label3.pack(side='top')
Label4 = tk.LabelFrame(MasterFrame1, text = 'Energy loss model', relief='raised', bd=2)
Label4.pack(side='top')

# Elements frame
Label1 = tk.Frame(MasterFrame2)
Label1.pack(side='top')
60 61 62 63 64 65

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

66
Iframel = tk.Frame(Label3, width=9)
67
Iframel.pack(side='left')
68
Iframee = tk.Frame(Label3, width=11)
69
Iframee.pack(side='right')
70

71
##############################################################################
72
# Parameters
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
# 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

OFlabentries.insert(0, tk.Label(Pframel, width=9, text='dƐ/dx', pady=2))
OFlabentries.insert(1, tk.Label(Pframel, width=9, text='dω²/dx', pady=2))
OFlabentries.insert(2, tk.Label(Pframel, width=9, text='θ out', pady=2))
OFlabentries.insert(3, tk.Label(Pframel, width=9, text='θ in', pady=2))
OFlabentries.insert(4, tk.Label(Pframel, width=9, text='FWHM0', pady=2))
OFlabentries.insert(5, tk.Label(Pframel, width=9, text='Emin', pady=2))
OFlabentries.insert(6, tk.Label(Pframel, width=9, text='Emax', pady=2))
OFlabentries.insert(7, tk.Label(Pframel, width=9, text='Estep', pady=2))
OFlabentries.insert(8, tk.Label(Pframel, width=9, text='Depth step', pady=2))
for n in range(9):
    OFlabentries[n].pack()
95 96

# Entries
97 98 99
for n in arange(9,18):
    OFlabentries.insert(n, tk.Entry(Pframee, width=11))
    OFlabentries[n].pack()
100 101

#Ion
102 103 104 105 106 107 108 109 110 111 112 113 114
# Labels // Entries numbers:
# 18 // 21 = Initial Energy
# 19 // 22 = mass
# 20 // 23 = Z (atomic number)
OFlabentries.insert(18, tk.Label(Iframel, width=9, text='Energy'))
OFlabentries.insert(19, tk.Label(Iframel, width=9, text='Mass'))
OFlabentries.insert(20, tk.Label(Iframel, width=9, text='Z'))
for n in arange(18,21):
    OFlabentries[n].pack()

for n in arange(21,24):
    OFlabentries.insert(n, tk.Entry(Iframee, width=11))
    OFlabentries[n].pack()
115

116
##############################################################################
117
#Initial values
118 119 120 121 122 123 124 125 126 127 128 129 130

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'])
131

132
##############################################################################
133 134 135 136 137 138 139
# 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()
140
R2.select()
141

142
##############################################################################
143
# Line shape/Convolve gaussian checkbox
144 145

LSvar = tk.IntVar()
146
CGvar = tk.IntVar()
147 148
C1 = tk.Checkbutton(Label4, text="Use Line Shape", variable=LSvar)
C1.pack()
149
C1.select()
150 151 152
C2 = tk.Checkbutton(Label4, text="Resolution Convolve", variable=CGvar)
C2.pack()
C2.select()
153 154

##############################################################################
155
# Calculate and Exit buttons
156

157
CalcButton = tk.Button(Label4, text = 'Calculate', command = init_calc, bd=4, width=17, height=2)
158 159
CalcButton.pack()

160
ExitButton = tk.Button(Label4, text = 'Exit', command = sys.exit, bd=4, width=17, height=2)
161 162
ExitButton.pack(side='bottom')

163
##############################################################################
164 165
# Elements callback

166
ewin_build(Label1, OFlabentries)
167

168
##############################################################################
169
if init == 1:
170 171
    CalcButton.invoke()
    init = 1
172 173

root.mainloop()
174
Label1.mainloop()
175

176
##############################################################################