source: trunk/testXNFF.py @ 3806

Last change on this file since 3806 was 3521, checked in by vondreele, 7 years ago

fix In neutron scattering length info
add MAXMAGN.py
minor changes to testXNFF & GSASIItestplot.py
work on transform some more

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