Changeset 1957 for trunk/GSASIImath.py


Ignore:
Timestamp:
Aug 14, 2015 3:08:55 PM (8 years ago)
Author:
vondreele
Message:

work on SS structure factors
some refactoring of SS special pos code
rearrange sf routines in G2strMath - some math error in the SS sf codes
make SS plots of structure behave properly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIImath.py

    r1956 r1957  
    924924################################################################################
    925925   
    926 def Modulation(waveTypes,SSUniq,SSPhi,FSSdata,XSSdata,USSdata):
     926def Modulation(waveTypes,SSUniq,SSPhi,FSSdata,XSSdata,USSdata,SStauM):
    927927    import scipy.special as sp
    928928    import scipy.integrate as si
     929    Smult,TauT = SStauM             # both atoms x SGops
    929930    m = SSUniq.T[3]
    930931    nh = np.zeros(1)
    931932    if XSSdata.ndim > 2:
    932         nh = np.arange(XSSdata.shape[1])       
    933     M = np.where(m>0,m+nh[:,np.newaxis],m-nh[:,np.newaxis])
    934     A = np.array(XSSdata[:3])
    935     B = np.array(XSSdata[3:])
    936     HdotA = (np.inner(A.T,SSUniq.T[:3].T)+SSPhi)
    937     HdotB = (np.inner(B.T,SSUniq.T[:3].T)+SSPhi)
    938     GpA = sp.jn(M[:,np.newaxis],twopi*HdotA)
    939     GpB = sp.jn(M[:,np.newaxis],twopi*HdotB)*(1.j)**M
    940     Gp = np.sum(GpA+GpB,axis=0)
    941     return np.real(Gp).T,np.imag(Gp).T
    942    
    943 def ModulationDerv(waveTypes,SSUniq,SSPhi,FSSdata,XSSdata,USSdata):
     933        nh = np.arange(XSSdata.shape[1])        #0..max harmonic order-1
     934    M = np.where(m>0,m+nh[:,np.newaxis],m-nh[:,np.newaxis])     # waves x SGops
     935    A = np.array(XSSdata[:3])   #sin mods x waves x atoms
     936    B = np.array(XSSdata[3:])   #cos mods...
     937    HdotA = (np.inner(A.T,SSUniq.T[:3].T)+SSPhi+TauT[:,np.newaxis,:])    # atoms X waves x SGops
     938    HdotB = (np.inner(B.T,SSUniq.T[:3].T)+SSPhi)    #+TauT[:,np.newaxis,:])    # ditto
     939    GpA = sp.jn(M,twopi*HdotA)                      # atoms x waves x SGops
     940    GpB = sp.jn(M,twopi*HdotB)*(1.j)**M             # ditto
     941    Gp = np.sum(GpA+GpB,axis=1)                     # atoms x SGops
     942    return np.real(Gp).T,np.imag(Gp).T              # SGops x atoms
     943   
     944def ModulationDerv(waveTypes,SSUniq,SSPhi,FSSdata,XSSdata,USSdata,SStauM):
    944945    import scipy.special as sp
    945946    m = SSUniq.T[3]
     
    950951    A = np.array([[a,b] for a,b in zip(XSSdata[:3],XSSdata[3:])])
    951952    HdotA = twopi*(np.inner(SSUniq.T[:3].T,A.T)+SSPhi)
    952     Gpm = sp.jn(M[:,np.newaxis,:]-1,HdotA)
    953     Gpp = sp.jn(M[:,np.newaxis,:]+1,HdotA)
     953    Gpm = sp.jn(M-1,HdotA)
     954    Gpp = sp.jn(M+1,HdotA)
    954955    if Gpm.ndim > 3: #sum over multiple harmonics
    955956        Gpm = np.sum(Gpm,axis=0)
     
    958959    return np.real(dGpdk),np.imag(dGpdk)
    959960   
    960 def posFourier(tau,psin,pcos):
    961     A = np.array([ps[:,np.newaxis]*np.sin(2*np.pi*(i+1)*tau) for i,ps in enumerate(psin)])
     961def posFourier(tau,psin,pcos,smul):
     962    A = np.array([ps[:,np.newaxis]*np.sin(2*np.pi*(i+1)*tau) for i,ps in enumerate(psin)])*smul
    962963    B = np.array([pc[:,np.newaxis]*np.cos(2*np.pi*(i+1)*tau) for i,pc in enumerate(pcos)])
    963964    return np.sum(A,axis=0)+np.sum(B,axis=0)
     
    988989    generalData = data['General']
    989990    SGData = generalData['SGData']
     991    SSGData = generalData['SSGData']
    990992    cx,ct,cs,cia = generalData['AtomPtrs']
    991993    drawingData = data['Drawing']
     
    9991001        Spos = atom[-1]['SS1']['Spos']
    10001002        Sadp = atom[-1]['SS1']['Sadp']
    1001         wave = np.zeros(3)
    1002         uwave = np.zeros(6)
    1003         if len(Spos):
    1004             scof = []
    1005             ccof = []
    1006             for i,spos in enumerate(Spos):
    1007                 if waveType in ['Sawtooth','ZigZag'] and not i:
    1008                     Toff = spos[0][0]
    1009                     slopes = np.array(spos[0][1:])
    1010                     if waveType == 'Sawtooth':
    1011                         wave = posSawtooth(tau,Toff,slopes)
    1012                     elif waveType == 'ZigZag':
    1013                         wave = posZigZag(tau,Toff,slopes)
    1014                 else:
    1015                     scof.append(spos[0][:3])
    1016                     ccof.append(spos[0][3:])
    1017             wave += np.sum(posFourier(tau,np.array(scof),np.array(ccof)),axis=1)
    1018         if len(Sadp):
    1019             scof = []
    1020             ccof = []
    1021             for i,sadp in enumerate(Sadp):
    1022                 scof.append(sadp[0][:6])
    1023                 ccof.append(sadp[0][6:])
    1024             uwave += np.sum(posFourier(tau,np.array(scof),np.array(ccof)),axis=1)
    10251003        indx = FindAtomIndexByIDs(drawAtoms,dci,[atom[cia+8],],True)
    10261004        for ind in indx:
    10271005            drawatom = drawAtoms[ind]
    10281006            opr = drawatom[dcs-1]
     1007            sop,ssop,icent = G2spc.OpsfromStringOps(opr,SGData,SSGData)
     1008            sdet,ssdet,dtau,dT,tauT = G2spc.getTauT(tau,sop,ssop,atxyz)
     1009            smul = sdet*ssdet
     1010#            tauT *= icent
     1011            wave = np.zeros(3)
     1012            uwave = np.zeros(6)
     1013            if len(Spos):
     1014                scof = []
     1015                ccof = []
     1016                for i,spos in enumerate(Spos):
     1017                    if waveType in ['Sawtooth','ZigZag'] and not i:
     1018                        Toff = spos[0][0]
     1019                        slopes = np.array(spos[0][1:])
     1020                        if waveType == 'Sawtooth':
     1021                            wave = posSawtooth(tauT,Toff,slopes)
     1022                        elif waveType == 'ZigZag':
     1023                            wave = posZigZag(tauT,Toff,slopes)
     1024                    else:
     1025                        scof.append(spos[0][:3])
     1026                        ccof.append(spos[0][3:])
     1027                wave += np.sum(posFourier(tauT,np.array(scof),np.array(ccof),smul),axis=1)
     1028            if len(Sadp):
     1029                scof = []
     1030                ccof = []
     1031                for i,sadp in enumerate(Sadp):
     1032                    scof.append(sadp[0][:6])
     1033                    ccof.append(sadp[0][6:])
     1034                uwave += np.sum(posFourier(tauT,np.array(scof),np.array(ccof),smul),axis=1)
    10291035            if atom[cia] == 'A':                   
    10301036                X,U = G2spc.ApplyStringOps(opr,SGData,atxyz+wave,atuij+uwave)
     
    20762082                    h,k,l,m = -hkl+Hmax
    20772083                    Fhkl[h,k,l,m] = F*phasem
     2084                elif 'Fcalc' in mapData['MapType']:
     2085                    F = np.where(Fcsq>0.,np.sqrt(Fcsq),0.)
     2086                    h,k,l,m = hkl+Hmax
     2087                    Fhkl[h,k,l,m] = F*phasep
     2088                    h,k,l,m = -hkl+Hmax
     2089                    Fhkl[h,k,l,m] = F*phasem                   
    20782090                elif 'delt-F' in mapData['MapType']:
    20792091                    dF = np.where(Fosq>0.,np.sqrt(Fosq),0.)-np.sqrt(Fcsq)
Note: See TracChangeset for help on using the changeset viewer.