Changeset 477
- Timestamp:
- Feb 9, 2012 1:23:01 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIImath.py
r470 r477 148 148 149 149 def calcDist(Ox,Tx,U,inv,C,M,T,Amat): 150 TxT = inv*(np.inner(M,Tx)+T)+C 151 TxT = G2spc.MoveToUnitCell(TxT)+U 150 TxT = inv*(np.inner(M,Tx)+T)+C+U 152 151 return np.sqrt(np.sum(np.inner(Amat,(TxT-Ox))**2)) 153 152 … … 236 235 return calcAngle(OxA,TxA,TxB,unitA,unitB,invA,CA,MA,TA,invB,CB,MB,TB,Amat),0.0 237 236 238 def GetTorsionSig(Atoms,Amat,SGData,covData={}): 239 XYZ = [] 240 for atom in Atoms: 241 XYZ.append(np.array(atom[3:6])) 242 XYZ = np.inner(Amat,XYZ).T 243 V1 = XYZ[1]-XYZ[0] 244 V2 = XYZ[2]-XYZ[1] 245 V3 = XYZ[3]-XYZ[2] 246 V1 /= np.sqrt(np.sum(V1**2)) 247 V2 /= np.sqrt(np.sum(V2**2)) 248 V3 /= np.sqrt(np.sum(V3**2)) 249 M = np.array([V1,V2,V3]) 250 D = nl.det(M) 251 Ang = 1.0 252 P12 = np.dot(V1,V2) 253 P13 = np.dot(V1,V3) 254 P23 = np.dot(V2,V3) 255 Tors = acosd((P12*P23-P13)/(np.sqrt(1.-P12**2)*np.sqrt(1.-P23**2)))*D/abs(D) 256 257 sig = 0.0 237 def GetTorsionSig(Oatoms,Atoms,Amat,SGData,covData={}): 238 239 def calcTorsion(Atoms,SyOps,Amat): 240 241 XYZ = [] 242 for i,atom in enumerate(Atoms): 243 Inv,M,T,C,U = SyOps[i] 244 XYZ.append(np.array(atom[1:4])) 245 XYZ[-1] = Inv*(np.inner(M,np.array(XYZ[-1]))+T)+C+U 246 XYZ[-1] = np.inner(Amat,XYZ[-1]).T 247 V1 = XYZ[1]-XYZ[0] 248 V2 = XYZ[2]-XYZ[1] 249 V3 = XYZ[3]-XYZ[2] 250 V1 /= np.sqrt(np.sum(V1**2)) 251 V2 /= np.sqrt(np.sum(V2**2)) 252 V3 /= np.sqrt(np.sum(V3**2)) 253 M = np.array([V1,V2,V3]) 254 D = nl.det(M) 255 Ang = 1.0 256 P12 = np.dot(V1,V2) 257 P13 = np.dot(V1,V3) 258 P23 = np.dot(V2,V3) 259 Tors = acosd((P12*P23-P13)/(np.sqrt(1.-P12**2)*np.sqrt(1.-P23**2)))*D/abs(D) 260 return Tors 261 262 Inv = [] 263 SyOps = [] 264 names = [] 265 for i,atom in enumerate(Oatoms): 266 names += atom[-1] 267 Op,unit = Atoms[i][-1] 268 inv = Op/abs(Op) 269 m,t = SGData['SGOps'][abs(Op)%100-1] 270 c = SGData['SGCen'][abs(Op)/100] 271 SyOps.append([inv,m,t,c,unit]) 272 Tors = calcTorsion(Oatoms,SyOps,Amat) 273 274 sig = -0.01 258 275 if 'covMatrix' in covData: 259 for atom in Atoms: 260 xyz = atom[3:6] 261 Op,Unit = atom[-1] 262 inv = Op/abs(Op) 263 M,T = SGData['SGOps'][abs(Op)%100-1] 264 C = SGData['SGCen'][abs(Op)/100] 265 #reverse inv*(np.inner(M,Tx)+T)+C 266 XYZ = np.inner(nl.inv(M),((xyz-C)*inv-T)) 267 print Op,Unit,xyz,XYZ 276 parmNames = [] 277 dx = .00001 278 dadx = np.zeros(12) 279 ang = calcTorsion(Oatoms,SyOps,Amat) 280 for i in range(12): 281 ia = i/3 282 ix = i%3 283 Oatoms[ia][ix+1] += dx 284 a0 = calcTorsion(Oatoms,SyOps,Amat) 285 Oatoms[ia][ix+1] -= 2*dx 286 dadx[i] = (calcTorsion(Oatoms,SyOps,Amat)-a0)/(2.*dx) 268 287 covMatrix = covData['covMatrix'] 269 288 varyList = covData['varyList'] 289 TorVcov = getVCov(names,varyList,covMatrix) 290 sig = np.sqrt(np.inner(dadx,np.inner(TorVcov,dadx))) 291 if sig < 0.01: 292 sig = -0.01 270 293 271 294 return Tors,sig … … 286 309 return str(fmt%(value,int(round(esd*10**(mdec(esd)))))).strip('"') 287 310 elif esd < 0: 288 return str(round(value,mdec(esd) ))311 return str(round(value,mdec(esd)-1)) 289 312 else: 290 313 text = str("%f"%(value)) -
trunk/GSASIIphsGUI.py
r476 r477 1648 1648 if atom[cuia] == 'A': 1649 1649 Uij = atom[cuij:cuij+6] 1650 result = G2spc.GenAtom(XYZ,SGData,False,Uij )1650 result = G2spc.GenAtom(XYZ,SGData,False,Uij,False) 1651 1651 for item in result: 1652 1652 atom = copy.copy(atomData[ind]) … … 1665 1665 atomData.append(atom[:]) 1666 1666 else: 1667 result = G2spc.GenAtom(XYZ,SGData,False )1667 result = G2spc.GenAtom(XYZ,SGData,False,Move=False) 1668 1668 for item in result: 1669 1669 atom = copy.copy(atomData[ind]) … … 1802 1802 event.StopPropagation() 1803 1803 1804 def FindAtomIndexByIDs(atomData,IDs ):1804 def FindAtomIndexByIDs(atomData,IDs,Draw=True): 1805 1805 indx = [] 1806 1806 for i,atom in enumerate(atomData): 1807 if atom[-2] in IDs: 1807 if Draw and atom[-3] in IDs: 1808 indx.append(i) 1809 elif atom[-1] in IDs: 1808 1810 indx.append(i) 1809 1811 return indx … … 1835 1837 return 1836 1838 TorsionData = {} 1839 ocx,oct,ocs,cia = data['General']['AtomPtrs'] 1837 1840 drawingData = data['Drawing'] 1838 1841 atomData = data['Atoms'] 1842 # for atom in atomData: print atom 1839 1843 atomDData = drawingData['Atoms'] 1844 # for atom in atomDData: print atom 1840 1845 colLabels = [drawAtoms.GetColLabelValue(c) for c in range(drawAtoms.GetNumberCols())] 1841 1846 cx = colLabels.index('x') 1842 1847 cn = colLabels.index('Name') 1848 cid = colLabels.index('I/A')+8 1843 1849 xyz = [] 1850 Oxyz = [] 1844 1851 for i,atom in enumerate(atomDData): 1845 1852 if i in indx: 1846 1853 xyz.append([i,]+atom[cn:cn+2]+atom[cx:cx+4]) #also gets Sym Op 1854 id = FindAtomIndexByIDs(atomData,[atom[cid],],False)[0] 1855 Oxyz.append([id,]+atomData[id][cx+1:cx+4]) 1847 1856 TorsionData['Datoms'] = xyz 1857 TorsionData['Oatoms'] = Oxyz 1848 1858 generalData = data['General'] 1849 1859 TorsionData['Name'] = generalData['Name'] -
trunk/GSASIIplot.py
r468 r477 2266 2266 return G2frame.dataDisplay.GetSelection() 2267 2267 except AttributeError: 2268 print G2frame.dataDisplay.GetLabel()2269 2268 G2frame.G2plotNB.status.SetStatusText('Select this from Phase data window!') 2270 2269 return 0 … … 2572 2571 2573 2572 def Draw(): 2574 import numpy.linalg as nl2575 2573 Ind = GetSelectedAtoms() 2576 2574 VS = np.array(Page.canvas.GetSize()) -
trunk/GSASIIspc.py
r459 r477 252 252 return new 253 253 254 def GenAtom(XYZ,SGData,All=False,Uij=[] ):254 def GenAtom(XYZ,SGData,All=False,Uij=[],Move=True): 255 255 ''' 256 256 Generates the equivalent positions for a specified coordinate and space group … … 273 273 Cell = [] 274 274 X = np.array(XYZ) 275 X = MoveToUnitCell(X) 275 if Move: 276 X = MoveToUnitCell(X) 276 277 for ic,cen in enumerate(SGData['SGCen']): 277 278 C = np.array(cen) -
trunk/GSASIIstruct.py
r474 r477 2610 2610 TxyzNames = [pfx+'dAx:%d'%(Tatom[0]),pfx+'dAy:%d'%(Tatom[0]),pfx+'dAz:%d'%(Tatom[0])] 2611 2611 Xvcov = G2mth.getVCov(OxyzNames+TxyzNames,varyList,covMatrix) 2612 result = G2spc.GenAtom(Tatom[3:6],SGData,False )2612 result = G2spc.GenAtom(Tatom[3:6],SGData,False,Move=False) 2613 2613 BsumR = (Radii[Oatom[2]][0]+Radii[Tatom[2]][0])*Factor[0] 2614 2614 AsumR = (Radii[Oatom[2]][1]+Radii[Tatom[2]][1])*Factor[1] … … 2679 2679 print 80*'*' 2680 2680 print ' Torsion angle for phase '+name 2681 print 80*'*' ,'\n'2681 print 80*'*' 2682 2682 2683 2683 ShowBanner(TorsionData['Name']) 2684 2684 SGData = TorsionData['SGData'] 2685 SGtext = G2spc.SGPrint(SGData)2686 for line in SGtext: print line2687 2685 Cell = TorsionData['Cell'] 2688 2686 2689 2687 Amat,Bmat = G2lat.cell2AB(Cell[:6]) 2690 2688 covData = {} 2689 pfx = '' 2691 2690 if 'covData' in TorsionData: 2692 2691 covData = TorsionData['covData'] … … 2694 2693 varyList = covData['varyList'] 2695 2694 pfx = str(TorsionData['pId'])+'::' 2696 A = G2lat.cell2A(Cell[:6])2697 cellSig = getCellEsd(pfx,SGData,A,covData)2698 names = [' a = ',' b = ',' c = ',' alpha = ',' beta = ',' gamma = ',' Volume = ']2699 valEsd = [G2mth.ValEsd(Cell[i],cellSig[i],True) for i in range(7)]2700 line = '\n Unit cell:'2701 for name,vals in zip(names,valEsd):2702 line += name+vals2703 print line2704 else:2705 print '\n Unit cell: a = ','%.5f'%(Cell[0]),' b = ','%.5f'%(Cell[1]),' c = ','%.5f'%(Cell[2]), \2706 ' alpha = ','%.3f'%(Cell[3]),' beta = ','%.3f'%(Cell[4]),' gamma = ', \2707 '%.3f'%(Cell[5]),' volume = ','%.3f'%(Cell[6])2708 2695 #find one end of 4 atom string - involved in longest distance 2709 2696 dist = {} … … 2717 2704 dist = {} 2718 2705 X1 = TorsionData['Datoms'][end] 2719 for i,X2 in enumerate(TorsionData['Datoms']): 2706 for i,X2 in enumerate(TorsionData['Datoms']): 2720 2707 dist[np.sqrt(np.sum(np.inner(Amat,np.array(X2[3:6])-np.array(X1[3:6]))**2))] = i 2721 2708 sortdist = dist.keys() 2722 2709 sortdist.sort() 2723 2710 Datoms = [] 2711 Oatoms = [] 2724 2712 for d in sortdist: 2725 2713 atom = TorsionData['Datoms'][dist[d]] … … 2730 2718 symop[1] = eval(symop[1]) 2731 2719 atom[-1] = symop 2732 print atom2733 2720 Datoms.append(atom) 2734 Tors,sig = G2mth.GetTorsionSig(Datoms,Amat,SGData,covData={}) 2735 print ' Torsion: ',G2mth.ValEsd(Tors,sig) 2736 2737 2721 oatom = TorsionData['Oatoms'][dist[d]] 2722 names = ['','',''] 2723 if pfx: 2724 names = [pfx+'dAx:'+str(oatom[0]),pfx+'dAy:'+str(oatom[0]),pfx+'dAz:'+str(oatom[0])] 2725 oatom += [names,] 2726 Oatoms.append(oatom) 2727 Tors,sig = G2mth.GetTorsionSig(Oatoms,Datoms,Amat,SGData,covData) 2728 print ' Torsion angle for atom sequence: ',[Datoms[i][1] for i in range(4)],'=',G2mth.ValEsd(Tors,sig) 2729 print ' NB: Atom sequence determined by interatomic distances' 2730 2738 2731 def BestPlane(PlaneData): 2739 2732
Note: See TracChangeset
for help on using the changeset viewer.