source: trunk/GSASIIddataGUI.py @ 1894

Last change on this file since 1894 was 1894, checked in by vondreele, 8 years ago

Twins & Flack parameter can't exist together - make each exclusive
rename TwinFr?;n as TwinFr:n so constraint will work
Add a "Clear" option for fixed background points
Prevent Add, Move, Del ops. for fixed points when toolbar active

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 47.2 KB
Line 
1# -*- coding: utf-8 -*-
2#GSASII - phase data display routines
3########### SVN repository information ###################
4# $Date: 2015-06-17 18:12:45 +0000 (Wed, 17 Jun 2015) $
5# $Author: vondreele $
6# $Revision: 1894 $
7# $URL: trunk/GSASIIddataGUI.py $
8# $Id: GSASIIddataGUI.py 1894 2015-06-17 18:12:45Z 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: 1894 $")
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            addtwin.SetValue(False)
786            wx.CallLater(100,RepaintHistogramInfo)
787           
788        def OnMat(event):
789            Obj = event.GetEventObject()
790            it,im = Indx[Obj.GetId()]
791            newMat = Obj.GetValue().split()
792            try:
793                uvw = [int(newMat[i]) for i in range(3)]
794            except ValueError:
795                uvw = UseList[G2frame.hist]['Twins'][it][0][im]
796            UseList[G2frame.hist]['Twins'][it][0][im] = uvw
797            Obj.SetValue('%d %d %d'%(uvw[0],uvw[1],uvw[2]))
798           
799        def OnTwinVal(event):
800            Obj = event.GetEventObject()
801            it = Indx[Obj.GetId()]
802            try:
803                val = float(Obj.GetValue())
804                if 0. > val > 1.:
805                    raise ValueError
806            except ValueError:
807                val = UseList[G2frame.hist]['Twins'][it][1]
808            UseList[G2frame.hist]['Twins'][it][1] = val
809            sumTw = 0.
810            for it,twin in enumerate(UseList[G2frame.hist]['Twins']):
811                if it:
812                    sumTw += twin[1]
813            UseList[G2frame.hist]['Twins'][0][1][0] = 1.-sumTw
814            wx.CallLater(100,RepaintHistogramInfo)
815           
816        def OnTwinRef(event):
817            Obj = event.GetEventObject()
818            UseList[G2frame.hist]['Twins'][0][1][1] = Obj.GetValue()
819                       
820        def OnTwinDel(event):
821            Obj = event.GetEventObject()
822            it = Indx[Obj.GetId()]
823            del UseList[G2frame.hist]['Twins'][it]
824            sumTw = 0.
825            for it,twin in enumerate(UseList[G2frame.hist]['Twins']):
826                if it:
827                    sumTw += twin[1]
828            UseList[G2frame.hist]['Twins'][0][1][0] = 1.-sumTw
829            if len(UseList[G2frame.hist]['Twins']) == 1:
830                UseList[G2frame.hist]['Twins'][0][1][1] = False
831            wx.CallLater(100,RepaintHistogramInfo)           
832           
833        twinsizer = wx.BoxSizer(wx.VERTICAL)
834        topsizer = wx.BoxSizer(wx.HORIZONTAL)         
835        topsizer.Add(wx.StaticText(DData,wx.ID_ANY,' Merohedral/pseudomerohedral twins: '),0,WACV)
836        addtwin = wx.CheckBox(DData,wx.ID_ANY,label=' Add Twin Law')
837        addtwin.Bind(wx.EVT_CHECKBOX, OnAddTwin)
838        topsizer.Add(addtwin,0,WACV)
839        twinsizer.Add(topsizer)
840        Indx = {}
841        nTwin = len(UseList[G2frame.hist]['Twins'])
842        if nTwin > 1:
843            for it,Twin in enumerate(UseList[G2frame.hist]['Twins']):
844                twinMat,twinVal = Twin
845                matSizer = wx.BoxSizer(wx.HORIZONTAL)
846                matSizer.Add(wx.StaticText(DData,-1,' Twin Law: '),0,WACV)
847                if it:
848                    Style = wx.TE_PROCESS_ENTER
849                    TwVal = Twin[1]
850                else:
851                    Style = wx.TE_READONLY
852                    TwVal = Twin[1][0]
853                for im,Mat in enumerate(twinMat):
854                    mat = wx.TextCtrl(DData,wx.ID_ANY,'%3d %3d %3d'%(Mat[0],Mat[1],Mat[2]),
855                        style=Style)
856                    if it:
857                        Indx[mat.GetId()] = [it,im]
858                        mat.Bind(wx.EVT_TEXT_ENTER,OnMat)
859                        mat.Bind(wx.EVT_KILL_FOCUS,OnMat)
860                    else:
861                        mat.SetBackgroundColour(VERY_LIGHT_GREY)
862                    matSizer.Add(mat,0,WACV|wx.LEFT,5)
863                twinsizer.Add(matSizer,0,WACV|wx.LEFT,5)
864                valSizer = wx.BoxSizer(wx.HORIZONTAL)
865                valSizer.Add(wx.StaticText(DData,-1,label=' Twin element fraction:'),0,WACV)
866                twinval = wx.TextCtrl(DData,-1,'%.3f'%(TwVal),style=wx.TE_PROCESS_ENTER)
867                Indx[twinval.GetId()] = it
868                twinval.Bind(wx.EVT_TEXT_ENTER,OnTwinVal)
869                twinval.Bind(wx.EVT_KILL_FOCUS,OnTwinVal)
870                if not it:
871                    twinval.SetBackgroundColour(VERY_LIGHT_GREY)
872                valSizer.Add(twinval,0,WACV)
873                if it:
874                    twindel = wx.CheckBox(DData,wx.ID_ANY,label=' Delete?')
875                    Indx[twindel.GetId()] = it
876                    twindel.Bind(wx.EVT_CHECKBOX, OnTwinDel)
877                    valSizer.Add(twindel,0,WACV)
878                else:
879                    twinref = wx.CheckBox(DData,wx.ID_ANY,label=' Refine?')
880                    twinref.SetValue(Twin[1][1])
881                    twinref.Bind(wx.EVT_CHECKBOX, OnTwinRef)
882                    valSizer.Add(twinref,0,WACV)
883                twinsizer.Add(valSizer,0,WACV|wx.LEFT,5)
884        return twinsizer
885       
886    def OnSelect(event):
887        G2frame.hist = keyList[select.GetSelection()]
888        oldFocus = wx.Window.FindFocus()
889        G2plt.PlotSizeStrainPO(G2frame,data,G2frame.hist)
890        oldFocus.SetFocus()
891        wx.CallLater(100,RepaintHistogramInfo)
892       
893    def RepaintHistogramInfo():
894        G2frame.bottomSizer.DeleteWindows()
895        Indx.clear()
896        G2frame.bottomSizer = ShowHistogramInfo()
897        mainSizer.Add(G2frame.bottomSizer)
898        mainSizer.Layout()
899        G2frame.dataFrame.Refresh()
900        DData.SetVirtualSize(mainSizer.GetMinSize())
901        G2frame.dataFrame.SendSizeEvent()
902       
903    def ShowHistogramInfo():
904       
905        def OnUseData(event):
906            Obj = event.GetEventObject()
907            UseList[G2frame.hist]['Use'] = Obj.GetValue()
908       
909        def OnResetSize(event):
910            Obj = event.GetEventObject()
911            Obj.SetValue(False)
912            item,name = Indx[Obj.GetId()]
913            if name == 'isotropic':
914                UseList[item]['Size'][1][0] = 1.0
915            elif name == 'uniaxial':
916                UseList[item]['Size'][1][0] = 1.0
917                UseList[item]['Size'][1][1] = 1.0
918            elif name == 'ellipsoidal':
919                for i in range(3):
920                    UseList[item]['Size'][4][i] = 1.0
921                    UseList[item]['Size'][4][i+3] = 0.0
922            G2plt.PlotSizeStrainPO(G2frame,data,item)
923            wx.CallLater(100,RepaintHistogramInfo)
924           
925        def OnSizeAxis(event):           
926            Obj = event.GetEventObject()
927            Saxis = Obj.GetValue().split()
928            try:
929                hkl = [int(Saxis[i]) for i in range(3)]
930            except (ValueError,IndexError):
931                hkl = UseList[G2frame.hist]['Size'][3]
932            if not np.any(np.array(hkl)):
933                hkl = UseList[G2frame.hist]['Size'][3]
934            UseList[G2frame.hist]['Size'][3] = hkl
935            h,k,l = hkl
936            Obj.SetValue('%3d %3d %3d'%(h,k,l)) 
937                       
938        try:
939            histData = UseList[G2frame.hist]
940        except KeyError:
941            G2frame.ErrorDialog('Missing data error',
942                    G2frame.hist+' not in GSAS-II data tree')
943            return
944        if 'Use' not in UseList[G2frame.hist]:      #patch
945            UseList[G2frame.hist]['Use'] = True
946        if 'Babinet' not in UseList[G2frame.hist]:
947            UseList[G2frame.hist]['Babinet'] = {'BabA':[0.0,False],'BabU':[0.0,False]}
948        bottomSizer = wx.BoxSizer(wx.VERTICAL)
949        useData = wx.CheckBox(DData,wx.ID_ANY,label='Use Histogram: '+G2frame.hist+' ?')
950        useData.Bind(wx.EVT_CHECKBOX, OnUseData)
951        useData.SetValue(UseList[G2frame.hist]['Use'])
952        bottomSizer.Add(useData,0,WACV|wx.TOP|wx.BOTTOM|wx.LEFT,5)
953       
954        bottomSizer.Add(ScaleSizer(),0,WACV|wx.BOTTOM,5)
955           
956        if G2frame.hist[:4] == 'PWDR':
957            if UseList[G2frame.hist]['Size'][0] == 'isotropic':
958                isoSizer = wx.BoxSizer(wx.HORIZONTAL)
959                isoSizer.Add(TopSizer(' Domain size model: ',['isotropic','uniaxial','ellipsoidal'],
960                    'Size',OnSizeType),0,WACV)
961                isoSizer.Add(LGmixSizer('Size',OnLGmixVal,OnLGmixRef))
962                isoSizer.Add(ResetSizer('isotropic',OnResetSize),0,WACV)
963                bottomSizer.Add(isoSizer)
964                bottomSizer.Add(IsoSizer(u'size(\xb5m): ','Size','%.5f',
965                    OnSizeVal,OnSizeRef),0,WACV|wx.BOTTOM,5)
966            elif UseList[G2frame.hist]['Size'][0] == 'uniaxial':
967                uniSizer = wx.BoxSizer(wx.HORIZONTAL)
968                uniSizer.Add(TopSizer(' Domain size model: ',['isotropic','uniaxial','ellipsoidal'],
969                    'Size',OnSizeType),0,WACV)
970                uniSizer.Add(LGmixSizer('Size',OnLGmixVal,OnLGmixRef))
971                uniSizer.Add(ResetSizer('uniaxial',OnResetSize),0,WACV)
972                bottomSizer.Add(UniSizer('Size',OnSizeAxis),0,WACV)
973                bottomSizer.Add(uniSizer)
974                bottomSizer.Add(UniDataSizer(u'size(\xb5m): ','Size','%.5f',OnSizeVal,OnSizeRef)
975                    ,0,WACV|wx.BOTTOM,5)
976            elif UseList[G2frame.hist]['Size'][0] == 'ellipsoidal':
977                ellSizer = wx.BoxSizer(wx.HORIZONTAL)
978                ellSizer.Add(TopSizer(' Domain size model: ',['isotropic','uniaxial','ellipsoidal'],
979                    'Size',OnSizeType),0,WACV)
980                ellSizer.Add(LGmixSizer('Size',OnLGmixVal,OnLGmixRef))
981                ellSizer.Add(ResetSizer('ellipsoidal',OnResetSize),0,WACV)
982                bottomSizer.Add(ellSizer)
983                bottomSizer.Add(EllSizeDataSizer(),0,WACV|wx.BOTTOM,5)
984           
985            if UseList[G2frame.hist]['Mustrain'][0] == 'isotropic':
986                isoSizer = wx.BoxSizer(wx.HORIZONTAL)
987                isoSizer.Add(TopSizer(' Mustrain model: ',['isotropic','uniaxial','generalized',],
988                    'Mustrain',OnStrainType),0,WACV)
989                isoSizer.Add(LGmixSizer('Mustrain',OnLGmixVal,OnLGmixRef))
990                isoSizer.Add(ResetSizer('isotropic',OnResetStrain),0,WACV)
991                bottomSizer.Add(isoSizer)
992                bottomSizer.Add(IsoSizer(' microstrain: ','Mustrain','%.1f',
993                    OnStrainVal,OnStrainRef),0,WACV|wx.BOTTOM,5)
994            elif UseList[G2frame.hist]['Mustrain'][0] == 'uniaxial':
995                uniSizer = wx.BoxSizer(wx.HORIZONTAL)
996                uniSizer.Add(TopSizer(' Mustrain model: ',['isotropic','uniaxial','generalized',],
997                    'Mustrain',OnStrainType),0,WACV)
998                uniSizer.Add(LGmixSizer('Mustrain',OnLGmixVal,OnLGmixRef))
999                uniSizer.Add(ResetSizer('uniaxial',OnResetStrain),0,WACV)
1000                bottomSizer.Add(uniSizer)
1001                bottomSizer.Add(UniSizer('Mustrain',OnStrainAxis),0,WACV)
1002                bottomSizer.Add(UniDataSizer('mustrain: ','Mustrain','%.1f',OnStrainVal,OnStrainRef)
1003                                ,0,WACV|wx.BOTTOM,5)
1004            elif UseList[G2frame.hist]['Mustrain'][0] == 'generalized':
1005                genSizer = wx.BoxSizer(wx.HORIZONTAL)
1006                genSizer.Add(TopSizer(' Mustrain model: ',['isotropic','uniaxial','generalized',],
1007                    'Mustrain',OnStrainType),0,WACV)
1008                genSizer.Add(LGmixSizer('Mustrain',OnLGmixVal,OnLGmixRef))
1009                genSizer.Add(ResetSizer('generalized',OnResetStrain),0,WACV)
1010                bottomSizer.Add(genSizer)
1011                bottomSizer.Add(GenStrainDataSizer(),0,WACV|wx.BOTTOM,5)
1012           
1013            bottomSizer.Add(wx.StaticText(DData,wx.ID_ANY,' Hydrostatic/elastic strain:'))
1014            bottomSizer.Add(HstrainSizer())
1015               
1016            poSizer = wx.BoxSizer(wx.VERTICAL)
1017            POData = UseList[G2frame.hist]['Pref.Ori.']
1018# patch - add penalty items
1019            if len(POData) < 7:
1020                POData.append(['',])
1021                POData.append(0.1)
1022            if not POData[6]:
1023                POData[6] = ['',]
1024# end patch
1025            poSizer.Add(PoTopSizer(POData))
1026            if POData[0] == 'MD':
1027                poSizer.Add(MDDataSizer(POData))
1028            else:           #'SH'
1029                if POData[4]:       #SH order > 0
1030                    textJ = G2lat.textureIndex(POData[5])
1031                    poSizer.Add(wx.StaticText(DData,wx.ID_ANY,' Spherical harmonic coefficients: '+'Texture index: %.3f'%(textJ))
1032                        ,0,WACV|wx.TOP|wx.BOTTOM,5)
1033                    poSizer.Add(SHDataSizer(POData),0,WACV|wx.TOP|wx.BOTTOM,5)
1034                    poSizer.Add(SHPenalty(POData),0,WACV|wx.TOP|wx.BOTTOM,5)
1035                   
1036            bottomSizer.Add(poSizer,0,WACV|wx.TOP|wx.BOTTOM,5)
1037            bottomSizer.Add(ExtSizer('PWDR'),0,WACV|wx.TOP|wx.BOTTOM,5)
1038            bottomSizer.Add(BabSizer(),0,WACV|wx.BOTTOM,5)
1039        elif G2frame.hist[:4] == 'HKLF':
1040#patch
1041            if 'Flack' not in UseList[G2frame.hist]:
1042                UseList[G2frame.hist]['Flack'] = [0.0,False]
1043            if 'Twins' not in UseList[G2frame.hist]:
1044                UseList[G2frame.hist]['Twins'] = [[np.array([[1,0,0],[0,1,0],[0,0,1]]),[1.0,False]],]
1045#end patch
1046            bottomSizer.Add(ExtSizer('HKLF'),0,WACV|wx.BOTTOM,5)
1047            bottomSizer.Add(BabSizer(),0,WACV|wx.BOTTOM,5)
1048            if not SGData['SGInv'] and len(UseList[G2frame.hist]['Twins']) < 2:
1049                bottomSizer.Add(FlackSizer(),0,WACV|wx.BOTTOM,5)
1050            bottomSizer.Add(twinSizer(),0,WACV|wx.BOTTOM,5)
1051        return bottomSizer
1052               
1053    if DData.GetSizer():
1054        DData.GetSizer().Clear(True)
1055    useList = []
1056    for name in keyList:
1057        if name in UseList:
1058            useList.append(name)
1059    mainSizer = wx.BoxSizer(wx.VERTICAL)
1060    mainSizer.Add(wx.StaticText(DData,wx.ID_ANY,' Histogram data for '+PhaseName+':'),0,WACV)
1061    if G2frame.hist != '':
1062        topSizer = wx.FlexGridSizer(1,2,5,5)
1063        select = wx.ListBox(DData,choices=useList,style=wx.LB_SINGLE,size=(-1,120))
1064        select.SetSelection(useList.index(G2frame.hist))
1065        select.SetFirstItem(useList.index(G2frame.hist))
1066        select.Bind(wx.EVT_LISTBOX,OnSelect)
1067        topSizer.Add(select,0,WACV|wx.LEFT,5)
1068        if PWDR:
1069            topSizer.Add(PlotSizer())
1070        mainSizer.Add(topSizer)       
1071        G2frame.bottomSizer = ShowHistogramInfo()
1072        mainSizer.Add(G2frame.bottomSizer)
1073    elif not keyList:
1074        mainSizer.Add(wx.StaticText(DData,wx.ID_ANY,'  (This project has no data; use Import to read it)'),
1075                      0,WACV|wx.TOP,10)
1076    elif not UseList:
1077        mainSizer.Add(wx.StaticText(DData,wx.ID_ANY,'  (This phase has no associated data; use appropriate Edit/Add... menu item)'),
1078                      0,WACV|wx.TOP,10)
1079    else:
1080        mainSizer.Add(wx.StaticText(DData,wx.ID_ANY,'  (Strange, how did we get here?)'),
1081                      0,WACV|wx.TOP,10)
1082       
1083    G2phsGUI.SetPhaseWindow(G2frame.dataFrame,DData,mainSizer)
Note: See TracBrowser for help on using the repository browser.