1 | #testMagSym |
---|
2 | import sys |
---|
3 | import wx |
---|
4 | import numpy as np |
---|
5 | import GSASIIpath |
---|
6 | GSASIIpath.SetBinaryPath() |
---|
7 | import GSASIIspc as G2spc |
---|
8 | import GSASIIctrlGUI as G2G |
---|
9 | import GSASIIphsGUI as G2phsGUI |
---|
10 | |
---|
11 | try: |
---|
12 | wx.NewId |
---|
13 | except AttributeError: |
---|
14 | wx.NewId = wx.NewIdRef |
---|
15 | |
---|
16 | [wxID_FILEEXIT, |
---|
17 | ] = [wx.NewId() for _init_coll_File_Items in range(1)] |
---|
18 | WACV = wx.ALIGN_CENTER_VERTICAL |
---|
19 | |
---|
20 | class testSytSym(wx.Frame): |
---|
21 | |
---|
22 | def _init_ctrls(self, parent): |
---|
23 | wx.Frame.__init__(self, name='testSytSym', parent=parent, |
---|
24 | size=[800,300],style=wx.DEFAULT_FRAME_STYLE, title='Test space group site symmetry') |
---|
25 | self.testSSMenu = wx.MenuBar() |
---|
26 | self.File = wx.Menu(title='') |
---|
27 | self.File.Append(wxID_FILEEXIT,'Exit') |
---|
28 | self.Bind(wx.EVT_MENU, self.OnFileExit, id=wxID_FILEEXIT) |
---|
29 | self.testSSMenu.Append(menu=self.File, title='Run') |
---|
30 | self.SetMenuBar(self.testSSMenu) |
---|
31 | self.testSSPanel = wx.Window(self) |
---|
32 | |
---|
33 | def __init__(self, parent): |
---|
34 | self._init_ctrls(parent) |
---|
35 | self.Bind(wx.EVT_CLOSE, self.ExitMain) |
---|
36 | self.dataFrame = None |
---|
37 | Data = {'SGData':G2spc.SpcGroup('P 1')[1],} |
---|
38 | self.propVec = '0,0,0' |
---|
39 | self.XYZ = '0,0,0' |
---|
40 | self.UpdateData(Data) |
---|
41 | |
---|
42 | def ExitMain(self, event): |
---|
43 | sys.exit() |
---|
44 | |
---|
45 | def OnFileExit(self,event): |
---|
46 | if self.dataFrame: |
---|
47 | self.dataFrame.Clear() |
---|
48 | self.dataFrame.Destroy() |
---|
49 | self.Close() |
---|
50 | |
---|
51 | def UpdateData(self,Data): |
---|
52 | |
---|
53 | def OnSpaceGroup(event): |
---|
54 | SpGrp = 'P 1' |
---|
55 | SpcGp = G2phsGUI.GetSpGrpfromUser(self,SpGrp) |
---|
56 | SGErr,SGData = G2spc.SpcGroup(SpcGp) |
---|
57 | if SGErr: |
---|
58 | text = [G2spc.SGErrors(SGErr)+'\nSpace Group set to previous'] |
---|
59 | SGTxt.SetLabel(Data['SGData']['SpGrp']) |
---|
60 | msg = 'Space Group Error' |
---|
61 | Style = wx.ICON_EXCLAMATION |
---|
62 | Text = '\n'.join(text) |
---|
63 | wx.MessageBox(Text,caption=msg,style=Style) |
---|
64 | else: |
---|
65 | text,table = G2spc.SGPrint(SGData,AddInv=True) |
---|
66 | Data['SGData'] = SGData |
---|
67 | SGTxt.SetLabel(Data['SGData']['SpGrp']) |
---|
68 | msg = 'Space Group Information' |
---|
69 | SgNo = G2spc.SpaceGroupNumber(SpcGp) |
---|
70 | if SgNo+1: |
---|
71 | text[0] += ', No. '+str(SgNo) |
---|
72 | G2G.SGMessageBox(self,msg,text,table).Show() |
---|
73 | self.UpdateData(Data) |
---|
74 | |
---|
75 | def OnXYZ(event): |
---|
76 | Obj = event.GetEventObject() |
---|
77 | self.XYZ = Obj.GetValue() |
---|
78 | try: |
---|
79 | XYZ= np.array(eval('['+self.XYZ+']'),dtype=np.float) |
---|
80 | print('for:',XYZ) |
---|
81 | SytSym,Mul,Nop,dupDir = G2spc.SytSym(XYZ,SGData) |
---|
82 | print('dupDir',dupDir.keys()) |
---|
83 | CSIX = G2spc.GetCSxinel(SytSym) |
---|
84 | CSIU = G2spc.GetCSuinel(SytSym) |
---|
85 | StrXYZ = [str(sxyz) for sxyz in CSIX[0]] |
---|
86 | ValXYZ = [str(val) for val in CSIX[1]] |
---|
87 | CSIXtxt.SetLabel(' site sym: %6s, mult: %3d, CSI-X: %s %s'%(SytSym,Mul,StrXYZ,ValXYZ)) |
---|
88 | StrUIJ = [str(suij) for suij in CSIU[0]] |
---|
89 | ValUIJ = [str(val) for val in CSIU[1]] |
---|
90 | CSIUtxt.SetLabel(' site sym: %6s, mult: %3d, CSI-U: %s %s'%(SytSym,Mul,StrUIJ,ValUIJ)) |
---|
91 | except: |
---|
92 | print('Bad X,Y,Z entry: ',Obj.GetValue()) |
---|
93 | self.XYZ = '0,0,0' |
---|
94 | Obj.SetValue(self.XYZ) |
---|
95 | |
---|
96 | def OnShowOps(event): |
---|
97 | text,table = G2spc.SGPrint(SGData) |
---|
98 | msg = 'Space Group Information' |
---|
99 | SgNo = G2spc.SpaceGroupNumber(SGData['SpGrp']) |
---|
100 | if SgNo+1: |
---|
101 | text[0] += ', No. '+str(SgNo) |
---|
102 | G2G.SGMessageBox(self,msg,text,table).Show() |
---|
103 | |
---|
104 | def OnShowGen(event): |
---|
105 | GenText = G2spc.TextGen(SGData,reverse=True) |
---|
106 | print(' Symmetry generators for %s:'%text[0].split(':')[1]) |
---|
107 | for item in GenText: |
---|
108 | print(item) |
---|
109 | |
---|
110 | def OnTestHKL(event): |
---|
111 | print('Extinctions for '+Data['SGData']['MagSpGrp']) |
---|
112 | hkls = np.mgrid[-6:6,-6:6,-6:6] |
---|
113 | HKLs = hkls.reshape((3,-1)).T |
---|
114 | for hkl in HKLs[1:]: #skip 0,0,0 |
---|
115 | ext = G2spc.checkMagextc(hkl,SGData) |
---|
116 | if ext: print(hkl) |
---|
117 | |
---|
118 | SGData = Data['SGData'] |
---|
119 | self.testSSPanel.DestroyChildren() |
---|
120 | mainSizer = wx.BoxSizer(wx.VERTICAL) |
---|
121 | topSizer = wx.FlexGridSizer(0,2,5,5) |
---|
122 | topSizer.Add(wx.StaticText(self.testSSPanel,-1,' Space group: '),0,WACV) |
---|
123 | SpGrp = Data['SGData']['SpGrp'] |
---|
124 | SGTxt = wx.Button(self.testSSPanel,wx.ID_ANY,SpGrp,size=(100,-1)) |
---|
125 | SGTxt.Bind(wx.EVT_BUTTON,OnSpaceGroup) |
---|
126 | topSizer.Add(SGTxt,0,WACV) |
---|
127 | text,table = G2spc.SGPrint(SGData,AddInv=True) |
---|
128 | topSizer.Add(wx.StaticText(self.testSSPanel,label=' Special position test:'),0,WACV) |
---|
129 | SpPos = wx.BoxSizer(wx.HORIZONTAL) |
---|
130 | SpPos.Add(wx.StaticText(self.testSSPanel,label=' X,Y,Z:'),0,WACV) |
---|
131 | xyz = wx.TextCtrl(self.testSSPanel,value=self.XYZ,style=wx.TE_PROCESS_ENTER) |
---|
132 | xyz.Bind(wx.EVT_TEXT_ENTER,OnXYZ) |
---|
133 | SpPos.Add(xyz,0,WACV) |
---|
134 | topSizer.Add(SpPos,0,WACV) |
---|
135 | mainSizer.Add(topSizer) |
---|
136 | XYZ= np.array(eval('['+self.XYZ+']'),dtype=np.float) |
---|
137 | SytSym,Mul,Nop,dupDir = G2spc.SytSym(XYZ,SGData) |
---|
138 | CSIX = G2spc.GetCSxinel(SytSym) |
---|
139 | CSIU = G2spc.GetCSuinel(SytSym) |
---|
140 | StrXYZ = [str(sxyz) for sxyz in CSIX[0]] |
---|
141 | ValXYZ = [str(val) for val in CSIX[1]] |
---|
142 | StrUIJ = [str(suij) for suij in CSIU[0]] |
---|
143 | ValUIJ = [str(val) for val in CSIU[1]] |
---|
144 | CSIXtxt = wx.StaticText(self.testSSPanel,label=' site sym: %6s, mult: %3d, CSI-X: %s %s'%(SytSym,Mul,StrXYZ,ValXYZ)) |
---|
145 | mainSizer.Add(CSIXtxt,0,WACV) |
---|
146 | mainSizer.Add((5,5),0) |
---|
147 | CSIUtxt = wx.StaticText(self.testSSPanel,label=' site sym: %6s, mult: %3d, CSI-U: %s %s'%(SytSym,Mul,StrUIJ,ValUIJ)) |
---|
148 | mainSizer.Add(CSIUtxt,0,WACV) |
---|
149 | testHKL = wx.Button(self.testSSPanel,-1,'Extinction test') |
---|
150 | testHKL.Bind(wx.EVT_BUTTON,OnTestHKL) |
---|
151 | mainSizer.Add(testHKL,0,WACV) |
---|
152 | printSizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
153 | showOps = wx.Button(self.testSSPanel,-1,'Show sym. ops') |
---|
154 | showOps.Bind(wx.EVT_BUTTON,OnShowOps) |
---|
155 | printSizer.Add(showOps,0,WACV) |
---|
156 | showGen = wx.Button(self.testSSPanel,-1,'Print generators') |
---|
157 | showGen.Bind(wx.EVT_BUTTON,OnShowGen) |
---|
158 | printSizer.Add(showGen,0,WACV) |
---|
159 | mainSizer.Add(printSizer,0,WACV) |
---|
160 | self.testSSPanel.SetSizer(mainSizer) |
---|
161 | Size = mainSizer.Fit(self.testSSPanel) |
---|
162 | Size[0] = 800 |
---|
163 | Size[1] = max(Size[1],350) |
---|
164 | self.testSSPanel.SetSize(Size) |
---|
165 | |
---|
166 | class testSytSmain(wx.App): |
---|
167 | def OnInit(self): |
---|
168 | self.main = testSytSym(None) |
---|
169 | self.main.Show() |
---|
170 | self.SetTopWindow(self.main) |
---|
171 | return True |
---|
172 | |
---|
173 | def main(): |
---|
174 | 'Starts main application to compute and plot derivatives' |
---|
175 | GSASIIpath.InvokeDebugOpts() |
---|
176 | application = testSytSmain(0) |
---|
177 | application.MainLoop() |
---|
178 | |
---|
179 | if __name__ == '__main__': |
---|
180 | main() |
---|
181 | |
---|
182 | |
---|