Changeset 1160


Ignore:
Timestamp:
Nov 28, 2013 9:16:02 PM (8 years ago)
Author:
toby
Message:

finish ISODISPLACE fixes; improve show var window; improve help window; add refine checkbox for newvars in constraints display

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r1147 r1160  
    26032603    def MakeLSParmDict(self):
    26042604        '''Load all parameters used for computation from the tree into a
    2605         dict
     2605        dict of paired values [value, refine flag]. Note that this is
     2606        different than the parmDict used in the refinement, which only has
     2607        values.
    26062608
    26072609        :returns: (parmDict,varyList) where:
     
    26462648        '''
    26472649        parmDict,varyList = self.MakeLSParmDict()
    2648         dlg = G2gd.ShowLSParms(self,'Least Squares Parameters',parmDict,varyList)
     2650        parmValDict = {}
     2651        for i in parmDict:
     2652            parmValDict[i] = parmDict[i][0]
     2653           
     2654        reqVaryList = tuple(varyList) # save requested variables
     2655        try:
     2656            # process constraints
     2657            sub = G2gd.GetPatternTreeItemId(self,self.root,'Constraints')
     2658            Constraints = self.PatternTree.GetItemPyData(sub)
     2659            constList = []
     2660            for item in Constraints:
     2661                if item.startswith('_'): continue
     2662                constList += Constraints[item]
     2663            G2mv.InitVars()
     2664            constrDict,fixedList,ignored = G2stIO.ProcessConstraints(constList)
     2665            groups,parmlist = G2mv.GroupConstraints(constrDict)
     2666            G2mv.GenerateConstraints(groups,parmlist,varyList,constrDict,fixedList)
     2667            G2mv.Map2Dict(parmValDict,varyList)
     2668        except:
     2669            pass
     2670        dlg = G2gd.ShowLSParms(self,'Least Squares Parameters',parmValDict,varyList,reqVaryList)
    26492671        dlg.ShowModal()
    26502672        dlg.Destroy()
  • trunk/GSASIIIO.py

    r1157 r1160  
    20182018        constList = []
    20192019        for item in consDict:
     2020            if item.startswith('_'): continue
    20202021            constList += consDict[item]
    20212022        # now process the constraints
  • trunk/GSASIIconstrGUI.py

    r1147 r1160  
    511511        '''
    512512        allcons = []
    513         for key in ['Hist','HAP','Phase','Global']:
     513        for key in data:
     514            if key.startswith('_'): continue
    514515            allcons += data[key]
    515516        allcons += newcons
     
    538539        '''
    539540        allcons = []
    540         for key in 'Hist','HAP','Phase':
     541        for key in data:
     542            if key.startswith('_'): continue
    541543            allcons += data[key]
    542544        if not len(allcons): return True
     
    675677        :returns: wx.Sizer created by method
    676678        '''
    677         constSizer = wx.FlexGridSizer(1,5,0,0)
     679        constSizer = wx.FlexGridSizer(1,6,0,0)
    678680        maxlen = 70 # characters before wrapping a constraint
    679681        for Id,item in enumerate(data[name]):
     682            refineflag = False
    680683            helptext = ""
    681684            eqString = ['',]
     
    693696                Indx[constEdit.GetId()] = [Id,name]
    694697                if item[-1] == 'f':
    695                     helptext = "A new variable is created from a linear combination of the following variables:"
     698                    helptext = "A new variable"
     699                    if item[-3]:
     700                        helptext += " named "+str(item[-3])
     701                    helptext += " is created from a linear combination of the following variables:\n"
    696702                    for term in item[:-3]:
    697703                        var = str(term[1])
     
    712718                            helptext += '\n\n'
    713719                            helptext += data['_Explain'][item[-3]]
    714                     typeString = 'NEWVAR'
     720                    # typeString = 'NEWVAR'
     721                    # if item[-3]:
     722                    #     eqString[-1] += ' = '+item[-3]
     723                    # else:
     724                    #     eqString[-1] += ' = New Variable'
    715725                    if item[-3]:
    716                         eqString[-1] += ' = '+item[-3]
     726                        typeString = item[-3] + ' = '
    717727                    else:
    718                         eqString[-1] += ' = New Variable'
     728                        typeString = 'New Variable = '
     729                    #print 'refine',item[-2]
     730                    refineflag = True
    719731                elif item[-1] == 'c':
    720732                    helptext = "The following variables constrained to equal a constant:"
     
    732744                        helptext += "\n" + var + " ("+ varMean + ")"
    733745                    typeString = 'CONST'
    734                     eqString[-1] += ' = %.3f'%(item[-3])+'  '
     746                    eqString[-1] += ' = '+str(item[-3])
    735747                elif item[-1] == 'e':
    736748                    helptext = "The following variables are set to be equivalent, noting multipliers:"
     
    763775                constSizer.Add(ch,0,wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER,1)
    764776            else:
     777                constSizer.Add((-1,-1))
     778            if refineflag:
     779                ch = G2gd.G2CheckBox(pageDisplay,'',item,-2)
     780                constSizer.Add(ch,0,wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER,1)
     781            else:
    765782                constSizer.Add((-1,-1))               
    766             constSizer.Add(wx.StaticText(pageDisplay,-1,typeString),0,wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER|wx.RIGHT|wx.LEFT,3)
     783            constSizer.Add(wx.StaticText(pageDisplay,-1,typeString),
     784                           0,wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER|wx.RIGHT|wx.LEFT,3)
    767785            if len(eqString) > 1:
    768786                Eq = wx.BoxSizer(wx.VERTICAL)
     
    815833                result = dlg.GetData()
    816834                for i in range(len(data[name][Id][:-3])):
     835                    if type(data[name][Id][i]) is tuple: # fix non-mutable construct
     836                        data[name][Id][i] = list(data[name][Id][i])
    817837                    data[name][Id][i][0] = result[i][0]
    818838                if data[name][Id][-1] == 'c':
     
    825845                    varname = varname.replace(':',';')
    826846                    if varname:
    827                         data[name][Id][-3] = '::' + varname
     847                        data[name][Id][-3] = varname
    828848                    else:
    829849                        data[name][Id][-3] = ''
     
    925945    # validate all the constrants -- should not see any errors here normally
    926946    allcons = []
    927     for key in 'Hist','HAP','Phase':
     947    for key in data:
     948        if key.startswith('_'): continue
    928949        allcons += data[key]
    929950    if not len(allcons): return
  • trunk/GSASIIgrid.py

    r1147 r1160  
    15671567    '''Create frame to show least-squares parameters
    15681568    '''
    1569     def __init__(self,parent,title,parmDict,varyList=None,
     1569    def __init__(self,parent,title,parmDict,varyList,fullVaryList,
    15701570                 size=(300,430)):
    15711571        wx.Dialog.__init__(self,parent,wx.ID_ANY,title,size=size,
     
    15771577            #size=size,
    15781578            style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
    1579         if varyList:
    1580             num = len(varyList)
    1581             mainSizer.Add(wx.StaticText(self,wx.ID_ANY,'Number of refined variables: '+str(num)))
     1579        num = len(varyList)
     1580        mainSizer.Add(wx.StaticText(self,wx.ID_ANY,'Number of refined variables: '+str(num)))
     1581        num = len(fullVaryList)
     1582        mainSizer.Add(wx.StaticText(self,wx.ID_ANY,'Number dependent and refined variables: '+str(num)))
    15821583
    15831584        subSizer = wx.FlexGridSizer(rows=len(parmDict)+1,cols=4,hgap=2,vgap=2)
    15841585        parmNames = parmDict.keys()
    15851586        parmNames.sort()
    1586         #parmText = ' p:h:Parameter       refine?              value\n'
    15871587        subSizer.Add((-1,-1))
    15881588        subSizer.Add(wx.StaticText(panel,wx.ID_ANY,'Parameter name  '))
    15891589        subSizer.Add(wx.StaticText(panel,wx.ID_ANY,'refine?'))
    15901590        subSizer.Add(wx.StaticText(panel,wx.ID_ANY,'value'),0,wx.ALIGN_RIGHT)
     1591        explainRefine = False
    15911592        for name in parmNames:
     1593            # skip entries without numerical values
     1594            if isinstance(parmDict[name],basestring): continue
     1595            try:
     1596                value = G2py3.FormatValue(parmDict[name])
     1597            except TypeError:
     1598                value = str(parmDict[name])+' -?' # unexpected
     1599                #continue
    15921600            v = G2obj.getVarDescr(name)
    15931601            if v is None or v[-1] is None:
     
    15971605                subSizer.Add(ch,0,wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER,1)
    15981606            subSizer.Add(wx.StaticText(panel,wx.ID_ANY,str(name)))
    1599             subSizer.Add(wx.StaticText(panel,wx.ID_ANY,str(parmDict[name][1])))
    1600             try:
    1601                 value = G2py3.FormatValue(parmDict[name][0])
    1602             except TypeError:
    1603                 value = str(parmDict[name][0])
     1607            if name in varyList:
     1608                subSizer.Add(wx.StaticText(panel,wx.ID_ANY,'R'))
     1609            elif name in fullVaryList:
     1610                subSizer.Add(wx.StaticText(panel,wx.ID_ANY,'C'))
     1611                explainRefine = True
     1612            else:
     1613                subSizer.Add((-1,-1))
    16041614            subSizer.Add(wx.StaticText(panel,wx.ID_ANY,value),0,wx.ALIGN_RIGHT)
    16051615
     
    16101620        mainSizer.Add(panel,1, wx.ALL|wx.EXPAND,1)
    16111621
     1622        if explainRefine:
     1623            mainSizer.Add(
     1624                wx.StaticText(self,wx.ID_ANY,
     1625                          '"R" indicates a refined variable\n'+
     1626                          '"C" is generated from a constraint'
     1627                          ),
     1628                0, wx.ALL,0)
    16121629        # make OK button
    16131630        btnsizer = wx.BoxSizer(wx.HORIZONTAL)
     
    16181635        # Allow window to be enlarged but not made smaller
    16191636        self.SetSizer(mainSizer)
    1620         #mainSizer.Fit(self)
    16211637        self.SetMinSize(self.GetSize())
    16221638
     
    19741990        self.msg=msg
    19751991        self.parent = parent
     1992    def _onClose(self,event):
     1993        self.dlg.EndModal(wx.ID_CANCEL)
    19761994    def _onPress(self,event):
    19771995        'Respond to a button press by displaying the requested text'
    1978         dlg = wx.MessageDialog(self.parent,self.msg,'Help info',wx.OK)
    1979         dlg.ShowModal()
    1980         dlg.Destroy()
     1996        #dlg = wx.MessageDialog(self.parent,self.msg,'Help info',wx.OK)
     1997        self.dlg = wx.Dialog(self.parent,wx.ID_ANY,'Help information',
     1998                        style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
     1999        #self.dlg.SetBackgroundColour(wx.WHITE)
     2000        mainSizer = wx.BoxSizer(wx.VERTICAL)
     2001        txt = wx.StaticText(self.dlg,wx.ID_ANY,self.msg)
     2002        mainSizer.Add(txt,1,wx.ALL|wx.EXPAND,10)
     2003        txt.SetBackgroundColour(wx.WHITE)
     2004
     2005        btnsizer = wx.BoxSizer(wx.HORIZONTAL)
     2006        btn = wx.Button(self.dlg, wx.ID_CLOSE)
     2007        btn.Bind(wx.EVT_BUTTON,self._onClose)
     2008        btnsizer.Add(btn)
     2009        mainSizer.Add(btnsizer, 0, wx.ALIGN_CENTER|wx.ALL, 5)
     2010        self.dlg.SetSizer(mainSizer)
     2011        mainSizer.Fit(self.dlg)
     2012        self.dlg.ShowModal()
     2013        self.dlg.Destroy()
    19812014################################################################################
    19822015class MyHtmlPanel(wx.Panel):
     
    24962529        self.AtomCompute.ISOcalc = self.AtomCompute.Append(
    24972530            id=wxID_ISODISP, kind=wx.ITEM_NORMAL,
    2498             text='Compute ISODISPLACE mode values',
    2499             help='Compute values of ISODISPLACE modes from atom parameters')
     2531            text='Compute ISODISTORT mode values',
     2532            help='Compute values of ISODISTORT modes from atom parameters')
    25002533        self.PostfillDataMenu()
    25012534                 
  • trunk/GSASIImapvars.py

    r1143 r1160  
    551551    for varlist,mapvars,multarr,invmultarr in zip(
    552552        dependentParmList,indParmList,arrayList,invarrayList):
    553         if multarr is None:
     553        if multarr is None: # do only if an equivalence
    554554            zeromult = False
    555555            for mv in mapvars:
     
    638638               
    639639    # now process each group and create the relations that are needed to form
    640     # non-singular square matrix
     640    # a non-singular square matrix
    641641    # If all are varied and this is a constraint equation, then set VaryFree flag
    642642    # so that the newly created relationships will be varied
     
    671671        group = group[:]
    672672        # scan through all generated and input relationships, we need to add to the varied list
    673         # all the new parameters where VaryFree has been set or where all the
    674         # dependent parameters are varied. Check again for inconsistent variable use
    675         # for new variables -- where varied and unvaried parameters get grouped
    676         # together. I don't think this can happen when not flagged before, but
    677         # it does not hurt to check again.
     673        # all the new parameters where VaryFree has been set or where a New Var is varied.
     674        #
     675        # If a group does not contain any fixed values (constraint equations)
     676        # and nothing in the group is varied, drop this group, so that the
     677        # dependent parameters can be refined individually.
     678        unused = True
    678679        for i in range(len(varlist)):
    679680            if len(group) > 0: # get the original equation reference
     
    682683                varyflag = constrDict[rel].get('_vary',False)
    683684                varname = constrDict[rel].get('_name','')
    684             else: # relationship has been generated
     685            else: # this relationship has been generated
    685686                varyflag = False
    686687                varname = ''
     
    692693                mapvar.append(varname)
    693694                # vary the new relationship if it is a degree of freedom in
    694                 # a set of contraint equations or if a new variable is flagged to be varied.
     695                # a set of contraint equations or if a New Var is flagged to be varied.
    695696                if VaryFree or varyflag:
     697                    unused = False
    696698                    varyList.append(varname)
    697699                    # fix (prevent varying) of all the variables inside the constraint group
     700                    # (dependent vars)
    698701                    for var in varsList:
    699702                        if var in varyList: varyList.remove(var)
    700703            else:
     704                unused = False
    701705                mapvar.append(fixedval)
     706        if unused: continue # skip over constraints that do not have a fixed value or a refined variable
    702707        dependentParmList.append(varlist)
    703708        arrayList.append(constrArr)
  • trunk/GSASIIphsGUI.py

    r1150 r1160  
    16341634        '''Compute the ISODISTORT mode values from the current coordinates.
    16351635        Called in response to the (Phase/Atoms tab) AtomCompute
    1636         "Compute ISODISPLACE mode values" menu item, which should be enabled
     1636        "Compute ISODISTORT mode values" menu item, which should be enabled
    16371637        only when Phase['ISODISTORT'] is defined.
    16381638        '''
     
    16651665            deltaList.append(cval-pval)
    16661666        modeVals = np.inner(ISO['Var2ModeMatrix'],deltaList)
    1667         dlg = wx.Dialog(G2frame,wx.ID_ANY,'ISODISPLACE mode values',#size=(630,400),
     1667        dlg = wx.Dialog(G2frame,wx.ID_ANY,'ISODISTORT mode values',#size=(630,400),
    16681668                           style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
    16691669        mainSizer = wx.BoxSizer(wx.VERTICAL)
  • trunk/GSASIIstrIO.py

    r1145 r1160  
    6868    and :func:`GSASIIstrMain.SeqRefine`.
    6969    '''
    70     constList = []
    7170    fl = open(GPXfile,'rb')
    7271    while True:
     
    7776        datum = data[0]
    7877        if datum[0] == 'Constraints':
    79             constDict = datum[1]
    80             for item in constDict:
    81                 constList += constDict[item]
     78            constList = []
     79            for item in datum[1]:
     80                if item.startswith('_'): continue
     81                constList += datum[1][item]
     82            fl.close()
     83            constDict,fixedList,ignored = ProcessConstraints(constList)
     84            if ignored:
     85                print ignored,'Constraints were rejected. Was a constrained phase, histogram or atom deleted?'
     86            return constDict,fixedList
    8287    fl.close()
    83     constDict,fixedList,ignored = ProcessConstraints(constList)
    84     if ignored:
    85         print ignored,'Constraints were rejected. Was a constrained phase, histogram or atom deleted?'
    86     return constDict,fixedList
     88    raise Exception,"No constraints in GPX file"
    8789   
    8890def ProcessConstraints(constList):
     
    101103     
    102104      * constDict (list of dicts) contains the constraint relationships
    103       * fixedList (list) contains the fixed values for type
     105      * fixedList (list) contains the fixed values for each type
    104106        of constraint.
    105107      * ignored (int) counts the number of invalid constraint items
     
    130132            if len(D) > 1:
    131133                # add extra dict terms for input variable name and vary flag
    132                 if varname is not None:
    133                     D['_name'] = varname
     134                if varname is not None:                   
     135                    if varname.startswith('::'):
     136                        varname = varname[2:].replace(':',';')
     137                    else:
     138                        varname = varname.replace(':',';')
     139                    D['_name'] = '::' + varname
    134140                D['_vary'] = varyFlag == True # force to bool
    135141                constDict.append(D)
  • trunk/imports/G2phase_ISO.py

    r1147 r1160  
    2222    def __init__(self):
    2323        super(self.__class__,self).__init__( # fancy way to say ImportPhase.__init__
    24             extensionlist=('.CIF','.cif'),
     24            extensionlist=('.CIF','.cif','.txt'),
    2525            strictExtension=False,
    2626            formatName = 'ISODISTORT CIF',
     
    199199                self.Phase['General']['Name'] = name.strip()[:20]
    200200                #----------------------------------------------------------------------
    201                 # now read in the ISODISPLACE modes
     201                # now read in the ISODISTORT modes
    202202                #----------------------------------------------------------------------
    203203                modelist = []
     
    298298                    for j,(lbl,k) in enumerate(zip(coordVarLbl,row)):
    299299                        if k == 0: continue
    300                         constraint.append((k,G2varObj[j]))
     300                        constraint.append([k,G2varObj[j]])
    301301                    constraint += [shortmodelist[i],False,'f']
    302302                    self.Constraints.append(constraint)
     
    314314                explaination = {}
    315315                for mode,shortmode in zip(modelist,shortmodelist):
    316                     explaination[shortmode] = "IsoDisplace full name "+str(mode)
     316                    explaination[shortmode] = "ISODISTORT full name "+str(mode)
    317317                self.Constraints.append(explaination)
    318318
     
    328328                # print 70*'='
    329329
    330                 # # debug: Get the ISODISPLACE offset values
     330                # # debug: Get the ISODISTORT offset values
    331331                # coordVarDelta = {}
    332332                # for lbl,val in zip(
Note: See TracChangeset for help on using the changeset viewer.