source: trunk/GSASIIddataGUI.py @ 4534

Last change on this file since 4534 was 4534, checked in by toby, 3 years ago

implement variable limits; show cell under Dij vals

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