source: trunk/GSASIIddataGUI.py @ 1954

Last change on this file since 1954 was 1922, checked in by vondreele, 10 years ago

fix 1 atom powder bug
implement merohedral twins of nonmerohedral twin members

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