Changeset 3373


Ignore:
Timestamp:
May 6, 2018 2:13:25 PM (6 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.)

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r3365 r3373  
    573573    file = open(G2frame.GSASprojectfile,'rb')
    574574    if showProvenance: print ('loading from file: '+G2frame.GSASprojectfile)
    575     G2frame.SetTitle("GSAS-II project: "+os.path.split(G2frame.GSASprojectfile)[1])
    576     G2frame.plotFrame.SetTitle("GSAS-II plots: "+os.path.split(G2frame.GSASprojectfile)[1])
    577575    wx.BeginBusyCursor()
    578576    try:
     
    648646        wx.EndBusyCursor()
    649647        G2frame.Status.SetStatusText('Mouse RB drag/drop to reorder',0)
     648    G2frame.SetTitleByGPX()
    650649   
    651650def ProjFileSave(G2frame):
     
    15131512
    15141513        Expands the parm & sig dicts to include values derived from constraints.
     1514
     1515        This could be made faster for sequential fits by reducing the histogram list to only
     1516        the active histogram being exported.
    15151517        '''
    15161518        self.parmDict = {}
  • trunk/GSASIIconstrGUI.py

    r3371 r3373  
    197197            phaseAtTypes[item] = ''
    198198             
    199     # create a list of the hist*phase variables; include wildcards here
    200     hapVary,hapDict,controlDict = G2stIO.GetHistogramPhaseData(Phases,Histograms,Print=False)
    201     hapList = [i for i in hapDict.keys() if i.split(':')[2] not in ('Type',)]
    202     hapList.sort()
    203     wildList = [] # list of variables with "*" for histogram number
    204     for i in hapList:
    205         s = i.split(':')
    206         if s[1] == "": continue
    207         s[1] = '*'
    208         sj = ':'.join(s)
    209         if sj not in wildList: wildList.append(sj)
    210     #wildList.sort() # unneeded
    211     hapList += wildList
    212     histVary,histDict,controlDict = G2stIO.GetHistogramData(Histograms,Print=False)
     199    # create a list of the hist*phase variables
     200    seqList = G2frame.testSeqRefineMode()
     201    if seqList: # for sequential refinement, only process 1st histgram in list
     202        histDict = {seqList[0]:Histograms[seqList[0]]}
     203    else:
     204        histDict = Histograms
     205    hapVary,hapDict,controlDict = G2stIO.GetHistogramPhaseData(Phases,histDict,Print=False)
     206    hapList = sorted([i for i in hapDict.keys() if i.split(':')[2] not in ('Type',)])
     207    if seqList: # convert histogram # to wildcard
     208        wildList = [] # list of variables with "*" for histogram number
     209        for i in hapList:
     210            s = i.split(':')
     211            if s[1] == "": continue
     212            s[1] = '*'
     213            sj = ':'.join(s)
     214            if sj not in wildList: wildList.append(sj)
     215        hapList = wildList
     216    histVary,histDict,controlDict = G2stIO.GetHistogramData(histDict,Print=False)
    213217    histList = []
    214218    for item in histDict:
     
    220224            histList.append(item)
    221225    histList.sort()
    222     wildList = []
    223     # for i in histList: # any reason to have this for hist constraints?
    224     #     s = i.split(':')
    225     #     if s[1] == "": continue
    226     #     s[1] = '*'
    227     #     sj = ':'.join(s)
    228     #     if sj not in wildList: wildList.append(sj)
    229     # histList += wildList
     226    if seqList: # convert histogram # to wildcard
     227        wildList = [] # list of variables with "*" for histogram number
     228        for i in histList:
     229            s = i.split(':')
     230            if s[1] == "": continue
     231            s[1] = '*'
     232            sj = ':'.join(s)
     233            if sj not in wildList: wildList.append(sj)
     234        histList = wildList
    230235    Indx = {}
    231236    G2frame.Page = [0,'phs']
     
    10811086        G2frame.dataWindow.ConstraintEdit.Enable(G2G.wxID_EQUIVALANCEATOMS,False)
    10821087#        G2frame.dataWindow.ConstraintEdit.Enable(G2G.wxID_ADDRIDING,False)
    1083         enableEditCons = True
    10841088        if text == 'Histogram/Phase':
     1089            enableEditCons = [False]+4*[True]
    10851090            G2frame.Page = [page,'hap']
    10861091            UpdateConstraintPanel(HAPConstr,'HAP')
    10871092        elif text == 'Histogram':
     1093            enableEditCons = [False]+4*[True]
    10881094            G2frame.Page = [page,'hst']
    10891095            UpdateConstraintPanel(HistConstr,'Hist')
    10901096        elif text == 'Phase':
     1097            enableEditCons = 5*[True]
    10911098            G2frame.Page = [page,'phs']
    10921099            G2frame.dataWindow.ConstraintEdit.Enable(G2G.wxID_EQUIVALANCEATOMS,True)
     
    10981105            UpdateConstraintPanel(PhaseConstr,'Phase')
    10991106        elif text == 'Global':
     1107            enableEditCons = [False]+4*[True]
    11001108            G2frame.Page = [page,'glb']
    11011109            UpdateConstraintPanel(GlobalConstr,'Global')
    11021110        else:
    1103             enableEditCons = False
     1111            enableEditCons = 5*[False]
    11041112            G2frame.Page = [page,'sym']
    11051113            UpdateConstraintPanel(SymConstr,'Sym-Generated')
    11061114        # remove menu items when not allowed
    1107         for i in G2frame.dataWindow.ConstraintEdit.GetMenuItems():
    1108             i.Enable(enableEditCons)
     1115        for obj,flag in zip(G2frame.dataWindow.ConstraintEdit.GetMenuItems(),enableEditCons):
     1116            obj.Enable(flag)
    11091117        G2frame.dataWindow.SetDataSize()
    11101118
  • 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
  • trunk/GSASIIstrIO.py

    r3340 r3373  
    182182    return constDict,fixedList,ignored
    183183
    184 def ReadCheckConstraints(GPXfile):
    185     '''Load constraints and related info and return any error or warning messages'''
     184def ReadCheckConstraints(GPXfile, seqHist=None):
     185    '''Load constraints and related info and return any error or warning messages
     186    This is done from the GPX file rather than the tree.
     187    This this is called before a refinement is launched (OnRefine and OnSeqRefine), where the
     188    tree could be used.
     189   
     190    :param dict seqHist: defines a specific histogram to be loaded for a sequential
     191       refinement, if None (default) all are loaded.
     192    '''
    186193    # init constraints
    187194    G2mv.InitVars()   
     
    193200        return 'Error: no diffraction data',''
    194201    constrDict,fixedList = GetConstraints(GPXfile) # load user constraints before internally generated ones
     202    if seqHist: Histograms = {seqHist:Histograms[seqHist]}  # sequential fit: only need one histogram
    195203    rigidbodyDict = GetRigidBodies(GPXfile)
    196204    rbIds = rigidbodyDict.get('RBIds',{'Vector':[],'Residue':[]})
Note: See TracChangeset for help on using the changeset viewer.