Skip to content

Commit 9c0f4c7

Browse files
committed
geometry fixes for deformation calcs. Now correct!
1 parent fdd954c commit 9c0f4c7

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

GSASII/GSASIIlattice.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2938,7 +2938,7 @@ def H2ThPh2(H,Bmat):
29382938
:returns array Ph: HKL polar angles
29392939
'''
29402940
Hcart = np.inner(H,Bmat)
2941-
R = np.sqrt(np.sum(np.square(Hcart),axis=1))
2941+
R = nl.norm(Hcart,axis=1)
29422942
Hcart /= R[:,nxs]
29432943
Pl = acosd(Hcart[:,2])
29442944
Az = atan2d(Hcart[:,1],Hcart[:,0])
@@ -2991,7 +2991,7 @@ def SHarmcal(SytSym,SHFln,psi,gam):
29912991
SHVal += (SHFln[term][0]*Ksl)
29922992
return SHVal
29932993

2994-
def KslCalc(trm,psi,gam):
2994+
def KslCalc(trm,psi,gam,RI=False):
29952995
'''Compute one angular part term in spherical harmonics
29962996
29972997
:param str trm:sp. harm term name in the form of 'C(l,m)' or 'C(l,m)c' for cubic
@@ -3002,9 +3002,21 @@ def KslCalc(trm,psi,gam):
30023002
'''
30033003
l,m = eval(trm.strip('C').strip('c'))
30043004
if 'c' in trm:
3005-
return CubicSHarm(l,m,psi,gam)
3005+
if not RI:
3006+
return CubicSHarm(l,m,psi,gam)
3007+
else:
3008+
return CubicSHarm(l,m,psi,gam),0.0
3009+
30063010
else:
3007-
return SphHarmAng(l,m,1.0,psi,gam)
3011+
if not RI:
3012+
return SphHarmAng(l,m,1.0,psi,gam)
3013+
else:
3014+
try:
3015+
#### TODO: this will be deprecated in scipy 1.17.0
3016+
ylmp = SQ2*spsp.sph_harm(m,l,rpd*psi,rpd*gam)*(-1)**m #wants radians; order then degree
3017+
except AttributeError: #new one sph_harm_y in scipy 1.15.1 but buggy?
3018+
ylmp = SQ2*spsp.sph_harm_y(l,m,rpd*psi,rpd*gam)*(-1)**m #order L,M makes more sense
3019+
return np.real(ylmp),np.imag(ylmp)
30083020

30093021
def SphHarmAng(L,M,P,Th,Ph):
30103022
''' Compute spherical harmonics values using scipy.special.sph_harm

GSASII/GSASIIphsGUI2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def MakeUVmat(defData,U,V):
243243
MY /= nl.norm(MY)
244244
MX = np.cross(MY,MZ)
245245
MX /= nl.norm(MX)
246-
return np.array([MX,MY,MZ]).T
246+
return np.vstack((MX,MY,MZ)).T
247247

248248
def OnDeformRef(event):
249249
Obj = event.GetEventObject()

GSASII/GSASIIplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7359,8 +7359,8 @@ def Draw(caller='',Fade=[],NPkey=False):
73597359
Npsi,Ngam = 60,30
73607360
PSI,GAM = np.mgrid[0:Npsi,0:Ngam] #[azm,pol]
73617361
PSI = PSI.flatten()*360./Npsi #azimuth 0-360 incl
7362-
PSI += 90.
73637362
GAM = GAM.flatten()*180./Ngam #polar 0-180 incl
7363+
PSI += 90.
73647364
Rp,PSIp,GAMp = G2mth.RotPolbyM(np.ones_like(PSI),PSI,GAM,UVMat)
73657365
P = G2lat.SHarmcal(SytSym,SHC,PSIp,GAMp).reshape((Npsi,Ngam))
73667366
if np.min(P) < np.max(P):

GSASII/GSASIIstrMath.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,11 @@ def MakePolar(Orient,QB):
450450
QA = G2mth.invQ(Orient) #rotates about chosen axis
451451
Q = G2mth.prodQQ(QA,QB) #might be switched? QB,QA is order for plotting
452452
M = np.inner(G2mth.Q2Mat(Q),Bmat)
453-
return G2lat.H2ThPh2(np.reshape(HKL,(-1,3)),M)[1:]
453+
return G2lat.H2ThPh2(hkl,M)[1:]
454454

455455
dFFdS = {}
456456
atFlg = []
457+
hkl = np.reshape(HKL,(-1,3))
457458
SQR = np.repeat(SQ,HKL.shape[1])
458459
for iAt,Atype in enumerate(Tdata):
459460
if 'Q' in Atype: #spinning RB
@@ -551,9 +552,9 @@ def MakePolar(Orient,QB):
551552
orKeys = [item for item in ORBtables[Atype] if item not in ['Slater','ZSlater','NSlater','SZE','popCore','popVal']]
552553
orKeys = [item for item in orKeys if 'Sl' in item]
553554
orbs = SHCdict[iAt]['1']
554-
UVmat = np.inner(SHCdict[-iAt]['UVmat'],Bmat)
555-
R,Th,Ph = G2lat.H2ThPh2(np.reshape(HKL,(-1,3)),UVmat) #radius,azimuth,polar
556-
# R = 1/R # correct dspacings - not used
555+
UVmat = np.inner(SHCdict[-iAt]['UVmat'],Bmat) #OK
556+
R,Th,Ph = G2lat.H2ThPh2(hkl,UVmat) #radius,azimuth,polar - OK
557+
R = 1./R # d-spacing for diagnostics - OK
557558
atFlg.append(1.0)
558559
orbTable = ORBtables[Atype] # should point at Sl core
559560
ffOrb = orbTable['Sl core']

0 commit comments

Comments
 (0)