Changeset 5515


Ignore:
Timestamp:
Mar 16, 2023 5:56:09 AM (2 years ago)
Author:
vondreele
Message:

fixes to spin RB derivatives

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/GSASIIstrMath.py

    r5513 r5515  
    364364       
    365365    dFFdS = {}
     366    atFlg = []
    366367    for iAt,Atype in enumerate(Tdata):
    367368        if 'Q' in Atype:
     369            atFlg.append(1.0)
    368370            SHdat = SHCdict[iAt]
    369371            symAxis = np.array(SHdat['symAxis'])
     
    387389            FF[:,iAt] = 0.
    388390            ishl = 0
     391#            dBSdR = np.zeros(HKL.shape[0]*HKL.shape[1])
     392            dSHdO = np.zeros(HKL.shape[0]*HKL.shape[1])
     393            dSHdOi = np.zeros(HKL.shape[0]*HKL.shape[1])
     394            dSHdOj = np.zeros(HKL.shape[0]*HKL.shape[1])
     395            dSHdOk = np.zeros(HKL.shape[0]*HKL.shape[1])
    389396            while True:
    390397                shl = '%d'%ishl
     
    407414                R0M = sp.spherical_jn(0,QR*(R-0.01))/(4.*np.pi)
    408415                dBSdR = Nat*SFF*(R0P-R0M)/0.02
    409                 dSHdO = np.zeros(HKL.shape[0]*HKL.shape[1])
    410                 dSHdOi = np.zeros(HKL.shape[0]*HKL.shape[1])
    411                 dSHdOj = np.zeros(HKL.shape[0]*HKL.shape[1])
    412                 dSHdOk = np.zeros(HKL.shape[0]*HKL.shape[1])
    413416                FF[:,iAt] += Nat*SFF*R0    #Bessel function; L=0 term
    414417                for item in Shell:
     
    438441                        dFFdS[name] = Nat*SFF*BS*SH
    439442                        #fill derivatives here wrt iAt,ishl,item or l,m
     443                ishl += 1
    440444                dFFdS[Rname] = dBSdR
    441                 dFFdS[Oname] = dSHdO
    442                 dFFdS[Oiname] = dSHdOi
    443                 dFFdS[Ojname] = dSHdOj
    444                 dFFdS[Okname] = dSHdOk
    445                 ishl += 1
     445            dFFdS[Oname] = dSHdO
     446            dFFdS[Oiname] = dSHdOi
     447            dFFdS[Ojname] = dSHdOj
     448            dFFdS[Okname] = dSHdOk
     449        else:
     450            atFlg.append(0.)
    446451    if ifDeriv:
    447         return dFFdS   
     452        return dFFdS,atFlg   
    448453           
    449454def GetSHC(pfx,parmDict):
     
    10651070        return {}
    10661071    mSize = len(Mdata)
     1072    nOps = len(SGMT)
    10671073    FF = np.zeros(len(Tdata))
    10681074    if 'NC' in calcControls[hfx+'histType'] or 'NB' in calcControls[hfx+'histType']:
     
    10781084    dFdvDict = {}
    10791085    dFdfr = np.zeros((nRef,mSize))
    1080     dFdff = np.zeros((nRef,mSize))
     1086    dFdff = np.zeros((nRef,nOps,mSize))
    10811087    dFdx = np.zeros((nRef,mSize,3))
    10821088    dFdui = np.zeros((nRef,mSize))
     
    11231129        Hij = np.reshape(np.array([G2lat.UijtoU6(uij) for uij in Hij]),(-1,len(SGT),6))     #Nref,Nops,6
    11241130        if len(SHCdict):
    1125             dffdsh = MakeSpHarmFF(Uniq,Bmat,SHCdict,Tdata,hType,FFtables,BLtables,FF,SQ,True)
     1131            dffdsh,atFlg = MakeSpHarmFF(Uniq,Bmat,SHCdict,Tdata,hType,FFtables,BLtables,FF,SQ,True)
    11261132            if len(dffdSH):
    11271133                for item in dffdSH:
     
    11461152        #sum below is over Uniq
    11471153        dfadfr = np.sum(fa/occ,axis=-2)        #array(2,refBlk,nAtom) Fdata != 0 avoids /0. problem
    1148         dfadff = np.sum(fa[0]*Tcorr/fot,axis=-2)           #ignores resonant scattering? #TODO needs only for Q atoms!
    1149         for i,aname in enumerate(Tdata):
    1150             if 'Q' not in aname:
    1151                 dfadff[:,i] = 0.0
     1154#        dfadff = np.sum(fa[0]*Tcorr*atFlg/fot,axis=-2)           #ignores resonant scattering? #TODO needs only for Q atoms!
     1155        dfadff = fa[0]*Tcorr*atFlg/fot           #ignores resonant scattering? no sum on Uniq
    11521156        dfadba = np.sum(-cosp*Tcorr,axis=-2)  #array(refBlk,nAtom)
    11531157        dfadx = np.sum(twopi*Uniq[nxs,:,nxs,:,:]*np.swapaxes(fax,-2,-1)[:,:,:,:,nxs],axis=-2)
     
    11571161        if not SGData['SGInv']:
    11581162            dfbdfr = np.sum(fb/occ,axis=-2)        #Fdata != 0 avoids /0. problem
    1159             dfbdff = np.sum(fb[0]*Tcorr/fot,axis=-2)           #ignores resonant scattering?
    1160             for i,aname in enumerate(Tdata):
    1161                 if 'Q' not in aname:
    1162                     dfbdff[:,i] = 0.0
     1163#            dfbdff = np.sum(fb[0]*Tcorr*atFlg/fot,axis=-2)           #ignores resonant scattering?
     1164            dfbdff = fb[0]*Tcorr*atFlg/fot           #ignores resonant scattering? no sum on Uniq
    11631165            dfbdba = np.sum(-sinp*Tcorr,axis=-2)
    11641166            dfadfl = np.sum(np.sum(-fotp*sinp,axis=-1),axis=-1)
     
    11811183        if 'P' in calcControls[hfx+'histType']: #checked perfect for centro & noncentro
    11821184            dFdfr[iBeg:iFin] = 2.*np.sum(fas[:,:,nxs]*dfadfr+fbs[:,:,nxs]*dfbdfr,axis=0)*Mdata/len(SGMT)
    1183             dFdff[iBeg:iFin] = 2.*np.sum(fas[:,:,nxs]*dfadff+fbs[:,:,nxs]*dfbdff,axis=0)/len(SGMT)
     1185#            dFdff[iBeg:iFin] = 2.*np.sum(fas[:,:,nxs]*dfadff+fbs[:,:,nxs]*dfbdff,axis=0)/len(SGMT)
     1186            dFdff[iBeg:iFin] = 2.*np.sum(fas[:,:,nxs,nxs]*dfadff[nxs,:,:,:]+fbs[:,:,nxs,nxs]*dfbdff[nxs,:,:,:],axis=0) #not summed on Uniq yet
    11841187            dFdx[iBeg:iFin] = 2.*np.sum(fas[:,:,nxs,nxs]*dfadx+fbs[:,:,nxs,nxs]*dfbdx,axis=0)
    11851188            dFdui[iBeg:iFin] = 2.*np.sum(fas[:,:,nxs]*dfadui+fbs[:,:,nxs]*dfbdui,axis=0)
     
    11871190        else:
    11881191            dFdfr[iBeg:iFin] = (2.*SA[:,nxs]*(dfadfr[0]+dfadfr[1])+2.*SB[:,nxs]*(dfbdfr[0]+dfbdfr[1]))*Mdata/len(SGMT)
    1189             dFdff[iBeg:iFin] = (2.*SA[:,nxs]*dfadff+2.*SB[:,nxs]*dfbdff)/len(SGMT)
     1192#            dFdff[iBeg:iFin] = (2.*SA[:,nxs]*dfadff+2.*SB[:,nxs]*dfbdff)/len(SGMT)
     1193            dFdff[iBeg:iFin] = (2.*SA[:,nxs,nxs]*dfadff+2.*SB[:,nxs,nxs]*dfbdff)      #not summed on Uniq yet
    11901194            dFdx[iBeg:iFin] = 2.*SA[:,nxs,nxs]*(dfadx[0]+dfadx[1])+2.*SB[:,nxs,nxs]*(dfbdx[0]+dfbdx[1])
    11911195            dFdui[iBeg:iFin] = 2.*SA[:,nxs]*(dfadui[0]+dfadui[1])+2.*SB[:,nxs]*(dfbdui[0]+dfbdui[1])
     
    12101214        dFdvDict[pfx+'AU23:'+str(i)] = dFdua.T[5][i]
    12111215        for item in dffdSH:
    1212             dFdvDict[pfx+'RBS'+item] = dFdff.T[i]*np.sum(np.reshape(dffdSH[item],(nRef,-1)),axis=-1)
     1216            i = int(item.split(':')[1])
     1217            dFdvDict[pfx+'RBS'+item] = np.sum(dFdff[:,:,i]*np.reshape(dffdSH[item],(nRef,-1)),axis=-1)
    12131218    dFdvDict[phfx+'Flack'] = 4.*dFdfl.T
    12141219    dFdvDict[phfx+'BabA'] = dFdbab.T[0]
Note: See TracChangeset for help on using the changeset viewer.