Changeset 443 for trunk/GSASIIpwd.py


Ignore:
Timestamp:
Dec 16, 2011 1:15:09 PM (11 years ago)
Author:
vondreele
Message:

make sum powder profiles numpy arrays
change name UpdateBackgroundGrid? to UpdateBackground?
min size is 1 nanometer = 10A
implement diffuse scattering model for background
iso/aniso Size & Mustrain are now Size:i/a instead of 0/1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpwd.py

    r432 r443  
    647647            bakInt = si.interp1d(bakPos,bakVals,'linear')
    648648            yb = bakInt(xdata)
     649    iD = 0       
     650    try:
     651        wave = parmDict[pfx+'Lam']
     652    except KeyError:
     653        wave = parmDict[pfx+'Lam1']
     654    q = 4.0*np.pi*npsind(xdata/2.0)/wave
     655    SQ = (q/(4*np.pi))**2
     656    FF = G2elem.GetFormFactorCoeff('Si')[0]
     657    ff = np.array(G2elem.ScatFac(FF,SQ)[0])**2
     658    while True:
     659        try:
     660            dbA = parmDict[pfx+'DebyeA:'+str(iD)]
     661            dbR = parmDict[pfx+'DebyeR:'+str(iD)]
     662            dbU = parmDict[pfx+'DebyeU:'+str(iD)]
     663            yb += ff*dbA*np.sin(q*dbR)*np.exp(-dbU*q**2)/(q*dbR)
     664            iD += 1       
     665        except KeyError:
     666            break   
    649667    return yb
    650668   
     
    658676            break
    659677    dydb = np.zeros(shape=(nBak,len(xdata)))
     678    dyddb = np.zeros(shape=(3*parmDict[pfx+'nDebye'],len(xdata)))
    660679
    661680    if bakType in ['chebyschev','cosine']:
     
    692711                        np.where(xdata<bakPos[i+1],(bakPos[i+1]-xdata)/(bakPos[i+1]-bakPos[i]),0.),
    693712                        np.where(xdata>bakPos[i-1],(xdata-bakPos[i-1])/(bakPos[i]-bakPos[i-1]),0.))
    694     return dydb
     713    iD = 0       
     714    try:
     715        wave = parmDict[pfx+'Lam']
     716    except KeyError:
     717        wave = parmDict[pfx+'Lam1']
     718    q = 4.0*np.pi*npsind(xdata/2.0)/wave
     719    SQ = (q/(4*np.pi))**2
     720    FF = G2elem.GetFormFactorCoeff('Si')[0]
     721    ff = np.array(G2elem.ScatFac(FF,SQ)[0])
     722    while True:
     723        try:
     724            dbA = parmDict[pfx+'DebyeA:'+str(iD)]
     725            dbR = parmDict[pfx+'DebyeR:'+str(iD)]
     726            dbU = parmDict[pfx+'DebyeU:'+str(iD)]
     727            sqr = np.sin(q*dbR)/(q*dbR)
     728            cqr = np.cos(q*dbR)
     729            temp = np.exp(-dbU*q**2)
     730            dyddb[3*iD] = ff*sqr*temp
     731            dyddb[3*iD+1] = ff*dbA*temp*(cqr-sqr)/dbR
     732            dyddb[3*iD+2] = -ff*dbA*sqr*temp*q**2
     733            iD += 1       
     734        except KeyError:
     735            break
     736    return dydb,dyddb
    695737
    696738#use old fortran routine
     
    790832# needs to return np.array([dMdx1,dMdx2,...]) in same order as varylist = backVary,insVary,peakVary order
    791833    dMdv = np.zeros(shape=(len(varyList),len(xdata)))
     834    dMdb,dMddb = getBackgroundDerv('',parmDict,bakType,xdata)
    792835    if 'Back:0' in varyList:            #background derivs are in front if present
    793         dMdb = getBackgroundDerv('',parmDict,bakType,xdata)
    794836        dMdv[0:len(dMdb)] = dMdb
    795        
     837    names = ['DebyeA','DebyeR','DebyeU']
     838    for name in varyList:
     839        if 'Debye' in name:
     840            ih,parm,id = name.split(':')
     841            ip = names.index(parm)
     842            dMdv[varyList.index(name)] = dMddb[3*int(id)+ip]
    796843    dx = xdata[1]-xdata[0]
    797844    U = parmDict['U']
     
    901948   
    902949    def SetBackgroundParms(Background):
    903         bakType,bakFlag = Background[:2]
    904         backVals = Background[3:]
     950        if len(Background) == 1:            # fix up old backgrounds
     951            BackGround.append({'nDebye':0,'debyeTerms':[]})
     952        bakType,bakFlag = Background[0][:2]
     953        backVals = Background[0][3:]
    905954        backNames = ['Back:'+str(i) for i in range(len(backVals))]
    906         if bakFlag: #returns backNames as varyList = backNames
    907             return bakType,dict(zip(backNames,backVals)),backNames
    908         else:       #no background varied; varyList = []
    909             return bakType,dict(zip(backNames,backVals)),[]
     955        Debye = Background[1]
     956        backDict = dict(zip(backNames,backVals))
     957        backVary = []
     958        if bakFlag:
     959            backVary = backNames
     960        backDict['nDebye'] = Debye['nDebye']
     961        debyeDict = {}
     962        debyeList = []
     963        for i in range(Debye['nDebye']):
     964            debyeNames = ['DebyeA:'+str(i),'DebyeR:'+str(i),'DebyeU:'+str(i)]
     965            debyeDict.update(dict(zip(debyeNames,Debye['debyeTerms'][i][::2])))
     966            debyeList += zip(debyeNames,Debye['debyeTerms'][i][1::2])
     967        debyeVary = []
     968        for item in debyeList:
     969            if item[1]:
     970                debyeVary.append(item[0])
     971        backDict.update(debyeDict)
     972        backVary += debyeVary   
     973        return bakType,backDict,backVary           
    910974       
    911975    def GetBackgroundParms(parmList,Background):
     
    914978            try:
    915979                bakName = 'Back:'+str(iBak)
    916                 Background[iBak+3] = parmList[bakName]
     980                Background[0][iBak+3] = parmList[bakName]
    917981                iBak += 1
     982            except KeyError:
     983                break
     984        iDb = 0
     985        while True:
     986            names = ['DebyeA:','DebyeR:','DebyeU:']
     987            try:
     988                for i,name in enumerate(names):
     989                    val = parmList[name+str(iDb)]
     990                    Background[1]['debyeTerms'][iDb][2*i] = val
     991                iDb += 1
    918992            except KeyError:
    919993                break
    920994               
    921995    def BackgroundPrint(Background,sigDict):
    922         if Background[1]:
    923             print 'Background coefficients for',Background[0],'function'
     996        if Background[0][1]:
     997            print 'Background coefficients for',Background[0][0],'function'
    924998            ptfmt = "%12.5f"
    925999            ptstr =  'values:'
    9261000            sigstr = 'esds  :'
    927             for i,back in enumerate(Background[3:]):
     1001            for i,back in enumerate(Background[0][3:]):
    9281002                ptstr += ptfmt % (back)
    9291003                sigstr += ptfmt % (sigDict['Back:'+str(i)])
     
    9321006        else:
    9331007            print 'Background not refined'
    934            
     1008        if Background[1]['nDebye']:
     1009            parms = ['DebyeA','DebyeR','DebyeU']
     1010            print 'Debye diffuse scattering coefficients'
     1011            ptfmt = "%12.5f"
     1012            names =   'names :'
     1013            ptstr =  'values:'
     1014            sigstr = 'esds  :'
     1015            for item in sigDict:
     1016                if 'Debye' in item:
     1017                    names += '%12s'%(item)
     1018                    sigstr += ptfmt%(sigDict[item])
     1019                    parm,id = item.split(':')
     1020                    ip = parms.index(parm)
     1021                    ptstr += ptfmt%(Background[1]['debyeTerms'][int(id)][2*ip])
     1022            print names
     1023            print ptstr
     1024            print sigstr
     1025                           
    9351026    def SetInstParms(Inst):
    9361027        insVals,insFlags,insNames = Inst[1:4]
Note: See TracChangeset for help on using the changeset viewer.