source: trunk/GSASIIddataGUI.py @ 4655

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

problem with "generalized" mustrain for R3 now fixed.The S301 term should not have been present.

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