source: trunk/PlotXNFF.py @ 5370

Last change on this file since 5370 was 5307, checked in by vondreele, 3 years 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

File size: 4.8 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
22try:
23    wx.NewIdRef
24    wx.NewId = wx.NewIdRef
25except AttributeError:
26    pass
27
28[wxID_FILEEXIT, wxID_PICKELEM,
29] = [wx.NewId() for _init_coll_File_Items in range(2)]
30
31class PlotXNFF(wx.Frame):
32   
33    def _init_ctrls(self, parent):
34        wx.Frame.__init__(self, name='PlotXNFF', parent=parent,
35            size=wx.Size(460, 250),style=wx.DEFAULT_FRAME_STYLE, title='Plot Xray, Neutron & Magnetic Form Factors')
36        self.PlotFFMenu = wx.MenuBar()
37        self.File = wx.Menu(title='')
38        self.File.Append(wxID_PICKELEM,'Pick element','Pick element')
39        self.File.Append(wxID_FILEEXIT,'Exit','Exit from PlotXNFF')
40        self.Bind(wx.EVT_MENU,self.OnPickElement,id=wxID_PICKELEM)
41        self.Bind(wx.EVT_MENU, self.OnFileExit, id=wxID_FILEEXIT)
42        self.PlotFFMenu.Append(menu=self.File, title='File')
43        self.SetMenuBar(self.PlotFFMenu)
44        self.PlotFFPanel = wx.ScrolledWindow(self)       
45        self.plotNB = plot.PlotNotebook()
46       
47    def __init__(self, parent):
48        self._init_ctrls(parent)
49        self.Bind(wx.EVT_CLOSE, self.ExitMain)
50
51    def ExitMain(self, event):
52        sys.exit()
53       
54    def OnFileExit(self,event):
55        self.Close()
56
57    def OnPickElement(self,Parms):
58
59        PE = G2elG.PickElement(self.PlotFFPanel,oneOnly=True)
60        if PE.ShowModal() == wx.ID_OK:
61            self.xrayFFs = G2el.GetFormFactorCoeff(PE.Elem)
62            self.elecFFs = G2el.GetEFormFactorCoeff(PE.Elem)
63            self.Elem = PE.Elem
64            self.atmInfo = G2el.GetAtomInfo(PE.Elem)
65            self.magFFs = G2el.GetMagFormFacCoeff(PE.Elem)
66        PE.Destroy()
67        self.MakePlot()
68
69    def MakePlot(self):
70       
71        def test1():
72            fplot = self.plotNB.add('Neutron scattering lengths').gca()
73            lams = np.linspace(0.3,10.0,1000,True)
74           
75            BLtable = {}
76            El = self.Elem.capitalize()
77            for isotope in self.atmInfo['Isotopes']:
78                if 'Nat' in isotope:
79                    BLtable[isotope] = ['',atmdata.AtmBlens[El+'_']]
80                else:
81                    BLtable[isotope] = ['',atmdata.AtmBlens[El+'_'+isotope]]
82            for isotope in BLtable:
83                if 'BW-LS' in BLtable[isotope][1]:
84                    b0 = np.ones_like(lams)*BLtable[isotope][1]['BW-LS'][0]                   
85                else:
86                    b0 = np.ones_like(lams)*BLtable[isotope][1]['SL'][0]
87                bp,bpp = G2el.BlenResTOF([isotope,],BLtable,lams)
88                fplot.plot(lams,b0,label=isotope+El+' b0')
89                fplot.plot(lams,bp[0],label=isotope+El+" b'")
90                fplot.plot(lams,bpp[0],label=isotope+El+' b"')
91               
92            fplot.legend(loc='best')
93            fplot.set_xlabel('wavelength, A')
94            fplot.set_ylabel('b')
95
96        def test2():
97            fplot = self.plotNB.add('X-ray form factors').gca()
98            sq = np.linspace(0,2.,1000,True)
99            for El in self.xrayFFs:
100                F = G2el.ScatFac(El, sq**2)
101                fplot.plot(sq,F,label=El['Symbol'])
102            fplot.legend(loc='best')
103            fplot.set_xlabel('sin-theta/lambda')
104            fplot.set_ylabel('form factor')
105           
106        def test3():
107            fplot = self.plotNB.add('Electron form factor').gca()
108            sq = np.linspace(0,2.,1000,True)
109            for El in self.elecFFs:
110                F = G2el.ScatFac(El, sq**2)
111                fplot.plot(sq,F,label=El['Symbol'])
112            fplot.legend(loc='best')
113            fplot.set_xlabel('sin-theta/lambda')
114            fplot.set_ylabel('form factor')
115           
116        def test4():
117            fplot = self.plotNB.add('magnetic form factors').gca()
118            sq = np.linspace(0,1.,1000,True)
119            for El in self.magFFs:
120                El['gfac'] = 2.0
121                F = G2el.MagScatFac(El, sq**2)
122                fplot.plot(sq,F,label=El['Symbol'])
123            fplot.legend(loc='best')
124            fplot.set_xlabel('sin-theta/lambda')
125            fplot.set_ylabel('form factor')
126           
127        while self.plotNB.nb.GetPageCount():
128            self.plotNB.nb.DeletePage(0)
129        test1()
130        test2()
131        test3()
132        if len(self.magFFs):
133            test4()
134       
135        self.plotNB.Show()
136       
Note: See TracBrowser for help on using the repository browser.