Changeset 159
- Timestamp:
- Oct 4, 2010 1:00:32 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIspc.py
r155 r159 2 2 3 3 import numpy as np 4 import numpy.ma as ma 4 5 import math 5 6 import sys … … 11 12 def SpcGroup(SGSymbol): 12 13 ''' 13 Determines cell and symmetry information from a short H-M space group name 14 input: space group symbol (string) with spaces between axial fields 15 returns [SGError,SGData] 16 SGError = 0 for no errors; >0 for errors (see SGErrors below for details) 17 returns dictionary SGData with entries: 18 'SpGrp': space group symbol slightly cleaned up 19 'Laue': one of '-1','2/m','mmm','4/m','4/mmm','3R','3mR','3', 20 '3m1','31m','6/m','6/mmm','m3','m3m' 21 'SGInv': boolean; True if centrosymmetric, False if not 22 'SGLatt': one of 'P','A','B','C','I','F','R' 23 'SGUniq': one of 'a','b','c' if monoclinic, '' otherwise 24 'SGCen': cell centering vectors [0,0,0] at least 25 'SGOps': symmetry operations as [M,T] so that M*x+T = x' 26 'SGSys': one of 'triclinic','monoclinic','orthorhombic','tetragonal','rhombohedral','trigonal','hexagonal','cubic' 14 Determines cell and symmetry information from a short H-M space group name 15 input: 16 SGSymbol - space group symbol (string) with spaces between axial fields 17 returns: 18 SGError = 0 for no errors; >0 for errors (see SGErrors below for details) 19 SGData - dictionary with entries: 20 'SpGrp': space group symbol slightly cleaned up 21 'Laue': one of '-1','2/m','mmm','4/m','4/mmm','3R','3mR','3', 22 '3m1','31m','6/m','6/mmm','m3','m3m' 23 'SGInv': boolean; True if centrosymmetric, False if not 24 'SGLatt': one of 'P','A','B','C','I','F','R' 25 'SGUniq': one of 'a','b','c' if monoclinic, '' otherwise 26 'SGCen': cell centering vectors [0,0,0] at least 27 'SGOps': symmetry operations as [M,T] so that M*x+T = x' 28 'SGSys': one of 'triclinic','monoclinic','orthorhombic','tetragonal','rhombohedral','trigonal','hexagonal','cubic' 27 29 ''' 28 30 LaueSym = ('-1','2/m','mmm','4/m','4/mmm','3R','3mR','3','3m1','31m','6/m','6/mmm','m3','m3m') … … 75 77 76 78 def SGErrors(IErr): 77 '''Interprets the error message code from SpcGroup. Used in SpaceGroup. 78 input: SGError, from SpcGroup 79 returns a string with the error message or "Unknown error" 79 ''' 80 Interprets the error message code from SpcGroup. Used in SpaceGroup. 81 input: 82 SGError - from SpcGroup 83 returns: 84 ErrString - a string with the error message or "Unknown error" 80 85 ''' 81 86 … … 115 120 ''' 116 121 Print the output of SpcGroup in a nicely formatted way. Used in SpaceGroup 117 input: SGData, from SpcGroup 118 returns a list of strings with the space group details 122 input: 123 SGData - from SpcGroup 124 returns: 125 SGText - list of strings with the space group details 119 126 ''' 120 127 POL = (' ','x','y','x y','z','x z','y z','xyz','111') … … 183 190 return lattTxt[Latt] 184 191 185 def SpaceGroup(S gSym):192 def SpaceGroup(SGSymbol): 186 193 ''' 187 194 Print the output of SpcGroup in a nicely formatted way. 188 input: space group symbol (string) with spaces between axial fields 189 returns nothing 190 ''' 191 E,A = SpcGroup(SgSym) 195 input: 196 SGSymbol - space group symbol (string) with spaces between axial fields 197 returns: 198 nothing 199 ''' 200 E,A = SpcGroup(SGSymbol) 192 201 if E > 0: 193 202 print SGErrors(E) … … 199 208 ''' 200 209 Translates a set of coordinates so that all values are >=0 and < 1 201 input: a list or numpy array of any length. 202 output: none; the object is modified in place. 210 input: 211 XYZ - a list or numpy array of fractional coordinates 212 output: 213 none; the object is modified in place. 203 214 ''' 204 215 for i,x in enumerate(XYZ): … … 248 259 C = np.array(cen) 249 260 for invers in range(int(SGData['SGInv']+1)): 250 for io, opsin enumerate(SGData['SGOps']):261 for io,M,T in enumerate(SGData['SGOps']): 251 262 idup = ((io+1)+100*ic)*(1-2*invers) 252 T = np.array(ops[1])253 M = np.array(ops[0])254 263 newX = np.inner(M,X)+T 255 264 if len(Uij): … … 276 285 else: 277 286 return zip(XYZEquiv,Idup) 287 288 def GenHKL(HKL,SGData,Friedel=False): 289 ''' 290 Generate set of equivalent reflections 291 input: 292 HKL - [h,k,l] 293 SGData - space group data obtained from SpcGroup 294 Friedel = True to retain Friedel pairs for centrosymmetric case 295 returns: 296 iabsnt = True is reflection is forbidden by symmetry 297 mulp = reflection multiplicity including Fridel pairs 298 Uniq = numpy array of equivalent hkl in descending order of h,k,l 299 Phs = numpy array of corresponding phase factors (multiples of 2pi) 300 ''' 301 iabsnt = False 302 H = np.array(HKL) 303 Inv = SGData['SGInv'] 304 Cen = SGData['SGCen'][1:] #skip P 305 # do cell centering extinction check 306 for cen in Cen: 307 iabsnt |= bool(int(round(np.sum(cen*H*12)))%12) 308 # get operators & expand if centrosymmetric 309 Ops = SGData['SGOps'] 310 opM = np.array([op[0].T for op in Ops]) 311 opT = np.array([op[1] for op in Ops]) 312 if Inv: 313 opM = np.concatenate((opM,-opM)) 314 opT = np.concatenate((opT,-opT)) 315 # generate full hkl table and phase factors; find duplicates for multiplicity 316 eqH = np.inner(opM,H) 317 HT = np.dot(opT,H)%1. 318 dup = len(ma.nonzero([ma.allclose(HKL,hkl,atol=0.001) for hkl in eqH])[0]) 319 mulp = len(eqH)/dup 320 # generate unique reflection set (with or without Friedel pairs) 321 HPT = [tuple(hp) for hp in np.column_stack((eqH,HT))] 322 HPT.sort() 323 UPT = HPT[::dup] 324 UPT.reverse() 325 if Inv and not Friedel: 326 UPT = UPT[:len(UPT)/2] 327 Uniq = np.split(UPT,[3,4],axis=1) 328 Phs = Uniq[1].T[0] 329 Uniq = Uniq[0] 330 # determine if extinct 331 HPT = np.split(HPT,[3,4],axis=1)[1].T[0] 332 HPT = np.reshape(HPT,(mulp,-1)).T 333 HPT = np.around(HPT-HPT[0],4)%1. 334 iabsnt |= np.any(HPT) 335 return iabsnt,mulp,Uniq,Phs 278 336 279 337 def GetOprPtrName(key):
Note: See TracChangeset
for help on using the changeset viewer.