Changeset 3772


Ignore:
Timestamp:
Dec 23, 2018 6:02:12 PM (5 years ago)
Author:
toby
Message:

add GUI (seen in debug mode only) for general (equation specified) restraints

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r3759 r3772  
    566566    return
    567567
    568 objectScanIgnore = [int,bool,float,str,np.float64,np.int32,np.int64,np.ndarray,G2obj.G2VarObj]
     568objectScanIgnore = [int,bool,float,str,np.float64,np.int32,np.int64,np.ndarray,G2obj.G2VarObj,G2obj.ExpressionObj]
    569569try:
    570570    objectScanIgnore += [ma.MaskedArray] # fails in doc builds
  • trunk/GSASIIexprGUI.py

    r3458 r3772  
    107107      may be a list with parameter values and a refine flag or may just contain
    108108      the parameter value (non-float/int values in dict are ignored)
    109     :param str exprObj: a :class:`GSASIIobj.ExpressionObj` object with an expression and
     109    :param exprObj: a :class:`GSASIIobj.ExpressionObj` object with an expression and
    110110      label assignments or None (default)
    111111    :param str wintitle: String placed on title bar of dialog;
     
    114114      what they will do here; default is "Enter restraint expression here"
    115115    :param bool fit: determines if the expression will be used in fitting (default=True).
    116       If set to False, and refinement flags are not shown
     116      If set to False, refinement flags are not shown
    117117      and Free parameters are not offered as an assignment option.
    118118    :param str VarLabel: an optional variable label to include before the expression
  • trunk/GSASIIrestrGUI.py

    r3682 r3772  
    3131import GSASIIctrlGUI as G2G
    3232import GSASIIphsGUI as G2phsGUI
     33import GSASIIobj as G2obj
     34import GSASIIconstrGUI as G2cnstG
     35import GSASIIexprGUI as G2exG
    3336
    3437WACV = wx.ALIGN_CENTER_VERTICAL
     
    151154            finally:
    152155                dlg.Destroy()
    153            
     156
     157    def SetupParmDict(G2frame):
     158        '''Creates a parameter dict with variable names as keys and
     159        numerical values (only)
     160        '''
     161        G2cnstG.CheckAllScalePhaseFractions(G2frame)
     162        try:
     163            parmDict,varyList = G2frame.MakeLSParmDict()
     164        except:
     165            print('Error retrieving parameters')
     166            return {}
     167        return {i:parmDict[i][0] for i in parmDict}
     168       
    154169    def OnAddRestraint(event):
     170        '''Adds a restraint depending on which tab is currently displayed'''
    155171        page = G2frame.restrBook.GetSelection()
    156172        if 'Bond' in G2frame.restrBook.GetPageText(page):
     
    164180        elif 'Texture' in G2frame.restrBook.GetPageText(page):
    165181            AddTextureRestraint(restrData['Texture'])
     182        elif 'General' in G2frame.restrBook.GetPageText(page):
     183            parmDict = SetupParmDict(G2frame)
     184            dlg = G2exG.ExpressionDialog(G2frame,parmDict,
     185                           header="Create a restraint expression",
     186                           fit=False,wildCard=G2frame.testSeqRefineMode())
     187            restobj = dlg.Show(True)
     188            if restobj:
     189                restrData['General'].append([restobj,0.0,1.0])
     190                wx.CallAfter(UpdateGeneralRestr,restrData['General'])
    166191           
    167192    def OnAddAARestraint(event):
     
    18301855        G2phsGUI.SetPhaseWindow(TextureRestr,mainSizer,Scroll=0)
    18311856           
     1857    def UpdateGeneralRestr(generalRestData):
     1858        '''Display any generalized restraint expressions'''
     1859        def OnEditGenRestraint(event):
     1860            '''Edit a restraint expression'''
     1861            n = event.GetEventObject().index
     1862            parmDict = SetupParmDict(G2frame)
     1863            dlg = G2exG.ExpressionDialog(G2frame,parmDict,
     1864                            exprObj=generalRestData[n][0],
     1865                            header="Edit a restraint expression",
     1866                            fit=False,wildCard=G2frame.testSeqRefineMode())
     1867            restobj = dlg.Show(True)
     1868            if restobj:
     1869                generalRestData[n][0] = restobj
     1870                wx.CallAfter(UpdateGeneralRestr,restrData['General'])
     1871        def OnDelGenRestraint(event):
     1872            '''Delete a restraint expression'''
     1873            n = event.GetEventObject().index
     1874            del generalRestData[n]
     1875            wx.CallAfter(UpdateGeneralRestr,restrData['General'])
     1876           
     1877        if GeneralRestr.GetSizer(): GeneralRestr.GetSizer().Clear(True)
     1878        mainSizer = wx.BoxSizer(wx.VERTICAL)
     1879        mainSizer.Add((5,5),0)
     1880        mainSizer.Add(wx.StaticText(GeneralRestr,wx.ID_ANY,'(not implemented yet)'))
     1881        btn = wx.Button(GeneralRestr, wx.ID_ANY,"Add restraint")
     1882        btn.Bind(wx.EVT_BUTTON,OnAddRestraint)
     1883        mainSizer.Add(btn,0,wx.ALIGN_CENTER)
     1884        mainSizer.Add((5,5),0)
     1885        if generalRestData:
     1886            parmDict = SetupParmDict(G2frame)
     1887            GridSiz = wx.FlexGridSizer(0,7,10,2)
     1888            for lbl in ('expression','target\nvalue','current\nvalue','weight'):
     1889                GridSiz.Add(
     1890                    wx.StaticText(GeneralRestr,wx.ID_ANY,lbl,style=wx.CENTER),
     1891                    0,wx.ALIGN_CENTER)
     1892            GridSiz.Add((-1,-1))
     1893            GridSiz.Add((-1,-1))
     1894            GridSiz.Add(
     1895                    wx.StaticText(GeneralRestr,wx.ID_ANY,'Variables',style=wx.CENTER),
     1896                    0,wx.ALIGN_CENTER)
     1897            for i,rest in enumerate(generalRestData):
     1898                txt = rest[0].expression
     1899                if len(txt) > 50:
     1900                    txt = txt[:47]+'... '
     1901                GridSiz.Add(wx.StaticText(GeneralRestr,wx.ID_ANY,txt))
     1902                GridSiz.Add(
     1903                    G2G.ValidatedTxtCtrl(GeneralRestr,rest,1,nDig=(10,2),typeHint=float)
     1904                    )
     1905                # evaluate the expression
     1906                try:
     1907                    calcobj = G2obj.ExpressionCalcObj(rest[0])
     1908                    calcobj.SetupCalc(parmDict)
     1909                    txt = '{:f}'.format(calcobj.EvalExpression())
     1910                except:
     1911                    txt = '(error)'
     1912                GridSiz.Add(wx.StaticText(GeneralRestr,wx.ID_ANY,txt))
     1913                GridSiz.Add(
     1914                    G2G.ValidatedTxtCtrl(GeneralRestr,rest,2,nDig=(10,1),typeHint=float)
     1915                    )
     1916                btn = wx.Button(GeneralRestr, wx.ID_ANY,"Edit",size=(40,-1))
     1917                btn.index = i
     1918                btn.Bind(wx.EVT_BUTTON,OnEditGenRestraint)
     1919                GridSiz.Add(btn)
     1920                btn = wx.Button(GeneralRestr, wx.ID_ANY,"Delete",size=(60,-1))
     1921                btn.index = i
     1922                btn.Bind(wx.EVT_BUTTON,OnDelGenRestraint)
     1923                GridSiz.Add(btn)
     1924                txt = str(rest[0].assgnVars)[1:-1].replace("'","")
     1925                if len(txt) > 50:
     1926                    txt = txt[:47]+'...'
     1927                GridSiz.Add(wx.StaticText(GeneralRestr,wx.ID_ANY,txt))
     1928            mainSizer.Add(GridSiz)
     1929        G2phsGUI.SetPhaseWindow(GeneralRestr,mainSizer,Scroll=0)
     1930
     1931   
    18321932    def OnPageChanged(event):
    18331933        page = event.GetSelection()
     
    18911991            textureRestData = restrData['Texture']
    18921992            UpdateTextureRestr(textureRestData)
     1993        elif text == 'General':
     1994            G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.RestraintMenu)
     1995            G2frame.dataWindow.RestraintEdit.Enable(G2G.wxID_RESTRAINTADD,True)
     1996            G2frame.dataWindow.RestraintEdit.Enable(G2G.wxID_RESRCHANGEVAL,False)
     1997            UpdateGeneralRestr(restrData['General'])
    18931998        event.Skip()
    18941999
     
    19472052    if 'ChemComp' not in restrData:
    19482053        restrData['ChemComp'] = {'wtFactor':1.0,'Sites':[],'Use':True}
     2054    if 'General' not in restrData: restrData['General'] = []
    19492055    General = phasedata['General']
    19502056    Cell = General['Cell'][1:7]          #skip flag & volume   
     
    20222128    Pages.append(txt)
    20232129   
     2130    if GSASIIpath.GetConfigValue('debug'):
     2131        txt = 'General'
     2132        GeneralRestr = wx.ScrolledWindow(G2frame.restrBook)
     2133        G2frame.restrBook.AddPage(GeneralRestr,txt)
     2134        Pages.append(txt)
     2135   
    20242136    if General['SH Texture']['Order']:
    20252137        txt = 'Texture'
Note: See TracChangeset for help on using the changeset viewer.