Changeset 5287


Ignore:
Timestamp:
May 23, 2022 1:24:25 PM (17 months ago)
Author:
vondreele
Message:

improvements to zero cycle refinement & partial calcs.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIdataGUI.py

    r5282 r5287  
    8484import GSASIIpwd as G2pwd
    8585import GSASIIstrMain as G2stMn
     86import GSASIIstrMath as G2stMth
    8687import defaultIparms as dI
    8788import GSASIIfpaGUI as G2fpa
     
    55645565        Controls = self.GPXtree.GetItemPyData(GetGPXtreeItemId(self,self.root, 'Controls'))
    55655566        savCyc,Controls['max cyc'] = Controls['max cyc'],0
     5567        saveDervtype,Controls['deriv type'] = Controls['deriv type'],'analytic Hessian'
    55665568        Controls['PhasePartials'] = os.path.abspath(os.path.splitext(self.GSASprojectfile)[0]+'.partials')
    55675569        self.OnFileSave(event)
     
    55745576        except Exception as msg:
    55755577            print('Refinement failed with message',msg)
     5578            Controls['deriv type'] = saveDervtype
    55765579            Controls['max cyc'] = savCyc
    55775580            Controls['PhasePartials'] = None
     
    55935596                dlg.Destroy()
    55945597            if result == wx.ID_NO:
     5598                Controls['deriv type'] = saveDervtype
    55955599                Controls['max cyc'] = savCyc
    55965600                Controls['PhasePartials'] = None
     
    56335637                    print('Error histogram',hId,'not found. This should not happen!')
    56345638                    fp.close()
     5639                    Controls['deriv type'] = saveDervtype
    56355640                    Controls['max cyc'] = savCyc
    56365641                    Controls['PhasePartials'] = None
     
    56635668                print('File',phPartialFile,'written')
    56645669
     5670        Controls['deriv type'] = saveDervtype
    56655671        Controls['max cyc'] = savCyc
    56665672        Controls['PhasePartials'] = None
  • trunk/GSASIImath.py

    r5271 r5287  
    383383        return [x0,None,info]
    384384    chisqf = np.sum(M**2) # ending chi**2
     385    if not maxcyc:  #zero cycle calc exit here
     386        info = {'num cyc':0,'fvec':M,'nfev':0,'lamMax':0,'SVD0':0,
     387            'Converged':True, 'DelChi2':0., 'Xvec':XvecAll, 'chisq0':chisqf}
     388        return [x0,None,info]
    385389    psing_prev = [i for i in range(n) if i not in indices] # save dropped vars
    386390    if AmatAll is None: # Save some time and use Hessian from the last refinement cycle
  • trunk/GSASIIstrMain.py

    r5266 r5287  
    253253            break
    254254        IfOK = True
    255         if not len(varyList):
     255        if not len(varyList) or not result[2]['num cyc']:
    256256            covMatrix = []
    257257            break
     
    403403            refPlotUpdate=refPlotUpdate)
    404404        if IfOK:
    405             sigDict = dict(zip(varyList,sig))
    406             newCellDict = G2stMth.GetNewCellParms(parmDict,varyList)
    407             newAtomDict = G2stMth.ApplyXYZshifts(parmDict,varyList)
    408             covData = {'variables':result[0],'varyList':varyList,'sig':sig,'Rvals':Rvals,
    409                        'varyListStart':varyListStart,'Lastshft':Lastshft,
    410                        'covMatrix':covMatrix,'title':GPXfile,'newAtomDict':newAtomDict,
    411                        'newCellDict':newCellDict,'freshCOV':True}
    412             # add indirectly computed uncertainties into the esd dict
    413             sigDict.update(G2mv.ComputeDepESD(covMatrix,varyList))
    414             G2stIO.PrintIndependentVars(parmDict,varyList,sigDict,pFile=printFile)
    415             G2stMth.ApplyRBModels(parmDict,Phases,rigidbodyDict,True)
    416             G2stIO.SetRigidBodyModels(parmDict,sigDict,rigidbodyDict,printFile)
    417             G2stIO.SetPhaseData(parmDict,sigDict,Phases,rbIds,covData,restraintDict,printFile)
    418             G2stIO.SetISOmodes(parmDict,sigDict,Phases,printFile)
    419             G2stIO.SetHistogramPhaseData(parmDict,sigDict,Phases,Histograms,calcControls,
    420                                          pFile=printFile,covMatrix=covMatrix,varyList=varyList)
    421             G2stIO.SetHistogramData(parmDict,sigDict,Histograms,calcControls,pFile=printFile)
    422             # check for variables outside their allowed range, reset and freeze them
    423             frozen = dropOOBvars(varyList,parmDict,sigDict,Controls,parmFrozenList)
    424             # covData['depSig'] = G2stIO.PhFrExtPOSig  # created in G2stIO.SetHistogramData, no longer used?
    425             covData['depSigDict'] = {i:(parmDict[i],sigDict[i]) for i in parmDict if i in sigDict}
    426             if len(frozen):
    427                 if 'msg' in Rvals:
    428                     Rvals['msg'] += '\n'
    429                 else:
    430                     Rvals['msg'] = ''
    431                 msg = ('Warning: {} variable(s) refined outside limits and were frozen ({} total frozen)'
    432                     .format(len(frozen),len(parmFrozenList))
    433                     )
    434                 G2fil.G2Print(msg)
    435                 Rvals['msg'] += msg
    436             elif len(parmFrozenList):
    437                 if 'msg' in Rvals:
    438                     Rvals['msg'] += '\n'
    439                 else:
    440                     Rvals['msg'] = ''
    441                 msg = ('Note: a total of {} variable(s) are frozen due to refining outside limits'
    442                     .format(len(parmFrozenList))
    443                     )
    444                 G2fil.G2Print('Note: ',msg)
    445                 Rvals['msg'] += msg
     405            if len(covMatrix):      #empty for zero cycle refinement
     406                sigDict = dict(zip(varyList,sig))
     407                newCellDict = G2stMth.GetNewCellParms(parmDict,varyList)
     408                newAtomDict = G2stMth.ApplyXYZshifts(parmDict,varyList)
     409                covData = {'variables':result[0],'varyList':varyList,'sig':sig,'Rvals':Rvals,
     410                           'varyListStart':varyListStart,'Lastshft':Lastshft,
     411                           'covMatrix':covMatrix,'title':GPXfile,'newAtomDict':newAtomDict,
     412                           'newCellDict':newCellDict,'freshCOV':True}
     413                # add indirectly computed uncertainties into the esd dict
     414                sigDict.update(G2mv.ComputeDepESD(covMatrix,varyList))
     415                G2stIO.PrintIndependentVars(parmDict,varyList,sigDict,pFile=printFile)
     416                G2stMth.ApplyRBModels(parmDict,Phases,rigidbodyDict,True)
     417                G2stIO.SetRigidBodyModels(parmDict,sigDict,rigidbodyDict,printFile)
     418                G2stIO.SetPhaseData(parmDict,sigDict,Phases,rbIds,covData,restraintDict,printFile)
     419                G2stIO.SetISOmodes(parmDict,sigDict,Phases,printFile)
     420                G2stIO.SetHistogramPhaseData(parmDict,sigDict,Phases,Histograms,calcControls,
     421                                             pFile=printFile,covMatrix=covMatrix,varyList=varyList)
     422                G2stIO.SetHistogramData(parmDict,sigDict,Histograms,calcControls,pFile=printFile)
     423                # check for variables outside their allowed range, reset and freeze them
     424                frozen = dropOOBvars(varyList,parmDict,sigDict,Controls,parmFrozenList)
     425                # covData['depSig'] = G2stIO.PhFrExtPOSig  # created in G2stIO.SetHistogramData, no longer used?
     426                covData['depSigDict'] = {i:(parmDict[i],sigDict[i]) for i in parmDict if i in sigDict}
     427                if len(frozen):
     428                    if 'msg' in Rvals:
     429                        Rvals['msg'] += '\n'
     430                    else:
     431                        Rvals['msg'] = ''
     432                    msg = ('Warning: {} variable(s) refined outside limits and were frozen ({} total frozen)'
     433                        .format(len(frozen),len(parmFrozenList))
     434                        )
     435                    G2fil.G2Print(msg)
     436                    Rvals['msg'] += msg
     437                elif len(parmFrozenList):
     438                    if 'msg' in Rvals:
     439                        Rvals['msg'] += '\n'
     440                    else:
     441                        Rvals['msg'] = ''
     442                    msg = ('Note: a total of {} variable(s) are frozen due to refining outside limits'
     443                        .format(len(parmFrozenList))
     444                        )
     445                    G2fil.G2Print('Note: ',msg)
     446                    Rvals['msg'] += msg
    446447            G2stIO.SetUsedHistogramsAndPhases(GPXfile,Histograms,Phases,rigidbodyDict,covData,parmFrozenList,makeBack)
    447448            printFile.close()
  • trunk/GSASIIstrMath.py

    r5284 r5287  
    33053305        phPartialFP.close()
    33063306       
    3307        
    33083307    if 'C' in calcControls[hfx+'histType']:   
    33093308        shl = max(parmDict[hfx+'SH/L'],0.002)
Note: See TracChangeset for help on using the changeset viewer.