Changeset 3806 for trunk/GSASIIobj.py


Ignore:
Timestamp:
Jan 30, 2019 5:15:41 PM (5 years ago)
Author:
toby
Message:

redo parameter lookup to provide numerical deriv step size (see G2obj.getVarStep)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIobj.py

    r3802 r3806  
    10121012'''
    10131013
    1014 VarDesc = {}
    1015 ''' This dictionary lists descriptions for GSAS-II variables,
    1016 as set in :func:`CompileVarDesc`. See that function for a description
    1017 for how keys and values are written.
     1014#VarDesc = {}  # removed 1/30/19 BHT as no longer needed (I think)
     1015#''' This dictionary lists descriptions for GSAS-II variables,
     1016#as set in :func:`CompileVarDesc`. See that function for a description
     1017#for how keys and values are written.
     1018#'''
     1019
     1020reVarDesc = {}
     1021''' This dictionary lists descriptions for GSAS-II variables where
     1022keys are compiled regular expressions that will match the name portion
     1023of a parameter name. Initialized in :func:`CompileVarDesc`.
    10181024'''
    10191025
    1020 reVarDesc = {}
    1021 ''' This dictionary lists descriptions for GSAS-II variables with
    1022 the same values as :attr:`VarDesc` except that keys have been compiled as
    1023 regular expressions. Initialized in :func:`CompileVarDesc`.
     1026reVarStep = {}
     1027''' This dictionary lists the preferred step size for numerical
     1028derivative computation w/r to a GSAS-II variable. Keys are compiled
     1029regular expressions and values are the step size for that parameter.
     1030Initialized in :func:`CompileVarDesc`.
    10241031'''
    10251032# create a default space group object for P1; N.B. fails when building documentation
     
    13091316    '''
    13101317
    1311     # special handling for parameter names without a colons
     1318    # special handling for parameter names without a colon
    13121319    # for now, assume self-defining
    13131320    if varname.find(':') == -1:
     
    14121419
    14131420def CompileVarDesc():
    1414     '''Set the values in the variable description lookup table (:attr:`VarDesc`)
    1415     into :attr:`reVarDesc`. This is called in :func:`getDescr` so the initialization
    1416     is always done before use.
     1421    '''Set the values in the variable lookup tables
     1422    (:attr:`reVarDesc` and :attr:`reVarStep`).
     1423    This is called in :func:`getDescr` and :func:`getVarStep` so this
     1424    initialization is always done before use.
    14171425
    14181426    Note that keys may contain regular expressions, where '[xyz]'
    1419     matches 'x' 'y' or 'z' (equivalently '[x-z]' describes this as range of values).
    1420     '.*' matches any string. For example::
     1427    matches 'x' 'y' or 'z' (equivalently '[x-z]' describes this as range
     1428    of values). '.*' matches any string. For example::
    14211429
    14221430    'AUiso':'Atomic isotropic displacement parameter',
     
    14421450        'Scale' : 'Phase or Histogram scale factor',
    14431451        # Phase vars (p::<var>)
    1444         'A([0-5])' : 'Reciprocal metric tensor component \\1',
     1452        'A([0-5])' : ('Reciprocal metric tensor component \\1',1e-5),
    14451453        '[vV]ol' : 'Unit cell volume', # probably an error that both upper and lower case are used
    14461454        # Atom vars (p::<var>:a)
    1447         'dA([xyz])$' : 'change to atomic coordinate, \\1',
     1455        'dA([xyz])$' : ('change to atomic coordinate, \\1',1e-6),
    14481456        'A([xyz])$' : '\\1 fractional atomic coordinate',
    1449         'AUiso':'Atomic isotropic displacement parameter',
    1450         'AU([123][123])':'Atomic anisotropic displacement parameter U\\1',
    1451         'Afrac': 'Atomic site fraction parameter',
     1457        'AUiso':('Atomic isotropic displacement parameter',1e-4),
     1458        'AU([123][123])':('Atomic anisotropic displacement parameter U\\1',1e-4),
     1459        'Afrac': ('Atomic site fraction parameter',1e-5),
    14521460        'Amul': 'Atomic site multiplicity value',
    14531461        'AM([xyz])$' : 'Atomic magnetic moment parameter, \\1',
     
    14721480        #Histogram vars (:h:<var>)
    14731481        'Absorption' : 'Absorption coef.',
    1474         'Displace([XY])' : 'Debye-Scherrer sample displacement \\1',
    1475         'Lam' : 'Wavelength',
    1476         'I\(L2\)\/I\(L1\)' : 'Ka2/Ka1 intensity ratio',
    1477         'Polariz\.' : 'Polarization correction',
    1478         'SH/L' : 'FCJ peak asymmetry correction',
    1479         '([UVW])$' : 'Gaussian instrument broadening \\1',
    1480         '([XYZ])$' : 'Cauchy instrument broadening \\1',
     1482        'Displace([XY])' : ('Debye-Scherrer sample displacement \\1',0.1),
     1483        'Lam' : ('Wavelength',1e-6),
     1484        'I\(L2\)\/I\(L1\)' : ('Ka2/Ka1 intensity ratio',0.001),
     1485        'Polariz\.' : ('Polarization correction',1e-3),
     1486        'SH/L' : ('FCJ peak asymmetry correction',1e-4),
     1487        '([UVW])$' : ('Gaussian instrument broadening \\1',1e-5),
     1488        '([XYZ])$' : ('Cauchy instrument broadening \\1',1e-5),
    14811489        'Zero' : 'Debye-Scherrer zero correction',
    14821490        'Shift' : 'Bragg-Brentano sample displ.',
     
    15501558        'C\([0-9]*,[0-9]*\)' : 'spherical harmonics preferred orientation coef.',
    15511559        }.items():
    1552         VarDesc[key] = value
    1553         reVarDesc[re.compile(key)] = value
     1560        if len(value) == 2:
     1561            #VarDesc[key] = value[0]
     1562            reVarDesc[re.compile(key)] = value[0]
     1563            reVarStep[re.compile(key)] = value[1]
     1564        else:
     1565            #VarDesc[key] = value
     1566            reVarDesc[re.compile(key)] = value
    15541567
    15551568def removeNonRefined(parmList):
     
    15861599            return m.expand(reVarDesc[key])
    15871600    return None
     1601
     1602def getVarStep(name,parmDict=None):
     1603    '''Return a step size for computing the derivative of a GSAS-II variable
     1604
     1605    :param str name: A complete variable name (with colons, :)
     1606    :param dict parmDict: A dict with parameter values or None (default)
     1607
     1608    :returns: a float that should be an appropriate step size, either from
     1609      the value supplied in :func:`CompileVarDesc` or based on the value for
     1610      name in parmDict, if supplied. If not found or the value is zero,
     1611      a default value of 1e-5 is used. If parmDict is None (default) and
     1612      no value is provided in :func:`CompileVarDesc`, then None is returned.
     1613    '''
     1614    CompileVarDesc() # compile the regular expressions, if needed
     1615    for key in reVarStep:
     1616        m = key.match(name)
     1617        if m:
     1618            return reVarStep[key]
     1619    if parmDict is None: return None
     1620    val = parmDict.get(key,0.0)
     1621    if abs(val) > 0.05:
     1622        return abs(val)/1000.
     1623    else:
     1624        return 1e-5
    15881625
    15891626def GenWildCard(varlist):
     
    27442781        print (70*'*')
    27452782
     2783# Note that this is GUI code and should be moved at somepoint
    27462784def CreatePDFitems(G2frame,PWDRtree,ElList,Qlimits,numAtm=1,FltBkg=0,PDFnames=[]):
    27472785    '''Create and initialize a new set of PDF tree entries
     
    28282866
    28292867if __name__ == "__main__":
     2868    # test variable descriptions
     2869    for var in '0::Afrac:*',':1:Scale','1::dAx:0','::undefined':
     2870        v = var.split(':')[2]
     2871        print(var+':\t', getDescr(v),getVarStep(v))
     2872    import sys; sys.exit()
    28302873    # test equation evaluation
    28312874    def showEQ(calcobj):
Note: See TracChangeset for help on using the changeset viewer.