source: trunk/GSASIIddataGUI.py @ 4185

Last change on this file since 4185 was 4080, checked in by vondreele, 6 years ago

fix to ellipsoid size math & GUI revisions

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