source: trunk/testXNFF.py

Last change on this file was 5307, checked in by vondreele, 3 months ago

add micro-ED support. New electron scattering tables, new histogram type ('SEC'), etc., etc.
Fix sign of ZERO for RMCProfile MakeInst? fxn.
Add calc of Rvalues to Error Analysis for PWDR & HKLF histograms; results are printed om console.
Add a stub for Cluster analysis in Controls GUI

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 5.0 KB
Line 
1# -*- coding: utf-8 -*-
2#testXNFF.py
3'''
4*testXNFF: Check x-ray, electron & 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
22try:
23    wx.NewIdRef
24    wx.NewId = wx.NewIdRef
25except AttributeError:
26    pass
27
28def create(parent):
29    return testXNFF(parent)
30   
31[wxID_FILEEXIT, wxID_PICKELEM,
32] = [wx.NewId() for _init_coll_File_Items in range(2)]
33
34class 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.elecFFs = G2el.GetEFormFactorCoeff(PE.Elem)
65            self.Elem = PE.Elem
66            self.atmInfo = G2el.GetAtomInfo(PE.Elem)
67            self.magFFs = G2el.GetMagFormFacCoeff(PE.Elem)
68        PE.Destroy()
69        self.MakePlot()
70
71    def MakePlot(self):
72       
73        def test1():
74            fplot = self.plotNB.add('Neutron scattering lengths').gca()
75            lams = np.linspace(0.3,10.0,1000,True)
76           
77            BLtable = {}
78            El = self.Elem.capitalize()
79            for isotope in self.atmInfo['Isotopes']:
80                if 'Nat' in isotope:
81                    BLtable[isotope] = ['',atmdata.AtmBlens[El+'_']]
82                else:
83                    BLtable[isotope] = ['',atmdata.AtmBlens[El+'_'+isotope]]
84            for isotope in BLtable:
85                if 'BW-LS' in BLtable[isotope][1]:
86                    b0 = np.ones_like(lams)*BLtable[isotope][1]['BW-LS'][0]                   
87                else:
88                    b0 = np.ones_like(lams)*BLtable[isotope][1]['SL'][0]
89                bp,bpp = G2el.BlenResTOF([isotope,],BLtable,lams)
90                fplot.plot(lams,b0,label=isotope+El+' b0')
91                fplot.plot(lams,bp[0],label=isotope+El+" b'")
92                fplot.plot(lams,bpp[0],label=isotope+El+' b"')
93               
94            fplot.legend(loc='best')
95            fplot.set_xlabel('wavelength, A')
96            fplot.set_ylabel('b')
97
98        def test2():
99            fplot = self.plotNB.add('X-ray form factors').gca()
100            sq = np.linspace(0,2.,1000,True)
101            for El in self.xrayFFs:
102                F = G2el.ScatFac(El, sq**2)
103                fplot.plot(sq,F,label=El['Symbol'])
104            fplot.legend(loc='best')
105            fplot.set_xlabel('sin-theta/lambda')
106            fplot.set_ylabel('form factor')
107           
108        def test3():
109            fplot = self.plotNB.add('Electron form factor').gca()
110            sq = np.linspace(0,2.,1000,True)
111            for El in self.elecFFs:
112                F = G2el.ScatFac(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        def test4():
119            fplot = self.plotNB.add('magnetic form factors').gca()
120            sq = np.linspace(0,1.,1000,True)
121            for El in self.magFFs:
122                El['gfac'] = 2.0
123                F = G2el.MagScatFac(El, sq**2)
124                fplot.plot(sq,F,label=El['Symbol'])
125            fplot.legend(loc='best')
126            fplot.set_xlabel('sin-theta/lambda')
127            fplot.set_ylabel('form factor')
128           
129        while self.plotNB.nb.GetPageCount():
130            self.plotNB.nb.DeletePage(0)
131        test1()
132        test2()
133        test3()
134        test4()
135       
136        self.plotNB.Show()
137       
138class testFFmain(wx.App):
139    def OnInit(self):
140        self.main = testXNFF(None)
141        self.main.Show()
142        self.SetTopWindow(self.main)
143        return True
144
145def main():
146    'Starts main application to compute and plot form factors'
147    application = testFFmain(0)
148    application.MainLoop()
149   
150if __name__ == '__main__':
151    GSASIIpath.InvokeDebugOpts()
152    main()
Note: See TracBrowser for help on using the repository browser.