Changeset 2316


Ignore:
Timestamp:
Jun 12, 2016 8:22:48 PM (5 years ago)
Author:
toby
Message:

prototype distance calc.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIgrid.py

    r2314 r2316  
    14651465            help='Add a new pseudo-variable')
    14661466        self.SequentialPvars.Append(
    1467             id=wxADDSEQDIST, kind=wx.ITEM_NORMAL,text='Add dist',
     1467            id=wxADDSEQDIST, kind=wx.ITEM_NORMAL,text='Calc Distance',
    14681468            help='Add a new bond distance pseudo-variable')
    14691469        self.SequentialPvars.Append(
    1470             id=wxADDSEQANGLE, kind=wx.ITEM_NORMAL,text='Add angle',
     1470            id=wxADDSEQANGLE, kind=wx.ITEM_NORMAL,text='Calc Angle',
    14711471            help='Add a new bond angle pseudo-variable')
    14721472        self.SequentialPvars.Append(
     
    27722772            VarLabel = "New Bond")
    27732773        if dlg.ShowModal() == wx.ID_OK:
    2774             obj = dlg.GetSelection()
     2774            #obj = dlg.GetSelection()
     2775            # create an expression object
     2776            obj = G2obj.ExpressionObj()
     2777            obj.expression = 'Dist(1,2)'
     2778            obj.distance_stuff = np.array([[0,1,1,-1]])
     2779            obj.distance_atoms = [1,2]
    27752780        else:
    27762781            dlg.Destroy()
     
    27782783        dlg.Destroy()
    27792784        if obj:
    2780             calcobj = G2obj.ExpressionCalcObj(obj)
    2781             Controls['SeqPseudoVars'][calcobj.eObj.expression] = obj
     2785            Controls['SeqPseudoVars'][obj.expression] = obj
    27822786            UpdateSeqResults(G2frame,data,G2frame.dataDisplay.GetSize()) # redisplay variables
    27832787
  • trunk/GSASIIobj.py

    r2308 r2316  
    16611661        (list of 1-3 str values)'''
    16621662
     1663        self.distance_stuff = None  # to be used for defining atom distances
     1664        self.distance_atoms = None  # to be used for defining atom distances
     1665
    16631666    def LoadExpression(self,expr,exprVarLst,varSelect,varName,varValue,varRefflag):
    16641667        '''Load the expression and associated settings into the object. Raises
     
    19391942            if not isinstance(self.eObj.assgnVars[v], basestring):
    19401943                self.eObj.assgnVars[v] = self.eObj.assgnVars[v][0]
     1944        self.parmDict = {}
     1945        '''A copy of the parameter dictionary, for distance and angle computation
     1946        '''
    19411947
    19421948    def SetupCalc(self,parmDict):
     
    19441950        Adds the free parameter values to the parameter dict (parmDict).
    19451951        '''
     1952        if self.eObj.expression.startswith('Dist'):
     1953            return
    19461954        self.fxnpkgdict = self.eObj.CheckVars()
    19471955        # all is OK, compile the expression
     
    20112019        :param list parmDict: a dict of values some of which may be in use here
    20122020        '''
     2021        if self.eObj.expression.startswith('Dist'):
     2022            self.parmDict = parmDict
     2023            return
    20132024        for var in parmDict:
    20142025            if var in self.lblLookup:
     
    20302041        then the result will be ``4.0``.
    20312042        '''
     2043        if self.eObj.expression.startswith('Dist'):
     2044            dist = 0
     2045            #dist = CalcDist(self.eObj.distance_stuff, self.eObj.distance_atoms, self.parmDict)
     2046            return dist
    20322047        if self.compiledExpr is None:
    20332048            raise Exception,"EvalExpression called before SetupCalc"
     
    20612076    obj.freeVars =  {'A': [u'A', 0.5, True]}
    20622077    #obj.CheckVars()
     2078    calcobj = ExpressionCalcObj(obj)
     2079
     2080    obj1 = ExpressionObj()
     2081    obj1.expression = "A*np.exp(B)"
     2082    obj1.assgnVars =  {'B': '0::Afrac:*'}
     2083    obj1.freeVars =  {'A': [u'Free Prm A', 0.5, True]}
     2084    #obj.CheckVars()
     2085    calcobj1 = ExpressionCalcObj(obj1)
     2086
     2087    obj2 = ExpressionObj()
     2088    obj2.distance_stuff = np.array([[0,1],[1,-1]])
     2089    obj2.expression = "Dist(1,2)"
     2090    GSASIIpath.InvokeDebugOpts()
    20632091    parmDict2 = {'0::Afrac:0':[0.0,True], '0::Afrac:1': [1.0,False]}
    2064     calcobj = ExpressionCalcObj(obj)
     2092    calcobj2 = ExpressionCalcObj(obj2)
     2093    calcobj2.SetupCalc(parmDict2)
     2094    showEQ(calcobj2)
     2095   
     2096    parmDict1 = {'0::Afrac:0':1.0, '0::Afrac:1': 1.0}
     2097    print '\nDict = ',parmDict1
     2098    calcobj.SetupCalc(parmDict1)
     2099    showEQ(calcobj)
     2100    calcobj1.SetupCalc(parmDict1)
     2101    showEQ(calcobj1)
     2102
     2103    parmDict2 = {'0::Afrac:0':[0.0,True], '0::Afrac:1': [1.0,False]}
     2104    print 'Dict = ',parmDict2
    20652105    calcobj.SetupCalc(parmDict2)
    20662106    showEQ(calcobj)
    2067 
    2068     obj.expression = "A*np.exp(B)"
    2069     obj.assgnVars =  {'B': '0::Afrac:*'}
    2070     obj.freeVars =  {'A': [u'Free Prm A', 0.5, True]}
    2071     #obj.CheckVars()
    2072     parmDict1 = {'0::Afrac:0':1.0, '0::Afrac:1': 1.0}
    2073     calcobj = ExpressionCalcObj(obj)
    2074     calcobj.SetupCalc(parmDict1)
    2075     showEQ(calcobj)
    2076 
    2077     calcobj.SetupCalc(parmDict2)
    2078     showEQ(calcobj)
     2107    calcobj1.SetupCalc(parmDict2)
     2108    showEQ(calcobj1)
     2109    calcobj2.SetupCalc(parmDict2)
     2110    showEQ(calcobj2)
Note: See TracChangeset for help on using the changeset viewer.