Changeset 166
- Timestamp:
- Oct 26, 2010 3:09:48 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASII.py
r164 r166 1 1 #GSASII 2 2 3 import os 3 4 import os.path as ospath 4 5 import sys … … 214 215 self.PatternTree.Bind(wx.EVT_TREE_ITEM_EXPANDED, 215 216 self.OnPatternTreeItemExpanded, id=wxID_PATTERNTREE) 216 self.root = self.PatternTree.AddRoot( "Loaded Data")217 self.root = self.PatternTree.AddRoot('Loaded Data: ') 217 218 218 219 plotFrame = wx.Frame(None,-1,'GSASII Plots',size=wx.Size(700,600), \ … … 228 229 self.GSASprojectfile = '' 229 230 self.dirname = '' 231 self.undofile = '' 230 232 self.Offset = 0.0 231 233 self.Weight = False … … 918 920 self.dirname = dlg.GetDirectory() 919 921 G2IO.ProjFileOpen(self) 922 self.PatternTree.SetItemText(self.root,'Loaded Data: '+self.GSASprojectfile) 920 923 self.PatternTree.Expand(self.root) 921 924 self.HKL = [] … … 942 945 if result != wx.ID_CANCEL: 943 946 self.GSASprojectfile = '' 947 self.PatternTree.SetItemText(self.root,'Loaded Data: ') 944 948 self.PatternTree.DeleteChildren(self.root) 945 949 if self.HKL: self.HKL = [] … … 951 955 def OnFileSave(self, event): 952 956 if self.GSASprojectfile: 957 self.PatternTree.SetItemText(self.root,'Loaded Data: '+self.GSASprojectfile) 953 958 G2IO.ProjFileSave(self) 954 959 else: … … 963 968 if dlg.ShowModal() == wx.ID_OK: 964 969 self.GSASprojectfile = dlg.GetPath() 970 self.PatternTree.SetItemText(self.root,'Loaded Data: '+self.GSASprojectfile) 965 971 G2IO.ProjFileSave(self) 966 972 self.dirname = dlg.GetDirectory() … … 969 975 970 976 def ExitMain(self, event): 977 if self.undofile: 978 os.remove(self.undofile) 971 979 sys.exit() 972 980 … … 1117 1125 def DoUnDo(self): 1118 1126 print 'Undo last refinement' 1119 file = open( 'GSASII.save','rb')1127 file = open(self.undofile,'rb') 1120 1128 PatternId = self.PatternId 1121 1129 for item in ['Background','Instrument Parameters','Peak List']: … … 1132 1140 1133 1141 def SaveState(self): 1134 file = open('GSASII.save','wb') 1142 self.undofile = self.dirname+'\\GSASII.save' 1143 file = open(self.undofile,'wb') 1135 1144 PatternId = self.PatternId 1136 1145 for item in ['Background','Instrument Parameters','Peak List']: -
trunk/GSASIIElem.py
r155 r166 207 207 return MagFormFactors 208 208 209 def ScatFac(FormFac, S ThL):209 def ScatFac(FormFac, SQ): 210 210 """compute value of form factor 211 211 @param FormFac: dictionary defined in GetFormFactorCoeff 212 @param S ThL: sin-theta/lambda212 @param SQ: (sin-theta/lambda)**2 213 213 @return: f: real part of form factor 214 214 """ 215 f = FormFac['fc'] 216 fa = FormFac['fa'] 217 fb = FormFac['fb'] 218 for i in range(4): 219 t = -fb[i]*SThL*SThL 220 if t > -35.0: f += fa[i]*math.exp(t) 221 return f 215 fa = np.array(FormFac['fa']) 216 fb = np.array(FormFac['fb']) 217 t = -fb*SQ 218 return np.sum(fa*np.exp(t))+FormFac['fc'] 222 219 223 220 def FPcalc(Orbs, KEv): -
trunk/GSASIIIO.py
r164 r166 217 217 HKLmax = [max(h,HKLmax[0]),max(k,HKLmax[1]),max(l,HKLmax[2])] 218 218 FoMax = max(FoMax,Fosq) 219 HKLref.append([HKL,Fosq,sigFosq,Fcsq,0,0,0]) #room for Fc , Fcp, Fcpp & phase219 HKLref.append([HKL,Fosq,sigFosq,Fcsq,0,0,0]) #room for Fcp, Fcpp & phase 220 220 S = File.readline() 221 221 else: #dumb h,k,l,Fo,sigFo .hkl file … … 622 622 print 'load: ',datum[0] 623 623 624 #temporary fixes to old project files625 #fix to convert old style list arrays to numpy arrays626 if 'PWDR' in datum[0] and 'list' in str(type(datum[1][1][0])):627 X = datum[1][1]628 X = [np.array(X[0]),np.array(X[1]),np.array(X[2]),np.array(X[3]),np.array(X[4]),np.array(X[5])]629 datum[1] = [datum[1][0],X]630 print 'powder data converted to numpy arrays'631 #temporary fix to insert 'PWDR' in front of powder names632 if 'PKS' not in datum[0] and 'IMG' not in datum[0] and 'SNGL' not in datum[0]:633 if datum[0] not in ['Notebook','Controls','Phases'] and 'PWDR' not in datum[0]:634 datum[0] = 'PWDR '+datum[0]635 print 'add PWDR to powder names'636 #end of temporary fixes637 638 624 Id = self.PatternTree.AppendItem(parent=self.root,text=datum[0]) 639 self.PatternTree.SetItemPyData(Id,datum[1]) 625 if 'PWDR' in datum[0]: 626 self.PatternTree.SetItemPyData(Id,datum[1][:3]) #temp. trim off junk 627 else: 628 self.PatternTree.SetItemPyData(Id,datum[1]) 640 629 for datus in data[1:]: 641 630 print ' load: ',datus[0] 642 643 #temporary fix to add azimuthal angle to instrument parameters 644 if 'PWDR' in datum[0] and 'Instrument Parameters' in datus[0]: 645 if len(datus[1][0]) == 10 or len(datus[1][0]) == 12: 646 datus[1][0] += (0.0,) #add missing azimuthal angle 647 datus[1][1].append(0.0) 648 datus[1][2].append(0.0) 649 datus[1][3].append('Azimuth') 650 print 'add azimuth to instrument parameters' 651 #end of temporary fix 652 631 653 632 sub = self.PatternTree.AppendItem(Id,datus[0]) 654 633 self.PatternTree.SetItemPyData(sub,datus[1]) 655 656 #temporary fix to add Comments to powder data sets 657 if 'PWDR' in datum[0] and not G2gd.GetPatternTreeItemId(self,Id, 'Comments'): 658 print 'no comments - add comments' 659 sub = self.PatternTree.AppendItem(Id,'Comments') 660 self.PatternTree.SetItemPyData(sub,['no comments']) 661 #end of temporary fix 662 634 663 635 if 'IMG' in datum[0]: #retreive image default flag & data if set 664 636 Data = self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,Id,'Image Controls')) 665 637 if Data['setDefault']: 666 self.imageDefault = Data 667 #temporary fix to add masks 668 if not G2gd.GetPatternTreeItemId(self,Id, 'Masks'): 669 Imin,Imax = Data['range'][0] 670 Masks = {'Points':[],'Rings':[],'Arcs':[],'Polygons':[],'Thresholds':[(Imin,Imax),[Imin,Imax]]} 671 self.PatternTree.SetItemPyData(self.PatternTree.AppendItem(Id,text='Masks'),Masks) 672 #end of temporary fix 673 638 self.imageDefault = Data 674 639 file.close() 675 640 676 #temporary fix to add Notebook & Controls to project677 if not G2gd.GetPatternTreeItemId(self,self.root,'Notebook'):678 sub = self.PatternTree.AppendItem(parent=self.root,text='Notebook')679 self.PatternTree.SetItemPyData(sub,[''])680 sub = self.PatternTree.AppendItem(parent=self.root,text='Controls')681 self.PatternTree.SetItemPyData(sub,[0])682 print 'add Notebook and Controls to project'683 684 641 finally: 685 642 wx.EndBusyCursor() -
trunk/GSASIIlattice.py
r164 r166 154 154 return A,B 155 155 156 #def U2Uij(U):157 # #returns the UIJ vector U11,U22,U33,U12,U13,U23 from tensor U158 # return [U[0][0],U[1][1],U[2][2],U[0][1],U[0][2],U[1][2]]159 #160 #def Uij2U(Uij):161 # #returns the thermal motion tensor U from Uij as numpy array162 # return np.array([[Uij[0],Uij[3],Uij[4]],[Uij[3],Uij[1],Uij[5]],[Uij[4],Uij[5],Uij[2]]])163 #164 156 def Uij2betaij(Uij,G): 165 157 ''' … … 201 193 else: 202 194 return [0,0,0] 203 204 205 195 206 196 #Permutations and Combinations … … 243 233 rdsq = H[0]*H[0]*A[0]+H[1]*H[1]*A[1]+H[2]*H[2]*A[2]+H[0]*H[1]*A[3]+H[0]*H[2]*A[4]+H[1]*H[2]*A[5] 244 234 return rdsq 235 236 def calc_rDsq2(H,G): 237 return np.inner(H,np.inner(G,H)) 245 238 246 239 def calc_rDsqZ(H,A,Z,tth,lam): -
trunk/GSASIIphsGUI.py
r165 r166 20 20 VERY_LIGHT_GREY = wx.Colour(235,235,235) 21 21 WHITE = wx.Colour(255,255,255) 22 BLACK = wx.Colour(0,0,0) 22 23 23 24 # trig functions in degrees … … 145 146 generalData['Color'] = [] 146 147 generalData['Mydir'] = self.dirname 147 c olType = 1148 colSS = 7148 cx,ct,cs,cia = [3,1,7,9] 149 generalData['AtomPtrs'] = [cx,ct,cs,cia] 149 150 if generalData['Type'] =='macromolecular': 150 c olType = 4151 colSS = 10151 cx,ct,cs,cia = [6,4,10,12] 152 generalData['AtomPtrs'] = [cx,ct,cs,cia] 152 153 for atom in atomData: 153 atom[c olType] = atom[colType].lower().capitalize() #force to standard form154 if generalData['AtomTypes'].count(atom[c olType]):155 generalData['NoAtoms'][atom[c olType]] += atom[colSS-1]*float(atom[colSS+1])156 elif atom[c olType] != 'UNK':157 Info = G2elem.GetAtomInfo(atom[c olType])158 generalData['AtomTypes'].append(atom[c olType])154 atom[ct] = atom[ct].lower().capitalize() #force to standard form 155 if generalData['AtomTypes'].count(atom[ct]): 156 generalData['NoAtoms'][atom[ct]] += atom[cs-1]*float(atom[cs+1]) 157 elif atom[ct] != 'UNK': 158 Info = G2elem.GetAtomInfo(atom[ct]) 159 generalData['AtomTypes'].append(atom[ct]) 159 160 generalData['BondRadii'].append(Info['Drad']) 160 161 generalData['AngleRadii'].append(Info['Arad']) 161 162 generalData['vdWRadii'].append(Info['Vdrad']) 162 163 generalData['AtomMass'].append(Info['Mass']) 163 generalData['NoAtoms'][atom[c olType]] = atom[colSS-1]*float(atom[colSS+1])164 generalData['NoAtoms'][atom[ct]] = atom[cs-1]*float(atom[cs+1]) 164 165 generalData['Color'].append(Info['Color']) 165 166 166 167 def UpdateGeneral(): 167 168 168 ''' default dictionary structure for "General" phase item: (taken from GSASII.py)169 ''' default dictionary structure for phase data: (taken from GSASII.py) 169 170 'General':{ 170 171 'Name':PhaseName … … 172 173 'SGData':SGData 173 174 'Cell':[False,10.,10.,10.,90.,90.,90,1000.] 175 'AtomPtrs':[] 174 176 'Histogram list':['',] 175 177 'Pawley dmin':1.0} 176 'Atoms':[] 177 'Drawing':{} 178 }) 178 'Atoms':[] 179 'Drawing':{} 179 180 ''' 180 181 phaseTypes = ['nuclear','modulated','magnetic','macromolecular','Pawley'] … … 465 466 Types = [wg.GRID_VALUE_STRING,wg.GRID_VALUE_STRING,wg.GRID_VALUE_CHOICE+": ,X,XU,U,F,FX,FXU,FU", 466 467 wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_FLOAT+':10,4', #x,y,z,frac 467 wg.GRID_VALUE_STRING,wg.GRID_VALUE_STRING,wg.GRID_VALUE_CHOICE+":I,A", 468 wg.GRID_VALUE_FLOAT+':10,4', #Uiso 469 wg.GRID_VALUE_STRING,wg.GRID_VALUE_STRING,wg.GRID_VALUE_STRING, #Uij - placeholders 470 wg.GRID_VALUE_STRING,wg.GRID_VALUE_STRING,wg.GRID_VALUE_STRING] 468 wg.GRID_VALUE_STRING,wg.GRID_VALUE_STRING,wg.GRID_VALUE_CHOICE+":I,A",] 469 Types += 7*[wg.GRID_VALUE_FLOAT+':10,4',] 471 470 colLabels = ['Name','Type','refine','x','y','z','frac','site sym','mult','I/A','Uiso','U11','U22','U33','U12','U13','U23'] 472 471 if generalData['Type'] == 'magnetic': … … 485 484 486 485 def RefreshAtomGrid(event): 487 488 def chkUij(Uij,CSI):489 return Uij490 486 491 487 r,c = event.GetRow(),event.GetCol() … … 578 574 ss = colLabels.index('site sym') 579 575 for r in range(Atoms.GetNumberRows()): 576 ID = atomData[r][-1] 580 577 if parms != atomData[r][c] and Atoms.GetColLabelValue(c) == 'I/A': 581 578 if parms == 'A': #'I' --> 'A' 582 Uiso = atomData[r][us]579 Uiso = float(Atoms.GetCellValue(r,us)) 583 580 sytsym = atomData[r][ss] 584 581 CSI = G2spc.GetCSuinel(sytsym) 585 582 atomData[r][ui:ui+6] = Uiso*np.array(CSI[3]) 586 atomData[r][us] = '' 587 Atoms.SetCellRenderer(r,us,wg.GridCellStringRenderer()) 583 atomData[r][us] = 0.0 588 584 Atoms.SetCellStyle(r,us,VERY_LIGHT_GREY,True) 589 585 for i in range(6): 590 586 ci = ui+i 591 Atoms.SetCellRenderer(r,ci,wg.GridCellFloatRenderer(10,4))592 587 Atoms.SetCellStyle(r,ci,VERY_LIGHT_GREY,True) 593 588 if CSI[2][i]: … … 595 590 else: #'A' --> 'I' 596 591 Uij = atomData[r][ui:ui+6] 597 atomData[r][us] = (Uij[0]+Uij[1]+Uij[2])/3.0 598 atomData[r][ui:ui+6] = [0,0,0,0,0,0] 599 Atoms.SetCellRenderer(r,us,wg.GridCellFloatRenderer(10,4)) 592 Uiso = (Uij[0]+Uij[1]+Uij[2])/3.0 593 atomData[r][us] = Uiso 600 594 Atoms.SetCellStyle(r,us,WHITE,False) 601 595 for i in range(6): 602 596 ci = ui+i 603 Atoms.SetCellRenderer(r,ci,wg.GridCellStringRenderer()) 604 Atoms.SetCellValue(r,ci,'') 597 atomData[r][ci] = 0.0 605 598 Atoms.SetCellStyle(r,ci,VERY_LIGHT_GREY,True) 606 Atoms.SetCellValue(r,c,parms) 607 elif Atoms.GetColLabelValue(c) in ['Name']: 599 atomData[r][c] = parms 600 if 'Atoms' in data['Drawing']: 601 DrawAtomsReplaceByID(data['Drawing'],atomData[r],ID) 602 FillAtomsGrid() 603 604 def ChangeAtomCell(event): 605 606 def chkUij(Uij,CSI): 607 return Uij 608 609 r,c = event.GetRow(),event.GetCol() 610 if r >= 0 and c >= 0: 611 ID = atomData[r][-1] 612 if Atoms.GetColLabelValue(c) in ['x','y','z']: 613 ci = colLabels.index('x') 614 XYZ = atomData[r][ci:ci+3] 615 if None in XYZ: 616 XYZ = [0,0,0] 617 SScol = colLabels.index('site sym') 618 Mulcol = colLabels.index('mult') 619 E,SGData = G2spc.SpcGroup(generalData['SGData']['SpGrp']) 620 Sytsym,Mult = G2spc.SytSym(XYZ,SGData) 621 atomData[r][SScol] = Sytsym 622 atomData[r][Mulcol] = Mult 623 if atomData[r][colLabels.index('I/A')] == 'A': 624 ui = colLabels.index('U11') 625 CSI = G2spc.GetCSuinel(Sytsym) 626 atomData[r][ui:ui+6] = chkUij(atomData[r][ui:ui+6],Sytsym) 627 for i in range(6): 628 ci = i+ui 629 Atoms.SetCellStyle(r,ci,VERY_LIGHT_GREY,True) 630 if CSI[2][i]: 631 Atoms.SetCellStyle(r,ci,WHITE,False) 632 SetupGeneral() 633 elif Atoms.GetColLabelValue(c) == 'I/A': #note use of text color to make it vanish! 634 atomData[r][c] = Atoms.GetCellValue(r,c) 635 if atomData[r][c] == 'I': 636 Uij = atomData[r][c+2:c+8] 637 atomData[r][c+1] = (Uij[0]+Uij[1]+Uij[2])/3.0 638 Atoms.SetCellStyle(r,c+1,WHITE,False) 639 Atoms.SetCellTextColour(r,c+1,BLACK) 640 Atoms.SetCellRenderer(r,c+1,wg.GridCellFloatRenderer(10,4)) 641 for i in range(6): 642 ci = i+colLabels.index('U11') 643 Atoms.SetCellStyle(r,ci,VERY_LIGHT_GREY,True) 644 Atoms.SetCellTextColour(r,ci,VERY_LIGHT_GREY) 645 atomData[r][ci] = 0.0 646 else: 647 value = atomData[r][c+1] 648 CSI = G2spc.GetCSuinel(atomData[r][colLabels.index('site sym')]) 649 atomData[r][c+1] = 0.0 650 Atoms.SetCellRenderer(r,c+1,wg.GridCellFloatRenderer(10,4)) 651 Atoms.SetCellStyle(r,c+1,VERY_LIGHT_GREY,True) 652 Atoms.SetCellTextColour(r,c+1,VERY_LIGHT_GREY) 653 for i in range(6): 654 ci = i+colLabels.index('U11') 655 atomData[r][ci] = value*CSI[3][i] 656 Atoms.SetCellStyle(r,ci,VERY_LIGHT_GREY,True) 657 Atoms.SetCellTextColour(r,ci,BLACK) 658 Atoms.SetCellRenderer(r,ci,wg.GridCellFloatRenderer(10,4)) 659 if CSI[2][i]: 660 Atoms.SetCellStyle(r,ci,WHITE,False) 661 elif Atoms.GetColLabelValue(c) in ['U11','U22','U33','U12','U13','U23']: 662 value = atomData[r][c] 663 CSI = G2spc.GetCSuinel(atomData[r][colLabels.index('site sym')]) 664 iUij = CSI[0][c-colLabels.index('U11')] 665 for i in range(6): 666 if iUij == CSI[0][i]: 667 atomData[r][i+colLabels.index('U11')] = value*CSI[1][i] 668 if 'Atoms' in data['Drawing']: 669 DrawAtomsReplaceByID(data['Drawing'],atomData[r],ID) 670 671 def AtomTypeSelect(event): 672 r,c = event.GetRow(),event.GetCol() 673 if Atoms.GetColLabelValue(c) == 'Type': 674 PE = G2elem.PickElement(self) 675 if PE.ShowModal() == wx.ID_OK: 676 atomData[r][c] = PE.Elem.strip() 677 name = atomData[r][c] 678 if len(name) in [2,4]: 679 atomData[r][c-1] = name[:2]+'(%d)'%(r+1) 680 else: 681 atomData[r][c-1] = name[:1]+'(%d)'%(r+1) 682 PE.Destroy() 683 SetupGeneral() 684 FillAtomsGrid() 608 685 value = Atoms.GetCellValue(r,c) 609 686 atomData[r][c] = value 610 ID = [atomData[r][-1],]687 ID = atomData[r][-1] 611 688 if 'Atoms' in data['Drawing']: 612 DrawAtomsReplaceByIDs(data['Drawing'],atomData[r],ID) 613 elif Atoms.GetColLabelValue(c) in ['x','y','z']: 614 atomData[r][c] = float(Atoms.GetCellValue(r,c)) 615 ci = colLabels.index('x') 616 XYZ = atomData[r][ci:ci+3] 617 if None in XYZ: 618 XYZ = [0,0,0] 619 SScol = colLabels.index('site sym') 620 Mulcol = colLabels.index('mult') 621 E,SGData = G2spc.SpcGroup(generalData['SGData']['SpGrp']) 622 Sytsym,Mult = G2spc.SytSym(XYZ,SGData) 623 atomData[r][SScol] = Sytsym 624 atomData[r][Mulcol] = Mult 625 Atoms.SetCellValue(r,SScol,Sytsym) 626 Atoms.SetCellValue(r,Mulcol,str(Mult)) 627 if atomData[r][colLabels.index('I/A')] == 'A': 628 ui = colLabels.index('U11') 629 CSI = G2spc.GetCSuinel(Sytsym) 630 atomData[r][ui:ui+6] = chkUij(atomData[r][ui:ui+6],Sytsym) 631 for i in range(6): 632 ci = i+ui 633 Atoms.SetCellStyle(r,ci,VERY_LIGHT_GREY,True) 634 if CSI[2][i]: 635 Atoms.SetCellStyle(r,ci,WHITE,False) 636 SetupGeneral() 637 elif Atoms.GetColLabelValue(c) == 'I/A': 638 atomData[r][c] = Atoms.GetCellValue(r,c) 639 if atomData[r][c] == 'I': 640 Uij = atomData[r][c+2:c+8] 641 atomData[r][c+1] = (Uij[0]+Uij[1]+Uij[2])/3.0 642 atomData[r][c+2:c+8] = [0,0,0,0,0,0] 643 Atoms.SetCellRenderer(r,c+1,wg.GridCellFloatRenderer(10,4)) 644 Atoms.SetCellStyle(r,c+1,WHITE,False) 645 for i in range(6): 646 ci = i+colLabels.index('U11') 647 Atoms.SetCellRenderer(r,ci,wg.GridCellStringRenderer()) 648 Atoms.SetCellValue(r,ci,'') 649 Atoms.SetCellStyle(r,ci,VERY_LIGHT_GREY,True) 650 else: 651 Uiso = atomData[r][c+1] 652 atomData[r][c+1] = '' 653 CSI = G2spc.GetCSuinel(atomData[r][colLabels.index('site sym')]) 654 atomData[r][c+2:c+8] = Uiso*np.array(CSI[3]) 655 Atoms.SetCellRenderer(r,c+1,wg.GridCellStringRenderer()) 656 Atoms.SetCellStyle(r,c+1,VERY_LIGHT_GREY,True) 657 for i in range(6): 658 ci = i+colLabels.index('U11') 659 Atoms.SetCellRenderer(r,ci,wg.GridCellFloatRenderer(10,4)) 660 Atoms.SetCellStyle(r,ci,VERY_LIGHT_GREY,True) 661 if CSI[2][i]: 662 Atoms.SetCellStyle(r,ci,WHITE,False) 663 elif Atoms.GetColLabelValue(c) in ['U11','U22','U33','U12','U13','U23']: 664 atomData[r][c] = float(Atoms.GetCellValue(r,c)) 665 CSI = G2spc.GetCSuinel(atomData[r][colLabels.index('site sym')]) 666 iUij = CSI[0][c-colLabels.index('U11')] 667 for i in range(6): 668 if iUij == CSI[0][i]: 669 atomData[r][i+colLabels.index('U11')] = value*CSI[1][i] 670 elif Atoms.GetColLabelValue(c) == 'Uiso': 671 atomData[r][c] = float(Atoms.GetCellValue(r,c)) 672 data['Atoms'] = atomData 689 DrawAtomsReplaceByID(data['Drawing'],atomData[r],ID) 690 else: 691 event.Skip() 673 692 674 693 def RowSelect(event): … … 705 724 Atoms.SelectCol(c,True) 706 725 707 def AtomTypeSelect(event):708 r,c = event.GetRow(),event.GetCol()709 if Atoms.GetColLabelValue(c) == 'Type':710 PE = G2elem.PickElement(self)711 if PE.ShowModal() == wx.ID_OK:712 atomData[r][c] = PE.Elem.strip()713 name = atomData[r][c]714 if len(name) in [2,4]:715 atomData[r][c-1] = name[:2]+'(%d)'%(r+1)716 else:717 atomData[r][c-1] = name[:1]+'(%d)'%(r+1)718 PE.Destroy()719 SetupGeneral()720 FillAtomsGrid()721 value = Atoms.GetCellValue(r,c)722 atomData[r][c] = value723 ID = [atomData[r][-1],]724 if 'Atoms' in data['Drawing']:725 DrawAtomsReplaceByIDs(data['Drawing'],atomData[r],ID)726 else:727 event.Skip()728 729 726 table = [] 730 727 rowLabels = [] 731 728 for i,atom in enumerate(atomData): 732 if atom[colLabels.index('I/A')] == 'I': 733 table.append(atom[:colLabels.index('U11')]+['','','','','','']) 734 else: 735 table.append(atom) 729 table.append(atom) 736 730 rowLabels.append(str(i+1)) 737 731 atomTable = G2gd.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types) 738 732 Atoms.SetTable(atomTable, True) 739 Atoms.Bind(wg.EVT_GRID_CELL_CHANGE, RefreshAtomGrid) 733 Atoms.Bind(wg.EVT_GRID_CELL_CHANGE, ChangeAtomCell) 734 Atoms.Bind(wg.EVT_GRID_CELL_LEFT_DCLICK, AtomTypeSelect) 740 735 Atoms.Bind(wg.EVT_GRID_LABEL_LEFT_DCLICK, RefreshAtomGrid) 741 736 Atoms.Bind(wg.EVT_GRID_LABEL_LEFT_CLICK, RowSelect) 742 737 Atoms.Bind(wg.EVT_GRID_LABEL_RIGHT_CLICK, ChangeSelection) 743 Atoms.Bind(wg.EVT_GRID_SELECT_CELL, AtomTypeSelect)744 738 Atoms.SetMargins(0,0) 745 Atoms.AutoSizeColumns( True)739 Atoms.AutoSizeColumns(False) 746 740 colType = colLabels.index('Type') 747 741 colSS = colLabels.index('site sym') … … 754 748 for i in range(colU11,colU11+6): 755 749 Atoms.SetColAttr(i,attr) 750 for i in range(colU11-1,colU11+6): 751 Atoms.SetColSize(i,50) 756 752 for row in range(Atoms.GetNumberRows()): 753 Atoms.SetReadOnly(row,colType,True) 757 754 Atoms.SetReadOnly(row,colSS,True) #site sym 758 755 Atoms.SetReadOnly(row,colSS+1,True) #Mult 759 756 if Atoms.GetCellValue(row,colIA) == 'A': 757 Atoms.SetCellRenderer(row,colUiso,wg.GridCellStringRenderer()) 758 Atoms.SetCellValue(row,colUiso,'') 760 759 CSI = G2spc.GetCSuinel(atomData[row][colLabels.index('site sym')]) 761 Atoms.SetCellRenderer(row,colUiso,wg.GridCellStringRenderer())762 760 Atoms.SetCellStyle(row,colUiso,VERY_LIGHT_GREY,True) 763 Atoms.SetCellValue(row,colUiso,'')764 761 for i in range(6): 765 762 ci = colU11+i 766 Atoms.SetCellRenderer(row,ci,wg.GridCellFloatRenderer(10,4))767 763 if CSI[2][i]: 768 764 Atoms.SetCellStyle(row,ci,WHITE,False) 765 else: 766 for i in range(6): 767 Atoms.SetCellRenderer(row,colU11+i,wg.GridCellStringRenderer()) 768 Atoms.SetCellValue(row,colU11+i,'') 769 769 770 770 def OnAtomAdd(event): … … 931 931 'L','K','M','F','P','S','T','W','Y','V','M',' ',' ',' '] 932 932 defaultDrawing = {'viewPoint':[[0.5,0.5,0.5],[]],'showHydrogen':True,'backColor':[0,0,0],'depthFog':False, 933 'Zclip':50.0,'cameraPos':50.,'radiusFactor':0.85, 'showBadContacts':False,933 'Zclip':50.0,'cameraPos':50.,'radiusFactor':0.85, 934 934 'bondRadius':0.1,'ballScale':0.33,'vdwScale':0.67,'ellipseProb':50,'sizeH':0.50, 935 'unitCellBox':False,'showABC':True,'s howSymElem':False,'selectedAtoms':[],935 'unitCellBox':False,'showABC':True,'selectedAtoms':[], 936 936 'Rotation':[0.0,0.0,0.0,[]],'bondList':{},'testPos':[-.1,-.1,-.1]} 937 937 try: … … 964 964 'L','K','M','F','P','S','T','W','Y','V','M',' ',' ',' '] 965 965 generalData = data['General'] 966 SGData = generalData['SGData'] 966 967 if generalData['Type'] == 'nuclear': 967 968 if oldatom: 968 atomInfo = [atom[:2]+oldatom[2:]][0] 969 opr = oldatom[5] 970 if atom[9] == 'A': 971 X,U = G2spc.ApplyStringOps(opr,SGData,atom[3:6],atom[11:17]) 972 atomInfo = [atom[:2]+list(X)+oldatom[5:9]+atom[9:11]+list(U)+oldatom[17:]][0] 973 else: 974 X = G2spc.ApplyStringOps(opr,SGData,atom[3:6]) 975 atomInfo = [atom[:2]+list(X)+oldatom[5:9]+atom[9:]+[oldatom[-1]]][0] 969 976 else: 970 977 atomInfo = [atom[:2]+atom[3:6]+['1',]+['vdW balls',]+ … … 995 1002 drawingData['Atoms'].append(MakeDrawAtom(atom)) 996 1003 997 def DrawAtomsReplaceByIDs(drawingData,atom,IDs): 1004 def DrawAtomsReplaceByID(drawingData,atom,ID): 1005 IDs = [ID,] 998 1006 atomData = drawingData['Atoms'] 999 1007 indx = FindAtomIndexByIDs(atomData,IDs) … … 1121 1129 FindBonds() 1122 1130 elif drawAtoms.GetColLabelValue(c) == 'Color': 1123 dlg = wx.ColourDialog(self) 1131 color = atomData[r][c] 1132 colors = wx.ColourData() 1133 colors.SetChooseFull(True) 1134 colors.SetCustomColour(0,color) 1135 colors.SetColour(color) 1136 dlg = wx.ColourDialog(self,colors) 1137 dlg.GetColourData().SetCustomColour(0,color) 1124 1138 if dlg.ShowModal() == wx.ID_OK: 1125 1139 color = dlg.GetColourData().GetColour() … … 1240 1254 atomData = data['Drawing']['Atoms'] 1241 1255 cx,ct,cs = data['Drawing']['atomPtrs'] 1242 dlg = wx.ColourDialog(self) 1256 atmColors = [] 1257 atmTypes = [] 1258 for r in indx: 1259 if atomData[r][cs+2] not in atmColors: 1260 atmColors.append(atomData[r][cs+2]) 1261 atmTypes.append(atomData[r][ct]) 1262 if len(atmColors) > 16: 1263 break 1264 colors = wx.ColourData() 1265 colors.SetChooseFull(True) 1266 for i,color in enumerate(atmColors): 1267 colors.SetCustomColour(i,color) 1268 dlg = wx.ColourDialog(self,colors) 1243 1269 if dlg.ShowModal() == wx.ID_OK: 1244 color = dlg.GetColourData().GetColour() 1270 for i in range(len(atmColors)): 1271 atmColors[i] = dlg.GetColourData().GetCustomColour(i) 1272 colorDict = dict(zip(atmTypes,atmColors)) 1245 1273 for r in indx: 1274 color = colorDict[atomData[r][ct]] 1246 1275 atomData[r][cs+2] = color 1247 1276 attr = wg.GridCellAttr() #needs to be here - gets lost if outside loop! … … 1304 1333 atom = copy.copy(atomData[ind]) 1305 1334 atom[cx:cx+3] = XYZ 1306 atom[cx+3] = str(((Opr+1)+100*Cent)*(1-2*Inv))+'+'+ \ 1307 str(int(Cell[0]))+str(int(Cell[1]))+str(int(Cell[2])) 1335 atomOp = atom[cx+3] 1336 newOp = str(((Opr+1)+100*Cent)*(1-2*Inv))+'+'+ \ 1337 str(int(Cell[0]))+','+str(int(Cell[1]))+','+str(int(Cell[2])) 1338 atom[cx+3] = G2spc.StringOpsProd(atomOp,newOp,SGData) 1308 1339 if atom[cuia] == 'A': 1309 1340 Uij = atom[cuij:cuij+6] … … 1345 1376 atom = atomData[ind] 1346 1377 atom[cx:cx+3] = XYZ 1347 atom[cx+3] = str(((Opr+1)+100*Cent)*(1-2*Inv))+'+'+ \ 1348 str(int(Cell[0]))+str(int(Cell[1]))+str(int(Cell[2])) 1378 atomOp = atom[cx+3] 1379 newOp = str(((Opr+1)+100*Cent)*(1-2*Inv))+'+'+ \ 1380 str(int(Cell[0]))+','+str(int(Cell[1]))+','+str(int(Cell[2])) 1381 atom[cx+3] = G2spc.StringOpsProd(atomOp,newOp,SGData) 1349 1382 if atom[cuia] == 'A': 1350 1383 Uij = atom[cuij:cuij+6] … … 1390 1423 if 0 < dist <= data['Drawing']['radiusFactor']*sumR: 1391 1424 if noDuplicate(xyz,atomData): 1425 oprB = atomB[cx+3] 1426 C = xyz-xyzB 1427 newOp = '1+'+str(int(round(C[0])))+','+str(int(round(C[1])))+','+str(int(round(C[2]))) 1392 1428 newAtom = atomB[:] 1393 1429 newAtom[cx:cx+3] = xyz 1430 newAtom[cx+3] = G2spc.StringOpsProd(oprB,newOp,SGData) 1394 1431 atomData.append(newAtom) 1395 1432 data['Drawing']['Atoms'] = atomData … … 1417 1454 atom = copy.copy(atomData[ind]) 1418 1455 atom[cx:cx+3] = item[0] 1419 atom[cx+3] = str(item[2])+'+000' 1456 atom[cx+3] = str(item[2])+'+' \ 1457 +str(item[3][0])+','+str(item[3][1])+','+str(item[3][2]) 1420 1458 atom[cuij:cuij+6] = item[1] 1421 1459 Opp = G2spc.Opposite(item[0]) 1422 1460 for xyz in Opp: 1423 1461 if noDuplicate(xyz,atomData): 1462 cell = np.asarray(np.rint(xyz-atom[cx:cx+3]),dtype=np.int32) 1463 cell = '1'+'+'+ \ 1464 str(cell[0])+','+str(cell[1])+','+str(cell[2]) 1424 1465 atom[cx:cx+3] = xyz 1466 atom[cx+3] = G2spc.StringOpsProd(cell,atom[cx+3],SGData) 1425 1467 atomData.append(atom[:]) 1426 1468 else: … … 1429 1471 atom = copy.copy(atomData[ind]) 1430 1472 atom[cx:cx+3] = item[0] 1431 atom[cx+3] = str(item[1])+'+000' 1473 atom[cx+3] = str(item[1])+'+' \ 1474 +str(item[2][0])+','+str(item[2][1])+','+str(item[2][2]) 1432 1475 Opp = G2spc.Opposite(item[0]) 1433 1476 for xyz in Opp: 1434 1477 if noDuplicate(xyz,atomData): 1478 cell = np.asarray(np.rint(xyz-atom[cx:cx+3]),dtype=np.int32) 1479 cell = '1'+'+'+ \ 1480 str(cell[0])+','+str(cell[1])+','+str(cell[2]) 1435 1481 atom[cx:cx+3] = xyz 1482 atom[cx+3] = G2spc.StringOpsProd(cell,atom[cx+3],SGData) 1436 1483 atomData.append(atom[:]) 1437 1484 data['Drawing']['Atoms'] = atomData … … 1613 1660 G2plt.PlotStructure(self,data) 1614 1661 1615 def OnShowBadContacts(event):1616 drawingData['showBadContacts'] = showBadContacts.GetValue()1617 1618 def OnShowSymElem(event):1619 drawingData['showSymElem'] = showSymElem.GetValue()1620 1621 1662 def OnShowHyd(event): 1622 1663 drawingData['showHydrogen'] = showHydrogen.GetValue() … … 1703 1744 mainSizer.Add((5,5),0) 1704 1745 1705 flexSizer = wx.FlexGridSizer( 6,2,5,0)1746 flexSizer = wx.FlexGridSizer(5,2,5,0) 1706 1747 flexSizer.Add(wx.StaticText(dataDisplay,-1,'View Point: '),0,wx.ALIGN_CENTER_VERTICAL) 1707 1748 VP = drawingData['viewPoint'][0] … … 1720 1761 unitCellBox.SetValue(drawingData['unitCellBox']) 1721 1762 flexSizer.Add(unitCellBox,0,wx.ALIGN_CENTER_VERTICAL) 1722 1723 showBadContacts = wx.CheckBox(dataDisplay,-1,label='Show bad contacts?')1724 showBadContacts.Bind(wx.EVT_CHECKBOX, OnShowBadContacts)1725 showBadContacts.SetValue(drawingData['showBadContacts'])1726 flexSizer.Add(showBadContacts,0,wx.ALIGN_CENTER_VERTICAL)1727 1728 showSymElem = wx.CheckBox(dataDisplay,-1,label='Show sym. elem.?')1729 showSymElem.Bind(wx.EVT_CHECKBOX, OnShowSymElem)1730 showSymElem.SetValue(drawingData['showSymElem'])1731 flexSizer.Add(showSymElem,0,wx.ALIGN_CENTER_VERTICAL)1732 1763 1733 1764 showHydrogen = wx.CheckBox(dataDisplay,-1,label='Show hydrogens?') -
trunk/GSASIIplot.py
r165 r166 408 408 if 'PWDR' in self.PatternTree.GetItemText(item): 409 409 Pattern = self.PatternTree.GetItemPyData(item) 410 Pattern.append(self.PatternTree.GetItemText(item)) 410 if len(Pattern) < 3: # put name on end if needed 411 Pattern.append(self.PatternTree.GetItemText(item)) 411 412 PlotList.append(Pattern) 412 413 item, cookie = self.PatternTree.GetNextChild(self.root, cookie) … … 1588 1589 Draw() 1589 1590 1591 def OnFocus(event): 1592 Draw() 1593 1590 1594 try: 1591 1595 plotNum = self.G2plotNB.plotList.index(generalData['Name']) … … 1609 1613 Page.canvas.Bind(wx.EVT_MOTION, OnMouseMove) 1610 1614 Page.canvas.Bind(wx.EVT_SIZE, OnSize) 1615 Page.canvas.Bind(wx.EVT_SET_FOCUS, OnFocus) 1611 1616 cell = generalData['Cell'][1:7] 1612 1617 Amat,Bmat = G2lat.cell2AB(cell) #Amat - crystal to cartesian, Bmat - inverse -
trunk/GSASIIspc.py
r165 r166 206 206 print l 207 207 208 def MoveToUnitCell( XYZ):208 def MoveToUnitCell(xyz): 209 209 ''' 210 210 Translates a set of coordinates so that all values are >=0 and < 1 211 211 input: 212 XYZ - a list or numpy array of fractional coordinates 213 output: 214 none; the object is modified in place. 215 ''' 216 for i,x in enumerate(XYZ): 212 xyz - a list or numpy array of fractional coordinates 213 returns: 214 XYZ - numpy array of new coordinates inside 0-1 215 ''' 216 XYZ = np.zeros(3) 217 for i,x in enumerate(xyz): 217 218 XYZ[i] = (x-int(x))%1.0 219 return XYZ 218 220 219 221 def Opposite(XYZ,toler=0.0002): … … 250 252 Idup = [-][C]SS where SS is the symmetry operator number (1-24), C (if not 0,0,0) 251 253 is centering operator number (1-4) and - is for inversion 254 Cell = unit cell translations needed to put new positions inside cell 252 255 [UijEquiv] - equivalent Uij; absent if no Uij given 253 256 ''' … … 255 258 UijEquiv = [] 256 259 Idup = [] 260 Cell = [] 257 261 X = np.array(XYZ) 258 MoveToUnitCell(X)262 X = MoveToUnitCell(X) 259 263 for ic,cen in enumerate(SGData['SGCen']): 260 264 C = np.array(cen) … … 262 266 for io,[M,T] in enumerate(SGData['SGOps']): 263 267 idup = ((io+1)+100*ic)*(1-2*invers) 264 newX= np.inner(M,X)+T268 XT = np.inner(M,X)+T 265 269 if len(Uij): 266 270 U = Uij2U(Uij) … … 268 272 newUij = U2Uij(U) 269 273 if invers: 270 newX = -newX 271 newX += C 272 MoveToUnitCell(newX) 274 XT = -XT 275 XT += C 276 newX = MoveToUnitCell(XT) 277 cell = np.asarray(np.rint(newX-XT),dtype=np.int32) 273 278 if All: 274 279 if np.allclose(newX,X,atol=0.0002): 275 idup = 0280 idup = False 276 281 else: 277 282 if True in [np.allclose(newX,X,atol=0.0002) for oldX in XYZEquiv]: 278 idup = 0283 idup = False 279 284 if All or idup: 280 285 XYZEquiv.append(newX) 281 286 Idup.append(idup) 287 Cell.append(cell) 282 288 if len(Uij): 283 289 UijEquiv.append(newUij) 284 290 if len(Uij): 285 return zip(XYZEquiv,UijEquiv,Idup )291 return zip(XYZEquiv,UijEquiv,Idup,Cell) 286 292 else: 287 return zip(XYZEquiv,Idup )293 return zip(XYZEquiv,Idup,Cell) 288 294 289 295 def GenHKL(HKL,SGData,Friedel=False): … … 649 655 650 656 return #SymElements 657 658 def ApplyStringOps(A,SGData,X,Uij=[]): 659 SGOps = SGData['SGOps'] 660 SGCen = SGData['SGCen'] 661 Ax = A.split('+') 662 Ax[0] = int(Ax[0]) 663 iC = 0 664 if Ax[0] < 0: 665 iC = 1 666 Ax[0] = abs(Ax[0]) 667 nA = Ax[0]%100-1 668 cA = Ax[0]/100 669 Cen = SGCen[cA] 670 M,T = SGOps[nA] 671 if len(Ax)>1: 672 cellA = Ax[1].split(',') 673 cellA = np.array([int(a) for a in cellA]) 674 else: 675 cellA = np.zeros(3) 676 newX = (1-2*iC)*(Cen+np.inner(M,X)+T)+cellA 677 if len(Uij): 678 U = Uij2U(Uij) 679 U = np.inner(M,np.inner(U,M).T) 680 newUij = U2Uij(U) 681 return [newX,newUij] 682 else: 683 return newX 651 684 652 653 654 655 685 def StringOpsProd(A,B,SGData): 686 ''' Find A*B where A & B are in strings '-' + '100*c+n' + '+ijk' 687 where '-' indicates inversion, c(>0) is the cell centering operator, 688 n is operator number from SgOps and ijk are unit cell translations (each may be <0). 689 Should return resultant string - C. 690 SGData - dictionary using entries: 691 'SGCen': cell centering vectors [0,0,0] at least 692 'SGOps': symmetry operations as [M,T] so that M*x+T = x' 693 ''' 694 SGOps = SGData['SGOps'] 695 SGCen = SGData['SGCen'] 696 #1st split out the cell translation part & work on the operator parts 697 Ax = A.split('+'); Bx = B.split('+') 698 Ax[0] = int(Ax[0]); Bx[0] = int(Bx[0]) 699 iC = 0 700 if Ax[0]*Bx[0] < 0: 701 iC = 1 702 Ax[0] = abs(Ax[0]); Bx[0] = abs(Bx[0]) 703 nA = Ax[0]%100-1; nB = Bx[0]%100-1 704 cA = Ax[0]/100; cB = Bx[0]/100 705 Cen = (SGCen[cA]+SGCen[cB])%1.0 706 cC = np.nonzero([np.allclose(C,Cen) for C in SGCen])[0][0] 707 Ma,Ta = SGOps[nA]; Mb,Tb = SGOps[nB] 708 Mc = np.inner(Ma,Mb.T) 709 # print Ma,Mb,Mc 710 Tc = (np.add(np.inner(Mb,Ta)+1.,Tb))%1.0 711 # print Ta,Tb,Tc 712 # print [np.allclose(M,Mc)&np.allclose(T,Tc) for M,T in SGOps] 713 nC = np.nonzero([np.allclose(M,Mc)&np.allclose(T,Tc) for M,T in SGOps])[0][0] 714 #now the cell translation part 715 if len(Ax)>1: 716 cellA = Ax[1].split(',') 717 cellA = [int(a) for a in cellA] 718 else: 719 cellA = [0,0,0] 720 if len(Bx)>1: 721 cellB = Bx[1].split(',') 722 cellB = [int(b) for b in cellB] 723 else: 724 cellB = [0,0,0] 725 cellC = np.add(cellA,cellB) 726 C = str(((nC+1)+(100*cC))*(1-2*iC))+'+'+ \ 727 str(int(cellC[0]))+','+str(int(cellC[1]))+','+str(int(cellC[2])) 728 return C 729 656 730 def U2Uij(U): 657 731 #returns the UIJ vector U11,U22,U33,U12,U13,U23 from tensor U … … 788 862 for cen in spc['SGCen']: 789 863 noff = off + cen 790 MoveToUnitCell(noff)864 noff = MoveToUnitCell(noff) 791 865 mult = tuple((op*inv).ravel().tolist()) 792 866 if debug: print "\n%s: %s + %s" % (spcname,mult,noff) … … 798 872 # check the translation 799 873 reftrans = list(refop[-3:]) 800 MoveToUnitCell(reftrans)874 reftrans = MoveToUnitCell(reftrans) 801 875 if all(abs(noff - reftrans) < 1.e-5): 802 876 cctbx.remove(refop)
Note: See TracChangeset
for help on using the changeset viewer.