Changeset 2516
- Timestamp:
- Nov 6, 2016 10:18:52 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASII.py
r2509 r2516 1007 1007 Found = False 1008 1008 il = 0 1009 if bank is None: # no bank was specified in the input file, is more than one present in file? 1010 banklist = set([]) 1011 for S in instLines: 1012 if S[0] == '#' and 'Bank' in S: 1013 banklist.add(int(S.split(':')[0].split()[1])) 1014 if len(banklist) > 1: # yes, the user must make a selection 1015 choices = [str(i) for i in banklist] 1016 bank = int(G2G.ItemSelector(choices,self.G2frame,multiple=False)) 1017 else: 1018 bank = 1 1019 rd.powderentry[2] = bank 1009 1020 while il < len(instLines): 1010 1021 S = instLines[il] … … 1098 1109 if ibanks == 1: # there is only one bank here, return it 1099 1110 rd.instbank = 1 1111 rd.powderentry[2] = 1 1100 1112 return Iparm 1101 if 'PNT' in hType: 1102 rd.instbank = bank 1103 elif ibanks != databanks: 1113 # if 'PNT' in hType: # not sure what this is about 1114 # rd.instbank = bank 1115 # elif ibanks != databanks or bank is None: 1116 if (ibanks != databanks and databanks != 1) or bank is None: 1104 1117 # number of banks in data and prm file not not agree, need a 1105 1118 # choice from a human here … … 1107 1120 for i in range(1,1+ibanks): 1108 1121 choices.append('Bank '+str(i)) 1109 bank = rd.BlockSelector(1122 bank = 1 + rd.BlockSelector( 1110 1123 choices, self, 1111 1124 title='Select an instrument parameter bank for '+ … … 1139 1152 1140 1153 :returns: a list of two dicts, the first containing instrument parameters 1141 and the second used for TO flookup tables for profile coeff.1154 and the second used for TOF lookup tables for profile coeff. 1142 1155 1143 1156 ''' -
trunk/GSASIIctrls.py
r2513 r2516 305 305 the :attr:`OnLeave` function. Defaults to ``{}`` 306 306 307 :param bool ASCIIonly: if set as True will remove unicode characters from 308 strings 309 307 310 :param (other): other optional keyword parameters for the 308 311 wx.TextCtrl widget such as size or style may be specified. … … 311 314 def __init__(self,parent,loc,key,nDig=None,notBlank=True,min=None,max=None, 312 315 OKcontrol=None,OnLeave=None,typeHint=None, 313 CIFinput=False, OnLeaveArgs={}, **kw):316 CIFinput=False, OnLeaveArgs={}, ASCIIonly=False, **kw): 314 317 # save passed values needed outside __init__ 315 318 self.result = loc … … 321 324 self.CIFinput = CIFinput 322 325 self.notBlank = notBlank 326 self.ASCIIonly = ASCIIonly 323 327 self.type = str 324 328 # initialization … … 429 433 wx.TextCtrl.SetValue(self,str(G2py3.FormatSigFigs(val)).rstrip('0')) 430 434 else: 431 if show: wx.TextCtrl.SetValue(self,str(val)) 435 if self.ASCIIonly: 436 s = '' 437 for c in val: 438 if ord(c) < 128: s += c 439 if val != s: 440 val = s 441 show = True 442 if show: 443 try: 444 wx.TextCtrl.SetValue(self,str(val)) 445 except: 446 wx.TextCtrl.SetValue(self,val) 432 447 self.ShowStringValidity() # test if valid input 433 448 return … … 1001 1016 def CallScrolledMultiEditor(parent,dictlst,elemlst,prelbl=[],postlbl=[], 1002 1017 title='Edit items',header='',size=(300,250), 1003 CopyButton=False, **kw):1018 CopyButton=False, ASCIIonly=False, **kw): 1004 1019 '''Shell routine to call a ScrolledMultiEditor dialog. See 1005 1020 :class:`ScrolledMultiEditor` for parameter definitions. … … 1011 1026 dlg = ScrolledMultiEditor(parent,dictlst,elemlst,prelbl,postlbl, 1012 1027 title,header,size, 1013 CopyButton, **kw)1028 CopyButton, ASCIIonly, **kw) 1014 1029 if dlg.ShowModal() == wx.ID_OK: 1015 1030 dlg.Destroy() … … 1059 1074 :param bool CopyButton: if True adds a small button that copies the 1060 1075 value for the current row to all fields below (default is False) 1076 1077 :param bool ASCIIonly: if set as True will remove unicode characters from 1078 strings 1061 1079 1062 1080 :param list minvals: optional list of minimum values for validation … … 1101 1119 def __init__(self,parent,dictlst,elemlst,prelbl=[],postlbl=[], 1102 1120 title='Edit items',header='',size=(300,250), 1103 CopyButton=False, 1121 CopyButton=False, ASCIIonly=False, 1104 1122 minvals=[],maxvals=[],sizevals=[], 1105 1123 checkdictlst=[], checkelemlst=[], checklabel=""): … … 1161 1179 subSizer.Add(but) 1162 1180 # create the validated TextCrtl, store it and add it to the sizer 1163 ctrl = ValidatedTxtCtrl(panel,d,k,OKcontrol=self.ControlOKButton, 1181 ctrl = ValidatedTxtCtrl(panel,d,k,OKcontrol=self.ControlOKButton,ASCIIonly=ASCIIonly, 1164 1182 **kargs) 1165 1183 self.ValidatedControlsList.append(ctrl) -
trunk/GSASIIgrid.py
r2512 r2516 65 65 ] = [wx.NewId() for item in range(10)] 66 66 67 [ wxID_ATOMSEDITADD, wxID_ATOMSEDITINSERT, wxID_ATOMSEDITDELETE, wxID_ATOMSREFINE,67 [ wxID_ATOMSEDITADD, wxID_ATOMSEDITINSERT, wxID_ATOMSEDITDELETE, 68 68 wxID_ATOMSMODIFY, wxID_ATOMSTRANSFORM, wxID_ATOMSVIEWADD, wxID_ATOMVIEWINSERT, 69 69 wxID_RELOADDRAWATOMS,wxID_ATOMSDISAGL,wxID_ATOMMOVE,wxID_MAKEMOLECULE, 70 70 wxID_ASSIGNATMS2RB,wxID_ATOMSPDISAGL, wxID_ISODISP,wxID_ADDHATOM,wxID_UPDATEHATOM, 71 71 wxID_WAVEVARY,wxID_ATOMSROTATE, wxID_ATOMSDENSITY, 72 ] = [wx.NewId() for item in range(20)] 72 wxID_ATOMSSETALL, wxID_ATOMSSETSEL, 73 ] = [wx.NewId() for item in range(21)] 73 74 74 75 [ wxID_DRAWATOMSTYLE, wxID_DRAWATOMLABEL, wxID_DRAWATOMCOLOR, wxID_DRAWATOMRESETCOLOR, … … 90 91 ] = [wx.NewId() for item in range(4)] 91 92 92 [ wxID_PAWLEYLOAD, wxID_PAWLEYESTIMATE, wxID_PAWLEYUPDATE, 93 ] = [wx.NewId() for item in range(3)] 93 [ wxID_PAWLEYLOAD, wxID_PAWLEYESTIMATE, wxID_PAWLEYUPDATE, wxID_PAWLEYSELALL, wxID_PAWLEYSELNONE, 94 wxID_PAWLEYSELTOGGLE, 95 ] = [wx.NewId() for item in range(6)] 94 96 95 97 [ wxID_IMCALIBRATE,wxID_IMRECALIBRATE,wxID_IMINTEGRATE, wxID_IMCLEARCALIB,wxID_IMRECALIBALL, … … 2229 2231 self.AtomsMenu.Append(menu=self.AtomEdit, title='Edit Atoms') 2230 2232 self.AtomsMenu.Append(menu=self.AtomCompute, title='Compute') 2233 submenu = wx.Menu() 2234 self.AtomEdit.AppendMenu(wx.ID_ANY, 'Atoms selection...', submenu, 2235 help='Set/Act on selected atoms') 2236 submenu.Append(wxID_ATOMSSETSEL, 2237 help='Set refinement flags for selected atoms', 2238 kind=wx.ITEM_NORMAL, 2239 text='Refine selected') 2240 submenu.Append(id=wxID_ATOMSMODIFY, kind=wx.ITEM_NORMAL,text='Modify parameters', 2241 help='Modify parameters values for all selected atoms') 2242 submenu.Append(id=wxID_ATOMSEDITINSERT, kind=wx.ITEM_NORMAL,text='Insert atom', 2243 help='Inserts an H atom before all selected atoms') 2244 submenu.Append(id=wxID_ADDHATOM, kind=wx.ITEM_NORMAL,text='Calc H atoms', 2245 help='Insert H atoms in expected bonding positions for selected atoms') 2246 submenu.Append(id=wxID_ATOMSEDITDELETE, kind=wx.ITEM_NORMAL,text='Delete atom', 2247 help='Delete selected atoms') 2248 submenu.Append(id=wxID_ATOMSTRANSFORM, kind=wx.ITEM_NORMAL,text='Transform atoms', 2249 help='Symmetry transform selected atoms') 2250 # self.AtomEdit.Append(id=wxID_ATOMSROTATE, kind=wx.ITEM_NORMAL,text='Rotate atoms', 2251 # help='Select atoms to rotate first') 2252 submenu.Append(wxID_ATOMSSETALL, 2253 help='Set refinement flags for all atoms', 2254 kind=wx.ITEM_NORMAL, 2255 text='Select All') 2256 2231 2257 self.AtomEdit.Append(id=wxID_ATOMSEDITADD, kind=wx.ITEM_NORMAL,text='Append atom', 2232 2258 help='Appended as an H atom') 2233 2259 self.AtomEdit.Append(id=wxID_ATOMSVIEWADD, kind=wx.ITEM_NORMAL,text='Append view point', 2234 2260 help='Appended as an H atom') 2235 self.AtomEdit.Append(id=wxID_ATOMSEDITINSERT, kind=wx.ITEM_NORMAL,text='Insert atom',2236 help='Select atom row to insert before; inserted as an H atom')2237 2261 self.AtomEdit.Append(id=wxID_ATOMVIEWINSERT, kind=wx.ITEM_NORMAL,text='Insert view point', 2238 2262 help='Select atom row to insert before; inserted as an H atom') 2239 self.AtomEdit.Append(id=wxID_ADDHATOM, kind=wx.ITEM_NORMAL,text='Insert H atoms',2240 help='Insert H atoms in standard positions bonded to selected atoms')2241 2263 self.AtomEdit.Append(id=wxID_UPDATEHATOM, kind=wx.ITEM_NORMAL,text='Update H atoms', 2242 2264 help='Update H atoms in standard positions') 2243 self.AtomEdit.Append(id=wxID_ATOMMOVE, kind=wx.ITEM_NORMAL,text='Move atom to view point', 2244 help='Select single atom to move') 2245 self.AtomEdit.Append(id=wxID_ATOMSEDITDELETE, kind=wx.ITEM_NORMAL,text='Delete atom', 2246 help='Select atoms to delete first') 2247 self.AtomEdit.Append(id=wxID_ATOMSREFINE, kind=wx.ITEM_NORMAL,text='Set atom refinement flags', 2248 help='Select atoms to refine first') 2249 self.AtomEdit.Append(id=wxID_ATOMSMODIFY, kind=wx.ITEM_NORMAL,text='Modify atom parameters', 2250 help='Select atoms to modify first') 2251 self.AtomEdit.Append(id=wxID_ATOMSTRANSFORM, kind=wx.ITEM_NORMAL,text='Transform atoms', 2252 help='Select atoms to transform first') 2253 # self.AtomEdit.Append(id=wxID_ATOMSROTATE, kind=wx.ITEM_NORMAL,text='Rotate atoms', 2254 # help='Select atoms to rotate first') 2265 self.AtomEdit.Append(id=wxID_ATOMMOVE, kind=wx.ITEM_NORMAL,text='Move selected atom to view point', 2266 help='Select a single atom to be moved to view point in plot') 2255 2267 self.AtomEdit.Append(id=wxID_MAKEMOLECULE, kind=wx.ITEM_NORMAL,text='Assemble molecule', 2256 help=' Assemble molecule from scatterd atom positions')2268 help='Select a single atom to assemble as a molecule from scattered atom positions') 2257 2269 self.AtomEdit.Append(id=wxID_RELOADDRAWATOMS, kind=wx.ITEM_NORMAL,text='Reload draw atoms', 2258 2270 help='Reload atom drawing list') … … 2412 2424 help='Estimate initial Pawley intensities') 2413 2425 self.PawleyEdit.Append(id=wxID_PAWLEYUPDATE, kind=wx.ITEM_NORMAL,text='Pawley update', 2414 help='Update negative Pawley intensities with -0.5*Fobs and turn off refinemnt') 2426 help='Update negative Pawley intensities with -0.5*Fobs and turn off refinement') 2427 self.PawleyEdit.Append(id=wxID_PAWLEYSELALL, kind=wx.ITEM_NORMAL,text='Select all', 2428 help='Select all reflections to be refined') 2429 self.PawleyEdit.Append(id=wxID_PAWLEYSELNONE, kind=wx.ITEM_NORMAL,text='Select none', 2430 help='Set flag for all reflections for no refinement') 2431 self.PawleyEdit.Append(id=wxID_PAWLEYSELTOGGLE, kind=wx.ITEM_NORMAL,text='Toggle Selection', 2432 help='Toggle Selection flag for all reflections to opposite setting') 2415 2433 self.PostfillDataMenu() 2416 2434 -
trunk/GSASIIphsGUI.py
r2512 r2516 1 #indx = Atoms.GetSelectedRows() 1 2 # -*- coding: utf-8 -*- 2 3 #GSASII - phase data display routines … … 856 857 except ValueError: 857 858 pass 858 pawlNegWt.SetValue("%.4f"%(generalData['Pawley neg wt'])) #reset in case of error 859 pawlNegWt.SetValue("%.4f"%(generalData['Pawley neg wt'])) #reset in case of error 859 860 860 861 pawleySizer = wx.BoxSizer(wx.HORIZONTAL) … … 1814 1815 rbAtmDict[id] += 'U' 1815 1816 # exclList will be 'x' or 'xu' if TLS used in RB 1816 Items = [G2gd.wxID_ATOMSEDITINSERT,G2gd.wxID_ATOMSEDITDELETE, G2gd.wxID_ATOMSREFINE,1817 Items = [G2gd.wxID_ATOMSEDITINSERT,G2gd.wxID_ATOMSEDITDELETE, 1817 1818 G2gd.wxID_ATOMSMODIFY,G2gd.wxID_ATOMSTRANSFORM,G2gd.wxID_MAKEMOLECULE, 1818 1819 G2gd.wxID_ATOMVIEWINSERT,G2gd.wxID_ATOMMOVE,G2gd.wxID_ADDHATOM] … … 1919 1920 1920 1921 def OnAtomInsert(event): 1921 indx = Atoms.GetSelectedRows() 1922 if indx: 1923 AtomInsert(indx[0],0,0,0) 1924 FillAtomsGrid(Atoms) 1925 event.StopPropagation() 1926 data['Drawing']['Atoms'] = [] 1927 UpdateDrawAtoms() 1928 G2plt.PlotStructure(G2frame,data) 1922 '''Inserts a new atom into list immediately before every selected atom 1923 ''' 1924 indx = GetSelectedAtoms() 1925 for a in reversed(sorted(indx)): 1926 AtomInsert(a,0,0,0) 1927 event.StopPropagation() 1928 FillAtomsGrid(Atoms) 1929 data['Drawing']['Atoms'] = [] 1930 UpdateDrawAtoms() 1931 G2plt.PlotStructure(G2frame,data) 1929 1932 1930 1933 def OnAtomViewInsert(event): … … 1937 1940 1938 1941 def OnHydAtomAdd(event): 1939 indx = Atoms.GetSelectedRows()1940 if indx:1941 DisAglCtls = {}1942 generalData = data['General']1943 if 'DisAglCtls' in generalData:1944 DisAglCtls = generalData['DisAglCtls']1945 if 'H' not in DisAglCtls['AtomTypes']:1946 DisAglCtls['AtomTypes'].append('H')1947 DisAglCtls['AngleRadii'].append(0.5)1948 DisAglCtls['BondRadii'].append(0.5)1949 dlg = G2gd.DisAglDialog(G2frame,DisAglCtls,generalData,Reset=False)1950 if dlg.ShowModal() == wx.ID_OK:1951 DisAglCtls = dlg.GetData()1952 else:1953 dlg.Destroy()1954 return1942 '''Adds H atoms to fill out coordination sphere for selected atoms 1943 ''' 1944 indx = GetSelectedAtoms() 1945 if not indx: return 1946 DisAglCtls = {} 1947 generalData = data['General'] 1948 if 'DisAglCtls' in generalData: 1949 DisAglCtls = generalData['DisAglCtls'] 1950 if 'H' not in DisAglCtls['AtomTypes']: 1951 DisAglCtls['AtomTypes'].append('H') 1952 DisAglCtls['AngleRadii'].append(0.5) 1953 DisAglCtls['BondRadii'].append(0.5) 1954 dlg = G2gd.DisAglDialog(G2frame,DisAglCtls,generalData,Reset=False) 1955 if dlg.ShowModal() == wx.ID_OK: 1956 DisAglCtls = dlg.GetData() 1957 else: 1955 1958 dlg.Destroy() 1956 generalData['DisAglCtls'] = DisAglCtls 1957 cx,ct,cs,cia = generalData['AtomPtrs'] 1958 atomData = data['Atoms'] 1959 AtNames = [atom[ct-1] for atom in atomData] 1960 AtLookUp = G2mth.FillAtomLookUp(atomData,cia+8) 1961 Neigh = [] 1962 AddHydIds = [] 1963 for ind in indx: 1964 atom = atomData[ind] 1965 if atom[ct] not in ['C','N','O']: 1966 continue 1967 neigh = [atom[ct-1],G2mth.FindNeighbors(data,atom[ct-1],AtNames),0] 1968 if len(neigh[1][0]) > 3 or (atom[ct] == 'O' and len(neigh[1][0]) > 1): 1969 continue 1970 nH = 1 #for O atom 1971 if atom[ct] in ['C','N']: 1972 nH = 4-len(neigh[1][0]) 1973 bonds = {item[0]:item[1:] for item in neigh[1][0]} 1974 nextName = '' 1975 if len(bonds) == 1: 1976 nextName = bonds.keys()[0] 1977 for bond in bonds: 1978 if 'C' in atom[ct]: 1979 if 'C' in bond and bonds[bond][0] < 1.42: 1980 nH -= 1 1981 break 1982 elif 'O' in bond and bonds[bond][0] < 1.3: 1983 nH -= 1 1984 break 1985 elif 'O' in atom[ct] and 'C' in bonds and bonds[bond][0] < 1.3: 1959 return 1960 dlg.Destroy() 1961 generalData['DisAglCtls'] = DisAglCtls 1962 cx,ct,cs,cia = generalData['AtomPtrs'] 1963 atomData = data['Atoms'] 1964 AtNames = [atom[ct-1] for atom in atomData] 1965 AtLookUp = G2mth.FillAtomLookUp(atomData,cia+8) 1966 Neigh = [] 1967 AddHydIds = [] 1968 for ind in indx: 1969 atom = atomData[ind] 1970 if atom[ct] not in ['C','N','O']: 1971 continue 1972 neigh = [atom[ct-1],G2mth.FindNeighbors(data,atom[ct-1],AtNames),0] 1973 if len(neigh[1][0]) > 3 or (atom[ct] == 'O' and len(neigh[1][0]) > 1): 1974 continue 1975 nH = 1 #for O atom 1976 if atom[ct] in ['C','N']: 1977 nH = 4-len(neigh[1][0]) 1978 bonds = {item[0]:item[1:] for item in neigh[1][0]} 1979 nextName = '' 1980 if len(bonds) == 1: 1981 nextName = bonds.keys()[0] 1982 for bond in bonds: 1983 if 'C' in atom[ct]: 1984 if 'C' in bond and bonds[bond][0] < 1.42: 1986 1985 nH -= 1 1987 1986 break 1988 nextneigh = [] 1989 if nextName: 1990 nextneigh = G2mth.FindNeighbors(data,nextName,AtNames,notName=neigh[0]) 1991 if nextneigh[0]: 1992 neigh[1][1].append(nextneigh[1][1][0]) 1993 neigh[2] = max(0,nH) #set expected no. H's needed 1994 if len(neigh[1][0]): 1995 AddHydIds.append(neigh[1][1]) 1996 Neigh.append(neigh) 1997 if Neigh: 1998 letters = ['A','B','C'] 1999 HydIds = {} 2000 mapError = False 2001 dlg = G2gd.AddHatomDialog(G2frame,Neigh,data) 2002 if dlg.ShowModal() == wx.ID_OK: 2003 Nat = len(atomData) 2004 Neigh = dlg.GetData() 2005 mapData = generalData['Map'] 2006 for ineigh,neigh in enumerate(Neigh): 2007 AddHydIds[ineigh].append(neigh[2]) 2008 loc = AtLookUp[AddHydIds[ineigh][0]]+1 2009 if 'O' in neigh[0] and (not len(mapData['rho']) or not 'delt-F' in mapData['MapType']): 2010 mapError = True 2011 continue 2012 Hxyz,HU = G2mth.AddHydrogens(AtLookUp,generalData,atomData,AddHydIds[ineigh]) 2013 for iX,X in enumerate(Hxyz): 2014 AtomInsert(loc+iX,X[0],X[1],X[2],'H','H%s'%(neigh[0][1:]+letters[iX])) 2015 data['Atoms'][loc+iX][cia+1] = HU[iX] 2016 Id = data['Atoms'][loc+iX][cia+8] 2017 HydIds[Id] = [iX,AddHydIds[ineigh]] 2018 Nat += 1 2019 AtLookUp = G2mth.FillAtomLookUp(atomData,cia+8) 2020 if mapError: 2021 G2frame.ErrorDialog('Add H atom error','Adding O-H atoms requires delt-F map') 2022 SetupGeneral() 2023 data['General']['HydIds'].update(HydIds) 2024 G2frame.dataFrame.AtomEdit.Enable(G2gd.wxID_UPDATEHATOM,True) 2025 data['Drawing']['Atoms'] = [] 2026 UpdateDrawAtoms() 2027 FillAtomsGrid(Atoms) 2028 dlg.Destroy() 2029 G2plt.PlotStructure(G2frame,data) 2030 else: 2031 wx.MessageBox('No candidates found',caption='Add H atom Error',style=wx.ICON_EXCLAMATION) 1987 elif 'O' in bond and bonds[bond][0] < 1.3: 1988 nH -= 1 1989 break 1990 elif 'O' in atom[ct] and 'C' in bonds and bonds[bond][0] < 1.3: 1991 nH -= 1 1992 break 1993 nextneigh = [] 1994 if nextName: 1995 nextneigh = G2mth.FindNeighbors(data,nextName,AtNames,notName=neigh[0]) 1996 if nextneigh[0]: 1997 neigh[1][1].append(nextneigh[1][1][0]) 1998 neigh[2] = max(0,nH) #set expected no. H's needed 1999 if len(neigh[1][0]): 2000 AddHydIds.append(neigh[1][1]) 2001 Neigh.append(neigh) 2002 if Neigh: 2003 letters = ['A','B','C'] 2004 HydIds = {} 2005 mapError = False 2006 dlg = G2gd.AddHatomDialog(G2frame,Neigh,data) 2007 if dlg.ShowModal() == wx.ID_OK: 2008 Nat = len(atomData) 2009 Neigh = dlg.GetData() 2010 mapData = generalData['Map'] 2011 for ineigh,neigh in enumerate(Neigh): 2012 AddHydIds[ineigh].append(neigh[2]) 2013 loc = AtLookUp[AddHydIds[ineigh][0]]+1 2014 if 'O' in neigh[0] and (not len(mapData['rho']) or not 'delt-F' in mapData['MapType']): 2015 mapError = True 2016 continue 2017 Hxyz,HU = G2mth.AddHydrogens(AtLookUp,generalData,atomData,AddHydIds[ineigh]) 2018 for iX,X in enumerate(Hxyz): 2019 AtomInsert(loc+iX,X[0],X[1],X[2],'H','H%s'%(neigh[0][1:]+letters[iX])) 2020 data['Atoms'][loc+iX][cia+1] = HU[iX] 2021 Id = data['Atoms'][loc+iX][cia+8] 2022 HydIds[Id] = [iX,AddHydIds[ineigh]] 2023 Nat += 1 2024 AtLookUp = G2mth.FillAtomLookUp(atomData,cia+8) 2025 if mapError: 2026 G2frame.ErrorDialog('Add H atom error','Adding O-H atoms requires delt-F map') 2027 SetupGeneral() 2028 data['General']['HydIds'].update(HydIds) 2029 G2frame.dataFrame.AtomEdit.Enable(G2gd.wxID_UPDATEHATOM,True) 2030 data['Drawing']['Atoms'] = [] 2031 UpdateDrawAtoms() 2032 FillAtomsGrid(Atoms) 2033 dlg.Destroy() 2034 G2plt.PlotStructure(G2frame,data) 2035 else: 2036 wx.MessageBox('No candidates found',caption='Add H atom Error',style=wx.ICON_EXCLAMATION) 2032 2037 2033 2038 def OnHydAtomUpdate(event): … … 2067 2072 cx = colLabels.index('x') 2068 2073 ci = colLabels.index('I/A') 2069 indx = Atoms.GetSelectedRows()2074 indx = GetSelectedAtoms() 2070 2075 if len(indx) != 1: 2071 2076 G2frame.ErrorDialog('Atom move error','Only one atom can be moved') … … 2155 2160 HydIds = data['General']['HydIds'] 2156 2161 ci = colLabels.index('I/A') 2157 indx = Atoms.GetSelectedRows()2162 indx = GetSelectedAtoms() 2158 2163 IDs = [] 2164 if not indx: return 2165 atomData = data['Atoms'] 2166 indx.reverse() 2167 for ind in indx: 2168 atom = atomData[ind] 2169 if atom[ci+8] in rbAtmDict: 2170 G2frame.dataFrame.SetStatusText('**** ERROR - atom is in a rigid body and can not be deleted ****') 2171 else: 2172 if atom[ci+8] in HydIds: #remove Hs from Hatom update dict 2173 del HydIds[atom[ci+8]] 2174 IDs.append(atom[ci+8]) 2175 del atomData[ind] 2176 if 'Atoms' in data['Drawing']: 2177 Atoms.ClearSelection() 2178 DrawAtomsDeleteByIDs(IDs) 2179 data['Drawing']['Atoms'] = [] 2180 UpdateDrawAtoms() 2181 wx.CallAfter(FillAtomsGrid,Atoms) 2182 G2plt.PlotStructure(G2frame,data) 2183 SetupGeneral() 2184 if not len(HydIds): 2185 G2frame.dataFrame.AtomEdit.Enable(G2gd.wxID_UPDATEHATOM,False) 2186 event.StopPropagation() 2187 2188 def GetSelectedAtoms(): 2189 '''Get all atoms that are selected by row or by having any cell selected. 2190 produce an error message if no atoms are selected. 2191 ''' 2192 indx = list(set([row for row,col in Atoms.GetSelectedCells()]+Atoms.GetSelectedRows())) 2159 2193 if indx: 2160 atomData = data['Atoms'] 2161 indx.reverse() 2162 for ind in indx: 2163 atom = atomData[ind] 2164 if atom[ci+8] in rbAtmDict: 2165 G2frame.dataFrame.SetStatusText('**** ERROR - atom is in a rigid body and can not be deleted ****') 2166 else: 2167 if atom[ci+8] in HydIds: #remove Hs from Hatom update dict 2168 del HydIds[atom[ci+8]] 2169 IDs.append(atom[ci+8]) 2170 del atomData[ind] 2171 if 'Atoms' in data['Drawing']: 2172 Atoms.ClearSelection() 2173 DrawAtomsDeleteByIDs(IDs) 2174 data['Drawing']['Atoms'] = [] 2175 UpdateDrawAtoms() 2176 wx.CallAfter(FillAtomsGrid,Atoms) 2177 G2plt.PlotStructure(G2frame,data) 2178 SetupGeneral() 2179 if not len(HydIds): 2180 G2frame.dataFrame.AtomEdit.Enable(G2gd.wxID_UPDATEHATOM,False) 2181 event.StopPropagation() 2182 2194 return indx 2195 else: 2196 G2G.G2MessageBox(G2frame,'Warning: no atoms were selected','Nothing selected') 2197 2183 2198 def AtomRefine(event): 2184 2199 colLabels = [Atoms.GetColLabelValue(c) for c in range(Atoms.GetNumberCols())] 2185 2200 c = colLabels.index('refine') 2186 indx = Atoms.GetSelectedRows() 2187 if indx: 2188 atomData = data['Atoms'] 2189 generalData = data['General'] 2190 Type = generalData['Type'] 2201 indx = GetSelectedAtoms() 2202 if not indx: return 2203 atomData = data['Atoms'] 2204 generalData = data['General'] 2205 Type = generalData['Type'] 2206 if Type in ['nuclear','macromolecular','faulted',]: 2191 2207 choice = ['F - site fraction','X - coordinates','U - thermal parameters'] 2192 dlg = wx.MultiChoiceDialog(G2frame,'Select','Refinement controls',choice) 2208 elif Type in ['magnetic',]: 2209 choice = ['F - site fraction','X - coordinates','U - thermal parameters','M - magnetic moment'] 2210 dlg = wx.MultiChoiceDialog(G2frame,'Select','Refinement controls',choice) 2211 if dlg.ShowModal() == wx.ID_OK: 2212 sel = dlg.GetSelections() 2213 parms = '' 2214 for x in sel: 2215 parms += choice[x][0] 2216 for r in indx: 2217 if not Atoms.IsReadOnly(r,c): 2218 atomData[r][c] = parms 2219 Atoms.ForceRefresh() 2220 dlg.Destroy() 2221 2222 def AtomModify(event): 2223 indx = GetSelectedAtoms() 2224 if not indx: return 2225 atomData = data['Atoms'] 2226 generalData = data['General'] 2227 colLabels = [Atoms.GetColLabelValue(c) for c in range(Atoms.GetNumberCols())] 2228 ci = colLabels.index('I/A') 2229 choices = ['Type','Name','x','y','z','frac','I/A','Uiso'] 2230 if generalData['Type'] == 'magnetic': 2231 choices += ['Mx','My','Mz',] 2232 dlg = wx.SingleChoiceDialog(G2frame,'Select','Atom parameter',choices) 2233 parm = '' 2234 if dlg.ShowModal() == wx.ID_OK: 2235 sel = dlg.GetSelection() 2236 parm = choices[sel] 2237 cid = colLabels.index(parm) 2238 dlg.Destroy() 2239 if parm in ['Type']: 2240 dlg = G2elemGUI.PickElement(G2frame) 2193 2241 if dlg.ShowModal() == wx.ID_OK: 2194 sel = dlg.GetSelections() 2195 parms = '' 2196 for x in sel: 2197 parms += choice[x][0] 2198 for r in indx: 2199 if not Atoms.IsReadOnly(r,c): 2200 atomData[r][c] = parms 2201 Atoms.ForceRefresh() 2242 if dlg.Elem not in ['None']: 2243 El = dlg.Elem.strip() 2244 for r in indx: 2245 if not Atoms.IsReadOnly(r,cid): 2246 atomData[r][cid] = El 2247 if len(El) in [2,4]: 2248 atomData[r][cid-1] = El[:2]+'%d'%(r+1) 2249 else: 2250 atomData[r][cid-1] = El[:1]+'%d'%(r+1) 2251 SetupGeneral() 2252 if 'Atoms' in data['Drawing']: 2253 for r in indx: 2254 ID = atomData[r][ci+8] 2255 DrawAtomsReplaceByID(data['Drawing'],ci+8,atomData[r],ID) 2256 FillAtomsGrid(Atoms) 2202 2257 dlg.Destroy() 2203 2204 def AtomModify(event): 2205 indx = Atoms.GetSelectedRows() 2206 if indx: 2207 atomData = data['Atoms'] 2208 generalData = data['General'] 2209 colLabels = [Atoms.GetColLabelValue(c) for c in range(Atoms.GetNumberCols())] 2210 ci = colLabels.index('I/A') 2211 choices = ['Type','Name','x','y','z','frac','I/A','Uiso'] 2212 if generalData['Type'] == 'magnetic': 2213 choices += ['Mx','My','Mz',] 2214 dlg = wx.SingleChoiceDialog(G2frame,'Select','Atom parameter',choices) 2215 parm = '' 2258 elif parm in ['Name',]: 2259 dlg = wx.MessageDialog(G2frame,'Do you really want to rename the selected atoms?','Rename', 2260 wx.YES_NO | wx.ICON_QUESTION) 2261 try: 2262 result = dlg.ShowModal() 2263 if result == wx.ID_YES: 2264 for r in indx: 2265 if not Atoms.IsReadOnly(r,cid+1): 2266 El = atomData[r][cid+1] 2267 if len(El) in [2,4]: 2268 atomData[r][cid] = El[:2]+'%d'%(r+1) 2269 else: 2270 atomData[r][cid] = El[:1]+'%d'%(r+1) 2271 FillAtomsGrid(Atoms) 2272 finally: 2273 dlg.Destroy() 2274 2275 elif parm in ['I/A']: 2276 choices = ['Isotropic','Anisotropic'] 2277 dlg = wx.SingleChoiceDialog(G2frame,'Select','Thermal parameter model',choices) 2216 2278 if dlg.ShowModal() == wx.ID_OK: 2217 2279 sel = dlg.GetSelection() 2218 parm = choices[sel] 2219 cid = colLabels.index(parm) 2280 parm = choices[sel][0] 2281 for r in indx: 2282 if not Atoms.IsReadOnly(r,cid): 2283 atomData[r][cid] = parm 2284 FillAtomsGrid(Atoms) 2220 2285 dlg.Destroy() 2221 if parm in ['Type']: 2222 dlg = G2elemGUI.PickElement(G2frame) 2223 if dlg.ShowModal() == wx.ID_OK: 2224 if dlg.Elem not in ['None']: 2225 El = dlg.Elem.strip() 2226 for r in indx: 2227 if not Atoms.IsReadOnly(r,cid): 2228 atomData[r][cid] = El 2229 if len(El) in [2,4]: 2230 atomData[r][cid-1] = El[:2]+'%d'%(r+1) 2231 else: 2232 atomData[r][cid-1] = El[:1]+'%d'%(r+1) 2233 SetupGeneral() 2234 if 'Atoms' in data['Drawing']: 2235 for r in indx: 2236 ID = atomData[r][ci+8] 2237 DrawAtomsReplaceByID(data['Drawing'],ci+8,atomData[r],ID) 2238 FillAtomsGrid(Atoms) 2239 dlg.Destroy() 2240 elif parm in ['Name',]: 2241 dlg = wx.MessageDialog(G2frame,'Do you really want to rename the selected atoms?','Rename', 2242 wx.YES_NO | wx.ICON_QUESTION) 2243 try: 2244 result = dlg.ShowModal() 2245 if result == wx.ID_YES: 2246 for r in indx: 2247 if not Atoms.IsReadOnly(r,cid+1): 2248 El = atomData[r][cid+1] 2249 if len(El) in [2,4]: 2250 atomData[r][cid] = El[:2]+'%d'%(r+1) 2251 else: 2252 atomData[r][cid] = El[:1]+'%d'%(r+1) 2253 FillAtomsGrid(Atoms) 2254 finally: 2255 dlg.Destroy() 2256 2257 elif parm in ['I/A']: 2258 choices = ['Isotropic','Anisotropic'] 2259 dlg = wx.SingleChoiceDialog(G2frame,'Select','Thermal parameter model',choices) 2260 if dlg.ShowModal() == wx.ID_OK: 2261 sel = dlg.GetSelection() 2262 parm = choices[sel][0] 2263 for r in indx: 2264 if not Atoms.IsReadOnly(r,cid): 2265 atomData[r][cid] = parm 2266 FillAtomsGrid(Atoms) 2267 dlg.Destroy() 2268 elif parm in ['frac','Uiso']: 2269 limits = [0.,1.] 2270 val = 1.0 2271 if parm in ['Uiso']: 2272 limits = [0.,0.25] 2273 val = 0.01 2274 dlg = G2G.SingleFloatDialog(G2frame,'New value','Enter new value for '+parm,val,limits) 2275 if dlg.ShowModal() == wx.ID_OK: 2276 parm = dlg.GetValue() 2277 for r in indx: 2278 if not Atoms.IsReadOnly(r,cid): 2279 atomData[r][cid] = parm 2280 SetupGeneral() 2281 FillAtomsGrid(Atoms) 2282 dlg.Destroy() 2283 elif parm in ['x','y','z']: 2284 limits = [-1.,1.] 2285 val = 0. 2286 dlg = G2G.SingleFloatDialog(G2frame,'Atom shift','Enter shift for '+parm,val,limits) 2287 if dlg.ShowModal() == wx.ID_OK: 2288 parm = dlg.GetValue() 2289 for r in indx: 2290 if not Atoms.IsReadOnly(r,cid): 2291 atomData[r][cid] += parm 2292 SetupGeneral() 2293 FillAtomsGrid(Atoms) 2294 dlg.Destroy() 2295 elif parm in ['Mx','My','Mz',]: 2296 limits = [-10.,10.] 2297 val = 0. 2298 dlg = G2G.SingleFloatDialog(G2frame,'Atom moment','Enter new value for '+parm,val,limits) 2299 if dlg.ShowModal() == wx.ID_OK: 2300 parm = dlg.GetValue() 2301 for r in indx: 2302 if not Atoms.IsReadOnly(r,cid): 2303 atomData[r][cid] = parm 2304 SetupGeneral() 2305 FillAtomsGrid(Atoms) 2306 dlg.Destroy() 2307 2308 data['Drawing']['Atoms'] = [] 2309 UpdateDrawAtoms() 2310 G2plt.PlotStructure(G2frame,data) 2286 elif parm in ['frac','Uiso']: 2287 limits = [0.,1.] 2288 val = 1.0 2289 if parm in ['Uiso']: 2290 limits = [0.,0.25] 2291 val = 0.01 2292 dlg = G2G.SingleFloatDialog(G2frame,'New value','Enter new value for '+parm,val,limits) 2293 if dlg.ShowModal() == wx.ID_OK: 2294 parm = dlg.GetValue() 2295 for r in indx: 2296 if not Atoms.IsReadOnly(r,cid): 2297 atomData[r][cid] = parm 2298 SetupGeneral() 2299 FillAtomsGrid(Atoms) 2300 dlg.Destroy() 2301 elif parm in ['x','y','z']: 2302 limits = [-1.,1.] 2303 val = 0. 2304 dlg = G2G.SingleFloatDialog(G2frame,'Atom shift','Enter shift for '+parm,val,limits) 2305 if dlg.ShowModal() == wx.ID_OK: 2306 parm = dlg.GetValue() 2307 for r in indx: 2308 if not Atoms.IsReadOnly(r,cid): 2309 atomData[r][cid] += parm 2310 SetupGeneral() 2311 FillAtomsGrid(Atoms) 2312 dlg.Destroy() 2313 elif parm in ['Mx','My','Mz',]: 2314 limits = [-10.,10.] 2315 val = 0. 2316 dlg = G2G.SingleFloatDialog(G2frame,'Atom moment','Enter new value for '+parm,val,limits) 2317 if dlg.ShowModal() == wx.ID_OK: 2318 parm = dlg.GetValue() 2319 for r in indx: 2320 if not Atoms.IsReadOnly(r,cid): 2321 atomData[r][cid] = parm 2322 SetupGeneral() 2323 FillAtomsGrid(Atoms) 2324 dlg.Destroy() 2325 2326 data['Drawing']['Atoms'] = [] 2327 UpdateDrawAtoms() 2328 G2plt.PlotStructure(G2frame,data) 2329 2330 def AtomTransform(event): 2331 indx = GetSelectedAtoms() 2332 if not indx: return 2333 generalData = data['General'] 2334 Amat,Bmat = G2lat.cell2AB(generalData['Cell'][1:7]) 2335 SpnFlp = generalData['SGData'].get('SpnFlp',[]) 2336 colLabels = [Atoms.GetColLabelValue(c) for c in range(Atoms.GetNumberCols())] 2337 cx = colLabels.index('x') 2338 cuia = colLabels.index('I/A') 2339 cuij = colLabels.index('U11') 2340 css = colLabels.index('site sym') 2341 cmx = 0 2342 if 'Mx' in colLabels: 2343 cmx = colLabels.index('Mx') 2344 atomData = data['Atoms'] 2345 SGData = generalData['SGData'] 2346 dlg = G2gd.SymOpDialog(G2frame,SGData,True,True) 2347 New = False 2348 try: 2349 if dlg.ShowModal() == wx.ID_OK: 2350 Inv,Cent,Opr,Cell,New,Force = dlg.GetSelection() 2351 Cell = np.array(Cell) 2352 cent = SGData['SGCen'][Cent] 2353 M,T = SGData['SGOps'][Opr] 2354 for ind in indx: 2355 XYZ = np.array(atomData[ind][cx:cx+3]) 2356 XYZ = np.inner(M,XYZ)+T 2357 if Inv: 2358 XYZ = -XYZ 2359 XYZ = XYZ+cent+Cell 2360 if Force: 2361 XYZ,cell = G2spc.MoveToUnitCell(XYZ) 2362 Cell += cell 2363 if New: 2364 atom = copy.copy(atomData[ind]) 2365 else: 2366 atom = atomData[ind] 2367 atom[cx:cx+3] = XYZ 2368 atom[css:css+2] = G2spc.SytSym(XYZ,SGData)[:2] 2369 OprNum = ((Opr+1)+100*Cent)*(1-2*Inv) 2370 if atom[cuia] == 'A': 2371 Uij = atom[cuij:cuij+6] 2372 U = G2spc.Uij2U(Uij) 2373 U = np.inner(np.inner(M,U),M) 2374 Uij = G2spc.U2Uij(U) 2375 atom[cuij:cuij+6] = Uij 2376 if cmx: 2377 opNum = G2spc.GetOpNum(OprNum,SGData) 2378 mom = np.inner(np.array(atom[cmx:cmx+3]),Bmat) 2379 atom[cmx:cmx+3] = np.inner(np.inner(mom,M),Amat)*nl.det(M)*SpnFlp[opNum-1] 2380 if New: 2381 atomData.append(atom) 2382 finally: 2383 dlg.Destroy() 2384 Atoms.ClearSelection() 2385 if New: 2386 FillAtomsGrid(Atoms) 2311 2387 else: 2312 print "select one or more rows of atoms" 2313 G2frame.ErrorDialog('Select atom',"select one or more atoms then redo") 2314 2315 def AtomTransform(event): 2316 indx = Atoms.GetSelectedRows() 2317 if indx: 2318 generalData = data['General'] 2319 Amat,Bmat = G2lat.cell2AB(generalData['Cell'][1:7]) 2320 SpnFlp = generalData['SGData'].get('SpnFlp',[]) 2321 colLabels = [Atoms.GetColLabelValue(c) for c in range(Atoms.GetNumberCols())] 2322 cx = colLabels.index('x') 2323 cuia = colLabels.index('I/A') 2324 cuij = colLabels.index('U11') 2325 css = colLabels.index('site sym') 2326 cmx = 0 2327 if 'Mx' in colLabels: 2328 cmx = colLabels.index('Mx') 2329 atomData = data['Atoms'] 2330 SGData = generalData['SGData'] 2331 dlg = G2gd.SymOpDialog(G2frame,SGData,True,True) 2332 New = False 2333 try: 2334 if dlg.ShowModal() == wx.ID_OK: 2335 Inv,Cent,Opr,Cell,New,Force = dlg.GetSelection() 2336 Cell = np.array(Cell) 2337 cent = SGData['SGCen'][Cent] 2338 M,T = SGData['SGOps'][Opr] 2339 for ind in indx: 2340 XYZ = np.array(atomData[ind][cx:cx+3]) 2341 XYZ = np.inner(M,XYZ)+T 2342 if Inv: 2343 XYZ = -XYZ 2344 XYZ = XYZ+cent+Cell 2345 if Force: 2346 XYZ,cell = G2spc.MoveToUnitCell(XYZ) 2347 Cell += cell 2348 if New: 2349 atom = copy.copy(atomData[ind]) 2350 else: 2351 atom = atomData[ind] 2352 atom[cx:cx+3] = XYZ 2353 atom[css:css+2] = G2spc.SytSym(XYZ,SGData)[:2] 2354 OprNum = ((Opr+1)+100*Cent)*(1-2*Inv) 2355 if atom[cuia] == 'A': 2356 Uij = atom[cuij:cuij+6] 2357 U = G2spc.Uij2U(Uij) 2358 U = np.inner(np.inner(M,U),M) 2359 Uij = G2spc.U2Uij(U) 2360 atom[cuij:cuij+6] = Uij 2361 if cmx: 2362 opNum = G2spc.GetOpNum(OprNum,SGData) 2363 mom = np.inner(np.array(atom[cmx:cmx+3]),Bmat) 2364 atom[cmx:cmx+3] = np.inner(np.inner(mom,M),Amat)*nl.det(M)*SpnFlp[opNum-1] 2365 if New: 2366 atomData.append(atom) 2367 finally: 2368 dlg.Destroy() 2369 Atoms.ClearSelection() 2370 if New: 2371 FillAtomsGrid(Atoms) 2372 else: 2373 Atoms.ForceRefresh() 2374 data['Drawing']['Atoms'] = [] 2375 UpdateDrawAtoms() 2376 G2plt.PlotStructure(G2frame,data) 2377 else: 2378 print "select one or more rows of atoms" 2379 G2frame.ErrorDialog('Select atom',"select one or more atoms then redo") 2388 Atoms.ForceRefresh() 2389 data['Drawing']['Atoms'] = [] 2390 UpdateDrawAtoms() 2391 G2plt.PlotStructure(G2frame,data) 2380 2392 2381 2393 def AtomRotate(event): 2382 ''' 2383 Currently not used - Bind commented out below 2394 '''Currently not used - Bind commented out below 2384 2395 ''' 2385 2396 Units = {'':np.zeros(3), … … 2388 2399 'yz':np.array([[0,i,j] for i in range(3) for j in range(3)])-np.array([1,1,0]), 2389 2400 'xyz':np.array([[i,j,k] for i in range(3) for j in range(3) for k in range(3)])-np.array([1,1,1])} 2390 indx = Atoms.GetSelectedRows()2401 indx = GetSelectedAtoms() 2391 2402 if indx: 2392 2403 generalData = data['General'] … … 2432 2443 2433 2444 def MakeMolecule(event): 2434 indx = Atoms.GetSelectedRows()2445 indx = GetSelectedAtoms() 2435 2446 Oxyz = [] 2436 2447 xyz = [] … … 2469 2480 print(msg) 2470 2481 G2G.G2MessageBox(G2frame.dataFrame,msg,'Density') 2471 2482 2483 def OnSetAll(event): 2484 'set refinement flags for all atoms in table' 2485 for row in range(Atoms.GetNumberRows()): 2486 Atoms.SelectRow(row,True) 2487 2472 2488 def OnDistAnglePrt(event): 2473 2489 'save distances and angles to a file' … … 2478 2494 def OnDistAngle(event,fp=None): 2479 2495 'Compute distances and angles' 2480 indx = Atoms.GetSelectedRows()2496 indx = GetSelectedAtoms() 2481 2497 Oxyz = [] 2482 2498 xyz = [] … … 7363 7379 wx.EndBusyCursor() 7364 7380 wx.CallAfter(FillPawleyReflectionsGrid) 7381 def OnPawleySelAll(event): 7382 refcol = [G2frame.PawleyRefl.GetColLabelValue(c) for c in range(G2frame.PawleyRefl.GetNumberCols())].index('refine') 7383 for r in range(G2frame.PawleyRefl.GetNumberRows()): 7384 G2frame.PawleyRefl.GetTable().SetValue(r,refcol,True) 7385 G2frame.PawleyRefl.ForceRefresh() 7386 def OnPawleySelNone(event): 7387 refcol = [G2frame.PawleyRefl.GetColLabelValue(c) for c in range(G2frame.PawleyRefl.GetNumberCols())].index('refine') 7388 for r in range(G2frame.PawleyRefl.GetNumberRows()): 7389 G2frame.PawleyRefl.GetTable().SetValue(r,refcol,False) 7390 G2frame.PawleyRefl.ForceRefresh() 7391 def OnPawleyToggle(event): 7392 raise Exception 7393 7394 refcol = [G2frame.PawleyRefl.GetColLabelValue(c) for c in range(G2frame.PawleyRefl.GetNumberCols())].index('refine') 7395 for r in range(G2frame.PawleyRefl.GetNumberRows()): 7396 G2frame.PawleyRefl.GetTable().SetValue( 7397 r,refcol, 7398 not G2frame.PawleyRefl.GetTable().GetValueAsBool(r,refcol)) 7399 G2frame.PawleyRefl.ForceRefresh() 7365 7400 7366 7401 ################################################################################ … … 7885 7920 # Atoms 7886 7921 FillSelectPageMenu(TabSelectionIdDict, G2frame.dataFrame.AtomsMenu) 7922 G2frame.dataFrame.Bind(wx.EVT_MENU, OnSetAll, id=G2gd.wxID_ATOMSSETALL) 7923 G2frame.dataFrame.Bind(wx.EVT_MENU, AtomRefine, id=G2gd.wxID_ATOMSSETSEL) 7924 G2frame.dataFrame.Bind(wx.EVT_MENU, AtomModify, id=G2gd.wxID_ATOMSMODIFY) 7925 G2frame.dataFrame.Bind(wx.EVT_MENU, OnAtomInsert, id=G2gd.wxID_ATOMSEDITINSERT) 7926 G2frame.dataFrame.Bind(wx.EVT_MENU, OnHydAtomAdd, id=G2gd.wxID_ADDHATOM) 7927 G2frame.dataFrame.Bind(wx.EVT_MENU, AtomDelete, id=G2gd.wxID_ATOMSEDITDELETE) 7928 G2frame.dataFrame.Bind(wx.EVT_MENU, AtomTransform, id=G2gd.wxID_ATOMSTRANSFORM) 7929 # G2frame.dataFrame.Bind(wx.EVT_MENU, AtomRotate, id=G2gd.wxID_ATOMSROTATE) 7930 7887 7931 G2frame.dataFrame.Bind(wx.EVT_MENU, OnAtomAdd, id=G2gd.wxID_ATOMSEDITADD) 7888 7932 G2frame.dataFrame.Bind(wx.EVT_MENU, OnAtomViewAdd, id=G2gd.wxID_ATOMSVIEWADD) 7889 G2frame.dataFrame.Bind(wx.EVT_MENU, OnAtomInsert, id=G2gd.wxID_ATOMSEDITINSERT)7890 7933 G2frame.dataFrame.Bind(wx.EVT_MENU, OnAtomViewInsert, id=G2gd.wxID_ATOMVIEWINSERT) 7891 G2frame.dataFrame.Bind(wx.EVT_MENU, OnHydAtomAdd, id=G2gd.wxID_ADDHATOM)7892 7934 G2frame.dataFrame.Bind(wx.EVT_MENU, OnHydAtomUpdate, id=G2gd.wxID_UPDATEHATOM) 7893 7935 G2frame.dataFrame.Bind(wx.EVT_MENU, OnAtomMove, id=G2gd.wxID_ATOMMOVE) 7894 G2frame.dataFrame.Bind(wx.EVT_MENU, AtomDelete, id=G2gd.wxID_ATOMSEDITDELETE)7895 G2frame.dataFrame.Bind(wx.EVT_MENU, AtomRefine, id=G2gd.wxID_ATOMSREFINE)7896 G2frame.dataFrame.Bind(wx.EVT_MENU, AtomModify, id=G2gd.wxID_ATOMSMODIFY)7897 G2frame.dataFrame.Bind(wx.EVT_MENU, AtomTransform, id=G2gd.wxID_ATOMSTRANSFORM)7898 # G2frame.dataFrame.Bind(wx.EVT_MENU, AtomRotate, id=G2gd.wxID_ATOMSROTATE)7899 7936 G2frame.dataFrame.Bind(wx.EVT_MENU, MakeMolecule, id=G2gd.wxID_MAKEMOLECULE) 7900 7937 G2frame.dataFrame.Bind(wx.EVT_MENU, OnReloadDrawAtoms, id=G2gd.wxID_RELOADDRAWATOMS) … … 7977 8014 G2frame.dataFrame.Bind(wx.EVT_MENU, OnPawleyEstimate, id=G2gd.wxID_PAWLEYESTIMATE) 7978 8015 G2frame.dataFrame.Bind(wx.EVT_MENU, OnPawleyUpdate, id=G2gd.wxID_PAWLEYUPDATE) 8016 G2frame.dataFrame.Bind(wx.EVT_MENU, OnPawleySelAll, id=G2gd.wxID_PAWLEYSELALL) 8017 G2frame.dataFrame.Bind(wx.EVT_MENU, OnPawleySelNone, id=G2gd.wxID_PAWLEYSELNONE) 8018 G2frame.dataFrame.Bind(wx.EVT_MENU, OnPawleyToggle, id=G2gd.wxID_PAWLEYSELTOGGLE) 7979 8019 7980 8020 # UpdatePhaseData execution starts here -
trunk/exports/G2export_CIF.py
r2449 r2516 34 34 import GSASIIIO as G2IO 35 35 import GSASIIgrid as G2gd 36 import GSASIIctrls as G2 ctrls36 import GSASIIctrls as G2G 37 37 import GSASIIstrIO as G2stIO 38 38 import GSASIImath as G2mth … … 56 56 self.CIFname = '' 57 57 58 def ValidateAscii(self,checklist): 59 '''Validate items as ASCII''' 60 msg = '' 61 for lbl,val in checklist: 62 if not all(ord(c) < 128 for c in val): 63 if msg: msg += '\n' 64 msg += lbl + " contains unicode characters: " + val 65 if msg: 66 G2G.G2MessageBox(self.G2frame, 67 'Error: CIFs can contain only ASCII characters. Please change item(s) below:\n\n'+msg, 68 'Unicode not valid for CIF') 69 return True 70 58 71 def _Exporter(self,event=None,phaseOnly=None,histOnly=None): 59 72 '''Basic code to export a CIF. Export can be full or simple, as set by … … 65 78 '''Write CIF data items to the file. Formats values as needed. 66 79 Also used without a value for loops, comments, loop headers, etc. 67 ''' 80 ''' 81 if all(ord(c) < 128 for c in value) and all(ord(c) < 128 for c in name): 82 pass 83 else: 84 print('Warning: unicode stripped from CIF item with name='+name+' value='+value) 85 s = '' 86 for c in name: 87 if ord(c) < 128: 88 s += c 89 else: 90 s += '.' 91 name = s 92 s = '' 93 for c in value: 94 if ord(c) < 128: 95 s += c 96 else: 97 s += '.' 98 value = s 99 print('...changed to name='+name+' value='+value) 100 68 101 if value: 69 102 if "\n" in value or len(value)> 70: … … 1303 1336 if instrname is None: 1304 1337 d['InstrName'] = '' 1305 return G2 ctrls.CallScrolledMultiEditor(1338 return G2G.CallScrolledMultiEditor( 1306 1339 self.G2frame,dictlist,keylist, 1307 1340 prelbl=range(1,len(dictlist)+1), … … 1309 1342 title='Instrument names', 1310 1343 header="Edit instrument names. Note that a non-blank\nname is required for all histograms", 1311 CopyButton=True )1344 CopyButton=True,ASCIIonly=True) 1312 1345 1313 1346 def EditRanges(event): … … 1591 1624 # make sure required information is present 1592 1625 self.CIFdate = dt.datetime.strftime(dt.datetime.now(),"%Y-%m-%dT%H:%M") 1593 if not self.CIFname: # Get a name for the CIF. If not defined, use the GPX name (save if that is needed).1626 if not self.CIFname: # Get a name for the CIF. If not defined, use the GPX name (save, if that is needed). 1594 1627 if not self.G2frame.GSASprojectfile: 1595 1628 self.G2frame.OnFileSaveas(None) … … 1599 1632 )[0] 1600 1633 self.CIFname = self.CIFname.replace(' ','') 1601 # get CIF author name -- required for full CIFs 1634 # replace non-ASCII characters in CIFname with dots 1635 s = '' 1636 for c in self.CIFname: 1637 if ord(c) < 128: 1638 s += c 1639 else: 1640 s += '.' 1641 self.CIFname = s 1642 # load saved CIF author name 1602 1643 try: 1603 1644 self.author = self.OverallParms['Controls'].get("Author",'').strip() 1604 1645 except KeyError: 1605 1646 pass 1606 if phaseOnly: 1647 #================================================================= 1648 # write quick CIFs 1649 #================================================================= 1650 if phaseOnly: #====Phase only CIF ================================ 1607 1651 print('Writing CIF output to file '+str(self.filename)) 1608 1652 self.OpenFile() 1609 1653 oneblock = True 1610 1654 self.quickmode = True 1611 #====Phase only CIF ====================================================1612 1655 self.Write(' ') 1613 1656 self.Write(70*'#') … … 1618 1661 self.CloseFile() 1619 1662 return 1620 elif histOnly: 1663 elif histOnly: #====Histogram only CIF ================================ 1621 1664 print('Writing CIF output to file '+str(self.filename)) 1622 1665 self.OpenFile() … … 1662 1705 return 1663 1706 #=============================================================================== 1664 # the normal export processstarts here1707 # the export process for a full CIF starts here 1665 1708 #=============================================================================== 1666 # get the project file name1667 self.CIFname = os.path.splitext(1668 os.path.split(self.G2frame.GSASprojectfile)[1]1669 )[0]1670 1709 self.InitExport(event) 1671 1710 # load all of the tree into a set of dicts … … 1688 1727 'Project does not contain any data or phases. Are they interconnected?') 1689 1728 return 1690 if not self.author: 1691 if not EditAuthor(): return 1692 # test for quick CIF mode or no data 1693 self.quickmode = False 1729 self.quickmode = False # full CIF 1694 1730 phasenam = None # include all phases 1695 # Project export: will this require a multiblock CIF?1731 # Will this require a multiblock CIF? 1696 1732 if len(self.Phases) > 1: 1697 1733 oneblock = False … … 1781 1817 instnam = histblk["Instrument Parameters"][0]['InstrName'] 1782 1818 break # ignore all but 1st data histogram 1783 # give the user a chance to edit all defaults 1819 # give the user a window to edit CIF contents 1820 if not self.author: 1821 if not EditAuthor(): return 1822 self.ValidateAscii([('Author name',self.author),]) # check for ASCII strings where needed, warn on problems 1784 1823 self.cifdefs = wx.Dialog( 1785 1824 self.G2frame, … … 1787 1826 EditCIFDefaults() 1788 1827 self.cifdefs.CenterOnParent() 1789 val = self.cifdefs.ShowModal() 1828 if self.cifdefs.ShowModal() != wx.ID_OK: 1829 self.cifdefs.Destroy() 1830 return 1831 while self.ValidateAscii([('Author name',self.author), 1832 ]): # validate a few things as ASCII 1833 if self.cifdefs.ShowModal() != wx.ID_OK: 1834 self.cifdefs.Destroy() 1835 return 1790 1836 self.cifdefs.Destroy() 1791 if val != wx.ID_OK:1792 return1793 1837 #====================================================================== 1794 1838 # Start writing the CIF - single block … … 1796 1840 print('Writing CIF output to file '+str(self.filename)+"...") 1797 1841 self.OpenFile() 1842 # test code *************************************************************************************************** 1843 WriteCIFitem('data_'+'\xc3\x81vila') 1844 # test code *************************************************************************************************** 1798 1845 if self.currentExportType == 'single' or self.currentExportType == 'powder': 1799 1846 #======Data only CIF (powder/xtal) ==================================== … … 2571 2618 if rng[0]: mn = hint(rng[0]) 2572 2619 if rng[1]: mx = hint(rng[1]) 2573 ent = G2 ctrls.ValidatedTxtCtrl(2620 ent = G2G.ValidatedTxtCtrl( 2574 2621 self,dct,item,typeHint=hint,min=mn,max=mx, 2575 CIFinput=True, 2622 CIFinput=True,ASCIIonly=True, 2576 2623 OKcontrol=self.ControlOKButton) 2577 2624 self.ValidatedControlsList.append(ent) 2578 2625 return ent 2579 2626 rw1 = rw.ResizeWidget(self) 2580 ent = G2 ctrls.ValidatedTxtCtrl(2627 ent = G2G.ValidatedTxtCtrl( 2581 2628 rw1,dct,item,size=(100, 20), 2582 2629 style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER, 2583 CIFinput=True, 2630 CIFinput=True,ASCIIonly=True, 2584 2631 OKcontrol=self.ControlOKButton) 2585 2632 self.ValidatedControlsList.append(ent) -
trunk/imports/G2pwd_BrukerRAW.py
r2408 r2516 63 63 self.comments = [] 64 64 self.repeat = True 65 self.powderentry[0] = filename 65 66 File = open(filename,'rb') 66 67 if 'ver. 1' in self.formatName: -
trunk/imports/G2pwd_CIF.py
r2347 r2516 341 341 self.powderentry[0] = filename 342 342 #self.powderentry[1] = pos # bank offset (N/A here) 343 self.powderentry[2] = 1 # xye file only has one bank343 #self.powderentry[2] = 1 # xye file only has one bank 344 344 self.idstring = os.path.basename(filename) + ': ' + blk 345 345 if cf[blk].get('_diffrn_radiation_probe'): -
trunk/imports/G2pwd_FP.py
r2465 r2516 146 146 self.powderentry[0] = filename 147 147 #self.powderentry[1] = pos # bank offset (N/A here) 148 self.powderentry[2] = 1 # xye file only has one bank148 #self.powderentry[2] = 1 # xye file only has one bank 149 149 self.idstring = ospath.basename(filename) 150 150 # scan comments for temperature -
trunk/imports/G2pwd_csv.py
r2463 r2516 98 98 self.powderentry[0] = filename 99 99 #self.powderentry[1] = pos # bank offset (N/A here) 100 self.powderentry[2] = 1 # xye file only has one bank100 #self.powderentry[2] = 1 # xye file only has one bank 101 101 self.idstring = ospath.basename(filename) 102 102 # scan comments for temperature -
trunk/imports/G2pwd_fxye.py
r2341 r2516 338 338 ParentFrame=ParentFrame, 339 339 title='Select Bank(s) to read from the list below', 340 size=(600, 100),340 size=(600,300), 341 341 header='Dataset Selector') 342 if len(self.selections) == 0: return False 342 if len(self.selections) == 0: 343 self.errors = 'No banks selected' 344 return False 343 345 selblk = self.selections[0] # select first in list 344 346 if len(self.selections) > 1: # prepare to loop through again -
trunk/imports/G2pwd_rigaku.py
r2456 r2516 122 122 ] 123 123 self.powderentry[0] = filename 124 self.powderentry[2] = 1 # xye file only has one bank124 #self.powderentry[2] = 1 # xye file only has one bank 125 125 self.idstring = os.path.basename(filename) 126 126 return True -
trunk/imports/G2pwd_xye.py
r2480 r2516 131 131 self.powderentry[0] = filename 132 132 #self.powderentry[1] = pos # bank offset (N/A here) 133 self.powderentry[2] = 1 # xye file only has one bank133 #self.powderentry[2] = 1 # xye file only has one bank 134 134 self.idstring = ospath.basename(filename) 135 135 # scan comments for temperature
Note: See TracChangeset
for help on using the changeset viewer.