source: trunk/GSASIIddataGUI.py @ 4046

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

remove histograms that are not added to a phse from the Seq Ref refinement; skip histograms w/o Use flag in mass fraction computation

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