Changeset 1805


Ignore:
Timestamp:
Apr 23, 2015 9:54:49 PM (7 years ago)
Author:
toby
Message:

fix bug on with unused constraints and with chained equivalences; improve diagnostics from constraint errors

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r1797 r1805  
    20412041            self._init_Macro()
    20422042        HelpMenu=G2G.MyHelp(self,helpType='Data tree',
    2043             morehelpitems=[#('&Old Tutorials','OldTutorials'), # this will eventually go away
     2043            morehelpitems=[
    20442044                           ('&Tutorials','Tutorials'),
    20452045                           ])
     
    21722172            try:
    21732173                self.StartProject()         #open the file if possible
    2174             except:
    2175                 print 'Error opening file',arg[1]
     2174            except Exception:
     2175                print 'Error opening or reading file',arg[1]
     2176                import traceback
     2177                print traceback.format_exc()
    21762178             
    21772179        self.ImportDir = os.path.normpath(os.getcwd()) # specifies a default path to be used for imports
     
    29532955            self.StartProject()         #open the file if possible
    29542956        except:
    2955             print 'Error opening file ',filename
     2957            print '\nError opening file ',filename
     2958            import traceback
     2959            print traceback.format_exc()
    29562960       
    29572961    def StartProject(self):
     
    29802984            self.PatternTree.SelectItem(Id)
    29812985        self.CheckNotebook()
    2982         os.chdir(self.dirname)           # to get Mac/Linux to change directory!
     2986        if self.dirname: os.chdir(self.dirname)           # to get Mac/Linux to change directory!
    29832987
    29842988    def OnFileClose(self, event):
     
    34693473        self.OnFileSave(event)
    34703474        # check that constraints are OK here
    3471         errmsg, warnmsg = G2stIO.CheckConstraints(self.GSASprojectfile)
     3475        errmsg, warnmsg = G2stIO.ReadCheckConstraints(self.GSASprojectfile)
    34723476        if errmsg:
    3473             print('Error in constraints:\n'+errmsg+
    3474                   '\nRefinement not possible')
    34753477            self.ErrorDialog('Constraint Error',
    3476                              'Error in constraints:\n'+errmsg+
    3477                              '\nRefinement not possible')
     3478                             'Error in constraints. Refinement not possible.'+
     3479                             '\nSee console error message for details.')
    34783480            return
    34793481        if warnmsg:
     
    34813483                  warnmsg+'\nRefinement not possible')
    34823484            self.ErrorDialog('Refinement Flag Error',
    3483                              'Conflict between refinment flag settings and constraints:\n'+
     3485                             'Conflict between refinement flag settings and constraints:\n'+
    34843486                             warnmsg+
    34853487                             '\nRefinement not possible')
     
    35463548        self.OnFileSave(event)
    35473549        # check that constraints are OK here
    3548         errmsg, warnmsg = G2stIO.CheckConstraints(self.GSASprojectfile)
     3550        errmsg, warnmsg = G2stIO.ReadCheckConstraints(self.GSASprojectfile)
    35493551        if errmsg:
    3550             print('Error in constraints:\n'+errmsg+
    3551                   '\nRefinement not possible')
    35523552            self.ErrorDialog('Constraint Error',
    35533553                             'Error in constraints:\n'+errmsg+
  • trunk/GSASIImapvars.py

    r1778 r1805  
    353353                if mv not in indepVarList: indepVarList.append(mv)
    354354                for v,m in zip(varlist,invmultarr):
     355                    if v in indepVarList:
     356                        errmsg += '\nVariable '+v+' is used to set values in a constraint before its value is set in another constraint\n'
    355357                    if m == 0: zeromult = True
    356358                    if v in varyList:
     
    380382
    381383    # check for errors:
    382     if debug:
    383         print 'indepVarList',indepVarList
    384         print 'depVarList',depVarList
    385         print 'multdepVarList',multdepVarList
    386     inboth = set(indepVarList).intersection(set(depVarList))
    387     if len(inboth) > 0:
    388         errmsg += "\nThe following parameters(s) are used as both dependent and independent variables in Equivalence relations:\n"
    389         s = ''
    390         for var in sorted(inboth):
    391             if s != "": s+= ", "
    392             s += str(var)
    393         errmsg += '\t'+ s + '\n'
    394384    if len(multdepVarList) > 0:
    395         errmsg += "\nThe following parameters(s) are used in multiple Equivalence relations as dependent variables:\n"
     385        errmsg += "\nThe following parameters(s) are used in conflicting Equivalence relations as dependent variables:\n"
    396386        s = ''
    397387        for var in sorted(set(multdepVarList)):
     
    582572                for v,m in zip(varlist,invmultarr):
    583573                    if parmDict is not None and v not in parmDict:
    584                         print "Dropping equivalence for variable "+str(v)+". Not defined in this refinement"
     574                        print "Dropping equivalence for dep. variable "+str(v)+". Not defined in this refinement"
    585575                        continue
    586576                    if m == 0: zeromult = True
     
    609599                    s += str(v)           
    610600                msg += str(mv) + " => " + s + '\n'
    611 
    612     if debug: print 'indepVarList',indepVarList
    613     if debug: print 'depVarList',depVarList
    614     # check for errors:
    615     inboth = set(indepVarList).intersection(set(depVarList))
    616     if len(inboth) > 0:
    617         msg += "\nThe following parameters(s) are used as both dependent and independent variables in Equivalence relations:\n"
    618         s = ''
    619         for var in sorted(inboth):
    620             if s != "": s+= ", "
    621             s += str(var)
    622         msg += '\t'+ s + '\n'
    623     if len(multdepVarList) > 0:
    624         msg += "\nThe following parameters(s) are used in multiple Equivalence relations as dependent variables:\n"
    625         s = ''
    626         for var in sorted(set(multdepVarList)):
    627             if s != "": s+= ", "
    628             s += str(var)           
    629         msg += '\t'+ s + '\n'
     601    # save the lists of dep. and indep. vars (after dropping unused)
     602    global dependentVars,independentVars
     603    dependentVars = depVarList
     604    independentVars = indepVarList
    630605    equivVarList = list(set(indepVarList).union(set(depVarList)))
    631606
     
    817792
    818793    '''
    819     dependentVars = []
    820     global dependentParmList
    821     for lst in dependentParmList:
    822         for itm in lst: dependentVars.append(itm)
    823794    return dependentVars
    824795
     
    830801
    831802    '''
    832     independentVars = []
    833     global indParmList,fixedDict
    834     for lst in indParmList:
    835         for name in lst:
    836             if name in fixedDict: continue
    837             independentVars.append(name)
    838803    return independentVars
    839804
     
    922887    return s1
    923888
    924 def VarRemapShow(varyList):
     889def VarRemapShow(varyList,inputOnly=False):
    925890    '''List out the saved relationships. This should be done after the constraints have been
    926891    defined using :func:`StoreEquivalence`, :func:`GroupConstraints` and :func:`GenerateConstraints`.
     
    959924            if mv in varyList: s += ' VARY'
    960925            s += '\n'
     926    if inputOnly: return s
    961927    s += 'Inverse variable mapping relations:\n'
    962928    for varlist,mapvars,invmultarr in zip(dependentParmList,indParmList,invarrayList):
     
    1013979    defined using :func:`StoreEquivalence`,
    1014980    :func:`GroupConstraints` and :func:`GenerateConstraints` and
    1015     before any variable refinement is done
    1016     to complete the parameter dictionary by defining independent
    1017     parameters and satisfying the constraint equations.
     981    before any variable refinement is done. This completes the parameter
     982    dictionary by defining independent parameters and it satisfies the
     983    constraint equations in the initial parameters
    1018984
    1019985    :param dict parmDict: a dict containing parameter values keyed by the
  • trunk/GSASIIstrIO.py

    r1800 r1805  
    6565    '''Read the constraints from the GPX file and interpret them
    6666
    67     called in :func:`CheckConstraints`, :func:`GSASIIstrMain.Refine`
     67    called in :func:`ReadCheckConstraints`, :func:`GSASIIstrMain.Refine`
    6868    and :func:`GSASIIstrMain.SeqRefine`.
    6969    '''
     
    176176    return constDict,fixedList,ignored
    177177
    178 def CheckConstraints(GPXfile):
     178def ReadCheckConstraints(GPXfile):
    179179    '''Load constraints and related info and return any error or warning messages'''
    180180    # init constraints
     
    186186    if not Histograms:
    187187        return 'Error: no diffraction data',''
     188    constrDict,fixedList = GetConstraints(GPXfile) # load user constraints before internally generated ones
    188189    rigidbodyDict = GetRigidBodies(GPXfile)
    189190    rbIds = rigidbodyDict.get('RBIds',{'Vector':[],'Residue':[]})
    190191    rbVary,rbDict = GetRigidBodyModels(rigidbodyDict,Print=False)
    191     Natoms,atomIndx,phaseVary,phaseDict,pawleyLookup,FFtables,BLtables,maxSSwave = GetPhaseData(Phases,RestraintDict=None,rbIds=rbIds,Print=False)
     192    Natoms,atomIndx,phaseVary,phaseDict,pawleyLookup,FFtables,BLtables,maxSSwave = GetPhaseData(Phases,RestraintDict=None,rbIds=rbIds,Print=False) # generates atom symmetry constraints
    192193    hapVary,hapDict,controlDict = GetHistogramPhaseData(Phases,Histograms,Print=False)
    193194    histVary,histDict,controlDict = GetHistogramData(Histograms,Print=False)
    194195    varyList = rbVary+phaseVary+hapVary+histVary
    195     constrDict,fixedList = GetConstraints(GPXfile)
    196     return G2mv.CheckConstraints(varyList,constrDict,fixedList)
    197    
     196    errmsg, warnmsg = G2mv.CheckConstraints(varyList,constrDict,fixedList)
     197    if errmsg:
     198        # print some diagnostic info on the constraints
     199        print('Error in constraints:\n'+errmsg+
     200              '\nRefinement not possible due to conflict in constraints, see below:\n')
     201        print G2mv.VarRemapShow(varyList,True)
     202    return errmsg, warnmsg
    198203def GetRestraints(GPXfile):
    199204    '''Read the restraints from the GPX file.
Note: See TracChangeset for help on using the changeset viewer.