Ignore:
Timestamp:
May 6, 2018 2:13:25 PM (4 years ago)
Author:
toby
Message:

make sequential refinement setting work like a global flag; add indicator to g2frame legend; clean up constrain selection by showing only wildcards in seq; and not showing them in for non-eq.; speed up some calls of G2stIO.GetHistogramPhaseData? but providing only current histogram (in seq. ref.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIdataGUI.py

    r3371 r3373  
    523523        self.Refine.append(item)
    524524        self.Bind(wx.EVT_MENU, self.OnRefine, id=item.GetId())
    525        
     525
     526        #===============================================================================
     527        # TODO: remove this, also EnableSeqRefineMenu and self.SeqRefine
     528        # do when tutorials are updated so that references to menu item are gone
    526529        item = parent.Append(wx.ID_ANY,'Sequential refine','')
    527530        self.Bind(wx.EVT_MENU, self.OnSeqRefine, id=item.GetId())
     
    532535        item.Enable(state)
    533536        self.SeqRefine.append(item) # save menu obj for use in self.EnableSeqRefineMenu
     537        #================================================================================
    534538#        if GSASIIpath.GetConfigValue('debug'): # allow exceptions for debugging
    535539#            item = parent.Append(help='', id=wx.ID_ANY, kind=wx.ITEM_NORMAL,
     
    551555        self.ImportMenuId = {}
    552556
     557    def testSeqRefineMode(self):
     558        '''Returns the list of histograms included in a sequential refinement or
     559        an empty list if a standard (non-sequential) refinement.
     560        '''
     561        controls = self.GPXtree.GetItemPyData(GetGPXtreeItemId(self,self.root, 'Controls'))
     562        return controls.get('Seq Data',[])
     563       
    553564    def EnableSeqRefineMenu(self):
    554565        '''Enable or disable the sequential refinement menu items based on the
    555566        contents of the Controls 'Seq Data' item (if present)
    556567        '''
    557         controls = self.GPXtree.GetItemPyData(GetGPXtreeItemId(self,self.root, 'Controls'))
    558         if controls.get('Seq Data'):
     568        if self.testSeqRefineMode():
    559569            for i in self.SeqRefine: i.Enable(True)
    560570        else:
     
    37173727        else:
    37183728            self.OnFileSaveas(event)
     3729           
     3730    def SetTitleByGPX(self):
     3731        '''Set the title for the two window frames
     3732        '''
     3733        if self.testSeqRefineMode():
     3734            s = u' (sequential refinement)'
     3735        else:
     3736            s = u''
     3737        self.SetTitle("GSAS-II project: "+os.path.split(self.GSASprojectfile)[1]+s)
     3738        self.plotFrame.SetTitle("GSAS-II plots: "+os.path.split(self.GSASprojectfile)[1])
    37193739
    37203740    def OnFileSaveas(self, event):
     
    37363756                self.GSASprojectfile = G2IO.FileDlgFixExt(dlg,self.GSASprojectfile)
    37373757                self.GPXtree.SetItemText(self.root,'Project: '+self.GSASprojectfile)
    3738                 self.SetTitle("GSAS-II project: "+os.path.split(self.GSASprojectfile)[1])
    3739                 self.plotFrame.SetTitle("GSAS-II plots: "+os.path.split(self.GSASprojectfile)[1])
    37403758                self.CheckNotebook()
    37413759                G2IO.ProjFileSave(self)
     3760                self.SetTitleByGPX()
    37423761                os.chdir(dlg.GetDirectory())           # to get Mac/Linux to change directory!
    37433762        finally:
     
    41924211        return Histograms,Phases
    41934212       
    4194     def MakeLSParmDict(self):
     4213    def MakeLSParmDict(self,seqHist=None):
    41954214        '''Load all parameters used for computation from the tree into a
    41964215        dict of paired values [value, refine flag]. Note that this is
     
    42024221        :func:`GSASIIstrMain.Refine` and :func:`GSASIIstrMain.SeqRefine` (from
    42034222        a GPX file).
     4223
     4224        :param dict seqHist: defines a specific histogram to be loaded for a sequential
     4225          refinement, if None (default) all are loaded.
     4226          Note: at present this parameter is not used anywhere.
    42044227
    42054228        :returns: (parmDict,varyList) where:
     
    42114234        parmDict = {}
    42124235        Histograms,Phases = self.GetUsedHistogramsAndPhasesfromTree()
     4236        if seqHist:
     4237            histDict = {seqHist:Histograms[seqHist]}
     4238        else:
     4239            histDict = Histograms
    42134240        for phase in Phases:
    42144241            if 'pId' not in Phases[phase]:
     
    42204247        rbIds = rigidbodyDict.get('RBIds',{'Vector':[],'Residue':[]})
    42214248        Natoms,atomIndx,phaseVary,phaseDict,pawleyLookup,FFtable,BLtable,MFtable,maxSSwave = G2stIO.GetPhaseData(Phases,RestraintDict=None,rbIds=rbIds,Print=False)       
    4222         hapVary,hapDict,controlDict = G2stIO.GetHistogramPhaseData(Phases,Histograms,Print=False)
    4223         histVary,histDict,controlDict = G2stIO.GetHistogramData(Histograms,Print=False)
     4249        hapVary,hapDict,controlDict = G2stIO.GetHistogramPhaseData(Phases,histDict,Print=False)
     4250        histVary,histDict,controlDict = G2stIO.GetHistogramData(histDict,Print=False)
    42244251        varyList = rbVary+phaseVary+hapVary+histVary
    42254252        parmDict.update(rbDict)
     
    42464273        '''Displays a window showing all parameters in the refinement.
    42474274        Called from the Calculate/View LS Parms menu.
     4275
     4276        This could potentially be sped up by loading only the histogram that is needed
     4277        for a sequential fit.
    42484278        '''
    42494279        try:
     
    42794309
    42804310    def OnRefine(self,event):
    4281         '''Perform a refinement.
     4311        '''Perform a refinement or a sequential refinement (depending on controls setting)
    42824312        Called from the Calculate/Refine menu.
    42834313        '''
    4284         Id = GetGPXtreeItemId(self,self.root,'Sequential results')
    4285         if Id:
    4286             dlg = wx.MessageDialog(
    4287                 self,
    4288                 'Your last refinement was sequential. Continue with "Refine", removing previous sequential results?',
    4289                 'Remove sequential results?',wx.OK|wx.CANCEL)
    4290             if dlg.ShowModal() == wx.ID_OK:
    4291                 self.GPXtree.Delete(Id)
    4292                 dlg.Destroy()
    4293             else:
    4294                 dlg.Destroy()
    4295                 return
     4314        if self.testSeqRefineMode():
     4315            self.OnSeqRefine(event)
     4316            return
     4317        # Id = GetGPXtreeItemId(self,self.root,'Sequential results')
     4318        # if Id:
     4319        #     dlg = wx.MessageDialog(
     4320        #         self,
     4321        #         'Your last refinement was sequential. Continue with "Refine", removing previous sequential results?',
     4322        #         'Remove sequential results?',wx.OK|wx.CANCEL)
     4323        #     if dlg.ShowModal() == wx.ID_OK:
     4324        #         self.GPXtree.Delete(Id)
     4325        #         dlg.Destroy()
     4326        #     else:
     4327        #         dlg.Destroy()
     4328        #         return
    42964329        self.OnFileSave(event)
    42974330        # check that constraints are OK here
     
    43994432    def OnSeqRefine(self,event):
    44004433        '''Perform a sequential refinement.
    4401         Called from the Calculate/Sequential refine menu.
     4434        Called from self.OnRefine (Called from the Calculate/Refine menu)
     4435       
     4436        temporarily called from the Calculate/Sequential refine menu (to be removed)
    44024437        '''
     4438        seqList = self.testSeqRefineMode()
     4439        if not seqList:
     4440            self.OnRefine(event)
     4441            return
    44034442        Id = GetGPXtreeItemId(self,self.root,'Sequential results')
    44044443        if not Id:
     
    44074446        self.G2plotNB.Delete('Sequential refinement')    #clear away probably invalid plot
    44084447        Controls = self.GPXtree.GetItemPyData(GetGPXtreeItemId(self,self.root, 'Controls'))
    4409         if not Controls.get('Seq Data'):
    4410             print('Error: a sequential refinement has not been set up')
    4411             return
    44124448        Controls['ShowCell'] = True
    44134449        self.OnFileSave(event)
    44144450        # check that constraints are OK here
    44154451        errmsg, warnmsg = G2stIO.ReadCheckConstraints(self.GSASprojectfile)
     4452        #errmsg, warnmsg = G2stIO.ReadCheckConstraints(self.GSASprojectfile,seqList[0]) # this would be faster, but at present it might not catch all errors
    44164453        if errmsg:
    44174454            self.ErrorDialog('Refinement error',errmsg)
     
    54895526                G2frame.EnableSeqRefineMenu()
    54905527            dlg.Destroy()
     5528            G2frame.SetTitleByGPX()
    54915529            wx.CallAfter(UpdateControls,G2frame,data)
    54925530           
     
    75327570#        if G2frame.dataDisplay:
    75337571#            oldPage = G2frame.dataDisplay.GetSelection()
    7534     G2frame.SetTitle("GSAS-II project: "+os.path.split(G2frame.GSASprojectfile)[1])
    7535     G2frame.plotFrame.SetTitle("GSAS-II plots: "+os.path.split(G2frame.GSASprojectfile)[1])
    75367572       
    75377573    SetDataMenuBar(G2frame)
     7574    G2frame.SetTitleByGPX()
    75387575    G2frame.PickId = item
    75397576    G2frame.PickIdText = None
Note: See TracChangeset for help on using the changeset viewer.