Ignore:
Timestamp:
Apr 27, 2015 1:22:06 PM (7 years ago)
Author:
vondreele
Message:

make new ranId for phases imported from gpx files
eliminate all raise Exceptions from Refine & seqRefine - now gives a ErrorMessage? popup upon e.g. user abort.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIstrMain.py

    r1800 r1812  
    147147    Histograms,Phases = G2stIO.GetUsedHistogramsAndPhases(GPXfile)
    148148    if not Phases:
    149         print ' *** ERROR - you have no phases! ***'
     149        print ' *** ERROR - you have no phases to refine! ***'
    150150        print ' *** Refine aborted ***'
    151         raise Exception
     151        return False,'No phases'
    152152    if not Histograms:
    153153        print ' *** ERROR - you have no data to refine with! ***'
    154154        print ' *** Refine aborted ***'
    155         raise Exception       
     155        return False,'No data'
    156156    rigidbodyDict = G2stIO.GetRigidBodies(GPXfile)
    157157    rbIds = rigidbodyDict.get('RBIds',{'Vector':[],'Residue':[]})
     
    183183        #print 'Errors',errmsg
    184184        #if warnmsg: print 'Warnings',warnmsg
    185         raise Exception(' *** Refine aborted ***')
     185        return False,' Constraint error'
    186186#    print G2mv.VarRemapShow(varyList)
    187187   
     
    189189    print >>printFile,'\n Refinement results:'
    190190    print >>printFile,135*'-'
    191     IfOK,Rvals,result,covMatrix,sig = RefineCore(Controls,Histograms,Phases,restraintDict,
    192         rigidbodyDict,parmDict,varyList,calcControls,pawleyLookup,ifPrint,printFile,dlg)
    193     sigDict = dict(zip(varyList,sig))
    194     newCellDict = G2stMth.GetNewCellParms(parmDict,varyList)
    195     newAtomDict = G2stMth.ApplyXYZshifts(parmDict,varyList)
    196     covData = {'variables':result[0],'varyList':varyList,'sig':sig,'Rvals':Rvals,
    197                'varyListStart':varyListStart,
    198                'covMatrix':covMatrix,'title':GPXfile,'newAtomDict':newAtomDict,
    199                'newCellDict':newCellDict,'freshCOV':True}
    200     # add the uncertainties into the esd dictionary (sigDict)
    201     sigDict.update(G2mv.ComputeDepESD(covMatrix,varyList,parmDict))
    202     G2mv.PrintIndependentVars(parmDict,varyList,sigDict,pFile=printFile)
    203     G2stMth.ApplyRBModels(parmDict,Phases,rigidbodyDict,True)
    204     G2stIO.SetRigidBodyModels(parmDict,sigDict,rigidbodyDict,printFile)
    205     G2stIO.SetPhaseData(parmDict,sigDict,Phases,rbIds,covData,restraintDict,printFile)
    206     G2stIO.SetHistogramPhaseData(parmDict,sigDict,Phases,Histograms,pFile=printFile)
    207     G2stIO.SetHistogramData(parmDict,sigDict,Histograms,pFile=printFile)
    208     G2stIO.SetUsedHistogramsAndPhases(GPXfile,Histograms,Phases,rigidbodyDict,covData)
    209     printFile.close()
    210     print ' Refinement results are in file: '+ospath.splitext(GPXfile)[0]+'.lst'
    211     print ' ***** Refinement successful *****'
     191    try:
     192        IfOK,Rvals,result,covMatrix,sig = RefineCore(Controls,Histograms,Phases,restraintDict,
     193            rigidbodyDict,parmDict,varyList,calcControls,pawleyLookup,ifPrint,printFile,dlg)
     194        sigDict = dict(zip(varyList,sig))
     195        newCellDict = G2stMth.GetNewCellParms(parmDict,varyList)
     196        newAtomDict = G2stMth.ApplyXYZshifts(parmDict,varyList)
     197        covData = {'variables':result[0],'varyList':varyList,'sig':sig,'Rvals':Rvals,
     198                   'varyListStart':varyListStart,
     199                   'covMatrix':covMatrix,'title':GPXfile,'newAtomDict':newAtomDict,
     200                   'newCellDict':newCellDict,'freshCOV':True}
     201        # add the uncertainties into the esd dictionary (sigDict)
     202        sigDict.update(G2mv.ComputeDepESD(covMatrix,varyList,parmDict))
     203        G2mv.PrintIndependentVars(parmDict,varyList,sigDict,pFile=printFile)
     204        G2stMth.ApplyRBModels(parmDict,Phases,rigidbodyDict,True)
     205        G2stIO.SetRigidBodyModels(parmDict,sigDict,rigidbodyDict,printFile)
     206        G2stIO.SetPhaseData(parmDict,sigDict,Phases,rbIds,covData,restraintDict,printFile)
     207        G2stIO.SetHistogramPhaseData(parmDict,sigDict,Phases,Histograms,pFile=printFile)
     208        G2stIO.SetHistogramData(parmDict,sigDict,Histograms,pFile=printFile)
     209        G2stIO.SetUsedHistogramsAndPhases(GPXfile,Histograms,Phases,rigidbodyDict,covData)
     210        printFile.close()
     211        print ' Refinement results are in file: '+ospath.splitext(GPXfile)[0]+'.lst'
     212        print ' ***** Refinement successful *****'
     213    except G2stMth.UserAbort:
     214        printFile.close()
     215        return False,'Refinement aborted by user'
    212216   
    213217#for testing purposes!!!
     
    227231
    228232    if dlg:
    229         return Rvals['Rwp']
     233        return True,Rvals['Rwp']
    230234
    231235def SeqRefine(GPXfile,dlg):
     
    378382        print >>printFile,'\n Refinement results for histogram: v'+histogram
    379383        print >>printFile,135*'-'
    380         IfOK,Rvals,result,covMatrix,sig = RefineCore(Controls,Histo,Phases,restraintDict,
    381             rigidbodyDict,parmDict,varyList,calcControls,pawleyLookup,ifPrint,printFile,dlg)
    382 
    383         print '  wR = %7.2f%%, chi**2 = %12.6g, reduced chi**2 = %6.2f, last delta chi = %.4f'%(
    384             Rvals['Rwp'],Rvals['chisq'],Rvals['GOF']**2,Rvals['DelChi2'])
    385         # add the uncertainties into the esd dictionary (sigDict)
    386         sigDict = dict(zip(varyList,sig))
    387         # the uncertainties for dependent constrained parms into the esd dict
    388         sigDict.update(G2mv.ComputeDepESD(covMatrix,varyList,parmDict))
    389 
    390         # a dict with values & esds for dependent (constrained) parameters
    391         depParmDict = {i:(parmDict[i],sigDict[i]) for i in varyListStart
    392                        if i not in varyList}
    393         newCellDict = copy.deepcopy(G2stMth.GetNewCellParms(parmDict,varyList))
    394         newAtomDict = copy.deepcopy(G2stMth.ApplyXYZshifts(parmDict,varyList))
    395         histRefData = {
    396             'variables':result[0],'varyList':varyList,'sig':sig,'Rvals':Rvals,
    397             'varyListStart':varyListStart,
    398             'covMatrix':covMatrix,'title':histogram,'newAtomDict':newAtomDict,
    399             'newCellDict':newCellDict,'depParmDict':depParmDict,
    400             'constraintInfo':constraintInfo,
    401             'parmDict':parmDict}
    402         SeqResult[histogram] = histRefData
    403         G2stMth.ApplyRBModels(parmDict,Phases,rigidbodyDict,True)
    404 #        G2stIO.SetRigidBodyModels(parmDict,sigDict,rigidbodyDict,printFile)
    405         G2stIO.SetHistogramPhaseData(parmDict,sigDict,Phases,Histo,ifPrint,printFile)
    406         G2stIO.SetHistogramData(parmDict,sigDict,Histo,ifPrint,printFile)
    407         G2stIO.SetUsedHistogramsAndPhases(GPXfile,Histo,Phases,rigidbodyDict,histRefData,makeBack)
    408         makeBack = False
    409         NewparmDict = {}
    410         # make dict of varied parameters in current histogram, renamed to
    411         # next histogram, for use in next refinement.
    412         if Controls['Copy2Next'] and ihst < len(histNames)-1:
    413             hId = Histo[histogram]['hId'] # current histogram
    414             nexthId = Histograms[histNames[ihst+1]]['hId']
    415             for parm in set(list(varyList)+list(varyListStart)):
    416                 items = parm.split(':')
    417                 if len(items) < 3: continue
    418                 if str(hId) in items[1]:
    419                     items[1] = str(nexthId)
    420                     newparm = ':'.join(items)
    421                     NewparmDict[newparm] = parmDict[parm]
     384        try:
     385            IfOK,Rvals,result,covMatrix,sig = RefineCore(Controls,Histo,Phases,restraintDict,
     386                rigidbodyDict,parmDict,varyList,calcControls,pawleyLookup,ifPrint,printFile,dlg)
     387   
     388            print '  wR = %7.2f%%, chi**2 = %12.6g, reduced chi**2 = %6.2f, last delta chi = %.4f'%(
     389                Rvals['Rwp'],Rvals['chisq'],Rvals['GOF']**2,Rvals['DelChi2'])
     390            # add the uncertainties into the esd dictionary (sigDict)
     391            sigDict = dict(zip(varyList,sig))
     392            # the uncertainties for dependent constrained parms into the esd dict
     393            sigDict.update(G2mv.ComputeDepESD(covMatrix,varyList,parmDict))
     394   
     395            # a dict with values & esds for dependent (constrained) parameters
     396            depParmDict = {i:(parmDict[i],sigDict[i]) for i in varyListStart
     397                           if i not in varyList}
     398            newCellDict = copy.deepcopy(G2stMth.GetNewCellParms(parmDict,varyList))
     399            newAtomDict = copy.deepcopy(G2stMth.ApplyXYZshifts(parmDict,varyList))
     400            histRefData = {
     401                'variables':result[0],'varyList':varyList,'sig':sig,'Rvals':Rvals,
     402                'varyListStart':varyListStart,
     403                'covMatrix':covMatrix,'title':histogram,'newAtomDict':newAtomDict,
     404                'newCellDict':newCellDict,'depParmDict':depParmDict,
     405                'constraintInfo':constraintInfo,
     406                'parmDict':parmDict}
     407            SeqResult[histogram] = histRefData
     408            G2stMth.ApplyRBModels(parmDict,Phases,rigidbodyDict,True)
     409    #        G2stIO.SetRigidBodyModels(parmDict,sigDict,rigidbodyDict,printFile)
     410            G2stIO.SetHistogramPhaseData(parmDict,sigDict,Phases,Histo,ifPrint,printFile)
     411            G2stIO.SetHistogramData(parmDict,sigDict,Histo,ifPrint,printFile)
     412            G2stIO.SetUsedHistogramsAndPhases(GPXfile,Histo,Phases,rigidbodyDict,histRefData,makeBack)
     413            makeBack = False
     414            NewparmDict = {}
     415            # make dict of varied parameters in current histogram, renamed to
     416            # next histogram, for use in next refinement.
     417            if Controls['Copy2Next'] and ihst < len(histNames)-1:
     418                hId = Histo[histogram]['hId'] # current histogram
     419                nexthId = Histograms[histNames[ihst+1]]['hId']
     420                for parm in set(list(varyList)+list(varyListStart)):
     421                    items = parm.split(':')
     422                    if len(items) < 3: continue
     423                    if str(hId) in items[1]:
     424                        items[1] = str(nexthId)
     425                        newparm = ':'.join(items)
     426                        NewparmDict[newparm] = parmDict[parm]
     427        except G2stMth.UserAbort:
     428            printFile.close()
     429            print ' ***** Refinement aborted *****'
     430            return False,' Refinement aborted by user'
    422431    G2stIO.SetSeqResult(GPXfile,Histograms,SeqResult)
    423432    printFile.close()
Note: See TracChangeset for help on using the changeset viewer.