Changeset 2038
- Timestamp:
- Oct 30, 2015 4:02:02 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIindex.py
r2025 r2038 813 813 if not GoOn: 814 814 break 815 tries += 1 815 tries += 1 816 816 X = sortM20(Asave) 817 817 if X: -
trunk/GSASIIlattice.py
r2022 r2038 50 50 SQ2 = np.sqrt(2.) 51 51 RSQPI = 1./np.sqrt(np.pi) 52 R2pisq = 1./(2.*np.pi**2) 52 53 53 54 def sec2HMS(sec): … … 285 286 return U6 286 287 288 def betaij2Uij(betaij,G): 289 """ 290 Convert beta-ij to Uij tensors 291 292 :param beta-ij - numpy array [beta-ij] 293 :param G: reciprocal metric tensor 294 :returns: Uij: numpy array [Uij] 295 """ 296 ast = np.sqrt(np.diag(G)) #a*, b*, c* 297 Mast = np.multiply.outer(ast,ast) 298 return R2pisq*UijtoU6(U6toUij(betaij)/Mast) 299 287 300 def Uij2betaij(Uij,G): 288 301 """ -
trunk/GSASIImath.py
r2025 r2038 927 927 ################################################################################ 928 928 929 def Modulation(waveTypes,H, FSSdata,XSSdata,USSdata,Mast):929 def Modulation(waveTypes,H,HP,FSSdata,XSSdata,USSdata,Mast): 930 930 ''' 931 931 H: array nRefBlk x ops X hklt 932 HP: array nRefBlk x ops X hklt proj to hkl 932 933 FSSdata: array 2 x atoms x waves (sin,cos terms) 933 934 XSSdata: array 2x3 x atoms X waves (sin,cos terms) … … 970 971 XmodB = Bx[:,nx:,:,nxs]*np.cos(twopi*tauX[nxs,:,nxs,:]) #ditto 971 972 Xmod = np.sum(XmodA+XmodB+XmodZ,axis=1) #atoms X 3 X 32; sum waves 972 Tau = np.reshape(np.tile(glTau,Xmod.shape[0]),(Xmod.shape[0],-1)) #atoms x 32 973 XmodT = np.swapaxes(np.concatenate((Xmod,Tau[:,nxs,:]),axis=1),1,2) # atoms x 32 x 4 (x,y,z,t) 973 Xmod = np.swapaxes(Xmod,1,2) #agree with J2K ParSup 974 974 if Au.shape[1]: 975 975 tauU = np.arange(1.,Au.shape[1]+1)[:,nxs]*glTau #Uwaves x 32 … … 977 977 UmodB = Bu[:,:,:,:,nxs]*np.cos(twopi*tauU[nxs,:,nxs,nxs,:]) #ditto 978 978 Umod = np.swapaxes(np.sum(UmodA+UmodB,axis=1),1,3) #atoms x 3x3 x 32; sum waves 979 HbH = np.exp(-np.sum(H [:,:,nxs,nxs,:3]*np.inner(H[:,:,:3],Umod),axis=-1)) # refBlk x ops x atoms x 32 add Overhauser corr.?979 HbH = np.exp(-np.sum(HP[:,:,nxs,nxs]*np.inner(HP[:,:],Umod),axis=-1)) # refBlk x ops x atoms x 32 add Overhauser corr.? 980 980 else: 981 981 HbH = 1.0 982 HdotX = np.inner(H,XmodT) #refBlk X ops x atoms X 32 982 D = H[:,:,3:]*glTau[nxs,nxs,:] #m*e*tau; refBlk x ops X 32 983 HdotX = np.inner(HP,Xmod)+D[:,:,nxs,:] #refBlk x ops x atoms X 32 983 984 cosHA = np.sum(Fmod*HbH*np.cos(twopi*HdotX)*glWt,axis=-1) #real part; refBlk X ops x atoms; sum for G-L integration 984 985 sinHA = np.sum(Fmod*HbH*np.sin(twopi*HdotX)*glWt,axis=-1) #imag part; ditto 985 986 # GSASIIpath.IPyBreak() 986 # if np.any(cosHA<0.) or np.any(cosHA>1.) or np.any(sinHA<0.) or np.any(sinHA>1.):987 # GSASIIpath.IPyBreak()988 987 return np.array([cosHA,sinHA]) # 2 x refBlk x SGops x atoms 989 988 990 def ModulationDerv(waveTypes,H,H ij,FSSdata,XSSdata,USSdata,Mast):991 ''' 992 H: array ops X hklt 989 def ModulationDerv(waveTypes,H,HP,Hij,FSSdata,XSSdata,USSdata,Mast): 990 ''' 991 H: array ops X hklt proj to hkl 993 992 FSSdata: array 2 x atoms x waves (sin,cos terms) 994 993 XSSdata: array 2x3 x atoms X waves (sin,cos terms) … … 999 998 nxs = np.newaxis 1000 999 numeric = True 1001 cosHA,sinHA = Modulation(waveTypes,np.array([H,]), FSSdata,XSSdata,USSdata,Mast)1000 cosHA,sinHA = Modulation(waveTypes,np.array([H,]),np.array([HP,]),FSSdata,XSSdata,USSdata,Mast) 1002 1001 Mf = [H.shape[0],]+list(FSSdata.T.shape) #ops x atoms x waves x 2 (sin+cos frac mods) 1003 1002 dGdMfC = np.zeros(Mf) … … 1037 1036 XmodB = Bx[:,nx:,:,nxs]*CtauX #ditto 1038 1037 Xmod = np.sum(XmodA+XmodB+XmodZ,axis=1) #atoms X pos X 32; sum waves 1039 Tau = np.reshape(np.tile(glTau,Xmod.shape[0]),(Xmod.shape[0],-1)) #atoms x 32 1040 XmodT = np.swapaxes(np.concatenate((Xmod,Tau[:,nxs,:]),axis=1),1,2) # atoms x 32 x 4 (x,y,z,t) 1041 D = H[:,3][:,nxs]*glTau[nxs,:] #m*tau; ops X 32 1042 # HdotX = np.inner(H[:,:3],np.swapaxes(Xmod,1,2))+D[:,nxs,:] #ops x atoms X 32 1043 HdotX = np.inner(H,XmodT) #refBlk X ops x atoms X 32 1038 Xmod = np.swapaxes(Xmod,1,2) 1039 D = H[:,3][:,nxs]*glTau[nxs,:] #m*e*tau; ops X 32 1040 HdotX = np.inner(HP,Xmod)+D[:,nxs,:] #refBlk X ops x atoms X 32 1044 1041 if Af.shape[1]: 1045 1042 tauF = np.arange(1.,Af.shape[1]+1-nf)[:,nxs]*glTau #Fwaves x 32 … … 1058 1055 UmodB = Bu[:,:,:,:,nxs]*CtauU #ditto 1059 1056 Umod = np.swapaxes(np.sum(UmodA+UmodB,axis=1),1,3) #atoms x 3x3 x 32; sum waves 1060 HbH = np.exp(-np.sum(H [:,nxs,nxs,:3]*np.inner(H[:,:3],Umod),axis=-1)) # ops x atoms x 32 add Overhauser corr.?1061 1057 HbH = np.exp(-np.sum(HP[:,nxs,nxs]*np.inner(HP[:],Umod),axis=-1)) # ops x atoms x 32 add Overhauser corr.? 1058 #derivatives?? 1062 1059 else: 1063 1060 HbH = np.ones_like(HdotX) 1064 HdotXA = H [:,nxs,nxs,nxs,:3]*np.swapaxes(XmodA,-1,-2)[nxs,:,:,:,:]+D[:,nxs,nxs,:,nxs] #ops x atoms x waves x 32 x xyz1065 HdotXB = H [:,nxs,nxs,nxs,:3]*np.swapaxes(XmodB,-1,-2)[nxs,:,:,:,:]+D[:,nxs,nxs,:,nxs]1066 dHdXA = H [:,nxs,nxs,nxs,:3]*np.swapaxes(StauX,-1,-2)[nxs,:,:,:,:] #ops x atoms x waves x 32 x xyz1067 dHdXB = H [:,nxs,nxs,nxs,:3]*np.swapaxes(CtauX,-1,-2)[nxs,:,:,:,:] #ditto1061 HdotXA = HP[:,nxs,nxs,nxs,:]*np.swapaxes(XmodA,-1,-2)[nxs,:,:,:,:]+D[:,nxs,nxs,:,nxs] #ops x atoms x waves x 32 x xyz 1062 HdotXB = HP[:,nxs,nxs,nxs,:]*np.swapaxes(XmodB,-1,-2)[nxs,:,:,:,:]+D[:,nxs,nxs,:,nxs] 1063 dHdXA = HP[:,nxs,nxs,nxs,:]*np.swapaxes(StauX,-1,-2)[nxs,:,:,:,:] #ops x atoms x waves x 32 x xyz 1064 dHdXB = HP[:,nxs,nxs,nxs,:]*np.swapaxes(CtauX,-1,-2)[nxs,:,:,:,:] #ditto 1068 1065 dGdMxCa = np.sum((Fmod*HbH)[:,:,nxs,:,nxs]*(-twopi*dHdXA*np.sin(twopi*HdotXA))*glWt[nxs,nxs,nxs,:,nxs],axis=-2) 1069 1066 dGdMxCb = np.sum((Fmod*HbH)[:,:,nxs,:,nxs]*(-twopi*dHdXB*np.sin(twopi*HdotXB))*glWt[nxs,nxs,nxs,:,nxs],axis=-2) … … 2252 2249 return mapData 2253 2250 2254 def Fourier4DMap(data,reflDict):2255 '''default doc string2256 2257 :param type name: description2258 2259 :returns: type name: description2260 2261 '''2262 generalData = data['General']2263 map4DData = generalData['4DmapData']2264 mapData = generalData['Map']2265 dmin = mapData['Resolution']2266 SGData = generalData['SGData']2267 SSGData = generalData['SSGData']2268 SSGMT = np.array([ops[0].T for ops in SSGData['SSGOps']])2269 SSGT = np.array([ops[1] for ops in SSGData['SSGOps']])2270 cell = generalData['Cell'][1:8]2271 A = G2lat.cell2A(cell[:6])2272 maxM = generalData['SuperVec'][2]2273 Hmax = G2lat.getHKLmax(dmin,SGData,A)+[maxM,]2274 adjHKLmax(SGData,Hmax)2275 Hmax = np.asarray(Hmax,dtype='i')+12276 Fhkl = np.zeros(shape=2*Hmax,dtype='c16')2277 time0 = time.time()2278 for iref,ref in enumerate(reflDict['RefList']):2279 if ref[5] > dmin:2280 Fosq,Fcsq,ph = ref[9:12]2281 Fosq = np.where(Fosq>0.,Fosq,0.) #can't use Fo^2 < 02282 Uniq = np.inner(ref[:4],SSGMT)2283 Phi = np.inner(ref[:4],SSGT)2284 for i,hkl in enumerate(Uniq): #uses uniq2285 hkl = np.asarray(hkl,dtype='i')2286 dp = 360.*Phi[i] #and phi2287 a = cosd(ph+dp)2288 b = sind(ph+dp)2289 phasep = complex(a,b)2290 phasem = complex(a,-b)2291 if 'Fobs' in mapData['MapType']:2292 F = np.sqrt(Fosq)2293 h,k,l,m = hkl+Hmax2294 Fhkl[h,k,l,m] = F*phasep2295 h,k,l,m = -hkl+Hmax2296 Fhkl[h,k,l,m] = F*phasem2297 elif 'Fcalc' in mapData['MapType']:2298 F = np.sqrt(Fcsq)2299 h,k,l,m = hkl+Hmax2300 Fhkl[h,k,l,m] = F*phasep2301 h,k,l,m = -hkl+Hmax2302 Fhkl[h,k,l,m] = F*phasem2303 elif 'delt-F' in mapData['MapType']:2304 dF = np.sqrt(Fosq)-np.sqrt(Fcsq)2305 h,k,l,m = hkl+Hmax2306 Fhkl[h,k,l,m] = dF*phasep2307 h,k,l,m = -hkl+Hmax2308 Fhkl[h,k,l,m] = dF*phasem2309 SSrho = fft.fftn(fft.fftshift(Fhkl))/cell[6] #4D map2310 rho = fft.fftn(fft.fftshift(Fhkl[:,:,:,maxM+1]))/cell[6] #3D map2311 map4DData['rho'] = np.real(SSrho)2312 map4DData['rhoMax'] = max(np.max(map4DData['rho']),-np.min(map4DData['rho']))2313 map4DData['minmax'] = [np.max(map4DData['rho']),np.min(map4DData['rho'])]2314 map4DData['Type'] = reflDict['Type']2315 mapData['Type'] = reflDict['Type']2316 mapData['rho'] = np.real(rho)2317 mapData['rhoMax'] = max(np.max(mapData['rho']),-np.min(mapData['rho']))2318 mapData['minmax'] = [np.max(mapData['rho']),np.min(mapData['rho'])]2319 print 'Fourier map time: %.4f'%(time.time()-time0),'no. elements: %d'%(Fhkl.size)2320 2321 2251 def FourierMap(data,reflDict): 2322 2252 '''default doc string … … 2388 2318 mapData['minmax'] = [np.max(mapData['rho']),np.min(mapData['rho'])] 2389 2319 2320 def Fourier4DMap(data,reflDict): 2321 '''default doc string 2322 2323 :param type name: description 2324 2325 :returns: type name: description 2326 2327 ''' 2328 generalData = data['General'] 2329 map4DData = generalData['4DmapData'] 2330 mapData = generalData['Map'] 2331 dmin = mapData['Resolution'] 2332 SGData = generalData['SGData'] 2333 SSGData = generalData['SSGData'] 2334 SSGMT = np.array([ops[0].T for ops in SSGData['SSGOps']]) 2335 SSGT = np.array([ops[1] for ops in SSGData['SSGOps']]) 2336 cell = generalData['Cell'][1:8] 2337 A = G2lat.cell2A(cell[:6]) 2338 maxM = generalData['SuperVec'][2] 2339 Hmax = G2lat.getHKLmax(dmin,SGData,A)+[maxM,] 2340 adjHKLmax(SGData,Hmax) 2341 Hmax = np.asarray(Hmax,dtype='i')+1 2342 Fhkl = np.zeros(shape=2*Hmax,dtype='c16') 2343 time0 = time.time() 2344 for iref,ref in enumerate(reflDict['RefList']): 2345 if ref[5] > dmin: 2346 Fosq,Fcsq,ph = ref[9:12] 2347 Fosq = np.where(Fosq>0.,Fosq,0.) #can't use Fo^2 < 0 2348 Uniq = np.inner(ref[:4],SSGMT) 2349 Phi = np.inner(ref[:4],SSGT) 2350 for i,hkl in enumerate(Uniq): #uses uniq 2351 hkl = np.asarray(hkl,dtype='i') 2352 dp = 360.*Phi[i] #and phi 2353 a = cosd(ph+dp) 2354 b = sind(ph+dp) 2355 phasep = complex(a,b) 2356 phasem = complex(a,-b) 2357 if 'Fobs' in mapData['MapType']: 2358 F = np.sqrt(Fosq) 2359 h,k,l,m = hkl+Hmax 2360 Fhkl[h,k,l,m] = F*phasep 2361 h,k,l,m = -hkl+Hmax 2362 Fhkl[h,k,l,m] = F*phasem 2363 elif 'Fcalc' in mapData['MapType']: 2364 F = np.sqrt(Fcsq) 2365 h,k,l,m = hkl+Hmax 2366 Fhkl[h,k,l,m] = F*phasep 2367 h,k,l,m = -hkl+Hmax 2368 Fhkl[h,k,l,m] = F*phasem 2369 elif 'delt-F' in mapData['MapType']: 2370 dF = np.sqrt(Fosq)-np.sqrt(Fcsq) 2371 h,k,l,m = hkl+Hmax 2372 Fhkl[h,k,l,m] = dF*phasep 2373 h,k,l,m = -hkl+Hmax 2374 Fhkl[h,k,l,m] = dF*phasem 2375 SSrho = fft.fftn(fft.fftshift(Fhkl))/cell[6] #4D map 2376 rho = fft.fftn(fft.fftshift(Fhkl[:,:,:,maxM+1]))/cell[6] #3D map 2377 map4DData['rho'] = np.real(SSrho) 2378 map4DData['rhoMax'] = max(np.max(map4DData['rho']),-np.min(map4DData['rho'])) 2379 map4DData['minmax'] = [np.max(map4DData['rho']),np.min(map4DData['rho'])] 2380 map4DData['Type'] = reflDict['Type'] 2381 mapData['Type'] = reflDict['Type'] 2382 mapData['rho'] = np.real(rho) 2383 mapData['rhoMax'] = max(np.max(mapData['rho']),-np.min(mapData['rho'])) 2384 mapData['minmax'] = [np.max(mapData['rho']),np.min(mapData['rho'])] 2385 print 'Fourier map time: %.4f'%(time.time()-time0),'no. elements: %d'%(Fhkl.size) 2386 2390 2387 # map printing for testing purposes 2391 2388 def printRho(SGLaue,rho,rhoMax): … … 2574 2571 np.seterr(**old) 2575 2572 print ' Charge flip time: %.4f'%(time.time()-time0),'no. elements: %d'%(Ehkl.size) 2576 CErho = np.real(fft.fftn(fft.fftshift(CEhkl))) 2573 CErho = np.real(fft.fftn(fft.fftshift(CEhkl)))/10. #? to get on same scale as e-map 2577 2574 print ' No.cycles = ',Ncyc,'Residual Rcf =%8.3f%s'%(Rcf,'%')+' Map size:',CErho.shape 2578 2575 roll = findOffset(SGData,A,CEhkl) #CEhkl needs to be just the observed set, not the full set! … … 2736 2733 np.seterr(**old) 2737 2734 print ' Charge flip time: %.4f'%(time.time()-time0),'no. elements: %d'%(Ehkl.size) 2738 CErho = np.real(fft.fftn(fft.fftshift(CEhkl[:,:,:,maxM+1]))) 2739 SSrho = np.real(fft.fftn(fft.fftshift(CEhkl))) 2735 CErho = np.real(fft.fftn(fft.fftshift(CEhkl[:,:,:,maxM+1])))/10. #? to get on same scale as e-map 2736 SSrho = np.real(fft.fftn(fft.fftshift(CEhkl)))/10. #? ditto 2740 2737 print ' No.cycles = ',Ncyc,'Residual Rcf =%8.3f%s'%(Rcf,'%')+' Map size:',CErho.shape 2741 2738 roll = findSSOffset(SGData,SSGData,A,CEhkl) #CEhkl needs to be just the observed set, not the full set! -
trunk/GSASIIstrMath.py
r2024 r2038 974 974 Mast = twopisq*np.multiply.outer(ast,ast) 975 975 SGInv = SGData['SGInv'] 976 SGMT = np.array([ops[0].T for ops in SGData['SGOps']]) 977 SGT = np.array([ops[1] for ops in SGData['SGOps']]) 976 978 SSGMT = np.array([ops[0].T for ops in SSGData['SSGOps']]) 977 979 SSGT = np.array([ops[1] for ops in SSGData['SSGOps']]) … … 1004 1006 FP = np.array([FFtables[El][hfx+'FP'] for El in Tdata]) 1005 1007 FPP = np.array([FFtables[El][hfx+'FPP'] for El in Tdata]) 1006 Uij = np.array(G2lat.U6toUij(Uijdata)) 1007 bij = Mast*Uij .T1008 Uij = np.array(G2lat.U6toUij(Uijdata)).T 1009 bij = Mast*Uij 1008 1010 blkSize = 100 #no. of reflections in a block 1009 1011 nRef = refDict['RefList'].shape[0] … … 1028 1030 refl = refDict['RefList'][iBeg:iFin] #array(blkSize,nItems) 1029 1031 H = refl.T[:4] #array(blkSize,4) 1032 HP = H[:3]+modQ[:,nxs]*H[3:] #projected hklm to hkl 1030 1033 # H = np.squeeze(np.inner(H.T,TwinLaw)) #maybe array(blkSize,nTwins,4) or (blkSize,4) 1031 1034 # TwMask = np.any(H,axis=-1) … … 1041 1044 SQfactor = 4.0*SQ*twopisq #ditto prev. 1042 1045 Uniq = np.inner(H.T,SSGMT) 1046 UniqP = np.inner(HP.T,SGMT) 1043 1047 Phi = np.inner(H.T,SSGT) 1048 PhiP = np.inner(HP.T,SGT) 1044 1049 if SGInv: #if centro - expand HKL sets 1045 1050 Uniq = np.hstack((Uniq,-Uniq)) 1046 1051 Phi = np.hstack((Phi,-Phi)) 1052 UniqP = np.hstack((UniqP,-UniqP)) 1053 PhiP = np.hstack((PhiP,-PhiP)) 1047 1054 if 'T' in calcControls[hfx+'histType']: 1048 1055 if 'P' in calcControls[hfx+'histType']: … … 1055 1062 Tindx = np.array([refDict['FF']['El'].index(El) for El in Tdata]) 1056 1063 FF = np.repeat(refDict['FF']['FF'][iBeg:iFin].T[Tindx].T,Uniq.shape[1]*len(TwinLaw),axis=0) 1057 phase = twopi*(np.inner(Uniq[:,:,:3],(dXdata.T+Xdata.T))+Phi[:,:,nxs]) #+TauT.T[nxs,:,:]*eps[nxs,:,nxs]1064 phase = twopi*(np.inner(Uniq[:,:,:3],(dXdata.T+Xdata.T))+Phi[:,:,nxs]) 1058 1065 sinp = np.sin(phase) 1059 1066 cosp = np.cos(phase) 1060 1067 biso = -SQfactor*Uisodata[:,nxs] 1061 1068 Tiso = np.repeat(np.where(biso<1.,np.exp(biso),1.0),Uniq.shape[1]*len(TwinLaw),axis=1).T 1062 HbH = -np.sum(Uniq [:,:,nxs,:3]*np.inner(Uniq[:,:,:3],bij),axis=-1)1069 HbH = -np.sum(UniqP[:,:,nxs,:]*np.inner(UniqP[:,:,:],bij),axis=-1) #use hklt proj to hkl 1063 1070 Tuij = np.where(HbH<1.,np.exp(HbH),1.0) 1064 Tcorr = np.reshape(Tiso,Tuij.shape)*Tuij*Mdata*Fdata/Uniq.shape[1] 1071 Tcorr = np.reshape(Tiso,Tuij.shape)*Tuij*Mdata*Fdata/Uniq.shape[1] #refBlk x ops x atoms 1065 1072 if 'T' in calcControls[hfx+'histType']: 1066 1073 fa = np.array([np.reshape(((FF+FP).T-Bab).T,cosp.shape)*cosp*Tcorr,-np.reshape(Flack*FPP,sinp.shape)*sinp*Tcorr]) … … 1069 1076 fa = np.array([np.reshape(((FF+FP).T-Bab).T,cosp.shape)*cosp*Tcorr,-Flack*FPP*sinp*Tcorr]) 1070 1077 fb = np.array([Flack*FPP*cosp*Tcorr,np.reshape(((FF+FP).T-Bab).T,sinp.shape)*sinp*Tcorr]) 1071 GfpuA = G2mth.Modulation(waveTypes,Uniq, FSSdata,XSSdata,USSdata,Mast) #2 x refBlk x sym X atoms1078 GfpuA = G2mth.Modulation(waveTypes,Uniq,UniqP,FSSdata,XSSdata,USSdata,Mast) #2 x refBlk x sym X atoms 1072 1079 fag = fa*GfpuA[0]-fb*GfpuA[1] #real; 2 x refBlk x sym x atoms 1073 1080 fbg = fb*GfpuA[0]+fa*GfpuA[1] 1074 1081 fas = np.sum(np.sum(fag,axis=-1),axis=-1) #2 x refBlk; sum sym & atoms 1075 1082 fbs = np.sum(np.sum(fbg,axis=-1),axis=-1) 1076 #GSASIIpath.IPyBreak()1083 # GSASIIpath.IPyBreak() 1077 1084 if 'P' in calcControls[hfx+'histType']: 1078 1085 refl.T[10] = np.sum(fas**2,axis=0)+np.sum(fbs**2,axis=0) … … 1098 1105 Mast = twopisq*np.multiply.outer(ast,ast) 1099 1106 SGInv = SGData['SGInv'] 1107 SGMT = np.array([ops[0].T for ops in SGData['SGOps']]) 1108 SGT = np.array([ops[1] for ops in SGData['SGOps']]) 1100 1109 SSGMT = np.array([ops[0].T for ops in SSGData['SSGOps']]) 1101 1110 SSGT = np.array([ops[1] for ops in SSGData['SSGOps']]) … … 1118 1127 if SGInv: 1119 1128 TauT = np.hstack((TauT,-TauT)) 1129 modQ = np.array([parmDict[pfx+'mV0'],parmDict[pfx+'mV1'],parmDict[pfx+'mV2']]) 1120 1130 FF = np.zeros(len(Tdata)) 1121 1131 if 'NC' in calcControls[hfx+'histType']: … … 1124 1134 FP = np.array([FFtables[El][hfx+'FP'] for El in Tdata]) 1125 1135 FPP = np.array([FFtables[El][hfx+'FPP'] for El in Tdata]) 1126 Uij = np.array(G2lat.U6toUij(Uijdata)) 1127 bij = Mast*Uij .T1136 Uij = np.array(G2lat.U6toUij(Uijdata)).T 1137 bij = Mast*Uij 1128 1138 if not len(refDict['FF']): 1129 1139 if 'N' in calcControls[hfx+'histType']: … … 1168 1178 FP,FPP = G2el.BlenResCW(Tdata,BLtables,refl.T[12+im]) 1169 1179 H = np.array(refl[:4]) 1180 HP = H[:3]+modQ*H[3:] #projected hklm to hkl 1170 1181 # H = np.squeeze(np.inner(H.T,TwinLaw)) #maybe array(4,nTwins) or (4) 1171 1182 # TwMask = np.any(H,axis=-1) … … 1184 1195 Uniq = np.inner(H,SSGMT) 1185 1196 Phi = np.inner(H,SSGT) 1197 UniqP = np.inner(HP,SGMT) 1198 PhiP = np.inner(HP,SGT) 1186 1199 if SGInv: #if centro - expand HKL sets 1187 1200 Uniq = np.vstack((Uniq,-Uniq)) 1188 1201 Phi = np.hstack((Phi,-Phi)) 1202 UniqP = np.vstack((UniqP,-UniqP)) 1203 PhiP = np.hstack((PhiP,-PhiP)) 1204 # GSASIIpath.IPyBreak() 1189 1205 phase = twopi*(np.inner(Uniq[:,:3],(dXdata+Xdata).T)+Phi[:,nxs]) 1190 1206 sinp = np.sin(phase) … … 1193 1209 biso = -SQfactor*Uisodata[:,nxs] 1194 1210 Tiso = np.repeat(np.where(biso<1.,np.exp(biso),1.0),Uniq.shape[0]*len(TwinLaw),axis=1).T #ops x atoms 1195 HbH = -np.sum(Uniq [:,nxs,:3]*np.inner(Uniq[:,:3],bij),axis=-1) #ops x atoms1196 Hij = np.array([Mast*np.multiply.outer(U[:3],U[:3]) for U in Uniq ]) #atoms x 3x31211 HbH = -np.sum(UniqP[:,nxs,:3]*np.inner(UniqP[:,:3],bij),axis=-1) #ops x atoms 1212 Hij = np.array([Mast*np.multiply.outer(U[:3],U[:3]) for U in UniqP]) #atoms x 3x3 1197 1213 Hij = np.squeeze(np.reshape(np.array([G2lat.UijtoU6(Uij) for Uij in Hij]),(nTwin,-1,6))) 1198 1214 Tuij = np.where(HbH<1.,np.exp(HbH),1.0) #ops x atoms … … 1200 1216 fot = (FF+FP-Bab)*Tcorr #ops x atoms 1201 1217 fotp = FPP*Tcorr #ops x atoms 1202 GfpuA,dGdf,dGdx,dGdu = G2mth.ModulationDerv(waveTypes,Uniq, Hij,FSSdata,XSSdata,USSdata,Mast)1218 GfpuA,dGdf,dGdx,dGdu = G2mth.ModulationDerv(waveTypes,Uniq,UniqP,Hij,FSSdata,XSSdata,USSdata,Mast) 1203 1219 # derivs are: ops x atoms x waves x 1,3,or 6 parms as [real,imag] parts 1204 1220 fa = np.array([((FF+FP).T-Bab).T*cosp*Tcorr,-Flack*FPP*sinp*Tcorr]) # array(2,nTwin,nEqv,nAtoms) … … 1220 1236 dfadui = np.sum(-SQfactor*fag,axis=1) 1221 1237 dfbdui = np.sum(-SQfactor*fbg,axis=1) 1222 # GSASIIpath.IPyBreak()1223 1238 if nTwin > 1: 1224 1239 dfadx = np.array([np.sum(twopi*Uniq[it,:,:3]*np.swapaxes(fax,-2,-1)[:,it,:,:,nxs],axis=-2) for it in range(nTwin)]) … … 1229 1244 dfadGx = np.sum(fa[:,it,:,:,nxs,nxs]*dGdx[0][nxs,nxs,:,:,:,:]-fb[:,it,:,:,nxs,nxs]*dGdx[1][nxs,nxs,:,:,:,:],axis=1) 1230 1245 dfbdGx = np.sum(fb[:,it,:,:,nxs,nxs]*dGdx[0][nxs,nxs,:,:,:,:]+fa[:,it,:,:,nxs,nxs]*dGdx[1][nxs,nxs,:,:,:,:],axis=1) 1246 dfadGx = np.sum(fa[:,it,:,:,nxs,nxs]*dGdu[0][nxs,nxs,:,:,:,:]-fb[:,it,:,:,nxs,nxs]*dGdu[1][nxs,nxs,:,:,:,:],axis=1) 1247 dfbdGx = np.sum(fb[:,it,:,:,nxs,nxs]*dGdu[0][nxs,nxs,:,:,:,:]+fa[:,it,:,:,nxs,nxs]*dGdu[1][nxs,nxs,:,:,:,:],axis=1) 1231 1248 # array (2,nAtom,wave,3) 1232 1249 else: … … 1238 1255 dfadGx = np.sum(fa[:,:,:,nxs,nxs]*dGdx[0][nxs,:,:,:,:]-fb[:,:,:,nxs,nxs]*dGdx[1][nxs,:,:,:,:],axis=1) 1239 1256 dfbdGx = np.sum(fb[:,:,:,nxs,nxs]*dGdx[0][nxs,:,:,:,:]+fa[:,:,:,nxs,nxs]*dGdx[1][nxs,:,:,:,:],axis=1) 1257 dfadGu = np.sum(fa[:,:,:,nxs,nxs]*dGdu[0][nxs,:,:,:,:]-fb[:,:,:,nxs,nxs]*dGdu[1][nxs,:,:,:,:],axis=1) 1258 dfbdGu = np.sum(fb[:,:,:,nxs,nxs]*dGdu[0][nxs,:,:,:,:]+fa[:,:,:,nxs,nxs]*dGdu[1][nxs,:,:,:,:],axis=1) 1240 1259 # array (2,nAtom,wave,3) 1241 1260 #NB: the above have been checked against PA(1:10,1:2) in strfctr.for for al2O3! … … 1257 1276 dFdua[iref] = 2.*(fas[0]*dfadua[0]+fas[1]*dfadua[1])+ \ 1258 1277 2.*(fbs[0]*dfbdua[0]+fbs[1]*dfbdua[1]) 1278 dFdGx[iref] = 2.*(fas[0]*dfadGx[0]+fas[1]*dfadGx[1])+ \ 1279 2.*(fbs[0]*dfbdGx[0]+fbs[1]*dfbdGx[1]) 1280 dFdGu[iref] = 2.*(fas[0]*dfadGu[0]+fas[1]*dfadGu[1])+ \ 1281 2.*(fbs[0]*dfbdGu[0]+fbs[1]*dfbdGu[1]) 1259 1282 else: 1260 1283 SA = fas[0]-fbs[1] … … 1266 1289 dFdua[iref] = [2.*TwMask[it]*(fas[0][it]*dfadua[it][0]+fas[1][it]*dfadua[it][1]+fbs[0][it]*dfbdua[it][0]+fbs[1][it]*dfbdua[it][1]) for it in range(nTwin)] 1267 1290 dFdGx[iref] = [2.*TwMask[it]*(fas[0][it]*dfadGx[0]+fas[1][it]*dfadGx[1]+fbs[0][it]*dfbdGx[0]+fbs[1][it]*dfbdGx[1]) for it in range(nTwin)] 1291 dFdGu[iref] = [2.*TwMask[it]*(fas[0][it]*dfadGu[0]+fas[1][it]*dfadGu[1]+fbs[0][it]*dfbdGu[0]+fbs[1][it]*dfbdGu[1]) for it in range(nTwin)] 1268 1292 dFdtw[iref] = np.sum(TwMask*fas,axis=0)**2+np.sum(TwMask*fbs,axis=0)**2 1269 1293 … … 1275 1299 dFdfl[iref] = -SA*dfadfl-SB*dfbdfl #array(nRef,) 1276 1300 dFdGx[iref] = 2.*(fas[0]*dfadGx[0]+fas[1]*dfadGx[1]+fbs[0]*dfbdGx[0]+fbs[1]*dfbdGx[1]) #array(nRef,natom,nwave,6) 1301 dFdGu[iref] = 2.*(fas[0]*dfadGu[0]+fas[1]*dfadGu[1]+fbs[0]*dfbdGu[0]+fbs[1]*dfbdGu[1]) #array(nRef,natom,nwave,6) 1277 1302 dFdbab[iref] = 2.*fas[0]*np.array([np.sum(dfadba*dBabdA),np.sum(-dfadba*parmDict[phfx+'BabA']*SQfactor*dBabdA)]).T+ \ 1278 1303 2.*fbs[0]*np.array([np.sum(dfbdba*dBabdA),np.sum(-dfbdba*parmDict[phfx+'BabA']*SQfactor*dBabdA)]).T … … 1299 1324 dFdvDict[pfx+'Ycos:'+str(i)+':'+str(j)] = dFdGx.T[4][j][i] 1300 1325 dFdvDict[pfx+'Zcos:'+str(i)+':'+str(j)] = dFdGx.T[5][j][i] 1326 for j in range(USSdata.shape[1]): 1327 dFdvDict[pfx+'U11sin:'+str(i)+':'+str(j)] = dFdGu.T[0][j][i] 1328 dFdvDict[pfx+'U22sin:'+str(i)+':'+str(j)] = dFdGu.T[1][j][i] 1329 dFdvDict[pfx+'U33sin:'+str(i)+':'+str(j)] = dFdGu.T[2][j][i] 1330 dFdvDict[pfx+'U12sin:'+str(i)+':'+str(j)] = dFdGu.T[3][j][i] 1331 dFdvDict[pfx+'U13sin:'+str(i)+':'+str(j)] = dFdGu.T[4][j][i] 1332 dFdvDict[pfx+'U23sin:'+str(i)+':'+str(j)] = dFdGu.T[5][j][i] 1333 dFdvDict[pfx+'U11cos:'+str(i)+':'+str(j)] = dFdGu.T[6][j][i] 1334 dFdvDict[pfx+'U22cos:'+str(i)+':'+str(j)] = dFdGu.T[7][j][i] 1335 dFdvDict[pfx+'U33cos:'+str(i)+':'+str(j)] = dFdGu.T[8][j][i] 1336 dFdvDict[pfx+'U12cos:'+str(i)+':'+str(j)] = dFdGu.T[9][j][i] 1337 dFdvDict[pfx+'U13cos:'+str(i)+':'+str(j)] = dFdGu.T[10][j][i] 1338 dFdvDict[pfx+'U23cos:'+str(i)+':'+str(j)] = dFdGu.T[11][j][i] 1339 1301 1340 dFdvDict[phfx+'BabA'] = dFdbab.T[0] 1302 1341 dFdvDict[phfx+'BabU'] = dFdbab.T[1] -
trunk/imports/G2phase.py
r1762 r2038 29 29 import GSASIIpath 30 30 GSASIIpath.SetVersionNumber("$Revision$") 31 R2pisq = 1./(2.*np.pi**2) 31 32 32 33 class PDB_ReaderClass(G2IO.ImportPhase): … … 402 403 float(cell[3]),float(cell[4]),float(cell[5])] 403 404 Volume = G2lat.calc_V(G2lat.cell2A(cell)) 405 G,g = G2lat.cell2Gmat(cell) 406 ast = np.sqrt(np.diag(G)) 407 Mast = np.multiply.outer(ast,ast) 408 404 409 elif 'spgroup' in S: 405 410 if 'X' in S: … … 479 484 Uiso = 0. 480 485 Uij = [float(S2[:9]),float(S2[9:18]),float(S2[18:27]), 481 float(S2[27:36]),float(S2[36:45]),float(S2[45:54])] 486 float(S2[27:36]),float(S2[36:45]),float(S2[45:54])] #these things are betaij! need to convert to Uij 487 Uij = R2pisq*G2lat.UijtoU6(G2lat.U6toUij(Uij)/Mast) 482 488 for i in range(S1N[0]): 483 489 if not i: … … 516 522 Spos[i] = [vals,False] 517 523 for i,it in enumerate(Sadp): 524 #these are betaij modulations! need to convert to Uij modulations 518 525 vals = [float(it[:9]),float(it[9:18]),float(it[18:27]),float(it[27:36]),float(it[36:45]),float(it[45:54]), 519 526 float(it[54:63]),float(it[63:72]),float(it[72:81]),float(it[81:90]),float(it[90:99]),float(it[99:108])] 527 vals[:6] = R2pisq*G2lat.UijtoU6(G2lat.U6toUij(vals[:6])/Mast) #convert sin bij to Uij 528 vals[6:] = R2pisq*G2lat.UijtoU6(G2lat.U6toUij(vals[6:])/Mast) #convert cos bij to Uij 520 529 Sadp[i] = [vals,False] 521 530 Atom = [Name,aType,'',XYZ[0],XYZ[1],XYZ[2],1.0,SytSym,Mult,IA,Uiso] -
trunk/imports/G2phase_CIF.py
r1985 r2038 196 196 '_atom_site_aniso_u_13' : 15, 197 197 '_atom_site_aniso_u_23' : 16, } 198 G2SSAtomDict = {'_atom_site_occ_Fourier_wave_vector_seq_id' : 1, 199 '_atom_site_occ_Fourier_param_cos' : 2, 200 '_atom_site_occ_Fourier_param_sin' : 3, 201 '_atom_site_displace_Fourier_axis' : 2, 202 '_atom_site_displace_Fourier_wave_vector_seq_id' : 3, 203 '_atom_site_displace_Fourier_param_cos' : 5, 204 '_atom_site_displace_Fourier_param_sin' : 4, 205 '_atom_site_U_Fourier_tens_elem' : 7, 206 '_atom_site_U_Fourier_wave_vector_seq_id' : 8, 207 '_atom_site_U_Fourier_param_cos' : 9, 208 '_atom_site_U_Fourier_param_sin' : 10, } 209 210 211 198 212 ranIdlookup = {} 199 213 for aitem in atomloop: -
trunk/imports/G2sfact.py
r1924 r2038 76 76 self.RefDict['Type'] = 'SXC' 77 77 self.RefDict['Super'] = 0 78 self.UpdateParameters(Type='SXC',Wave=None) # histogram type 79 return True 80 except Exception as detail: 81 self.errors += '\n '+str(detail) 82 print '\n\n'+self.formatName+' read error: '+str(detail) # for testing 83 import traceback 84 traceback.print_exc(file=sys.stdout) 85 return False 86 87 class HKLMF_ReaderClass(G2IO.ImportStructFactor): 88 'Routines to import F, reflections from a REMOS HKLMF file' 89 def __init__(self): 90 super(self.__class__,self).__init__( # fancy way to self-reference 91 extensionlist=('.fo','.FO'), 92 strictExtension=False, 93 formatName = 'HKLM F', 94 longFormatName = 'REMOS [hklm, Fo] Structure factor text file' 95 ) 96 97 def ContentsValidator(self, filepointer): 98 'Make sure file contains the expected columns on numbers' 99 return ColumnValidator(self, filepointer) 100 101 def Reader(self,filename,filepointer, ParentFrame=None, **unused): 102 'Read the file' 103 try: 104 for line,S in enumerate(filepointer): 105 self.errors = ' Error reading line '+str(line+1) 106 if S[0] == '#': continue #ignore comments, if any 107 h,k,l,m,Fo= S.split() 108 h,k,l,m = [int(h),int(k),int(l),int(m)] 109 if h == 999 or not any([h,k,l]): 110 break 111 Fo = float(Fo) 112 sigFo2 = Fo 113 if Fo < 1.0: 114 sigFo2 = 1.0 115 # h,k,l,m,tw,dsp,Fo2,sig,Fc2,Fot2,Fct2,phase,... 116 self.RefDict['RefList'].append([h,k,l,m,1,0,Fo**2,sigFo2,0,Fo**2,0,0,0]) 117 self.errors = 'Error after reading reflections (unexpected!)' 118 self.RefDict['RefList'] = np.array(self.RefDict['RefList']) 119 self.RefDict['Type'] = 'SXC' 120 self.RefDict['Super'] = 1 78 121 self.UpdateParameters(Type='SXC',Wave=None) # histogram type 79 122 return True
Note: See TracChangeset
for help on using the changeset viewer.