Changeset 902 for trunk/GSASIImath.py


Ignore:
Timestamp:
May 10, 2013 3:07:50 PM (12 years ago)
Author:
vondreele
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/GSASIImath.py

    r889 r902  
    203203        if atom[cia] == 'A':
    204204            UIJ = atom[cia+2:cia+8]
     205               
     206def TLS2Uij(xyz,g,Amat,rbObj):
     207    TLStype,TLS = rbObj['ThermalMotion'][:2]
     208    Tmat = np.zeros((3,3))
     209    Lmat = np.zeros((3,3))
     210    Smat = np.zeros((3,3))
     211    gvec = np.sqrt(np.array([g[0][0]**2,g[1][1]**2,g[2][2]**2,
     212        g[0][0]*g[1][1],g[0][0]*g[2][2],g[1][1]*g[2][2]]))
     213    if 'T' in TLStype:
     214        Tmat = G2lat.U6toUij(TLS[:6])
     215    if 'L' in TLStype:
     216        Lmat = G2lat.U6toUij(TLS[6:12])
     217    if 'S' in TLStype:
     218        Smat = np.array([[TLS[18],TLS[12],TLS[13]],[TLS[14],TLS[19],TLS[15]],[TLS[16],TLS[17],0] ])
     219    XYZ = np.inner(Amat,xyz)
     220    Axyz = np.array([[ 0,XYZ[2],-XYZ[1]], [-XYZ[2],0,XYZ[0]], [XYZ[1],-XYZ[0],0]] )
     221    Umat = Tmat+np.inner(Axyz,Smat)+np.inner(Smat.T,Axyz.T)+np.inner(np.inner(Axyz,Lmat),Axyz.T)
     222    beta = np.inner(np.inner(g,Umat),g)
     223    return G2lat.UijtoU6(beta)*gvec   
    205224       
    206225def AtomTLS2UIJ(atomData,atPtrs,Amat,rbObj):
     
    217236        Lmat = G2lat.U6toUij(TLS[6:12])
    218237    if 'S' in TLStype:
    219         Smat = np.array([[TLS[18],TLS[12],S[13]],[TLS[14],TLS[19],TLS[15]],[TLS[16],TLS[17],0]])
     238        Smat = np.array([ [TLS[18],TLS[12],TLS[13]], [TLS[14],TLS[19],TLS[15]], [TLS[16],TLS[17],0] ])
    220239    for atom in atomData:
    221240        XYZ = np.inner(Amat,atom[cx:cx+3])
    222         Axyz = np.array([0,XYZ[2],-XYZ[1]],[-XYZ[2],0,XYZ[0]],[XYZ[1],-XYZ[0],0])
     241        Axyz = np.array([ 0,XYZ[2],-XYZ[1], -XYZ[2],0,XYZ[0], XYZ[1],-XYZ[0],0],ndmin=2 )
    223242        if 'U' in TSLtype:
    224243            atom[cia+1] = TLS[0]
     
    352371    for j,xyz in enumerate(XYZ):
    353372        for i,x in enumerate(np.array([[dx,0,0],[0,dx,0],[0,0,dx]])):
    354             XYZ[j] += x
     373            XYZ[j] -= x
    355374            d1 = Func(getSyXYZ(XYZ,ops,SGData),Amat)
    356             XYZ[j] -= 2*x
     375            XYZ[j] += 2*x
    357376            d2 = Func(getSyXYZ(XYZ,ops,SGData),Amat)
    358             XYZ[j] += x
     377            XYZ[j] -= x
    359378            deriv[j][i] = (d1-d2)/(2*dx)
    360379    return deriv.flatten()
     
    432451    for j,xyz in enumerate(XYZ):
    433452        for i,x in enumerate(np.array([[dx,0,0],[0,dx,0],[0,0,dx]])):
    434             XYZ[j] += x
     453            XYZ[j] -= x
    435454            tor = getRestTorsion(XYZ,Amat)
    436455            p,d1 = calcTorsionEnergy(tor,Coeff)
    437             XYZ[j] -= 2*x
     456            XYZ[j] += 2*x
    438457            tor = getRestTorsion(XYZ,Amat)
    439458            p,d2 = calcTorsionEnergy(tor,Coeff)           
    440             XYZ[j] += x
    441             deriv[j][i] = (d1-d2)/(2*dx)
     459            XYZ[j] -= x
     460            deriv[j][i] = (d2-d1)/(2*dx)
    442461    return deriv.flatten()
    443462
     
    469488    for j,xyz in enumerate(XYZ):
    470489        for i,x in enumerate(np.array([[dx,0,0],[0,dx,0],[0,0,dx]])):
    471             XYZ[j] += x
     490            XYZ[j] -= x
    472491            phi,psi = getRestRama(XYZ,Amat)
    473492            p,d1 = calcRamaEnergy(phi,psi,Coeff)
    474             XYZ[j] -= 2*x
     493            XYZ[j] += 2*x
    475494            phi,psi = getRestRama(XYZ,Amat)
    476495            p,d2 = calcRamaEnergy(phi,psi,Coeff)
    477             XYZ[j] += x
    478             deriv[j][i] = (d1-d2)/(2*dx)
     496            XYZ[j] -= x
     497            deriv[j][i] = (d2-d1)/(2*dx)
    479498    return deriv.flatten()
    480499
     
    505524    deriv = np.zeros(6)
    506525    for i in [0,1,2]:
    507         Oxyz[i] += dx
     526        Oxyz[i] -= dx
    508527        d0 = calcDist(Oxyz,Txyz,Tunit,inv,C,M,T,Amat)
    509         Oxyz[i] -= 2*dx
     528        Oxyz[i] += 2*dx
    510529        deriv[i] = (calcDist(Oxyz,Txyz,Tunit,inv,C,M,T,Amat)-d0)/(2.*dx)
    511         Oxyz[i] += dx
    512         Txyz[i] += dx
     530        Oxyz[i] -= dx
     531        Txyz[i] -= dx
    513532        d0 = calcDist(Oxyz,Txyz,Tunit,inv,C,M,T,Amat)
    514         Txyz[i] -= 2*dx
     533        Txyz[i] += 2*dx
    515534        deriv[i+3] = (calcDist(Oxyz,Txyz,Tunit,inv,C,M,T,Amat)-d0)/(2.*dx)
    516         Txyz[i] += dx
     535        Txyz[i] -= dx
    517536    return deriv
    518537   
     
    556575        Ang = calcAngle(OxA,TxA,TxB,unitA,unitB,invA,CA,MA,TA,invB,CB,MB,TB,Amat)
    557576        for i in [0,1,2]:
    558             OxA[i] += dx
     577            OxA[i] -= dx
    559578            a0 = calcAngle(OxA,TxA,TxB,unitA,unitB,invA,CA,MA,TA,invB,CB,MB,TB,Amat)
    560             OxA[i] -= 2*dx
    561             dadx[i] = (calcAngle(OxA,TxA,TxB,unitA,unitB,invA,CA,MA,TA,invB,CB,MB,TB,Amat)-a0)/dx
    562             OxA[i] += dx
     579            OxA[i] += 2*dx
     580            dadx[i] = (calcAngle(OxA,TxA,TxB,unitA,unitB,invA,CA,MA,TA,invB,CB,MB,TB,Amat)-a0)/(2*dx)
     581            OxA[i] -= dx
    563582           
    564             TxA[i] += dx
     583            TxA[i] -= dx
    565584            a0 = calcAngle(OxA,TxA,TxB,unitA,unitB,invA,CA,MA,TA,invB,CB,MB,TB,Amat)
    566             TxA[i] -= 2*dx
    567             dadx[i+3] = (calcAngle(OxA,TxA,TxB,unitA,unitB,invA,CA,MA,TA,invB,CB,MB,TB,Amat)-a0)/dx
    568             TxA[i] += dx
     585            TxA[i] += 2*dx
     586            dadx[i+3] = (calcAngle(OxA,TxA,TxB,unitA,unitB,invA,CA,MA,TA,invB,CB,MB,TB,Amat)-a0)/(2*dx)
     587            TxA[i] -= dx
    569588           
    570             TxB[i] += dx
     589            TxB[i] -= dx
    571590            a0 = calcAngle(OxA,TxA,TxB,unitA,unitB,invA,CA,MA,TA,invB,CB,MB,TB,Amat)
    572             TxB[i] -= 2*dx
    573             dadx[i+6] = (calcAngle(OxA,TxA,TxB,unitA,unitB,invA,CA,MA,TA,invB,CB,MB,TB,Amat)-a0)/dx
    574             TxB[i] += dx
     591            TxB[i] += 2*dx
     592            dadx[i+6] = (calcAngle(OxA,TxA,TxB,unitA,unitB,invA,CA,MA,TA,invB,CB,MB,TB,Amat)-a0)/(2*dx)
     593            TxB[i] -= dx
    575594           
    576595        sigAng = np.sqrt(np.inner(dadx,np.inner(AngVcov,dadx)))
     
    721740            ia = i/3
    722741            ix = i%3
    723             Oatoms[ia][ix+1] += dx
     742            Oatoms[ia][ix+1] -= dx
    724743            a0 = calcTorsion(Oatoms,SyOps,Amat)
    725             Oatoms[ia][ix+1] -= 2*dx
     744            Oatoms[ia][ix+1] += 2*dx
    726745            dadx[i] = (calcTorsion(Oatoms,SyOps,Amat)-a0)/(2.*dx)
     746            Oatoms[ia][ix+1] -= dx           
    727747        covMatrix = covData['covMatrix']
    728748        varyList = covData['varyList']
Note: See TracChangeset for help on using the changeset viewer.