source: trunk/GSASIIddataGUI.py @ 4427

Last change on this file since 4427 was 4416, checked in by vondreele, 5 years ago

fix 3D surface problem when changing mystrain/size axis
remove MPLsubplots - obsolete sine mpl 2.2
reduce mpl > 3.03 warnings to just one
fix plotting of 3D size/mustrain surfaces - now consistent with values & table
add size & mustrain columns to Reflection Lists - checked against plots
provide better escape from crashed sequential refinement

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