source: trunk/GSASIIddataGUI.py @ 3296

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

add selection for mustain, size & 3D pole distribution projections

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