OpenFlatus.py 7.17 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
init=0
13
espessura = 30.
14

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
##############################################################################
# Report file, writes parameters
def config_write():
    config = open("config.cfg", 'w+')
    config.write( (Entrydedx.get())+'\n' )
    config.write( (EntrydW2dx.get())+'\n' )
    config.write( (EntryT_out.get())+'\n' )
    config.write( (EntryT_in.get())+'\n' )
    config.write( (EntryFWHM0.get())+'\n' )
    config.write( (EntryEmin.get())+'\n' )
    config.write( (EntryEmax.get())+'\n' )
    config.write( (EntryEstep.get())+'\n' )
    config.write( (EntryDstep.get())+'\n' )
    config.write( (EntryE0.get())+'\n' )
    config.write( (Entryionmass.get())+'\n' )
    config.write( (EntryionZ.get())+'\n\n' )
    config.write( '##############################################################################\n' )
    config.write( '# dƐ/dx\n# dω²/dx\n# θ out\n# θ in\n# FWHM\n# E min\n# E max\n# E step\n# Depth step\n# Ion energy\n# Ion mass\n# Ion Z\n' )
    config.close()

35
##############################################################################
36 37 38 39
# Calculation callback
# Defines parameters

def init_calc():
40
    global modelvar
41 42 43 44 45
    param['dedx'] = float(Entrydedx.get())
    param['dW2dx'] = float(EntrydW2dx.get())
    param['Theta_out'] = float(EntryT_out.get())
    param['Theta_in'] = float(EntryT_in.get())
    param['E0'] = float(EntryE0.get())
46
    param['FWHM0'] = float(EntryFWHM0.get())
47
    ionb['mass'] = float(Entryionmass.get())
48
    ionb['Z'] = float(EntryionZ.get())      
49

50 51
    config_write()

52 53
    for i in range(len(Edict)):
        Edict[i]['dist'] = np.loadtxt(Edict[i]['symbol']+".prof")
54
    spectro(param, str(modelvar.get()), ionb, float(EntryEmin.get()),float(EntryEmax.get()), float(EntryEstep.get()), float(EntryDstep.get()), int(LSvar.get()), float(EntryFWHM0.get()), espessura )
55

56
##############################################################################
57 58 59
# Main window

root = tk.Tk()
60
root.minsize(730,460)
61
root.title('Open Flatus')
62
root.geometry('375x270+200+400')
63

64
##############################################################################
65 66 67
# Frames
MasterFrame1 = tk.Frame(root)
MasterFrame1.pack(side='left')
68 69
MasterFrame2 = tk.Frame(root)
MasterFrame2.pack(side='top')
70 71 72 73

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)
74 75 76 77 78 79 80
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')
81 82 83 84 85 86

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

87
Iframel = tk.Frame(Label3, width=9)
88
Iframel.pack(side='left')
89
Iframee = tk.Frame(Label3, width=11)
90
Iframee.pack(side='right')
91

92
##############################################################################
93 94
# Parameters
# Labels
95 96 97 98
Labeldedx = tk.Label(Pframel, width=9, text='dƐ/dx', pady=2)
LabeldW2dx = tk.Label(Pframel, width=9, text='dω²/dx', pady=2)
LabelT_out = tk.Label(Pframel, width=9, text='θ out', pady=2)
LabelT_in = tk.Label(Pframel, width=9, text='θ in', pady=2)
99
LabelFWHM0 = tk.Label(Pframel, width=9, text='FWHM0')
100 101 102
LabelEmin = tk.Label(Pframel, width=9, text='Emin', pady=2)
LabelEmax = tk.Label(Pframel, width=9, text='Emax', pady=2)
LabelEstep = tk.Label(Pframel, width=9, text='Estep', pady=2)
103
LabelDstep = tk.Label(Pframel, width=9, text='Depth step', pady=2)
104 105 106 107
Labeldedx.pack()
LabeldW2dx.pack()
LabelT_out.pack()
LabelT_in.pack()
108
LabelFWHM0.pack()
109 110
LabelEmin.pack()
LabelEmax.pack()
111 112
LabelEstep.pack()
LabelDstep.pack()
113 114

