Source code for GSASIIpwdGUI

# -*- coding: utf-8 -*-
#GSASIIpwdGUI - powder data display routines
########### SVN repository information ###################
# $Date: 2021-08-25 19:37:53 +0000 (Wed, 25 Aug 2021) $
# $Author: vondreele $
# $Revision: 5016 $
# $URL: https://subversion.xray.aps.anl.gov/pyGSAS/trunk/GSASIIpwdGUI.py $
# $Id: GSASIIpwdGUI.py 5016 2021-08-25 19:37:53Z vondreele $
########### SVN repository information ###################
'''
*GSASIIpwdGUI: Powder Pattern GUI routines*
-------------------------------------------

Used to define GUI controls for the routines that interact
with the powder histogram (PWDR) data tree items.

'''
from __future__ import division, print_function
import platform
import sys
import os.path
# Don't depend on graphics for scriptable
try:
    import wx
    import wx.grid as wg
except ImportError:
    pass
import numpy as np
import numpy.linalg as nl
import numpy.ma as ma
import math
import copy
import random as ran
if '2' in platform.python_version_tuple()[0]:
    import cPickle
else:
    import pickle as cPickle
import scipy.interpolate as si
import GSASIIpath
GSASIIpath.SetVersionNumber("$Revision: 5016 $")
import GSASIImath as G2mth
import GSASIIpwd as G2pwd
import GSASIIfiles as G2fil
import GSASIIobj as G2obj
import GSASIIlattice as G2lat
import GSASIIspc as G2spc
import GSASIIindex as G2indx
import GSASIIplot as G2plt
import GSASIIdataGUI as G2gd
import GSASIIphsGUI as G2phsG
import GSASIIctrlGUI as G2G
import GSASIIElemGUI as G2elemGUI
import GSASIIElem as G2elem
import GSASIIsasd as G2sasd
import G2shapes
import SUBGROUPS as kSUB
VERY_LIGHT_GREY = wx.Colour(235,235,235)
WACV = wx.ALIGN_CENTER_VERTICAL
if '2' in platform.python_version_tuple()[0]:
    GkDelta = unichr(0x0394)
    GkSigma = unichr(0x03a3)
    GkTheta = unichr(0x03f4)
    Gklambda = unichr(0x03bb)
    Pwr10 = unichr(0x0b9)+unichr(0x2070)
    Pwr20 = unichr(0x0b2)+unichr(0x2070)
    Pwrm1 = unichr(0x207b)+unichr(0x0b9)
    Pwrm2 = unichr(0x207b)+unichr(0x0b2)
    Pwrm6 = unichr(0x207b)+unichr(0x2076)
    Pwrm4 = unichr(0x207b)+unichr(0x2074)
    Angstr = unichr(0x00c5)
    superMinusOne = unichr(0xaf)+unichr(0xb9)
else:
    GkDelta = chr(0x0394)
    GkSigma = chr(0x03a3)
    GkTheta = chr(0x03f4)
    Gklambda = chr(0x03bb)
    Pwr10 = chr(0x0b9)+chr(0x2070)
    Pwr20 = chr(0x0b2)+chr(0x2070)
    Pwrm1 = chr(0x207b)+chr(0x0b9)
    Pwrm2 = chr(0x207b)+chr(0x0b2)
    Pwrm6 = chr(0x207b)+chr(0x2076)
    Pwrm4 = chr(0x207b)+chr(0x2074)
    Angstr = chr(0x00c5)
    superMinusOne = chr(0xaf)+chr(0xb9)
# trig functions in degrees
sind = lambda x: math.sin(x*math.pi/180.)
tand = lambda x: math.tan(x*math.pi/180.)
cosd = lambda x: math.cos(x*math.pi/180.)
asind = lambda x: 180.*math.asin(x)/math.pi
    
################################################################################
###### class definitions
################################################################################

