1 | # -*- coding: utf-8 -*- |
---|
2 | #testXNFF.py |
---|
3 | ''' |
---|
4 | *testXNFF: Check x-ray & neutron form factor computation* |
---|
5 | ========================================= |
---|
6 | |
---|
7 | Use this to check form factors used in neutron scattering |
---|
8 | |
---|
9 | ''' |
---|
10 | |
---|
11 | import sys |
---|
12 | import wx |
---|
13 | import numpy as np |
---|
14 | import GSASIIpath |
---|
15 | GSASIIpath.SetBinaryPath() |
---|
16 | import GSASIItestplot as plot |
---|
17 | import GSASIIElem as G2el |
---|
18 | import GSASIIElemGUI as G2elG |
---|
19 | import atmdata |
---|
20 | WACV = wx.ALIGN_CENTER_VERTICAL |
---|
21 | |
---|
22 | try: |
---|
23 | wx.NewIdRef |
---|
24 | wx.NewId = wx.NewIdRef |
---|
25 | except AttributeError: |
---|
26 | pass |
---|
27 | |
---|
28 | def create(parent): |
---|
29 | return testXNFF(parent) |
---|
30 | |
---|
31 | [wxID_FILEEXIT, wxID_PICKELEM, |
---|
32 | ] = [wx.NewId() for _init_coll_File_Items in range(2)] |
---|
33 | |
---|
34 | class testXNFF(wx.Frame): |
---|
35 | def _init_ctrls(self, parent): |
---|
36 | wx.Frame.__init__(self, name='testXNFF', parent=parent, |
---|
37 | size=wx.Size(460, 250),style=wx.DEFAULT_FRAME_STYLE, title='Test Xray & Neutron Form Factors') |
---|
38 | self.testFFMenu = wx.MenuBar() |
---|
39 | self.File = wx.Menu(title='') |
---|
40 | self.File.Append(wxID_PICKELEM,'Pick element','Pick element') |
---|
41 | self.File.Append(wxID_FILEEXIT,'Exit','Exit from testXNFF') |
---|
42 | self.Bind(wx.EVT_MENU,self.OnPickElement,id=wxID_PICKELEM) |
---|
43 | self.Bind(wx.EVT_MENU, self.OnFileExit, id=wxID_FILEEXIT) |
---|
44 | self.testFFMenu.Append(menu=self.File, title='File') |
---|
45 | self.SetMenuBar(self.testFFMenu) |
---|
46 | self.testFFPanel = wx.ScrolledWindow(self) |
---|
47 | self.plotNB = plot.PlotNotebook() |
---|
48 | |
---|
49 | def __init__(self, parent): |
---|
50 | self._init_ctrls(parent) |
---|
51 | self.Bind(wx.EVT_CLOSE, self.ExitMain) |
---|
52 | |
---|
53 | def ExitMain(self, event): |
---|
54 | sys.exit() |
---|
55 | |
---|
56 | def OnFileExit(self,event): |
---|
57 | self.Close() |
---|
58 | |
---|
59 | def OnPickElement(self,Parms): |
---|
60 | |
---|
61 | PE = G2elG.PickElement(self.testFFPanel,oneOnly=True) |
---|
62 | if PE.ShowModal() == wx.ID_OK: |
---|
63 | self.xrayFFs = G2el.GetFormFactorCoeff(PE.Elem) |
---|
64 | self.Elem = PE.Elem |
---|
65 | self.atmInfo = G2el.GetAtomInfo(PE.Elem) |
---|
66 | self.magFFs = G2el.GetMagFormFacCoeff(PE.Elem) |
---|
67 | PE.Destroy() |
---|
68 | self.MakePlot() |
---|
69 | |
---|
70 | def MakePlot(self): |
---|
71 | |
---|
72 | def test1(): |
---|
73 | fplot = self.plotNB.add('Neutron scattering lengths').gca() |
---|
74 | lams = np.linspace(0.3,10.0,1000,True) |
---|
75 | |
---|
76 | BLtable = {} |
---|
77 | El = self.Elem.capitalize() |
---|
78 | for isotope in self.atmInfo['Isotopes']: |
---|
79 | if 'Nat' in isotope: |
---|
80 | BLtable[isotope] = ['',atmdata.AtmBlens[El+'_']] |
---|
81 | else: |
---|
82 | BLtable[isotope] = ['',atmdata.AtmBlens[El+'_'+isotope]] |
---|
83 | for isotope in BLtable: |
---|
84 | if 'BW-LS' in BLtable[isotope][1]: |
---|
85 | b0 = np.ones_like(lams)*BLtable[isotope][1]['BW-LS'][0] |
---|
86 | else: |
---|
87 | b0 = np.ones_like(lams)*BLtable[isotope][1]['SL'][0] |
---|
88 | bp,bpp = G2el.BlenResTOF([isotope,],BLtable,lams) |
---|
89 | fplot.plot(lams,b0,label=isotope+El+' b0') |
---|
90 | fplot.plot(lams,bp[0],label=isotope+El+" b'") |
---|
91 | fplot.plot(lams,bpp[0],label=isotope+El+' b"') |
---|
92 | |
---|
93 | fplot.legend(loc='best') |
---|
94 | fplot.set_xlabel('wavelength, A') |
---|
95 | fplot.set_ylabel('b') |
---|
96 | |
---|
97 | def test2(): |
---|
98 | fplot = self.plotNB.add('X-ray form factors').gca() |
---|
99 | sq = np.linspace(0,2.,1000,True) |
---|
100 | for El in self.xrayFFs: |
---|
101 | F = G2el.ScatFac(El, sq**2) |
---|
102 | fplot.plot(sq,F,label=El['Symbol']) |
---|
103 | fplot.legend(loc='best') |
---|
104 | fplot.set_xlabel('sin-theta/lambda') |
---|
105 | fplot.set_ylabel('form factor') |
---|
106 | |
---|
107 | def test3(): |
---|
108 | fplot = self.plotNB.add('magnetic form factors').gca() |
---|
109 | sq = np.linspace(0,1.,1000,True) |
---|
110 | for El in self.magFFs: |
---|
111 | El['gfac'] = 2.0 |
---|
112 | F = G2el.MagScatFac(El, sq**2) |
---|
113 | fplot.plot(sq,F,label=El['Symbol']) |
---|
114 | fplot.legend(loc='best') |
---|
115 | fplot.set_xlabel('sin-theta/lambda') |
---|
116 | fplot.set_ylabel('form factor') |
---|
117 | |
---|
118 | while self.plotNB.nb.GetPageCount(): |
---|
119 | self.plotNB.nb.DeletePage(0) |
---|
120 | test1() |
---|
121 | test2() |
---|
122 | test3() |
---|
123 | |
---|
124 | self.plotNB.Show() |
---|
125 | |
---|
126 | class testFFmain(wx.App): |
---|
127 | def OnInit(self): |
---|
128 | self.main = testXNFF(None) |
---|
129 | self.main.Show() |
---|
130 | self.SetTopWindow(self.main) |
---|
131 | return True |
---|
132 | |
---|
133 | def main(): |
---|
134 | 'Starts main application to compute and plot form factors' |
---|
135 | application = testFFmain(0) |
---|
136 | application.MainLoop() |
---|
137 | |
---|
138 | if __name__ == '__main__': |
---|
139 | GSASIIpath.InvokeDebugOpts() |
---|
140 | main() |
---|