Ignore:
Timestamp:
Feb 20, 2021 9:43:32 AM (10 months ago)
Author:
toby
Message:

Warn if param limits on constrained vars

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIconstrGUI.py

    r4812 r4822  
    353353        return self.data
    354354       
    355 ################################################################################
    356 #####  Constraints
    357 ################################################################################           
     355#####  Constraints ################################################################################           
    358356def UpdateConstraints(G2frame,data):
    359357    '''Called when Constraints tree item is selected.
     
    655653        return constDictList,phaseDict,fixedList
    656654           
    657     def ConstraintsCheck(data,newcons=[]):
     655    def ConstraintsCheck(data,newcons=[],reqVaryList=None):
    658656        '''Load constraints & check them for errors. Since error checking
    659657        can cause changes in constraints in case of repairable conflicts
     
    661659        This could probably be done more effectively, but only reloading when
    662660        needed, but the reload should be quick.
     661       
     662        When reqVaryList is included (see WarnConstraintLimit) then
     663        parameters with limits are checked against constraints and a
     664        warning is shown.
    663665        '''
    664666        constDictList,phaseDict,fixedList = ConstraintsLoad(data,newcons)
     
    669671        # reload constraints in case any were merged in MoveConfEquiv
    670672        ConstraintsLoad(data,newcons)
     673        impossible = []
     674        if reqVaryList:
     675            Controls = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.root, 'Controls'))
     676            for key in ('parmMinDict','parmMaxDict','parmFrozen'):
     677                if key not in Controls: Controls[key] = {}
     678            varyList = reqVaryList[:]
     679            try:
     680                G2mv.GenerateConstraints(varyList,constDictList,fixedList,phaseDict)
     681                G2mv.Map2Dict(phaseDict,varyList)
     682                # check for limits on dependent vars
     683                consVars = [i for i in reqVaryList if i not in varyList]
     684                impossible = set(
     685                    [str(i) for i in Controls['parmMinDict'] if i in consVars] +
     686                    [str(i) for i in Controls['parmMaxDict'] if i in consVars])
     687            except G2mv.ConstraintException:
     688                pass
     689        if impossible:
     690            msg = ''
     691            for i in sorted(impossible):
     692                if msg: msg += ', '
     693                msg += i
     694            msg =  ' &'.join(msg.rsplit(',',1))
     695            msg = ('Note: limits on variable(s) '+msg+
     696            ' will be ignored because they are constrained.')
     697            G2G.G2MessageBox(G2frame,msg,'Limits ignored for constrained vars')
    671698        return res
    672699
     
    695722            print ('Unexpected contraint warning:\n'+warnmsg)
    696723        return True
     724
     725    def WarnConstraintLimit():
     726        '''Check if constraints reference variables with limits.
     727        Displays a warning message, but does nothing
     728        '''
     729       
     730        try:
     731            parmDict,reqVaryList = G2frame.MakeLSParmDict()
     732            errmsg,warnmsg = ConstraintsCheck(data,[],reqVaryList)
     733        except:
     734            print('Error retrieving parameters')           
     735
    697736
    698737    def CheckChangedConstraint():
     
    884923                    data[constrDictEnt] += newcons
    885924        dlg.Destroy()
     925        WarnConstraintLimit()
    886926        wx.CallAfter(OnPageChanged,None)
    887927                       
     
    9831023                if CheckAddedConstraint(newcons):
    9841024                    data[constrDictEnt] += newcons
     1025        WarnConstraintLimit()
    9851026        wx.CallAfter(OnPageChanged,None)
    9861027                       
     
    13061347    def SetStatusLine(text):
    13071348        G2frame.GetStatusBar().SetStatusText(text,1)
    1308 
    1309     # UpdateConstraints execution starts here
     1349       
     1350    def OnShowISODISTORT(event):
     1351        ShowIsoDistortCalc(G2frame)
     1352
     1353    #### UpdateConstraints execution starts here ##############################
    13101354    if not data:
    13111355        data.update({'Hist':[],'HAP':[],'Phase':[],'Global':[]})       #empty dict - fill it
    13121356    if 'Global' not in data:                                            #patch
    13131357        data['Global'] = []
    1314     # DEBUG code ########################################
     1358    # DEBUG code #=====================================
    13151359    #import GSASIIconstrGUI
    13161360    #reload(GSASIIconstrGUI)
     
    13211365    #reload(G2mv)
    13221366    #reload(G2gd)
    1323     ###################################################
     1367    #===================================================
    13241368    Histograms,Phases = G2frame.GetUsedHistogramsAndPhasesfromTree()
    13251369    if not len(Phases) or not len(Histograms):
     
    13351379            G2frame.dataWindow.ConstraintEdit.Enable(G2G.wxID_SHOWISO,True)
    13361380            break
    1337     ##################################################################################
    1338     # patch: convert old-style (str) variables in constraints to G2VarObj objects
     1381    ###### patch: convert old-style (str) variables in constraints to G2VarObj objects #####
    13391382    for key,value in data.items():
    13401383        if key.startswith('_'): continue
     
    13481391        if j:
    13491392            print (str(key) + ': '+str(j)+' variable(s) as strings converted to objects')
    1350     ##################################################################################
     1393    ##### end patch #############################################################################
    13511394    rigidbodyDict = G2frame.GPXtree.GetItemPyData(
    13521395        G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Rigid bodies'))
     
    14261469    G2frame.Bind(wx.EVT_MENU, OnAddAtomEquiv, id=G2G.wxID_EQUIVALANCEATOMS)
    14271470#    G2frame.Bind(wx.EVT_MENU, OnAddRiding, id=G2G.wxID_ADDRIDING)
    1428     def OnShowISODISTORT(event):
    1429         ShowIsoDistortCalc(G2frame)
    14301471    G2frame.Bind(wx.EVT_MENU, OnShowISODISTORT, id=G2G.wxID_SHOWISO)
    14311472    # tab commands
     
    14621503        print (errmsg)
    14631504        print (G2mv.VarRemapShow([],True))
     1505        return
    14641506    elif warnmsg:
    14651507        print ('Unexpected contraint warning:\n'+warnmsg)
     1508    WarnConstraintLimit()
    14661509       
    1467 ################################################################################
    1468 # check scale & phase fractions, create constraint if needed
    1469 ################################################################################
     1510###### check scale & phase fractions, create constraint if needed #############
    14701511def CheckAllScalePhaseFractions(G2frame):
    14711512    '''Check if scale factor and all phase fractions are refined without a constraint
     
    15271568    Constraints['HAP'] += [constr]
    15281569       
    1529 ################################################################################
    1530 #### Make nuclear/magnetic phase transition constraints - called by OnTransform in G2phsGUI
    1531 ################################################################################       
    1532        
     1570#### Make nuclear/magnetic phase transition constraints - called by OnTransform in G2phsGUI ##########
    15331571def TransConstraints(G2frame,oldPhase,newPhase,Trans,Vec,atCodes):
    15341572    '''Add constraints for new magnetic phase created via transformation of old
     
    17521790            constraints['HAP'].append([IndpCon,DepCons,None,None,'e'])
    17531791       
    1754 ################################################################################
    1755 #### Rigid bodies
    1756 ################################################################################
     1792#### Rigid bodies #############################################################
    17571793resRBsel = None
    17581794def UpdateRigidBodies(G2frame,data):
     
    36483684        G2frame.GetStatusBar().SetStatusText(text,1)                                     
    36493685
    3650     #================== UpdateRigidBodies starts here =========
     3686    #### UpdateRigidBodies starts here =========
    36513687    global resList,resRBsel           
    36523688    if not data.get('RBIds') or not data:
Note: See TracChangeset for help on using the changeset viewer.