[docs]class SubCellsDialog(wx.Dialog): def __init__(self,parent,title,controls,SGData,items,phaseDict): wx.Dialog.__init__(self,parent,-1,title, pos=wx.DefaultPosition,style=wx.DEFAULT_DIALOG_STYLE) self.panel = None self.controls = controls self.SGData = SGData #for parent phase self.items = items self.phaseDict = phaseDict self.Draw() def Draw(self): def RefreshGrid(event): r,c = event.GetRow(),event.GetCol() br = self.items[r] phase = self.phaseDict[br] rLab = magDisplay.GetRowLabelValue(r) pname = '(%s) %s'%(rLab,phase['Name']) if c == 0: mSGData = phase['SGData'] text,table = G2spc.SGPrint(mSGData,AddInv=True) if 'magAtms' in phase: msg = 'Magnetic space group information' text[0] = ' Magnetic Space Group: '+mSGData['MagSpGrp'] text[3] = ' The magnetic lattice point group is '+mSGData['MagPtGp'] OprNames,SpnFlp = G2spc.GenMagOps(mSGData) G2G.SGMagSpinBox(self.panel,msg,text,table,mSGData['SGCen'],OprNames, mSGData['SpnFlp'],False).Show() else: msg = 'Space Group Information' G2G.SGMessageBox(self.panel,msg,text,table).Show() elif c == 1: maxequiv = phase['maxequiv'] mSGData = phase['SGData'] Uvec = phase['Uvec'] Trans = phase['Trans'] ifMag = False if 'magAtms' in phase: ifMag = True allmom = phase.get('allmom',False) magAtms = phase.get('magAtms','') mAtoms = TestMagAtoms(phase,magAtms,self.SGData,Uvec,Trans,allmom,maxequiv) else: mAtoms = TestAtoms(phase,self.controls[15],self.SGData,Uvec,Trans,maxequiv) Atms = [] AtCods = [] atMxyz = [] for ia,atom in enumerate(mAtoms): atom[0] += '_%d'%ia SytSym,Mul,Nop,dupDir = G2spc.SytSym(atom[2:5],mSGData) Atms.append(atom[:2]+['',]+atom[2:5]) AtCods.append('1') if 'magAtms' in phase: MagSytSym = G2spc.MagSytSym(SytSym,dupDir,mSGData) CSI = G2spc.GetCSpqinel(mSGData['SpnFlp'],dupDir) atMxyz.append([MagSytSym,CSI[0]]) else: CSI = G2spc.GetCSxinel(SytSym) atMxyz.append([SytSym,CSI[0]]) G2phsG.UseMagAtomDialog(self.panel,pname,Atms,AtCods,atMxyz,ifMag=ifMag,ifOK=True).Show() elif c in [2,3]: if c == 2: title = 'Conjugacy list for '+pname items = phase['altList'] elif c == 3: title = 'Super groups list list for '+pname items = phase['supList'] if not items[0]: wx.MessageBox(pname+' is a maximal subgroup',caption='Super group is parent',style=wx.ICON_INFORMATION) return SubCellsDialog(self.panel,title,self.controls,self.SGData,items,self.phaseDict).Show() if self.panel: self.panel.Destroy() self.panel = wx.Panel(self) rowLabels = [str(i+1) for i in range(len(self.items))] colLabels = ['Space Gp','Uniq','nConj','nSup','Trans','Vec','a','b','c','alpha','beta','gamma','Volume'] Types = [wg.GRID_VALUE_STRING,]+3*[wg.GRID_VALUE_LONG,]+2*[wg.GRID_VALUE_STRING,]+ \ 3*[wg.GRID_VALUE_FLOAT+':10,5',]+3*[wg.GRID_VALUE_FLOAT+':10,3',]+[wg.GRID_VALUE_FLOAT+':10,2'] table = [] for ip in self.items: phase = self.phaseDict[ip] natms = phase.get('nAtoms',1) try: nConj = len(phase['altList']) nSup = len(phase['supList']) except KeyError: nConj = 0 nSup = 0 cell = list(phase['Cell']) trans = G2spc.Trans2Text(phase['Trans']) vec = G2spc.Latt2text([phase['Uvec'],]) row = [phase['Name'],natms,nConj,nSup,trans,vec]+cell table.append(row) CellsTable = G2G.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types) mainSizer = wx.BoxSizer(wx.VERTICAL) magDisplay = G2G.GSGrid(self.panel) magDisplay.SetTable(CellsTable, True) magDisplay.Bind(wg.EVT_GRID_CELL_LEFT_CLICK,RefreshGrid) magDisplay.AutoSizeColumns(False) mainSizer.Add(magDisplay,0) OkBtn = wx.Button(self.panel,-1,"Ok") OkBtn.Bind(wx.EVT_BUTTON, self.OnOk) btnSizer = wx.BoxSizer(wx.HORIZONTAL) btnSizer.Add((20,20),1) btnSizer.Add(OkBtn) btnSizer.Add((20,20),1) mainSizer.Add(btnSizer,0,wx.EXPAND|wx.BOTTOM|wx.TOP, 10) self.panel.SetSizer(mainSizer) self.panel.Fit() self.Fit() def OnOk(self,event): parent = self.GetParent() parent.Raise() self.Destroy()
# self.EndModal(wx.ID_OK)
[docs]class RDFDialog(wx.Dialog): def __init__(self,parent): wx.Dialog.__init__(self,parent,-1,'Background radial distribution function', pos=wx.DefaultPosition,style=wx.DEFAULT_DIALOG_STYLE) self.panel = None self.result = {'UseObsCalc':'obs-calc','maxR':20.0,'Smooth':'linear'} self.Draw() def Draw(self): def OnUseOC(event): self.result['UseObsCalc'] = useOC.GetValue() def OnSmCombo(event): self.result['Smooth'] = smCombo.GetValue() if self.panel: self.panel.Destroy() self.panel = wx.Panel(self) mainSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(wx.StaticText(self.panel,label='Background RDF controls:'),0) plotType = wx.BoxSizer(wx.HORIZONTAL) plotType.Add(wx.StaticText(self.panel,label=' Select plot type:'),0,WACV) Choices = ['obs-back','calc-back','obs-calc'] useOC = wx.ComboBox(self.panel,value=Choices[2],choices=Choices, style=wx.CB_READONLY|wx.CB_DROPDOWN) useOC.SetValue(self.result['UseObsCalc']) useOC.Bind(wx.EVT_COMBOBOX,OnUseOC) plotType.Add(useOC,0,WACV) mainSizer.Add(plotType,0) dataSizer = wx.BoxSizer(wx.HORIZONTAL) dataSizer.Add(wx.StaticText(self.panel,label=' Smoothing type: '),0,WACV) smChoice = ['linear','nearest',] smCombo = wx.ComboBox(self.panel,value=self.result['Smooth'],choices=smChoice, style=wx.CB_READONLY|wx.CB_DROPDOWN) smCombo.Bind(wx.EVT_COMBOBOX, OnSmCombo) dataSizer.Add(smCombo,0,WACV) dataSizer.Add(wx.StaticText(self.panel,label=' Maximum radial dist.: '),0,WACV) maxR = G2G.ValidatedTxtCtrl(self.panel,self.result,'maxR',nDig=(10,1),xmin=10.,xmax=50., typeHint=float) dataSizer.Add(maxR,0,WACV) mainSizer.Add(dataSizer,0) OkBtn = wx.Button(self.panel,-1,"Ok") OkBtn.Bind(wx.EVT_BUTTON, self.OnOk) cancelBtn = wx.Button(self.panel,-1,"Cancel") cancelBtn.Bind(wx.EVT_BUTTON, self.OnCancel) btnSizer = wx.BoxSizer(wx.HORIZONTAL) btnSizer.Add((20,20),1) btnSizer.Add(OkBtn) btnSizer.Add((20,20),1) btnSizer.Add(cancelBtn) btnSizer.Add((20,20),1) mainSizer.Add(btnSizer,0,wx.EXPAND|wx.BOTTOM|wx.TOP, 10) self.panel.SetSizer(mainSizer) self.panel.Fit() self.Fit() def GetSelection(self): return self.result def OnOk(self,event): parent = self.GetParent() parent.Raise() self.EndModal(wx.ID_OK) def OnCancel(self,event): parent = self.GetParent() parent.Raise() self.EndModal(wx.ID_CANCEL)
################################################################################ ##### Setup routines ################################################################################ def GetFileBackground(G2frame,xye,background,scale=True): bxye = np.zeros(len(xye[1])) mult = 1.0 if 'background PWDR' in background[1]: backfile,mult = background[1]['background PWDR'][:2] if backfile: bId = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,backfile) if bId: bxye = G2frame.GPXtree.GetItemPyData(bId)[1][1] else: print('Error: background PWDR {} not found'.format(backfile)) background[1]['background PWDR'] = ['',1.0,False] if scale: return bxye*mult else: return bxye
[docs]def IsHistogramInAnyPhase(G2frame,histoName): '''Tests a Histogram to see if it is linked to any phases. Returns the name of the first phase where the histogram is used. ''' phases = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Phases') if phases: item, cookie = G2frame.GPXtree.GetFirstChild(phases) while item: data = G2frame.GPXtree.GetItemPyData(item) histoList = data['Histograms'].keys() if histoName in histoList: return G2frame.GPXtree.GetItemText(item) item, cookie = G2frame.GPXtree.GetNextChild(phases, cookie) return False else: return False
[docs]def SetupSampleLabels(histName,dataType,histType): '''Setup a list of labels and number formatting for use in labeling sample parameters. :param str histName: Name of histogram, ("PWDR ...") :param str dataType: ''' parms = [] parms.append(['Scale','Histogram scale factor: ',[10,7]]) if 'C' in histType or 'B' in histType: parms.append(['Gonio. radius','Goniometer radius (mm): ',[10,3]]) if 'PWDR' in histName: if dataType == 'Debye-Scherrer': if 'T' in histType: parms += [['Absorption',u'Sample absorption (\xb5\xb7r/l): ',[10,4]],] else: parms += [['DisplaceX',u'Sample X displ. perp. to beam (\xb5m): ',[10,3]], ['DisplaceY',u'Sample Y displ. || to beam (\xb5m): ',[10,3]], ['Absorption',u'Sample absorption (\xb5\xb7r): ',[10,4]],] elif dataType == 'Bragg-Brentano': parms += [['Shift',u'Sample displacement(\xb5m): ',[10,4]], ['Transparency',u'Sample transparency(1/\xb5eff, cm): ',[10,3]], ['SurfRoughA','Surface roughness A: ',[10,4]], ['SurfRoughB','Surface roughness B: ',[10,4]]] elif 'SASD' in histName: parms.append(['Thick','Sample thickness (mm)',[10,3]]) parms.append(['Trans','Transmission (meas)',[10,3]]) parms.append(['SlitLen',u'Slit length (Q,\xc5'+Pwrm1+')',[10,3]]) parms.append(['Omega','Goniometer omega:',[10,3]]) parms.append(['Chi','Goniometer chi:',[10,3]]) parms.append(['Phi','Goniometer phi:',[10,3]]) parms.append(['Azimuth','Detector azimuth:',[10,3]]) parms.append(['Time','Clock time (s):',[12,3]]) parms.append(['Temperature','Sample temperature (K): ',[10,3]]) parms.append(['Pressure','Sample pressure (MPa): ',[10,3]]) return parms
[docs]def SetDefaultSASDModel(): 'Fills in default items for the SASD Models dictionary' return {'Back':[0.0,False], 'Size':{'MinDiam':50,'MaxDiam':10000,'Nbins':100,'logBins':True,'Method':'MaxEnt', 'Distribution':[],'Shape':['Spheroid',1.0], 'MaxEnt':{'Niter':100,'Precision':0.01,'Sky':-3}, 'IPG':{'Niter':100,'Approach':0.8,'Power':-1},'Reg':{},}, 'Pair':{'Method':'Moore','MaxRadius':100.,'NBins':100,'Errors':'User', 'Percent error':2.5,'Background':[0,False],'Distribution':[], 'Moore':10,'Dist G':100.,'Result':[],}, 'Particle':{'Matrix':{'Name':'vacuum','VolFrac':[0.0,False]},'Levels':[],}, 'Shapes':{'outName':'run','NumAA':100,'Niter':1,'AAscale':1.0,'Symm':1,'bias-z':0.0, 'inflateV':1.0,'AAglue':0.0,'pdbOut':False,'boxStep':4.0}, 'Current':'Size dist.','BackFile':'', }
[docs]def SetDefaultREFDModel(): '''Fills in default items for the REFD Models dictionary which are defined as follows for each layer: * Name: name of substance * Thick: thickness of layer in Angstroms (not present for top & bottom layers) * Rough: upper surface roughness for layer (not present for toplayer) * Penetration: mixing of layer substance into layer above-is this needed? * DenMul: multiplier for layer scattering density (default = 1.0) Top layer defaults to vacuum (or air/any gas); can be substituted for some other substance. Bottom layer default: infinitely thisck Silicon; can be substituted for some other substance. ''' return {'Layers':[{'Name':'vacuum','DenMul':[1.0,False],}, #top layer {'Name':'vacuum','Rough':[0.,False],'Penetration':[0.,False],'DenMul':[1.0,False],}], #bottom layer 'Scale':[1.0,False],'FltBack':[0.0,False],'Zero':'Top','dQ type':'None','Layer Seq':[], #globals 'Minimizer':'LMLS','Resolution':[0.,'Const dq/q'],'Recomb':0.5,'Toler':0.5, #minimizer controls 'DualFitFiles':['',],'DualFltBacks':[[0.0,False],],'DualScales':[[1.0,False],]} #optional stuff for multidat fits?
[docs]def SetDefaultSubstances(): 'Fills in default items for the SASD Substances dictionary' return {'Substances':{'vacuum':{'Elements':{},'Volume':1.0,'Density':0.0,'Scatt density':0.0,'XImag density':0.0}, 'unit scatter':{'Elements':None,'Volume':None,'Density':None,'Scatt density':1.0,'XImag density':1.0}}}
def GetFileList(G2frame,fileType): fileList = [] Id, cookie = G2frame.GPXtree.GetFirstChild(G2frame.root) while Id: name = G2frame.GPXtree.GetItemText(Id) if fileType in name.split()[0]: fileList.append(name) Id, cookie = G2frame.GPXtree.GetNextChild(G2frame.root, cookie) return fileList
[docs]def GetHistsLikeSelected(G2frame): '''Get the histograms that match the current selected one: The histogram prefix and data type (PXC etc.), the number of wavelengths and the instrument geometry (Debye-Scherrer etc.) must all match. The current histogram is not included in the list. :param wx.Frame G2frame: pointer to main GSAS-II data tree ''' histList = [] inst,inst2 = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Instrument Parameters')) hType = inst['Type'][0] if 'Lam1' in inst: hLam = 2 elif 'Lam' in inst: hLam = 1 else: hLam = 0 sample = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId,'Sample Parameters')) # hGeom = sample.get('Type') hstName = G2frame.GPXtree.GetItemText(G2frame.PatternId) hPrefix = hstName.split()[0]+' ' # cycle through tree looking for items that match the above item, cookie = G2frame.GPXtree.GetFirstChild(G2frame.root) while item: name = G2frame.GPXtree.GetItemText(item) if name.startswith(hPrefix) and name != hstName: cGeom,cType,cLam, = '?','?',-1 subitem, subcookie = G2frame.GPXtree.GetFirstChild(item) while subitem: subname = G2frame.GPXtree.GetItemText(subitem) if subname == 'Sample Parameters': sample = G2frame.GPXtree.GetItemPyData(subitem) # cGeom = sample.get('Type') elif subname == 'Instrument Parameters': inst,inst2 = G2frame.GPXtree.GetItemPyData(subitem) cType = inst['Type'][0] if 'Lam1' in inst: cLam = 2 elif 'Lam' in inst: cLam = 1 else: cLam = 0 subitem, subcookie = G2frame.GPXtree.GetNextChild(item, subcookie) if cLam == hLam and cType == hType: # and cGeom == hGeom: if name not in histList: histList.append(name) item, cookie = G2frame.GPXtree.GetNextChild(G2frame.root, cookie) return histList
[docs]def SetCopyNames(histName,dataType,addNames=[]): '''Determine the items in the sample parameters that should be copied, depending on the histogram type and the instrument type. ''' copyNames = ['Scale',] histType = 'HKLF' if 'PWDR' in histName: histType = 'PWDR' if 'Debye' in dataType: copyNames += ['DisplaceX','DisplaceY','Absorption'] else: #Bragg-Brentano copyNames += ['Shift','Transparency','SurfRoughA','SurfRoughB'] elif 'SASD' in histName: histType = 'SASD' copyNames += ['Materials','Thick',] if len(addNames): copyNames += addNames return histType,copyNames
[docs]def CopyPlotCtrls(G2frame): '''Global copy: Copy plot controls from current histogram to others. ''' hst = G2frame.GPXtree.GetItemText(G2frame.PatternId) histList = GetHistsLikeSelected(G2frame) if not histList: G2frame.ErrorDialog('No match','No other histograms match '+hst,G2frame) return sourceData = G2frame.GPXtree.GetItemPyData(G2frame.PatternId) if 'Offset' not in sourceData[0]: #patch for old data sourceData[0].update({'Offset':[0.0,0.0],'delOffset':0.02,'refOffset':-1.0, 'refDelt':0.01,}) G2frame.GPXtree.SetItemPyData(G2frame.PatternId,sourceData) dlg = G2G.G2MultiChoiceDialog(G2frame,'Copy plot controls from\n'+str(hst[5:])+' to...', 'Copy plot controls', histList) results = [] try: if dlg.ShowModal() == wx.ID_OK: results = dlg.GetSelections() finally: dlg.Destroy() copyList = [] for i in results: copyList.append(histList[i]) keys = ['Offset','delOffset','refOffset','refDelt'] source = dict(zip(keys,[sourceData[0][item] for item in keys])) for hist in copyList: Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,hist) data = G2frame.GPXtree.GetItemPyData(Id) data[0].update(source) G2frame.GPXtree.SetItemPyData(Id,data) print ('Copy of plot controls successful')
[docs]def CopySelectedHistItems(G2frame): '''Global copy: Copy items from current histogram to others. ''' hst = G2frame.GPXtree.GetItemText(G2frame.PatternId) histList = GetHistsLikeSelected(G2frame) if not histList: G2frame.ErrorDialog('No match','No other histograms match '+hst,G2frame) return choices = ['Limits','Background','Instrument Parameters','Sample Parameters'] dlg = G2G.G2MultiChoiceDialog(G2frame,'Copy which histogram sections from\n'+str(hst[5:]), 'Select copy sections', choices, filterBox=False) dlg.SetSelections(range(len(choices))) choiceList = [] if dlg.ShowModal() == wx.ID_OK: choiceList = [choices[i] for i in dlg.GetSelections()] if not choiceList: return dlg = G2G.G2MultiChoiceDialog(G2frame,'Copy parameters from\n'+str(hst[5:])+' to...', 'Copy parameters', histList) results = [] try: if dlg.ShowModal() == wx.ID_OK: results = dlg.GetSelections() finally: dlg.Destroy() copyList = [] for i in results: copyList.append(histList[i]) if 'Limits' in choiceList: # Limits data = G2frame.GPXtree.GetItemPyData( G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId,'Limits')) for item in copyList: Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,item) G2frame.GPXtree.SetItemPyData( G2gd.GetGPXtreeItemId(G2frame,Id,'Limits'), copy.deepcopy(data)) if 'Background' in choiceList: # Background data = G2frame.GPXtree.GetItemPyData( G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId,'Background')) for item in copyList: Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,item) G2frame.GPXtree.SetItemPyData( G2gd.GetGPXtreeItemId(G2frame,Id,'Background'), copy.deepcopy(data)) if 'Instrument Parameters' in choiceList: # Instrument Parameters # for now all items in Inst. parms are copied data,data1 = G2frame.GPXtree.GetItemPyData( G2gd.GetGPXtreeItemId( G2frame,G2frame.PatternId,'Instrument Parameters')) for item in copyList: Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,item) G2frame.GPXtree.GetItemPyData( G2gd.GetGPXtreeItemId(G2frame,Id,'Instrument Parameters') )[0].update(copy.deepcopy(data)) G2frame.GPXtree.GetItemPyData( G2gd.GetGPXtreeItemId(G2frame,Id,'Instrument Parameters') )[1].update(copy.deepcopy(data1)) if 'Sample Parameters' in choiceList: # Sample Parameters data = G2frame.GPXtree.GetItemPyData( G2gd.GetGPXtreeItemId( G2frame,G2frame.PatternId,'Sample Parameters')) # selects items to be copied histType,copyNames = SetCopyNames(hst,data['Type'], addNames = ['Omega','Chi','Phi','Gonio. radius','InstrName']) copyDict = {parm:data[parm] for parm in copyNames} for item in copyList: Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,item) G2frame.GPXtree.GetItemPyData( G2gd.GetGPXtreeItemId(G2frame,Id,'Sample Parameters') ).update(copy.deepcopy(copyDict))
def TestMagAtoms(phase,magAtms,SGData,Uvec,Trans,allmom,maxequiv=100,maximal=False): found = False anymom = False phase['Keep'] = False if not magAtms: phase['Keep'] = True return [] invTrans = nl.inv(Trans) atCodes = [] Phase = {'General':{'AtomPtrs':[2,1],'SGData':copy.deepcopy(phase['SGData'])},'Atoms':[]} for matm in magAtms: XYZ = G2spc.GenAtom(matm[3:6],SGData,False,Move=True) xyzs = [xyz[0] for xyz in XYZ] atCodes += len(xyzs)*['1',] xyzs,atCodes = G2lat.ExpandCell(xyzs,atCodes,0,Trans) for ix,x in enumerate(xyzs): xyz = G2lat.TransformXYZ(x-Uvec,invTrans.T,np.zeros(3))%1. Phase['Atoms'].append(matm[:2]+list(xyz)) SytSym,Mul,Nop,dupDir = G2spc.SytSym(xyz,phase['SGData']) CSI = G2spc.GetCSpqinel(phase['SGData']['SpnFlp'],dupDir) if any(CSI[0]): anymom = True if allmom: if not any(CSI[0]): phase['Keep'] = False found = True uAtms = G2lat.GetUnique(Phase,atCodes)[0] natm = len(uAtms) if anymom and natm <= maxequiv and not found: phase['Keep'] = True if maximal and phase['supList'][0]: phase['Keep'] = False return uAtms def TestAtoms(phase,magAtms,SGData,Uvec,Trans,maxequiv=100,maximal=False): phase['Keep'] = True invTrans = nl.inv(Trans) atCodes = [] Phase = {'General':{'AtomPtrs':[2,1],'SGData':copy.deepcopy(phase['SGData'])},'Atoms':[]} for matm in magAtms: XYZ = G2spc.GenAtom(matm[3:6],SGData,False,Move=True) xyzs = [xyz[0] for xyz in XYZ] atCodes += len(xyzs)*['1',] xyzs,atCodes = G2lat.ExpandCell(xyzs,atCodes,0,Trans) for ix,x in enumerate(xyzs): xyz = G2lat.TransformXYZ(x-Uvec,invTrans.T,np.zeros(3))%1. Phase['Atoms'].append(matm[:2]+list(xyz)) uAtms = G2lat.GetUnique(Phase,atCodes)[0] natm = len(uAtms) if natm > maxequiv: #too many allowed atoms found phase['Keep'] = False if maximal and phase['supList'][0]: phase['Keep'] = False return uAtms ################################################################################ ##### Powder Peaks ################################################################################
[docs]def UpdatePeakGrid(G2frame, data): '''respond to selection of PWDR powder peaks data tree item. ''' def OnAutoSearch(event): PatternId = G2frame.PatternId limits = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Limits'))[1] background = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Background')) inst,inst2 = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Instrument Parameters')) Pattern = G2frame.GPXtree.GetItemPyData(PatternId) profile = Pattern[1] bxye = GetFileBackground(G2frame,profile,background) x0 = profile[0] iBeg = np.searchsorted(x0,limits[0]) iFin = np.searchsorted(x0,limits[1]) x = x0[iBeg:iFin] y0 = (profile[1]-bxye)[iBeg:iFin] ysig = 1.0*np.std(y0) offset = [-1,1] ymask = ma.array(y0,mask=(y0<ysig)) for off in offset: ymask = ma.array(ymask,mask=(ymask-np.roll(y0,off)<=0.)) indx = ymask.nonzero() mags = ymask[indx] poss = x[indx] refs = list(zip(poss,mags)) if 'T' in Inst['Type'][0]: refs = G2mth.sortArray(refs,0,reverse=True) #big TOFs first else: #'c' or 'B' refs = G2mth.sortArray(refs,0,reverse=False) #small 2-Thetas first for i,ref1 in enumerate(refs): #reject picks closer than 1 FWHM for ref2 in refs[i+1:]: if abs(ref2[0]-ref1[0]) < 2.*G2pwd.getFWHM(ref1[0],inst): del(refs[i]) if 'T' in Inst['Type'][0]: refs = G2mth.sortArray(refs,1,reverse=False) else: #'C' or 'B' refs = G2mth.sortArray(refs,1,reverse=True) for pos,mag in refs: data['peaks'].append(G2mth.setPeakparms(inst,inst2,pos,mag)) UpdatePeakGrid(G2frame,data) G2plt.PlotPatterns(G2frame,plotType='PWDR') def OnCopyPeaks(event): hst = G2frame.GPXtree.GetItemText(G2frame.PatternId) histList = GetHistsLikeSelected(G2frame) if not histList: G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame) return copyList = [] dlg = G2G.G2MultiChoiceDialog(G2frame,'Copy peak list from\n'+str(hst[5:])+' to...', 'Copy peaks', histList) try: if dlg.ShowModal() == wx.ID_OK: for i in dlg.GetSelections(): copyList.append(histList[i]) finally: dlg.Destroy() for item in copyList: Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,item) G2frame.GPXtree.SetItemPyData( G2gd.GetGPXtreeItemId(G2frame,Id,'Peak List'),copy.deepcopy(data)) def OnLoadPeaks(event): pth = G2G.GetExportPath(G2frame) dlg = wx.FileDialog(G2frame, 'Choose GSAS-II PWDR peaks list file', pth, '', 'PWDR peak list files (*.pkslst)|*.pkslst',wx.FD_OPEN) try: if dlg.ShowModal() == wx.ID_OK: peaks = [] filename = dlg.GetPath() File = open(filename,'r') S = File.readline() while S: if '#' in S: S = File.readline() continue try: peaks.append(eval(S)) except: break S = File.readline() File.close() finally: dlg.Destroy() data = {'peaks':peaks,'sigDict':{}} UpdatePeakGrid(G2frame,data) G2plt.PlotPatterns(G2frame,plotType='PWDR') def OnSavePeaks(event): pth = G2G.GetExportPath(G2frame) dlg = wx.FileDialog(G2frame, 'Choose GSAS-II PWDR peaks list file', pth, '', 'PWDR peak list files (*.pkslst)|*.pkslst',wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) try: if dlg.ShowModal() == wx.ID_OK: filename = dlg.GetPath() # make sure extension is .pkslst filename = os.path.splitext(filename)[0]+'.pkslst' File = open(filename,'w') File.write("#GSAS-II PWDR peaks list file; do not add/delete items!\n") for item in data: if item == 'peaks': for pk in data[item]: File.write(str(pk)+'\n') File.close() print ('PWDR peaks list saved to: '+filename) finally: dlg.Destroy() def OnUnDo(event): DoUnDo() G2frame.dataWindow.UnDo.Enable(False) def DoUnDo(): print ('Undo last refinement') file = open(G2frame.undofile,'rb') PatternId = G2frame.PatternId for item in ['Background','Instrument Parameters','Peak List']: G2frame.GPXtree.SetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, item),cPickle.load(file)) if G2frame.dataWindow.GetName() == item: if item == 'Background': UpdateBackground(G2frame,G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, item))) elif item == 'Instrument Parameters': UpdateInstrumentGrid(G2frame,G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, item))) elif item == 'Peak List': UpdatePeakGrid(G2frame,G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, item))) print (item+' recovered') file.close() def SaveState(): G2frame.undofile = os.path.join(G2frame.dirname,'GSASII.save') file = open(G2frame.undofile,'wb') PatternId = G2frame.PatternId for item in ['Background','Instrument Parameters','Peak List']: cPickle.dump(G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId,item)),file,1) file.close() G2frame.dataWindow.UnDo.Enable(True) def OnLSQPeakFit(event): if reflGrid.IsCellEditControlEnabled(): # complete any grid edits in progress reflGrid.HideCellEditControl() reflGrid.DisableCellEditControl() if not G2frame.GSASprojectfile: #force a save of the gpx file so SaveState can write in the same directory G2frame.OnFileSaveas(event) wx.CallAfter(OnPeakFit,'LSQ') def OnOneCycle(event): if reflGrid.IsCellEditControlEnabled(): # complete any grid edits in progress reflGrid.HideCellEditControl() reflGrid.DisableCellEditControl() wx.CallAfter(OnPeakFit,'LSQ',oneCycle=True) def OnSeqPeakFit(event): histList = G2gd.GetGPXtreeDataNames(G2frame,['PWDR',]) od = {'label_1':'Copy to next','value_1':False,'label_2':'Reverse order','value_2':False} dlg = G2G.G2MultiChoiceDialog(G2frame, 'Sequential peak fits', 'Select dataset to include',histList,extraOpts=od) names = [] if dlg.ShowModal() == wx.ID_OK: for sel in dlg.GetSelections(): names.append(histList[sel]) dlg.Destroy() if not names: return Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Sequential peak fit results') if Id: SeqResult = G2frame.GPXtree.GetItemPyData(Id) else: SeqResult = {} Id = G2frame.GPXtree.AppendItem(parent=G2frame.root,text='Sequential peak fit results') SeqResult = {'SeqPseudoVars':{},'SeqParFitEqList':[]} SeqResult['histNames'] = names dlg = wx.ProgressDialog('Sequential peak fit','Data set name = '+names[0],len(names), style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME|wx.PD_CAN_ABORT) controls = {'deriv type':'analytic','min dM/M':0.001,} print ('Peak Fitting with '+controls['deriv type']+' derivatives:') oneCycle = False FitPgm = 'LSQ' prevVaryList = [] peaks = None varyList = None if od['value_2']: names.reverse() try: for i,name in enumerate(names): print (' Sequential fit for '+name) dlg.Raise() GoOn = dlg.Update(i,newmsg='Data set name = '+name)[0] if not GoOn: dlg.Destroy() break PatternId = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,name) if i and od['value_1']: G2frame.GPXtree.SetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Peak List'),copy.deepcopy(peaks)) prevVaryList = varyList[:] peaks = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Peak List')) background = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Background')) limits = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Limits'))[1] inst,inst2 = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Instrument Parameters')) Pattern = G2frame.GPXtree.GetItemPyData(PatternId) data = Pattern[1] fixback = GetFileBackground(G2frame,data,background,scale=False) peaks['sigDict'],result,sig,Rvals,varyList,parmDict,fullvaryList,badVary = G2pwd.DoPeakFit(FitPgm,peaks['peaks'], background,limits,inst,inst2,data,fixback,prevVaryList,oneCycle,controls) #needs wtFactor after controls? if len(result[0]) != len(fullvaryList): dlg.Destroy() print (' ***** Sequential peak fit stopped at '+name+' *****') break else: G2frame.GPXtree.SetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Peak List'),copy.deepcopy(peaks)) SeqResult[name] = {'variables':result[0],'varyList':varyList,'sig':sig,'Rvals':Rvals, 'covMatrix':np.eye(len(result[0])),'title':name,'parmDict':parmDict, 'fullVary':fullvaryList,'badVary':badVary} print (' ***** Sequential peak fit successful *****') finally: dlg.Destroy() SeqResult['histNames'] = histList G2frame.GPXtree.SetItemPyData(Id,SeqResult) G2frame.G2plotNB.Delete('Sequential refinement') #clear away probably invalid plot G2frame.GPXtree.SelectItem(Id) def OnClearPeaks(event): dlg = wx.MessageDialog(G2frame,'Delete all peaks?','Clear peak list',wx.OK|wx.CANCEL) try: if dlg.ShowModal() == wx.ID_OK: peaks = {'peaks':[],'sigDict':{}} finally: dlg.Destroy() UpdatePeakGrid(G2frame,peaks) G2plt.PlotPatterns(G2frame,plotType='PWDR') def OnPeakFit(FitPgm,oneCycle=False): SaveState() controls = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.root, 'Controls')) if not controls: controls = {'deriv type':'analytic','min dM/M':0.001,} #fill in defaults if needed print ('Peak Fitting with '+controls['deriv type']+' derivatives:') PatternId = G2frame.PatternId peaks = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Peak List')) if not peaks: G2frame.ErrorDialog('No peaks!','Nothing to fit!') return background = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Background')) limits = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Limits'))[1] inst,inst2 = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Instrument Parameters')) Pattern = G2frame.GPXtree.GetItemPyData(PatternId) data = Pattern[1] wtFactor = Pattern[0]['wtFactor'] bxye = GetFileBackground(G2frame,data,background,scale=False) dlg = wx.ProgressDialog('Residual','Peak fit Rwp = ',101.0, style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME|wx.PD_CAN_ABORT) screenSize = wx.ClientDisplayRect() Size = dlg.GetSize() if 50 < Size[0] < 500: # sanity check on size, since this fails w/Win & wx3.0 dlg.SetSize((int(Size[0]*1.2),Size[1])) # increase size a bit along x dlg.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5)) try: results = G2pwd.DoPeakFit(FitPgm,peaks['peaks'],background,limits,inst,inst2,data,bxye,[],oneCycle,controls,wtFactor,dlg) peaks['sigDict'] = results[0] text = 'Peak fit: Rwp=%.2f%% Nobs= %d Nparm= %d Npeaks= %d'%(results[3]['Rwp'],results[1][2]['fjac'].shape[1],len(results[0]),len(peaks['peaks'])) finally: # dlg.Destroy() print ('finished') newpeaks = copy.copy(peaks) G2frame.GPXtree.SetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Peak List'),newpeaks) G2frame.AddToNotebook(text) G2plt.PlotPatterns(G2frame,plotType='PWDR') wx.CallAfter(UpdatePeakGrid,G2frame,newpeaks) def OnResetSigGam(event): PatternId = G2frame.PatternId Inst,Inst2 = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Instrument Parameters')) peaks = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Peak List')) if not peaks['peaks']: G2frame.ErrorDialog('No peaks!','Nothing to do!') return newpeaks = {'peaks':[],'sigDict':{}} for peak in peaks['peaks']: newpeaks['peaks'].append(G2mth.setPeakparms(Inst,Inst2,peak[0],peak[2])) G2frame.GPXtree.SetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Peak List'),newpeaks) UpdatePeakGrid(G2frame,newpeaks) def setBackgroundColors(): for r in range(reflGrid.GetNumberRows()): for c in range(reflGrid.GetNumberCols()): if reflGrid.GetColLabelValue(c) in ['position','intensity','alpha','beta','sigma','gamma']: if float(reflGrid.GetCellValue(r,c)) < 0.: reflGrid.SetCellBackgroundColour(r,c,wx.RED) else: reflGrid.SetCellBackgroundColour(r,c,wx.WHITE) def KeyEditPeakGrid(event): '''Respond to pressing a key to act on selection of a row, column or cell in the Peak List table ''' rowList = reflGrid.GetSelectedRows() colList = reflGrid.GetSelectedCols() selectList = reflGrid.GetSelectedCells() data = G2frame.GPXtree.GetItemPyData(G2frame.PickId) if event.GetKeyCode() == wx.WXK_RETURN: event.Skip(True) elif event.GetKeyCode() == wx.WXK_CONTROL: event.Skip(True) elif event.GetKeyCode() == wx.WXK_SHIFT: event.Skip(True) elif rowList and (event.GetKeyCode() == wx.WXK_DELETE or event.GetKeyCode() == 8): # pressing the delete key or backspace deletes selected peak(s) reflGrid.ClearSelection() reflGrid.ClearGrid() rowList.sort() rowList.reverse() nDel = 0 for row in rowList: G2frame.PeakTable.DeleteRow(row) nDel += 1 if nDel: msg = wg.GridTableMessage(G2frame.PeakTable, wg.GRIDTABLE_NOTIFY_ROWS_DELETED,0,nDel) reflGrid.ProcessTableMessage(msg) data['peaks'] = G2frame.PeakTable.GetData()[:-nDel] G2frame.GPXtree.SetItemPyData(G2frame.PickId,data) setBackgroundColors() elif colList and (event.GetKeyCode() == 89 or event.GetKeyCode() == 78): reflGrid.ClearSelection() key = event.GetKeyCode() for col in colList: if G2frame.PeakTable.GetTypeName(0,col) == wg.GRID_VALUE_BOOL: if key == 89: #'Y' for row in range(G2frame.PeakTable.GetNumberRows()): data['peaks'][row][col]=True elif key == 78: #'N' for row in range(G2frame.PeakTable.GetNumberRows()): data['peaks'][row][col]=False elif selectList and (event.GetKeyCode() == 89 or event.GetKeyCode() == 78): reflGrid.ClearSelection() key = event.GetKeyCode() for row,col in selectList: if G2frame.PeakTable.GetTypeName(row,col) == wg.GRID_VALUE_BOOL: if key == 89: #'Y' data['peaks'][row][col]=True elif key == 78: #'N' data['peaks'][row][col]=False else: event.Skip() return G2plt.PlotPatterns(G2frame,plotType='PWDR') wx.CallAfter(UpdatePeakGrid,G2frame,data) def SelectVars(rows): '''Set or clear peak refinement variables for peaks listed in rows ''' refOpts = {reflGrid.GetColLabelValue(i):i+1 for i in range(reflGrid.GetNumberCols()) if reflGrid.GetColLabelValue(i) != "refine"} dlg = G2G.G2MultiChoiceDialog(G2frame,'Select columns to refine', 'Refinement Selection', sorted(refOpts.keys()), filterBox=False,toggle=False) sels = [] try: if dlg.ShowModal() == wx.ID_OK: sels = [sorted(refOpts.keys())[i] for i in dlg.GetSelections()] else: return finally: dlg.Destroy() for r in rows: for lbl,c in refOpts.items(): data['peaks'][r][c] = lbl in sels UpdatePeakGrid(G2frame,data) def OnRefineSelected(event): '''set refinement flags for the selected peaks ''' rows = list(set([row for row,col in reflGrid.GetSelectedCells()] + reflGrid.GetSelectedRows())) if not rows: wx.MessageBox('No selected rows. You must select rows or cells before using this command', caption='No selected peaks') return SelectVars(rows) def OnRefineAll(event): '''set refinement flags for all peaks ''' SelectVars(range(reflGrid.GetNumberRows())) # def onCellListSClick(event): # '''Called when a peak is selected so that it can be highlighted in the plot # ''' # event.Skip() # c = event.GetRow(),event.GetCol() # if c < 0: # replot except whan a column is selected # wx.CallAfter(G2plt.PlotPatterns,G2frame,plotType='PWDR') # def onCellListDClick(event): '''Called after a double-click on a cell label''' r,c = event.GetRow(),event.GetCol() if r < 0 and c < 0: for row in range(reflGrid.GetNumberRows()): reflGrid.SelectRow(row,True) for col in range(reflGrid.GetNumberCols()): reflGrid.SelectCol(col,True) elif r > 0: #row label: select it and replot! reflGrid.ClearSelection() reflGrid.SelectRow(r,True) wx.CallAfter(G2frame.reflGrid.ForceRefresh) wx.CallAfter(G2plt.PlotPatterns,G2frame,plotType='PWDR') elif c > 0: #column label: just select it (& redisplay) reflGrid.ClearSelection() reflGrid.SelectCol(c,True) if reflGrid.GetColLabelValue(c) != 'refine': return choice = ['Y - vary all','N - vary none',] dlg = wx.SingleChoiceDialog(G2frame,'Select refinement option for '+reflGrid.GetColLabelValue(c-1), 'Refinement controls',choice) dlg.CenterOnParent() if dlg.ShowModal() == wx.ID_OK: sel = dlg.GetSelection() if sel == 0: for row in range(reflGrid.GetNumberRows()): data['peaks'][row][c]=True else: for row in range(reflGrid.GetNumberRows()): data['peaks'][row][c]=False wx.CallAfter(UpdatePeakGrid,G2frame,data) #====================================================================== # beginning of UpdatePeakGrid init #====================================================================== G2frame.GetStatusBar().SetStatusText('Global refine: select refine column & press Y or N',1) G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.PeakMenu) G2frame.Bind(wx.EVT_MENU, OnAutoSearch, id=G2G.wxID_AUTOSEARCH) G2frame.Bind(wx.EVT_MENU, OnCopyPeaks, id=G2G.wxID_PEAKSCOPY) G2frame.Bind(wx.EVT_MENU, OnSavePeaks, id=G2G.wxID_PEAKSAVE) G2frame.Bind(wx.EVT_MENU, OnLoadPeaks, id=G2G.wxID_PEAKLOAD) G2frame.Bind(wx.EVT_MENU, OnUnDo, id=G2G.wxID_UNDO) G2frame.Bind(wx.EVT_MENU, OnRefineSelected, id=G2frame.dataWindow.peaksSel.GetId()) G2frame.Bind(wx.EVT_MENU, OnRefineAll, id=G2frame.dataWindow.peaksAll.GetId()) G2frame.Bind(wx.EVT_MENU, OnLSQPeakFit, id=G2G.wxID_LSQPEAKFIT) G2frame.Bind(wx.EVT_MENU, OnOneCycle, id=G2G.wxID_LSQONECYCLE) G2frame.Bind(wx.EVT_MENU, OnSeqPeakFit, id=G2G.wxID_SEQPEAKFIT) G2frame.Bind(wx.EVT_MENU, OnClearPeaks, id=G2G.wxID_CLEARPEAKS) G2frame.Bind(wx.EVT_MENU, OnResetSigGam, id=G2G.wxID_RESETSIGGAM) if data['peaks']: G2frame.dataWindow.AutoSearch.Enable(False) G2frame.dataWindow.PeakCopy.Enable(True) G2frame.dataWindow.PeakFit.Enable(True) G2frame.dataWindow.PFOneCycle.Enable(True) G2frame.dataWindow.SeqPeakFit.Enable(True) else: G2frame.dataWindow.PeakFit.Enable(False) G2frame.dataWindow.PeakCopy.Enable(False) G2frame.dataWindow.PFOneCycle.Enable(False) G2frame.dataWindow.AutoSearch.Enable(True) G2frame.dataWindow.SeqPeakFit.Enable(False) G2frame.PickTable = [] rowLabels = [] PatternId = G2frame.PatternId Inst = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Instrument Parameters'))[0] for i in range(len(data['peaks'])): rowLabels.append(str(i+1)) if 'C' in Inst['Type'][0]: colLabels = ['position','refine','intensity','refine','sigma','refine','gamma','refine'] Types = [wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_BOOL, wg.GRID_VALUE_FLOAT+':10,1',wg.GRID_VALUE_BOOL, wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL, wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL] else: colLabels = ['position','refine','intensity','refine','alpha','refine', 'beta','refine','sigma','refine','gamma','refine'] if 'T' in Inst['Type'][0]: Types = [wg.GRID_VALUE_FLOAT+':10,1',wg.GRID_VALUE_BOOL, wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_BOOL, wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_BOOL, wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL, wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL, wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL] else: #'B' Types = [wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_BOOL, wg.GRID_VALUE_FLOAT+':10,1',wg.GRID_VALUE_BOOL, wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL, wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL, wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL, wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL] T = [] for peak in data['peaks']: T.append(peak[0]) D = dict(zip(T,data['peaks'])) T.sort() if 'T' in Inst['Type'][0]: #want big TOF's first T.reverse() X = [] for key in T: X.append(D[key]) data['peaks'] = X G2frame.dataWindow.ClearData() mainSizer = wx.BoxSizer(wx.VERTICAL) G2frame.GPXtree.SetItemPyData(G2frame.PickId,data) G2frame.PeakTable = G2G.Table(data['peaks'],rowLabels=rowLabels,colLabels=colLabels,types=Types) #G2frame.SetLabel(G2frame.GetLabel().split('||')[0]+' || '+'Peak List') G2frame.dataWindow.currentGrids = [] reflGrid = G2G.GSGrid(parent=G2frame.dataWindow) reflGrid.SetTable(G2frame.PeakTable, True) setBackgroundColors() # reflGrid.Bind(wg.EVT_GRID_CELL_CHANGE, RefreshPeakGrid) reflGrid.Bind(wx.EVT_KEY_DOWN, KeyEditPeakGrid) # reflGrid.Bind(wg.EVT_GRID_LABEL_LEFT_CLICK, onCellListSClick) # G2frame.dataWindow.Bind(wg.EVT_GRID_CELL_LEFT_CLICK, onCellListSClick) reflGrid.Bind(wg.EVT_GRID_LABEL_LEFT_DCLICK, onCellListDClick) # G2frame.dataWindow.Bind(wg.EVT_GRID_CELL_LEFT_DCLICK, onCellListDClick) reflGrid.AutoSizeColumns(False) reflGrid.SetScrollRate(10,10) G2frame.reflGrid = reflGrid # mainSizer.Add(reflGrid,1,wx.ALL|wx.EXPAND,1) mainSizer.Add(reflGrid) mainSizer.Add(G2G.HelpButton(G2frame.dataWindow,helpIndex=G2frame.dataWindow.helpKey)) G2frame.dataWindow.SetSizer(mainSizer) G2frame.dataWindow.SetDataSize()
################################################################################ ##### Background ################################################################################
[docs]def UpdateBackground(G2frame,data): '''respond to selection of PWDR background data tree item. ''' def OnBackFlagCopy(event): flag = data[0][1] backDict = data[-1] if backDict['nDebye']: DBflags = [] for term in backDict['debyeTerms']: DBflags.append(term[1::2]) if backDict['nPeaks']: PKflags = [] for term in backDict['peaksList']: PKflags.append(term[1::2]) FBflag = bool(backDict['background PWDR'][2]) hst = G2frame.GPXtree.GetItemText(G2frame.PatternId) histList = GetHistsLikeSelected(G2frame) if not histList: G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame) return dlg = G2G.G2MultiChoiceDialog(G2frame,'Copy bkg ref. flags from\n'+str(hst[5:])+' to...', 'Copy bkg flags', histList) copyList = [] try: if dlg.ShowModal() == wx.ID_OK: for i in dlg.GetSelections(): copyList.append(histList[i]) finally: dlg.Destroy() for item in copyList: Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,item) backData = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,Id,'Background')) backData[0][1] = copy.copy(flag) bkDict = backData[-1] if bkDict['nDebye'] == backDict['nDebye']: for i,term in enumerate(bkDict['debyeTerms']): term[1::2] = copy.copy(DBflags[i]) if bkDict['nPeaks'] == backDict['nPeaks']: for i,term in enumerate(bkDict['peaksList']): term[1::2] = copy.copy(PKflags[i]) try: backData[1]['background PWDR'][2] = FBflag except: backData[1]['background PWDR'] = ['',-1.,False] def OnBackCopy(event): hst = G2frame.GPXtree.GetItemText(G2frame.PatternId) histList = GetHistsLikeSelected(G2frame) if not histList: G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame) return copyList = [] dlg = G2G.G2MultiChoiceDialog(G2frame,'Copy bkg params from\n'+str(hst[5:])+' to...', 'Copy parameters', histList) try: if dlg.ShowModal() == wx.ID_OK: for i in dlg.GetSelections(): copyList.append(histList[i]) finally: dlg.Destroy() for item in copyList: Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,item) G2frame.GPXtree.SetItemPyData( G2gd.GetGPXtreeItemId(G2frame,Id,'Background'),copy.deepcopy(data)) CalcBack(Id) def OnBackSave(event): pth = G2G.GetExportPath(G2frame) dlg = wx.FileDialog(G2frame, 'Set name to save GSAS-II background parameters file', pth, '', 'background parameter files (*.pwdrbck)|*.pwdrbck',wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) try: if dlg.ShowModal() == wx.ID_OK: filename = dlg.GetPath() # make sure extension is .pwdrbck filename = os.path.splitext(filename)[0]+'.pwdrbck' File = open(filename,'w') File.write("#GSAS-II background parameter file; do not add/delete items!\n") File.write(str(data[0])+'\n') for item in data[1]: if item in ['nPeaks','background PWDR','nDebye'] or not len(data[1][item]): File.write(item+':'+str(data[1][item])+'\n') else: File.write(item+':\n') for term in data[1][item]: File.write(str(term)+'\n') File.close() print ('Background parameters saved to: '+filename) finally: dlg.Destroy() def OnBackLoad(event): pth = G2G.GetImportPath(G2frame) if not pth: pth = '.' dlg = wx.FileDialog(G2frame, 'Choose GSAS-II background parameters file', pth, '', 'background parameter files (*.pwdrbck)|*.pwdrbck',wx.FD_OPEN) try: if dlg.ShowModal() == wx.ID_OK: newback = [[],{}] filename = dlg.GetPath() File = open(filename,'r') S = File.readline() if S[0] == '#': #skip the heading S = File.readline() #should contain the std. bck fxn newback[0] = eval(S.strip()) S = File.readline() while S and ':' in S: item,vals = S.strip().split(':') if item in ['nPeaks','nDebye']: newback[1][item] = int(vals) elif 'PWDR' in item: newback[1][item] = eval(vals) elif item in ['FixedPoints','debyeTerms','peaksList']: newback[1][item] = [] S = File.readline() while S and ':' not in S: newback[1][item].append(eval(S.strip())) S = File.readline() else: continue S = File.readline() File.close() G2frame.GPXtree.SetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId,'Background'),newback) finally: dlg.Destroy() CalcBack(G2frame.PatternId) G2plt.PlotPatterns(G2frame,plotType='PWDR') wx.CallLater(100,UpdateBackground,G2frame,newback) def OnBkgFit(event): def SetInstParms(Inst): dataType = Inst['Type'][0] insVary = [] insNames = [] insVals = [] for parm in Inst: insNames.append(parm) insVals.append(Inst[parm][1]) if parm in ['U','V','W','X','Y','Z','SH/L','I(L2)/I(L1)','alpha', 'beta-0','beta-1','beta-q','sig-0','sig-1','sig-2','sig-q',] and Inst[parm][2]: Inst[parm][2] = False # insVary.append(parm) instDict = dict(zip(insNames,insVals)) instDict['X'] = max(instDict['X'],0.01) instDict['Y'] = max(instDict['Y'],0.01) if 'SH/L' in instDict: instDict['SH/L'] = max(instDict['SH/L'],0.002) return dataType,instDict,insVary PatternId = G2frame.PatternId controls = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.root, 'Controls')) background = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Background')) limits = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Limits'))[1] inst,inst2 = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Instrument Parameters')) # sort the points for convenience and then separate them; extend the range if needed if 'FixedPoints' not in background[1]: msg = ("You have not defined any fixed background points. "+ "Use the Fixed Points/Add menu item to define points that will be fit."+ '\n\nSee the "Fitting the Starting Background using Fixed Points" tutorial for more details.') print (msg) G2frame.ErrorDialog('No points',msg) return background[1]['FixedPoints'] = sorted(background[1]['FixedPoints'],key=lambda pair:pair[0]) X = [x for x,y in background[1]['FixedPoints']] Y = [y for x,y in background[1]['FixedPoints']] if X[0] > limits[0]: X = [limits[0]] + X Y = [Y[0]] + Y if X[-1] < limits[1]: X += [limits[1]] Y += [Y[-1]] # interpolate the fixed points onto the grid of data points within limits pwddata = G2frame.GPXtree.GetItemPyData(PatternId)[1] xBeg = np.searchsorted(pwddata[0],limits[0]) xFin = np.searchsorted(pwddata[0],limits[1]) xdata = pwddata[0][xBeg:xFin] ydata = si.interp1d(X,Y)(ma.getdata(xdata)) W = [1]*len(xdata) Z = [0]*len(xdata) bxye = GetFileBackground(G2frame,data,background,scale=False)[xBeg:xFin] if not np.any(bxye): bxye = None # load instrument and background params print (' NB: Any instrument parameter refinement flags will be cleared') dataType,insDict,insVary = SetInstParms(inst) bakType,bakDict,bakVary = G2pwd.SetBackgroundParms(background) # how many background parameters are refined? if len(bakVary)*1.5 > len(X): msg = ("You are attempting to vary "+str(len(bakVary))+ " background terms with only "+str(len(X))+" background points"+ "\nAdd more points or reduce the number of terms") print (msg) G2frame.ErrorDialog('Too few points',msg) return wx.BeginBusyCursor() try: G2pwd.DoPeakFit('LSQ',[],background,limits,inst,inst2, np.array((xdata,ydata,W,Z,Z,Z)),bxye,prevVaryList=bakVary,controls=controls) finally: wx.EndBusyCursor() # compute the background values and plot them parmDict = {} bakType,bakDict,bakVary = G2pwd.SetBackgroundParms(background) parmDict.update(bakDict) parmDict.update(insDict) # Note that this generates a MaskedArrayFutureWarning, but these items are not always masked pwddata[3][xBeg:xFin] *= 0. pwddata[5][xBeg:xFin] *= 0. pwddata[4][xBeg:xFin] = G2pwd.getBackground('',parmDict,bakType,dataType,xdata,bxye)[0] G2plt.PlotPatterns(G2frame,plotType='PWDR') # show the updated background values wx.CallLater(100,UpdateBackground,G2frame,data) def OnBkgClear(event): if 'FixedPoints' not in data[1]: return else: data[1]['FixedPoints'] = [] G2plt.PlotPatterns(G2frame,plotType='PWDR') def OnPeaksMove(event): if not data[1]['nPeaks']: G2frame.ErrorDialog('Error','No peaks to move') return Peaks = {'peaks':[],'sigDict':{}} for peak in data[1]['peaksList']: Peaks['peaks'].append([peak[0],0,peak[2],0,peak[4],0,peak[6],0]) G2frame.GPXtree.SetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Peak List'),Peaks) def OnMakeRDF(event): dlg = RDFDialog(G2frame) try: if dlg.ShowModal() == wx.ID_OK: RDFcontrols = dlg.GetSelection() else: return finally: dlg.Destroy() PatternId = G2frame.PatternId background = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Background')) inst,inst2 = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Instrument Parameters')) pwddata = G2frame.GPXtree.GetItemPyData(PatternId)[1] auxPlot = G2pwd.MakeRDF(RDFcontrols,background,inst,pwddata) for plot in auxPlot: XY = np.array(plot[:2]) if 'D(R)' in plot[2]: xlabel = r'$R, \AA$' ylabel = r'$D(R), arb. units$' else: xlabel = r'$Q,\AA$'+superMinusOne ylabel = r'$I(Q)$' G2plt.PlotXY(G2frame,[XY,],Title=plot[2],labelX=xlabel,labelY=ylabel,lines=True) def BackSizer(): def OnNewType(event): data[0][0] = bakType.GetValue() def OnBakRef(event): data[0][1] = bakRef.GetValue() def OnBakTerms(event): data[0][2] = int(bakTerms.GetValue()) M = len(data[0]) N = data[0][2]+3 item = data[0] if N > M: #add terms for i in range(M,N): item.append(0.0) elif N < M: #delete terms for i in range(N,M): del(item[-1]) G2frame.GPXtree.SetItemPyData(BackId,data) wx.CallLater(100,UpdateBackground,G2frame,data) def AfterChange(invalid,value,tc): if invalid: return CalcBack(G2frame.PatternId) G2plt.PlotPatterns(G2frame,plotType='PWDR') backSizer = wx.BoxSizer(wx.VERTICAL) topSizer = wx.BoxSizer(wx.HORIZONTAL) topSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Background function: '),0,WACV) bakType = wx.ComboBox(G2frame.dataWindow,value=data[0][0], choices=Choices,style=wx.CB_READONLY|wx.CB_DROPDOWN) bakType.Bind(wx.EVT_COMBOBOX, OnNewType) topSizer.Add(bakType) topSizer.Add((5,0),0) bakRef = wx.CheckBox(G2frame.dataWindow,label=' Refine?') bakRef.SetValue(bool(data[0][1])) bakRef.Bind(wx.EVT_CHECKBOX, OnBakRef) topSizer.Add(bakRef,0,WACV) backSizer.Add(topSizer) topSizer = wx.BoxSizer(wx.HORIZONTAL) topSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Number of coeff.: '),0,WACV) bakTerms = wx.ComboBox(G2frame.dataWindow,-1,value=str(data[0][2]),choices=[str(i+1) for i in range(36)], style=wx.CB_READONLY|wx.CB_DROPDOWN) bakTerms.Bind(wx.EVT_COMBOBOX,OnBakTerms) topSizer.Add(bakTerms,0,WACV) topSizer.Add((5,0),0) backSizer.Add(topSizer) backSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Background coefficients:'),0) bakSizer = wx.FlexGridSizer(0,5,5,5) for i,value in enumerate(data[0][3:]): bakVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,data[0],i+3,nDig=(10,4),OnLeave=AfterChange) bakSizer.Add(bakVal,0,WACV) backSizer.Add(bakSizer) return backSizer def DebyeSizer(): def OnDebTerms(event): data[1]['nDebye'] = int(debTerms.GetValue()) M = len(data[1]['debyeTerms']) N = data[1]['nDebye'] if N > M: #add terms for i in range(M,N): data[1]['debyeTerms'].append([1.0,False,1.0,False,0.010,False]) elif N < M: #delete terms for i in range(N,M): del(data[1]['debyeTerms'][-1]) if N == 0: CalcBack(G2frame.PatternId) G2plt.PlotPatterns(G2frame,plotType='PWDR') wx.CallAfter(UpdateBackground,G2frame,data) def KeyEditPeakGrid(event): colList = debyeGrid.GetSelectedCols() if event.GetKeyCode() == wx.WXK_RETURN: event.Skip(True) elif event.GetKeyCode() == wx.WXK_CONTROL: event.Skip(True) elif event.GetKeyCode() == wx.WXK_SHIFT: event.Skip(True) elif colList: debyeGrid.ClearSelection() key = event.GetKeyCode() for col in colList: if debyeTable.GetTypeName(0,col) == wg.GRID_VALUE_BOOL: if key == 89: #'Y' for row in range(debyeGrid.GetNumberRows()): data[1]['debyeTerms'][row][col]=True elif key == 78: #'N' for row in range(debyeGrid.GetNumberRows()): data[1]['debyeTerms'][row][col]=False def OnCellChange(event): CalcBack(G2frame.PatternId) G2plt.PlotPatterns(G2frame,plotType='PWDR') debSizer = wx.BoxSizer(wx.VERTICAL) topSizer = wx.BoxSizer(wx.HORIZONTAL) topSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Debye scattering: '),0,WACV) topSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Number of terms: '),0,WACV) debTerms = wx.ComboBox(G2frame.dataWindow,-1,value=str(data[1]['nDebye']),choices=[str(i) for i in range(21)], style=wx.CB_READONLY|wx.CB_DROPDOWN) debTerms.Bind(wx.EVT_COMBOBOX,OnDebTerms) topSizer.Add(debTerms,0,WACV) topSizer.Add((5,0),0) debSizer.Add(topSizer) if data[1]['nDebye']: debSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Debye diffuse terms:'),0) rowLabels = [] for i in range(len(data[1]['debyeTerms'])): rowLabels.append(str(i)) colLabels = ['A','refine','R','refine','U','refine'] Types = [wg.GRID_VALUE_FLOAT+':10,2',wg.GRID_VALUE_BOOL, wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_BOOL, wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL] debyeTable = G2G.Table(data[1]['debyeTerms'],rowLabels=rowLabels,colLabels=colLabels,types=Types) debyeGrid = G2G.GSGrid(parent=G2frame.dataWindow) debyeGrid.SetTable(debyeTable, True) debyeGrid.Bind(wx.EVT_KEY_DOWN, KeyEditPeakGrid) debyeGrid.Bind(wg.EVT_GRID_CELL_CHANGED,OnCellChange) debyeGrid.AutoSizeColumns(False) debSizer.Add(debyeGrid) return debSizer def PeaksSizer(): def OnPeaks(event): 'Respond to a change in the number of background peaks' data[1]['nPeaks'] = int(peaks.GetValue()) M = len(data[1]['peaksList']) N = data[1]['nPeaks'] if N > M: #add terms for i in range(M,N): data[1]['peaksList'].append([1.0,False,1.0,False,0.10,False,0.10,False]) elif N < M: #delete terms for i in range(N,M): del(data[1]['peaksList'][-1]) if N == 0: CalcBack(G2frame.PatternId) G2plt.PlotPatterns(G2frame,plotType='PWDR') # this callback is crashing wx when there is an open # peaksGrid cell editor, at least on Mac. Code below # should fix this, but it does not. # https://stackoverflow.com/questions/64082199/wxpython-grid-destroy-with-open-celleditor-crashes-python-even-with-disablece if peaksGrid and peaksGrid.IsCellEditControlEnabled(): # complete any grid edits in progress #print('closing') peaksGrid.HideCellEditControl() peaksGrid.DisableCellEditControl() #wx.CallLater(100,peaksGrid.Destroy) # crashes python wx.CallAfter(UpdateBackground,G2frame,data) def KeyEditPeakGrid(event): colList = peaksGrid.GetSelectedCols() if event.GetKeyCode() == wx.WXK_RETURN: event.Skip(True) elif event.GetKeyCode() == wx.WXK_CONTROL: event.Skip(True) elif event.GetKeyCode() == wx.WXK_SHIFT: event.Skip(True) elif colList: peaksGrid.ClearSelection() key = event.GetKeyCode() for col in colList: if peaksTable.GetTypeName(0,col) == wg.GRID_VALUE_BOOL: if key == 89: #'Y' for row in range(peaksGrid.GetNumberRows()): data[1]['peaksList'][row][col]=True elif key == 78: #'N' for row in range(peaksGrid.GetNumberRows()): data[1]['peaksList'][row][col]=False def OnCellChange(event): CalcBack(G2frame.PatternId) G2plt.PlotPatterns(G2frame,plotType='PWDR') peaksSizer = wx.BoxSizer(wx.VERTICAL) topSizer = wx.BoxSizer(wx.HORIZONTAL) topSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Peaks in background: '),0,WACV) topSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Number of peaks: '),0,WACV) peaks = wx.ComboBox(G2frame.dataWindow,-1,value=str(data[1]['nPeaks']),choices=[str(i) for i in range(30)], style=wx.CB_READONLY|wx.CB_DROPDOWN) peaks.Bind(wx.EVT_COMBOBOX,OnPeaks) topSizer.Add(peaks,0,WACV) topSizer.Add((5,0),0) peaksSizer.Add(topSizer) G2frame.dataWindow.currentGrids = [] peaksGrid = None if data[1]['nPeaks']: peaksSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Peak list:'),0) rowLabels = [] for i in range(len(data[1]['peaksList'])): rowLabels.append(str(i)) colLabels = ['pos','refine','int','refine','sig','refine','gam','refine'] Types = [wg.GRID_VALUE_FLOAT+':10,2',wg.GRID_VALUE_BOOL, wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_BOOL, wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_BOOL, wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL] peaksTable = G2G.Table(data[1]['peaksList'],rowLabels=rowLabels,colLabels=colLabels,types=Types) peaksGrid = G2G.GSGrid(parent=G2frame.dataWindow) peaksGrid.SetTable(peaksTable, True) peaksGrid.Bind(wx.EVT_KEY_DOWN, KeyEditPeakGrid) peaksGrid.Bind(wg.EVT_GRID_CELL_CHANGED,OnCellChange) peaksGrid.AutoSizeColumns(False) peaksSizer.Add(peaksGrid) return peaksSizer def BackFileSizer(): def OnBackPWDR(event): data[1]['background PWDR'][0] = back.GetValue() if len(data[1]['background PWDR'][0]): curHist = G2frame.GPXtree.GetItemPyData(G2frame.PatternId) Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,data[1]['background PWDR'][0]) if not Id: G2G.G2MessageBox(G2frame,'Histogram not found -- how did this happen?','Missing histogram') back.SetValue('') data[1]['background PWDR'][0] = back.GetValue() return bkgHist = G2frame.GPXtree.GetItemPyData(Id) if len(bkgHist[1][0]) != len(curHist[1][0]): G2G.G2MessageBox(G2frame,'Histogram have different lengths','Mismatched histograms') back.SetValue('') data[1]['background PWDR'][0] = back.GetValue() return else: data[1]['background PWDR'][2] = False CalcBack() G2plt.PlotPatterns(G2frame,plotType='PWDR') wx.CallLater(100,UpdateBackground,G2frame,data) def AfterChange(invalid,value,tc): if invalid: return CalcBack() G2plt.PlotPatterns(G2frame,plotType='PWDR') def OnBackFit(event): data[1]['background PWDR'][2] = not data[1]['background PWDR'][2] fileSizer = wx.BoxSizer(wx.VERTICAL) fileSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Fixed background histogram (for point-by-point subraction):'),0) if 'background PWDR' not in data[1]: data[1]['background PWDR'] = ['',-1.,False] backSizer = wx.BoxSizer(wx.HORIZONTAL) Choices = ['',]+G2gd.GetGPXtreeDataNames(G2frame,['PWDR',]) Source = G2frame.GPXtree.GetItemText(G2frame.PatternId) Choices.pop(Choices.index(Source)) back = wx.ComboBox(parent=G2frame.dataWindow,value=data[1]['background PWDR'][0],choices=Choices, style=wx.CB_READONLY|wx.CB_DROPDOWN) back.Bind(wx.EVT_COMBOBOX,OnBackPWDR) backSizer.Add(back) backSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' multiplier'),0,WACV) backMult = G2G.ValidatedTxtCtrl(G2frame.dataWindow,data[1]['background PWDR'],1,nDig=(10,3),OnLeave=AfterChange) backSizer.Add(backMult,0,WACV) if len(data[1]['background PWDR'][0]): backFit = wx.CheckBox(G2frame.dataWindow,label=' Refine?') backFit.SetValue(data[1]['background PWDR'][2]) backFit.Bind(wx.EVT_CHECKBOX, OnBackFit) backSizer.Add(backFit,0,WACV) fileSizer.Add(backSizer) return fileSizer def CalcBack(PatternId=G2frame.PatternId): limits = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Limits'))[1] inst,inst2 = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Instrument Parameters')) backData = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Background')) dataType = inst['Type'][0] insDict = {inskey:inst[inskey][1] for inskey in inst} parmDict = {} bakType,bakDict,bakVary = G2pwd.SetBackgroundParms(data) parmDict.update(bakDict) parmDict.update(insDict) pwddata = G2frame.GPXtree.GetItemPyData(PatternId) xBeg = np.searchsorted(pwddata[1][0],limits[0]) xFin = np.searchsorted(pwddata[1][0],limits[1]) fixBack = GetFileBackground(G2frame,pwddata[1],backData,scale=False) pwddata[1][4][xBeg:xFin] = G2pwd.getBackground('',parmDict,bakType,dataType,pwddata[1][0][xBeg:xFin],fixBack[xBeg:xFin])[0] # UpdateBackground execution starts here if len(data) < 2: #add Debye diffuse & peaks scattering here data.append({'nDebye':0,'debyeTerms':[],'nPeaks':0,'peaksList':[],'background PWDR':['',1.0,False]}) if 'nPeaks' not in data[1]: data[1].update({'nPeaks':0,'peaksList':[],'background PWDR':['',1.0,False]}) if 'background PWDR' not in data[1]: data[1].update({'background PWDR':['',1.0,False]}) elif len(data[1]['background PWDR']) < 3: data[1]['background PWDR'].append(False) G2frame.dataWindow.currentGrids = [] G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.BackMenu) G2frame.Bind(wx.EVT_MENU,OnBackCopy,id=G2G.wxID_BACKCOPY) G2frame.Bind(wx.EVT_MENU,OnBackFlagCopy,id=G2G.wxID_BACKFLAGCOPY) G2frame.Bind(wx.EVT_MENU,OnBackSave,id=G2G.wxID_BACKSAVE) G2frame.Bind(wx.EVT_MENU,OnBackLoad,id=G2G.wxID_BACKLOAD) G2frame.Bind(wx.EVT_MENU,OnPeaksMove,id=G2G.wxID_BACKPEAKSMOVE) G2frame.Bind(wx.EVT_MENU,OnMakeRDF,id=G2G.wxID_MAKEBACKRDF) G2frame.Bind(wx.EVT_MENU,OnBkgFit,id=G2frame.dataWindow.wxID_BackPts['Fit']) G2frame.Bind(wx.EVT_MENU,OnBkgClear,id=G2frame.dataWindow.wxID_BackPts['Clear']) BackId = G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Background') Choices = ['chebyschev','chebyschev-1','cosine','Q^2 power series','Q^-2 power series','lin interpolate','inv interpolate','log interpolate'] G2frame.dataWindow.ClearData() mainSizer = wx.BoxSizer(wx.VERTICAL) topSizer = wx.BoxSizer(wx.HORIZONTAL) topSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Background used in refinement'),0,WACV) # add help button to bring up help web page - at right side of window topSizer.Add((-1,-1),1,wx.EXPAND) topSizer.Add(G2G.HelpButton(G2frame.dataWindow,helpIndex=G2frame.dataWindow.helpKey)) mainSizer.Add(topSizer,0,wx.EXPAND) mainSizer.Add(BackSizer()) mainSizer.Add((0,5),0) mainSizer.Add(DebyeSizer()) mainSizer.Add((0,5),0) mainSizer.Add(PeaksSizer()) mainSizer.Add((0,5),0) mainSizer.Add(BackFileSizer()) G2frame.dataWindow.SetSizer(mainSizer) G2frame.dataWindow.SetDataSize()
################################################################################ ##### Limits ################################################################################
[docs]def UpdateLimitsGrid(G2frame, data,plottype): '''respond to selection of PWDR Limits data tree item. ''' def AfterChange(invalid,value,tc): if invalid: return plottype = G2frame.GPXtree.GetItemText(G2frame.PatternId)[:4] wx.CallAfter(G2plt.PlotPatterns,G2frame,newPlot=False,plotType=plottype) #unfortunately this resets the plot width def LimitSizer(): limits = wx.FlexGridSizer(0,3,0,5) labels = ['Tmin','Tmax'] for i in [0,1]: limits.Add(wx.StaticText(G2frame.dataWindow, label=' Original {} {:.4f}'.format(labels[i],data[0][i])),0,WACV) limits.Add(wx.StaticText(G2frame.dataWindow,label=' New: '),0,WACV) limits.Add(G2G.ValidatedTxtCtrl(G2frame.dataWindow,data[1],i, \ xmin=data[0][0],xmax=data[0][1],nDig=(10,4),typeHint=float,OnLeave=AfterChange)) return limits def ExclSizer(): def OnDelExcl(event): Obj = event.GetEventObject() item = Indx[Obj.GetId()] del(data[item+2]) G2plt.PlotPatterns(G2frame,newPlot=False,plotType=plottype) wx.CallAfter(UpdateLimitsGrid,G2frame,data,plottype) Indx = {} excl = wx.FlexGridSizer(0,3,0,5) excl.Add(wx.StaticText(G2frame.dataWindow,label=' From: '),0,WACV) excl.Add(wx.StaticText(G2frame.dataWindow,label=' To: '),0,WACV) excl.Add(wx.StaticText(G2frame.dataWindow,label=' Delete?: '),0,WACV) for Id,item in enumerate(data[2:]): for i in [0,1]: excl.Add(G2G.ValidatedTxtCtrl(G2frame.dataWindow,item,i, \ xmin=data[0][0],xmax=data[0][1],nDig=(10,4),typeHint=float,OnLeave=AfterChange)) delExcl = wx.CheckBox(G2frame.dataWindow,label='') Indx[delExcl.GetId()] = Id delExcl.Bind(wx.EVT_CHECKBOX,OnDelExcl) excl.Add(delExcl,0,WACV) return excl def OnAddExcl(event): G2frame.ifGetExclude = True G2frame.plotFrame.Raise() G2G.G2MessageBox(G2frame.plotFrame,'Click on a point in the pattern to be excluded, then drag or edit limits to adjust range','Creating excluded region') def OnLimitCopy(event): hst = G2frame.GPXtree.GetItemText(G2frame.PatternId) histList = GetHistsLikeSelected(G2frame) if not histList: G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame) return dlg = G2G.G2MultiChoiceDialog(G2frame,'Copy limits from\n'+str(hst[5:])+' to...', 'Copy limits', histList) try: if dlg.ShowModal() == wx.ID_OK: for i in dlg.GetSelections(): item = histList[i] Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,item) G2frame.GPXtree.SetItemPyData( G2gd.GetGPXtreeItemId(G2frame,Id,'Limits'),copy.deepcopy(data)) finally: dlg.Destroy() def Draw(): G2frame.dataWindow.ClearData() mainSizer = wx.BoxSizer(wx.VERTICAL) topSizer = wx.BoxSizer(wx.HORIZONTAL) topSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Data used in refinement'),0,WACV) # add help button to bring up help web page - at right side of window topSizer.Add((-1,-1),1,wx.EXPAND) topSizer.Add(G2G.HelpButton(G2frame.dataWindow,helpIndex=G2frame.dataWindow.helpKey)) mainSizer.Add(topSizer,0,wx.EXPAND) mainSizer.Add((5,5)) mainSizer.Add(LimitSizer()) if len(data)>2: mainSizer.Add((0,5),0) mainSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Excluded regions:')) mainSizer.Add(ExclSizer()) G2frame.dataWindow.SetSizer(mainSizer) G2frame.dataWindow.SetDataSize() G2frame.ifGetExclude = False G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.LimitMenu) #G2frame.SetLabel(G2frame.GetLabel().split('||')[0]+' || '+'Limits') G2frame.Bind(wx.EVT_MENU,OnLimitCopy,id=G2G.wxID_LIMITCOPY) G2frame.Bind(wx.EVT_MENU,OnAddExcl,id=G2G.wxID_ADDEXCLREGION) Draw()
################################################################################ ##### Instrument parameters ################################################################################
[docs]def UpdateInstrumentGrid(G2frame,data): '''respond to selection of PWDR/SASD/REFD Instrument Parameters data tree item. ''' if 'Bank' not in data: #get it from name; absent for default parms selection hst = G2frame.GPXtree.GetItemText(G2frame.PatternId) if 'Bank' in hst: bank = int(hst.split('Bank')[1].split('_')[0]) data['Bank'] = [bank,bank,0] else: data['Bank'] = [1,1,0] def keycheck(keys): good = [] for key in keys: if key in ['Type','Bank','U','V','W','X','Y','Z','SH/L','I(L2)/I(L1)','alpha', 'beta-0','beta-1','beta-q','sig-0','sig-1','sig-2','sig-q','Polariz.','alpha-0','alpha-1', 'Lam','Azimuth','2-theta','fltPath','difC','difA','difB','Zero','Lam1','Lam2']: good.append(key) return good def updateData(inst,ref): data = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame, G2frame.PatternId,'Instrument Parameters'))[0] for item in data: try: data[item] = [data[item][0],inst[item],ref[item]] except KeyError: try: data[item] = [data[item][0],inst[item]] except KeyError: pass #skip 'Polariz.' for N-data def RefreshInstrumentGrid(event,doAnyway=False): if doAnyway or event.GetRow() == 1: peaks = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Peak List')) newpeaks = [] for peak in peaks['peaks']: newpeaks.append(G2mth.setPeakparms(data,Inst2,peak[0],peak[2])) peaks['peaks'] = newpeaks G2frame.GPXtree.SetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Peak List'),peaks) def OnCalibrate(event): Pattern = G2frame.GPXtree.GetItemPyData(G2frame.PatternId) xye = ma.array(ma.getdata(Pattern[1])) cw = np.diff(xye[0]) IndexPeaks = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Index Peak List')) if not len(IndexPeaks[0]): G2frame.ErrorDialog('Can not calibrate','Index Peak List empty') return if not np.any(IndexPeaks[1]): G2frame.ErrorDialog('Can not calibrate','Peak positions not refined') return False Ok = False for peak in IndexPeaks[0]: if peak[2] and peak[3]: Ok = True if not Ok: G2frame.ErrorDialog('Can not calibrate','Index Peak List not indexed') return if G2pwd.DoCalibInst(IndexPeaks,data): UpdateInstrumentGrid(G2frame,data) XY = [] Sigs = [] for ip,peak in enumerate(IndexPeaks[0]): if peak[2] and peak[3]: binwid = cw[np.searchsorted(xye[0],peak[0])] XY.append([peak[-1],peak[0],binwid]) Sigs.append(IndexPeaks[1][ip]) if len(XY): XY = np.array(XY) G2plt.PlotCalib(G2frame,data,XY,Sigs,newPlot=True) else: G2frame.ErrorDialog('Can not calibrate','Nothing selected for refinement') def OnLoad(event): '''Loads instrument parameters from a G2 .instprm file in response to the Instrument Parameters-Operations/Load Profile menu If instprm file has multiple banks each with header #Bank n: ..., this finds matching bank no. to load - rejects nonmatches. Note that similar code is found in ReadPowderInstprm (GSASIIdataGUI.py) ''' def GetDefaultParms(rd): '''Solicits from user a default set of parameters & returns Inst parm dict param: self: refers to the GSASII main class param: rd: importer data structure returns: dict: Instrument parameter dictionary ''' import defaultIparms as dI sind = lambda x: math.sin(x*math.pi/180.) tand = lambda x: math.tan(x*math.pi/180.) while True: # loop until we get a choice choices = [] head = 'Select from default instrument parameters' for l in dI.defaultIparm_lbl: choices.append('Defaults for '+l) res = G2G.BlockSelector(choices,ParentFrame=G2frame,title=head, header='Select default inst parms',useCancel=True) if res is None: return None if 'Generic' in choices[res]: dlg = G2G.MultiDataDialog(G2frame,title='Generic TOF detector bank', prompts=['Total FP','2-theta',],values=[25.0,150.,], limits=[[6.,200.],[5.,175.],],formats=['%6.2f','%6.1f',]) if dlg.ShowModal() == wx.ID_OK: #strictly empirical approx. FP,tth = dlg.GetValues() difC = 505.632*FP*sind(tth/2.) sig1 = 50.+2.5e-6*(difC/tand(tth/2.))**2 bet1 = .00226+7.76e+11/difC**4 Inst = G2frame.ReadPowderInstprm(dI.defaultIparms[res],bank,1,rd) Inst[0]['difC'] = [difC,difC,0] Inst[0]['sig-1'] = [sig1,sig1,0] Inst[0]['beta-1'] = [bet1,bet1,0] return Inst #this is [Inst1,Inst2] a pair of dicts dlg.Destroy() else: inst1,inst2 = G2frame.ReadPowderInstprm(dI.defaultIparms[res],bank,1,rd) return [inst1,inst2] if 'lab data' in choices[res]: rd.Sample.update({'Type':'Bragg-Brentano','Shift':[0.,False],'Transparency':[0.,False], 'SurfRoughA':[0.,False],'SurfRoughB':[0.,False]}) else: rd.Sample.update({'Type':'Debye-Scherrer','Absorption':[0.,False],'DisplaceX':[0.,False], 'DisplaceY':[0.,False]}) data = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame, G2frame.PatternId,'Instrument Parameters'))[0] bank = data['Bank'][0] pth = G2G.GetImportPath(G2frame) if not pth: pth = '.' dlg = wx.FileDialog(G2frame, 'Choose GSAS-II instrument parameters file', pth, '', 'instrument parameter files (*.instprm)|*.instprm',wx.FD_OPEN) try: if dlg.ShowModal() == wx.ID_OK: filename = dlg.GetPath() File = open(filename,'r') S = File.readline() newItems = [] newVals = [] Found = False while S: if S[0] == '#': if Found: break if 'Bank' in S: if bank == int(S.split(':')[0].split()[1]): S = File.readline() continue else: S = File.readline() while S and '#Bank' not in S: S = File.readline() continue else: #a non #Bank file S = File.readline() continue Found = True [item,val] = S[:-1].split(':') newItems.append(item) try: newVals.append(float(val)) except ValueError: newVals.append(val) S = File.readline() File.close() if Found: Inst,Inst2 = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId,'Instrument Parameters')) if 'Bank' not in Inst: #patch for old .instprm files - may cause faults for TOF data Inst['Bank'] = [1,1,0] data = G2fil.makeInstDict(newItems,newVals,len(newVals)*[False,]) G2frame.GPXtree.SetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId,'Instrument Parameters'),[data,Inst2]) RefreshInstrumentGrid(event,doAnyway=True) #to get peaks updated UpdateInstrumentGrid(G2frame,data) else: G2frame.ErrorDialog('No match','Bank %d not in %s'%(bank,filename),G2frame) else: rd = G2obj.ImportPowderData('Dummy') rd.Sample = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId,'Sample Parameters')) try: data = GetDefaultParms(rd)[0] except TypeError: #Cancel - got None pass UpdateInstrumentGrid(G2frame,data) G2plt.PlotPeakWidths(G2frame) finally: dlg.Destroy() def OnSave(event): '''Respond to the Instrument Parameters Operations/Save Profile menu item: writes current parameters to a .instprm file It does not write Bank n: on # line & thus can be used any time w/o clash of bank nos. ''' pth = G2G.GetExportPath(G2frame) dlg = wx.FileDialog(G2frame, 'Set name to save GSAS-II instrument parameters file', pth, '', 'instrument parameter files (*.instprm)|*.instprm',wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) try: if dlg.ShowModal() == wx.ID_OK: filename = dlg.GetPath() # make sure extension is .instprm filename = os.path.splitext(filename)[0]+'.instprm' File = open(filename,'w') File.write("#GSAS-II instrument parameter file; do not add/delete items!\n") for item in data: File.write(item+':'+str(data[item][1])+'\n') File.close() print ('Instrument parameters saved to: '+filename) finally: dlg.Destroy() def OnSaveAll(event): '''Respond to the Instrument Parameters Operations/Save all Profile menu & writes selected inst parms. across multiple banks into a single file Each block starts with #Bank n: GSAS-II instrument... where n is bank no. item: writes parameters from selected PWDR entries to a .instprm file ''' hst = G2frame.GPXtree.GetItemText(G2frame.PatternId) histList = GetHistsLikeSelected(G2frame) histList.insert(0,hst) saveList = [] dlg = G2G.G2MultiChoiceDialog(G2frame,'Save instrument parameters from', 'Save instrument parameters', histList) try: if dlg.ShowModal() == wx.ID_OK: for i in dlg.GetSelections(): saveList.append(histList[i]) finally: dlg.Destroy() pth = G2G.GetExportPath(G2frame) dlg = wx.FileDialog(G2frame, 'Choose GSAS-II instrument parameters file', pth, '', 'instrument parameter files (*.instprm)|*.instprm',wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) try: if dlg.ShowModal() == wx.ID_OK: filename = dlg.GetPath() # make sure extension is .instprm filename = os.path.splitext(filename)[0]+'.instprm' File = open(filename,'w') for hist in saveList: Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,hist) inst = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,Id,'Instrument Parameters'))[0] if 'Bank' not in inst: #patch bank = 1 if 'Bank' in hist: bank = int(hist.split('Bank')[1]) inst['Bank'] = [bank,bank,0] bank = inst['Bank'][0] File.write("#Bank %d: GSAS-II instrument parameter file; do not add/delete items!\n"%(bank)) for item in inst: File.write(item+':'+str(inst[item][1])+'\n') File.close() finally: dlg.Destroy() def OnReset(event): insVal.update(insDef) updateData(insVal,insRef) RefreshInstrumentGrid(event,doAnyway=True) #to get peaks updated UpdateInstrumentGrid(G2frame,data) G2plt.PlotPeakWidths(G2frame) def OnInstFlagCopy(event): hst = G2frame.GPXtree.GetItemText(G2frame.PatternId) histList = GetHistsLikeSelected(G2frame) if not histList: G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame) return keys = list(data.keys()) try: keys.remove('Source') except ValueError: pass flags = dict(zip(keys,[data[key][2] for key in keys])) instType = data['Type'][0] copyList = [] dlg = G2G.G2MultiChoiceDialog(G2frame,'Copy inst ref. flags from\n'+hst[5:], 'Copy refinement flags', histList) try: if dlg.ShowModal() == wx.ID_OK: for i in dlg.GetSelections(): copyList.append(histList[i]) finally: dlg.Destroy() for item in copyList: Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,item) instData = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,Id,'Instrument Parameters'))[0] if 'Bank' not in instData: instData['Bank'] = [1,1,0] if len(data) == len(instData) and instType == instData['Type'][0]: #don't mix data types or lam & lam1/lam2 parms! for item in instData: if item not in ['Source',]: instData[item][2] = copy.copy(flags[item]) else: print (item+' not copied - instrument parameters not commensurate') def OnInstCopy(event): #need fix for dictionary hst = G2frame.GPXtree.GetItemText(G2frame.PatternId) histList = GetHistsLikeSelected(G2frame) if not histList: G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame) return copyList = [] copyData = copy.deepcopy(data) del copyData['Azimuth'] #not to be copied! instType = data['Type'][0] dlg = G2G.G2MultiChoiceDialog(G2frame,'Copy inst params from\n'+hst, 'Copy parameters', histList) try: if dlg.ShowModal() == wx.ID_OK: for i in dlg.GetSelections(): copyList.append(histList[i]) finally: dlg.Destroy() for item in copyList: Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,item) instData = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,Id,'Instrument Parameters'))[0] if 'Bank' not in instData: instData['Bank'] = [1,1,0] if len(data) == len(instData) and instType == instData['Type'][0]: #don't mix data types or lam & lam1/lam2 parms! instData.update(copyData) else: print (item+' not copied - instrument parameters not commensurate') def AfterChange(invalid,value,tc): if invalid: return updateData(insVal,insRef) def NewProfile(invalid,value,tc): if invalid: return updateData(insVal,insRef) G2plt.PlotPeakWidths(G2frame) def OnItemRef(event): Obj = event.GetEventObject() item = RefObj[Obj.GetId()] insRef[item] = Obj.GetValue() updateData(insVal,insRef) def OnCopy1Val(event): '''Select one instrument parameter value to edit and copy to many histograms optionally allow values to be edited in a table ''' updateData(insVal,insRef) G2G.SelectEdit1Var(G2frame,data,labelLst,elemKeysLst,dspLst,refFlgElem) insVal.update({key:data[key][1] for key in instkeys}) insRef.update({key:data[key][2] for key in instkeys}) wx.CallAfter(MakeParameterWindow) def lblWdef(lbl,dec,val): 'Label parameter showing the default value' fmt = "%15."+str(dec)+"f" return " " + lbl + " (" + (fmt % val).strip() + "): " def RefineBox(item): 'Define a refine checkbox with binding' #wid = wx.CheckBox(G2frame.dataWindow,label=' Refine? ') wid = wx.CheckBox(G2frame.dataWindow,label='') wid.SetValue(bool(insRef[item])) RefObj[wid.GetId()] = item wid.Bind(wx.EVT_CHECKBOX, OnItemRef) return wid def OnLamPick(event): data['Source'][1] = lamType = event.GetEventObject().GetValue() if 'P' in insVal['Type']: insVal['Lam1'] = waves[lamType][0] insVal['Lam2'] = waves[lamType][1] elif 'S' in insVal['Type'] and 'synch' not in lamType: insVal['Lam'] = meanwaves[lamType] updateData(insVal,insRef) i,j= wx.__version__.split('.')[0:2] if int(i)+int(j)/10. > 2.8: pass # repaint crashes wxpython 2.9 wx.CallLater(100, MakeParameterWindow) #wx.CallAfter(MakeParameterWindow) else: wx.CallAfter(MakeParameterWindow) def MakeParameterWindow(): 'Displays the Instrument parameters in the dataWindow frame' G2frame.dataWindow.ClearData() mainSizer = wx.BoxSizer(wx.VERTICAL) instSizer = wx.FlexGridSizer(0,3,5,5) subSizer = wx.BoxSizer(wx.HORIZONTAL) if insVal['Bank'] == None: #patch insVal['Bank'] = 1 text = ' Histogram Type: %s Bank: %d'%(insVal['Type'],insVal['Bank']) subSizer.Add(wx.StaticText(G2frame.dataWindow,-1,text),0,WACV) # add help button to bring up help web page - at right side of window subSizer.Add((-1,-1),1,wx.EXPAND) subSizer.Add(G2G.HelpButton(G2frame.dataWindow,helpIndex=G2frame.dataWindow.helpKey)) mainSizer.Add(subSizer,0,wx.EXPAND) # mainSizer.Add(subSizer) labelLst[:],elemKeysLst[:],dspLst[:],refFlgElem[:] = [],[],[],[] if 'P' in insVal['Type']: #powder data [instSizer.Add(wx.StaticText(G2frame.dataWindow,-1,txt),0,WACV) for txt in [' Name (default)',' Value','Refine?']] if 'C' in insVal['Type']: #constant wavelength labelLst.append('Azimuth angle') elemKeysLst.append(['Azimuth',1]) dspLst.append([10,2]) refFlgElem.append(None) if 'Lam1' in insVal: subSizer = wx.BoxSizer(wx.HORIZONTAL) subSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Azimuth: '),0,WACV) txt = '%7.2f'%(insVal['Azimuth']) subSizer.Add(wx.StaticText(G2frame.dataWindow,-1,txt.strip()),0,WACV) subSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Ka1/Ka2: '),0,WACV) txt = u' %8.6f/%8.6f\xc5'%(insVal['Lam1'],insVal['Lam2']) subSizer.Add(wx.StaticText(G2frame.dataWindow,-1,txt.strip()),0,WACV) waveSizer = wx.BoxSizer(wx.HORIZONTAL) waveSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Source type: '),0,WACV) # PATCH?: for now at least, Source is not saved anywhere before here if 'Source' not in data: data['Source'] = ['CuKa','?'] choice = ['TiKa','CrKa','FeKa','CoKa','CuKa','MoKa','AgKa'] lamPick = wx.ComboBox(G2frame.dataWindow,value=data['Source'][1],choices=choice,style=wx.CB_READONLY|wx.CB_DROPDOWN) lamPick.Bind(wx.EVT_COMBOBOX, OnLamPick) waveSizer.Add(lamPick,0) subSizer.Add(waveSizer,0) mainSizer.Add(subSizer) instSizer.Add(wx.StaticText(G2frame.dataWindow,-1,lblWdef('I(L2)/I(L1)',4,insDef['I(L2)/I(L1)'])),0,WACV) key = 'I(L2)/I(L1)' labelLst.append(key) elemKeysLst.append([key,1]) dspLst.append([10,4]) refFlgElem.append([key,2]) ratVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,insVal,key,nDig=(10,4),typeHint=float,OnLeave=AfterChange) instSizer.Add(ratVal,0) instSizer.Add(RefineBox(key),0,WACV) else: # single wavelength instSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Azimuth: '),0,WACV) txt = '%7.2f'%(insVal['Azimuth']) instSizer.Add(wx.StaticText(G2frame.dataWindow,-1,txt.strip()),0,WACV) instSizer.Add((5,5),0) key = 'Lam' instSizer.Add(wx.StaticText(G2frame.dataWindow,-1,u' Lam (\xc5): (%10.6f)'%(insDef[key])),0,WACV) waveVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,insVal,key,nDig=(10,6),typeHint=float,OnLeave=AfterChange) labelLst.append(u'Lam (\xc5)') elemKeysLst.append([key,1]) dspLst.append([10,6]) instSizer.Add(waveVal,0,WACV) refFlgElem.append([key,2]) instSizer.Add(RefineBox(key),0,WACV) for item in ['Zero','Polariz.']: if item in insDef: labelLst.append(item) elemKeysLst.append([item,1]) dspLst.append([10,4]) instSizer.Add(wx.StaticText(G2frame.dataWindow,-1,lblWdef(item,4,insDef[item])),0,WACV) itemVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,insVal,item,nDig=(10,4),typeHint=float,OnLeave=AfterChange) instSizer.Add(itemVal,0,WACV) refFlgElem.append([item,2]) instSizer.Add(RefineBox(item),0,WACV) for item in ['U','V','W','X','Y','Z','SH/L']: nDig = (10,3) if item == 'SH/L': nDig = (10,5) labelLst.append(item) elemKeysLst.append([item,1]) dspLst.append(nDig) refFlgElem.append([item,2]) instSizer.Add(wx.StaticText(G2frame.dataWindow,-1,lblWdef(item,nDig[1],insDef[item])),0,WACV) itemVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,insVal,item,nDig=nDig,typeHint=float,OnLeave=NewProfile) instSizer.Add(itemVal,0,WACV) instSizer.Add(RefineBox(item),0,WACV) elif 'B' in insVal['Type']: #pink beam CW (x-rays & neutrons(?)) labelLst.append('Azimuth angle') elemKeysLst.append(['Azimuth',1]) dspLst.append([10,2]) refFlgElem.append(None) instSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Azimuth: '),0,WACV) txt = '%7.2f'%(insVal['Azimuth']) instSizer.Add(wx.StaticText(G2frame.dataWindow,-1,txt.strip()),0,WACV) instSizer.Add((5,5),0) key = 'Lam' instSizer.Add(wx.StaticText(G2frame.dataWindow,-1,u' Lam (\xc5): (%10.6f)'%(insDef[key])),0,WACV) waveVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,insVal,key,nDig=(10,6),typeHint=float,OnLeave=AfterChange) labelLst.append(u'Lam (\xc5)') elemKeysLst.append([key,1]) dspLst.append([10,6]) instSizer.Add(waveVal,0,WACV) refFlgElem.append([key,2]) instSizer.Add(RefineBox(key),0,WACV) for item in ['Zero','Polariz.']: if item in insDef: labelLst.append(item) elemKeysLst.append([item,1]) dspLst.append([10,4]) instSizer.Add(wx.StaticText(G2frame.dataWindow,-1,lblWdef(item,4,insDef[item])),0,WACV) itemVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,insVal,item,nDig=(10,4),typeHint=float,OnLeave=AfterChange) instSizer.Add(itemVal,0,WACV) refFlgElem.append([item,2]) instSizer.Add(RefineBox(item),0,WACV) for item in ['U','V','W','X','Y','Z','alpha-0','alpha-1','beta-0','beta-1']: nDig = (10,3) labelLst.append(item) elemKeysLst.append([item,1]) dspLst.append(nDig) refFlgElem.append([item,2]) instSizer.Add(wx.StaticText(G2frame.dataWindow,-1,lblWdef(item,nDig[1],insDef[item])),0,WACV) itemVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,insVal,item,nDig=nDig,typeHint=float,OnLeave=NewProfile) instSizer.Add(itemVal,0,WACV) instSizer.Add(RefineBox(item),0,WACV) elif 'T' in insVal['Type']: #time of flight (neutrons) subSizer = wx.BoxSizer(wx.HORIZONTAL) subSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Flight path: '),0,WACV) txt = '%8.3f'%(insVal['fltPath']) subSizer.Add(wx.StaticText(G2frame.dataWindow,-1,txt.strip()),0,WACV) labelLst.append('flight path') elemKeysLst.append(['fltPath',1]) dspLst.append([10,2]) refFlgElem.append(None) subSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' 2-theta: '),0,WACV) txt = '%7.2f'%(insVal['2-theta']) subSizer.Add(wx.StaticText(G2frame.dataWindow,-1,txt.strip()),0,WACV) labelLst.append('2-theta') elemKeysLst.append(['2-theta',1]) dspLst.append([10,2]) refFlgElem.append(None) if 'Pdabc' in Inst2: Items = ['sig-0','sig-1','sig-2','sig-q','X','Y','Z'] subSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' difC: '),0,WACV) txt = '%8.2f'%(insVal['difC']) subSizer.Add(wx.StaticText(G2frame.dataWindow,-1,txt.strip()),0,WACV) labelLst.append('difC') elemKeysLst.append(['difC',1]) dspLst.append([10,2]) refFlgElem.append(None) subSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' alpha, beta: fixed by table'),0,WACV) else: Items = ['difC','difA','difB','Zero','alpha','beta-0','beta-1','beta-q','sig-0','sig-1','sig-2','sig-q','X','Y','Z'] mainSizer.Add((5,5),0) mainSizer.Add(subSizer) mainSizer.Add((5,5),0) for item in Items: if item == '': instSizer.Add((5,5),0) instSizer.Add((5,5),0) instSizer.Add((5,5),0) continue nDig = (10,3) if 'beta' in item: nDig = (12,6) instSizer.Add( wx.StaticText(G2frame.dataWindow,-1,lblWdef(item,nDig[1],insDef[item])), 0,WACV) itemVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,insVal,item,nDig=nDig,typeHint=float,OnLeave=AfterChange) instSizer.Add(itemVal,0,WACV) labelLst.append(item) elemKeysLst.append([item,1]) dspLst.append(nDig) refFlgElem.append([item,2]) instSizer.Add(RefineBox(item),0,WACV) elif 'PKS' in insVal['Type']: #peak positions only key = 'Lam' instSizer.Add(wx.StaticText(G2frame.dataWindow,-1,u' Lam (\xc5): (%10.6f)'%(insDef[key])), 0,WACV) waveVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,insVal,key,nDig=(10,6),typeHint=float,OnLeave=AfterChange) labelLst.append(u'Lam (\xc5)') elemKeysLst.append([key,1]) dspLst.append([10,6]) instSizer.Add(waveVal,0,WACV) refFlgElem.append([key,2]) for item in ['Zero',]: if item in insDef: labelLst.append(item) elemKeysLst.append([item,1]) dspLst.append([10,4]) instSizer.Add( wx.StaticText(G2frame.dataWindow,-1,lblWdef(item,4,insDef[item])), 0,WACV) itemVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,insVal,item,nDig=(10,4),typeHint=float,OnLeave=AfterChange) instSizer.Add(itemVal,0,WACV) refFlgElem.append([item,2]) elif 'S' in insVal['Type']: #single crystal data if 'C' in insVal['Type']: #constant wavelength instSizer.Add(wx.StaticText(G2frame.dataWindow,-1,u' Lam (\xc5): (%10.6f)'%(insDef['Lam'])), 0,WACV) waveVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,insVal,'Lam',nDig=(10,6),typeHint=float,OnLeave=AfterChange) instSizer.Add(waveVal,0,WACV) labelLst.append(u'Lam (\xc5)') waveSizer = wx.BoxSizer(wx.HORIZONTAL) waveSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Source type: '),0,WACV) # PATCH?: for now at least, Source is not saved anywhere before here if 'Source' not in data: data['Source'] = ['CuKa','?'] choice = ['synchrotron','TiKa','CrKa','FeKa','CoKa','CuKa','MoKa','AgKa'] lamPick = wx.ComboBox(G2frame.dataWindow,value=data['Source'][1],choices=choice,style=wx.CB_READONLY|wx.CB_DROPDOWN) lamPick.Bind(wx.EVT_COMBOBOX, OnLamPick) waveSizer.Add(lamPick,0,WACV) instSizer.Add(waveSizer,0,WACV) elemKeysLst.append(['Lam',1]) dspLst.append([10,6]) refFlgElem.append(None) else: #time of flight (neutrons) pass #for now elif insVal['Type'][0] in ['L','R',]: if 'C' in insVal['Type']: instSizer.Add(wx.StaticText(G2frame.dataWindow,-1,u' Lam (\xc5): (%10.6f)'%(insDef['Lam'])), 0,WACV) waveVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,insVal,'Lam',nDig=(10,6),typeHint=float,OnLeave=AfterChange) instSizer.Add(waveVal,0,WACV) labelLst.append(u'Lam (\xc5)') elemKeysLst.append(['Lam',1]) dspLst.append([10,6]) refFlgElem.append(None) instSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Azimuth: %7.2f'%(insVal['Azimuth'])),0,WACV) labelLst.append('Azimuth angle') elemKeysLst.append(['Azimuth',1]) dspLst.append([10,2]) refFlgElem.append(None) else: #time of flight (neutrons) pass #for now mainSizer.Add(instSizer,0) G2frame.dataWindow.SetDataSize() G2frame.dataWindow.SetSizer(mainSizer) # end of MakeParameterWindow # beginning of UpdateInstrumentGrid code #patch: make sure all parameter items are lists patched = 0 for key in data: if type(data[key]) is tuple: data[key] = list(data[key]) patched += 1 if patched: print (patched,' instrument parameters changed from tuples') if 'Z' not in data: data['Z'] = [0.0,0.0,False] #end of patch labelLst,elemKeysLst,dspLst,refFlgElem = [],[],[],[] instkeys = keycheck(data.keys()) if 'P' in data['Type'][0]: #powder data insVal = dict(zip(instkeys,[data[key][1] for key in instkeys])) insDef = dict(zip(instkeys,[data[key][0] for key in instkeys])) insRef = dict(zip(instkeys,[data[key][2] for key in instkeys])) if 'NC' in data['Type'][0]: del(insDef['Polariz.']) del(insVal['Polariz.']) del(insRef['Polariz.']) elif 'S' in data['Type'][0]: #single crystal data insVal = dict(zip(instkeys,[data[key][1] for key in instkeys])) insDef = dict(zip(instkeys,[data[key][0] for key in instkeys])) insRef = {} elif 'L' in data['Type'][0]: #low angle data insVal = dict(zip(instkeys,[data[key][1] for key in instkeys])) insDef = dict(zip(instkeys,[data[key][0] for key in instkeys])) insRef = {} elif 'R' in data['Type'][0]: #low angle data insVal = dict(zip(instkeys,[data[key][1] for key in instkeys])) insDef = dict(zip(instkeys,[data[key][0] for key in instkeys])) insRef = {} RefObj = {} #These from Intl. Tables C, Table 4.2.2.1, p. 177-179 waves = {'CuKa':[1.54051,1.54433],'TiKa':[2.74841,2.75207],'CrKa':[2.28962,2.29351], 'FeKa':[1.93597,1.93991],'CoKa':[1.78892,1.79278],'MoKa':[0.70926,0.713543], 'AgKa':[0.559363,0.563775]} # meanwaves computed as (2*Ka1+Ka2)/3 meanwaves = {'CuKa':1.54178,'TiKa':2.74963,'CrKa':2.29092,'FeKa':1.93728, 'CoKa':1.79021,'MoKa':0.71069,'AgKa':0.56083} Inst2 = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame, G2frame.PatternId,'Instrument Parameters'))[1] G2gd.SetDataMenuBar(G2frame) #patch if 'P' in insVal['Type']: #powder data if 'C' in insVal['Type']: #constant wavelength if 'Azimuth' not in insVal: insVal['Azimuth'] = 0.0 insDef['Azimuth'] = 0.0 insRef['Azimuth'] = False # if 'T' in insVal['Type']: # if 'difB' not in insVal: # insVal['difB'] = 0.0 # insDef['difB'] = 0.0 # insRef['difB'] = False #end of patch if 'P' in insVal['Type']: #powder data menu commands G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.InstMenu) G2frame.GetStatusBar().SetStatusText('NB: Azimuth is used for polarization only',1) G2frame.Bind(wx.EVT_MENU,OnCalibrate,id=G2G.wxID_INSTCALIB) G2frame.Bind(wx.EVT_MENU,OnLoad,id=G2G.wxID_INSTLOAD) G2frame.Bind(wx.EVT_MENU,OnSave,id=G2G.wxID_INSTSAVE) G2frame.Bind(wx.EVT_MENU,OnSaveAll,id=G2G.wxID_INSTSAVEALL) G2frame.Bind(wx.EVT_MENU,OnReset,id=G2G.wxID_INSTPRMRESET) G2frame.Bind(wx.EVT_MENU,OnInstCopy,id=G2G.wxID_INSTCOPY) G2frame.Bind(wx.EVT_MENU,OnInstFlagCopy,id=G2G.wxID_INSTFLAGCOPY) G2frame.Bind(wx.EVT_MENU,OnCopy1Val,id=G2G.wxID_INST1VAL) elif 'L' in insVal['Type'] or 'R' in insVal['Type']: #SASD data menu commands G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.SASDInstMenu) G2frame.Bind(wx.EVT_MENU,OnInstCopy,id=G2G.wxID_SASDINSTCOPY) MakeParameterWindow() G2frame.dataWindow.SendSizeEvent()
################################################################################ ##### Sample parameters ################################################################################
[docs]def UpdateSampleGrid(G2frame,data): '''respond to selection of PWDR/SASD Sample Parameters data tree item. ''' def OnSampleSave(event): '''Respond to the Sample Parameters Operations/Save menu item: writes current parameters to a .samprm file ''' pth = G2G.GetExportPath(G2frame) dlg = wx.FileDialog(G2frame, 'Choose GSAS-II sample parameters file', pth, '', 'sample parameter files (*.samprm)|*.samprm',wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) try: if dlg.ShowModal() == wx.ID_OK: filename = dlg.GetPath() # make sure extension is .samprm filename = os.path.splitext(filename)[0]+'.samprm' File = open(filename,'w') File.write("#GSAS-II sample parameter file\n") File.write("'Type':'"+str(data['Type'])+"'\n") File.write("'Gonio. radius':"+str(data['Gonio. radius'])+"\n") if data.get('InstrName'): File.write("'InstrName':'"+str(data['InstrName'])+"'\n") File.close() finally: dlg.Destroy() def OnSampleLoad(event): '''Loads sample parameters from a G2 .samprm file in response to the Sample Parameters-Operations/Load menu Note that similar code is found in ReadPowderInstprm (GSASII.py) ''' pth = G2G.GetImportPath(G2frame) if not pth: pth = '.' dlg = wx.FileDialog(G2frame, 'Choose GSAS-II sample parameters file', pth, '', 'sample parameter files (*.samprm)|*.samprm',wx.FD_OPEN) try: if dlg.ShowModal() == wx.ID_OK: filename = dlg.GetPath() File = open(filename,'r') S = File.readline() newItems = {} while S: if S[0] == '#': S = File.readline() continue [item,val] = S[:-1].split(':') newItems[item.strip("'")] = eval(val) S = File.readline() File.close() data.update(newItems) G2frame.GPXtree.SetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId,'Sample Parameters'),data) UpdateSampleGrid(G2frame,data) finally: dlg.Destroy() def OnAllSampleLoad(event): filename = '' pth = G2G.GetImportPath(G2frame) if not pth: pth = '.' dlg = wx.FileDialog(G2frame, 'Choose multihistogram metadata text file', pth, '', 'metadata file (*.*)|*.*',wx.FD_OPEN) try: if dlg.ShowModal() == wx.ID_OK: filename = dlg.GetPath() File = open(filename,'r') S = File.readline() newItems = [] itemNames = [] Comments = [] while S: if S[0] == '#': Comments.append(S) S = File.readline() continue S = S.replace(',',' ').replace('\t',' ') Stuff = S[:-1].split() itemNames.append(Stuff[0]) newItems.append(Stuff[1:]) S = File.readline() File.close() finally: dlg.Destroy() if not filename: G2frame.ErrorDialog('Nothing to do','No file selected') return dataDict = dict(zip(itemNames,newItems)) ifany = False Controls = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Controls')) Names = [' ','Phi','Chi','Omega','Time','Temperature','Pressure'] freeNames = {} for name in ['FreePrm1','FreePrm2','FreePrm3']: freeNames[Controls[name]] = name Names.append(Controls[name]) #import imp #imp.reload(G2G) dlg = G2G.G2ColumnIDDialog( G2frame,' Choose multihistogram metadata columns:', 'Select columns',Comments,Names,np.array(newItems).T) try: if dlg.ShowModal() == wx.ID_OK: colNames,newData = dlg.GetSelection() dataDict = dict(zip(itemNames,newData.T)) for item in colNames: if item != ' ': ifany = True finally: dlg.Destroy() if not ifany: G2frame.ErrorDialog('Nothing to do','No columns identified') return histList = [G2frame.GPXtree.GetItemText(G2frame.PatternId),] histList += GetHistsLikeSelected(G2frame) colIds = {} for i,name in enumerate(colNames): if name != ' ': colIds[name] = i for hist in histList: name = hist.split()[1] #this is file name newItems = {} for item in colIds: key = freeNames.get(item,item) newItems[key] = float(dataDict[name][colIds[item]]) Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,hist) sampleData = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,Id,'Sample Parameters')) sampleData.update(newItems) UpdateSampleGrid(G2frame,data) def OnSetScale(event): if histName[:4] in ['REFD','PWDR']: Scale = data['Scale'][0] dlg = wx.MessageDialog(G2frame,'Rescale data by %.2f?'%(Scale),'Rescale data',wx.OK|wx.CANCEL) try: if dlg.ShowModal() == wx.ID_OK: pId = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,histName) y,w = G2frame.GPXtree.GetItemPyData(pId)[1][1:3] y *= Scale w /= Scale**2 data['Scale'][0] = 1.0 finally: dlg.Destroy() G2plt.PlotPatterns(G2frame,plotType=histName[:4],newPlot=True) UpdateSampleGrid(G2frame,data) return #SASD rescaliing histList = [] item, cookie = G2frame.GPXtree.GetFirstChild(G2frame.root) while item: name = G2frame.GPXtree.GetItemText(item) if 'SASD' in name and name != histName: histList.append(name) item, cookie = G2frame.GPXtree.GetNextChild(G2frame.root, cookie) if not len(histList): #nothing to copy to! return dlg = wx.SingleChoiceDialog(G2frame,'Select reference histogram for scaling', 'Reference histogram',histList) try: if dlg.ShowModal() == wx.ID_OK: sel = dlg.GetSelection() refHist = histList[sel] finally: dlg.Destroy() Limits = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Limits')) Profile = G2frame.GPXtree.GetItemPyData(G2frame.PatternId)[1] Data = [Profile,Limits,data] refId = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,refHist) refSample = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,refId, 'Sample Parameters')) refLimits = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,refId, 'Limits')) refProfile = G2frame.GPXtree.GetItemPyData(refId)[1] refData = [refProfile,refLimits,refSample] G2sasd.SetScale(Data,refData) G2plt.PlotPatterns(G2frame,plotType='SASD',newPlot=True) UpdateSampleGrid(G2frame,data) def OnRescaleAll(event): hst = G2frame.GPXtree.GetItemText(G2frame.PatternId) histList = GetHistsLikeSelected(G2frame) x0,y0,w0 = G2frame.GPXtree.GetItemPyData(G2frame.PatternId)[1][:3] if not histList: G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame) return od = {'label_1':'Scaling range min','value_1':0.0,'label_2':'Scaling range max','value_2':10.} dlg = G2G.G2MultiChoiceDialog(G2frame, 'Do scaling from\n'+str(hst[5:])+' to...','Rescale histograms', histList,extraOpts=od) try: if dlg.ShowModal() == wx.ID_OK: Xmin = od['value_1'] Xmax = od['value_2'] iBeg = np.searchsorted(x0,Xmin) iFin = np.searchsorted(x0,Xmax) if iBeg > iFin: wx.MessageBox('Wrong order for Xmin, Xmax','Error',style=wx.ICON_EXCLAMATION) else: sum0 = np.sum(y0[iBeg:iFin]) result = dlg.GetSelections() for i in result: item = histList[i] Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,item) xi,yi,wi = G2frame.GPXtree.GetItemPyData(Id)[1][:3] sumi = np.sum(yi[iBeg:iFin]) if sumi: Scale = sum0/sumi yi *= Scale wi /= Scale**2 finally: dlg.Destroy() G2plt.PlotPatterns(G2frame,plotType=histName[:4],newPlot=True) def OnSampleCopy(event): histType,copyNames = SetCopyNames(histName,data['Type'], addNames = ['Omega','Chi','Phi','Gonio. radius','InstrName']) copyDict = {} for parm in copyNames: copyDict[parm] = data[parm] hst = G2frame.GPXtree.GetItemText(G2frame.PatternId) histList = GetHistsLikeSelected(G2frame) if not histList: G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame) return dlg = G2G.G2MultiChoiceDialog(G2frame,'Copy sample params from\n'+str(hst[5:])+' to...', 'Copy sample parameters', histList) try: if dlg.ShowModal() == wx.ID_OK: result = dlg.GetSelections() for i in result: item = histList[i] Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,item) sampleData = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,Id,'Sample Parameters')) sampleData.update(copy.deepcopy(copyDict)) finally: dlg.Destroy() def OnSampleCopySelected(event): hst = G2frame.GPXtree.GetItemText(G2frame.PatternId) Controls = G2frame.GPXtree.GetItemPyData( G2gd.GetGPXtreeItemId(G2frame,G2frame.root, 'Controls')) histList = GetHistsLikeSelected(G2frame) if not histList: G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame) return # Assemble a list of item labels TextTable = {key:label for key,label,dig in SetupSampleLabels(hst,data.get('Type'),Inst['Type'][0])} # get flexible labels TextTable.update({key:Controls[key] for key in Controls if key.startswith('FreePrm')}) # add a few extra TextTable.update({'Type':'Diffractometer type','InstrName':'Instrument Name',}) # Assemble a list of dict entries that would be labeled in the Sample # params data window (drop ranId and items not used). keyList = [i for i in data.keys() if i in TextTable] keyText = [TextTable[i] for i in keyList] # sort both lists together, ordered by keyText keyText, keyList = zip(*sorted(list(zip(keyText,keyList)))) # sort lists selectedKeys = [] dlg = G2G.G2MultiChoiceDialog(G2frame,'Select which sample parameters\nto copy', 'Select sample parameters', keyText) try: if dlg.ShowModal() == wx.ID_OK: selectedKeys = [keyList[i] for i in dlg.GetSelections()] finally: dlg.Destroy() if not selectedKeys: return # nothing to copy copyDict = {} for parm in selectedKeys: copyDict[parm] = data[parm] dlg = G2G.G2MultiChoiceDialog(G2frame,'Copy sample params from\n'+str(hst[5:])+' to...', 'Copy sample parameters', histList) try: if dlg.ShowModal() == wx.ID_OK: result = dlg.GetSelections() for i in result: item = histList[i] Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,item) sampleData = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,Id,'Sample Parameters')) sampleData.update(copy.deepcopy(copyDict)) finally: dlg.Destroy() G2plt.PlotPatterns(G2frame,plotType=hst[:4],newPlot=False) def OnSampleFlagCopy(event): histType,copyNames = SetCopyNames(histName,data['Type']) flagDict = {} for parm in copyNames: flagDict[parm] = data[parm][1] hst = G2frame.GPXtree.GetItemText(G2frame.PatternId) histList = GetHistsLikeSelected(G2frame) if not histList: G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame) return dlg = G2G.G2MultiChoiceDialog(G2frame,'Copy sample ref. flags from\n'+str(hst[5:])+' to...', 'Copy sample flags', histList) try: if dlg.ShowModal() == wx.ID_OK: result = dlg.GetSelections() for i in result: item = histList[i] Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,item) sampleData = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,Id,'Sample Parameters')) for name in copyNames: sampleData[name][1] = copy.copy(flagDict[name]) finally: dlg.Destroy() def OnHistoChange(): '''Called when the histogram type is changed to refresh the window ''' #wx.CallAfter(UpdateSampleGrid,G2frame,data) wx.CallLater(100,UpdateSampleGrid,G2frame,data) def SetNameVal(): inst = instNameVal.GetValue() data['InstrName'] = inst.strip() def OnNameVal(event): event.Skip() wx.CallAfter(SetNameVal) def AfterChange(invalid,value,tc): if invalid: return if tc.key == 0 and 'SASD' in histName: #a kluge for Scale! G2plt.PlotPatterns(G2frame,plotType='SASD',newPlot=True) elif tc.key == 'Thick': wx.CallAfter(UpdateSampleGrid,G2frame,data) def OnMaterial(event): Obj = event.GetEventObject() Id = Info[Obj.GetId()] data['Materials'][Id]['Name'] = Obj.GetValue() wx.CallAfter(UpdateSampleGrid,G2frame,data) def OnVolFrac(invalid,value,tc): Id = Info[tc.GetId()] data['Materials'][not Id][key] = 1.-value wx.CallAfter(UpdateSampleGrid,G2frame,data) def OnCopy1Val(event): 'Select one value to copy to many histograms and optionally allow values to be edited in a table' G2G.SelectEdit1Var(G2frame,data,labelLst,elemKeysLst,dspLst,refFlgElem) wx.CallAfter(UpdateSampleGrid,G2frame,data) def SearchAllComments(value,tc,*args,**kwargs): '''Called when the label for a FreePrm is changed: the comments for all PWDR histograms are searched for a "label=value" pair that matches the label (case is ignored) and the values are then set to this value, if it can be converted to a float. ''' Id, cookie = G2frame.GPXtree.GetFirstChild(G2frame.root) while Id: name = G2frame.GPXtree.GetItemText(Id) if 'PWDR' in name: Comments = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,Id,'Comments')) Sample = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,Id, 'Sample Parameters')) for i,item in enumerate(Comments): itemSp = item.split('=') if value.lower() == itemSp[0].lower(): try: Sample[tc.key] = float(itemSp[1]) except: print('"{}" has an invalid value in Comments from {}' .format(item.strip(),name)) Id, cookie = G2frame.GPXtree.GetNextChild(G2frame.root, cookie) wx.CallLater(100,UpdateSampleGrid,G2frame,data) ######## DEBUG ####################################################### #import GSASIIpwdGUI #reload(GSASIIpwdGUI) #reload(G2gd) ###################################################################### Inst = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId( G2frame,G2frame.PatternId, 'Instrument Parameters'))[0] histName = G2frame.GPXtree.GetItemText(G2frame.PatternId) G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.SampleMenu) #G2frame.SetLabel(G2frame.GetLabel().split('||')[0]+' || '+'Sample Parameters') G2frame.Bind(wx.EVT_MENU, OnSetScale, id=G2G.wxID_SETSCALE) G2frame.Bind(wx.EVT_MENU, OnSampleCopy, id=G2G.wxID_SAMPLECOPY) G2frame.Bind(wx.EVT_MENU, OnSampleCopySelected, id=G2G.wxID_SAMPLECOPYSOME) G2frame.Bind(wx.EVT_MENU, OnSampleFlagCopy, id=G2G.wxID_SAMPLEFLAGCOPY) G2frame.Bind(wx.EVT_MENU, OnSampleSave, id=G2G.wxID_SAMPLESAVE) G2frame.Bind(wx.EVT_MENU, OnSampleLoad, id=G2G.wxID_SAMPLELOAD) G2frame.Bind(wx.EVT_MENU, OnCopy1Val, id=G2G.wxID_SAMPLE1VAL) G2frame.Bind(wx.EVT_MENU, OnAllSampleLoad, id=G2G.wxID_ALLSAMPLELOAD) G2frame.Bind(wx.EVT_MENU, OnRescaleAll, id=G2G.wxID_RESCALEALL) if histName[:4] in ['SASD','REFD','PWDR']: G2frame.dataWindow.SetScale.Enable(True) Controls = G2frame.GPXtree.GetItemPyData( G2gd.GetGPXtreeItemId(G2frame,G2frame.root, 'Controls')) #patch if 'ranId' not in data: data['ranId'] = ran.randint(0,sys.maxsize) if not 'Gonio. radius' in data: data['Gonio. radius'] = 200.0 if not 'Omega' in data: data.update({'Omega':0.0,'Chi':0.0,'Phi':0.0}) if 'Azimuth' not in data: data['Azimuth'] = 0.0 if type(data['Temperature']) is int: data['Temperature'] = float(data['Temperature']) if 'Time' not in data: data['Time'] = 0.0 if 'FreePrm1' not in Controls: Controls['FreePrm1'] = 'Sample humidity (%)' if 'FreePrm2' not in Controls: Controls['FreePrm2'] = 'Sample voltage (V)' if 'FreePrm3' not in Controls: Controls['FreePrm3'] = 'Applied load (MN)' if 'FreePrm1' not in data: data['FreePrm1'] = 0. if 'FreePrm2' not in data: data['FreePrm2'] = 0. if 'FreePrm3' not in data: data['FreePrm3'] = 0. if 'SurfRoughA' not in data and 'PWDR' in histName: data['SurfRoughA'] = [0.,False] data['SurfRoughB'] = [0.,False] if 'Trans' not in data and 'SASD' in histName: data['Trans'] = 1.0 if 'SlitLen' not in data and 'SASD' in histName: data['SlitLen'] = 0.0 if 'Shift' not in data: data['Shift'] = [0.0,False] if 'Transparency' not in data: data['Transparency'] = [0.0,False] data['InstrName'] = data.get('InstrName','') #patch end labelLst,elemKeysLst,dspLst,refFlgElem = [],[],[],[] parms = SetupSampleLabels(histName,data.get('Type'),Inst['Type'][0]) G2frame.dataWindow.ClearData() mainSizer = wx.BoxSizer(wx.VERTICAL) topSizer = wx.BoxSizer(wx.HORIZONTAL) topSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Sample and Experimental Parameters')) # add help button to bring up help web page - at right side of window topSizer.Add((-1,-1),1,wx.EXPAND) topSizer.Add(G2G.HelpButton(G2frame.dataWindow,helpIndex=G2frame.dataWindow.helpKey)) mainSizer.Add(topSizer,0,wx.EXPAND) nameSizer = wx.BoxSizer(wx.HORIZONTAL) nameSizer.Add(wx.StaticText(G2frame.dataWindow,wx.ID_ANY,' Instrument Name '),0,WACV) nameSizer.Add((-1,-1),1,WACV) instNameVal = wx.TextCtrl(G2frame.dataWindow,wx.ID_ANY,data['InstrName'], size=(200,-1),style=wx.TE_PROCESS_ENTER) nameSizer.Add(instNameVal) instNameVal.Bind(wx.EVT_CHAR,OnNameVal) mainSizer.Add(nameSizer,0) mainSizer.Add((5,5),0) labelLst.append('Instrument Name') elemKeysLst.append(['InstrName']) dspLst.append(None) refFlgElem.append(None) if 'PWDR' in histName: nameSizer = wx.BoxSizer(wx.HORIZONTAL) nameSizer.Add(wx.StaticText(G2frame.dataWindow,wx.ID_ANY,' Diffractometer type: '), 0,WACV) if 'T' in Inst['Type'][0] or 'B' in Inst['Type'][0]: choices = ['Debye-Scherrer',] else: choices = ['Debye-Scherrer','Bragg-Brentano',] histoType = G2G.G2ChoiceButton(G2frame.dataWindow,choices, strLoc=data,strKey='Type', onChoice=OnHistoChange) nameSizer.Add(histoType) mainSizer.Add(nameSizer,0) mainSizer.Add((5,5),0) parmSizer = wx.FlexGridSizer(0,2,5,0) for key,lbl,nDig in parms: labelLst.append(lbl.strip().strip(':').strip()) dspLst.append(nDig) if 'list' in str(type(data[key])): parmRef = G2G.G2CheckBox(G2frame.dataWindow,' '+lbl,data[key],1) parmSizer.Add(parmRef,0,wx.EXPAND) parmVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,data[key],0, nDig=nDig,typeHint=float,OnLeave=AfterChange) elemKeysLst.append([key,0]) refFlgElem.append([key,1]) else: parmSizer.Add(wx.StaticText(G2frame.dataWindow,label=' '+lbl), 0,wx.EXPAND) parmVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,data,key, typeHint=float,OnLeave=AfterChange) elemKeysLst.append([key]) refFlgElem.append(None) parmSizer.Add(parmVal,0,WACV) Info = {} for key in ('FreePrm1','FreePrm2','FreePrm3'): parmVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,Controls,key,typeHint=str, notBlank=False,OnLeave=SearchAllComments) parmSizer.Add(parmVal,1,wx.EXPAND) parmVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,data,key,typeHint=float) parmSizer.Add(parmVal,0,WACV) labelLst.append(Controls[key]) dspLst.append(None) elemKeysLst.append([key]) refFlgElem.append(None) mainSizer.Add(parmSizer,0) mainSizer.Add((0,5),0) if histName[:4] in ['SASD',]: rho = [0.,0.] anomrho = [0.,0.] mu = 0. subSizer = wx.FlexGridSizer(0,4,5,5) Substances = G2frame.GPXtree.GetItemPyData( G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Substances')) for Id,item in enumerate(data['Materials']): subSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Material: '),0,WACV) matsel = wx.ComboBox(G2frame.dataWindow,value=item['Name'],choices=list(Substances['Substances'].keys()), style=wx.CB_READONLY|wx.CB_DROPDOWN) Info[matsel.GetId()] = Id matsel.Bind(wx.EVT_COMBOBOX,OnMaterial) subSizer.Add(matsel,0,WACV) subSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Volume fraction: '),0,WACV) volfrac = G2G.ValidatedTxtCtrl(G2frame.dataWindow,item,'VolFrac', xmin=0.,xmax=1.,nDig=(10,3),typeHint=float,OnLeave=OnVolFrac) subSizer.Add(volfrac,0,WACV) try: material = Substances['Substances'][item['Name']] except KeyError: print('ERROR - missing substance: '+item['Name']) material = Substances['Substances']['vacuum'] mu += item['VolFrac']*material.get('XAbsorption',0.) rho[Id] = material['Scatt density'] anomrho[Id] = material.get('XAnom density',0.) data['Contrast'] = [(rho[1]-rho[0])**2,(anomrho[1]-anomrho[0])**2] mainSizer.Add(subSizer,0) conSizer = wx.BoxSizer(wx.HORIZONTAL) conSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Contrast: %10.2f '%(data['Contrast'][0])),0,WACV) conSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Anom. Contrast: %10.2f '%(data['Contrast'][1])),0,WACV) mut = mu*data['Thick'] conSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Transmission (calc): %10.3f '%(np.exp(-mut))),0,WACV) mainSizer.Add(conSizer,0) G2frame.dataWindow.SetSizer(mainSizer) G2frame.dataWindow.SetDataSize()
################################################################################ ##### Indexing Peaks ################################################################################
[docs]def UpdateIndexPeaksGrid(G2frame, data): '''respond to selection of PWDR Index Peak List data tree item. ''' bravaisSymb = ['Fm3m','Im3m','Pm3m','R3-H','P6/mmm','I4/mmm', 'P4/mmm','Fmmm','Immm','Ammm','Bmmm','Cmmm','Pmmm','C2/m','P2/m','C1','P1'] IndexId = G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Index Peak List') Inst = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Instrument Parameters'))[0] limitId = G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Limits') Limits = G2frame.GPXtree.GetItemPyData(limitId) def RefreshIndexPeaksGrid(event): r,c = event.GetRow(),event.GetCol() peaks = G2frame.IndexPeaksTable.GetData() if c == 2: peaks[r][c] = not peaks[r][c] G2frame.IndexPeaksTable.SetData(peaks) G2frame.indxPeaks.ForceRefresh() if 'PKS' in G2frame.GPXtree.GetItemText(G2frame.PatternId): G2plt.PlotPowderLines(G2frame) else: G2plt.PlotPatterns(G2frame,plotType='PWDR') def OnReload(event): peaks = [] sigs = [] Peaks = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Peak List')) for ip,peak in enumerate(Peaks['peaks']): dsp = G2lat.Pos2dsp(Inst,peak[0]) peaks.append([peak[0],peak[2],True,False,0,0,0,dsp,0.0]) #SS? try: sig = Peaks['sigDict']['pos'+str(ip)] except KeyError: sig = 0. sigs.append(sig) data = [peaks,sigs] G2frame.GPXtree.SetItemPyData(IndexId,data) UpdateIndexPeaksGrid(G2frame,data) def OnSave(event): pth = G2G.GetExportPath(G2frame) dlg = wx.FileDialog(G2frame, 'Choose Index peaks csv file', pth, '', 'indexing peaks file (*.csv)|*.csv',wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) try: if dlg.ShowModal() == wx.ID_OK: filename = dlg.GetPath() filename = os.path.splitext(filename)[0]+'.csv' File = open(filename,'w') names = 'h,k,l,position,intensity,d-Obs,d-calc\n' File.write(names) fmt = '%d,%d,%d,%.4f,%.1f,%.5f,%.5f\n' for refl in data[0]: if refl[3]: File.write(fmt%(refl[4],refl[5],refl[6],refl[0],refl[1],refl[7],refl[8])) File.close() finally: dlg.Destroy() def KeyEditPickGrid(event): colList = G2frame.indxPeaks.GetSelectedCols() data = G2frame.GPXtree.GetItemPyData(IndexId) if event.GetKeyCode() == wx.WXK_RETURN: event.Skip(True) elif event.GetKeyCode() == wx.WXK_CONTROL: event.Skip(True) elif event.GetKeyCode() == wx.WXK_SHIFT: event.Skip(True) elif colList: G2frame.indxPeaks.ClearSelection() key = event.GetKeyCode() for col in colList: if G2frame.IndexPeaksTable.GetColLabelValue(col) in ['use',]: if key == 89: #'Y' for row in range(G2frame.IndexPeaksTable.GetNumberRows()): data[0][row][col]=True elif key == 78: #'N' for row in range(G2frame.IndexPeaksTable.GetNumberRows()): data[0][row][col]=False elif key == 83: # 'S' for row in range(G2frame.IndexPeaksTable.GetNumberRows()): data[0][row][col] = not data[0][row][col] if 'PWD' in G2frame.GPXtree.GetItemText(G2frame.PatternId): G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.IndPeaksMenu) G2frame.Bind(wx.EVT_MENU, OnReload, id=G2G.wxID_INDXRELOAD) G2frame.Bind(wx.EVT_MENU, OnSave, id=G2G.wxID_INDEXSAVE) G2frame.dataWindow.IndexPeaks.Enable(False) G2frame.IndexPeaksTable = [] if len(data[0]): G2frame.dataWindow.IndexPeaks.Enable(True) Unit = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Unit Cells List')) if Unit: if len(Unit) == 4: #patch Unit.append({}) if len(Unit) == 5: #patch Unit.append({}) controls,bravais,cellist,dmin,ssopt,magcells = Unit if 'T' in Inst['Type'][0]: #TOF - use other limit! dmin = G2lat.Pos2dsp(Inst,Limits[1][0]) else: dmin = G2lat.Pos2dsp(Inst,Limits[1][1]) G2frame.HKL = [] if ssopt.get('Use',False): cell = controls[6:12] A = G2lat.cell2A(cell) ibrav = bravaisSymb.index(controls[5]) spc = controls[13] SGData = G2spc.SpcGroup(spc)[1] SSGData = G2spc.SSpcGroup(SGData,ssopt['ssSymb'])[1] Vec = ssopt['ModVec'] maxH = ssopt['maxH'] G2frame.HKL = G2pwd.getHKLMpeak(dmin,Inst,SGData,SSGData,Vec,maxH,A) G2frame.HKL = np.array(G2frame.HKL) data[0] = G2indx.IndexSSPeaks(data[0],G2frame.HKL)[1] else: #select cell from table - no SS for i,cell in enumerate(cellist): if cell[-2]: ibrav = cell[2] A = G2lat.cell2A(cell[3:9]) G2frame.HKL = G2lat.GenHBravais(dmin,ibrav,A) for hkl in G2frame.HKL: hkl.insert(4,G2lat.Dsp2pos(Inst,hkl[3])) G2frame.HKL = np.array(G2frame.HKL) data[0] = G2indx.IndexPeaks(data[0],G2frame.HKL)[1] break rowLabels = [] for i in range(len(data[0])): rowLabels.append(str(i+1)) colLabels = ['position','intensity','use','indexed','h','k','l','d-obs','d-calc'] Types = [wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_FLOAT+':10,1',]+2*[wg.GRID_VALUE_BOOL,]+ \ 3*[wg.GRID_VALUE_LONG,]+2*[wg.GRID_VALUE_FLOAT+':10,5',] if len(data[0]) and len(data[0][0]) > 9: colLabels = ['position','intensity','use','indexed','h','k','l','m','d-obs','d-calc'] Types = [wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_FLOAT+':10,1',]+2*[wg.GRID_VALUE_BOOL,]+ \ 4*[wg.GRID_VALUE_LONG,]+2*[wg.GRID_VALUE_FLOAT+':10,5',] G2frame.GPXtree.SetItemPyData(IndexId,data) G2frame.IndexPeaksTable = G2G.Table(data[0],rowLabels=rowLabels,colLabels=colLabels,types=Types) G2frame.dataWindow.currentGrids = [] G2frame.indxPeaks = G2G.GSGrid(parent=G2frame.dataWindow) G2frame.indxPeaks.SetTable(G2frame.IndexPeaksTable, True) G2frame.indxPeaks.SetScrollRate(10,10) XY = [] Sigs = [] for r in range(G2frame.indxPeaks.GetNumberRows()): for c in range(G2frame.indxPeaks.GetNumberCols()): if c == 2: G2frame.indxPeaks.SetReadOnly(r,c,isReadOnly=False) else: G2frame.indxPeaks.SetReadOnly(r,c,isReadOnly=True) if data[0][r][2] and data[0][r][3]: XY.append([data[0][r][-1],data[0][r][0]]) try: sig = data[1][r] except IndexError: sig = 0. Sigs.append(sig) G2frame.indxPeaks.Bind(wg.EVT_GRID_CELL_LEFT_CLICK, RefreshIndexPeaksGrid) G2frame.indxPeaks.Bind(wx.EVT_KEY_DOWN, KeyEditPickGrid) G2frame.indxPeaks.AutoSizeColumns(False) if len(XY): XY = np.array(XY) G2plt.PlotCalib(G2frame,Inst,XY,Sigs,newPlot=True) G2frame.dataWindow.ClearData() mainSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(G2frame.indxPeaks,0,wx.ALL|wx.EXPAND,1) G2frame.dataWindow.SetSizer(mainSizer) G2frame.dataWindow.SetDataSize()
################################################################################ ##### Unit cells ################################################################################
[docs]def UpdateUnitCellsGrid(G2frame, data): '''respond to selection of PWDR Unit Cells data tree item. ''' def SetLattice(controls): ibrav = bravaisSymb.index(controls[5]) if controls[5] in ['Fm3m','Im3m','Pm3m']: controls[7] = controls[8] = controls[6] controls[9] = controls[10] = controls[11] = 90. elif controls[5] in ['R3m','P6/mmm','I4/mmm','P4/mmm']: controls[7] = controls[6] controls[9] = controls[10] = controls[11] = 90. if controls[5] in ['R3-H','P6/mmm']: controls[11] = 120. elif controls[5] in ['Fmmm','Immm','Ammm','Bmmm','Cmmm','Pmmm']: controls[9] = controls[10] = controls[11] = 90. elif controls[5] in ['A2/m','C2/m','P2/m','I2/m']: controls[9] = controls[11] = 90. # b unique controls[12] = G2lat.calc_V(G2lat.cell2A(controls[6:12])) return ibrav def OnNcNo(event): controls[2] = NcNo.GetValue() def OnIfX20(event): G2frame.ifX20 = x20.GetValue() def OnBravais(event): Obj = event.GetEventObject() bravais[bravList.index(Obj.GetId())] = Obj.GetValue() # wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) def OnZeroVar(event): controls[0] = zeroVar.GetValue() def OnSSopt(event): if controls[5] in ['Fm3m','Im3m','Pm3m']: SSopt.SetValue(False) G2frame.ErrorDialog('Cubic lattice','Incommensurate superlattice not possible with a cubic lattice') return ssopt['Use'] = SSopt.GetValue() if 'ssSymb' not in ssopt: ssopt.update({'ssSymb':'(abg)','ModVec':[0.1,0.1,0.1],'maxH':1}) wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) def OnSelMG(event): ssopt['ssSymb'] = selMG.GetValue() Vec = ssopt['ModVec'] modS = G2spc.splitSSsym(ssopt['ssSymb'])[0] ssopt['ModVec'] = G2spc.SSGModCheck(Vec,modS)[0] print (' Selecting: '+controls[13]+ssopt['ssSymb']+ 'maxH:'+str(ssopt['maxH'])) OnHklShow(event) wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) def OnModVal(invalid,value,tc): OnHklShow(tc.event) def OnMoveMod(event): Obj = event.GetEventObject() ObjId = Obj.GetId() Id,valObj = Indx[ObjId] move = Obj.GetValue()*0.01 Obj.SetValue(0) value = min(0.98,max(-0.98,float(valObj.GetValue())+move)) valObj.SetValue('%.4f'%(value)) ssopt['ModVec'][Id] = value OnHklShow(event) def OnMaxMH(event): ssopt['maxH'] = int(maxMH.GetValue()) print (' Selecting: '+controls[13]+ssopt['ssSymb']+'maxH:'+str(ssopt['maxH'])) OnHklShow(event) def OnButton(xpos,ypos): modSym = ssopt['ssSymb'].split(')')[0]+')' if modSym in ['(a0g)','(a1/2g)']: ssopt['ModVec'][0] = xpos ssopt['ModVec'][2] = ypos elif modSym in ['(0bg)','(1/2bg)']: ssopt['ModVec'][1] = xpos ssopt['ModVec'][2] = ypos elif modSym in ['(ab0)','(ab1/2)']: ssopt['ModVec'][0] = xpos ssopt['ModVec'][1] = ypos vec = ssopt['ModVec'] print(' Trying: %s %s modulation vector = %.3f %.3f %.3f'%(controls[13],ssopt['ssSymb'],vec[0],vec[1],vec[2])) OnHklShow(None) wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) def OnFindOneMV(event): Peaks = np.copy(peaks[0]) print (' Trying: '+controls[13],ssopt['ssSymb']+' maxH: 1') dlg = wx.ProgressDialog('Elapsed time','Modulation vector search', style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE) try: ssopt['ModVec'],result = G2indx.findMV(Peaks,controls,ssopt,Inst,dlg) if len(result[0]) == 2: G2plt.PlotXYZ(G2frame,result[2],1./result[3],labelX='a',labelY='g', newPlot=True,Title='Modulation vector search',buttonHandler=OnButton) finally: dlg.Destroy() OnHklShow(event) wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) def OnFindMV(event): best = 1. bestSS = '' for ssSym in ssChoice: ssopt['ssSymb'] = ssSym Peaks = np.copy(peaks[0]) ssopt['ModVec'] = G2spc.SSGModCheck(ssopt['ModVec'],G2spc.splitSSsym(ssSym)[0],True)[0] print (' Trying: '+controls[13]+ssSym+' maxH: 1') ssopt['ModVec'],result = G2indx.findMV(Peaks,controls,ssopt,Inst,dlg=None) OnHklShow(event) if result[1] < best: bestSS = ssSym best = result[1] if bestSS != '': ssopt['ssSymb'] = bestSS ssopt['ModVec'],result = G2indx.findMV(Peaks,controls,ssopt,Inst,dlg=None) if len(result[0]) == 2: G2plt.PlotXYZ(G2frame,result[2],1./result[3],labelX='a',labelY='g', newPlot=True,Title='Modulation vector search') wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) def OnBravSel(event): brav = bravSel.GetString(bravSel.GetSelection()) controls[5] = brav controls[13] = SPGlist[brav][0] ssopt['Use'] = False OnHklShow(event) wx.CallLater(100,UpdateUnitCellsGrid,G2frame,data) def OnSpcSel(event): controls[13] = spcSel.GetString(spcSel.GetSelection()) ssopt['SGData'] = G2spc.SpcGroup(controls[13])[1] ssopt['Use'] = False G2frame.dataWindow.RefineCell.Enable(True) OnHklShow(event) wx.CallLater(100,UpdateUnitCellsGrid,G2frame,data) def SetCellValue(Obj,ObjId,value): if controls[5] in ['Fm3m','Im3m','Pm3m']: controls[6] = controls[7] = controls[8] = value controls[9] = controls[10] = controls[11] = 90.0 Obj.SetValue(controls[6]) elif controls[5] in ['R3-H','P6/mmm','I4/mmm','P4/mmm']: if ObjId == 0: controls[6] = controls[7] = value Obj.SetValue(controls[6]) else: controls[8] = value Obj.SetValue(controls[8]) controls[9] = controls[10] = controls[11] = 90.0 if controls[5] in ['R3-H','P6/mmm']: controls[11] = 120. elif controls[5] in ['Fmmm','Immm','Cmmm','Pmmm']: controls[6+ObjId] = value Obj.SetValue(controls[6+ObjId]) controls[9] = controls[10] = controls[11] = 90.0 elif controls[5] in ['I2/m','A2/m','C2/m','P2/m']: controls[9] = controls[11] = 90.0 if ObjId != 3: controls[6+ObjId] = value Obj.SetValue(controls[6+ObjId]) else: controls[10] = value Obj.SetValue(controls[10]) else: controls[6+ObjId] = value if ObjId < 3: Obj.SetValue(controls[6+ObjId]) else: Obj.SetValue(controls[6+ObjId]) controls[12] = G2lat.calc_V(G2lat.cell2A(controls[6:12])) volVal.SetValue("%.3f"%(controls[12])) def OnMoveCell(event): Obj = event.GetEventObject() ObjId = cellList.index(Obj.GetId()) valObj = valDict[Obj.GetId()] inc = float(shiftChoices[shiftSel.GetSelection()][:-1]) move = Obj.GetValue() # +1 or -1 Obj.SetValue(0) value = float(valObj.GetValue()) * (1. + move*inc/100.) SetCellValue(valObj,ObjId//2,value) OnHklShow(event) def OnExportCells(event): pth = G2G.GetExportPath(G2frame) dlg = wx.FileDialog(G2frame, 'Choose Indexing Result csv file', pth, '', 'indexing result file (*.csv)|*.csv',wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) try: if dlg.ShowModal() == wx.ID_OK: filename = dlg.GetPath() filename = os.path.splitext(filename)[0]+'.csv' File = open(filename,'w') names = 'M20,X20,Bravais,a,b,c,alpha,beta,gamma,volume\n' File.write(names) fmt = '%.2f,%d,%s,%.4f,%.4f,%.4f,%.2f,%.2f,%.2f,%.3f\n' for cell in cells: File.write(fmt%(cell[0],cell[1],bravaisSymb[cell[2]], cell[3],cell[4],cell[5], cell[6],cell[7],cell[8],cell[9])) File.close() finally: dlg.Destroy() def OnCellChange(invalid,value,tc): if invalid: return try: # fails when zero is updated SetCellValue(tc,Info[tc.GetId()],value) except: pass OnHklShow(tc.event) wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) def OnHklShow(event): PatternId = G2frame.PatternId peaks = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Index Peak List')) controls,bravais,cells,dminx,ssopt,magcells = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Unit Cells List')) # recompute dmin in case limits were changed Inst = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Instrument Parameters'))[0] Limits = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Limits'))[1] if 'T' in Inst['Type'][0]: dmin = G2lat.Pos2dsp(Inst,Limits[0]) else: dmin = G2lat.Pos2dsp(Inst,Limits[1]) cell = controls[6:12] A = G2lat.cell2A(cell) spc = controls[13] SGData = ssopt.get('SGData',G2spc.SpcGroup(spc)[1]) Symb = SGData['SpGrp'] M20 = X20 = 0. if ssopt.get('Use',False) and ssopt.get('ssSymb',''): SSGData = G2spc.SSpcGroup(SGData,ssopt['ssSymb'])[1] if SSGData is None: SSGData = G2spc.SSpcGroup(SGData,ssopt['ssSymb'][:-1])[1] #skip trailing 's' for mag. Symb = SSGData['SSpGrp'] Vec = ssopt['ModVec'] maxH = ssopt['maxH'] G2frame.HKL = G2pwd.getHKLMpeak(dmin,Inst,SGData,SSGData,Vec,maxH,A) if len(peaks[0]): peaks = [G2indx.IndexSSPeaks(peaks[0],G2frame.HKL)[1],peaks[1]] #keep esds from peak fit M20,X20 = G2indx.calc_M20SS(peaks[0],G2frame.HKL) else: G2frame.HKL = G2pwd.getHKLpeak(dmin,SGData,A,Inst) if len(peaks[0]): peaks = [G2indx.IndexPeaks(peaks[0],G2frame.HKL)[1],peaks[1]] #keep esds from peak fit M20,X20 = G2indx.calc_M20(peaks[0],G2frame.HKL) G2frame.HKL = np.array(G2frame.HKL) if len(G2frame.HKL): print (' new M20,X20: %.2f %d, fraction found: %.3f for %s' \ %(M20,X20,float(len(peaks[0]))/len(G2frame.HKL),Symb)) G2frame.GPXtree.SetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Index Peak List'),peaks) if 'PKS' in G2frame.GPXtree.GetItemText(G2frame.PatternId): G2plt.PlotPowderLines(G2frame) else: G2plt.PlotPatterns(G2frame) def OnSortCells(event): controls,bravais,cells,dminx,ssopt,magcells = G2frame.GPXtree.GetItemPyData(UnitCellsId) c = event.GetCol() if colLabels[c] == 'M20': cells = G2indx.sortM20(cells) elif colLabels[c] in ['X20','Bravais','a','b','c','alpha','beta','gamma','Volume']: if c == 1: c += 1 #X20 before Use cells = G2indx.sortCells(cells,c-1) #an extra column (Use) not in cells else: return data = [controls,bravais,cells,dmin,ssopt,magcells] G2frame.GPXtree.SetItemPyData(UnitCellsId,data) wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) def CopyUnitCell(event): controls,bravais,cells,dminx,ssopt,magcells = G2frame.GPXtree.GetItemPyData(UnitCellsId) controls = controls[:5]+10*[0.,] if len(cells): for Cell in cells: if Cell[-2]: break cell = Cell[2:10] controls[4] = 1 controls[5] = bravaisSymb[cell[0]] controls[6:13] = cell[1:8] controls[13] = spaceGroups[bravaisSymb.index(controls[5])] # G2frame.dataWindow.RefineCell.Enable(True) # set in UpdateUnitCellsGrid elif magcells: for phase in magcells: if phase['Use']: break SGData = phase['SGData'] controls[4] = 1 controls[5] = (SGData['SGLatt']+SGData['SGLaue']).replace('-','') if controls[5][1:] == 'm3': controls[5] += 'm' if 'P3' in controls[5] or 'P-3' in controls[5]: controls[5] = 'P6/mmm' if 'R' in controls[5]: controls[5] = 'R3-H' controls[6:13] = phase['Cell'] controls[13] = SGData['SpGrp'] ssopt['SGData'] = SGData data = [controls,bravais,cells,dminx,ssopt,magcells] G2frame.dataWindow.RunSubGroups.Enable(True) G2frame.GPXtree.SetItemPyData(UnitCellsId,data) OnHklShow(None) wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) def LoadUnitCell(event): '''Called in response to a Load Phase menu command''' UnitCellsId = G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Unit Cells List') data = G2frame.GPXtree.GetItemPyData(UnitCellsId) if len(data) < 5: data.append({}) controls,bravais,cells,dminx,ssopt = data[:5] magcells = [] #clear away old mag cells list (if any) controls = controls[:14]+[['0','0','0',' ',' ',' '],[],] data = controls,bravais,cells,dminx,ssopt,magcells G2frame.GPXtree.SetItemPyData(UnitCellsId,data) pId = G2gd.GetGPXtreeItemId(G2frame,G2frame.root, 'Phases') if not pId: return Phases = [] item, cookie = G2frame.GPXtree.GetFirstChild(pId) while item: pName = G2frame.GPXtree.GetItemText(item) Phase = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,pId,pName)) if not Phase['General']['SGData'].get('SGFixed',False): Phases.append(G2frame.GPXtree.GetItemText(item)) item, cookie = G2frame.GPXtree.GetNextChild(pId, cookie) if not len(Phases): wx.MessageBox('NB: Magnetic phases from mcif files are not suitable for this purpose,\n because of space group symbol - operators mismatches', caption='No usable space groups',style=wx.ICON_EXCLAMATION) return elif len(Phases) == 1: # don't ask questions when there is only 1 answer pNum = 0 else: pNum = G2G.ItemSelector(Phases,G2frame,'Select phase',header='Phase') if pNum is None: return Phase = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,pId,Phases[pNum])) Phase['magPhases'] = G2frame.GPXtree.GetItemText(G2frame.PatternId) #use as reference for recovering possible phases Cell = Phase['General']['Cell'] SGData.update(Phase['General']['SGData']) if 'SGGray' not in SGData: SGData['SGGray'] = False if Phase['General']['Type'] == 'nuclear' and 'MagSpGrp' in SGData: SGData.update(G2spc.SpcGroup(SGData['SpGrp'])[1]) G2frame.dataWindow.RunSubGroups.Enable(True) ssopt.update({'Use':False,'ssSymb':'(abg)','ModVec':[0.1,0.1,0.1],'maxH':1}) if 'SuperSg' in Phase['General'] or SGData.get('SGGray',False): ssopt.update({'SGData':SGData,'ssSymb':Phase['General']['SuperSg'],'ModVec':Phase['General']['SuperVec'][0],'Use':True,'maxH':1}) ssopt['ssSymb'] = ssopt['ssSymb'].replace(',','') ssSym = ssopt['ssSymb'] if SGData.get('SGGray',False): ssSym = ssSym[:-1] if ssSym not in G2spc.SSChoice(SGData): ssSym = ssSym.split(')')[0]+')000' ssopt['ssSymb'] = ssSym wx.MessageBox('Super space group '+SGData['SpGrp']+ssopt['ssSymb']+' not valid;\n It is set to '+ssSym, caption='Unusable super space group',style=wx.ICON_EXCLAMATION) G2frame.dataWindow.RunSubGroups.Enable(False) SpGrp = SGData['SpGrp'] if 'mono' in SGData['SGSys']: SpGrp = G2spc.fixMono(SpGrp) if SpGrp == None: wx.MessageBox('Monoclinic '+SGData['SpGrp']+' not usable here',caption='Unusable space group',style=wx.ICON_EXCLAMATION) return controls[13] = SpGrp controls[4] = 1 controls[5] = (SGData['SGLatt']+SGData['SGLaue']).replace('-','') if controls[5][1:] == 'm3': controls[5] += 'm' if controls[5] in ['P3','P3m1','P31m','P6/m']: controls[5] = 'P6/mmm' if controls[5] in ['P4/m',]: controls[5] = 'P4/mmm' if 'R' in controls[5]: controls[5] = 'R3-H' controls[6:13] = Cell[1:8] cx,ct,cs,cia = Phase['General']['AtomPtrs'] controls[15] = [atom[:cx+3] for atom in Phase['Atoms']] if 'N' in Inst['Type'][0]: if not ssopt.get('Use',False): G2frame.dataWindow.RunSubGroupsMag.Enable(True) data = controls,bravais,cells,dminx,ssopt,magcells G2frame.GPXtree.SetItemPyData(UnitCellsId,data) G2frame.dataWindow.RefineCell.Enable(True) OnHklShow(None) wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) def ImportUnitCell(event): controls,bravais,cells,dminx,ssopt = G2frame.GPXtree.GetItemPyData(UnitCellsId)[:5] reqrdr = G2frame.dataWindow.ReImportMenuId.get(event.GetId()) rdlist = G2frame.OnImportGeneric(reqrdr, G2frame.ImportPhaseReaderlist,'phase') if len(rdlist) == 0: return rd = rdlist[0] Cell = rd.Phase['General']['Cell'] SGData = rd.Phase['General']['SGData'] if '1 1' in SGData['SpGrp']: wx.MessageBox('Unusable space group',caption='Monoclinic '+SGData['SpGrp']+' not usable here',style=wx.ICON_EXCLAMATION) return controls[4] = 1 controls[5] = (SGData['SGLatt']+SGData['SGLaue']).replace('-','') if controls[5][1:] == 'm3': controls[5] += 'm' if 'P3' in controls[5] or 'P-3' in controls[5]: controls[5] = 'P6/mmm' if 'R' in controls[5]: controls[5] = 'R3-H' controls[6:13] = Cell[1:8] controls[13] = SGData['SpGrp'] # G2frame.GPXtree.SetItemPyData(UnitCellsId,[controls,bravais,cells,dmin,ssopt]) # G2frame.dataWindow.RunSubGroups.Enable(True) G2frame.dataWindow.RefineCell.Enable(True) OnHklShow(None) wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) def RefineCell(event): def cellPrint(ibrav,A): cell = G2lat.A2cell(A) Vol = G2lat.calc_V(A) if ibrav in ['Fm3m','Im3m','Pm3m']: print (" %s%10.6f" % ('a =',cell[0])) elif ibrav in ['R3-H','P6/mmm','I4/mmm','P4/mmm']: print (" %s%10.6f %s%10.6f %s%12.3f" % ('a =',cell[0],' c =',cell[2],' volume =',Vol)) elif ibrav in ['P4/mmm','Fmmm','Immm','Ammm','Bmmm','Cmmm','Pmmm']: print (" %s%10.6f %s%10.6f %s%10.6f %s%12.3f" % ('a =',cell[0],'b =',cell[1],'c =',cell[2],' volume =',Vol)) elif ibrav in ['I2/m','A2/m','C2/m','P2/m']: print (" %s%10.6f %s%10.6f %s%10.6f %s%8.3f %s%12.3f" % ('a =',cell[0],'b =',cell[1],'c =',cell[2],'beta =',cell[4],' volume =',Vol)) else: print (" %s%10.6f %s%10.6f %s%10.6f" % ('a =',cell[0],'b =',cell[1],'c =',cell[2])) print (" %s%8.3f %s%8.3f %s%8.3f %s%12.3f" % ('alpha =',cell[3],'beta =',cell[4],'gamma =',cell[5],' volume =',Vol)) def vecPrint(Vec): print (' %s %10.5f %10.5f %10.5f'%('Modulation vector:',Vec[0],Vec[1],Vec[2])) PatternId = G2frame.PatternId peaks = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Index Peak List')) print (' Refine cell') controls,bravais,cells,dminx,ssopt,magcells = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Unit Cells List')) cell = controls[6:12] A = G2lat.cell2A(cell) ibrav = bravaisSymb.index(controls[5]) # if not controls[13]: controls[13] = SPGlist[controls[5]][0] #don't know if this is needed? SGData = G2spc.SpcGroup(controls[13])[1] if 'T' in Inst['Type'][0]: if ssopt.get('Use',False): vecFlags = [True if x in ssopt['ssSymb'] else False for x in ['a','b','g']] SSGData = G2spc.SSpcGroup(SGData,ssopt['ssSymb'])[1] G2frame.HKL = G2pwd.getHKLMpeak(dmin,Inst,SGData,SSGData,ssopt['ModVec'],ssopt['maxH'],A) peaks = [G2indx.IndexSSPeaks(peaks[0],G2frame.HKL)[1],peaks[1]] #put peak fit esds back in peaks Lhkl,M20,X20,Aref,Vec,Zero = \ G2indx.refinePeaksTSS(peaks[0],difC,Inst,SGData,SSGData,ssopt['maxH'],ibrav,A,ssopt['ModVec'],vecFlags,controls[1],controls[0]) else: G2frame.HKL = G2pwd.getHKLpeak(dmin,SGData,A,Inst) peaks = [G2indx.IndexPeaks(peaks[0],G2frame.HKL)[1],peaks[1]] #put peak fit esds back in peaks Lhkl,M20,X20,Aref,Zero = G2indx.refinePeaksT(peaks[0],difC,ibrav,A,controls[1],controls[0]) else: if ssopt.get('Use',False): vecFlags = [True if x in ssopt['ssSymb'] else False for x in ['a','b','g']] SSGData = G2spc.SSpcGroup(SGData,ssopt['ssSymb'])[1] G2frame.HKL = G2pwd.getHKLMpeak(dmin,Inst,SGData,SSGData,ssopt['ModVec'],ssopt['maxH'],A) peaks = [G2indx.IndexSSPeaks(peaks[0],G2frame.HKL)[1],peaks[1]] #put peak fit esds back in peaks Lhkl,M20,X20,Aref,Vec,Zero = \ G2indx.refinePeaksZSS(peaks[0],wave,Inst,SGData,SSGData,ssopt['maxH'],ibrav,A,ssopt['ModVec'],vecFlags,controls[1],controls[0]) else: G2frame.HKL = G2pwd.getHKLpeak(dmin,SGData,A,Inst) peaks = [G2indx.IndexPeaks(peaks[0],G2frame.HKL)[1],peaks[1]] #put peak fit esds back in peaks Lhkl,M20,X20,Aref,Zero = G2indx.refinePeaksZ(peaks[0],wave,ibrav,A,controls[1],controls[0]) controls[1] = Zero controls[6:12] = G2lat.A2cell(Aref) controls[12] = G2lat.calc_V(Aref) cells = G2frame.GPXtree.GetItemPyData(UnitCellsId)[2] for cell in cells: cell[-2] = False cells.insert(0,[M20,X20,ibrav]+controls[6:13]+[True,False]) if ssopt.get('Use',False): ssopt['ModVec'] = Vec G2frame.HKL = G2pwd.getHKLMpeak(dmin,Inst,SGData,SSGData,ssopt['ModVec'],ssopt['maxH'],A) else: G2frame.HKL = G2pwd.getHKLpeak(dmin,SGData,A,Inst) G2frame.HKL = np.array(G2frame.HKL) data = [controls,bravais,cells,dmin,ssopt,magcells] G2frame.GPXtree.SetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Unit Cells List'),data) print (" %s%10.3f" % ('refinement M20 = ',M20)) print (' unindexed lines = %d'%X20) cellPrint(controls[5],Aref) ip = 4 if ssopt.get('Use',False): vecPrint(Vec) ip = 5 for hkl in G2frame.HKL: hkl[ip] = G2lat.Dsp2pos(Inst,hkl[ip-1])+controls[1] G2frame.HKL = np.array(G2frame.HKL) if 'PKS' in G2frame.GPXtree.GetItemText(G2frame.PatternId): G2plt.PlotPowderLines(G2frame) else: G2plt.PlotPatterns(G2frame) wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) def OnIndexPeaks(event): PatternId = G2frame.PatternId print ('Peak Indexing') keepcells = [] try: controls,bravais,cells,dminx,ssopt,magcells = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Unit Cells List')) for cell in cells: if cell[11]: cell[10] = False #clear selection flag on keepers keepcells.append(cell) except IndexError: pass except ValueError: G2frame.ErrorDialog('Error','Need to set controls in Unit Cell List first') return if ssopt.get('Use',False): G2frame.ErrorDialog('Super lattice error','Indexing not available for super lattices') return if True not in bravais: G2frame.ErrorDialog('Error','No Bravais lattices selected') return if not len(peaks[0]): G2frame.ErrorDialog('Error','Index Peak List is empty') return if len(peaks[0][0]) > 9: G2frame.ErrorDialog('Error','You need to reload Index Peaks List first') return G2frame.dataWindow.CopyCell.Enable(False) G2frame.dataWindow.RefineCell.Enable(False) dlg = wx.ProgressDialog("Generated reflections",'0 '+" cell search for "+bravaisNames[ibrav],101, # style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME|wx.PD_CAN_SKIP|wx.PD_CAN_ABORT) #desn't work in 32 bit versions style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME|wx.PD_CAN_ABORT) try: OK,dmin,newcells = G2indx.DoIndexPeaks(peaks[0],controls,bravais,dlg,G2frame.ifX20) finally: dlg.Destroy() cells = keepcells+newcells cells = G2indx.sortM20(cells) if OK: cells[0][10] = True #select best M20 data = [controls,bravais,cells,dmin,ssopt,magcells] G2frame.GPXtree.SetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Unit Cells List'),data) bestCell = cells[0] if bestCell[0] > 10.: G2frame.HKL = G2lat.GenHBravais(dmin,bestCell[2],G2lat.cell2A(bestCell[3:9])) for hkl in G2frame.HKL: hkl.insert(4,G2lat.Dsp2pos(Inst,hkl[3])+controls[1]) G2frame.HKL = np.array(G2frame.HKL) if 'PKS' in G2frame.GPXtree.GetItemText(G2frame.PatternId): G2plt.PlotPowderLines(G2frame) else: G2plt.PlotPatterns(G2frame) G2frame.dataWindow.CopyCell.Enable(True) G2frame.dataWindow.IndexPeaks.Enable(True) G2frame.dataWindow.MakeNewPhase.Enable(True) G2frame.ifX20 = True wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) def RefreshUnitCellsGrid(event): 'responds when "use" is pressed in index table; generates/plots reflections' data = G2frame.GPXtree.GetItemPyData(UnitCellsId) cells,dminx = data[2:4] r,c = event.GetRow(),event.GetCol() if cells: if event.GetEventObject().GetColLabelValue(c) == 'use': for i in range(len(cells)): cells[i][-2] = False UnitCellsTable.SetValue(i,c,False) UnitCellsTable.SetValue(r,c,True) gridDisplay.ForceRefresh() cells[r][-2] = True ibrav = cells[r][2] A = G2lat.cell2A(cells[r][3:9]) G2frame.HKL = G2lat.GenHBravais(dmin,ibrav,A) for hkl in G2frame.HKL: hkl.insert(4,G2lat.Dsp2pos(Inst,hkl[3])+controls[1]) G2frame.HKL = np.array(G2frame.HKL) if 'PKS' in G2frame.GPXtree.GetItemText(G2frame.PatternId): G2plt.PlotPowderLines(G2frame) else: G2plt.PlotPatterns(G2frame) elif event.GetEventObject().GetColLabelValue(c) == 'Keep': if UnitCellsTable.GetValue(r,c): UnitCellsTable.SetValue(r,c,False) cells[r][c] = False else: cells[r][c] = True UnitCellsTable.SetValue(r,c,True) gridDisplay.ForceRefresh() G2frame.GPXtree.SetItemPyData(UnitCellsId,data) KeyList = [] def ClearCurrentShowNext(): KeepShowNext(False) KeyList += [['j',ClearCurrentShowNext,'Show next Mag. Spc. Group, clear keep flag on current']] def KeepCurrentShowNext(): KeepShowNext(True) KeyList += [['k',KeepCurrentShowNext,'Show next Mag. Spc. Group, keep current']] def KeepShowNext(KeepCurrent=True): '''Show next "keep" item in Magnetic Space Group list, possibly resetting the keep flag for the current displayed cell ''' for i in range(len(magcells)): # find plotted setting if magcells[i]['Use']: break else: return # no Try is set if not KeepCurrent: # clear current magcells[i]['Keep'] = False MagCellsTable.SetValue(i,2,False) keeps = [j for j in range(i+1,len(magcells)) if magcells[j]['Keep']] if not keeps: if not KeepCurrent: magDisplay.ForceRefresh() return # no remaining Keep-flagged entries next = keeps[0] # update table magcells[i]['Use'] = False MagCellsTable.SetValue(i,1,False) magcells[next]['Use'] = True MagCellsTable.SetValue(next,1,True) # get SG info and plot SGData = magcells[next]['SGData'] A = G2lat.cell2A(magcells[next]['Cell'][:6]) G2frame.HKL = G2pwd.getHKLpeak(1.0,SGData,A,Inst) G2plt.PlotPatterns(G2frame,extraKeys=KeyList) magDisplay.ForceRefresh() # change Scroll to display new setting xscroll = G2frame.dataWindow.GetScrollPos(wx.HORIZONTAL) yscroll = magDisplay.CellToRect(next,1)[1]/G2frame.dataWindow.GetScrollPixelsPerUnit()[1] G2frame.dataWindow.Scroll(xscroll,yscroll) def RefreshMagCellsGrid(event): controls,bravais,cells,dminx,ssopt,magcells = G2frame.GPXtree.GetItemPyData(UnitCellsId) r,c = event.GetRow(),event.GetCol() rLab = magDisplay.GetRowLabelValue(r) br = baseList[r] phase = phaseDict[br] pname = '(%s) %s'%(rLab,phase['Name']) if magcells: if c == 0: mSGData = phase['SGData'] text,table = G2spc.SGPrint(mSGData,AddInv=True) if 'magAtms' in phase: msg = 'Magnetic space group information' text[0] = ' Magnetic Space Group: '+mSGData['MagSpGrp'] text[3] = ' The magnetic lattice point group is '+mSGData['MagPtGp'] OprNames,SpnFlp = G2spc.GenMagOps(mSGData) G2G.SGMagSpinBox(G2frame.dataWindow,msg,text,table,mSGData['SGCen'],OprNames, mSGData['SpnFlp'],False).Show() else: msg = 'Space Group Information' G2G.SGMessageBox(G2frame.dataWindow,msg,text,table).Show() elif c == 1: for i in range(len(magcells)): magcells[i]['Use'] = False for i in range(len(baseList)): MagCellsTable.SetValue(i,c,False) MagCellsTable.SetValue(r,c,True) magDisplay.ForceRefresh() phase['Use'] = True mSGData = phase['SGData'] A = G2lat.cell2A(phase['Cell'][:6]) G2frame.HKL = G2pwd.getHKLpeak(1.0,mSGData,A,Inst) G2plt.PlotPatterns(G2frame,extraKeys=KeyList) elif c == 2: if MagCellsTable.GetValue(r,c): MagCellsTable.SetValue(r,c,False) phase['Keep'] = False else: phase['Keep'] = True MagCellsTable.SetValue(r,c,True) magDisplay.ForceRefresh() elif c ==3: maxequiv = magcells[0].get('maxequiv',100) mSGData = phase['SGData'] Uvec = phase['Uvec'] Trans = phase['Trans'] ifMag = False if 'magAtms' in phase: ifMag = True allmom = phase.get('allmom',False) magAtms = phase.get('magAtms','') mAtoms = TestMagAtoms(phase,magAtms,SGData,Uvec,Trans,allmom,maxequiv) else: mAtoms = TestAtoms(phase,controls[15],SGData,Uvec,Trans,maxequiv) Atms = [] AtCods = [] atMxyz = [] for ia,atom in enumerate(mAtoms): atom[0] += '_%d'%ia SytSym,Mul,Nop,dupDir = G2spc.SytSym(atom[2:5],mSGData) Atms.append(atom[:2]+['',]+atom[2:5]) AtCods.append('1') if 'magAtms' in phase: MagSytSym = G2spc.MagSytSym(SytSym,dupDir,mSGData) CSI = G2spc.GetCSpqinel(mSGData['SpnFlp'],dupDir) atMxyz.append([MagSytSym,CSI[0]]) else: CSI = G2spc.GetCSxinel(SytSym) atMxyz.append([SytSym,CSI[0]]) G2phsG.UseMagAtomDialog(G2frame,pname,Atms,AtCods,atMxyz,ifMag=ifMag,ifOK=True).ShowModal() elif c in [4,5]: if 'altList' not in phase: return if c == 4: title = 'Conjugacy list for '+pname items = phase['altList'] elif c == 5: title = 'Super groups list for '+pname items = phase['supList'] if not items[0]: wx.MessageBox(pname+' is a maximal subgroup',caption='Super group is parent',style=wx.ICON_INFORMATION) return SubCellsDialog(G2frame,title,controls,SGData,items,phaseDict).ShowModal() data = [controls,bravais,cells,dminx,ssopt,magcells] G2frame.GPXtree.SetItemPyData(UnitCellsId,data) def OnRefreshKeep(event): controls,bravais,cells,dminx,ssopt,magcells = G2frame.GPXtree.GetItemPyData(UnitCellsId) c = event.GetCol() E,SGData = G2spc.SpcGroup(controls[13]) if c == 2: testAtoms = ['',]+list(set([atom[1] for atom in controls[15]])) ifMag = False maxequiv = magcells[0]['maxequiv'] maximal = False if 'magAtms' in magcells[0]: ifMag = True allmom = magcells[0]['allmom'] magAtms = magcells[0]['magAtms'] dlg = G2G.MultiDataDialog(G2frame,title='Keep options', prompts=['max unique','test for mag. atoms','all have moment','only maximal subgroups',], values=[maxequiv,'',allmom,False],limits=[[1,100],testAtoms,[True,False],[True,False]], formats=['%d','choice','bool','bool']) else: dlg = G2G.MultiDataDialog(G2frame,title='Keep options', prompts=['max unique','only maximal subgroups',], values=[maxequiv,False],limits=[[1,100],[True,False],], formats=['%d','bool',]) if dlg.ShowModal() == wx.ID_OK: if ifMag: maxequiv,atype,allmom,maximal = dlg.GetValues() magAtms = [atom for atom in controls[15] if atom[1] == atype] else: maxequiv,maximal = dlg.GetValues() dlg = wx.ProgressDialog('Setting Keep flags','Processing '+magcells[0]['Name'],len(magcells), style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME) for ip,phase in enumerate(magcells): dlg.Update(ip,newmsg='Processing '+phase['Name']) Uvec = phase['Uvec'] Trans = phase['Trans'] if ifMag: phase['nAtoms'] = len(TestMagAtoms(phase,magAtms,SGData,Uvec,Trans,allmom,maxequiv,maximal)) else: phase['nAtoms'] = len(TestAtoms(phase,controls[15],SGData,Uvec,Trans,maxequiv,maximal)) dlg.Destroy() data = controls,bravais,cells,dminx,ssopt,magcells G2frame.GPXtree.SetItemPyData(UnitCellsId,data) wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) def MakeNewPhase(event): PhaseName = '' dlg = wx.TextEntryDialog(None,'Enter a name for this phase','Phase Name Entry','New phase', style=wx.OK) try: if dlg.ShowModal() == wx.ID_OK: PhaseName = dlg.GetValue() cells = G2frame.GPXtree.GetItemPyData(UnitCellsId)[2] for Cell in cells: if Cell[-2]: break cell = Cell[2:10] sub = G2gd.FindPhaseItem(G2frame) sub = G2frame.GPXtree.AppendItem(parent=sub,text=PhaseName) E,SGData = G2spc.SpcGroup(controls[13]) G2frame.GPXtree.SetItemPyData(sub, \ G2obj.SetNewPhase(Name=PhaseName,SGData=SGData,cell=cell[1:],Super=ssopt)) G2frame.GetStatusBar().SetStatusText('Change space group from '+str(controls[13])+' if needed',1) finally: dlg.Destroy() def OnMagSel(event): Obj = event.GetEventObject() if Obj.GetValue(): SGData['SGSpin'] = [1,]*len(SGData['SGSpin']) GenSym,GenFlg,BNSsym = G2spc.GetGenSym(SGData) SGData['GenSym'] = GenSym SGData['GenFlg'] = GenFlg OprNames,SpnFlp = G2spc.GenMagOps(SGData) SGData['SpnFlp'] = SpnFlp SGData['MagSpGrp'] = G2spc.MagSGSym(SGData) else: del SGData['MagSpGrp'] ssopt['SGData'] = SGData OnHklShow(None) wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) def OnSpinOp(event): Obj = event.GetEventObject() isym = Indx[Obj.GetId()]+1 spCode = {'red':-1,'black':1} SGData['SGSpin'][isym] = spCode[Obj.GetValue()] G2spc.CheckSpin(isym,SGData) GenSym,GenFlg,BNSsym = G2spc.GetGenSym(SGData) SGData['GenSym'] = GenSym SGData['GenFlg'] = GenFlg OprNames,SpnFlp = G2spc.GenMagOps(SGData) SGData['SpnFlp'] = SpnFlp SGData['MagSpGrp'] = G2spc.MagSGSym(SGData) OnHklShow(None) def OnBNSlatt(event): Obj = event.GetEventObject() SGData.update(G2spc.SpcGroup(SGData['SpGrp'])[1]) BNSlatt = Obj.GetValue() if '_' in BNSlatt: SGData['BNSlattsym'] = [BNSlatt,BNSsym[BNSlatt]] else: SGData['BNSlattsym'] = [SGData['SGLatt'],[0.,0.,0.]] SGData['SGSpin'] = [1,]*len(SGData['SGSpin']) GenSym,GenFlg = G2spc.GetGenSym(SGData)[:2] SGData['GenSym'] = GenSym SGData['GenFlg'] = GenFlg SGData['MagSpGrp'] = G2spc.MagSGSym(SGData) G2spc.ApplyBNSlatt(SGData,SGData['BNSlattsym']) OprNames,SpnFlp = G2spc.GenMagOps(SGData) SGData['SpnFlp'] = SpnFlp OnHklShow(None) def OnShowSpins(event): msg = 'Magnetic space group information' text,table = G2spc.SGPrint(SGData,AddInv=True) text[0] = ' Magnetic Space Group: '+SGData['MagSpGrp'] text[3] = ' The magnetic lattice point group is '+SGData['MagPtGp'] G2G.SGMagSpinBox(G2frame.dataWindow,msg,text,table,SGData['SGCen'],OprNames, SGData['SpnFlp'],False).Show() def TransformUnitCell(event): Trans = np.eye(3) Uvec = np.zeros(3) Vvec = np.zeros(3) ifMag = False Type = 'nuclear' BNSlatt = '' E,SGData = G2spc.SpcGroup(controls[13]) phase = {'General':{'Name':'','Type':Type,'Cell':['',]+controls[6:13],'SGData':SGData}} dlg = G2phsG.TransformDialog(G2frame,phase,Trans,Uvec,Vvec,ifMag,BNSlatt) try: if dlg.ShowModal() == wx.ID_OK: newPhase,Trans,Uvec,Vvec,ifMag,ifConstr,Common = dlg.GetSelection() sgData = newPhase['General']['SGData'] controls[5] = sgData['SGLatt']+sgData['SGLaue'] controls[13] = sgData['SpGrp'] ssopt['SGData'] = sgData controls[6:13] = newPhase['General']['Cell'][1:8] else: return finally: dlg.Destroy() OnHklShow(None) wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) def OnLatSym(event): 'Run Bilbao PsuedoLattice cell search' # look up a space group matching Bravais lattice (should not matter which one) bravaisSPG = {'Fm3m':225,'Im3m':229,'Pm3m':221,'R3-H':146,'P6/mmm':191, 'I4/mmm':139,'P4/mmm':123,'Fmmm':69,'Immm':71, 'Cmmm':65,'Pmmm':47,'C2/m':12,'P2/m':10,'P1':2} pUCid = G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Unit Cells List') controls,bravais,cells,dminx,ssopt,magcells = G2frame.GPXtree.GetItemPyData(pUCid) sgNum = bravaisSPG.get(controls[5],0) if sgNum < 1: wx.MessageBox('Sorry, only standard cell settings are allowed, please transform axes',caption='Bilbao requires standard settings',style=wx.ICON_EXCLAMATION) return cell = controls[6:12] tolerance = 5. dlg = G2G.SingleFloatDialog(G2frame,'Tolerance', 'Enter angular tolerance for search',5.0,[.1,30.],"%.1f") if dlg.ShowModal() == wx.ID_OK: tolerance = dlg.GetValue() dlg.Destroy() else: dlg.Destroy() return import SUBGROUPS as kSUB wx.BeginBusyCursor() wx.MessageBox(''' For use of PSEUDOLATTICE, please cite: Bilbao Crystallographic Server I: Databases and crystallographic computing programs, M. I. Aroyo, J. M. Perez-Mato, C. Capillas, E. Kroumova, S. Ivantchev, G. Madariaga, A. Kirov & H. Wondratschek Z. Krist. 221, 1, 15-27 (2006). doi: https://doi.org/doi:10.1524/zkri.2006.221.1.15''', caption='Bilbao PSEUDOLATTICE',style=wx.ICON_INFORMATION) page = kSUB.subBilbaoCheckLattice(sgNum,cell,tolerance) wx.EndBusyCursor() if not page: return # while cells: cells.pop() # cells.clear() is much cleaner but not Py2 for i,(cell,mat) in enumerate(kSUB.parseBilbaoCheckLattice(page)): cells.append([]) cells[-1] += [mat,0,16] cells[-1] += cell cells[-1] += [G2lat.calc_V(G2lat.cell2A(cell)),False,False] G2frame.GPXtree.SetItemPyData(pUCid,data) G2frame.OnFileSave(event) wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) def OnRunSubs(event): import SUBGROUPS as kSUB G2frame.dataWindow.RunSubGroupsMag.Enable(False) pUCid = G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Unit Cells List') controls,bravais,cells,dminx,ssopt,magcells = G2frame.GPXtree.GetItemPyData(pUCid) E,SGData = G2spc.SpcGroup(controls[13]) Kx = [' ','0','1/2','-1/2','1/3','-1/3','2/3','1'] Ky = [' ','0','1/2','1/3','2/3','1'] Kz = [' ','0','1/2','3/2','1/3','2/3','1'] kvec = [['0','0','0'],[' ',' ',' '],[' ',' ',' ',' ']] dlg = G2G.MultiDataDialog(G2frame,title='SUBGROUPS options',prompts=[' k-vector 1',' k-vector 2',' k-vector 3', \ ' Use whole star',' Filter by','preserve axes','max unique'], values=kvec+[False,'',True,100], limits=[[Kx[1:],Ky[1:],Kz[1:]],[Kx,Ky,Kz],[Kx,Ky,Kz],[True,False],['',' Landau transition',' Only maximal subgroups',], [True,False],[1,100]], formats=[['choice','choice','choice'],['choice','choice','choice'],['choice','choice','choice'],'bool','choice', 'bool','%d',]) if dlg.ShowModal() == wx.ID_OK: magcells = [] newVals = dlg.GetValues() kvec[:9] = newVals[0]+newVals[1]+newVals[2]+[' ',] nkvec = kvec.index(' ') star = newVals[3] filterby = newVals[4] keepaxes = newVals[5]