# Entries
115 116 117 118
Entrydedx = tk.Entry(Pframee, width=11)
EntrydW2dx = tk.Entry(Pframee, width=11)
EntryT_out = tk.Entry(Pframee, width=11)
EntryT_in = tk.Entry(Pframee, width=11)
119
EntryFWHM0 = tk.Entry(Pframee, width=11)
120 121 122 123
EntryEmin = tk.Entry(Pframee, width=11)
EntryEmax = tk.Entry(Pframee, width=11)
EntryEstep = tk.Entry(Pframee, width=11)
EntryDstep = tk.Entry(Pframee, width=11)
124 125 126 127
Entrydedx.pack()
EntrydW2dx.pack()
EntryT_out.pack()
EntryT_in.pack()
128
EntryFWHM0.pack()
129
EntryEmin.pack()
130
EntryEmax.pack()
131 132
EntryEstep.pack()
EntryDstep.pack()
133 134

#Ion
135 136 137 138
LabelE0 = tk.Label(Iframel, width=9, text='Energy')
Labelionmass = tk.Label(Iframel, width=9, text='Mass')
LabelionZ = tk.Label(Iframel, width=9, text='Z')
LabelE0.pack()
139 140
Labelionmass.pack()
LabelionZ.pack()
141 142 143 144
EntryE0 = tk.Entry(Iframee, width=11)
Entryionmass = tk.Entry(Iframee, width=11)
EntryionZ = tk.Entry(Iframee, width=11)
EntryE0.pack()
145 146 147 148
Entryionmass.pack()
EntryionZ.pack()

#Initial values
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
try:
    config = open("config.cfg", 'r+')
except IOError: 
    Entrydedx.insert(0,param['dedx'])
    EntrydW2dx.insert(0,param['dW2dx'])
    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,70000)
    EntryEmax.insert(0,100000) 
    EntryEstep.insert(0,20) 
    EntryDstep.insert(0,0.01) 
    Entryionmass.insert(0, ionb['mass'])
    EntryionZ.insert(0, ionb['Z'])
else:
    Entrydedx.insert(0,float(config.readline()))
    EntrydW2dx.insert(0,float(config.readline()))
    EntryT_out.insert(0,float(config.readline()))
    EntryT_in.insert(0,float(config.readline()))
    EntryFWHM0.insert(0,float(config.readline()))
    EntryEmin.insert(0,float(config.readline()))
    EntryEmax.insert(0,float(config.readline())) 
    EntryEstep.insert(0,float(config.readline())) 
    EntryDstep.insert(0,float(config.readline())) 
    EntryE0.insert(0,float(config.readline()))
    Entryionmass.insert(0, float(config.readline()))
    EntryionZ.insert(0, int(config.readline()))
    config.close()
178

179
##############################################################################
180 181 182 183 184 185 186
# 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()
187
R2.select()
188

189 190 191 192 193 194
##############################################################################
# Line shape checkbox

LSvar = tk.IntVar()
C1 = tk.Checkbutton(Label4, text="Use Line Shape", variable=LSvar)
C1.pack()
195
C1.select()
196 197

##############################################################################
198

199
CalcButton = tk.Button(Label4, text = 'Calculate', command = init_calc, bd=4, width=17, height=2)
200 201
CalcButton.pack()

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

205
##############################################################################
206 207
# Elements callback

208
ewin_build(Label1, espessura, float(EntryDstep.get()))
209

210
##############################################################################
211
if init == 1:
212 213
    CalcButton.invoke()
    init = 1
214 215

root.mainloop()
216
Label1.mainloop()
217

218
##############################################################################