source: trunk/GSASIIddataGUI.py @ 4523

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

more fullrmc work, but not done

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