1 | #GSASII - data display routines |
---|
2 | import wx |
---|
3 | import wx.grid as wg |
---|
4 | import matplotlib as mpl |
---|
5 | import math |
---|
6 | import time |
---|
7 | import cPickle |
---|
8 | import GSASIIcomp as G2cmp |
---|
9 | import GSASIIspc as G2spc |
---|
10 | import GSASIIElem as G2elem |
---|
11 | import GSASIIplot as G2plt |
---|
12 | |
---|
13 | # trig functions in degrees |
---|
14 | sind = lambda x: math.sin(x*math.pi/180.) |
---|
15 | tand = lambda x: math.tan(x*math.pi/180.) |
---|
16 | cosd = lambda x: math.cos(x*math.pi/180.) |
---|
17 | asind = lambda x: 180.*math.asin(x)/math.pi |
---|
18 | |
---|
19 | [ wxID_ATOMSEDITADD, wxID_ATOMSEDITINSERT, |
---|
20 | ] = [wx.NewId() for _init_coll_Atom_Items in range(2)] |
---|
21 | |
---|
22 | [ wxID_IMCALIBRATE, wxID_IMINTEGRATE, wxID_IMCLEARCALIB, wxID_IMREFRESHTA, |
---|
23 | ] = [wx.NewId() for _init_coll_IMAGE_Items in range(4)] |
---|
24 | |
---|
25 | [ wxID_UNDO,wxID_PEAKFIT,wxID_AUTOPEAKFIT, |
---|
26 | ] = [wx.NewId() for _init_coll_PEAK_Items in range(3)] |
---|
27 | |
---|
28 | [ wxID_INDEXPEAKS, wxID_REFINECELL, wxID_COPYCELL, |
---|
29 | ] = [wx.NewId() for _init_coll_INDEX_Items in range(3)] |
---|
30 | |
---|
31 | class DataFrame(wx.Frame): |
---|
32 | def _init_coll_BlankMenu(self,parent): |
---|
33 | parent.Append(menu=self.Blank,title='') |
---|
34 | |
---|
35 | def _init_coll_AtomsMenu(self,parent): |
---|
36 | parent.Append(menu=self.AtomEdit, title='Add atom') |
---|
37 | |
---|
38 | def _init_coll_ImageMenu(self,parent): |
---|
39 | parent.Append(menu=self.ImageEdit, title='Image Operations') |
---|
40 | |
---|
41 | def _init_coll_PeakMenu(self,parent): |
---|
42 | parent.Append(menu=self.PeakEdit, title='Peak Fitting') |
---|
43 | |
---|
44 | def _init_coll_IndexMenu(self,parent): |
---|
45 | parent.Append(menu=self.IndexEdit, title='Cell Index/Refine') |
---|
46 | |
---|
47 | def _init_coll_Atom_Items(self,parent): |
---|
48 | parent.Append(help='',id=wxID_ATOMSEDITADD, kind=wx.ITEM_NORMAL,text='Append empty atom') |
---|
49 | parent.Append(id=wxID_ATOMSEDITINSERT, kind=wx.ITEM_NORMAL,text='Insert empty atom', |
---|
50 | help='Double left click on atom row to Insert before') |
---|
51 | |
---|
52 | def _init_coll_Image_Items(self,parent): |
---|
53 | parent.Append(help='',id=wxID_IMCALIBRATE, kind=wx.ITEM_NORMAL,text='Calibrate') |
---|
54 | parent.Append(help='',id=wxID_IMCLEARCALIB, kind=wx.ITEM_NORMAL,text='Clear calibration') |
---|
55 | parent.Append(help='',id=wxID_IMINTEGRATE, kind=wx.ITEM_NORMAL,text='Integrate') |
---|
56 | parent.Append(help='',id=wxID_IMREFRESHTA, kind=wx.ITEM_NORMAL,text='Refresh transformed image') |
---|
57 | |
---|
58 | |
---|
59 | def _init_coll_Peak_Items(self,parent): |
---|
60 | self.UnDo = parent.Append(help='', id=wxID_UNDO, kind=wx.ITEM_NORMAL, |
---|
61 | text='UnDo') |
---|
62 | self.PeakFit = parent.Append(help='', id=wxID_PEAKFIT, kind=wx.ITEM_NORMAL, |
---|
63 | text='PeakFit') |
---|
64 | self.AutoPeakFit = parent.Append(help='', id=wxID_AUTOPEAKFIT, kind=wx.ITEM_NORMAL, |
---|
65 | text='AutoPeakFit') |
---|
66 | |
---|
67 | def _init_coll_Index_Items(self,parent): |
---|
68 | self.IndexPeaks = parent.Append(help='', id=wxID_INDEXPEAKS, kind=wx.ITEM_NORMAL, |
---|
69 | text='Index Cell') |
---|
70 | self.CopyCell = parent.Append(help='', id=wxID_COPYCELL, kind=wx.ITEM_NORMAL, |
---|
71 | text='Copy Cell') |
---|
72 | self.RefineCell = parent.Append(help='', id=wxID_REFINECELL, kind=wx.ITEM_NORMAL, |
---|
73 | text='Refine Cell') |
---|
74 | |
---|
75 | def _init_utils(self): |
---|
76 | self.BlankMenu = wx.MenuBar() |
---|
77 | |
---|
78 | self.AtomsMenu = wx.MenuBar() |
---|
79 | self.ImageMenu = wx.MenuBar() |
---|
80 | self.PeakMenu = wx.MenuBar() |
---|
81 | self.IndexMenu = wx.MenuBar() |
---|
82 | self.AtomEdit = wx.Menu(title='') |
---|
83 | self.ImageEdit = wx.Menu(title='') |
---|
84 | self.PeakEdit = wx.Menu(title='') |
---|
85 | self.IndexEdit = wx.Menu(title='') |
---|
86 | self._init_coll_AtomsMenu(self.AtomsMenu) |
---|
87 | self._init_coll_Atom_Items(self.AtomEdit) |
---|
88 | self._init_coll_ImageMenu(self.ImageMenu) |
---|
89 | self._init_coll_Image_Items(self.ImageEdit) |
---|
90 | self._init_coll_PeakMenu(self.PeakMenu) |
---|
91 | self._init_coll_Peak_Items(self.PeakEdit) |
---|
92 | self._init_coll_IndexMenu(self.IndexMenu) |
---|
93 | self._init_coll_Index_Items(self.IndexEdit) |
---|
94 | self.UnDo.Enable(False) |
---|
95 | self.PeakFit.Enable(False) |
---|
96 | self.AutoPeakFit.Enable(False) |
---|
97 | self.IndexPeaks.Enable(False) |
---|
98 | self.CopyCell.Enable(False) |
---|
99 | self.RefineCell.Enable(False) |
---|
100 | |
---|
101 | def _init_ctrls(self, parent,name=None,size=None,pos=None): |
---|
102 | wx.Frame.__init__(self,parent=parent,style=wx.DEFAULT_FRAME_STYLE ^ wx.CLOSE_BOX, |
---|
103 | size=size,pos=pos,title='GSAS-II data display') |
---|
104 | self._init_utils() |
---|
105 | if name: |
---|
106 | self.SetLabel(name) |
---|
107 | self.Show() |
---|
108 | |
---|
109 | def __init__(self,parent,data=None,name=None, size=None,pos=None): |
---|
110 | self._init_ctrls(parent,name,size,pos) |
---|
111 | self.data = data |
---|
112 | self.screenSize = wx.DisplaySize() |
---|
113 | Size = self.GetSize() |
---|
114 | xPos = self.screenSize[0]-Size[0] |
---|
115 | self.SetPosition(wx.Point(xPos,250)) |
---|
116 | self.dirname = '' |
---|
117 | self.AtomGrid = [] |
---|
118 | self.selectedRow = 0 |
---|
119 | |
---|
120 | def setSizePosLeft(self,Width): |
---|
121 | screenSize = wx.DisplaySize() |
---|
122 | self.SetSize(Width) |
---|
123 | self.SetPosition(wx.Point(screenSize[0]-Width[0],250)) |
---|
124 | |
---|
125 | def Clear(self): |
---|
126 | self.ClearBackground() |
---|
127 | self.DestroyChildren() |
---|
128 | |
---|
129 | class GSGrid(wg.Grid): |
---|
130 | def __init__(self, parent, name=''): |
---|
131 | wg.Grid.__init__(self,parent,-1,name=name) |
---|
132 | self.SetSize(parent.GetClientSize()) |
---|
133 | |
---|
134 | def Clear(self): |
---|
135 | wg.Grid.ClearGrid(self) |
---|
136 | |
---|
137 | def SetCellStyle(self,r,c,color="white",readonly=True): |
---|
138 | self.SetCellBackgroundColour(r,c,color) |
---|
139 | self.SetReadOnly(r,c,isReadOnly=readonly) |
---|
140 | |
---|
141 | class GSNoteBook(wx.Notebook): |
---|
142 | def __init__(self, parent, name='',size = None): |
---|
143 | wx.Notebook.__init__(self, parent, -1, name=name, style= wx.BK_TOP) |
---|
144 | if size: self.SetSize(size) |
---|
145 | |
---|
146 | def Clear(self): |
---|
147 | GSNoteBook.DeleteAllPages(self) |
---|
148 | |
---|
149 | class Table(wg.PyGridTableBase): |
---|
150 | def __init__(self, data=[], rowLabels=None, colLabels=None, types = None): |
---|
151 | wg.PyGridTableBase.__init__(self) |
---|
152 | self.colLabels = colLabels |
---|
153 | self.rowLabels = rowLabels |
---|
154 | self.dataTypes = types |
---|
155 | self.data = data |
---|
156 | |
---|
157 | def AppendRows(self, numRows=1): |
---|
158 | self.data.append([]) |
---|
159 | return True |
---|
160 | |
---|
161 | def CanGetValueAs(self, row, col, typeName): |
---|
162 | if self.dataTypes: |
---|
163 | colType = self.dataTypes[col].split(':')[0] |
---|
164 | if typeName == colType: |
---|
165 | return True |
---|
166 | else: |
---|
167 | return False |
---|
168 | else: |
---|
169 | return False |
---|
170 | |
---|
171 | def CanSetValueAs(self, row, col, typeName): |
---|
172 | return self.CanGetValueAs(row, col, typeName) |
---|
173 | |
---|
174 | def DeleteRow(self,pos): |
---|
175 | data = self.GetData() |
---|
176 | self.SetData([]) |
---|
177 | new = [] |
---|
178 | for irow,row in enumerate(data): |
---|
179 | if irow <> pos: |
---|
180 | new.append(row) |
---|
181 | self.SetData(new) |
---|
182 | |
---|
183 | def GetColLabelValue(self, col): |
---|
184 | if self.colLabels: |
---|
185 | return self.colLabels[col] |
---|
186 | |
---|
187 | def GetData(self): |
---|
188 | data = [] |
---|
189 | for row in range(self.GetNumberRows()): |
---|
190 | data.append(self.GetRowValues(row)) |
---|
191 | return data |
---|
192 | |
---|
193 | def GetNumberCols(self): |
---|
194 | try: |
---|
195 | return len(self.colLabels) |
---|
196 | except TypeError: |
---|
197 | return None |
---|
198 | |
---|
199 | def GetNumberRows(self): |
---|
200 | return len(self.data) |
---|
201 | |
---|
202 | def GetRowLabelValue(self, row): |
---|
203 | if self.rowLabels: |
---|
204 | return self.rowLabels[row] |
---|
205 | |
---|
206 | def GetRowValues(self, row): |
---|
207 | data = [] |
---|
208 | for col in range(self.GetNumberCols()): |
---|
209 | data.append(self.GetValue(row, col)) |
---|
210 | return data |
---|
211 | |
---|
212 | def GetTypeName(self, row, col): |
---|
213 | try: |
---|
214 | return self.dataTypes[col] |
---|
215 | except TypeError: |
---|
216 | return None |
---|
217 | |
---|
218 | def GetValue(self, row, col): |
---|
219 | try: |
---|
220 | return self.data[row][col] |
---|
221 | except IndexError: |
---|
222 | return None |
---|
223 | |
---|
224 | def InsertRows(self, pos, rows): |
---|
225 | for row in range(rows): |
---|
226 | self.data.insert(pos,[]) |
---|
227 | pos += 1 |
---|
228 | |
---|
229 | def IsEmptyCell(self,row,col): |
---|
230 | try: |
---|
231 | return not self.data[row][col] |
---|
232 | except IndexError: |
---|
233 | return True |
---|
234 | |
---|
235 | def OnKeyPress(self, event): |
---|
236 | dellist = self.GetSelectedRows() |
---|
237 | if event.GetKeyCode() == wx.WXK_DELETE and dellist: |
---|
238 | grid = self.GetView() |
---|
239 | for i in dellist: grid.DeleteRow(i) |
---|
240 | |
---|
241 | def SetColLabelValue(self, col, label): |
---|
242 | numcols = self.GetNumberCols() |
---|
243 | if col > numcols-1: |
---|
244 | self.colLabels.append(label) |
---|
245 | else: |
---|
246 | self.colLabels[col]=label |
---|
247 | |
---|
248 | def SetData(self,data): |
---|
249 | for row in range(len(data)): |
---|
250 | self.SetRowValues(row,data[row]) |
---|
251 | |
---|
252 | def SetRowLabelValue(self, row, label): |
---|
253 | self.rowLabels[row]=label |
---|
254 | |
---|
255 | def SetRowValues(self,row,data): |
---|
256 | self.data[row] = data |
---|
257 | |
---|
258 | def SetValue(self, row, col, value): |
---|
259 | def innerSetValue(row, col, value): |
---|
260 | try: |
---|
261 | self.data[row][col] = value |
---|
262 | except TypeError: |
---|
263 | return |
---|
264 | except IndexError: |
---|
265 | print row,col,value |
---|
266 | # add a new row |
---|
267 | if row > self.GetNumberRows(): |
---|
268 | self.data.append([''] * self.GetNumberCols()) |
---|
269 | elif col > self.GetNumberCols(): |
---|
270 | for row in range(self.GetNumberRows): |
---|
271 | self.data[row].append('') |
---|
272 | print self.data |
---|
273 | self.data[row][col] = value |
---|
274 | innerSetValue(row, col, value) |
---|
275 | |
---|
276 | |
---|
277 | def UpdateNotebook(self,data): |
---|
278 | if data: |
---|
279 | self.dataFrame.SetLabel('Notebook') |
---|
280 | self.dataDisplay = wx.TextCtrl(parent=self.dataFrame,size=self.dataFrame.GetClientSize(), |
---|
281 | style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER | wx.TE_DONTWRAP) |
---|
282 | for line in data: |
---|
283 | self.dataDisplay.AppendText(line+"\n") |
---|
284 | self.dataDisplay.AppendText('Notebook entry @ '+time.ctime()+"\n") |
---|
285 | |
---|
286 | def UpdateControls(self,data): |
---|
287 | if data: |
---|
288 | self.dataFrame.SetLabel('Controls') |
---|
289 | |
---|
290 | |
---|
291 | def UpdateComments(self,data): |
---|
292 | if data: |
---|
293 | self.dataFrame.SetLabel('Comments') |
---|
294 | self.dataDisplay = wx.TextCtrl(parent=self.dataFrame,size=self.dataFrame.GetClientSize(), |
---|
295 | style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER | wx.TE_DONTWRAP) |
---|
296 | for line in data: |
---|
297 | self.dataDisplay.AppendText(line+"\n") |
---|
298 | |
---|
299 | def UpdatePeakGrid(self, data): |
---|
300 | if self.dataDisplay: |
---|
301 | self.dataDisplay.Destroy() |
---|
302 | |
---|
303 | def OnUnDo(event): |
---|
304 | DoUnDo() |
---|
305 | self.dataFrame.UnDo.Enable(False) |
---|
306 | |
---|
307 | def DoUnDo(): |
---|
308 | print 'Undo last refinement' |
---|
309 | file = open('GSASII.save','rb') |
---|
310 | PatternId = self.PatternId |
---|
311 | for item in ['Background','Instrument Parameters','Peak List']: |
---|
312 | self.PatternTree.SetItemPyData(GetPatternTreeItemId(self,PatternId, item),cPickle.load(file)) |
---|
313 | if self.dataDisplay.GetName() == item: |
---|
314 | if item == 'Background': |
---|
315 | UpdateBackgroundGrid(self,self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,PatternId, item))) |
---|
316 | elif item == 'Instrument Parameters': |
---|
317 | UpdateInstrumentGrid(self,self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,PatternId, item))) |
---|
318 | elif item == 'Peak List': |
---|
319 | UpdatePeakGrid(self,self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,PatternId, item))) |
---|
320 | print item,' recovered' |
---|
321 | file.close() |
---|
322 | |
---|
323 | def OnPeakFit(event): |
---|
324 | self.SaveState() |
---|
325 | print 'Peak Fitting - Do one cycle of peak fitting' |
---|
326 | PatternId = self.PatternId |
---|
327 | PickId = self.PickId |
---|
328 | peaks = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,PatternId, 'Peak List')) |
---|
329 | if not peaks: |
---|
330 | self.ErrorDialog('No peaks!','Nothing to fit!') |
---|
331 | return |
---|
332 | background = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,PatternId, 'Background'))[0] |
---|
333 | limits = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,PatternId, 'Limits'))[1] |
---|
334 | inst = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,PatternId, 'Instrument Parameters')) |
---|
335 | data = self.PatternTree.GetItemPyData(PatternId)[1] |
---|
336 | OK,smin,Rwp,runtime,GoOn = G2cmp.DoPeakFit(peaks,background,limits,inst,data) |
---|
337 | UpdatePeakGrid(self,peaks) |
---|
338 | G2plt.PlotPatterns(self) |
---|
339 | if not OK: |
---|
340 | print 'Refinement failed' |
---|
341 | dlg = wx.MessageDialog(self, 'Do you want to reload now?', 'Refinement failed', wx.YES_NO) |
---|
342 | try: |
---|
343 | if dlg.ShowModal() == wx.ID_YES: |
---|
344 | DoUnDo() |
---|
345 | self.dataFrame.UnDo.Enable(False) |
---|
346 | finally: |
---|
347 | dlg.Destroy() |
---|
348 | else: |
---|
349 | self.dataFrame.UnDo.Enable(True) |
---|
350 | print "%s%7.2f%s%12.6g" % ('Rwp = ',Rwp,'%, Smin = ',smin) |
---|
351 | print "%s%8.3f%s " % ('fitpeak time =',runtime,'s') |
---|
352 | print 'finished' |
---|
353 | return |
---|
354 | |
---|
355 | def OnAutoPeakFit(event): |
---|
356 | self.SaveState() |
---|
357 | print 'AutoPeak Fitting - run until minimized' |
---|
358 | PatternId = self.PatternId |
---|
359 | PickId = self.PickId |
---|
360 | peaks = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,PatternId, 'Peak List')) |
---|
361 | if not peaks: |
---|
362 | self.ErrorDialog('No peaks!','Nothing to fit!') |
---|
363 | return |
---|
364 | background = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,PatternId, 'Background'))[0] |
---|
365 | limits = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,PatternId, 'Limits'))[1] |
---|
366 | inst = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,PatternId, 'Instrument Parameters')) |
---|
367 | data = self.PatternTree.GetItemPyData(PatternId)[1] |
---|
368 | smin = 1.0e10 |
---|
369 | GoOn = True |
---|
370 | while GoOn: |
---|
371 | osmin = smin |
---|
372 | OK,smin,Rwp,runtime,GoOn = G2cmp.DoPeakFit(peaks,background,limits,inst,data) |
---|
373 | UpdatePeakGrid(self,peaks) |
---|
374 | if not OK: |
---|
375 | break |
---|
376 | G2plt.PlotPatterns(self) |
---|
377 | print "%s%7.2f%s%12.6g" % ('Rwp = ',Rwp,'%, Smin = ',smin) |
---|
378 | rat = (osmin-smin)/smin |
---|
379 | if rat < 1.0e-4: GoOn = False |
---|
380 | if not OK: |
---|
381 | print 'Refinement failed' |
---|
382 | dlg = wx.MessageDialog(self, 'Do you want to reload now?', 'Refinement failed', wx.YES_NO) |
---|
383 | try: |
---|
384 | if dlg.ShowModal() == wx.ID_YES: |
---|
385 | DoUnDo() |
---|
386 | self.dataFrame.UnDo.Enable(False) |
---|
387 | finally: |
---|
388 | dlg.Destroy() |
---|
389 | else: |
---|
390 | self.dataFrame.UnDo.Enable(True) |
---|
391 | print "%s%8.3f%s " % ('fitpeak time =',runtime,'s per cycle') |
---|
392 | print 'finished' |
---|
393 | return |
---|
394 | |
---|
395 | def RefreshPeakGrid(event): |
---|
396 | event.StopPropagation() |
---|
397 | data = self.PeakTable.GetData() |
---|
398 | T = [] |
---|
399 | for peak in data:T.append(peak[0]) |
---|
400 | D = dict(zip(T,data)) |
---|
401 | T.sort() |
---|
402 | X = [] |
---|
403 | for key in T: X.append(D[key]) |
---|
404 | data = X |
---|
405 | G2plt.PlotPatterns(self) |
---|
406 | |
---|
407 | def setBackgroundColors(): |
---|
408 | for r in range(self.dataDisplay.GetNumberRows()): |
---|
409 | for c in range(self.dataDisplay.GetNumberCols()): |
---|
410 | if self.dataDisplay.GetColLabelValue(c) in ['position','intensity','sigma','gamma','SH/L']: |
---|
411 | if float(self.dataDisplay.GetCellValue(r,c)) < 0.: |
---|
412 | self.dataDisplay.SetCellBackgroundColour(r,c,wx.RED) |
---|
413 | else: |
---|
414 | self.dataDisplay.SetCellBackgroundColour(r,c,wx.WHITE) |
---|
415 | |
---|
416 | def KeyEditPeakGrid(event): |
---|
417 | rowList = self.dataDisplay.GetSelectedRows() |
---|
418 | colList = self.dataDisplay.GetSelectedCols() |
---|
419 | selectList = self.dataDisplay.GetSelectedCells() |
---|
420 | data = self.PatternTree.GetItemPyData(self.PickId) |
---|
421 | if event.GetKeyCode() == wx.WXK_RETURN: |
---|
422 | event.Skip(True) |
---|
423 | elif event.GetKeyCode() == wx.WXK_CONTROL: |
---|
424 | event.Skip(True) |
---|
425 | elif event.GetKeyCode() == wx.WXK_SHIFT: |
---|
426 | event.Skip(True) |
---|
427 | elif rowList: |
---|
428 | self.dataDisplay.ClearSelection() |
---|
429 | if event.GetKeyCode() == wx.WXK_DELETE: |
---|
430 | self.dataDisplay.ClearGrid() |
---|
431 | rowList.reverse() |
---|
432 | nDel = 0 |
---|
433 | for row in rowList: |
---|
434 | self.PeakTable.DeleteRow(row) |
---|
435 | nDel += 1 |
---|
436 | if nDel: |
---|
437 | msg = wg.GridTableMessage(self.PeakTable, |
---|
438 | wg.GRIDTABLE_NOTIFY_ROWS_DELETED,0,nDel) |
---|
439 | self.dataDisplay.ProcessTableMessage(msg) |
---|
440 | data = self.PeakTable.GetData() |
---|
441 | self.PatternTree.SetItemPyData(self.PickId,data[:-nDel]) |
---|
442 | self.dataDisplay.ForceRefresh() |
---|
443 | setBackgroundColors() |
---|
444 | elif colList: |
---|
445 | self.dataDisplay.ClearSelection() |
---|
446 | key = event.GetKeyCode() |
---|
447 | for col in colList: |
---|
448 | if self.PeakTable.GetTypeName(0,col) == wg.GRID_VALUE_BOOL: |
---|
449 | if key == 89: #'Y' |
---|
450 | for row in range(self.PeakTable.GetNumberRows()): data[row][col]=True |
---|
451 | elif key == 78: #'N' |
---|
452 | for row in range(self.PeakTable.GetNumberRows()): data[row][col]=False |
---|
453 | elif selectList: |
---|
454 | self.dataDisplay.ClearSelection() |
---|
455 | key = event.GetKeyCode() |
---|
456 | for row,col in selectList: |
---|
457 | if self.PeakTable.GetTypeName(row,col) == wg.GRID_VALUE_BOOL: |
---|
458 | if key == 89: #'Y' |
---|
459 | data[row][col]=True |
---|
460 | elif key == 78: #'N' |
---|
461 | data[row][col]=False |
---|
462 | G2plt.PlotPatterns(self) |
---|
463 | |
---|
464 | self.dataFrame.SetMenuBar(self.dataFrame.PeakMenu) |
---|
465 | self.Bind(wx.EVT_MENU, OnUnDo, id=wxID_UNDO) |
---|
466 | self.Bind(wx.EVT_MENU, OnPeakFit, id=wxID_PEAKFIT) |
---|
467 | self.Bind(wx.EVT_MENU, OnAutoPeakFit, id=wxID_AUTOPEAKFIT) |
---|
468 | if data: |
---|
469 | self.dataFrame.PeakFit.Enable(True) |
---|
470 | self.dataFrame.AutoPeakFit.Enable(True) |
---|
471 | self.PickTable = [] |
---|
472 | rowLabels = [] |
---|
473 | for i in range(len(data)): rowLabels.append(str(i+1)) |
---|
474 | colLabels = ['position','refine','intensity','refine','sigma','refine','gamma','refine','SH/L','refine'] |
---|
475 | Types = [wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_BOOL, |
---|
476 | wg.GRID_VALUE_FLOAT+':10,1',wg.GRID_VALUE_BOOL, |
---|
477 | wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL, |
---|
478 | wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL, |
---|
479 | wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL] |
---|
480 | T = [] |
---|
481 | for peak in data: |
---|
482 | T.append(peak[0]) |
---|
483 | D = dict(zip(T,data)) |
---|
484 | T.sort() |
---|
485 | X = [] |
---|
486 | for key in T: X.append(D[key]) |
---|
487 | data = X |
---|
488 | self.PatternTree.SetItemPyData(self.PickId,data) |
---|
489 | self.PeakTable = Table(data,rowLabels=rowLabels,colLabels=colLabels,types=Types) |
---|
490 | self.dataFrame.SetLabel('Peak List') |
---|
491 | self.dataDisplay = GSGrid(parent=self.dataFrame) |
---|
492 | self.dataDisplay.SetTable(self.PeakTable, True) |
---|
493 | setBackgroundColors() |
---|
494 | self.dataDisplay.Bind(wg.EVT_GRID_CELL_CHANGE, RefreshPeakGrid) |
---|
495 | self.dataDisplay.Bind(wx.EVT_KEY_DOWN, KeyEditPeakGrid) |
---|
496 | self.dataDisplay.SetMargins(0,0) |
---|
497 | self.dataDisplay.AutoSizeColumns(False) |
---|
498 | self.dataFrame.setSizePosLeft([650,350]) |
---|
499 | |
---|
500 | def UpdateBackgroundGrid(self,data): |
---|
501 | BackId = GetPatternTreeItemId(self,self.PatternId, 'Background') |
---|
502 | |
---|
503 | def RefreshBackgroundGrid(event): |
---|
504 | data = self.BackTable.GetData() |
---|
505 | M = len(data[0]) |
---|
506 | N = data[0][2]+3 |
---|
507 | item = data[0] |
---|
508 | if N > M: #add terms |
---|
509 | for i in range(M,N): |
---|
510 | item.append(0.0) |
---|
511 | self.BackTable.SetColLabelValue(i,str(i-2)) |
---|
512 | data = [item] |
---|
513 | msg = wg.GridTableMessage(self.BackTable, |
---|
514 | wg.GRIDTABLE_NOTIFY_COLS_APPENDED,0,N-M) |
---|
515 | self.dataDisplay.ProcessTableMessage(msg) |
---|
516 | elif N < M: #delete terms |
---|
517 | new = [] |
---|
518 | for i in range(N): |
---|
519 | new.append(item[i]) |
---|
520 | data = [new] |
---|
521 | msg = wg.GridTableMessage(self.BackTable, |
---|
522 | wg.GRIDTABLE_NOTIFY_COLS_DELETED,0,M-N) |
---|
523 | self.dataDisplay.ProcessTableMessage(msg) |
---|
524 | self.PatternTree.SetItemPyData(BackId,data) |
---|
525 | |
---|
526 | self.dataFrame.setSizePosLeft([700,150]) |
---|
527 | maxTerm = 7 |
---|
528 | self.BackTable = [] |
---|
529 | N = len(data[0]) |
---|
530 | M = data[0][2] |
---|
531 | colLabels = ['function','refine','Nterms'] |
---|
532 | rowLabels=['background'] |
---|
533 | for i in range(M): colLabels.append(str(i+1)) |
---|
534 | Types = [wg.GRID_VALUE_CHOICE+':chebyschev,another,more', |
---|
535 | wg.GRID_VALUE_BOOL, |
---|
536 | wg.GRID_VALUE_NUMBER+':1,'+str(maxTerm)] |
---|
537 | for i in range(maxTerm): |
---|
538 | Types.append(wg.GRID_VALUE_FLOAT+':10,3') |
---|
539 | self.BackTable = Table(data,rowLabels=rowLabels,colLabels=colLabels,types=Types) |
---|
540 | self.dataFrame.SetLabel('Background') |
---|
541 | self.dataFrame.SetMenuBar(self.dataFrame.BlankMenu) |
---|
542 | self.dataDisplay = GSGrid(parent=self.dataFrame) |
---|
543 | self.dataDisplay.Bind(wg.EVT_GRID_CELL_CHANGE, RefreshBackgroundGrid) |
---|
544 | self.dataDisplay.SetTable(self.BackTable, True) |
---|
545 | self.dataDisplay.SetMargins(0,0) |
---|
546 | self.dataDisplay.AutoSizeColumns(False) |
---|
547 | |
---|
548 | def UpdateLimitsGrid(self, data): |
---|
549 | if self.dataDisplay: |
---|
550 | self.dataDisplay.Destroy() |
---|
551 | self.dataFrame.setSizePosLeft([250,150]) |
---|
552 | LimitId = GetPatternTreeItemId(self,self.PatternId, 'Limits') |
---|
553 | def RefreshLimitsGrid(event): |
---|
554 | data = self.LimitsTable.GetData() |
---|
555 | old = data[0] |
---|
556 | new = data[1] |
---|
557 | new[0] = max(old[0],new[0]) |
---|
558 | new[1] = max(new[0],min(old[1],new[1])) |
---|
559 | data = [old,new] |
---|
560 | G2plt.PlotPatterns(self) |
---|
561 | |
---|
562 | self.LimitsTable = [] |
---|
563 | colLabels = ['Tmin','Tmax'] |
---|
564 | rowLabels = ['original','changed'] |
---|
565 | Types = [wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_FLOAT+':10,3'] |
---|
566 | self.LimitsTable = Table(data,rowLabels=rowLabels,colLabels=colLabels,types=Types) |
---|
567 | self.dataFrame.SetLabel('Limits') |
---|
568 | self.dataFrame.SetMenuBar(self.dataFrame.BlankMenu) |
---|
569 | self.dataDisplay = GSGrid(parent=self.dataFrame) |
---|
570 | self.dataDisplay.SetTable(self.LimitsTable, True) |
---|
571 | self.dataDisplay.Bind(wg.EVT_GRID_CELL_CHANGE, RefreshLimitsGrid) |
---|
572 | self.dataDisplay.SetMargins(0,0) |
---|
573 | self.dataDisplay.AutoSizeColumns(False) |
---|
574 | |
---|
575 | def UpdateInstrumentGrid(self, data): |
---|
576 | if self.dataDisplay: |
---|
577 | self.dataDisplay.Destroy() |
---|
578 | Ka2 = False |
---|
579 | Xwid = 720 |
---|
580 | if len(data[0]) == 12: |
---|
581 | Ka2 = True |
---|
582 | Xwid = 800 |
---|
583 | self.dataFrame.setSizePosLeft([Xwid,150]) |
---|
584 | self.dataFrame.SetMenuBar(self.dataFrame.BlankMenu) |
---|
585 | InstId = GetPatternTreeItemId(self,self.PatternId, 'Instrument Parameters') |
---|
586 | def RefreshInstrumentGrid(event): |
---|
587 | if event.GetRow() == 1: |
---|
588 | peaks = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,self.PatternId, 'Peak List')) |
---|
589 | ins = data[1] |
---|
590 | if 'P' in ins[0]: #update powder peak parameters |
---|
591 | for peak in peaks: |
---|
592 | if Ka2: |
---|
593 | peak[4] = ins[6]*tand(peak[0]/2.0)**2+ins[7]*tand(peak[0]/2.0)+ins[8] |
---|
594 | peak[6] = ins[9]/cosd(peak[0]/2.0)+ins[10]*tand(peak[0]/2.0) |
---|
595 | peak[8] = ins[11] |
---|
596 | else: |
---|
597 | peak[4] = ins[4]*tand(peak[0]/2.0)**2+ins[5]*tand(peak[0]/2.0)+ins[6] |
---|
598 | peak[6] = ins[7]/cosd(peak[0]/2.0)+ins[8]*tand(peak[0]/2.0) |
---|
599 | peak[8] = ins[9] |
---|
600 | |
---|
601 | self.InstrumentTable = [] |
---|
602 | if 'P' in data[1][0]: |
---|
603 | if Ka2: |
---|
604 | Types = [wg.GRID_VALUE_CHOICE+":PXC,PNC,PNT",wg.GRID_VALUE_FLOAT+':10,6',wg.GRID_VALUE_FLOAT+':10,6', #type, lam-1 & lam-2 |
---|
605 | wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_FLOAT+':10,3', #zero, ratio, pola |
---|
606 | wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_FLOAT+':10,3', #u,v,w |
---|
607 | wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_FLOAT+':10,5'] |
---|
608 | else: |
---|
609 | Types = [wg.GRID_VALUE_CHOICE+":PXC,PNC,PNT",wg.GRID_VALUE_FLOAT+':10,6', #type & lam-1 |
---|
610 | wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_FLOAT+':10,3', #zero, pola |
---|
611 | wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_FLOAT+':10,3', #u,v,w |
---|
612 | wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_FLOAT+':10,5'] |
---|
613 | colLabels = data[3] |
---|
614 | rowLabels = ['original','changed','refine'] |
---|
615 | self.InstrumentTable = Table(data[:-1],rowLabels=rowLabels,colLabels=colLabels,types=Types) |
---|
616 | self.dataFrame.SetLabel('Instrument Parameters') |
---|
617 | self.dataDisplay = GSGrid(parent=self.dataFrame) |
---|
618 | self.dataDisplay.SetTable(self.InstrumentTable, True) |
---|
619 | self.dataDisplay.Bind(wg.EVT_GRID_CELL_CHANGE, RefreshInstrumentGrid) |
---|
620 | self.dataDisplay.SetMargins(0,0) |
---|
621 | self.dataDisplay.AutoSizeColumns(False) |
---|
622 | beg = 4 |
---|
623 | if Ka2: beg = 6 |
---|
624 | for i in range(len(data[2])): |
---|
625 | if i < beg: |
---|
626 | self.dataDisplay.SetCellRenderer(2,i,wg.GridCellStringRenderer()) |
---|
627 | self.dataDisplay.SetCellValue(2,i,'') |
---|
628 | self.dataDisplay.SetReadOnly(2,i,isReadOnly=True) |
---|
629 | else: |
---|
630 | self.dataDisplay.SetCellRenderer(2,i,wg.GridCellBoolRenderer()) |
---|
631 | self.dataDisplay.SetCellEditor(2,i,wg.GridCellBoolEditor()) |
---|
632 | else: |
---|
633 | Types = [wg.GRID_VALUE_CHOICE+":SXC,SNC,SNT",wg.GRID_VALUE_FLOAT+':10,6'] |
---|
634 | colLabels = data[2] |
---|
635 | rowLabels = ['original','changed'] |
---|
636 | self.InstrumentTable = Table(data[:-1],rowLabels=rowLabels,colLabels=colLabels,types=Types) |
---|
637 | self.dataFrame.SetLabel('Instrument Parameters') |
---|
638 | self.dataDisplay = GSGrid(parent=self.dataFrame) |
---|
639 | self.dataDisplay.SetTable(self.InstrumentTable, True) |
---|
640 | self.dataDisplay.Bind(wg.EVT_GRID_CELL_CHANGE, RefreshInstrumentGrid) |
---|
641 | self.dataDisplay.SetMargins(0,0) |
---|
642 | self.dataDisplay.AutoSizeColumns(False) |
---|
643 | |
---|
644 | def UpdateIndexPeaksGrid(self, data): |
---|
645 | IndexId = GetPatternTreeItemId(self,self.PatternId, 'Index Peak List') |
---|
646 | |
---|
647 | def RefreshIndexPeaksGrid(event): |
---|
648 | data = self.IndexPeaksTable.GetData() |
---|
649 | self.PatternTree.SetItemPyData(IndexId,data) |
---|
650 | |
---|
651 | def KeyEditPickGrid(event): |
---|
652 | colList = self.dataDisplay.GetSelectedCols() |
---|
653 | rowList = self.dataDisplay.GetSelectedRows() |
---|
654 | data = self.PatternTree.GetItemPyData(IndexId) |
---|
655 | if event.GetKeyCode() == wx.WXK_RETURN: |
---|
656 | event.Skip(True) |
---|
657 | elif event.GetKeyCode() == wx.WXK_CONTROL: |
---|
658 | event.Skip(True) |
---|
659 | elif event.GetKeyCode() == wx.WXK_SHIFT: |
---|
660 | event.Skip(True) |
---|
661 | elif event.GetKeyCode() == wx.WXK_DELETE: |
---|
662 | dlg = wx.MessageDialog(self, 'Delete Index Peak List?', ' ', wx.YES | wx.NO) |
---|
663 | try: |
---|
664 | result = dlg.ShowModal() |
---|
665 | if result == wx.ID_YES: |
---|
666 | oldlen = len(data) |
---|
667 | data = [] |
---|
668 | self.PatternTree.SetItemPyData(IndexId,data) |
---|
669 | self.dataDisplay.Clear() |
---|
670 | self.dataDisplay.Destroy() |
---|
671 | self.IndexPeaksTable = [] |
---|
672 | finally: |
---|
673 | dlg.Destroy() |
---|
674 | elif colList: |
---|
675 | self.dataDisplay.ClearSelection() |
---|
676 | key = event.GetKeyCode() |
---|
677 | for col in colList: |
---|
678 | if self.IndexPeaksTable.GetTypeName(0,col) == wg.GRID_VALUE_BOOL: |
---|
679 | if key == 89: #'Y' |
---|
680 | for row in range(self.IndexPeaksTable.GetNumberRows()): data[row][col]=True |
---|
681 | elif key == 78: #'N' |
---|
682 | for row in range(self.IndexPeaksTable.GetNumberRows()): data[row][col]=False |
---|
683 | |
---|
684 | if self.dataDisplay: |
---|
685 | self.dataDisplay.Destroy() |
---|
686 | self.dataFrame.setSizePosLeft([500,300]) |
---|
687 | self.dataFrame.SetMenuBar(self.dataFrame.BlankMenu) |
---|
688 | inst = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,self.PatternId, 'Instrument Parameters'))[1] |
---|
689 | self.IndexPeaksTable = [] |
---|
690 | if not data: |
---|
691 | peaks = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,self.PatternId, 'Peak List')) |
---|
692 | for peak in peaks: |
---|
693 | dsp = inst[1]/(2.0*sind(peak[0]/2.0)) |
---|
694 | data.append([peak[0],peak[2],True,False,0,0,0,dsp,0.0]) |
---|
695 | else: |
---|
696 | cells = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,self.PatternId, 'Unit Cells List')) |
---|
697 | if cells: |
---|
698 | cellist = cells[2] |
---|
699 | dmin = cells[3] |
---|
700 | self.HKL = [] |
---|
701 | for i,cell in enumerate(cellist): |
---|
702 | if cell[-1]: |
---|
703 | ibrav = cell[2] |
---|
704 | A = G2cmp.cell2A(cell[3:9]) |
---|
705 | self.HKL = G2cmp.GenHBravais(dmin,ibrav,A) |
---|
706 | G2cmp.IndexPeaks(data,self.HKL) |
---|
707 | for hkl in self.HKL: |
---|
708 | hkl.append(2.0*asind(inst[1]/(2.*hkl[3]))) |
---|
709 | rowLabels = [] |
---|
710 | for i in range(len(data)): rowLabels.append(str(i+1)) |
---|
711 | colLabels = ['position','intensity','use','indexed','h','k','l','d-obs','d-calc'] |
---|
712 | Types = [wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_FLOAT+':10,1',wg.GRID_VALUE_BOOL, |
---|
713 | wg.GRID_VALUE_BOOL,wg.GRID_VALUE_LONG,wg.GRID_VALUE_LONG,wg.GRID_VALUE_LONG, |
---|
714 | wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_FLOAT+':10,5'] |
---|
715 | self.PatternTree.SetItemPyData(IndexId,data) |
---|
716 | self.IndexPeaksTable = Table(data,rowLabels=rowLabels,colLabels=colLabels,types=Types) |
---|
717 | self.dataFrame.SetLabel('Index Peak List') |
---|
718 | self.dataDisplay = GSGrid(parent=self.dataFrame) |
---|
719 | self.dataDisplay.SetTable(self.IndexPeaksTable, True) |
---|
720 | self.dataDisplay.Bind(wg.EVT_GRID_CELL_CHANGE, RefreshIndexPeaksGrid) |
---|
721 | self.dataDisplay.Bind(wx.EVT_KEY_DOWN, KeyEditPickGrid) |
---|
722 | self.dataDisplay.SetMargins(0,0) |
---|
723 | self.dataDisplay.AutoSizeColumns(False) |
---|
724 | |
---|
725 | def UpdateUnitCellsGrid(self, data): |
---|
726 | UnitCellsId = GetPatternTreeItemId(self,self.PatternId, 'Unit Cells List') |
---|
727 | bravaisSymb = ['Fm3m','Im3m','Pm3m','R3-H','P6/mmm','I4/mmm', |
---|
728 | 'P4/mmm','Fmmm','Immm','Cmmm','Pmmm','C2/m','P2/m','P1'] |
---|
729 | |
---|
730 | def OnRefineCell(event): |
---|
731 | def cellPrint(ibrav,A): |
---|
732 | cell = G2cmp.A2cell(A) |
---|
733 | Vol = G2cmp.calc_V(A) |
---|
734 | if ibrav in [0,1,2]: |
---|
735 | print "%s%10.6f" % ('a =',cell[0]) |
---|
736 | elif ibrav in [3,4,5,6]: |
---|
737 | print "%s%10.6f %s%10.6f %s%12.3f" % ('a =',cell[0],' c =',cell[2],' volume =',Vol) |
---|
738 | elif ibrav in [7,8,9,10]: |
---|
739 | print "%s%10.6f %s%10.6f %s%10.6f %s%12.3f" % ('a =',cell[0],'b =',cell[1],'c =',cell[2],' volume =',Vol) |
---|
740 | elif ibrav in [11,12]: |
---|
741 | print "%s%10.6f %s%10.6f %s%10.6f %s%8.3f %s%12.3f" % ('a =',cell[0],'b =',cell[1],'c =',cell[2],'beta =',cell[4],' volume =',Vol) |
---|
742 | else: |
---|
743 | print "%s%10.6f %s%10.6f %s%10.6f" % ('a =',cell[0],'b =',cell[1],'c =',cell[2]) |
---|
744 | print "%s%8.3f %s%8.3f %s%8.3f %s%12.3f" % ('alpha =',cell[3],'beta =',cell[4],'gamma =',cell[5],' volume =',Vol) |
---|
745 | |
---|
746 | bravaisSymb = ['Fm3m','Im3m','Pm3m','R3-H','P6/mmm','I4/mmm', |
---|
747 | 'P4/mmm','Fmmm','Immm','Cmmm','Pmmm','C2/m','P2/m','P1'] |
---|
748 | PatternId = self.PatternId |
---|
749 | PickId = self.PickId |
---|
750 | peaks = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,PatternId, 'Index Peak List')) |
---|
751 | if not peaks: |
---|
752 | self.ErrorDialog('No peaks!', 'Nothing to refine!') |
---|
753 | return |
---|
754 | print 'Refine cell' |
---|
755 | inst = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,PatternId, 'Instrument Parameters'))[1] |
---|
756 | controls,bravais,cells,dmin = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,PatternId, 'Unit Cells List')) |
---|
757 | cell = controls[6:12] |
---|
758 | A = G2cmp.cell2A(cell) |
---|
759 | print controls[5] |
---|
760 | ibrav = bravaisSymb.index(controls[5]) |
---|
761 | dmin = G2cmp.getDmin(peaks)-0.05 |
---|
762 | Lhkl,M20,X20 = G2cmp.refinePeaks(peaks,ibrav,A) |
---|
763 | controls[6:12] = G2cmp.A2cell(A) |
---|
764 | controls[12] = G2cmp.calc_V(A) |
---|
765 | data = [controls,bravais,cells,dmin] |
---|
766 | self.PatternTree.SetItemPyData(GetPatternTreeItemId(self,PatternId, 'Unit Cells List'),data) |
---|
767 | self.HKL = G2cmp.GenHBravais(dmin,ibrav,A) |
---|
768 | UpdateUnitCellsGrid(self,data) |
---|
769 | print "%s%10.3f" % ('refinement M20 = ',M20) |
---|
770 | print 'unindexed lines = ',X20 |
---|
771 | cellPrint(ibrav,A) |
---|
772 | for hkl in self.HKL: |
---|
773 | hkl.append(2.0*asind(inst[1]/(2.*hkl[3]))) |
---|
774 | if 'PKS' in self.PatternTree.GetItemText(self.PatternId): |
---|
775 | G2plt.PlotPowderLines(self) |
---|
776 | else: |
---|
777 | G2plt.PlotPatterns(self) |
---|
778 | |
---|
779 | def OnIndexPeaks(event): |
---|
780 | PatternId = self.PatternId |
---|
781 | peaks = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,PatternId, 'Index Peak List')) |
---|
782 | if not peaks: |
---|
783 | self.ErrorDialog('No peaks!', 'Nothing to index!') |
---|
784 | return |
---|
785 | inst = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,PatternId, 'Instrument Parameters'))[1] |
---|
786 | print 'Peak Indexing' |
---|
787 | try: |
---|
788 | controls,bravais,cells,dmin = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,PatternId, 'Unit Cells List')) |
---|
789 | cells = [] |
---|
790 | except ValueError: |
---|
791 | self.ErrorDialog('Error','Need to set controls in Unit Cell List first') |
---|
792 | return |
---|
793 | if True not in bravais: |
---|
794 | self.ErrorDialog('Error','No Bravais lattices selected') |
---|
795 | return |
---|
796 | self.dataFrame.IndexPeaks.Enable(False) |
---|
797 | self.dataFrame.CopyCell.Enable(False) |
---|
798 | OK,dmin,cells = G2cmp.DoIndexPeaks(peaks,inst,controls,bravais) |
---|
799 | if OK: |
---|
800 | data = [controls,bravais,cells,dmin] |
---|
801 | self.PatternTree.SetItemPyData(GetPatternTreeItemId(self,PatternId, 'Unit Cells List'),data) |
---|
802 | UpdateUnitCellsGrid(self,data) |
---|
803 | bestCell = cells[0] |
---|
804 | if bestCell[0] > 10.: |
---|
805 | self.HKL = G2cmp.GenHBravais(dmin,bestCell[2],G2cmp.cell2A(bestCell[3:9])) |
---|
806 | for hkl in self.HKL: |
---|
807 | hkl.append(2.0*asind(inst[1]/(2.*hkl[3]))) |
---|
808 | if 'PKS' in self.PatternTree.GetItemText(self.PatternId): |
---|
809 | G2plt.PlotPowderLines(self) |
---|
810 | else: |
---|
811 | G2plt.PlotPatterns(self) |
---|
812 | self.dataFrame.CopyCell.Enable(True) |
---|
813 | self.dataFrame.IndexPeaks.Enable(True) |
---|
814 | |
---|
815 | def CopyUnitCell(event): |
---|
816 | controls,bravais,cells,dmin = self.PatternTree.GetItemPyData(UnitCellsId) |
---|
817 | for Cell in cells: |
---|
818 | if Cell[-1]: |
---|
819 | break |
---|
820 | cell = Cell[2:9] |
---|
821 | controls[4] = 1 |
---|
822 | controls[5] = bravaisSymb[cell[0]] |
---|
823 | controls[6:12] = cell[1:8] |
---|
824 | controls[12] = G2cmp.calc_V(G2cmp.cell2A(controls[6:12])) |
---|
825 | for i in range(4,13): |
---|
826 | self.UnitCellsTable.SetValue(i,1,controls[i]) |
---|
827 | self.PatternTree.SetItemPyData(UnitCellsId,[controls,bravais,cells,dmin]) |
---|
828 | self.dataDisplay.ForceRefresh() |
---|
829 | self.dataFrame.RefineCell.Enable(True) |
---|
830 | |
---|
831 | def RefreshUnitCellsGrid(event): |
---|
832 | cells,dmin = self.PatternTree.GetItemPyData(UnitCellsId)[2:] |
---|
833 | r,c = event.GetRow(),event.GetCol() |
---|
834 | if cells: |
---|
835 | if c == 6: |
---|
836 | for i in range(min(self.UnitCellsTable.GetNumberRows(),len(cells))): |
---|
837 | cells[i][-1] = False |
---|
838 | self.UnitCellsTable.SetValue(i,c,0) |
---|
839 | self.UnitCellsTable.SetValue(r,c,1) |
---|
840 | cells[r][-1] = True |
---|
841 | ibrav = cells[r][2] |
---|
842 | A = G2cmp.cell2A(cells[r][3:9]) |
---|
843 | self.HKL = G2cmp.GenHBravais(dmin,ibrav,A) |
---|
844 | for hkl in self.HKL: |
---|
845 | hkl.append(2.0*asind(inst[1]/(2.*hkl[3]))) |
---|
846 | if 'PKS' in self.PatternTree.GetItemText(self.PatternId): |
---|
847 | G2plt.PlotPowderLines(self) |
---|
848 | else: |
---|
849 | G2plt.PlotPatterns(self) |
---|
850 | controls = [] |
---|
851 | bravais = [0,0,0,0,0,0,0, 0,0,0,0,0,0,0] |
---|
852 | table = self.UnitCellsTable.GetData() |
---|
853 | for i,row in enumerate(table): |
---|
854 | if i in [0,4]: |
---|
855 | if row[1]: |
---|
856 | controls.append(1) |
---|
857 | else: |
---|
858 | controls.append(0) |
---|
859 | elif i in [1,3]: |
---|
860 | controls.append(float(row[1])) |
---|
861 | elif i in [2]: |
---|
862 | controls.append(int(row[1])) |
---|
863 | elif i in [5]: |
---|
864 | controls.append(row[1]) |
---|
865 | elif i in [6,7,8,9,10,11]: |
---|
866 | if controls[5] in bravaisSymb[:3]: #cubic |
---|
867 | if i in [6]: |
---|
868 | controls.append(float(row[1])) |
---|
869 | controls.append(float(row[1])) |
---|
870 | controls.append(float(row[1])) |
---|
871 | controls.append(90.) |
---|
872 | controls.append(90.) |
---|
873 | controls.append(90.) |
---|
874 | elif controls[5] in bravaisSymb[3:7]: #hexagonal & tetragonal |
---|
875 | if i in [6]: |
---|
876 | controls.append(float(row[1])) |
---|
877 | controls.append(float(row[1])) |
---|
878 | elif i in [8]: |
---|
879 | controls.append(float(row[1])) |
---|
880 | controls.append(90.) |
---|
881 | controls.append(90.) |
---|
882 | if controls[5] in bravaisSymb[3:5]: #hexagonal |
---|
883 | controls.append(120.) |
---|
884 | else: #tetragonal |
---|
885 | controls.append(90.) |
---|
886 | elif controls[5] in bravaisSymb[7:13]: #orthorhombic & monoclinic |
---|
887 | if i in [6,7,8]: |
---|
888 | controls.append(float(row[1])) |
---|
889 | if i in [9,10,11]: |
---|
890 | if controls[5] in bravaisSymb[7:11]: |
---|
891 | controls.append(90.) |
---|
892 | controls.append(90.) |
---|
893 | controls.append(90.) |
---|
894 | break |
---|
895 | else: |
---|
896 | if i in [9,11]: |
---|
897 | controls.append(90.) |
---|
898 | else: |
---|
899 | controls.append(float(row[1])) |
---|
900 | else: #triclinic |
---|
901 | controls.append(float(row[1])) |
---|
902 | controls.append(G2cmp.calc_V(G2cmp.cell2A(controls[6:12]))) #volume |
---|
903 | for i,row in enumerate(table): |
---|
904 | if i < 14: |
---|
905 | bravais[i] = int(row[2]) |
---|
906 | else: |
---|
907 | break |
---|
908 | if controls[4]: |
---|
909 | for i in range(6,13): |
---|
910 | self.UnitCellsTable.SetValue(i,1,controls[i]) |
---|
911 | self.dataDisplay.ForceRefresh() |
---|
912 | if controls[4] and not False in controls[6:12]: |
---|
913 | self.dataFrame.RefineCell.Enable(True) |
---|
914 | else: |
---|
915 | self.dataFrame.RefineCell.Enable(False) |
---|
916 | data = [controls,bravais,cells,dmin] |
---|
917 | self.PatternTree.SetItemPyData(UnitCellsId,data) |
---|
918 | |
---|
919 | if self.dataDisplay: |
---|
920 | self.dataDisplay.Destroy() |
---|
921 | self.dataFrame.SetMenuBar(self.dataFrame.IndexMenu) |
---|
922 | self.Bind(wx.EVT_MENU, OnIndexPeaks, id=wxID_INDEXPEAKS) |
---|
923 | self.Bind(wx.EVT_MENU, CopyUnitCell, id=wxID_COPYCELL) |
---|
924 | self.Bind(wx.EVT_MENU, OnRefineCell, id=wxID_REFINECELL) |
---|
925 | self.UnitCellsTable = [] |
---|
926 | controls,bravais,cells,dmin = data |
---|
927 | if cells: |
---|
928 | self.dataFrame.setSizePosLeft([900,320]) |
---|
929 | else: |
---|
930 | self.dataFrame.setSizePosLeft([280,320]) |
---|
931 | if len(controls) < 13: |
---|
932 | controls.append(G2cmp.calc_V(G2cmp.cell2A(controls[6:12]))) |
---|
933 | self.PatternTree.SetItemPyData(UnitCellsId,data) |
---|
934 | inst = self.PatternTree.GetItemPyData(GetPatternTreeItemId(self,self.PatternId, 'Instrument Parameters'))[1] |
---|
935 | if cells: |
---|
936 | colLabels = ['controls','value','try','Bravais cells', |
---|
937 | 'M20','X20','use','Bravais','a','b','c','alpha','beta','gamma','Volume'] |
---|
938 | Types = [wg.GRID_VALUE_STRING,wg.GRID_VALUE_FLOAT+":10,1", |
---|
939 | wg.GRID_VALUE_BOOL,wg.GRID_VALUE_STRING,wg.GRID_VALUE_FLOAT+':10,2', |
---|
940 | wg.GRID_VALUE_NUMBER,wg.GRID_VALUE_BOOL,wg.GRID_VALUE_STRING, |
---|
941 | wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_FLOAT+':10,5', |
---|
942 | wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_FLOAT+':10,3', |
---|
943 | wg.GRID_VALUE_FLOAT+':10,2'] |
---|
944 | else: |
---|
945 | colLabels = ['controls','value','try','Bravais cells'] |
---|
946 | Types = [wg.GRID_VALUE_STRING,wg.GRID_VALUE_STRING, |
---|
947 | wg.GRID_VALUE_BOOL,wg.GRID_VALUE_STRING] |
---|
948 | controlNames = ['Vary zero?','Max zero error','Max Nc/Nobs','Start volume','refine cell?', |
---|
949 | 'bravais','a=','b=','c=','alpha=','beta=','gamma=','Volume='] |
---|
950 | bravaisNames = ['Cubic-F','Cubic-I','Cubic-P','Trigonal-R','Trigonal/Hexagonal-P', |
---|
951 | 'Tetragonal-I','Tetragonal-P','Orthorhombic-F','Orthorhombic-I','Orthorhombic-C', |
---|
952 | 'Orthorhombic-P','Monoclinic-C','Monoclinic-P','Triclinic'] |
---|
953 | rowLabels = [] |
---|
954 | table = [] |
---|
955 | numRows = max(len(bravais),len(cells)) |
---|
956 | for i in range(numRows): |
---|
957 | rowLabels.append('') |
---|
958 | if i < 13: |
---|
959 | row = [controlNames[i],controls[i],bravais[i],bravaisSymb[i]] |
---|
960 | elif i < 14: |
---|
961 | row = ['','',bravais[i],bravaisSymb[i]] |
---|
962 | else: |
---|
963 | row = ['','','',''] |
---|
964 | if cells: |
---|
965 | if i < len(cells): |
---|
966 | cell = cells[i] |
---|
967 | row += cell[0:2]+[cell[-1]]+[bravaisSymb[cell[2]]]+cell[3:10] |
---|
968 | if cell[-1]: |
---|
969 | A = G2cmp.cell2A(cell[3:9]) |
---|
970 | self.HKL = G2cmp.GenHBravais(dmin,cell[2],A) |
---|
971 | for hkl in self.HKL: |
---|
972 | hkl.append(2.0*asind(inst[1]/(2.*hkl[3]))) |
---|
973 | else: |
---|
974 | row += 14*['',] |
---|
975 | table.append(row) |
---|
976 | self.UnitCellsTable = Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types) |
---|
977 | self.dataFrame.SetLabel('Unit Cells List') |
---|
978 | self.dataDisplay = GSGrid(parent=self.dataFrame) |
---|
979 | self.dataDisplay.SetTable(self.UnitCellsTable, True) |
---|
980 | self.dataDisplay.Bind(wg.EVT_GRID_CELL_CHANGE, RefreshUnitCellsGrid) |
---|
981 | self.dataDisplay.SetMargins(0,0) |
---|
982 | self.dataDisplay.SetRowLabelSize(0) |
---|
983 | self.dataDisplay.SetCellRenderer(0,1,wg.GridCellBoolRenderer()) |
---|
984 | self.dataDisplay.SetCellEditor(0,1,wg.GridCellBoolEditor()) |
---|
985 | self.dataDisplay.SetCellRenderer(1,1,wg.GridCellFloatRenderer(5,2)) |
---|
986 | self.dataDisplay.SetCellEditor(1,1,wg.GridCellFloatEditor(5,0)) |
---|
987 | self.dataDisplay.SetCellRenderer(2,1,wg.GridCellNumberRenderer()) |
---|
988 | self.dataDisplay.SetCellEditor(2,1,wg.GridCellNumberEditor(1,10)) |
---|
989 | self.dataDisplay.SetCellRenderer(3,1,wg.GridCellFloatRenderer(5,0)) |
---|
990 | self.dataDisplay.SetCellEditor(3,1,wg.GridCellFloatEditor(5,2)) |
---|
991 | self.dataDisplay.SetCellRenderer(4,1,wg.GridCellBoolRenderer()) |
---|
992 | self.dataDisplay.SetCellEditor(4,1,wg.GridCellBoolEditor()) |
---|
993 | self.dataDisplay.SetCellRenderer(5,1,wg.GridCellStringRenderer()) |
---|
994 | self.dataDisplay.SetCellEditor(5,1,wg.GridCellChoiceEditor(bravaisSymb,False)) |
---|
995 | for i in range(6,9): |
---|
996 | self.dataDisplay.SetCellRenderer(i,1,wg.GridCellFloatRenderer(10,5)) |
---|
997 | self.dataDisplay.SetCellEditor(i,1,wg.GridCellFloatEditor(10,5)) |
---|
998 | for i in range(9,13): |
---|
999 | self.dataDisplay.SetCellRenderer(i,1,wg.GridCellFloatRenderer(10,3)) |
---|
1000 | self.dataDisplay.SetCellEditor(i,1,wg.GridCellFloatEditor(10,3)) |
---|
1001 | for i in range(14): |
---|
1002 | self.dataDisplay.SetReadOnly(i,0,isReadOnly=True) |
---|
1003 | self.dataDisplay.SetReadOnly(i,3,isReadOnly=True) |
---|
1004 | if cells: |
---|
1005 | self.dataFrame.CopyCell.Enable(True) |
---|
1006 | for r in range(max(len(cells),14)): |
---|
1007 | if r > 12: |
---|
1008 | self.dataDisplay.SetCellRenderer(r,0,wg.GridCellStringRenderer()) |
---|
1009 | self.dataDisplay.SetCellRenderer(r,1,wg.GridCellStringRenderer()) |
---|
1010 | if r > 13: |
---|
1011 | self.dataDisplay.SetCellRenderer(r,2,wg.GridCellStringRenderer()) |
---|
1012 | for c in range(4,15): |
---|
1013 | if r >= len(cells): |
---|
1014 | self.dataDisplay.SetCellRenderer(r,c,wg.GridCellStringRenderer()) |
---|
1015 | if c != 6: |
---|
1016 | self.dataDisplay.SetReadOnly(r,c,isReadOnly=True) |
---|
1017 | self.dataDisplay.AutoSizeColumns(False) |
---|
1018 | if controls[4] and not False in controls[6:12]: |
---|
1019 | self.dataFrame.RefineCell.Enable(True) |
---|
1020 | else: |
---|
1021 | self.dataFrame.RefineCell.Enable(False) |
---|
1022 | |
---|
1023 | def UpdateHKLControls(self,data): |
---|
1024 | |
---|
1025 | def OnScaleSlider(event): |
---|
1026 | scale = int(scaleSel.GetValue())/1000. |
---|
1027 | scaleSel.SetValue(int(scale*1000.)) |
---|
1028 | data['Scale'] = scale*10. |
---|
1029 | G2plt.PlotSngl(self) |
---|
1030 | |
---|
1031 | def OnLayerSlider(event): |
---|
1032 | layer = layerSel.GetValue() |
---|
1033 | data['Layer'] = layer |
---|
1034 | G2plt.PlotSngl(self) |
---|
1035 | |
---|
1036 | def OnSelZone(event): |
---|
1037 | data['Zone'] = zoneSel.GetValue() |
---|
1038 | G2plt.PlotSngl(self) |
---|
1039 | |
---|
1040 | def OnSelType(event): |
---|
1041 | data['Type'] = typeSel.GetValue() |
---|
1042 | G2plt.PlotSngl(self) |
---|
1043 | |
---|
1044 | def SetStatusLine(): |
---|
1045 | Status.SetStatusText("look at me!!!") |
---|
1046 | |
---|
1047 | if self.dataDisplay: |
---|
1048 | self.dataDisplay.Destroy() |
---|
1049 | Status = self.dataFrame.CreateStatusBar() |
---|
1050 | SetStatusLine() |
---|
1051 | zones = ['100','010','001'] |
---|
1052 | HKLmax = data['HKLmax'] |
---|
1053 | HKLmin = data['HKLmin'] |
---|
1054 | if data['ifFc']: |
---|
1055 | typeChoices = ['Fosq','Fo','|DFsq|/sig','|DFsq|>sig','|DFsq|>3sig'] |
---|
1056 | else: |
---|
1057 | typeChoices = ['Fosq','Fo'] |
---|
1058 | self.dataDisplay = wx.Panel(self.dataFrame) |
---|
1059 | self.dataFrame.SetMenuBar(self.dataFrame.BlankMenu) |
---|
1060 | mainSizer = wx.BoxSizer(wx.VERTICAL) |
---|
1061 | mainSizer.Add((5,10),0) |
---|
1062 | |
---|
1063 | scaleSizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1064 | scaleSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Scale'),0, |
---|
1065 | wx.ALIGN_CENTER_VERTICAL|wx.EXPAND) |
---|
1066 | scaleSel = wx.Slider(parent=self.dataDisplay,maxValue=1000,minValue=100, |
---|
1067 | style=wx.SL_HORIZONTAL,value=int(data['Scale']*100)) |
---|
1068 | scaleSizer.Add(scaleSel,1,wx.EXPAND|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
---|
1069 | scaleSel.SetLineSize(100) |
---|
1070 | scaleSel.SetPageSize(900) |
---|
1071 | scaleSel.Bind(wx.EVT_SLIDER, OnScaleSlider) |
---|
1072 | mainSizer.Add(scaleSizer,1,wx.EXPAND|wx.RIGHT) |
---|
1073 | |
---|
1074 | zoneSizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1075 | zoneSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Zone '),0, |
---|
1076 | wx.ALIGN_CENTER_VERTICAL) |
---|
1077 | zoneSel = wx.ComboBox(parent=self.dataDisplay,value=data['Zone'],choices=['100','010','001'], |
---|
1078 | style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
1079 | zoneSel.Bind(wx.EVT_COMBOBOX, OnSelZone) |
---|
1080 | zoneSizer.Add(zoneSel,0,wx.ALIGN_CENTER_VERTICAL) |
---|
1081 | zoneSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Plot type '),0, |
---|
1082 | wx.ALIGN_CENTER_VERTICAL) |
---|
1083 | typeSel = wx.ComboBox(parent=self.dataDisplay,value=data['Type'],choices=typeChoices, |
---|
1084 | style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
1085 | typeSel.Bind(wx.EVT_COMBOBOX, OnSelType) |
---|
1086 | zoneSizer.Add(typeSel,0,wx.ALIGN_CENTER_VERTICAL) |
---|
1087 | zoneSizer.Add((10,0),0) |
---|
1088 | mainSizer.Add(zoneSizer,1,wx.EXPAND|wx.RIGHT) |
---|
1089 | |
---|
1090 | izone = zones.index(data['Zone']) |
---|
1091 | layerSizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1092 | layerSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Layer'),0, |
---|
1093 | wx.ALIGN_CENTER_VERTICAL|wx.EXPAND) |
---|
1094 | layerSel = wx.Slider(parent=self.dataDisplay,maxValue=HKLmax[izone],minValue=HKLmin[izone], |
---|
1095 | style=wx.SL_HORIZONTAL|wx.SL_AUTOTICKS|wx.SL_LABELS,value=0) |
---|
1096 | layerSel.SetLineSize(1) |
---|
1097 | layerSel.SetLineSize(5) |
---|
1098 | layerSel.Bind(wx.EVT_SLIDER, OnLayerSlider) |
---|
1099 | layerSizer.Add(layerSel,1,wx.EXPAND|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
---|
1100 | layerSizer.Add((10,0),0) |
---|
1101 | mainSizer.Add(layerSizer,1,wx.EXPAND|wx.RIGHT) |
---|
1102 | |
---|
1103 | |
---|
1104 | mainSizer.Layout() |
---|
1105 | self.dataDisplay.SetSizer(mainSizer) |
---|
1106 | self.dataDisplay.SetSize(mainSizer.Fit(self.dataFrame)) |
---|
1107 | self.dataFrame.setSizePosLeft(mainSizer.Fit(self.dataFrame)) |
---|
1108 | |
---|
1109 | def UpdateImageControls(self,data): |
---|
1110 | import ImageCalibrants as calFile |
---|
1111 | |
---|
1112 | def OnNewColorBar(event): |
---|
1113 | data['color'] = colSel.GetValue() |
---|
1114 | G2plt.PlotImage(self) |
---|
1115 | |
---|
1116 | def OnNewCalibrant(event): |
---|
1117 | data['calibrant'] = calSel.GetValue() |
---|
1118 | |
---|
1119 | def OnPixLimit(event): |
---|
1120 | data['pixLimit'] = int(pixLimit.GetValue()) |
---|
1121 | |
---|
1122 | def OnMaxSlider(event): |
---|
1123 | imax = int(maxSel.GetValue()) |
---|
1124 | delt = data['range'][0][1]-data['range'][0][0] |
---|
1125 | data['range'][1][1] = int((imax/100.)*delt)+data['range'][0][0] |
---|
1126 | G2plt.PlotImage(self) |
---|
1127 | |
---|
1128 | def OnMinSlider(event): |
---|
1129 | imin = int(minSel.GetValue()) |
---|
1130 | delt = data['range'][1][1]-data['range'][0][0] |
---|
1131 | data['range'][1][0] = int((imin/100.)*delt)+data['range'][0][0] |
---|
1132 | G2plt.PlotImage(self) |
---|
1133 | |
---|
1134 | def OnNumOutChans(event): |
---|
1135 | try: |
---|
1136 | numChans = int(outChan.GetValue()) |
---|
1137 | if numChans < 1: |
---|
1138 | raise ValueError |
---|
1139 | data['outChannels'] = numChans |
---|
1140 | except ValueError: |
---|
1141 | pass |
---|
1142 | outChan.SetValue(str(data['outChannels'])) #reset in case of error |
---|
1143 | |
---|
1144 | def OnNumOutAzms(event): |
---|
1145 | try: |
---|
1146 | numAzms = int(outAzim.GetValue()) |
---|
1147 | if numAzms < 1: |
---|
1148 | raise ValueError |
---|
1149 | data['outAzimuths'] = numAzms |
---|
1150 | except ValueError: |
---|
1151 | pass |
---|
1152 | outAzim.SetValue(str(data['outAzimuths'])) #reset in case of error |
---|
1153 | |
---|
1154 | def OnWavelength(event): |
---|
1155 | try: |
---|
1156 | wave = float(waveSel.GetValue()) |
---|
1157 | if wave < .01: |
---|
1158 | raise ValueError |
---|
1159 | data['wavelength'] = wave |
---|
1160 | except ValueError: |
---|
1161 | pass |
---|
1162 | waveSel.SetValue("%6.5f" % (data['wavelength'])) #reset in case of error |
---|
1163 | |
---|
1164 | def OnCutOff(event): |
---|
1165 | try: |
---|
1166 | cutoff = float(cutOff.GetValue()) |
---|
1167 | data['cutoff'] = cutoff |
---|
1168 | except ValueError: |
---|
1169 | pass |
---|
1170 | cutOff.SetValue("%.1f"%(data['cutoff'])) #reset in case of error |
---|
1171 | |
---|
1172 | def OnShowLines(event): |
---|
1173 | if data['showLines']: |
---|
1174 | data['showLines'] = False |
---|
1175 | else: |
---|
1176 | data['showLines'] = True |
---|
1177 | G2plt.PlotImage(self) |
---|
1178 | |
---|
1179 | def OnFullIntegrate(event): |
---|
1180 | if data['fullIntegrate']: |
---|
1181 | data['fullIntegrate'] = False |
---|
1182 | self.Lazim.SetEditable(True) |
---|
1183 | self.Razim.SetEditable(True) |
---|
1184 | else: |
---|
1185 | data['fullIntegrate'] = True |
---|
1186 | self.Lazim.SetEditable(False) |
---|
1187 | self.Razim.SetEditable(False) |
---|
1188 | G2plt.PlotImage(self) |
---|
1189 | |
---|
1190 | def OnSetDefault(event): |
---|
1191 | import copy |
---|
1192 | if data['setDefault']: |
---|
1193 | self.imageDefault = {} |
---|
1194 | data['setDefault'] = False |
---|
1195 | else: |
---|
1196 | self.imageDefault = copy.copy(data) |
---|
1197 | data['setDefault'] = True |
---|
1198 | |
---|
1199 | def OnIOtth(event): |
---|
1200 | Ltth = float(self.InnerTth.GetValue()) |
---|
1201 | Utth = float(self.OuterTth.GetValue()) |
---|
1202 | if Ltth > Utth: |
---|
1203 | G2cmp.SwapXY(Ltth,Utth) |
---|
1204 | data['IOtth'] = [Ltth,Utth] |
---|
1205 | self.InnerTth.SetValue("%8.2f" % (Ltth)) |
---|
1206 | self.OuterTth.SetValue("%8.2f" % (Utth)) |
---|
1207 | G2plt.PlotImage(self) |
---|
1208 | |
---|
1209 | def OnLRazim(event): |
---|
1210 | Lazm = int(self.Lazim.GetValue()) |
---|
1211 | Razm = int(self.Razim.GetValue()) |
---|
1212 | data['LRazimuth'] = [Lazm,Razm] |
---|
1213 | G2plt.PlotImage(self) |
---|
1214 | |
---|
1215 | def OnSetRings(event): |
---|
1216 | if data['setRings']: |
---|
1217 | data['setRings'] = False |
---|
1218 | else: |
---|
1219 | data['setRings'] = True |
---|
1220 | setRings.SetValue(data['setRings']) |
---|
1221 | G2plt.PlotImage(self) |
---|
1222 | |
---|
1223 | def OnClearCalib(event): |
---|
1224 | data['ring'] = [] |
---|
1225 | data['rings'] = [] |
---|
1226 | data['ellipses'] = [] |
---|
1227 | G2plt.PlotImage(self) |
---|
1228 | |
---|
1229 | def OnCalibrate(event): |
---|
1230 | data['setRings'] = False |
---|
1231 | setRings.SetValue(data['setRings']) |
---|
1232 | msg = \ |
---|
1233 | '''Select > 4 points on inner ring of image pattern. |
---|
1234 | Click right mouse button to select point. |
---|
1235 | Use left mouse button to delete point. |
---|
1236 | Press OK when done''' |
---|
1237 | dlg = wx.MessageDialog(self,msg,'Pick inner ring',wx.OK) |
---|
1238 | self.ifGetRing = True |
---|
1239 | dlg.ShowModal() |
---|
1240 | self.ifGetRing = False |
---|
1241 | |
---|
1242 | if G2cmp.ImageCalibrate(self,data): |
---|
1243 | Status.SetStatusText('Calibration successful') |
---|
1244 | cent = data['center'] |
---|
1245 | centText.SetValue(("%8.3f,%8.3f" % (cent[0],cent[1]))) |
---|
1246 | distSel.SetValue("%8.3f"%(data['distance'])) |
---|
1247 | tiltSel.SetValue("%9.3f"%(data['tilt'])) |
---|
1248 | rotSel.SetValue("%9.3f"%(data['rotation'])) |
---|
1249 | else: |
---|
1250 | Status.SetStatusText('Calibration failed') |
---|
1251 | |
---|
1252 | def OnIntegrate(event): |
---|
1253 | G2cmp.ImageIntegrate(self,data) |
---|
1254 | |
---|
1255 | def OnRefreshTA(event): |
---|
1256 | G2plt.PlotTRImage(self) |
---|
1257 | |
---|
1258 | colorList = [m for m in mpl.cm.datad.keys() if not m.endswith("_r")] |
---|
1259 | calList = [m for m in calFile.Calibrants.keys()] |
---|
1260 | if self.dataDisplay: |
---|
1261 | self.dataDisplay.Destroy() |
---|
1262 | self.dataFrame.SetMenuBar(self.dataFrame.ImageMenu) |
---|
1263 | Status = self.dataFrame.CreateStatusBar() |
---|
1264 | self.dataFrame.Bind(wx.EVT_MENU, OnCalibrate, id=wxID_IMCALIBRATE) |
---|
1265 | self.dataFrame.Bind(wx.EVT_MENU, OnClearCalib, id=wxID_IMCLEARCALIB) |
---|
1266 | self.dataFrame.Bind(wx.EVT_MENU, OnIntegrate, id=wxID_IMINTEGRATE) |
---|
1267 | self.dataFrame.Bind(wx.EVT_MENU, OnRefreshTA, id=wxID_IMREFRESHTA) |
---|
1268 | self.dataDisplay = wx.Panel(self.dataFrame) |
---|
1269 | mainSizer = wx.BoxSizer(wx.VERTICAL) |
---|
1270 | mainSizer.Add((5,10),0) |
---|
1271 | |
---|
1272 | maxSizer = wx.FlexGridSizer(2,2,0,5) |
---|
1273 | maxSizer.AddGrowableCol(1,1) |
---|
1274 | maxSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Max intensity'),0, |
---|
1275 | wx.ALIGN_CENTER_VERTICAL|wx.EXPAND) |
---|
1276 | maxSel = wx.Slider(parent=self.dataDisplay,style=wx.SL_HORIZONTAL, |
---|
1277 | value=int(100*data['range'][1][1]/(data['range'][0][1]-data['range'][0][0]))) |
---|
1278 | maxSizer.Add(maxSel,1,wx.EXPAND|wx.RIGHT) |
---|
1279 | maxSel.Bind(wx.EVT_SLIDER, OnMaxSlider) |
---|
1280 | maxSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Min intensity'),0, |
---|
1281 | wx.ALIGN_CENTER_VERTICAL|wx.EXPAND) |
---|
1282 | minSel = wx.Slider(parent=self.dataDisplay,style=wx.SL_HORIZONTAL, |
---|
1283 | value=int(100*data['range'][1][0]/(data['range'][1][1]-data['range'][0][0]))) |
---|
1284 | maxSizer.Add(minSel,1,wx.EXPAND|wx.RIGHT) |
---|
1285 | minSel.Bind(wx.EVT_SLIDER, OnMinSlider) |
---|
1286 | mainSizer.Add(maxSizer,1,wx.EXPAND|wx.RIGHT) |
---|
1287 | |
---|
1288 | comboSizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1289 | comboSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Color bar '),0, |
---|
1290 | wx.ALIGN_CENTER_VERTICAL) |
---|
1291 | colSel = wx.ComboBox(parent=self.dataDisplay,value=data['color'],choices=colorList, |
---|
1292 | style=wx.CB_READONLY|wx.CB_DROPDOWN|wx.CB_SORT) |
---|
1293 | colSel.Bind(wx.EVT_COMBOBOX, OnNewColorBar) |
---|
1294 | comboSizer.Add(colSel,0,wx.ALIGN_CENTER_VERTICAL) |
---|
1295 | |
---|
1296 | comboSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Calibrant '),0, |
---|
1297 | wx.ALIGN_CENTER_VERTICAL) |
---|
1298 | calSel = wx.ComboBox(parent=self.dataDisplay,value=data['calibrant'],choices=calList, |
---|
1299 | style=wx.CB_READONLY|wx.CB_DROPDOWN|wx.CB_SORT) |
---|
1300 | calSel.Bind(wx.EVT_COMBOBOX, OnNewCalibrant) |
---|
1301 | comboSizer.Add(calSel,0,wx.ALIGN_CENTER_VERTICAL) |
---|
1302 | comboSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Pixel search range '),0, |
---|
1303 | wx.ALIGN_CENTER_VERTICAL) |
---|
1304 | pixLimit = wx.ComboBox(parent=self.dataDisplay,value=str(data['pixLimit']),choices=['1','2','5','10','15','20'], |
---|
1305 | style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
1306 | pixLimit.Bind(wx.EVT_COMBOBOX, OnPixLimit) |
---|
1307 | comboSizer.Add(pixLimit,0,wx.ALIGN_CENTER_VERTICAL) |
---|
1308 | comboSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Min ring I/Ib '),0, |
---|
1309 | wx.ALIGN_CENTER_VERTICAL) |
---|
1310 | cutOff = wx.TextCtrl(parent=self.dataDisplay,value=("%.1f" % (data['cutoff'])), |
---|
1311 | style=wx.TE_PROCESS_ENTER) |
---|
1312 | cutOff.Bind(wx.EVT_TEXT_ENTER,OnCutOff) |
---|
1313 | comboSizer.Add(cutOff,0,wx.ALIGN_CENTER_VERTICAL) |
---|
1314 | |
---|
1315 | mainSizer.Add(comboSizer,0,wx.ALIGN_CENTER_HORIZONTAL) |
---|
1316 | mainSizer.Add((5,5),0) |
---|
1317 | |
---|
1318 | dataSizer = wx.FlexGridSizer(6,4,5,5) |
---|
1319 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Calibration coefficients'),0, |
---|
1320 | wx.ALIGN_CENTER_VERTICAL) |
---|
1321 | dataSizer.Add((5,0),0) |
---|
1322 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Integration coefficients'),0, |
---|
1323 | wx.ALIGN_CENTER_VERTICAL) |
---|
1324 | dataSizer.Add((5,0),0) |
---|
1325 | |
---|
1326 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Beam center X,Y'),0, |
---|
1327 | wx.ALIGN_CENTER_VERTICAL) |
---|
1328 | cent = data['center'] |
---|
1329 | centText = wx.TextCtrl(parent=self.dataDisplay,value=("%8.3f,%8.3f" % (cent[0],cent[1])),style=wx.TE_READONLY) |
---|
1330 | dataSizer.Add(centText,0,wx.ALIGN_CENTER_VERTICAL) |
---|
1331 | |
---|
1332 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Inner/Outer 2-theta'),0, |
---|
1333 | wx.ALIGN_CENTER_VERTICAL) |
---|
1334 | |
---|
1335 | #temporary fixes |
---|
1336 | if 'IOtth' not in data: |
---|
1337 | del data['IOradii'] |
---|
1338 | data['IOtth'] = [2.0,5.0] |
---|
1339 | if 'outAzimuths' not in data: |
---|
1340 | data['outAzimuths'] = 1 |
---|
1341 | |
---|
1342 | IOtth = data['IOtth'] |
---|
1343 | littleSizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1344 | self.InnerTth = wx.TextCtrl(parent=self.dataDisplay, |
---|
1345 | value=("%8.2f" % (IOtth[0])),style=wx.TE_PROCESS_ENTER) |
---|
1346 | self.InnerTth.Bind(wx.EVT_TEXT_ENTER,OnIOtth) |
---|
1347 | littleSizer.Add(self.InnerTth,0,wx.ALIGN_CENTER_VERTICAL) |
---|
1348 | self.OuterTth = wx.TextCtrl(parent=self.dataDisplay, |
---|
1349 | value=("%8.2f" % (IOtth[1])),style=wx.TE_PROCESS_ENTER) |
---|
1350 | self.OuterTth.Bind(wx.EVT_TEXT_ENTER,OnIOtth) |
---|
1351 | littleSizer.Add(self.OuterTth,0,wx.ALIGN_CENTER_VERTICAL) |
---|
1352 | dataSizer.Add(littleSizer,0,) |
---|
1353 | |
---|
1354 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Wavelength'),0, |
---|
1355 | wx.ALIGN_CENTER_VERTICAL) |
---|
1356 | waveSel = wx.TextCtrl(parent=self.dataDisplay,value=("%6.5f" % (data['wavelength'])), |
---|
1357 | style=wx.TE_PROCESS_ENTER) |
---|
1358 | waveSel.Bind(wx.EVT_TEXT_ENTER,OnWavelength) |
---|
1359 | dataSizer.Add(waveSel,0,wx.ALIGN_CENTER_VERTICAL) |
---|
1360 | |
---|
1361 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Start/End azimuth'),0, |
---|
1362 | wx.ALIGN_CENTER_VERTICAL) |
---|
1363 | LRazim = data['LRazimuth'] |
---|
1364 | littleSizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1365 | self.Lazim = wx.TextCtrl(parent=self.dataDisplay, |
---|
1366 | value=("%6d" % (LRazim[0])),style=wx.TE_PROCESS_ENTER) |
---|
1367 | self.Lazim.Bind(wx.EVT_TEXT_ENTER,OnLRazim) |
---|
1368 | littleSizer.Add(self.Lazim,0,wx.ALIGN_CENTER_VERTICAL) |
---|
1369 | self.Razim = wx.TextCtrl(parent=self.dataDisplay, |
---|
1370 | value=("%6d" % (LRazim[1])),style=wx.TE_PROCESS_ENTER) |
---|
1371 | self.Razim.Bind(wx.EVT_TEXT_ENTER,OnLRazim) |
---|
1372 | littleSizer.Add(self.Razim,0,wx.ALIGN_CENTER_VERTICAL) |
---|
1373 | dataSizer.Add(littleSizer,0,) |
---|
1374 | |
---|
1375 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Distance'),0, |
---|
1376 | wx.ALIGN_CENTER_VERTICAL) |
---|
1377 | distSel = wx.TextCtrl(parent=self.dataDisplay,value=("%8.3f"%(data['distance'])),style=wx.TE_READONLY) |
---|
1378 | dataSizer.Add(distSel,0,wx.ALIGN_CENTER_VERTICAL) |
---|
1379 | |
---|
1380 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' No. 2-theta/azimuth bins'),0, |
---|
1381 | wx.ALIGN_CENTER_VERTICAL) |
---|
1382 | littleSizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1383 | outChan = wx.TextCtrl(parent=self.dataDisplay,value=str(data['outChannels']),style=wx.TE_PROCESS_ENTER) |
---|
1384 | outChan.Bind(wx.EVT_TEXT_ENTER,OnNumOutChans) |
---|
1385 | littleSizer.Add(outChan,0,wx.ALIGN_CENTER_VERTICAL) |
---|
1386 | outAzim = wx.TextCtrl(parent=self.dataDisplay,value=str(data['outAzimuths']),style=wx.TE_PROCESS_ENTER) |
---|
1387 | outAzim.Bind(wx.EVT_TEXT_ENTER,OnNumOutAzms) |
---|
1388 | littleSizer.Add(outAzim,0,wx.ALIGN_CENTER_VERTICAL) |
---|
1389 | dataSizer.Add(littleSizer,0,) |
---|
1390 | |
---|
1391 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Tilt angle'),0, |
---|
1392 | wx.ALIGN_CENTER_VERTICAL) |
---|
1393 | tiltSel = wx.TextCtrl(parent=self.dataDisplay,value=("%9.3f"%(data['tilt'])),style=wx.TE_READONLY) |
---|
1394 | dataSizer.Add(tiltSel,0,wx.ALIGN_CENTER_VERTICAL) |
---|
1395 | showLines = wx.CheckBox(parent=self.dataDisplay,label='Show integration limits?') |
---|
1396 | dataSizer.Add(showLines,0) |
---|
1397 | showLines.Bind(wx.EVT_CHECKBOX, OnShowLines) |
---|
1398 | showLines.SetValue(data['showLines']) |
---|
1399 | fullIntegrate = wx.CheckBox(parent=self.dataDisplay,label='Do full integration?') |
---|
1400 | dataSizer.Add(fullIntegrate,0) |
---|
1401 | fullIntegrate.Bind(wx.EVT_CHECKBOX, OnFullIntegrate) |
---|
1402 | fullIntegrate.SetValue(data['fullIntegrate']) |
---|
1403 | |
---|
1404 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Tilt rotation'),0, |
---|
1405 | wx.ALIGN_CENTER_VERTICAL) |
---|
1406 | rotSel = wx.TextCtrl(parent=self.dataDisplay,value=("%9.3f"%(data['rotation'])),style=wx.TE_READONLY) |
---|
1407 | dataSizer.Add(rotSel,0,wx.ALIGN_CENTER_VERTICAL) |
---|
1408 | setDefault = wx.CheckBox(parent=self.dataDisplay,label='Use as default for all images?') |
---|
1409 | dataSizer.Add(setDefault,0) |
---|
1410 | setDefault.Bind(wx.EVT_CHECKBOX, OnSetDefault) |
---|
1411 | setDefault.SetValue(data['setDefault']) |
---|
1412 | setRings = wx.CheckBox(parent=self.dataDisplay,label='Show ring picks?') |
---|
1413 | dataSizer.Add(setRings,0) |
---|
1414 | setRings.Bind(wx.EVT_CHECKBOX, OnSetRings) |
---|
1415 | setRings.SetValue(data['setRings']) |
---|
1416 | |
---|
1417 | mainSizer.Add(dataSizer,0) |
---|
1418 | |
---|
1419 | mainSizer.Layout() |
---|
1420 | self.dataDisplay.SetSizer(mainSizer) |
---|
1421 | self.dataDisplay.SetSize(mainSizer.Fit(self.dataFrame)) |
---|
1422 | self.dataFrame.setSizePosLeft(mainSizer.Fit(self.dataFrame)) |
---|
1423 | |
---|
1424 | def UpdatePhaseData(self,item,data,oldPage): |
---|
1425 | import GSASIIElem as G2el |
---|
1426 | Atoms = [] |
---|
1427 | self.SelectedRow = 0 |
---|
1428 | |
---|
1429 | def BookResize(event): |
---|
1430 | w,h = self.GetSize() |
---|
1431 | self.dataDisplay.SetSize(wx.Size(w,h)) |
---|
1432 | |
---|
1433 | def FillGeneralGrid(): |
---|
1434 | def SetLatticeParametersStyle(SGData,table): |
---|
1435 | if SGData['SGLaue'] in ['m3','m3m']: |
---|
1436 | table[4][2] = table[4][3] = table[4][1] |
---|
1437 | General.SetCellStyle(4,2,"light grey",True) |
---|
1438 | General.SetCellStyle(4,3,"light grey",True) |
---|
1439 | table[4][4] = table[4][5] = table[4][6] = 90. |
---|
1440 | General.SetCellStyle(4,4,"light grey",True) |
---|
1441 | General.SetCellStyle(4,5,"light grey",True) |
---|
1442 | General.SetCellStyle(4,6,"light grey",True) |
---|
1443 | elif SGData['SGLaue'] in ['3R','3mR']: |
---|
1444 | table[4][2] = table[4][3] = table[4][1] |
---|
1445 | General.SetCellStyle(4,2,"light grey",True) |
---|
1446 | General.SetCellStyle(4,3,"light grey",True) |
---|
1447 | table[4][5] = table[4][6] = table[4][4] |
---|
1448 | General.SetCellStyle(4,5,"light grey",True) |
---|
1449 | General.SetCellStyle(4,6,"light grey",True) |
---|
1450 | elif SGData['SGLaue'] in ['3','3m1','31m','6/m','6/mmm']: |
---|
1451 | table[4][2] = table[4][1] |
---|
1452 | General.SetCellStyle(4,2,"light grey",True) |
---|
1453 | table[4][4] = table[4][5] = 90. |
---|
1454 | table[4][6] = 120. |
---|
1455 | General.SetCellStyle(4,4,"light grey",True) |
---|
1456 | General.SetCellStyle(4,5,"light grey",True) |
---|
1457 | General.SetCellStyle(4,6,"light grey",True) |
---|
1458 | elif SGData['SGLaue'] in ['4/m','4/mmm']: |
---|
1459 | table[4][2] = table[4][1] |
---|
1460 | General.SetCellStyle(4,2,"light grey",True) |
---|
1461 | table[4][4] = table[4][5] = table[4][6] = 90. |
---|
1462 | General.SetCellStyle(4,4,"light grey",True) |
---|
1463 | General.SetCellStyle(4,5,"light grey",True) |
---|
1464 | General.SetCellStyle(4,6,"light grey",True) |
---|
1465 | elif SGData['SGLaue'] in ['mmm']: |
---|
1466 | table[4][4] = table[4][5] = table[4][6] = 90. |
---|
1467 | General.SetCellStyle(4,4,"light grey",True) |
---|
1468 | General.SetCellStyle(4,5,"light grey",True) |
---|
1469 | General.SetCellStyle(4,6,"light grey",True) |
---|
1470 | elif SGData['SGLaue'] in ['2/m']: |
---|
1471 | if SGData['SGUniq'] == 'a': |
---|
1472 | table[4][5]= table[4][6] = 90. |
---|
1473 | General.SetCellStyle(4,5,"light grey",True) |
---|
1474 | General.SetCellStyle(4,6,"light grey",True) |
---|
1475 | if SGData['SGUniq'] == 'b': |
---|
1476 | table[4][4]= table[4][6] = 90. |
---|
1477 | General.SetCellStyle(4,4,"light grey",True) |
---|
1478 | General.SetCellStyle(4,6,"light grey",True) |
---|
1479 | if SGData['SGUniq'] == 'c': |
---|
1480 | table[4][4]= table[4][5] = 90. |
---|
1481 | General.SetCellStyle(4,4,"light grey",True) |
---|
1482 | General.SetCellStyle(4,5,"light grey",True) |
---|
1483 | |
---|
1484 | def RefreshGeneralGrid(event): |
---|
1485 | |
---|
1486 | r,c = event.GetRow(),event.GetCol() |
---|
1487 | generalData[0] = table[0][0] |
---|
1488 | self.PatternTree.SetItemText(item,generalData[0]) |
---|
1489 | generalData[1] = table[1][0] |
---|
1490 | SpcGp = table[2][0] |
---|
1491 | SGErr,SGData = G2spc.SpcGroup(SpcGp) |
---|
1492 | if r == 2 and c == 0: |
---|
1493 | if SGErr: |
---|
1494 | text = [G2spc.SGErrors(SGErr)+'\nSpace Group set to previous'] |
---|
1495 | table[2][0] = generalData[2]['SpGrp'] |
---|
1496 | msg = 'Space Group Error' |
---|
1497 | Style = wx.ICON_EXCLAMATION |
---|
1498 | else: |
---|
1499 | text = G2spc.SGPrint(SGData) |
---|
1500 | generalData[2] = SGData |
---|
1501 | msg = 'Space Group Information' |
---|
1502 | Style = wx.ICON_INFORMATION |
---|
1503 | Text = '' |
---|
1504 | for line in text: |
---|
1505 | Text += line+'\n' |
---|
1506 | wx.MessageBox(Text,caption=msg,style=Style) |
---|
1507 | General.SetCellValue(4,0,str(generalData[3][0])) |
---|
1508 | for c in range(1,7): |
---|
1509 | General.SetCellStyle(4,c,"white",False) |
---|
1510 | generalData[3][c] = float(General.GetCellValue(4,c)) |
---|
1511 | generalData[3][7] = G2cmp.calc_V(G2cmp.cell2A(generalData[3][1:7])) |
---|
1512 | SetLatticeParametersStyle(SGData,table) |
---|
1513 | generalData[4][1] = float(General.GetCellValue(5,1)) |
---|
1514 | General.ForceRefresh() |
---|
1515 | |
---|
1516 | rowLabels = ['Phase name','Phase type','Space group', |
---|
1517 | 'Lattice ',' parameters','Scale factor','Elements','No. per cell','Atom weight','','Bond radii','Angle radii'] |
---|
1518 | generalData = data['General'] |
---|
1519 | atomData = data['Atoms'] |
---|
1520 | AtomTypes = [] |
---|
1521 | NoAtoms = {} |
---|
1522 | BondRadii = [] |
---|
1523 | AngleRadii = [] |
---|
1524 | AtomMass = [] |
---|
1525 | colType = 1 |
---|
1526 | colSS = 7 |
---|
1527 | self.dataFrame.setSizePosLeft([600,350]) |
---|
1528 | if generalData[1] =='macromolecular': |
---|
1529 | colType = 4 |
---|
1530 | colSS = 10 |
---|
1531 | for atom in atomData: |
---|
1532 | if AtomTypes.count(atom[colType]): |
---|
1533 | NoAtoms[atom[colType]] += atom[colSS-1]*atom[colSS+1] |
---|
1534 | else: |
---|
1535 | Info = G2el.GetAtomInfo(atom[colType]) |
---|
1536 | AtomTypes.append(Info['Symbol']) |
---|
1537 | BondRadii.append(Info['Drad']) |
---|
1538 | AngleRadii.append(Info['Arad']) |
---|
1539 | AtomMass.append(Info['Mass']) |
---|
1540 | NoAtoms[atom[colType]] = atom[colSS-1]*atom[colSS+1] |
---|
1541 | generalData[5:9] = [AtomTypes,NoAtoms,AtomMass,BondRadii,AngleRadii] |
---|
1542 | colLabels = [] |
---|
1543 | colLabels += ['' for i in range(max(8,len(generalData[5])))] |
---|
1544 | table = [] |
---|
1545 | table.append([generalData[0],'','','','','','','','']) #phase name |
---|
1546 | table.append([generalData[1],'','','','','','','','']) #phase type |
---|
1547 | E,SGData = G2spc.SpcGroup(generalData[2]['SpGrp']) |
---|
1548 | table.append([SGData['SpGrp'],'','','','','','','','']) #space group symbol |
---|
1549 | table.append(['refine','a ','b ','c ','alpha ','beta ','gamma','volume ']) |
---|
1550 | table.append(generalData[3]) #lattice parameters |
---|
1551 | table.append([generalData[4][0],generalData[4][1],'','','','','','']) #scale factor |
---|
1552 | table.append(generalData[5]+['' for i in range(max(8,len(generalData[5])))]) #element list |
---|
1553 | line = [] |
---|
1554 | mass = 0. |
---|
1555 | for i,elem in enumerate(generalData[5]): |
---|
1556 | mass += generalData[6][elem]*generalData[7][i] |
---|
1557 | line.append(generalData[6][elem]) |
---|
1558 | Volume = generalData[3][7] |
---|
1559 | table.append(line+['' for i in range(max(8,len(generalData[5])))]) #No. per cell |
---|
1560 | table.append(generalData[7]+['' for i in range(max(8,len(generalData[5])))]) #At. wt. |
---|
1561 | if generalData[1] == 'macromolecular' and mass > 0.0: |
---|
1562 | table.append(['density',mass/(0.6022137*Volume),'Matthews coeff.',Volume/mass,'','','','','']) |
---|
1563 | else: |
---|
1564 | table.append(['density',mass/(0.6022137*Volume),'','','','','','','']) |
---|
1565 | table.append(generalData[8]+['' for i in range(max(8,len(generalData[5])))]) |
---|
1566 | table.append(generalData[9]+['' for i in range(max(8,len(generalData[5])))]) |
---|
1567 | Types = [wg.GRID_VALUE_STRING for i in range(max(8,len(generalData[5])))] |
---|
1568 | generalTable = Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types) |
---|
1569 | General.SetTable(generalTable, True) |
---|
1570 | General.Bind(wg.EVT_GRID_CELL_CHANGE, RefreshGeneralGrid) |
---|
1571 | General.SetMargins(0,0) |
---|
1572 | General.SetColSize(0,100) |
---|
1573 | General.SetColLabelSize(0) |
---|
1574 | for c in range(max(8,len(generalData[5]))): |
---|
1575 | if c > 0: |
---|
1576 | General.SetReadOnly(0,c,isReadOnly=True) |
---|
1577 | General.SetReadOnly(1,c,isReadOnly=True) |
---|
1578 | General.SetReadOnly(2,c,isReadOnly=True) |
---|
1579 | General.SetReadOnly(3,c,isReadOnly=True) #unit cell labels |
---|
1580 | General.SetCellAlignment(3,c,wx.ALIGN_RIGHT, wx.ALIGN_CENTRE) |
---|
1581 | if c < 4: |
---|
1582 | General.SetCellRenderer(4,c,wg.GridCellFloatRenderer(10,5)) |
---|
1583 | General.SetCellEditor(4,c,wg.GridCellFloatEditor(10,5)) |
---|
1584 | General.SetReadOnly(9,c,isReadOnly=True) |
---|
1585 | else: |
---|
1586 | General.SetCellRenderer(4,c,wg.GridCellFloatRenderer(10,3)) |
---|
1587 | General.SetCellEditor(4,c,wg.GridCellFloatEditor(10,3)) |
---|
1588 | for r in range(6,12): |
---|
1589 | General.SetReadOnly(r,c,isReadOnly=True) |
---|
1590 | General.SetReadOnly(4,7,isReadOnly=True) #cell volume - no edit |
---|
1591 | General.SetCellEditor(1,0,wg.GridCellChoiceEditor(['nuclear','modulated', #phase type |
---|
1592 | 'magnetic','macromolecular','Pawley'],False)) #- change only if no atoms |
---|
1593 | if line: #no.of atoms not zero! |
---|
1594 | General.SetReadOnly(1,0,isReadOnly=True) #can't change phase type |
---|
1595 | General.SetCellRenderer(4,0,wg.GridCellBoolRenderer()) #lattice parameters |
---|
1596 | General.SetCellEditor(4,0,wg.GridCellBoolEditor()) |
---|
1597 | SetLatticeParametersStyle(SGData,table) |
---|
1598 | General.SetCellRenderer(5,1,wg.GridCellFloatRenderer(10,4)) #scale factor |
---|
1599 | General.SetCellEditor(5,1,wg.GridCellFloatEditor(10,4)) |
---|
1600 | General.SetCellRenderer(5,0,wg.GridCellBoolRenderer()) |
---|
1601 | General.SetCellEditor(5,0,wg.GridCellBoolEditor()) |
---|
1602 | General.SetCellRenderer(9,1,wg.GridCellFloatRenderer(8,3)) |
---|
1603 | General.SetCellRenderer(9,3,wg.GridCellFloatRenderer(8,3)) |
---|
1604 | |
---|
1605 | def FillAtomsGrid(): |
---|
1606 | |
---|
1607 | def RefreshAtomGrid(event): |
---|
1608 | r,c = event.GetRow(),event.GetCol() |
---|
1609 | if r < 0: #on col label! |
---|
1610 | sel = -1 |
---|
1611 | if Atoms.GetColLabelValue(c) == 'refine': |
---|
1612 | choice = ['F - site fraction','X - coordinates','U - thermal parameters'] |
---|
1613 | dlg = wx.MultiChoiceDialog(self,'Select','Refinement controls',choice) |
---|
1614 | if dlg.ShowModal() == wx.ID_OK: |
---|
1615 | sel = dlg.GetSelections() |
---|
1616 | parms = '' |
---|
1617 | for x in sel: |
---|
1618 | parms += choice[x][0] |
---|
1619 | elif Atoms.GetColLabelValue(c) == 'I/A': |
---|
1620 | choice = ['Isotropic','Anisotropic'] |
---|
1621 | dlg = wx.SingleChoiceDialog(self,'Select','Thermal Motion',choice) |
---|
1622 | if dlg.ShowModal() == wx.ID_OK: |
---|
1623 | sel = dlg.GetSelection() |
---|
1624 | parms = choice[sel][0] |
---|
1625 | if sel >= 0: |
---|
1626 | for r in range(Atoms.GetNumberRows()): |
---|
1627 | Atoms.SetCellValue(r,c,parms) |
---|
1628 | elif c < 0: #picked atom row |
---|
1629 | self.SelectedRow = r |
---|
1630 | elif Atoms.GetColLabelValue(c) in ['x','y','z']: |
---|
1631 | colLabel = Atoms.GetColLabelValue(c) |
---|
1632 | if colLabel == 'x': |
---|
1633 | XYZ = [atomData[r][c],atomData[r][c+1],atomData[r][c+2]] |
---|
1634 | elif colLabel == 'y': |
---|
1635 | XYZ = [atomData[r][c-1],atomData[r][c],atomData[r][c+1]] |
---|
1636 | elif colLabel == 'z': |
---|
1637 | XYZ = [atomData[r][c-2],atomData[r][c-1],atomData[r][c]] |
---|
1638 | if None in XYZ: |
---|
1639 | XYZ = [0,0,0] |
---|
1640 | SScol = colLabels.index('site sym') |
---|
1641 | Mulcol = colLabels.index('mult') |
---|
1642 | E,SGData = G2spc.SpcGroup(generalData[2]['SpGrp']) |
---|
1643 | Sytsym,Mult = G2spc.SytSym(XYZ,SGData) |
---|
1644 | atomData[r][SScol] = Sytsym |
---|
1645 | atomData[r][Mulcol] = Mult |
---|
1646 | Atoms.ForceRefresh() |
---|
1647 | |
---|
1648 | def AtomTypeSelect(event): |
---|
1649 | r,c = event.GetRow(),event.GetCol() |
---|
1650 | if Atoms.GetColLabelValue(c) == 'Type': |
---|
1651 | PE = G2elem.PickElement(self) |
---|
1652 | if PE.ShowModal() == wx.ID_OK: |
---|
1653 | atomData[r][c] = PE.Elem.strip() |
---|
1654 | PE.Destroy() |
---|
1655 | Atoms.ForceRefresh() |
---|
1656 | else: |
---|
1657 | event.Skip() |
---|
1658 | |
---|
1659 | generalData = data['General'] |
---|
1660 | atomData = data['Atoms'] |
---|
1661 | Types = [wg.GRID_VALUE_STRING,wg.GRID_VALUE_STRING,wg.GRID_VALUE_CHOICE+": ,X,XU,U,F,FX,FXU,FU", |
---|
1662 | wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_FLOAT+':10,5', |
---|
1663 | wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_STRING,wg.GRID_VALUE_NUMBER,wg.GRID_VALUE_CHOICE+":I,A", |
---|
1664 | wg.GRID_VALUE_FLOAT+':10,4', |
---|
1665 | wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_FLOAT+':10,4', |
---|
1666 | wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_FLOAT+':10,4'] |
---|
1667 | colLabels = ['Name','Type','refine','x','y','z','frac','site sym','mult','I/A','Uiso','U11','U22','U33','U12','U13','U23'] |
---|
1668 | if generalData[1] == 'magnetic': |
---|
1669 | colLabels += ['Mx','My','Mz'] |
---|
1670 | Types[2] = wg.GRID_VALUE_CHOICE+": ,X,XU,U,M,MX,MXU,MU,F,FX,FXU,FU,FM,FMX,FMU," |
---|
1671 | Types += [ |
---|
1672 | wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_FLOAT+':10,4'] |
---|
1673 | elif generalData[1] == 'macromolecular': |
---|
1674 | colLabels = ['res no','residue','chain'] + colLabels |
---|
1675 | Types = [wg.GRID_VALUE_NUMBER, |
---|
1676 | wg.GRID_VALUE_CHOICE+": ,ALA,ARG,ASN,ASP,CYS,GLN,GLU,GLY,HIS,ILE,LEU,LYS,MET,PHE,PRO,SER,THR,TRP,TYR,VAL,MSE,HOH,UNK", |
---|
1677 | wg.GRID_VALUE_STRING] + Types |
---|
1678 | table = [] |
---|
1679 | rowLabels = [] |
---|
1680 | for i,atom in enumerate(atomData): |
---|
1681 | table.append(atom) |
---|
1682 | rowLabels.append(str(i+1)) |
---|
1683 | atomTable = Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types) |
---|
1684 | Atoms.SetTable(atomTable, True) |
---|
1685 | Atoms.Bind(wg.EVT_GRID_CELL_CHANGE, RefreshAtomGrid) |
---|
1686 | Atoms.Bind(wg.EVT_GRID_LABEL_LEFT_DCLICK, RefreshAtomGrid) |
---|
1687 | Atoms.Bind(wg.EVT_GRID_SELECT_CELL, AtomTypeSelect) |
---|
1688 | Atoms.SetMargins(0,0) |
---|
1689 | Atoms.AutoSizeColumns(True) |
---|
1690 | colType = colLabels.index('Type') |
---|
1691 | colSS = colLabels.index('site sym') |
---|
1692 | colIA = colLabels.index('I/A') |
---|
1693 | for row in range(Atoms.GetNumberRows()): |
---|
1694 | Atoms.SetReadOnly(row,colSS,True) #site sym |
---|
1695 | Atoms.SetReadOnly(row,colSS+1,True) #Mult |
---|
1696 | if Atoms.GetCellValue(row,colIA) == 'I': |
---|
1697 | for i in range(2,8): |
---|
1698 | Atoms.SetCellRenderer(row,colIA+i,wg.GridCellStringRenderer()) |
---|
1699 | Atoms.SetReadOnly(row,colIA+i,isReadOnly=True) |
---|
1700 | Atoms.SetCellValue(row,colIA+i,'') |
---|
1701 | elif Atoms.GetCellValue(row,colIA) == 'A': |
---|
1702 | Atoms.SetCellRenderer(row,colIA+1,wg.GridCellStringRenderer()) |
---|
1703 | Atoms.SetReadOnly(row,colIA+1,isReadOnly=True) |
---|
1704 | Atoms.SetCellValue(row,colIA+1,'') |
---|
1705 | |
---|
1706 | def AtomAdd(event): |
---|
1707 | atomData = data['Atoms'] |
---|
1708 | generalData = data['General'] |
---|
1709 | Ncol = Atoms.GetNumberCols() |
---|
1710 | if generalData[1] == 'macromolecular': |
---|
1711 | atomData.append([0,'UNK','','UNK','UNK','',0,0,0,0,'',0,'I',0.10,0,0,0,0,0,0]) |
---|
1712 | elif generalData[1] == 'nuclear': |
---|
1713 | atomData.append(['UNK','UNK','',0,0,0,0,'',0,'I',0.01,0,0,0,0,0,0]) |
---|
1714 | event.StopPropagation() |
---|
1715 | FillAtomsGrid() |
---|
1716 | |
---|
1717 | def AtomInsert(event): |
---|
1718 | atomData = data['Atoms'] |
---|
1719 | generalData = data['General'] |
---|
1720 | Ncol = Atoms.GetNumberCols() |
---|
1721 | if generalData[1][0] == 'macromolecular': |
---|
1722 | atomData.append([0,'UNK','','UNK','UNK','',0,0,0,0,'',0,'I',0.10,0,0,0,0,0,0]) |
---|
1723 | elif generalData[1][0] == 'nuclear': |
---|
1724 | atomData.append(['UNK','UNK','',0,0,0,0,'',0,'I',0.01,0,0,0,0,0,0]) |
---|
1725 | event.StopPropagation() |
---|
1726 | FillAtomsGrid() |
---|
1727 | |
---|
1728 | def UpdateDrawing(): |
---|
1729 | print 'Drawing' |
---|
1730 | |
---|
1731 | def FillPawleyReflectionsGrid(): |
---|
1732 | |
---|
1733 | print 'Pawley reflections' |
---|
1734 | |
---|
1735 | def OnPageChanged(event): |
---|
1736 | page = event.GetSelection() |
---|
1737 | text = self.dataDisplay.GetPageText(page) |
---|
1738 | if text == 'Atoms': |
---|
1739 | self.dataFrame.SetMenuBar(self.dataFrame.AtomsMenu) |
---|
1740 | self.dataFrame.Bind(wx.EVT_MENU, AtomAdd, id=wxID_ATOMSEDITADD) |
---|
1741 | self.dataFrame.Bind(wx.EVT_MENU, AtomInsert, id=wxID_ATOMSEDITINSERT) |
---|
1742 | FillAtomsGrid() |
---|
1743 | else: |
---|
1744 | self.dataFrame.SetMenuBar(self.dataFrame.BlankMenu) |
---|
1745 | event.Skip() |
---|
1746 | |
---|
1747 | if self.dataDisplay: |
---|
1748 | self.dataDisplay.Destroy() |
---|
1749 | PhaseName = self.PatternTree.GetItemText(item) |
---|
1750 | self.dataFrame.SetMenuBar(self.dataFrame.BlankMenu) |
---|
1751 | self.dataFrame.SetLabel('Phase Data for '+PhaseName) |
---|
1752 | self.dataDisplay = GSNoteBook(parent=self.dataFrame,size=self.dataFrame.GetClientSize()) |
---|
1753 | |
---|
1754 | General = GSGrid(parent=self.dataDisplay) |
---|
1755 | FillGeneralGrid() |
---|
1756 | self.dataDisplay.AddPage(General,'General') |
---|
1757 | |
---|
1758 | GeneralData = data['General'] |
---|
1759 | if GeneralData[3] == 'Pawley': |
---|
1760 | PawleyRefl = GSGrid(parent=self.dataDisplay) |
---|
1761 | self.dataDisplay.AddPage(PawleyRefl,'Pawley reflections') |
---|
1762 | FillPawleyReflectionsGrid() |
---|
1763 | else: |
---|
1764 | Atoms = GSGrid(parent=self.dataDisplay) |
---|
1765 | FillAtomsGrid() |
---|
1766 | self.dataDisplay.AddPage(Atoms,'Atoms') |
---|
1767 | |
---|
1768 | Drawing = wx.Window(parent=self.dataDisplay) |
---|
1769 | self.dataDisplay.AddPage(Drawing,'Drawing') |
---|
1770 | |
---|
1771 | self.dataDisplay.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, OnPageChanged) |
---|
1772 | self.dataDisplay.SetSelection(oldPage) |
---|
1773 | |
---|
1774 | |
---|
1775 | def GetPatternTreeItemId(self, parentId, itemText): |
---|
1776 | item, cookie = self.PatternTree.GetFirstChild(parentId) |
---|
1777 | while item: |
---|
1778 | if self.PatternTree.GetItemText(item) == itemText: |
---|
1779 | return item |
---|
1780 | item, cookie = self.PatternTree.GetNextChild(parentId, cookie) |
---|
1781 | return 0 |
---|
1782 | |
---|
1783 | def MovePatternTreeToGrid(self,item): |
---|
1784 | |
---|
1785 | oldPage = 0 |
---|
1786 | if self.dataFrame: |
---|
1787 | self.dataFrame.SetMenuBar(self.dataFrame.BlankMenu) |
---|
1788 | if self.dataFrame.GetLabel() == 'Comments': |
---|
1789 | data = [self.dataDisplay.GetValue()] |
---|
1790 | self.dataDisplay.Clear() |
---|
1791 | Id = GetPatternTreeItemId(self,self.root, 'Comments') |
---|
1792 | if Id: self.PatternTree.SetItemPyData(Id,data) |
---|
1793 | if self.dataFrame.GetLabel() == 'Notebook': |
---|
1794 | data = [self.dataDisplay.GetValue()] |
---|
1795 | self.dataDisplay.Clear() |
---|
1796 | Id = GetPatternTreeItemId(self,self.root, 'Notebook') |
---|
1797 | if Id: self.PatternTree.SetItemPyData(Id,data) |
---|
1798 | if 'Phase Data for' in self.dataFrame.GetLabel(): |
---|
1799 | if self.dataDisplay: |
---|
1800 | oldPage = self.dataDisplay.GetSelection() |
---|
1801 | self.dataFrame.Clear() |
---|
1802 | self.dataFrame.SetLabel('') |
---|
1803 | else: |
---|
1804 | self.dataFrame = DataFrame(parent=self.mainPanel) |
---|
1805 | |
---|
1806 | self.dataFrame.Raise() |
---|
1807 | self.PickId = 0 |
---|
1808 | self.PatternId = 0 |
---|
1809 | parentID = self.root |
---|
1810 | if item != self.root: |
---|
1811 | parentID = self.PatternTree.GetItemParent(item) |
---|
1812 | if self.PatternTree.GetItemParent(item) == self.root: |
---|
1813 | self.PatternId = item |
---|
1814 | self.ExportPattern.Enable(True) |
---|
1815 | self.PickId = item |
---|
1816 | if self.PatternTree.GetItemText(item) == 'Notebook': |
---|
1817 | self.PatternId = 0 |
---|
1818 | self.ExportPattern.Enable(False) |
---|
1819 | data = self.PatternTree.GetItemPyData(item) |
---|
1820 | UpdateNotebook(self,data) |
---|
1821 | elif self.PatternTree.GetItemText(item) == 'Controls': |
---|
1822 | self.PatternId = 0 |
---|
1823 | self.ExportPattern.Enable(False) |
---|
1824 | data = self.PatternTree.GetItemPyData(item) |
---|
1825 | UpdateControls(self,data) |
---|
1826 | elif 'IMG' in self.PatternTree.GetItemText(item): |
---|
1827 | self.Image = item |
---|
1828 | self.Img = 0 |
---|
1829 | G2plt.PlotImage(self) |
---|
1830 | elif 'PKS' in self.PatternTree.GetItemText(item): |
---|
1831 | G2plt.PlotPowderLines(self) |
---|
1832 | elif 'PWDR' in self.PatternTree.GetItemText(item): |
---|
1833 | G2plt.PlotPatterns(self,True) |
---|
1834 | elif 'SXTL' in self.PatternTree.GetItemText(item): |
---|
1835 | self.Sngl = item |
---|
1836 | G2plt.PlotSngl(self) |
---|
1837 | |
---|
1838 | elif self.PatternTree.GetItemText(parentID) == 'Phases': |
---|
1839 | self.PickId = item |
---|
1840 | data = self.PatternTree.GetItemPyData(item) |
---|
1841 | UpdatePhaseData(self,item,data,oldPage) |
---|
1842 | elif self.PatternTree.GetItemText(item) == 'Comments': |
---|
1843 | self.PatternId = self.PatternTree.GetItemParent(item) |
---|
1844 | self.PickId = item |
---|
1845 | data = self.PatternTree.GetItemPyData(item) |
---|
1846 | UpdateComments(self,data) |
---|
1847 | elif self.PatternTree.GetItemText(item) == 'Image Controls': |
---|
1848 | self.dataFrame.SetTitle('Image Controls') |
---|
1849 | self.PickId = item |
---|
1850 | self.Image = self.PatternTree.GetItemParent(item) |
---|
1851 | data = self.PatternTree.GetItemPyData(item) |
---|
1852 | UpdateImageControls(self,data) |
---|
1853 | G2plt.PlotImage(self) |
---|
1854 | elif self.PatternTree.GetItemText(item) == 'HKL Plot Controls': |
---|
1855 | self.PickId = item |
---|
1856 | self.Sngl = self.PatternTree.GetItemParent(item) |
---|
1857 | data = self.PatternTree.GetItemPyData(item) |
---|
1858 | UpdateHKLControls(self,data) |
---|
1859 | G2plt.PlotSngl(self) |
---|
1860 | elif self.PatternTree.GetItemText(item) == 'Peak List': |
---|
1861 | self.PatternId = self.PatternTree.GetItemParent(item) |
---|
1862 | self.ExportPeakList.Enable(True) |
---|
1863 | self.PickId = item |
---|
1864 | data = self.PatternTree.GetItemPyData(item) |
---|
1865 | UpdatePeakGrid(self,data) |
---|
1866 | G2plt.PlotPatterns(self) |
---|
1867 | elif self.PatternTree.GetItemText(item) == 'Background': |
---|
1868 | self.PatternId = self.PatternTree.GetItemParent(item) |
---|
1869 | self.PickId = item |
---|
1870 | data = self.PatternTree.GetItemPyData(item) |
---|
1871 | UpdateBackgroundGrid(self,data) |
---|
1872 | G2plt.PlotPatterns(self) |
---|
1873 | elif self.PatternTree.GetItemText(item) == 'Limits': |
---|
1874 | self.PatternId = self.PatternTree.GetItemParent(item) |
---|
1875 | self.PickId = item |
---|
1876 | data = self.PatternTree.GetItemPyData(item) |
---|
1877 | UpdateLimitsGrid(self,data) |
---|
1878 | G2plt.PlotPatterns(self) |
---|
1879 | elif self.PatternTree.GetItemText(item) == 'Instrument Parameters': |
---|
1880 | self.PatternId = self.PatternTree.GetItemParent(item) |
---|
1881 | self.PickId = item |
---|
1882 | data = self.PatternTree.GetItemPyData(item) |
---|
1883 | UpdateInstrumentGrid(self,data) |
---|
1884 | G2plt.PlotPeakWidths(self) |
---|
1885 | elif self.PatternTree.GetItemText(item) == 'Index Peak List': |
---|
1886 | self.PatternId = self.PatternTree.GetItemParent(item) |
---|
1887 | self.ExportPeakList.Enable(True) |
---|
1888 | self.PickId = item |
---|
1889 | data = self.PatternTree.GetItemPyData(item) |
---|
1890 | UpdateIndexPeaksGrid(self,data) |
---|
1891 | if 'PKS' in self.PatternTree.GetItemText(self.PatternId): |
---|
1892 | G2plt.PlotPowderLines(self) |
---|
1893 | else: |
---|
1894 | G2plt.PlotPatterns(self) |
---|
1895 | elif self.PatternTree.GetItemText(item) == 'Unit Cells List': |
---|
1896 | self.PatternId = self.PatternTree.GetItemParent(item) |
---|
1897 | self.PickId = item |
---|
1898 | data = self.PatternTree.GetItemPyData(item) |
---|
1899 | if not data: |
---|
1900 | data.append([0,0.1,4,25.0,0,'P1',1,1,1,90,90,90]) #zero error flag, max zero error, max Nc/No, start volume |
---|
1901 | data.append([0,0,0,0,0,0,0,0,0,0,0,0,0,0]) #Bravais lattice flags |
---|
1902 | data.append([]) #empty cell list |
---|
1903 | data.append([]) #empty dmin |
---|
1904 | self.PatternTree.SetItemPyData(item,data) |
---|
1905 | UpdateUnitCellsGrid(self,data) |
---|
1906 | self.dataFrame.RefineCell.Enable(True) |
---|
1907 | self.dataFrame.IndexPeaks.Enable(True) |
---|
1908 | if 'PKS' in self.PatternTree.GetItemText(self.PatternId): |
---|
1909 | G2plt.PlotPowderLines(self) |
---|
1910 | else: |
---|
1911 | G2plt.PlotPatterns(self) |
---|