Changeset 443 for trunk/GSASIIstruct.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/GSASIIstruct.py

    r441 r443  
    12591259                    hapData[item][1][0] = parmDict[pfx+item+':i']
    12601260                    if item == 'Size':
    1261                         hapData[item][1][0] = min(10.,max(0.01,hapData[item][1][0]))
     1261                        hapData[item][1][0] = min(10.,max(0.001,hapData[item][1][0]))
    12621262                    if pfx+item+':i' in sigDict:
    12631263                        SizeMuStrSig[item][0][0] = sigDict[pfx+item+':i']
     
    12651265                        hapData[item][1][1] = parmDict[pfx+item+':a']
    12661266                        if item == 'Size':
    1267                             hapData[item][1][1] = min(10.,max(0.01,hapData[item][1][1]))                       
     1267                            hapData[item][1][1] = min(10.,max(0.001,hapData[item][1][1]))                       
    12681268                        if pfx+item+':a' in sigDict:
    12691269                            SizeMuStrSig[item][0][1] = sigDict[pfx+item+':a']
     
    12871287   
    12881288    def GetBackgroundParms(hId,Background):
    1289         bakType,bakFlag = Background[:2]
    1290         backVals = Background[3:]
     1289        Back = Background[0]
     1290        Debye = Background[1]
     1291        bakType,bakFlag = Back[:2]
     1292        backVals = Back[3:]
    12911293        backNames = [':'+str(hId)+':Back:'+str(i) for i in range(len(backVals))]
    1292         if bakFlag:                                 #returns backNames as varyList = backNames
    1293             return bakType,dict(zip(backNames,backVals)),backNames
    1294         else:                                       #no background varied; varyList = []
    1295             return bakType,dict(zip(backNames,backVals)),[]
     1294        backDict = dict(zip(backNames,backVals))
     1295        backVary = []
     1296        if bakFlag:
     1297            backVary = backNames
     1298        backDict[':'+str(hId)+':nDebye'] = Debye['nDebye']
     1299        debyeDict = {}
     1300        debyeList = []
     1301        for i in range(Debye['nDebye']):
     1302            debyeNames = [':'+str(hId)+':DebyeA:'+str(i),':'+str(hId)+':DebyeR:'+str(i),':'+str(hId)+':DebyeU:'+str(i)]
     1303            debyeDict.update(dict(zip(debyeNames,Debye['debyeTerms'][i][::2])))
     1304            debyeList += zip(debyeNames,Debye['debyeTerms'][i][1::2])
     1305        debyeVary = []
     1306        for item in debyeList:
     1307            if item[1]:
     1308                debyeVary.append(item[0])
     1309        backDict.update(debyeDict)
     1310        backVary += debyeVary   
     1311        return bakType,backDict,backVary           
    12961312       
    12971313    def GetInstParms(hId,Inst):
     
    13061322            if flag:
    13071323                insVary.append(insName)
    1308         instDict[pfx+'X'] = max(instDict[pfx+'X'],0.01)
    1309         instDict[pfx+'Y'] = max(instDict[pfx+'Y'],0.01)
     1324        instDict[pfx+'X'] = max(instDict[pfx+'X'],0.001)
     1325        instDict[pfx+'Y'] = max(instDict[pfx+'Y'],0.001)
    13101326        instDict[pfx+'SH/L'] = max(instDict[pfx+'SH/L'],0.0005)
    13111327        return dataType,instDict,insVary
     
    13301346       
    13311347    def PrintBackground(Background):
    1332         print '\n Background function: ',Background[0],' Refine?',bool(Background[1])
     1348        Back = Background[0]
     1349        Debye = Background[1]
     1350        print '\n Background function: ',Back[0],' Refine?',bool(Back[1])
    13331351        line = ' Coefficients: '
    1334         for i,back in enumerate(Background[3:]):
     1352        for i,back in enumerate(Back[3:]):
    13351353            line += '%10.3f'%(back)
    13361354            if i and not i%10:
    13371355                line += '\n'+15*' '
    1338         print line
     1356        print line
     1357        if Debye['nDebye']:
     1358            print '\n Debye diffuse scattering coefficients'
     1359            parms = ['DebyeA','DebyeR','DebyeU']
     1360            line = ' names :'
     1361            for parm in parms:
     1362                line += '%16s'%(parm)
     1363            print line
     1364            for j,term in enumerate(Debye['debyeTerms']):
     1365                line = ' term'+'%2d'%(j)+':'
     1366                for i in range(3):
     1367                    line += '%10.4f %5s'%(term[2*i],bool(term[2*i+1]))                   
     1368                print line
    13391369       
    13401370    def PrintInstParms(Inst):
     
    13881418        controlDict[pfx+'Limits'] = Histogram['Limits'][1]
    13891419       
    1390         Background = Histogram['Background'][0]
     1420        Background = Histogram['Background']
    13911421        Type,bakDict,bakVary = GetBackgroundParms(hId,Background)
    13921422        controlDict[pfx+'bakType'] = Type
     
    14271457   
    14281458    def SetBackgroundParms(pfx,Background,parmDict,sigDict):
    1429         lenBack = len(Background[3:])
    1430         backSig = [0 for i in range(lenBack)]
     1459        Back = Background[0]
     1460        Debye = Background[1]
     1461        lenBack = len(Back[3:])
     1462        backSig = [0 for i in range(lenBack+3*Debye['nDebye'])]
    14311463        for i in range(lenBack):
    1432             Background[3+i] = parmDict[pfx+'Back:'+str(i)]
     1464            Back[3+i] = parmDict[pfx+'Back:'+str(i)]
    14331465            if pfx+'Back:'+str(i) in sigDict:
    14341466                backSig[i] = sigDict[pfx+'Back:'+str(i)]
     1467        if Debye['nDebye']:
     1468            for i in range(Debye['nDebye']):
     1469                names = [pfx+'DebyeA:'+str(i),pfx+'DebyeR:'+str(i),pfx+'DebyeU:'+str(i)]
     1470                for j,name in enumerate(names):
     1471                    Debye['debyeTerms'][i][2*j] = parmDict[name]
     1472                    if name in sigDict:
     1473                        backSig[lenBack+3*i+j] = sigDict[name]           
    14351474        return backSig
    14361475       
     
    14611500       
    14621501    def PrintBackgroundSig(Background,backSig):
    1463         print '\n Background function: ',Background[0]
     1502        Back = Background[0]
     1503        Debye = Background[1]
     1504        lenBack = len(Back[3:])
     1505        print '\n Background function: ',Back[0]
    14641506        valstr = ' value : '
    14651507        sigstr = ' sig   : '
    1466         for i,back in enumerate(Background[3:]):
     1508        for i,back in enumerate(Back[3:]):
    14671509            valstr += '%10.4f'%(back)
    1468             if Background[1]:
     1510            if Back[1]:
    14691511                sigstr += '%10.4f'%(backSig[i])
    14701512            else:
     
    14721514        print valstr
    14731515        print sigstr
     1516        if Debye['nDebye']:
     1517            ifAny = False
     1518            ptfmt = "%12.5f"
     1519            names =  ' names :'
     1520            ptstr =  ' values:'
     1521            sigstr = ' esds  :'
     1522            for item in sigDict:
     1523                if 'Debye' in item:
     1524                    ifAny = True
     1525                    names += '%12s'%(item)
     1526                    ptstr += ptfmt%(parmDict[item])
     1527                    sigstr += ptfmt%(sigDict[item])
     1528            if ifAny:
     1529                print '\n Debye diffuse scattering coefficients'
     1530                print names
     1531                print ptstr
     1532                print sigstr
    14741533       
    14751534    def PrintInstParmsSig(Inst,instSig):
     
    15221581            hId = Histogram['hId']
    15231582            pfx = ':'+str(hId)+':'
    1524             Background = Histogram['Background'][0]
     1583            Background = Histogram['Background']
    15251584            backSig = SetBackgroundParms(pfx,Background,parmDict,sigDict)
    15261585           
     
    19562015    #microstrain derivatives               
    19572016    if calcControls[phfx+'MustrainType'] == 'isotropic':
    1958         gamDict[phfx+'Mustrain:0'] =  0.018*tanth/np.pi           
     2017        gamDict[phfx+'Mustrain:i'] =  0.018*tanth/np.pi           
    19592018    elif calcControls[phfx+'MustrainType'] == 'uniaxial':
    19602019        H = np.array(refl[:3])
    19612020        P = np.array(calcControls[phfx+'MustrainAxis'])
    19622021        cosP,sinP = G2lat.CosSinAngle(H,P,G)
    1963         Si = parmDict[phfx+'Mustrain:0']
    1964         Sa = parmDict[phfx+'Mustrain:1']
     2022        Si = parmDict[phfx+'Mustrain:i']
     2023        Sa = parmDict[phfx+'Mustrain:a']
    19652024        gami = 0.018*Si*Sa*tanth/np.pi
    19662025        sqtrm = np.sqrt((Si*cosP)**2+(Sa*sinP)**2)
    19672026        gam = gami/sqtrm
    1968         gamDict[phfx+'Mustrain:0'] = gam/Si-gami*Si*cosP**2/sqtrm**3
    1969         gamDict[phfx+'Mustrain:1'] = gam/Sa-gami*Sa*sinP**2/sqtrm**3
     2027        gamDict[phfx+'Mustrain:i'] = gam/Si-gami*Si*cosP**2/sqtrm**3
     2028        gamDict[phfx+'Mustrain:a'] = gam/Sa-gami*Sa*sinP**2/sqtrm**3
    19702029    else:       #generalized - P.W. Stephens model
    19712030        pwrs = calcControls[phfx+'MuPwrs']
     
    22672326    bakType = calcControls[hfx+'bakType']
    22682327    dMdv = np.zeros(shape=(len(varylist),len(x)))
     2328    dMdb,dMddb = G2pwd.getBackgroundDerv(hfx,parmDict,bakType,x)
    22692329    if hfx+'Back:0' in varylist: # for now assume that Back:x vars to not appear in constraints
    2270         dMdb = G2pwd.getBackgroundDerv(hfx,parmDict,bakType,x)
    22712330        bBpos =varylist.index(hfx+'Back:0')
    22722331        dMdv[bBpos:bBpos+len(dMdb)] = dMdb
    2273        
     2332    names = [hfx+'DebyeA',hfx+'DebyeR',hfx+'DebyeU']
     2333    for name in varylist:
     2334        if 'Debye' in name:
     2335            id = int(name.split(':')[-1])
     2336            parm = name[:int(name.rindex(':'))]
     2337            ip = names.index(parm)
     2338            dMdv[varylist.index(name)] = dMddb[3*id+ip]
    22742339    if 'C' in calcControls[hfx+'histType']:   
    22752340        dx = x[1]-x[0]
     
    24162481    G2mv.Dict2Map(parmdict,varylist)
    24172482    Histograms,Phases = HistoPhases
     2483    nvar = len(varylist)
    24182484    dMdv = np.empty(0)
    24192485    for histogram in Histograms:
     
    25852651    sigDict = dict(zip(varyList,sig))
    25862652    newCellDict = GetNewCellParms(parmDict,varyList)
    2587     print newCellDict
    25882653    newAtomDict = ApplyXYZshifts(parmDict,varyList)
    25892654    covData = {'variables':result[0],'varyList':varyList,'sig':sig,
Note: See TracChangeset for help on using the changeset viewer.