forked from L-anc/Pharet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pharet v1.1.py
363 lines (264 loc) · 10.7 KB
/
Pharet v1.1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
145
146
147
148
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
import tkinter as tk
from tkinter import *
import tkinter.messagebox
import math
import sympy as sy
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
root = tk.Tk()
root.wm_title("Pharet")
root.geometry("700x450")
tbdeg=tk.IntVar()
dtdeg=tk.IntVar()
lensType=tk.StringVar()
canvas = tk.Canvas(root, bg='#696969') #sets up the window size and color
canvas.place(relwidth=1, relheight=1, relx=0, rely=0)
frame1 = tk.Frame(root, bd=0.1)
frame1.place(relwidth=0.3, relheight=0.12, relx=0.05, rely=0.075) #places a frame for other elements within the window
buttonsi = tk.Button(frame1, bg='#848482', text='Silicon', font=80) #Creates the silicone button
buttonsi.place(relwidth=0.5, relheight=1)
buttondmnd = tk.Button(frame1, bg='#848482', text='Diamond', font=80) #creates the diamond button(ADD MORE ENTRYS FOR t AND eV)
buttondmnd.place(relwidth=0.5, relheight=1, relx=0.5)
framegrpr = tk.Frame(root, bd=0.1)
framegrpr.place(relwidth=0.4, relheight=0.12, relx=0.5, rely=0.6)
buttongr = tk.Button(framegrpr, bg='#7C7273', text='Graph', font=80) #Creates the silicone button
buttongr.place(relwidth=0.5, relheight=1)
buttonpr = tk.Button(framegrpr, bg='#8a7f80', text='Print', font=80) #creates the diamond button(ADD MORE ENTRYS FOR t AND eV)
buttonpr.place(relwidth=0.5, relheight=1, relx=0.5)
frameentry = tk.Frame(root, bd=0.1)
frameentry.place(relheight=0.6, relwidth=0.3, relx=0.05, rely=0.25) #creates another frame for entrys
labelh = tk.Label(frameentry, bd=0.1, bg='#7C7273', text='h:', font=80) #label for variable 1
labelh.place(relheight=0.2, relwidth=0.4, anchor='nw')
entryh = tk.Entry(frameentry, bd=0.1, bg='#8a7f80', font=80) #entry for variable 1
entryh.place(relheight=0.2, relwidth=0.6, relx=0.4, rely=0)
labelk = tk.Label(frameentry, bd=0.1, bg='#7D777B', text='k:', font=80) #label for variable 2
labelk.place(relheight=0.2, relwidth=0.4, rely=0.2, relx=0)
entryk = tk.Entry(frameentry, bd=0.1, bg='#8b8589', font=80)
entryk.place(relheight=0.2, relwidth=0.6, relx=0.4, rely=0.2) #entry for variable 2
labell = tk.Label(frameentry, bd=0.1, bg='#7C7273', text='l:', font=80) #label for variable 3
labell.place(relheight=0.2, relwidth=0.4, rely=0.4, relx=0)
entryl = tk.Entry(frameentry, bd=0.1, bg='#8a7f80', font=80)
entryl.place(relheight=0.2, relwidth=0.6, relx=0.4, rely=0.4) #entry for variable 3
labelt = tk.Label(frameentry, bd=0.1, bg='#7D777B', text='thickness(μm):', font=40)
labelt.place(relheight=0.2, relwidth=0.5, rely=0.6, relx=0)
entryt = tk.Entry(frameentry, bd=0.1, bg='#8b8589', font=80)
entryt.place(relheight=0.2, relwidth=0.5, relx=0.5, rely=0.6)
labeleV = tk.Label(frameentry, bd=0.1, bg='#7C7273', text='energy(eV):', font=50)
labeleV.place(relheight=0.2, relwidth=0.5, rely=0.8, relx=0)
entryeV = tk.Entry(frameentry, bd=0.1, bg='#8a7f80', font=80)
entryeV.place(relheight=0.2, relwidth=0.5, relx=0.5, rely=0.8)
frameres = tk.Frame(root, bd=0.1)
frameres.place(relheight= 0.4, relwidth=0.4, relx=0.5, rely=0.1) #frame for results
labelres = tk.Label(frameres, bd=0.1, bg='#7C7273', text='Results for Crystal Type:', font=200) #title for results
labelres.place(relheight=0.15, relwidth=1)
labelres = tk.Label(frameres, bd=0.1, bg='#7C7273', textvariable=lensType, font=200) #title for results
labelres.place(relheight=0.15, relwidth=1, rely=0.15)
labelang = tk.Label(frameres, bd=0.1, bg='#7C7273', text='Bragg Angle', font=200) #label for angle
labelang.place(relheight=0.35, relwidth=0.5, rely=0.3)
labelresang = tk.Label(frameres, bd=0.1, bg='#8a7f80', textvariable=tbdeg, font=200) #angle text box
labelresang.place(relheight=0.35, relwidth=0.5, rely=0.3, relx=0.5)
labeloff = tk.Label(frameres, bd=0.1, bg='#7C7273', text='Offset (Pc=1)', font=200) #label for offset
labeloff.place(relheight=0.35, relwidth=0.5, rely=0.65)
labelresoff = tk.Label(frameres, bd=0.1, bg='#8a7f80', textvariable=dtdeg, font=200) #offset text box
labelresoff.place(relheight=0.35, relwidth=0.5, rely=0.65, relx=0.5)
ident=0
deltathetadeg=0
thetabdiamdeg=0
thetabsildeg=0
h=0
k=0
l=0
t=0
eV=0
#coordinate arrays
arrx=[]
arry=[]
arrsin=[]
#diamond and silicone specific variables
x1=0.1250
y1=0.1250
z1=0.1250
x2=0.8750
y2=0.8750
z2=0.8750
x3=0.6250
y3=0.6250
z3=0.1250
x4=0.3750
y4=0.3750
z4=0.8750
x5=0.1250
y5=0.6250
z5=0.6250
x6=0.8750
y6=0.3750
z6=0.3750
x7=0.6250
y7=0.1250
z7=0.6250
x8=0.3750
y8=0.8750
z8=0.3750
##test function
def truncate(number, decimals):
"""
Returns a value truncated to a specific number of decimal places.
"""
factor = 10.0 ** decimals
return math.trunc(number * factor) / factor
##test function
def calcdiam():
try:
buttondmnd.configure(bg="#4f666a")
buttonsi.configure(bg="#848482")
lensType.set('Diamond')
global ident
ident=1
global h
global k
global l
global t
global eV
h=int(entryh.get())
k=int(entryk.get())
l=int(entryl.get())
t=int(entryt.get())
eV=int(entryeV.get())
tm=t*10**4
Re=2.81794*10**-5
wavel=12398.506/eV
adaim=3.567
ddiam=3.567/(math.sqrt(h**2+k**2+l**2))
Vdiam=3.567**3
thetabdiam=math.asin(wavel/(2*ddiam))
changethetadiam=0
#fh summation
pi = 3.141592653589793
e = 2.7182818284590452
s = 1/(2*ddiam)
a = complex(0, 1)
f0carbon=((2.31*e**(-20.844*s**2))+(1.02*e**(-10.208*s**2))+(1.589*e**(-0.569*s**2))+(0.865*e**(-51.651*s**2))+0.216)
FminH = (f0carbon*e**(-2*pi*a*(h*x1+k*y1+l*z1)))+(f0carbon*e**(-2*pi*a*(h*x2+k*y2+l*z2)))+(f0carbon*e**(-2*pi*a*(h*x3+k*y3+l*z3)))+(f0carbon*e**(-2*pi*a*(h*x4+k*y4+l*z4)))+(f0carbon*e**(-2*pi*a*(h*x5+k*y5+l*z5)))+(f0carbon*e**(-2*pi*a*(h*x6+k*y6+l*z6)))+(f0carbon*e**(-2*pi*a*(h*x7+k*y7+l*z7)))+(f0carbon*e**(-2*pi*a*(h*x8+k*y8+l*z8)))
FplusH = (f0carbon*e**(2*pi*a*(h*x1+k*y1+l*z1)))+(f0carbon*e**(2*pi*a*(h*x2+k*y2+l*z2)))+(f0carbon*e**(2*pi*a*(h*x3+k*y3+l*z3)))+(f0carbon*e**(2*pi*a*(h*x4+k*y4+l*z4)))+(f0carbon*e**(2*pi*a*(h*x5+k*y5+l*z5)))+(f0carbon*e**(2*pi*a*(h*x6+k*y6+l*z6)))+(f0carbon*e**(2*pi*a*(h*x7+k*y7+l*z7)))+(f0carbon*e**(2*pi*a*(h*x8+k*y8+l*z8)))
FinFH = np.real(FminH*FplusH)
deltatheta = (tm*math.sin(2*thetabdiam)*(pi/2)*(((Re*wavel**2)/(pi*Vdiam))**2)*FinFH)/((pi/2)*math.sin(thetabdiam)*wavel)
global deltathetadeg
global thetabdiamdeg
deltathetadeg = (deltatheta/(2*pi))*360
dtdeg.set(truncate(deltathetadeg,6))
thetabdiamdeg = (thetabdiam/(2*pi))*360
tbdeg.set(truncate(thetabdiamdeg,6))
#use data frames for printing this to txt!
global arrx
global arry
global arrsin
arrx=[]
arry=[]
arrsin=[]
g=1
whiletemp=0
while(g<=200):
arrx.append(whiletemp*(180/pi))
whiletemp=g*5*10**-6
arry.append(FinFH*((Re*wavel**2)/(pi*Vdiam))**2*((tm*math.sin(2*thetabdiam))/(wavel*math.sin(thetabdiam)*whiletemp)))
arrsin.append(math.sin((pi/2)*arry[g-1]))
g=g+1
except Exception:
tkinter.messagebox.showinfo('Error','You have entered an invalid value')
def calcsi():
try:
buttondmnd.configure(bg="#848482")
buttonsi.configure(bg="#4f666a")
lensType.set('Silicon')
global ident
ident=2
global h
global k
global l
global t
global eV
h=int(entryh.get())
k=int(entryk.get())
l=int(entryl.get())
t=int(entryt.get())
eV=int(entryeV.get())
tm=t*10**4
Re=2.81794*10**-5
wavel=12398.506/eV
asil=5.4300
dsil=5.43/(math.sqrt(h**2+k**2+l**2))
Vsil=5.43**3
thetabsil=math.asin(wavel/(2*dsil))
#fh summation
pi = 3.141592653589793
e = 2.7182818284590452
s = 1/(2*dsil)
a = complex(0, 1)
f0silicon=((6.292*e**(-2.439*s**2))+(3.035*e**(-32.334*s**2))+(1.989*e**(-0.678*s**2))+(1.541*e**(-81.694*s**2))+1.141)
FminH = (f0silicon*e**(-2*pi*a*(h*x1+k*y1+l*z1)))+(f0silicon*e**(-2*pi*a*(h*x2+k*y2+l*z2)))+(f0silicon*e**(-2*pi*a*(h*x3+k*y3+l*z3)))+(f0silicon*e**(-2*pi*a*(h*x4+k*y4+l*z4)))+(f0silicon*e**(-2*pi*a*(h*x5+k*y5+l*z5)))+(f0silicon*e**(-2*pi*a*(h*x6+k*y6+l*z6)))+(f0silicon*e**(-2*pi*a*(h*x7+k*y7+l*z7)))+(f0silicon*e**(-2*pi*a*(h*x8+k*y8+l*z8)))
FplusH = (f0silicon*e**(2*pi*a*(h*x1+k*y1+l*z1)))+(f0silicon*e**(2*pi*a*(h*x2+k*y2+l*z2)))+(f0silicon*e**(2*pi*a*(h*x3+k*y3+l*z3)))+(f0silicon*e**(2*pi*a*(h*x4+k*y4+l*z4)))+(f0silicon*e**(2*pi*a*(h*x5+k*y5+l*z5)))+(f0silicon*e**(2*pi*a*(h*x6+k*y6+l*z6)))+(f0silicon*e**(2*pi*a*(h*x7+k*y7+l*z7)))+(f0silicon*e**(2*pi*a*(h*x8+k*y8+l*z8)))
FinFH = np.real(FminH*FplusH)
deltatheta = (tm*math.sin(2*thetabsil)*(pi/2)*(((Re*wavel**2)/(pi*Vsil))**2)*FinFH)/((pi/2)*math.sin(thetabsil)*wavel)
global deltathetadeg
global thetabsildeg
deltathetadeg = (deltatheta/(2*pi))*360
dtdeg.set(truncate(deltathetadeg,6))
thetabsildeg = (thetabsil/(2*pi))*360
tbdeg.set(truncate(thetabsildeg,6))
##under construction (while loop creates arrays of x and y coords of graph)\
global arrx
global arry
global arrsin
arrx=[]
arry=[]
arrsin=[]
g=1
whiletemp=0
while(g<=200):
arrx.append(whiletemp*(180/pi))
whiletemp=g*5*10**-6
arry.append(FinFH*((Re*wavel**2)/(pi*Vsil))**2*((tm*math.sin(2*thetabsil))/(wavel*math.sin(thetabsil)*whiletemp)))
arrsin.append(math.sin((pi/2)*arry[g-1]))
g=g+1
except Exception:
tkinter.messagebox.showinfo('Error','You have entered an invalid value')
def genGraph():
fig , ax = plt.subplots(nrows = 2, ncols = 1, figsize=(8,6))
#Plotting on the 1st axes
ax[0].set_ylim([0,2])
ax[0].set_xlabel('Offset(degrees)')
ax[0].set_ylabel('Phase(pi/2)')
ax[0].plot(arrx,arry, color = 'blue')
#Plotting on the last axes
ax[1].set_xlabel('Offset(degrees)')
ax[1].set_ylabel('Sin(phase)')
ax[1].plot(arrx,arrsin , color = 'orange')
plt.show()
forcount=0
def genTXT():
tkinter.messagebox.showinfo('Print Alert','Your results have been printed to the file PHAREToutput.txt in the same directory as the program')
global forcount
forcount=0
bang=0
if(ident==1):
bang=thetabdiamdeg
if(ident==2):
bang=thetabsildeg
with open("PHAREToutput.txt","w") as f:
f.write("#Output for h="+str(h)+" k="+str(k)+" l="+str(l)+" t(microns)="+str(t)+" eV="+str(eV)+'\n')
if(ident==1):
f.write("#Diamond plate"+'\n')
if(ident==2):
f.write("#Silicone plate"+'\n')
f.write("#Bragg Angle(degrees)="+str(truncate(bang,6))+'\n')
f.write("#Offset(degrees)="+str(truncate(deltathetadeg,6))+'\n')
f.write("#Offset(degrees) Phase(pi/2) Sin(phase)"+'\n')
for x in arrx:
f.write(str(truncate(x,6))+" "+str(truncate(arry[forcount],6))+" "+str(truncate(arrsin[forcount],6))+'\n')
forcount=forcount+1
buttonpr.config(command=genTXT)
buttongr.config(command=genGraph)
buttonsi.config(command=calcsi)
buttondmnd.config(command=calcdiam)
root.mainloop()