This repository has been archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
fprime.py
632 lines (572 loc) · 25.1 KB
/
fprime.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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
#!/usr/bin/env python
"""main Fprime routines
Copyright: 2008, Robert B. Von Dreele (Argonne National Laboratory)
"""
from __future__ import division, print_function
import platform
import math
import sys
import wx
# the next line removes the need for pythonw. Thanks to Matt Newville!
# appears unneaded from wx 4.2.1 on
if sys.platform.lower() == 'darwin': wx.PyApp.IsDisplayAvailable = lambda _: True
import numpy as np
import matplotlib as mpl
import GSASIIpath
GSASIIpath.SetVersionNumber("$Revision: 5743 $")
import GSASIIElem as G2elem
import GSASIIElemGUI as G2elemGUI
try:
wx.NewIdRef
wx.NewId = wx.NewIdRef
except AttributeError:
pass
if '2' in platform.python_version_tuple()[0]:
Gkmu = unichr(0x3bc)
Gktheta = unichr(0x3b8)
Gklambda = unichr(0x3bb)
GkDelta = unichr(0x0394)
Pwr10 = unichr(0x0b9)+unichr(0x2070)
Pwr20 = unichr(0x0b2)+unichr(0x2070)
Pwrm1 = unichr(0x207b)+unichr(0x0b9)
Pwrm2 = unichr(0x207b)+unichr(0x0b2)
Pwrm6 = unichr(0x207b)+unichr(0x2076)
Pwrm4 = unichr(0x207b)+unichr(0x2074)
Angstr = unichr(0x00c5)
else:
Gkmu = chr(0x3bc)
Gktheta = chr(0x3b8)
Gklambda = chr(0x3bb)
GkDelta = chr(0x0394)
Pwr10 = chr(0x0b9)+chr(0x2070)
Pwr20 = chr(0x0b2)+chr(0x2070)
Pwrm1 = chr(0x207b)+chr(0x0b9)
Pwrm2 = chr(0x207b)+chr(0x0b2)
Pwrm6 = chr(0x207b)+chr(0x2076)
Pwrm4 = chr(0x207b)+chr(0x2074)
Angstr = chr(0x00c5)
[wxID_FPRIMECHOICE1, wxID_FPRIMECHOICE2, wxID_SPINTEXT1, wxID_SPINTEXT2,
wxID_FPRIMERESULTS,wxID_FPRIMESLIDER1, wxID_SPINBUTTON,
] = [wx.NewId() for _init_ctrls in range(7)]
[wxID_FPRIMEEXIT, wxID_FPRIMEDELETE, wxID_FPRIMENEW,
] = [wx.NewId() for _init_coll_FPRIME_Items in range(3)]
[wxID_FPRIMEKALPHAAGKA, wxID_FPRIMEKALPHACOKA, wxID_FPRIMEKALPHACRKA,
wxID_FPRIMEKALPHACUKA, wxID_FPRIMEKALPHAFEKA, wxID_FPRIMEKALPHAMNKA,
wxID_FPRIMEKALPHAMOKA, wxID_FPRIMEKALPHANIKA, wxID_FPRIMEKALPHAZNKA,
wxID_FPRIMEKALPHAGAKA,wxID_FPRIMEKALPHAINKA,
] = [wx.NewId() for _init_coll_KALPHA_Items in range(11)]
[wxID_FPRIMEABOUT] = [wx.NewId() for _init_coll_ABOUT_Items in range(1)]
class Fprime(wx.Frame):
'''Creates a frame where input for absorption calculation is supplied
'''
Elems = []
Wave = 1.5405 #CuKa default
Kev = 12.397639 #keV for 1A x-rays
for arg in sys.argv:
if '-w' in arg:
Wave = float(arg.split('-w')[1])
elif '-e' in arg:
E = float(arg.split('-e')[1])
Wave = Kev/E
elif '-h' in arg:
print( '''
fprime.py can take the following arguments:
-h - this help listing
-wv - set default wavelength to v, e.g. -w1.54 sets wavelength to 1.54A
-ev - set default energy to v, e.g. -e27 sets energy to 27keV
without arguments fprime uses CuKa as default (Wave=1.54052A, E=8.0478keV)
''')
sys.exit()
Wmin = 0.05 #wavelength range
Wmax = 3.0
Wres = 0.004094 #plot resolution step size as const delta-lam/lam - gives 1000 steps for Wmin to Wmax
Eres = 1.5e-4 #typical energy resolution for synchrotron x-ray sources
ffpfignum = 1
fppfignum = 2
Energy = Kev/Wave
ifWave = True
FFxaxis = 'S' #default form factor plot is vs sin(theta)/lambda
def _init_coll_ABOUT_Items(self, parent):
parent.Append(wxID_FPRIMEABOUT, 'About')
self.Bind(wx.EVT_MENU, self.OnABOUTItems0Menu, id=wxID_FPRIMEABOUT)
def _init_coll_menuBar1_Menus(self, parent):
parent.Append(menu=self.FPRIME, title='Fprime')
parent.Append(menu=self.KALPHA, title='Kalpha')
parent.Append(menu=self.ABOUT, title='About')
def _init_coll_KALPHA_Items(self, parent):
"Set of characteristic radiation from sealed tube sources"
parent.Append(wxID_FPRIMEKALPHACRKA,'CrKa')
parent.Append(wxID_FPRIMEKALPHAMNKA,'MnKa')
parent.Append(wxID_FPRIMEKALPHAFEKA,'FeKa')
parent.Append(wxID_FPRIMEKALPHACOKA,'CoKa')
parent.Append(wxID_FPRIMEKALPHANIKA,'NiKa')
parent.Append(wxID_FPRIMEKALPHACUKA,'CuKa')
parent.Append(wxID_FPRIMEKALPHAZNKA,'ZnKa')
parent.Append(wxID_FPRIMEKALPHAGAKA,'GaKa')
parent.Append(wxID_FPRIMEKALPHAMOKA,'MoKa')
parent.Append(wxID_FPRIMEKALPHAAGKA,'AgKa')
parent.Append(wxID_FPRIMEKALPHAINKA,'InKa')
self.Bind(wx.EVT_MENU, self.OnKALPHACrkaMenu, id=wxID_FPRIMEKALPHACRKA)
self.Bind(wx.EVT_MENU, self.OnKALPHAMnkaMenu, id=wxID_FPRIMEKALPHAMNKA)
self.Bind(wx.EVT_MENU, self.OnKALPHAFekaMenu, id=wxID_FPRIMEKALPHAFEKA)
self.Bind(wx.EVT_MENU, self.OnKALPHACokaMenu, id=wxID_FPRIMEKALPHACOKA)
self.Bind(wx.EVT_MENU, self.OnKALPHANikaMenu, id=wxID_FPRIMEKALPHANIKA)
self.Bind(wx.EVT_MENU, self.OnKALPHACukaMenu, id=wxID_FPRIMEKALPHACUKA)
self.Bind(wx.EVT_MENU, self.OnKALPHAZnkaMenu, id=wxID_FPRIMEKALPHAZNKA)
self.Bind(wx.EVT_MENU, self.OnKALPHAGakaMenu, id=wxID_FPRIMEKALPHAGAKA)
self.Bind(wx.EVT_MENU, self.OnKALPHAMokaMenu, id=wxID_FPRIMEKALPHAMOKA)
self.Bind(wx.EVT_MENU, self.OnKALPHAAgkaMenu, id=wxID_FPRIMEKALPHAAGKA)
self.Bind(wx.EVT_MENU, self.OnKALPHAInkaMenu, id=wxID_FPRIMEKALPHAINKA)
def _init_coll_FPRIME_Items(self, parent):
parent.Append(wxID_FPRIMENEW,'&New Element','Add new element')
self.Delete = parent.Append(wxID_FPRIMEDELETE,'&Delete Element','Delete an element')
self.Delete.Enable(False)
parent.Append(wxID_FPRIMEEXIT,'&Exit','Exit Fprime')
self.Bind(wx.EVT_MENU, self.OnFPRIMEExitMenu, id=wxID_FPRIMEEXIT)
self.Bind(wx.EVT_MENU, self.OnFPRIMENewMenu, id=wxID_FPRIMENEW)
self.Bind(wx.EVT_MENU, self.OnFPRIMEDeleteMenu, id=wxID_FPRIMEDELETE)
def _init_utils(self):
self.FPRIME = wx.Menu(title='')
self.KALPHA = wx.Menu(title='')
self.KALPHA.SetEvtHandlerEnabled(True)
self.ABOUT = wx.Menu(title='')
self.menuBar1 = wx.MenuBar()
self._init_coll_FPRIME_Items(self.FPRIME)
self._init_coll_KALPHA_Items(self.KALPHA)
self._init_coll_ABOUT_Items(self.ABOUT)
self._init_coll_menuBar1_Menus(self.menuBar1)
def _init_ctrls(self, parent):
wx.Frame.__init__(self, parent=parent,
size=wx.Size(500, 300),style=wx.DEFAULT_FRAME_STYLE ^ wx.CLOSE_BOX, title='Fprime')
self._init_utils()
self.SetMenuBar(self.menuBar1)
panel = wx.Panel(self)
mainSizer = wx.BoxSizer(wx.VERTICAL)
self.Results = wx.TextCtrl( parent=panel,style=wx.TE_MULTILINE|wx.TE_DONTWRAP )
self.Results.SetEditable(False)
mainSizer.Add(self.Results,1,wx.EXPAND)
mainSizer.Add((10,15),0)
selSizer = wx.BoxSizer(wx.HORIZONTAL)
selSizer.Add((5,10),0)
selSizer.Add(wx.StaticText(parent=panel, label='Wavelength:'),0,wx.EXPAND)
selSizer.Add((5,10),0)
self.SpinText1 = wx.TextCtrl(id=wxID_SPINTEXT1, parent=panel,
size=wx.Size(100,20), value = "%6.4f" % (self.Wave),style=wx.TE_PROCESS_ENTER )
selSizer.Add(self.SpinText1,0)
selSizer.Add((5,10),0)
self.SpinText1.Bind(wx.EVT_TEXT_ENTER, self.OnSpinText1, id=wxID_SPINTEXT1)
selSizer.Add(wx.StaticText(parent=panel, label='Energy:'),0,wx.EXPAND)
selSizer.Add((5,10),0)
self.SpinText2 = wx.TextCtrl(id=wxID_SPINTEXT2, parent=panel,
size=wx.Size(100,20), value = "%7.4f" % (self.Energy),style=wx.TE_PROCESS_ENTER)
selSizer.Add(self.SpinText2,0)
self.SpinText2.Bind(wx.EVT_TEXT_ENTER, self.OnSpinText2, id=wxID_SPINTEXT2)
mainSizer.Add(selSizer,0)
mainSizer.Add((10,10),0)
slideSizer = wx.BoxSizer(wx.HORIZONTAL)
self.SpinButton = wx.SpinButton(id=wxID_SPINBUTTON, parent=panel,
size=wx.Size(25,24), style=wx.SP_VERTICAL | wx.SP_ARROW_KEYS)
slideSizer.Add(self.SpinButton)
self.SpinButton.SetRange(-1,1)
self.SpinButton.SetValue(0)
self.SpinButton.Bind(wx.EVT_SPIN, self.OnSpinButton, id=wxID_SPINBUTTON)
self.slider1 = wx.Slider(id=wxID_FPRIMESLIDER1, maxValue=int(1000.*self.Wmax),
minValue=int(1000.*self.Wmin), parent=panel,style=wx.SL_HORIZONTAL,
value=int(self.Wave*1000.), )
slideSizer.Add(self.slider1,1,wx.EXPAND)
self.slider1.Bind(wx.EVT_SLIDER, self.OnSlider1, id=wxID_FPRIMESLIDER1)
mainSizer.Add(slideSizer,0,wx.EXPAND)
mainSizer.Add((10,10),0)
choiceSizer = wx.BoxSizer(wx.HORIZONTAL)
choiceSizer.Add((5,10),0)
choiceSizer.Add(wx.StaticText(parent=panel, label='Plot scales:'),0,wx.EXPAND)
choiceSizer.Add((5,10),0)
self.choice1 = wx.ComboBox(id=wxID_FPRIMECHOICE1, parent=panel, value='Wavelength',
choices=['Wavelength','Energy'],style=wx.CB_READONLY|wx.CB_DROPDOWN)
choiceSizer.Add(self.choice1,0)
choiceSizer.Add((10,10),0)
self.choice1.Bind(wx.EVT_COMBOBOX, self.OnChoice1, id=wxID_FPRIMECHOICE1)
def OnChoice2(event):
if event.GetString() == ' sin('+Gktheta+')/'+Gklambda:
self.FFxaxis = 'S'
elif event.GetString() == ' Q':
self.FFxaxis = 'Q'
else:
self.FFxaxis = 'T'
self.UpDateFPlot(self.Wave,rePlot=False)
self.choice2 = wx.ComboBox(id=wxID_FPRIMECHOICE2, value=' sin('+Gktheta+')/'+Gklambda,
choices=[' sin('+Gktheta+')/'+Gklambda,' 2'+Gktheta,' Q'],
parent=panel, style=wx.CB_READONLY|wx.CB_DROPDOWN)
choiceSizer.Add(self.choice2,0)
self.choice2.Bind(wx.EVT_COMBOBOX, OnChoice2, id=wxID_FPRIMECHOICE2)
mainSizer.Add(choiceSizer,0)
mainSizer.Add((10,10),0)
panel.SetSizer(mainSizer)
def __init__(self, parent):
self._init_ctrls(parent)
self.parent = parent
self.Lines = []
self.Elems = []
self.linePicked = None
def OnFPRIMEExitMenu(self, event):
self.parent.G2plotNB.Delete('Fprime')
self.Close()
self.Destroy()
def OnFPRIMENewMenu(self, event):
ElList = []
for Elem in self.Elems: ElList.append(Elem[0])
PE = G2elemGUI.PickElements(self,ElList)
if PE.ShowModal() == wx.ID_OK:
Elems = PE.Elem
else:
return
# PE.Destroy()
if Elems:
for El in Elems:
ElemSym = El.strip().upper()
if ElemSym not in ElList:
FormFactors = G2elem.GetFormFactorCoeff(ElemSym)
for FormFac in FormFactors:
FormSym = FormFac['Symbol'].strip()
if FormSym == ElemSym:
Z = FormFac['Z'] #At. No.
Orbs = G2elem.GetXsectionCoeff(ElemSym)
Elem = (ElemSym,Z,FormFac,Orbs)
self.Elems.append(Elem)
self.Delete.Enable(True)
self.CalcFPPS()
self.SetWaveEnergy(self.Wave)
def OnFPRIMEDeleteMenu(self, event):
if len(self.Elems):
ElList = []
for Elem in self.Elems: ElList.append(Elem[0])
S = []
DE = G2elemGUI.DeleteElement(self,ElList)
if DE.ShowModal() == wx.ID_OK:
El = DE.GetDeleteElement().strip().upper()
for Elem in self.Elems:
if Elem[0] != El:
S.append(Elem)
self.Elems = S
self.CalcFPPS()
if not self.Elems:
self.Delete.Enable(False)
self.SetWaveEnergy(self.Wave)
def OnKALPHACrkaMenu(self, event):
self.SetWaveEnergy(2.28962)
def OnKALPHAMnkaMenu(self, event):
self.SetWaveEnergy(2.10174)
def OnKALPHAFekaMenu(self, event):
self.SetWaveEnergy(1.93597)
def OnKALPHACokaMenu(self, event):
self.SetWaveEnergy(1.78896)
def OnKALPHANikaMenu(self, event):
self.SetWaveEnergy(1.65784)
def OnKALPHACukaMenu(self, event):
self.SetWaveEnergy(1.54052)
def OnKALPHAZnkaMenu(self, event):
self.SetWaveEnergy(1.43510)
def OnKALPHAGakaMenu(self, event):
self.SetWaveEnergy(1.34134)
def OnKALPHAMokaMenu(self, event):
self.SetWaveEnergy(0.70926)
def OnKALPHAAgkaMenu(self, event):
self.SetWaveEnergy(0.55936)
def OnKALPHAInkaMenu(self, event):
self.SetWaveEnergy(0.51357)
def OnSpinText1(self, event):
self.SetWaveEnergy(float(self.SpinText1.GetValue()))
def OnSpinText2(self, event):
self.SetWaveEnergy(self.Kev/(float(self.SpinText2.GetValue())))
def OnSpinButton(self, event):
move = self.SpinButton.GetValue()/10000.
self.Wave = min(max(self.Wave+move,self.Wmin),self.Wmax)
self.SpinButton.SetValue(0)
self.SetWaveEnergy(self.Wave)
def OnSlider1(self, event):
if self.ifWave:
Wave = float(self.slider1.GetValue())/1000.
else:
Wave = self.Kev/(float(self.slider1.GetValue())/1000.)
self.SetWaveEnergy(Wave)
def OnKeyPress(self,event):
if event.key == 'g':
mpl.rcParams['axes.grid'] = not mpl.rcParams['axes.grid']
self.SetWaveEnergy(self.Wave)
def UpDateFPlot(self,Wave,rePlot=True):
"""Plot f' & f" vs wavelength 0.05-3.0A"""
"generate a set of form factor curves & plot them vs sin-theta/lambda or q or 2-theta"
self.axylim = []
self.bxylim = []
try:
if rePlot:
self.axylim = self.ax.get_xlim(),self.ax.get_ylim()
self.bxylim = self.bx.get_xlim(),self.bx.get_ylim()
newPlot = False
except:
new,plotNum,self.Page,self.fplot,lim = self.parent.G2plotNB.FindPlotTab('Fprime','mpl')
self.Page.canvas.mpl_connect('pick_event', self.OnPick)
self.Page.canvas.mpl_connect('button_release_event', self.OnRelease)
self.Page.canvas.mpl_connect('motion_notify_event', self.OnMotion)
self.Page.canvas.mpl_connect('key_press_event', self.OnKeyPress)
newPlot = True
self.ax,self.bx = self.Page.figure.subplots(1,2)
self.Page.Choice = (' key press','g: toggle grid',)
self.Page.keyPress = self.OnKeyPress
self.fplot.set_visible(False)
self.ax.cla()
self.bx.cla()
self.ax.set_title('Resonant Scattering Factors',x=0,ha='left')
self.ax.set_ylabel("f ',"+' f ", e-',fontsize=14)
Ymin = 0.0
Ymax = 0.0
colors=['r','b','g','c','m','k']
if self.FPPS:
for i,Fpps in enumerate(self.FPPS):
Color = colors[i%6]
Ymin = min(Ymin,min(Fpps[2]),min(Fpps[3]))
Ymax = max(Ymax,max(Fpps[2]),max(Fpps[3]))
fppsP1 = np.array(Fpps[1])
fppsP2 = np.array(Fpps[2])
fppsP3 = np.array(Fpps[3])
self.ax.plot(fppsP1,fppsP2,Color,label=Fpps[0]+" f '")
self.ax.plot(fppsP1,fppsP3,Color,linestyle='dashed',label=Fpps[0]+' f "')
if self.ifWave:
self.ax.set_xlabel(r'$\mathsf{\lambda, \AA}$',fontsize=14)
self.ax.axvline(x=Wave,picker=3,color='black')
else:
self.ax.set_xlabel(r'$\mathsf{E, keV}$',fontsize=14)
self.ax.set_xscale('log')
self.ax.axvline(x=self.Kev/Wave,picker=3,color='black')
self.ax.set_ylim(Ymin,Ymax)
if self.FPPS:
self.ax.legend(loc='best')
self.Page.figure.subplots_adjust(hspace=0.25)
if self.ifWave:
self.bx.set_title('%s%s%6.4f%s'%('Form factors (',r'$\lambda=$',self.Wave,r'$\AA)$'),x=0,ha='left')
else:
self.bx.set_title('%s%6.2f%s'%('Form factors (E =',self.Energy,'keV)'),x=0,ha='left')
if self.FFxaxis == 'S':
self.bxlabel = 'sin('+Gktheta+')/'+Gklambda
self.bx.set_xlabel(r'$\mathsf{sin(\theta)/\lambda}$',fontsize=14)
elif self.FFxaxis == 'T':
self.bxlabel = '2'+Gktheta
self.bx.set_xlabel(r'$\mathsf{2\theta}$',fontsize=14)
else:
self.bxlabel = 'Q, '+Angstr+Pwrm1
self.bx.set_xlabel(r'$Q, \AA$',fontsize=14)
self.bx.set_ylabel("f+f ', e-",fontsize=14)
E = self.Energy
DE = E*self.Eres #smear by defined source resolution
StlMax = min(2.0,math.sin(80.0*math.pi/180.)/Wave)
Stl = np.arange(0.,StlMax,.01)
Ymax = 0.0
for i,Elem in enumerate(self.Elems):
Els = Elem[0]
Els = Els = Els.ljust(2).lower().capitalize()
Ymax = max(Ymax,Elem[1])
res1 = G2elem.FPcalc(Elem[3],E+DE)
res2 = G2elem.FPcalc(Elem[3],E-DE)
res = (res1[0]+res2[0])/2.0
if Elem[1] > 78 and self.Energy > self.Kev/0.16: res = 0.0
if Elem[1] > 94 and self.Energy < self.Kev/2.67: res = 0.0
Els = Elem[0]
Els = Els.ljust(2).lower().capitalize()
X = []
ff = []
ffo = []
for S in Stl:
ff.append(G2elem.ScatFac(Elem[2],S*S)+res)
ffo.append(G2elem.ScatFac(Elem[2],S*S))
if self.FFxaxis == 'S':
X.append(S)
elif self.FFxaxis == 'T':
X.append(360.0*math.asin(S*self.Wave)/math.pi)
else:
X.append(4.0*S*math.pi)
Color = colors[i%6]
Xp = np.array(X)
ffop = np.array(ffo)
ffp = np.array(ff)
self.bx.plot(Xp,ffop,Color,linestyle='dashed',label=Els+" f")
self.bx.plot(Xp,ffp,Color,label=Els+" f+f'")
if self.Elems:
self.bx.legend(loc='best')
self.bx.set_ylim(0.0,Ymax+1.0)
if newPlot:
newPlot = False
self.Page.canvas.draw()
else:
if rePlot:
tb = self.Page.canvas.toolbar
tb.push_current()
self.ax.set_xlim(self.axylim[0])
self.ax.set_ylim(self.axylim[1])
self.axylim = []
tb.push_current()
self.bx.set_xlim(self.bxylim[0])
self.bx.set_ylim(self.bxylim[1])
self.bxylim = []
tb.push_current()
self.Page.canvas.draw()
def OnPick(self, event):
self.linePicked = event.artist
def OnMotion(self,event):
xpos = event.xdata
if xpos and xpos>0.1:
ypos = event.ydata
if self.ifWave:
Wave = xpos
else:
Wave = self.Kev/xpos
Wave = min(max(Wave,self.Wmin),self.Wmax)
if event.inaxes == self.ax:
self.parent.G2plotNB.status.SetStatusText("Wavelength: %.4f, Energy: %.3f, f'%s: %.3f"%(Wave,self.Kev/Wave,'f"',ypos),1)
elif event.inaxes == self.bx:
self.parent.G2plotNB.status.SetStatusText("%s: %.4f, f,f+f': %.3f"%(self.bxlabel,xpos,ypos),1)
if self.linePicked:
self.SetWaveEnergy(Wave)
def OnRelease(self, event):
if self.linePicked is None: return
self.linePicked = None
xpos = event.xdata
if xpos:
if self.ifWave:
Wave = xpos
else:
Wave = self.Kev/xpos
self.SetWaveEnergy(Wave)
def SetWaveEnergy(self,Wave):
self.Wave = Wave
self.Energy = self.Kev/self.Wave
self.Energy = round(self.Energy,4)
E = self.Energy
DE = E*self.Eres #smear by defined source resolution
self.SpinText1.SetValue("%6.4f" % (self.Wave))
self.SpinText2.SetValue("%7.4f" % (self.Energy))
self.SpinText1.Update()
self.SpinText2.Update()
if self.ifWave:
self.slider1.SetValue(int(1000.*self.Wave))
else:
self.slider1.SetValue(int(1000.*self.Energy))
Text = ''
for Elem in self.Elems:
r1 = G2elem.FPcalc(Elem[3],E+DE)
r2 = G2elem.FPcalc(Elem[3],E-DE)
Els = Elem[0]
Els = Els.ljust(2).lower().capitalize()
if Elem[1] > 78 and self.Energy+DE > self.Kev/0.16:
Text += "%s\t%s%6s\t%s%6.3f \t%s%10.2f %s\n" % (
'Element= '+str(Els)," f'=",'not valid',
' f"=',(r1[1]+r2[1])/2.0,' '+Gkmu+'=',(r1[2]+r2[2])/2.0,'barns/atom')
elif Elem[1] > 94 and self.Energy-DE < self.Kev/2.67:
Text += "%s\t%s%6s\t%s%6s\t%s%10s%s\n" % (
'Element= '+str(Els)," f'=",'not valid',
' f"=','not valid',' '+Gkmu+'=','not valid')
else:
Text += "%s\t%s%6.3f \t%s%6.3f \t%s%10.2f %s\n" % (
'Element= '+str(Els)," f'=",(r1[0]+r2[0])/2.0,
' f"=',(r1[1]+r2[1])/2.0,' '+Gkmu+'=',(r1[2]+r2[2])/2.0,'barns/atom')
if len(self.Elems):
self.Results.SetValue(Text)
self.Results.Update()
self.UpDateFPlot(Wave)
def CalcFPPS(self):
"""generate set of f' & f" curves for selected elements
does constant delta-lambda/lambda steps over defined range
"""
FPPS = []
if self.Elems:
wx.BeginBusyCursor()
try:
for Elem in self.Elems:
Els = Elem[0]
Els = Els = Els.ljust(2).lower().capitalize()
Wmin = self.Wmin
Wmax = self.Wmax
Z = Elem[1]
if Z > 78: Wmin = 0.16 #heavy element high energy failure of Cromer-Liberman
if Z > 94: Wmax = 2.67 #heavy element low energy failure of Cromer-Liberman
lWmin = math.log(Wmin)
N = int(round(math.log(Wmax/Wmin)/self.Wres)) #number of constant delta-lam/lam steps
I = range(N+1)
Ws = []
for i in I: Ws.append(math.exp(i*self.Wres+lWmin))
fps = []
fpps = []
Es = []
for W in Ws:
E = self.Kev/W
DE = E*self.Eres #smear by defined source resolution
res1 = G2elem.FPcalc(Elem[3],E+DE)
res2 = G2elem.FPcalc(Elem[3],E-DE)
fps.append((res1[0]+res2[0])/2.0)
fpps.append((res1[1]+res2[1])/2.0)
Es.append(E)
if self.ifWave:
Fpps = (Els,Ws,fps,fpps)
else:
Fpps = (Els,Es,fps,fpps)
FPPS.append(Fpps)
finally:
wx.EndBusyCursor()
self.FPPS = FPPS
def OnChoice1(self, event):
if event.GetString() == "Wavelength":
self.ifWave = True
self.NewFPPlot = True
self.Wave = round(self.Wave,4)
self.slider1.SetRange(int(1000.*self.Wmin),int(1000.*self.Wmax))
self.slider1.SetValue(int(1000.*self.Wave))
self.SpinText1.SetValue("%6.4f" % (self.Wave))
self.SpinText2.SetValue("%7.4f" % (self.Energy))
else:
self.ifWave = False
self.NewFPPlot = True
Emin = self.Kev/self.Wmax
Emax = self.Kev/self.Wmin
self.Energy = round(self.Energy,4)
self.slider1.SetRange(int(1000.*Emin),int(1000.*Emax))
self.slider1.SetValue(int(1000.*self.Energy))
self.SpinText1.SetValue("%6.4f" % (self.Wave))
self.SpinText2.SetValue("%7.4f" % (self.Energy))
self.CalcFPPS()
self.UpDateFPlot(self.Wave,rePlot=False)
def OnABOUTItems0Menu(self, event):
'''Displays the About window
'''
try:
import wx.adv as wxadv # AboutBox moved here in Phoenix
except:
wxadv = wx
info = wxadv.AboutDialogInfo()
info.Name = 'pyFprime'
info.Copyright = '''
Robert B. Von Dreele, 2008(C)
Argonne National Laboratory
This product includes software developed
by the UChicago Argonne, LLC, as
Operator of Argonne National Laboratory. '''
info.Description = '''
For calculating real and resonant X-ray scattering factors to 250keV;
based on Fortran program of Cromer & Liberman corrected for
Kissel & Pratt energy term; Jensen term not included
(D. T. Cromer and D. A. Liberman, Acta Cryst. (1981). A37, 267-268.)
'''
wxadv.AboutBox(info)
if __name__ == "__main__":
import GSASIIplot as G2plt
app = wx.App()
GSASIIpath.InvokeDebugOpts()
frm = wx.Frame(None) # create a frame
frm.Show(False)
size = wx.Size(700,700)
frm.plotFrame = wx.Frame(frm,-1,'GSASII Plots',size=size,
style=wx.DEFAULT_FRAME_STYLE ^ wx.CLOSE_BOX)
frm.plotFrame.Show()
frm.G2plotNB = G2plt.G2PlotNoteBook(frm.plotFrame,G2frame=frm)
win = Fprime(frm)
win.Show()
win.Bind(wx.EVT_WINDOW_DESTROY,lambda event: sys.exit())
app.MainLoop()