source: trunk/GSASIIddataGUI.py @ 4899

Last change on this file since 4899 was 4846, checked in by toby, 4 years ago

save GPX before OnFileSave?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 52.1 KB
Line 
1# -*- coding: utf-8 -*-
2#GSASII - phase data display routines
3########### SVN repository information ###################
4# $Date: 2021-03-08 23:05:59 +0000 (Mon, 08 Mar 2021) $
5# $Author: vondreele $
6# $Revision: 4846 $
7# $URL: trunk/GSASIIddataGUI.py $
8# $Id: GSASIIddataGUI.py 4846 2021-03-08 23:05:59Z vondreele $
9########### SVN repository information ###################
10'''
11*GSASIIddataGUI: Phase Diffraction Data GUI*
12--------------------------------------------
13
14Module to create the GUI for display of diffraction data * phase
15information that is shown in the data display window
16(when a phase is selected.)
17
18'''
19from __future__ import division, print_function
20import wx
21import numpy as np
22import numpy.linalg as nl
23import GSASIIpath
24GSASIIpath.SetVersionNumber("$Revision: 4846 $")
25import GSASIIlattice as G2lat
26import GSASIIspc as G2spc
27import GSASIIplot as G2plt
28import GSASIIpwd as G2pwd
29import GSASIIphsGUI as G2phG
30import GSASIIctrlGUI as G2G
31import GSASIIpy3 as G2py3
32import GSASIIdataGUI as G2gd
33
34WACV = wx.ALIGN_CENTER_VERTICAL
35VERY_LIGHT_GREY = wx.Colour(235,235,235)
36WHITE = wx.Colour(255,255,255)
37BLACK = wx.Colour(0,0,0)
38mapDefault = {'MapType':'','RefList':'','GridStep':0.25,'Show bonds':True,
39                'rho':[],'rhoMax':0.,'mapSize':10.0,'cutOff':50.,'Flip':False}
40
41##### DData routines ################################################################################       
42def UpdateDData(G2frame,DData,data,hist='',Scroll=0):
43    '''Display the Diffraction Data associated with a phase
44    (items where there is a value for each histogram and phase)
45
46    :param wx.frame G2frame: the main GSAS-II frame object
47    :param wx.ScrolledWindow DData: notebook page to be used for the display
48    :param dict data: all the information on the phase in a dictionary
49    :param str hist: histogram name
50    :param int Scroll: previous scroll position
51
52    '''
53    def PlotSizer():
54
55        def OnPlotSel(event):
56            Obj = event.GetEventObject()
57            generalData['Data plot type'] = Obj.GetStringSelection()
58            G2plt.PlotSizeStrainPO(G2frame,data,G2frame.hist)
59            wx.CallLater(100,UpdateDData,G2frame,DData,data,G2frame.hist)
60           
61        def OnPOhkl(event):
62            event.Skip()
63            Obj = event.GetEventObject()
64            Saxis = Obj.GetValue().split()
65            try:
66                hkl = [int(Saxis[i]) for i in range(3)]
67            except (ValueError,IndexError):
68                hkl = generalData['POhkl']
69            if not np.any(np.array(hkl)):
70                hkl = generalData['POhkl']
71            generalData['POhkl'] = hkl
72            h,k,l = hkl
73            Obj.SetValue('%3d %3d %3d'%(h,k,l)) 
74            G2plt.PlotSizeStrainPO(G2frame,data,G2frame.hist)
75           
76        def OnProj(event):
77            Obj = event.GetEventObject()
78            generalData['3Dproj'] = Obj.GetValue()
79            G2plt.PlotSizeStrainPO(G2frame,data,G2frame.hist)
80       
81        plotSizer = wx.BoxSizer(wx.VERTICAL)
82        choice = ['None','Mustrain','Size','Preferred orientation','St. proj. Inv. pole figure','Eq. area Inv. pole figure']
83        plotSel = wx.RadioBox(DData,wx.ID_ANY,'Select plot type:',choices=choice,
84            majorDimension=1,style=wx.RA_SPECIFY_COLS)
85        plotSel.SetStringSelection(generalData['Data plot type'])
86        plotSel.Bind(wx.EVT_RADIOBOX,OnPlotSel)   
87        plotSizer.Add(plotSel)
88        if generalData['Data plot type'] == 'Preferred orientation':
89            POhklSizer = wx.BoxSizer(wx.HORIZONTAL)
90            POhklSizer.Add(wx.StaticText(DData,wx.ID_ANY,' Plot preferred orientation for H K L: '),0,WACV)
91            h,k,l = generalData['POhkl']
92            poAxis = wx.TextCtrl(DData,wx.ID_ANY,'%3d %3d %3d'%(h,k,l),style=wx.TE_PROCESS_ENTER)
93            poAxis.Bind(wx.EVT_TEXT_ENTER,OnPOhkl)
94            poAxis.Bind(wx.EVT_KILL_FOCUS,OnPOhkl)
95            POhklSizer.Add(poAxis,0,WACV)
96            plotSizer.Add(POhklSizer)
97        elif generalData['Data plot type'] in ['Mustrain','Size']:
98            projSizer = wx.BoxSizer(wx.HORIZONTAL)
99            projSizer.Add(wx.StaticText(DData,wx.ID_ANY,' Show projections for: '),0,WACV)
100            proj = ['','x','y','z','xy','xz','yz','xyz']
101            projType = wx.ComboBox(DData,wx.ID_ANY,value=generalData['3Dproj'],choices=proj,
102                style=wx.CB_READONLY|wx.CB_DROPDOWN)
103            projType.Bind(wx.EVT_COMBOBOX, OnProj)
104            projSizer.Add(projType,0,WACV)
105            plotSizer.Add(projSizer)           
106        return plotSizer
107       
108    def ScaleSizer():
109       
110        def OnScaleRef(event):
111            Obj = event.GetEventObject()
112            UseList[G2frame.hist]['Scale'][1] = Obj.GetValue()
113        def onChangeFraction(invalid,value,tc):
114            wx.CallLater(100,RepaintHistogramInfo,DData.GetScrollPos(wx.VERTICAL))
115           
116        scaleSizer = wx.BoxSizer(wx.HORIZONTAL)
117        if 'PWDR' in G2frame.hist:
118            scaleRef = wx.CheckBox(DData,wx.ID_ANY,label=' Phase fraction: ')
119        elif 'HKLF' in G2frame.hist:
120            scaleRef = wx.CheckBox(DData,wx.ID_ANY,label=' Scale factor: ')               
121        scaleRef.SetValue(UseList[G2frame.hist]['Scale'][1])
122        scaleRef.Bind(wx.EVT_CHECKBOX, OnScaleRef)
123        scaleSizer.Add(scaleRef,0,WACV|wx.LEFT,5)
124        scaleVal = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist]['Scale'],0,
125            xmin=0.,nDig=(10,4,'g'),typeHint=float,OnLeave=onChangeFraction)
126        scaleSizer.Add(scaleVal,0,WACV)
127        if 'PWDR' in G2frame.hist and generalData['Type'] != 'magnetic':
128            wtSum = G2pwd.PhaseWtSum(G2frame,G2frame.hist)
129            if wtSum and UseList[G2frame.hist]['Use']:
130                weightFr = UseList[G2frame.hist]['Scale'][0]*generalData['Mass']/wtSum
131                scaleSizer.Add(wx.StaticText(DData,label=' Wt. fraction: %.3f'%(weightFr)),0,WACV)
132        return scaleSizer
133       
134    def OnLGmixRef(event):
135        Obj = event.GetEventObject()
136        hist,name = Indx[Obj.GetId()]
137        UseList[G2frame.hist][name][2][2] = Obj.GetValue()
138       
139    def OnSizeType(event):
140        Obj = event.GetEventObject()
141        UseList[G2frame.hist]['Size'][0] = Obj.GetValue()
142        G2plt.PlotSizeStrainPO(G2frame,data,G2frame.hist)
143        wx.CallLater(100,RepaintHistogramInfo,DData.GetScrollPos(wx.VERTICAL))
144       
145    def OnSizeRef(event):
146        Obj = event.GetEventObject()
147        hist,pid = Indx[Obj.GetId()]
148        if UseList[G2frame.hist]['Size'][0] == 'ellipsoidal':
149            UseList[G2frame.hist]['Size'][5][pid] = Obj.GetValue()               
150        else:
151            UseList[G2frame.hist]['Size'][2][pid] = Obj.GetValue()
152       
153    def OnStrainType(event):
154        Obj = event.GetEventObject()
155        UseList[G2frame.hist]['Mustrain'][0] = Obj.GetValue()
156        G2plt.PlotSizeStrainPO(G2frame,data,G2frame.hist)
157        wx.CallLater(100,RepaintHistogramInfo,DData.GetScrollPos(wx.VERTICAL))
158       
159    def OnStrainRef(event):
160        Obj = event.GetEventObject()
161        hist,pid = Indx[Obj.GetId()]
162        if UseList[G2frame.hist]['Mustrain'][0] == 'generalized':
163            UseList[G2frame.hist]['Mustrain'][5][pid] = Obj.GetValue()
164        else:
165            UseList[G2frame.hist]['Mustrain'][2][pid] = Obj.GetValue()
166       
167    def OnStrainAxis(event):
168        event.Skip()
169        Obj = event.GetEventObject()
170        Saxis = Obj.GetValue().split()
171        try:
172            hkl = [int(Saxis[i]) for i in range(3)]
173        except (ValueError,IndexError):
174            hkl = UseList[G2frame.hist]['Mustrain'][3]
175        if not np.any(np.array(hkl)):
176            hkl = UseList[G2frame.hist]['Mustrain'][3]
177        UseList[G2frame.hist]['Mustrain'][3] = hkl
178        h,k,l = hkl
179        Obj.SetValue('%3d %3d %3d'%(h,k,l)) 
180        wx.CallAfter(G2plt.PlotSizeStrainPO,G2frame,data,hist)
181       
182    def OnResetStrain(event):
183        Obj = event.GetEventObject()
184        item,name = Indx[Obj.GetId()]
185        if name == 'isotropic':
186            UseList[item]['Mustrain'][1][0] = 1000.0
187        elif name == 'uniaxial':
188            UseList[item]['Mustrain'][1][0] = 1000.0
189            UseList[item]['Mustrain'][1][1] = 1000.0
190        elif name == 'generalized':
191            muiso = 1000.
192            cell = generalData['Cell'][1:7]
193            vals = G2spc.Muiso2Shkl(muiso,SGData,cell)
194            UseList[item]['Mustrain'][4] = vals
195        G2plt.PlotSizeStrainPO(G2frame,data,item)
196        wx.CallLater(100,RepaintHistogramInfo,DData.GetScrollPos(wx.VERTICAL))
197           
198    def OnPOAxis(event):
199        event.Skip()
200        Obj = event.GetEventObject()
201        Saxis = Obj.GetValue().split()
202        try:
203            hkl = [int(Saxis[i]) for i in range(3)]
204        except (ValueError,IndexError):
205            hkl = UseList[G2frame.hist]['Pref.Ori.'][3]
206        if not np.any(np.array(hkl)):
207            hkl = UseList[G2frame.hist]['Pref.Ori.'][3]
208        UseList[G2frame.hist]['Pref.Ori.'][3] = hkl
209        h,k,l = hkl
210        Obj.SetValue('%3d %3d %3d'%(h,k,l)) 
211       
212    def OnPOOrder(event):
213        Obj = event.GetEventObject()
214        Order = int(Obj.GetValue())
215        UseList[G2frame.hist]['Pref.Ori.'][4] = Order
216        UseList[G2frame.hist]['Pref.Ori.'][5] = SetPOCoef(Order,G2frame.hist)
217        wx.CallLater(100,RepaintHistogramInfo,DData.GetScrollPos(wx.VERTICAL))
218
219    def OnPOType(event):
220        Obj = event.GetEventObject()
221        if 'March' in Obj.GetValue():
222            UseList[G2frame.hist]['Pref.Ori.'][0] = 'MD'
223        else:
224            UseList[G2frame.hist]['Pref.Ori.'][0] = 'SH'
225        wx.CallLater(100,RepaintHistogramInfo,DData.GetScrollPos(wx.VERTICAL))
226
227    def OnPORef(event):
228        Obj = event.GetEventObject()
229        UseList[G2frame.hist]['Pref.Ori.'][2] = Obj.GetValue()
230
231    def OnAddFixed(event):
232        fixedVars = UseList[G2frame.hist].get('FixedSeqVars',[])
233        SeqId = G2gd.GetGPXtreeItemId(G2frame, G2frame.root, 'Sequential results')
234        seqData = G2frame.GPXtree.GetItemPyData(SeqId)
235        if G2frame.hist not in seqData:
236            print('Strange: '+G2frame.hist+' not found')
237            return
238        parmDict = seqData[G2frame.hist].get('parmDict',[])
239        # narrow down to items w/o a histogram & having float values
240        phaseKeys = [i for i in parmDict if ':' in i and i.split(':')[1] == '']
241        phaseKeys = [i for i in phaseKeys if type(parmDict[i]) not in (int,str,bool)]
242        if len(phaseKeys) == 0: return
243        selected = []
244        for i,key in enumerate(phaseKeys):
245            if key in fixedVars: selected.append(i)
246        dlg = G2G.G2MultiChoiceDialog(G2frame, 'Choose phase vars to fix for this histogram only', 
247                                      'Choose items to edit', phaseKeys,selected=selected)
248        if dlg.ShowModal() == wx.ID_OK:
249            sel = dlg.GetSelections()
250            dlg.Destroy()
251        else:
252            dlg.Destroy()
253            return
254        UseList[G2frame.hist]['FixedSeqVars'] = [phaseKeys[i] for i in sel]
255        wx.CallLater(100,RepaintHistogramInfo,DData.GetScrollPos(wx.VERTICAL))
256
257    def SetPOCoef(Order,hist):
258        cofNames = G2lat.GenSHCoeff(SGData['SGLaue'],'0',Order,False)     #cylindrical & no M
259        newPOCoef = dict(zip(cofNames,np.zeros(len(cofNames))))
260        POCoeff = UseList[G2frame.hist]['Pref.Ori.'][5]
261        for cofName in POCoeff:
262            if cofName in  cofNames:
263                newPOCoef[cofName] = POCoeff[cofName]
264        return newPOCoef
265       
266    def checkAxis(axis):
267        if not np.any(np.array(axis)):
268            return False
269        return axis
270       
271    def OnNewValue(invalid,value,tc):
272        G2plt.PlotSizeStrainPO(G2frame,data,G2frame.hist)
273           
274    def OnNewValueReDraw(invalid,value,tc):
275        G2plt.PlotSizeStrainPO(G2frame,data,G2frame.hist)
276        wx.CallLater(100,RepaintHistogramInfo,DData.GetScrollPos(wx.VERTICAL))
277           
278    def TopSizer(name,choices,parm,OnType):
279        topSizer = wx.BoxSizer(wx.HORIZONTAL)
280        topSizer.Add(wx.StaticText(DData,wx.ID_ANY,name),0,WACV)
281        sizeType = wx.ComboBox(DData,wx.ID_ANY,value=UseList[G2frame.hist][parm][0],choices=choices,
282            style=wx.CB_READONLY|wx.CB_DROPDOWN)
283        sizeType.Bind(wx.EVT_COMBOBOX, OnType)
284        topSizer.Add(sizeType,0,WACV|wx.BOTTOM,5)
285        return topSizer
286       
287    def LGmixSizer(name,Limits,OnRef):
288        lgmixSizer = wx.BoxSizer(wx.HORIZONTAL)
289        lgmixRef = wx.CheckBox(DData,wx.ID_ANY,label='LGmix')
290        lgmixRef.thisown = False
291        lgmixRef.SetValue(UseList[G2frame.hist][name][2][2])
292        Indx[lgmixRef.GetId()] = [G2frame.hist,name]
293        lgmixRef.Bind(wx.EVT_CHECKBOX, OnRef)
294        lgmixSizer.Add(lgmixRef,0,WACV|wx.LEFT,5)
295        lgmixVal = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist][name][1],2,
296            nDig=(10,3),xmin=Limits[0],xmax=Limits[1])
297        lgmixSizer.Add(lgmixVal,0,WACV|wx.LEFT,5)
298        return lgmixSizer
299                   
300    def ResetSizer(name,OnReset):
301        resetSizer = wx.BoxSizer(wx.HORIZONTAL)
302        reset = wx.Button(DData,wx.ID_ANY,label='Reset?')
303        reset.thisown = False
304        Indx[reset.GetId()] = [G2frame.hist,name]
305        reset.Bind(wx.EVT_BUTTON,OnReset)
306        resetSizer.Add(reset,0,WACV)
307        return resetSizer
308       
309    def IsoSizer(name,parm,fmt,Limits,OnRef):
310        isoSizer = wx.BoxSizer(wx.HORIZONTAL)
311        sizeRef = wx.CheckBox(DData,wx.ID_ANY,label=name)
312        sizeRef.thisown = False
313        sizeRef.SetValue(UseList[G2frame.hist][parm][2][0])
314        Indx[sizeRef.GetId()] = [G2frame.hist,0]
315        sizeRef.Bind(wx.EVT_CHECKBOX, OnRef)
316        isoSizer.Add(sizeRef,0,WACV|wx.LEFT,5)
317        sizeVal = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist][parm][1],0,
318            nDig=fmt,xmin=Limits[0],xmax=Limits[1],OnLeave=OnNewValue)
319        isoSizer.Add(sizeVal,0,WACV)
320        return isoSizer
321       
322    def UniSizer(parm,OnAxis):
323        uniSizer = wx.BoxSizer(wx.HORIZONTAL)
324        uniSizer.Add(wx.StaticText(DData,wx.ID_ANY,' Unique axis, H K L: '),0,WACV)
325        h,k,l = UseList[G2frame.hist][parm][3]
326        Axis = wx.TextCtrl(DData,wx.ID_ANY,'%3d %3d %3d'%(h,k,l),style=wx.TE_PROCESS_ENTER)
327        Axis.Bind(wx.EVT_TEXT_ENTER,OnAxis)
328        Axis.Bind(wx.EVT_KILL_FOCUS,OnAxis)
329        uniSizer.Add(Axis,0,WACV|wx.LEFT,5)
330        return uniSizer
331       
332    def UniDataSizer(parmName,parm,fmt,Limits,OnRef):
333        dataSizer = wx.BoxSizer(wx.HORIZONTAL)
334        parms = zip([' Equatorial '+parmName,' Axial '+parmName],
335            UseList[G2frame.hist][parm][2],range(2))
336        for Pa,ref,Id in parms:
337            sizeRef = wx.CheckBox(DData,wx.ID_ANY,label=Pa)
338            sizeRef.thisown = False
339            sizeRef.SetValue(ref)
340            Indx[sizeRef.GetId()] = [G2frame.hist,Id]
341            sizeRef.Bind(wx.EVT_CHECKBOX, OnRef)
342            dataSizer.Add(sizeRef,0,WACV|wx.LEFT,5)
343            sizeVal = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist][parm][1],
344                Id,fmt,xmin=Limits[0],xmax=Limits[1],OnLeave=OnNewValue)
345            dataSizer.Add(sizeVal,0,WACV)
346        return dataSizer
347
348    def EllSizeDataSizer():
349        parms = zip(['S11','S22','S33','S12','S13','S23'],UseList[G2frame.hist]['Size'][4],
350            UseList[G2frame.hist]['Size'][5],range(6))
351        dataSizer = wx.BoxSizer(wx.VERTICAL)
352        matrixSizer = wx.FlexGridSizer(0,6,5,5)
353        Sij = []
354        for Pa,val,ref,Id in parms:
355            sizeRef = wx.CheckBox(DData,wx.ID_ANY,label=Pa)
356            sizeRef.thisown = False
357            sizeRef.SetValue(ref)
358            Indx[sizeRef.GetId()] = [G2frame.hist,Id]
359            sizeRef.Bind(wx.EVT_CHECKBOX, OnSizeRef)
360            matrixSizer.Add(sizeRef,0,WACV)
361            if Id < 3:
362                sizeVal = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist]['Size'][4],
363                    Id,nDig=(10,3),xmin=0.,xmax=4.,OnLeave=OnNewValueReDraw)
364            else:
365                sizeVal = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist]['Size'][4],
366                    Id,nDig=(10,3),OnLeave=OnNewValueReDraw)
367            # Create Sij matrix
368            Sij += [val]
369            matrixSizer.Add(sizeVal,0,WACV)
370        dataSizer.Add(matrixSizer, 0)
371        Esize,Rsize = nl.eigh(G2lat.U6toUij(np.asarray(Sij)))
372        lengths = Esize
373        G,g = G2lat.cell2Gmat(data['General']['Cell'][1:7])       #recip & real metric tensors
374        GA,GB = G2lat.Gmat2AB(G)    #Orthogonalization matricies
375        hkls = [x/(sum(x**2)**0.5) for x in np.dot(Rsize, GA)]
376        Ids = np.argsort(lengths)
377        dataSizer.Add(wx.StaticText(DData,label=' Principal ellipsoid components:'),0)
378        compSizer = wx.FlexGridSizer(3,3,5,5)
379        Axes = [' Short Axis:',' Middle Axis:',' Long Axis:']
380        for Id in Ids:
381            compSizer.Add(wx.StaticText(DData,label=Axes[Id]),0,WACV)
382            compSizer.Add(wx.StaticText(DData,label='(%.3f, %.3f, %.3f) '%(hkls[Id][0], hkls[Id][1], hkls[Id][2])),0,WACV)
383            compSizer.Add(wx.StaticText(DData,label='Length: %.3f'%lengths[Id]),0,WACV)
384        dataSizer.Add(compSizer)
385        return dataSizer
386       
387    def GenStrainDataSizer():
388        Snames = G2spc.MustrainNames(SGData)
389        numb = len(Snames)
390        onumb = len(UseList[G2frame.hist]['Mustrain'][4])
391        while onumb < numb:
392            UseList[G2frame.hist]['Mustrain'][4].append(0.0)
393            UseList[G2frame.hist]['Mustrain'][5].append(False)
394            onumb += 1
395        muMean = G2spc.MuShklMean(SGData,Amat,UseList[G2frame.hist]['Mustrain'][4][:numb])
396        parms = zip(Snames,UseList[G2frame.hist]['Mustrain'][5],range(numb))
397        mainSizer = wx.BoxSizer(wx.VERTICAL)
398        dataSizer = wx.FlexGridSizer(0,6,5,5)
399        for Pa,ref,Id in parms:
400            strainRef = wx.CheckBox(DData,wx.ID_ANY,label=Pa)
401            strainRef.thisown = False
402            strainRef.SetValue(ref)
403            Indx[strainRef.GetId()] = [G2frame.hist,Id]
404            strainRef.Bind(wx.EVT_CHECKBOX, OnStrainRef)
405            dataSizer.Add(strainRef,0,WACV)
406            strainVal = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist]['Mustrain'][4],
407                Id,nDig=(10,2),OnLeave=OnNewValueReDraw)
408            dataSizer.Add(strainVal,0,WACV)
409        mainSizer.Add(dataSizer)
410        mainSizer.Add(wx.StaticText(DData,label=' Mean mustrain %.1f'%muMean)
411                          ,0,wx.ALIGN_CENTER_HORIZONTAL)
412        return mainSizer
413
414    def HstrainSizer():
415       
416        def OnHstrainRef(event):
417            Obj = event.GetEventObject()
418            hist,pid = Indx[Obj.GetId()]
419            UseList[G2frame.hist]['HStrain'][1][pid] = Obj.GetValue()
420           
421        hSizer = wx.BoxSizer(wx.VERTICAL)
422        hstrainSizer = wx.FlexGridSizer(0,6,5,5)
423        Hsnames = G2spc.HStrainNames(SGData)
424        parms = zip(Hsnames,UseList[G2frame.hist]['HStrain'][1],range(len(Hsnames)))
425        allzero = True
426        for Pa,ref,Id in parms:
427            hstrainRef = wx.CheckBox(DData,wx.ID_ANY,label=Pa)
428            hstrainRef.thisown = False
429            hstrainRef.SetValue(ref)
430            Indx[hstrainRef.GetId()] = [G2frame.hist,Id]
431            hstrainRef.Bind(wx.EVT_CHECKBOX, OnHstrainRef)
432            hstrainSizer.Add(hstrainRef,0,WACV|wx.LEFT,5)
433            hstrainVal = G2G.ValidatedTxtCtrl(DData,
434                        UseList[G2frame.hist]['HStrain'][0],Id,nDig=(10,3,'g'),
435                        OnLeave=OnNewValueReDraw)
436            if abs(UseList[G2frame.hist]['HStrain'][0][Id]) > 1e-8:
437                allzero = False
438            hstrainSizer.Add(hstrainVal,0,WACV)
439        hSizer.Add(hstrainSizer,0)
440        if not allzero:   # show Dij shifted unit cell
441            DijVals = UseList[G2frame.hist]['HStrain'][0][:]
442            # apply the Dij values to the reciprocal cell
443            newA = []
444            Dijdict = dict(zip(G2spc.HStrainNames(SGData),DijVals))
445            for Aij,lbl in zip(G2lat.cell2A(data['General']['Cell'][1:7]),
446                            ['D11','D22','D33','D12','D13','D23']):
447                newA.append(Aij + Dijdict.get(lbl,0.0))
448            cell = G2lat.A2cell(newA)   # convert back to direct cell
449            laue = generalData['SGData']['SGLaue']
450            if laue == '2/m':
451                laue += generalData['SGData']['SGUniq']
452            for cellGUI in G2py3.cellGUIlist:
453                if laue in cellGUI[0]:
454                    useGUI = cellGUI
455                    break
456            else:
457                return hSizer
458            cellstr = ''
459            for txt,fmt,ifEdit,Id in zip(*useGUI[2:]):
460                if cellstr: cellstr += ", "
461                cellstr += txt+fmt.format(cell[Id])
462            cellstr += ', Vol = {:.3f}'.format(G2lat.calc_V(newA))
463            hSizer.Add(wx.StaticText(DData,wx.ID_ANY,'     '+cellstr),0)
464        return hSizer
465       
466    def PoTopSizer(POData):
467        poSizer = wx.FlexGridSizer(0,6,5,5)
468        choice = ['March-Dollase','Spherical harmonics']
469        POtype = choice[['MD','SH'].index(POData[0])]
470        poSizer.Add(wx.StaticText(DData,wx.ID_ANY,' Preferred orientation model '),0,WACV)
471        POType = wx.ComboBox(DData,wx.ID_ANY,value=POtype,choices=choice,
472            style=wx.CB_READONLY|wx.CB_DROPDOWN)
473        POType.Bind(wx.EVT_COMBOBOX, OnPOType)
474        poSizer.Add(POType)
475        if POData[0] == 'SH':
476            poSizer.Add(wx.StaticText(DData,wx.ID_ANY,' Harmonic order: '),0,WACV)
477            poOrder = wx.ComboBox(DData,wx.ID_ANY,value=str(POData[4]),choices=[str(2*i) for i in range(18)],
478                style=wx.CB_READONLY|wx.CB_DROPDOWN)
479            poOrder.Bind(wx.EVT_COMBOBOX,OnPOOrder)
480            poSizer.Add(poOrder,0,WACV)
481            poRef = wx.CheckBox(DData,wx.ID_ANY,label=' Refine? ')
482            poRef.SetValue(POData[2])
483            poRef.Bind(wx.EVT_CHECKBOX,OnPORef)
484            poSizer.Add(poRef,0,WACV)
485        return poSizer
486       
487    def MDDataSizer(POData):
488        poSizer = wx.BoxSizer(wx.HORIZONTAL)
489        poRef = wx.CheckBox(DData,wx.ID_ANY,label=' March-Dollase ratio: ')
490        poRef.SetValue(POData[2])
491        poRef.Bind(wx.EVT_CHECKBOX,OnPORef)
492        poSizer.Add(poRef,0,WACV|wx.LEFT,5)
493        poVal = G2G.ValidatedTxtCtrl(DData,POData,1,nDig=(10,3),typeHint=float,xmin=0.)
494        poSizer.Add(poVal,0,WACV)
495        poSizer.Add(wx.StaticText(DData,wx.ID_ANY,' Unique axis, H K L: '),0,WACV)
496        h,k,l =POData[3]
497        poAxis = wx.TextCtrl(DData,wx.ID_ANY,'%3d %3d %3d'%(h,k,l),style=wx.TE_PROCESS_ENTER)
498        poAxis.Bind(wx.EVT_TEXT_ENTER,OnPOAxis)
499        poAxis.Bind(wx.EVT_KILL_FOCUS,OnPOAxis)
500        poSizer.Add(poAxis,0,WACV)
501        return poSizer
502       
503    def SHDataSizer(POData):
504       
505        ODFSizer = wx.FlexGridSizer(0,8,2,2)
506        ODFkeys = list(POData[5].keys())
507        ODFkeys.sort()
508        for odf in ODFkeys:
509            ODFSizer.Add(wx.StaticText(DData,wx.ID_ANY,odf),0,WACV)
510            ODFval = G2G.ValidatedTxtCtrl(DData,POData[5],odf,nDig=(8,3),typeHint=float,OnLeave=OnNewValue)
511            ODFSizer.Add(ODFval,0,WACV|wx.LEFT,5)
512        return ODFSizer
513       
514    def SHPenalty(POData):
515       
516        def OnHKLList(event):
517            dlg = G2G.G2MultiChoiceDialog(G2frame, 'Select penalty hkls',
518                'Penalty hkls',hkls,filterBox=False)
519            try:
520                if dlg.ShowModal() == wx.ID_OK:
521                    POData[6] = [hkls[i] for i in dlg.GetSelections()]
522                    if not POData[6]:
523                        POData[6] = ['',]
524                else:
525                    return
526            finally:
527                dlg.Destroy()
528            wx.CallLater(100,RepaintHistogramInfo,DData.GetScrollPos(wx.VERTICAL))
529           
530        A = G2lat.cell2A(generalData['Cell'][1:7])
531        hkls = G2lat.GenPfHKLs(10,SGData,A)   
532        shPenalty = wx.BoxSizer(wx.HORIZONTAL)
533        shPenalty.Add(wx.StaticText(DData,wx.ID_ANY,' Negative MRD penalty list: '),0,WACV)
534        shPenalty.Add(wx.ComboBox(DData,value=POData[6][0],choices=POData[6],
535            style=wx.CB_DROPDOWN),0,WACV|wx.LEFT,5)
536        hklList = wx.Button(DData,label='Select penalty hkls')
537        hklList.Bind(wx.EVT_BUTTON,OnHKLList)
538        shPenalty.Add(hklList,0,WACV)
539        shPenalty.Add(wx.StaticText(DData,wx.ID_ANY,' Zero MRD tolerance: '),0,WACV)
540        shToler = G2G.ValidatedTxtCtrl(DData,POData,7,nDig=(10,2),typeHint=float)
541        shPenalty.Add(shToler,0,WACV)
542        return shPenalty   
543       
544    def ExtSizer(Type):
545       
546        def OnSCExtType(event):
547            Obj = event.GetEventObject()
548            item = Indx[Obj.GetId()]
549            UseList[item[0]]['Extinction'][item[1]] = Obj.GetValue()
550            wx.CallLater(100,RepaintHistogramInfo,DData.GetScrollPos(wx.VERTICAL))
551               
552        def OnEref(event):
553            Obj = event.GetEventObject()
554            item = Indx[Obj.GetId()]
555            UseList[item[0]]['Extinction'][2][item[1]][1] = Obj.GetValue()
556   
557        def OnExtRef(event):
558            Obj = event.GetEventObject()
559            UseList[G2frame.hist]['Extinction'][1] = Obj.GetValue()
560           
561        if Type == 'HKLF':
562            extSizer = wx.BoxSizer(wx.VERTICAL)
563            typeSizer = wx.BoxSizer(wx.HORIZONTAL)           
564            typeSizer.Add(wx.StaticText(DData,wx.ID_ANY,' Extinction type: '),0,WACV)
565            Choices = ['None','Primary','Secondary Type I','Secondary Type II',]    # remove 'Secondary Type I & II'
566            typeTxt = wx.ComboBox(DData,wx.ID_ANY,choices=Choices,value=UseList[G2frame.hist]['Extinction'][1],
567                style=wx.CB_READONLY|wx.CB_DROPDOWN)
568            Indx[typeTxt.GetId()] = [G2frame.hist,1]
569            typeTxt.Bind(wx.EVT_COMBOBOX,OnSCExtType)
570            typeSizer.Add(typeTxt)
571            typeSizer.Add(wx.StaticText(DData,wx.ID_ANY,' Approx: '),0,WACV)
572            Choices=['Lorentzian','Gaussian']
573            approxTxT = wx.ComboBox(DData,wx.ID_ANY,choices=Choices,value=UseList[G2frame.hist]['Extinction'][0],
574                style=wx.CB_READONLY|wx.CB_DROPDOWN)
575            Indx[approxTxT.GetId()] = [G2frame.hist,0]
576            approxTxT.Bind(wx.EVT_COMBOBOX,OnSCExtType)
577            typeSizer.Add(approxTxT)
578            if UseList[G2frame.hist]['Extinction'][1] == 'None':
579                extSizer.Add(typeSizer,0)
580            else:
581                extSizer.Add(typeSizer,0,wx.BOTTOM,5)       
582                if 'Tbar' in UseList[G2frame.hist]['Extinction'][2]:       #skipped for TOF   
583                    valSizer =wx.BoxSizer(wx.HORIZONTAL)
584                    valSizer.Add(wx.StaticText(DData,wx.ID_ANY,' Tbar(mm):'),0,WACV)
585                    tbarVal = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist]['Extinction'][2],'Tbar',
586                        xmin=0.,nDig=(10,3),typeHint=float)
587                    valSizer.Add(tbarVal,0,WACV)
588                    valSizer.Add(wx.StaticText(DData,wx.ID_ANY,' cos(2ThM):'),0,WACV)
589                    cos2tm = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist]['Extinction'][2],'Cos2TM',
590                        xmin=0.,xmax=1.,nDig=(10,3),typeHint=float)
591                    valSizer.Add(cos2tm,0,WACV)
592                    extSizer.Add(valSizer,0)
593                val2Sizer =wx.BoxSizer(wx.HORIZONTAL)
594                if 'Primary' in UseList[G2frame.hist]['Extinction'][1]:
595                    Ekey = ['Ep',]
596                elif 'Secondary Type II' == UseList[G2frame.hist]['Extinction'][1]:
597                    Ekey = ['Es',]
598                elif 'Secondary Type I' == UseList[G2frame.hist]['Extinction'][1]:
599                    Ekey = ['Eg',]
600                else:
601                    Ekey = ['Eg','Es']
602                for ekey in Ekey:
603                    Eref = wx.CheckBox(DData,wx.ID_ANY,label=ekey+' : ')
604                    Eref.SetValue(UseList[G2frame.hist]['Extinction'][2][ekey][1])
605                    Indx[Eref.GetId()] = [G2frame.hist,ekey]
606                    Eref.Bind(wx.EVT_CHECKBOX, OnEref)
607                    val2Sizer.Add(Eref,0,WACV|wx.LEFT,5)
608                    Eval = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist]['Extinction'][2][ekey],0,
609                        xmin=0.,nDig=(10,3,'g'),typeHint=float)
610                    val2Sizer.Add(Eval,0,WACV)
611                extSizer.Add(val2Sizer,0)
612        else:   #PWDR
613            extSizer = wx.BoxSizer(wx.HORIZONTAL)
614            extRef = wx.CheckBox(DData,wx.ID_ANY,label=' Extinction: ')
615            extRef.SetValue(UseList[G2frame.hist]['Extinction'][1])
616            extRef.Bind(wx.EVT_CHECKBOX, OnExtRef)
617            extSizer.Add(extRef,0,WACV|wx.LEFT,5)
618            extVal = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist]['Extinction'],0,
619                xmin=0.,nDig=(10,2),typeHint=float)
620            extSizer.Add(extVal,0,WACV)
621
622        return extSizer
623       
624    def BabSizer():
625       
626        def OnBabRef(event):
627            Obj = event.GetEventObject()
628            item,bab = Indx[Obj.GetId()]
629            UseList[item]['Babinet']['Bab'+bab][1] = Obj.GetValue()
630       
631        babSizer = wx.BoxSizer(wx.HORIZONTAL)
632        for bab in ['A','U']:
633            babRef = wx.CheckBox(DData,wx.ID_ANY,label=' Babinet '+bab+': ')
634            babRef.SetValue(UseList[G2frame.hist]['Babinet']['Bab'+bab][1])
635            Indx[babRef.GetId()] = [G2frame.hist,bab]
636            babRef.Bind(wx.EVT_CHECKBOX, OnBabRef)
637            babSizer.Add(babRef,0,WACV|wx.LEFT,5)
638            babVal = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist]['Babinet']['Bab'+bab],0,
639                nDig=(10,3),xmin=0.,typeHint=float)
640            babSizer.Add(babVal,0,WACV)
641        return babSizer
642       
643    def FlackSizer():
644       
645        def OnFlackRef(event):
646            Obj = event.GetEventObject()
647            UseList[G2frame.hist]['Flack'][1] = Obj.GetValue()
648               
649        flackSizer = wx.BoxSizer(wx.HORIZONTAL)
650        flackRef = wx.CheckBox(DData,wx.ID_ANY,label=' Flack parameter: ')
651        flackRef.SetValue(UseList[G2frame.hist]['Flack'][1])
652        flackRef.Bind(wx.EVT_CHECKBOX, OnFlackRef)
653        flackSizer.Add(flackRef,0,WACV|wx.LEFT,5)
654        flackVal = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist]['Flack'],0,nDig=(10,3),typeHint=float)
655        flackSizer.Add(flackVal,0,WACV)
656        return flackSizer
657       
658    def DispSizer():
659       
660        def OnDispRef(event):
661            Obj = event.GetEventObject()
662            UseList[G2frame.hist]['Layer Disp'][1] = Obj.GetValue()
663               
664        dispSizer = wx.BoxSizer(wx.HORIZONTAL)
665        dispRef = wx.CheckBox(DData,wx.ID_ANY,label=u' Layer displacement (\xb5m): ')
666        dispRef.SetValue(UseList[G2frame.hist]['Layer Disp'][1])
667        dispRef.Bind(wx.EVT_CHECKBOX, OnDispRef)
668        dispSizer.Add(dispRef,0,WACV|wx.LEFT,5)
669        dispSizer.Add(G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist]['Layer Disp'],0,nDig=(10,2),typeHint=float),0,WACV)
670        return dispSizer
671       
672    def twinSizer():
673       
674        def OnAddTwin(event):
675            twinMat = np.array([[-1,0,0],[0,-1,0],[0,0,-1]])    #inversion by default
676            twinVal = 0.0
677            UseList[G2frame.hist]['Twins'].append([twinMat,twinVal])
678            nNonM = UseList[G2frame.hist]['Twins'][0][1][2]
679            for i in range(nNonM):
680                UseList[G2frame.hist]['Twins'].append([False,0.0])
681            addtwin.SetValue(False)
682            wx.CallLater(100,RepaintHistogramInfo,DData.GetScrollPos(wx.VERTICAL))
683           
684        def OnMat(event):
685            event.Skip()
686            Obj = event.GetEventObject()
687            it,im = Indx[Obj.GetId()]
688            newMat = Obj.GetValue().split()
689            try:
690                uvw = [int(newMat[i]) for i in range(3)]
691            except ValueError:
692                uvw = UseList[G2frame.hist]['Twins'][it][0][im]
693            UseList[G2frame.hist]['Twins'][it][0][im] = uvw
694            Obj.SetValue('%3d %3d %3d'%(uvw[0],uvw[1],uvw[2]))
695           
696        def OnTwinVal(invalid,value,tc):
697            it = Indx[tc.GetId()]
698            sumTw = 0.
699            for it,twin in enumerate(UseList[G2frame.hist]['Twins']):
700                if it:
701                    sumTw += twin[1]
702            UseList[G2frame.hist]['Twins'][0][1][0] = 1.-sumTw
703            wx.CallLater(100,RepaintHistogramInfo,DData.GetScrollPos(wx.VERTICAL))
704           
705        def OnTwinRef(event):
706            Obj = event.GetEventObject()
707            UseList[G2frame.hist]['Twins'][0][1][1] = Obj.GetValue()
708           
709        def OnTwinInv(event):
710            Obj = event.GetEventObject()
711            it = Indx[Obj.GetId()]
712            UseList[G2frame.hist]['Twins'][it][0] = Obj.GetValue()
713                       
714        def OnTwinDel(event):
715            Obj = event.GetEventObject()
716            it = Indx[Obj.GetId()]
717            nNonM = UseList[G2frame.hist]['Twins'][0][1][2]
718            for i in range(nNonM):
719                del UseList[G2frame.hist]['Twins'][1+i+it]
720            del UseList[G2frame.hist]['Twins'][it]
721            sumTw = 0.
722            for it,twin in enumerate(UseList[G2frame.hist]['Twins']):
723                if it:
724                    sumTw += twin[1]
725            UseList[G2frame.hist]['Twins'][0][1][0] = 1.-sumTw
726            if len(UseList[G2frame.hist]['Twins']) == 1:
727                UseList[G2frame.hist]['Twins'][0][1][1] = False
728            wx.CallLater(100,RepaintHistogramInfo,DData.GetScrollPos(wx.VERTICAL))           
729           
730        nTwin = len(UseList[G2frame.hist]['Twins'])
731        twinsizer = wx.BoxSizer(wx.VERTICAL)
732        topsizer = wx.BoxSizer(wx.HORIZONTAL)         
733        topsizer.Add(wx.StaticText(DData,wx.ID_ANY,' Merohedral twins: '),0,WACV)
734        #temporary - add twin not allowed if nonmerohedral twins present
735#        if nTwin == 1 or 'bool' not in str(type(UseList[G2frame.hist]['Twins'][1][0])):
736        addtwin = wx.CheckBox(DData,wx.ID_ANY,label=' Add Twin Law')
737        addtwin.Bind(wx.EVT_CHECKBOX, OnAddTwin)
738        topsizer.Add(addtwin,0,WACV|wx.LEFT,5)
739        twinsizer.Add(topsizer)
740        Indx = {}
741        if nTwin > 1:
742            for it,Twin in enumerate(UseList[G2frame.hist]['Twins']):
743                twinMat,twinVal = Twin
744                matSizer = wx.BoxSizer(wx.HORIZONTAL)
745                if it:
746                    Style = wx.TE_PROCESS_ENTER
747                    TwVal = Twin[1]
748                else:
749                    Style = wx.TE_READONLY
750                    TwVal = Twin[1][0]
751                if 'bool' not in str(type(Twin[0])):
752                    matSizer.Add(wx.StaticText(DData,-1,' Twin Law: '),0,WACV|wx.LEFT,5)
753                    for im,Mat in enumerate(twinMat):
754                        mat = wx.TextCtrl(DData,wx.ID_ANY,'%3d %3d %3d'%(Mat[0],Mat[1],Mat[2]),
755                            style=Style)
756                        if it:
757                            Indx[mat.GetId()] = [it,im]
758                            mat.Bind(wx.EVT_TEXT_ENTER,OnMat)
759                            mat.Bind(wx.EVT_KILL_FOCUS,OnMat)
760                        else:
761                            mat.SetBackgroundColour(VERY_LIGHT_GREY)
762                        matSizer.Add(mat,0,WACV|wx.LEFT,5)
763                else:
764                    matSizer.Add(wx.StaticText(DData,-1,' Nonmerohedral twin component %d: '%(it)),0,WACV|wx.LEFT,5)
765                    if not SGData['SGInv']:
766                        twinv = wx.CheckBox(DData,wx.ID_ANY,label=' Use enantiomorph?')
767                        twinv.SetValue(Twin[0])
768                        Indx[twinv.GetId()] = it
769                        twinv.Bind(wx.EVT_CHECKBOX, OnTwinInv)
770                        matSizer.Add(twinv,0,WACV)
771                twinsizer.Add(matSizer,0,wx.LEFT,5)
772                valSizer = wx.BoxSizer(wx.HORIZONTAL)
773                valSizer.Add(wx.StaticText(DData,-1,label=' Twin element fraction:'),0,WACV)
774                if it:
775                    twinval = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist]['Twins'][it],1,nDig=(10,3),
776                        xmin=0.,xmax=1.,typeHint=float,OnLeave=OnTwinVal)
777                    Indx[twinval.GetId()] = it
778                else:
779                    twinval = wx.TextCtrl(DData,-1,'%.3f'%(TwVal),style=Style)
780                    twinval.SetBackgroundColour(VERY_LIGHT_GREY)
781                valSizer.Add(twinval,0,WACV)
782                if it and 'bool' not in str(type(Twin[0])):
783                    twindel = wx.CheckBox(DData,wx.ID_ANY,label=' Delete?')
784                    Indx[twindel.GetId()] = it
785                    twindel.Bind(wx.EVT_CHECKBOX, OnTwinDel)
786                    valSizer.Add(twindel,0,WACV)
787                elif not it:
788                    twinref = wx.CheckBox(DData,wx.ID_ANY,label=' Refine?')
789                    twinref.SetValue(Twin[1][1])
790                    twinref.Bind(wx.EVT_CHECKBOX, OnTwinRef)
791                    valSizer.Add(twinref,0,WACV)
792                twinsizer.Add(valSizer,0,wx.LEFT,5)
793        return twinsizer
794       
795    def OnSelect(event):
796        G2frame.hist = G2frame.dataWindow.HistsInPhase[DData.select.GetSelection()]
797        oldFocus = wx.Window.FindFocus()
798        G2plt.PlotSizeStrainPO(G2frame,data,G2frame.hist)
799        wx.CallLater(100,RepaintHistogramInfo)
800        if oldFocus: wx.CallAfter(oldFocus.SetFocus)
801       
802    def RepaintHistogramInfo(Scroll=0):
803        if 'phoenix' in wx.version():
804            G2frame.bottomSizer.Clear(True)
805            # deal with case where this is called after another tree item has been selected
806            try:
807                DData.Shown
808            except RuntimeError:
809                if GSASIIpath.GetConfigValue('debug'):
810                    print('DBG: DData window deleted. Ignoring RepaintHistogramInfo, forcing redraw')
811                # Repaint called while DData window deleted, force redraw of entire window
812                import GSASIIdataGUI
813                G2frame.PickIdText = ''
814                wx.CallLater(100,GSASIIdataGUI.SelectDataTreeItem,G2frame,G2frame.GPXtree.Selection)
815                return
816        else:
817            # deal with case where this is called after another tree item has been selected
818            if DData.__class__ is  not wx._windows.ScrolledWindow:
819                # fix bug where this is called after the Window is deleted
820                return
821            G2frame.bottomSizer.DeleteWindows()
822        Indx.clear()
823        G2frame.bottomSizer = ShowHistogramInfo()
824        mainSizer.Add(G2frame.bottomSizer)
825        mainSizer.Layout()
826        G2frame.dataWindow.Refresh()
827        DData.SetVirtualSize(mainSizer.GetMinSize())
828        DData.Scroll(0,Scroll)
829        G2frame.dataWindow.SendSizeEvent()
830       
831    def ShowHistogramInfo():
832        '''This creates a sizer with all the information pulled out from the Phase/data dict
833        '''
834       
835        def OnUseData(event):
836            Obj = event.GetEventObject()
837            UseList[G2frame.hist]['Use'] = Obj.GetValue()
838            wx.CallLater(100,RepaintHistogramInfo,DData.GetScrollPos(wx.VERTICAL))
839
840        def OnLeBail(event):
841            Obj = event.GetEventObject()
842            if not UseList[G2frame.hist]['LeBail']:
843                UseList[G2frame.hist]['newLeBail'] = True
844                Obj.SetLabel('Do new Le Bail extraction?')
845            UseList[G2frame.hist]['LeBail'] = not UseList[G2frame.hist]['LeBail']
846        def OnResetSize(event):
847            Obj = event.GetEventObject()
848            item,name = Indx[Obj.GetId()]
849            if name == 'isotropic':
850                UseList[item]['Size'][1][0] = 1.0
851            elif name == 'uniaxial':
852                UseList[item]['Size'][1][0] = 1.0
853                UseList[item]['Size'][1][1] = 1.0
854            elif name == 'ellipsoidal':
855                for i in range(3):
856                    UseList[item]['Size'][4][i] = 1.0
857                    UseList[item]['Size'][4][i+3] = 0.0
858            G2plt.PlotSizeStrainPO(G2frame,data,item)
859            wx.CallLater(100,RepaintHistogramInfo,DData.GetScrollPos(wx.VERTICAL))
860           
861        def OnSizeAxis(event):           
862            event.Skip()
863            Obj = event.GetEventObject()
864            Saxis = Obj.GetValue().split()
865            try:
866                hkl = [int(Saxis[i]) for i in range(3)]
867            except (ValueError,IndexError):
868                hkl = UseList[G2frame.hist]['Size'][3]
869            if not np.any(np.array(hkl)):
870                hkl = UseList[G2frame.hist]['Size'][3]
871            UseList[G2frame.hist]['Size'][3] = hkl
872            h,k,l = hkl
873            Obj.SetValue('%3d %3d %3d'%(h,k,l)) 
874           
875        def OnFixVals(event):
876            Obj = event.GetEventObject()
877            UseList[G2frame.hist]['Fix FXU'] = Obj.GetValue()
878
879        if G2frame.hist not in UseList:               
880            G2frame.ErrorDialog('Missing data error',
881                    G2frame.hist+' not in GSAS-II data tree')
882            return
883#patch
884        if 'Use' not in UseList[G2frame.hist]:
885            UseList[G2frame.hist]['Use'] = True
886        if 'LeBail' not in UseList[G2frame.hist]:
887            UseList[G2frame.hist]['LeBail'] = False
888        if 'newLeBail' not in UseList[G2frame.hist]:
889            UseList[G2frame.hist]['newLeBail'] = True
890        if 'Babinet' not in UseList[G2frame.hist]:
891            UseList[G2frame.hist]['Babinet'] = {'BabA':[0.0,False],'BabU':[0.0,False]}
892        if 'Fix FXU' not in UseList[G2frame.hist]:
893            UseList[G2frame.hist]['Fix FXU'] = ' '
894        if 'FixedSeqVars' not in UseList[G2frame.hist]:
895            UseList[G2frame.hist]['FixedSeqVars'] = []
896        if 'Flack' not in UseList[G2frame.hist]:
897            UseList[G2frame.hist]['Flack'] = [0.0,False]
898        if 'Twins' not in UseList[G2frame.hist]:
899            UseList[G2frame.hist]['Twins'] = [[np.array([[1,0,0],[0,1,0],[0,0,1]]),[1.0,False]],]
900        if 'Layer Disp' not in UseList[G2frame.hist]:
901            UseList[G2frame.hist]['Layer Disp'] = [0.0,False]
902#end patch
903        bottomSizer = wx.BoxSizer(wx.VERTICAL)
904        useBox = wx.BoxSizer(wx.HORIZONTAL)
905        useData = wx.CheckBox(DData,wx.ID_ANY,label='Use Histogram: '+G2frame.hist+' ?')
906        useData.Bind(wx.EVT_CHECKBOX, OnUseData)
907        useData.SetValue(UseList[G2frame.hist]['Use'])
908        useBox.Add(useData,0,WACV)
909        if not generalData['doPawley'] and 'PWDR' in G2frame.hist[:4]:
910            lbLabel = 'Redo Le Bail extraction?   '
911            if UseList[G2frame.hist]['newLeBail']:
912                lbLabel = 'Do new Le Bail extraction?'
913            lebail = wx.CheckBox(DData,wx.ID_ANY,label=lbLabel)
914            lebail.Bind(wx.EVT_CHECKBOX, OnLeBail)
915            lebail.SetValue(UseList[G2frame.hist]['LeBail'])
916            useBox.Add(lebail,0,WACV)
917            if UseList[G2frame.hist]['LeBail']:
918                G2frame.SetStatusText('To reset Le Bail, cycle Le Bail check box.',1)
919        bottomSizer.Add(useBox,0,wx.TOP|wx.BOTTOM|wx.LEFT,5)
920        if G2frame.testSeqRefineMode():
921            bottomSizer.Add(wx.StaticText(DData,label='     Sequential Refinemment Options'))
922            parmChoice = [' ','X','XU','U','F','FX','FXU','FU']
923            if generalData['Type'] == 'magnetic':
924                parmChoice += ['M','MX','MXU','MU','MF','MFX','MFXU','MFU']
925            fixBox = wx.BoxSizer(wx.HORIZONTAL)
926            fixBox.Add(wx.StaticText(DData,label='     Fix these var types: '),0,WACV)
927            fixVals = wx.ComboBox(DData,value=UseList[G2frame.hist]['Fix FXU'],choices=parmChoice,
928                style=wx.CB_DROPDOWN)
929            fixVals.Bind(wx.EVT_COMBOBOX,OnFixVals)
930            fixBox.Add(fixVals,0,WACV)
931            fixBox.Add(wx.StaticText(DData,label=' in phase '+generalData['Name']+' for this histogram'),0,WACV)
932            bottomSizer.Add(fixBox)
933            SeqId = G2gd.GetGPXtreeItemId(G2frame, G2frame.root, 'Sequential results')
934            if SeqId:
935                fixBox = wx.BoxSizer(wx.HORIZONTAL)
936                fixBox.Add(wx.StaticText(DData,label='     Specific phase variables to fix for this histogram: '),0,WACV)
937                addFixed = wx.Button(DData,wx.ID_ANY,label='Select Vars')
938                fixBox.Add(addFixed,0,WACV)
939                addFixed.Bind(wx.EVT_BUTTON,OnAddFixed)
940                fixedVars = UseList[G2frame.hist].get('FixedSeqVars',[])
941                if len(fixedVars): 
942                    fixBox.Add(wx.StaticText(DData,label=' (currently {} fixed)'.format(len(fixedVars))),0,WACV)
943            bottomSizer.Add(fixBox)
944       
945        bottomSizer.Add(ScaleSizer(),0,wx.BOTTOM,5)
946           
947        if G2frame.hist[:4] == 'PWDR':
948            if UseList[G2frame.hist]['Size'][0] == 'isotropic':
949                isoSizer = wx.BoxSizer(wx.HORIZONTAL)
950                isoSizer.Add(TopSizer(' Domain size model: ',['isotropic','uniaxial','ellipsoidal'],
951                    'Size',OnSizeType),0,WACV)
952                isoSizer.Add(LGmixSizer('Size',[0.,1.],OnLGmixRef))
953                isoSizer.Add(ResetSizer('isotropic',OnResetSize),0,WACV)
954                bottomSizer.Add(isoSizer)
955                bottomSizer.Add(IsoSizer(u'size(\xb5m): ','Size',(10,4),[0.,4.],OnSizeRef),0,wx.BOTTOM,5)
956            elif UseList[G2frame.hist]['Size'][0] == 'uniaxial':
957                uniSizer = wx.BoxSizer(wx.HORIZONTAL)
958                uniSizer.Add(TopSizer(' Domain size model: ',['isotropic','uniaxial','ellipsoidal'],
959                    'Size',OnSizeType),0,WACV)
960                uniSizer.Add(LGmixSizer('Size',[0.,1.],OnLGmixRef))
961                uniSizer.Add(ResetSizer('uniaxial',OnResetSize),0,WACV)
962                bottomSizer.Add(UniSizer('Size',OnSizeAxis),0)
963                bottomSizer.Add(uniSizer)
964                bottomSizer.Add(UniDataSizer(u'size(\xb5m): ','Size',(10,3),[0.,4.],OnSizeRef),0,wx.BOTTOM,5)
965            elif UseList[G2frame.hist]['Size'][0] == 'ellipsoidal':
966                ellSizer = wx.BoxSizer(wx.HORIZONTAL)
967                ellSizer.Add(TopSizer(' Domain size model: ',['isotropic','uniaxial','ellipsoidal'],
968                    'Size',OnSizeType),0,WACV)
969                ellSizer.Add(LGmixSizer('Size',[0.,1.],OnLGmixRef))
970                ellSizer.Add(ResetSizer('ellipsoidal',OnResetSize),0,WACV)
971                bottomSizer.Add(ellSizer)
972                bottomSizer.Add(EllSizeDataSizer(),0,wx.BOTTOM,5)
973           
974            if UseList[G2frame.hist]['Mustrain'][0] == 'isotropic':
975                isoSizer = wx.BoxSizer(wx.HORIZONTAL)
976                isoSizer.Add(TopSizer(' Mustrain model: ',['isotropic','uniaxial','generalized',],
977                    'Mustrain',OnStrainType),0,WACV)
978                isoSizer.Add(LGmixSizer('Mustrain',[0.,1.],OnLGmixRef))
979                isoSizer.Add(ResetSizer('isotropic',OnResetStrain),0,WACV)
980                bottomSizer.Add(isoSizer)
981                bottomSizer.Add(IsoSizer(' microstrain: ','Mustrain',(10,1),[0.,1.e5],OnStrainRef),0,wx.BOTTOM,5)
982            elif UseList[G2frame.hist]['Mustrain'][0] == 'uniaxial':
983                uniSizer = wx.BoxSizer(wx.HORIZONTAL)
984                uniSizer.Add(TopSizer(' Mustrain model: ',['isotropic','uniaxial','generalized',],
985                    'Mustrain',OnStrainType),0,WACV)
986                uniSizer.Add(LGmixSizer('Mustrain',[0.,1.],OnLGmixRef))
987                uniSizer.Add(ResetSizer('uniaxial',OnResetStrain),0,WACV)
988                bottomSizer.Add(uniSizer)
989                bottomSizer.Add(UniSizer('Mustrain',OnStrainAxis),0)
990                bottomSizer.Add(UniDataSizer('mustrain: ','Mustrain',(10,1),[0.,1.e5],OnStrainRef),0,wx.BOTTOM,5)
991            elif UseList[G2frame.hist]['Mustrain'][0] == 'generalized':
992                genSizer = wx.BoxSizer(wx.HORIZONTAL)
993                genSizer.Add(TopSizer(' Mustrain model: ',['isotropic','uniaxial','generalized',],
994                    'Mustrain',OnStrainType),0,WACV)
995                genSizer.Add(LGmixSizer('Mustrain',[0.,1.],OnLGmixRef))
996                genSizer.Add(ResetSizer('generalized',OnResetStrain),0,WACV)
997                bottomSizer.Add(genSizer)
998                bottomSizer.Add(GenStrainDataSizer(),0,wx.BOTTOM,5)
999           
1000            bottomSizer.Add(wx.StaticText(DData,wx.ID_ANY,' Hydrostatic/elastic strain:'))
1001            bottomSizer.Add(HstrainSizer())
1002            bottomSizer.Add(DispSizer())
1003               
1004            poSizer = wx.BoxSizer(wx.VERTICAL)
1005            POData = UseList[G2frame.hist]['Pref.Ori.']
1006# patch - add penalty items
1007            if len(POData) < 7:
1008                POData.append(['',])
1009                POData.append(0.1)
1010            if not POData[6]:
1011                POData[6] = ['',]
1012# end patch
1013            poSizer.Add(PoTopSizer(POData))
1014            if POData[0] == 'MD':
1015                poSizer.Add(MDDataSizer(POData))
1016            else:           #'SH'
1017                if POData[4]:       #SH order > 0
1018                    textJ = G2lat.textureIndex(POData[5])
1019                    poSizer.Add(wx.StaticText(DData,wx.ID_ANY,' Spherical harmonic coefficients: '+'Texture index: %.3f'%(textJ))
1020                        ,0,wx.TOP|wx.BOTTOM,5)
1021                    poSizer.Add(SHDataSizer(POData),0,wx.TOP|wx.BOTTOM,5)
1022                    poSizer.Add(SHPenalty(POData),0,wx.TOP|wx.BOTTOM,5)
1023                   
1024            bottomSizer.Add(poSizer,0,wx.TOP|wx.BOTTOM,5)
1025            bottomSizer.Add(ExtSizer('PWDR'),0,wx.TOP|wx.BOTTOM,5)
1026            if generalData['Type'] != 'magnetic': 
1027                bottomSizer.Add(BabSizer(),0,wx.BOTTOM,5)
1028        elif G2frame.hist[:4] == 'HKLF':
1029            bottomSizer.Add(ExtSizer('HKLF'),0,wx.BOTTOM,5)
1030            bottomSizer.Add(BabSizer(),0,wx.BOTTOM,5)
1031            if not SGData['SGInv'] and len(UseList[G2frame.hist]['Twins']) < 2:
1032                bottomSizer.Add(FlackSizer(),0,wx.BOTTOM,5)
1033            bottomSizer.Add(twinSizer(),0,wx.BOTTOM,5)
1034        return bottomSizer
1035
1036    ######################################################################
1037    ### Beginning of UpdateDData execution here
1038    ######################################################################
1039    G2frame.SetStatusText('',1)
1040    keyList = G2frame.GetHistogramNames(['PWDR','HKLF'])
1041    UseList = data['Histograms']
1042    # look for histgrams that are no longer in the project (should not happen!)
1043    broken = [i for i in UseList if i not in keyList]
1044    if broken:
1045        msg = 'Removing histogram(s) referenced in this phase that are no longer in project:\n\n'
1046        for i,j in enumerate(broken): 
1047            if i > 0: msg += ', '
1048            msg += j
1049            del data['Histograms'][j]
1050        G2G.G2MessageBox(G2frame,msg,'Removing bad histograms')
1051    if UseList:
1052        G2frame.dataWindow.DataMenu.Enable(G2G.wxID_DATADELETE,True)
1053        for item in G2frame.Refine: item.Enable(True)
1054    else:
1055        G2frame.dataWindow.DataMenu.Enable(G2G.wxID_DATADELETE,False)
1056        for item in G2frame.Refine: item.Enable(False)
1057    # make a list of histograms (any type) used in this phase, ordered as in tree
1058    G2frame.dataWindow.HistsInPhase = [name for name in keyList if name in UseList]
1059    generalData = data['General']
1060    cell = generalData['Cell'][1:]
1061    Amat,Bmat = G2lat.cell2AB(cell[:6])
1062    PhaseName = generalData['Name']       
1063    SGData = generalData['SGData']
1064    if len(G2frame.dataWindow.HistsInPhase) == 0: # no associated histograms, nothing to display here
1065        G2frame.hist = ''
1066    elif hist and hist in G2frame.dataWindow.HistsInPhase: # something was input as a selection as an argument
1067        G2frame.hist = hist
1068    elif (not G2frame.hist) or (G2frame.hist not in G2frame.dataWindow.HistsInPhase): # no or bad selection but have data, take the first
1069        G2frame.hist = G2frame.dataWindow.HistsInPhase[0]
1070    Indx = {}
1071   
1072    if DData.GetSizer():
1073        try:
1074            if hasattr(DData,'select'): 
1075                DData.select.Unbind(wx.EVT_LISTBOX)  # remove binding to avoid event on Linux
1076        except:
1077            pass
1078        DData.GetSizer().Clear(True)
1079    mainSizer = wx.BoxSizer(wx.VERTICAL)
1080    topSizer = wx.BoxSizer(wx.HORIZONTAL)
1081    topSizer.Add(wx.StaticText(DData,wx.ID_ANY,' Histogram data for '+PhaseName+':'),0,wx.LEFT,5)
1082    # add help button to bring up help web page - at right sede of window
1083    topSizer.Add((-1,-1),1,wx.EXPAND)
1084    topSizer.Add(G2G.HelpButton(DData,helpIndex=G2frame.dataWindow.helpKey))
1085    mainSizer.Add(topSizer,0,wx.EXPAND)
1086    if G2frame.hist:
1087        topSizer = wx.FlexGridSizer(1,2,5,5)
1088        DData.select = wx.ListBox(DData,choices=G2frame.dataWindow.HistsInPhase,
1089                            style=wx.LB_SINGLE,size=(-1,160))
1090        DData.select.SetSelection(G2frame.dataWindow.HistsInPhase.index(G2frame.hist))
1091        DData.select.SetFirstItem(G2frame.dataWindow.HistsInPhase.index(G2frame.hist))
1092        DData.select.Bind(wx.EVT_LISTBOX,OnSelect)
1093        topSizer.Add(DData.select,0,WACV|wx.LEFT,5)
1094        if any(['PWDR' in item for item in keyList]):
1095            topSizer.Add(PlotSizer())
1096        mainSizer.Add(topSizer)       
1097        G2frame.bottomSizer = ShowHistogramInfo()
1098        mainSizer.Add(G2frame.bottomSizer)
1099    elif not keyList:
1100        mainSizer.Add(wx.StaticText(DData,wx.ID_ANY,
1101            '  (This project has no data; use Import to read it)'),0,wx.TOP,10)
1102    elif not UseList in G2frame.dataWindow.HistsInPhase:
1103        mainSizer.Add(wx.StaticText(DData,wx.ID_ANY,
1104            '  (This phase has no associated data; use appropriate Edit/Add... menu item)'),0,wx.TOP,10)
1105    else:
1106        mainSizer.Add(wx.StaticText(DData,wx.ID_ANY,'  (Strange, how did we get here?)'),0,wx.TOP,10)
1107       
1108    G2phG.SetPhaseWindow(DData,mainSizer,Scroll=Scroll)
Note: See TracBrowser for help on using the repository browser.