Changeset 417 for trunk/GSASIImapvars.py


Ignore:
Timestamp:
Nov 16, 2011 2:42:49 PM (10 years ago)
Author:
toby
Message:

compute derivs for constrained vars

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIImapvars.py

    r415 r417  
    430430    return msg
    431431
     432def GetDependentVars():
     433    '''Return a list of dependent variables: e.g. variables that are
     434    constrained in terms of other variables'''
     435    dependentVars = []
     436    global dependentParmList
     437    for lst in dependentParmList:
     438        for itm in lst: dependentVars.append(itm)
     439    return dependentVars
    432440
    433441def VarRemapShow(varyList):
     
    442450    s += 'Variable mapping relations:\n'
    443451    global dependentParmList,arrayList,invarrayList,indParmList,fixedDict
    444     for varlist,mapvars,multarr in zip(dependentParmList,indParmList,arrayList):
     452    for varlist,mapvars,multarr,invmultarr in zip(
     453        dependentParmList,indParmList,arrayList,invarrayList):
    445454        i = 0
    446455        for mv in mapvars:
     
    448457                s += '  ' + str(mv) + ' defines parameter(s): '
    449458                j = 0
    450                 for v in varlist:
     459                for v,m in zip(varlist,invmultarr):
     460                    print v,m[0]
    451461                    if j > 0: s += '  & '
    452462                    j += 1
    453463                    s += str(v)
     464                    if m != 1:
     465                        s += " / " + str(m[0])                       
    454466                s += '\n'
    455467                continue
     
    478490            i += 1
    479491    return s
     492
     493def Dict2Deriv(varyList,derivDict,dMdv):
     494    '''Compute derivatives for Independent Parameters from the
     495    derivatives for the original parameters
     496    '''
     497    global dependentParmList,arrayList,invarrayList,indParmList,invarrayList
     498    for varlist,mapvars,multarr,invmultarr in zip(
     499        dependentParmList,indParmList,arrayList,invarrayList):
     500        for i,name in enumerate(mapvars):
     501            if name not in varyList: continue # if independent var not varied
     502            if multarr is None:
     503                # grouped variables need to add in the derv. w/r
     504                # dependent variables to the dependent ones
     505                for v,m in zip(varlist,invmultarr):
     506                    print 'add derv',v,'/',m[0],'to derv',name
     507                    if m[0] != 1 and m[0] != 0:
     508                        dMdv[varyList.index(name)] += derivDict[v]/m[0]
     509            else:
     510                for m,v in zip(multarr[i,:],varlist):
     511                    print 'add',m,' * derv',v,'to derv',name
     512                    dMdv[varyList.index(name)] += m * derivDict[v]
    480513
    481514def Map2Dict(parmDict,varyList):
     
    701734    StoreEquivalence('2::atomx:3',('2::atomy:3', ('2::atomz:3',2,), ))
    702735    varylist = ['2::atomx:3',]
    703     print VarRemapShow(varylist)
    704     msg = SetVaryFlags(varylist)
    705     if msg != "": print msg
     736    #print VarRemapShow(varylist)
     737    #msg = SetVaryFlags(varylist)
     738    #if msg != "": print msg
    706739    varylist = ['2::atomx:3', '2::atomy:3', '2::atomz:3',]
    707740    print VarRemapShow(varylist)
Note: See TracChangeset for help on using the changeset viewer.