Changeset 1147 for trunk/GSASII.py


Ignore:
Timestamp:
Nov 22, 2013 4:24:29 PM (9 years ago)
Author:
toby
Message:

Complete initial ISODISPLACE implementation; mod. phase initialization; change atom pointer init.; rework parameter display window

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r1145 r1147  
    182182        item = parent.Append(help='View least squares parameters',
    183183            id=wx.ID_ANY, kind=wx.ITEM_NORMAL,text='&View LS parms')
    184         self.Bind(wx.EVT_MENU, self.OnViewLSParms, id=item.GetId())
     184        self.Bind(wx.EVT_MENU, self.ShowLSParms, id=item.GetId())
    185185       
    186186        item = parent.Append(help='', id=wx.ID_ANY, kind=wx.ITEM_NORMAL,
     
    195195       
    196196        item = parent.Append(help='', id=wx.ID_ANY, kind=wx.ITEM_NORMAL,
    197             text='Sequental refine')
     197            text='Sequential refine')
    198198        if len(self.SeqRefine): # extend state for new menus to match main (on mac)
    199199            state = self.SeqRefine[0].IsEnabled()
     
    262262            if fp: fp.close()
    263263
    264     def OnImportGeneric(self,reader,readerlist,label,multiple=False):
     264    def OnImportGeneric(self,reader,readerlist,label,multiple=False,usedRanIdList=[]):
    265265        '''Used to import Phases, powder dataset or single
    266266        crystal datasets (structure factor tables) using reader objects
    267         subclassed from GSASIIIO.ImportPhase, GSASIIIO.ImportStructFactor
    268         or GSASIIIO.ImportPowderData. If a reader is specified, only
     267        subclassed from :class:`GSASIIIO.ImportPhase`, :class:`GSASIIIO.ImportStructFactor`
     268        or :class:`GSASIIIO.ImportPowderData`. If a reader is specified, only
    269269        that will be attempted, but if no reader is specified, every one
    270270        that is potentially compatible (by file extension) will
     
    287287        :param bool multiple: True if multiple files can be selected
    288288          in the file dialog. False is default. At present True is used
    289           only for reading of powder data.
    290          
     289          only for reading of powder data.
     290
     291        :param list usedRanIdList: an optional list of random Ids that
     292          have been used and should not be reused
     293
    291294        :returns: a list of reader objects (rd_list) that were able
    292295          to read the specified file(s). This list may be empty.
     
    425428                            flag = rd.Reader(filename,fp,self,
    426429                                             buffer=rdbuffer,
    427                                              blocknum=block)
     430                                             blocknum=block,
     431                                             usedRanIdList=usedRanIdList,
     432                                             )
    428433                            if flag:
    429434                                rd_list.append(copy.deepcopy(rd)) # success
     
    483488        # look up which format was requested
    484489        reqrdr = self.ImportMenuId.get(event.GetId())
     490        # make a list of used phase ranId's
     491        phaseRIdList = []
     492        sub = G2gd.GetPatternTreeItemId(self,self.root,'Phases')
     493        if sub:
     494            item, cookie = self.PatternTree.GetFirstChild(sub)
     495            while item:
     496                phaseName = self.PatternTree.GetItemText(item)
     497                ranId = self.PatternTree.GetItemPyData(item).get('ranId')
     498                if ranId: phaseRIdList.append(ranId)
     499                item, cookie = self.PatternTree.GetNextChild(sub, cookie)
    485500        rdlist = self.OnImportGeneric(reqrdr,
    486501                                  self.ImportPhaseReaderlist,
    487                                   'phase')
     502                                  'phase',usedRanIdList=phaseRIdList)
    488503        if len(rdlist) == 0: return
    489504        # for now rdlist is only expected to have one element
     
    509524            self.PatternTree.Expand(self.root) # make sure phases are seen
    510525            self.PatternTree.Expand(sub)
    511             self.PatternTree.Expand(psub)
     526            self.PatternTree.Expand(psub)
     527            if rd.Constraints:
     528                sub = G2gd.GetPatternTreeItemId(self,self.root,'Constraints') # was created in CheckNotebook if needed
     529                Constraints = self.PatternTree.GetItemPyData(sub)               
     530                # TODO: make sure that NEWVAR names are unique here?
     531                for i in rd.Constraints:
     532                    if type(i) is dict:
     533                        #for j in i: print j,' --> ',i[j]
     534                        if '_Explain' not in Constraints: Constraints['_Explain'] = {}
     535                        Constraints['_Explain'].update(i)
     536                        continue
     537                    Constraints['Phase'].append(i)
    512538        return # success
    513539       
     
    13151341        self._Add_ImportMenu_powder(Import)
    13161342        self._Add_ImportMenu_Sfact(Import)
     1343        #======================================================================
     1344        # Code to help develop/debug an importer, much is hard-coded below
     1345        # but module is reloaded before each use, allowing faster testing
     1346        # def DebugImport(event):
     1347        #     print 'start reload'
     1348        #     import G2phase_ISO as dev
     1349        #     reload(dev)
     1350        #     rd = dev.ISODISTORTPhaseReader()
     1351        #     self.ImportMenuId[event.GetId()] = rd
     1352        #     self.OnImportPhase(event)
     1353            # or ----------------------------------------------------------------------
     1354            #self.OnImportGeneric(rd,[],'test of ISODISTORTPhaseReader')
     1355            # special debug code
     1356            # or ----------------------------------------------------------------------
     1357            # filename = '/Users/toby/projects/branton/subgroup_cif.txt'
     1358            # fp = open(filename,'Ur')
     1359            # if not rd.ContentsValidator(fp):
     1360            #     print 'not validated'
     1361            #     # make a list of used phase ranId's
     1362            # phaseRIdList = []
     1363            # sub = G2gd.GetPatternTreeItemId(self,self.root,'Phases')
     1364            # if sub:
     1365            #     item, cookie = self.PatternTree.GetFirstChild(sub)
     1366            #     while item:
     1367            #         phaseName = self.PatternTree.GetItemText(item)
     1368            #         ranId = self.PatternTree.GetItemPyData(item).get('ranId')
     1369            #         if ranId: phaseRIdList.append(ranId)
     1370            #         item, cookie = self.PatternTree.GetNextChild(sub, cookie)
     1371            # if rd.Reader(filename,fp,usedRanIdList=phaseRIdList):
     1372            #     print 'read OK'
     1373        # item = Import.Append(
     1374        #     wx.ID_ANY,kind=wx.ITEM_NORMAL,
     1375        #     help="debug importer",text="test importer")
     1376        # self.Bind(wx.EVT_MENU, DebugImport, id=item.GetId())
     1377        #======================================================================
    13171378        self.ExportMenu = wx.Menu(title='')
    13181379        menubar.Append(menu=self.ExportMenu, title='Export')
     
    25162577        for phase in phaseData:
    25172578            Phase = phaseData[phase]
     2579            pId = phaseNames.index(phase)
     2580            Phase['pId'] = pId
    25182581            if Phase['Histograms']:
    25192582                if phase not in Phases:
    2520                     pId = phaseNames.index(phase)
    2521                     Phase['pId'] = pId
    25222583                    Phases[phase] = Phase
    25232584                for hist in Phase['Histograms']:
     
    25362597                            print('For phase "'+str(phase)+
    25372598                                  '" unresolved reference to histogram "'+str(hist)+'"')
    2538         G2obj.IndexAllIds(Histograms=Histograms,Phases=Phases)
     2599        #G2obj.IndexAllIds(Histograms=Histograms,Phases=Phases)
     2600        G2obj.IndexAllIds(Histograms=Histograms,Phases=phaseData)
    25392601        return Histograms,Phases
    25402602       
    2541     class ViewParmDialog(wx.Dialog):
    2542         '''Window to show all parameters in the refinement.
    2543         Called from :meth:`OnViewLSParms`
    2544         '''
    2545         def __init__(self,parent,title,parmDict):
    2546             wx.Dialog.__init__(self,parent,-1,title,size=(300,430),
    2547                 pos=wx.DefaultPosition,style=wx.DEFAULT_DIALOG_STYLE)
    2548             panel = wx.Panel(self,size=(300,430))
    2549             parmNames = parmDict.keys()
    2550             parmNames.sort()
    2551             parmText = ' p:h:Parameter       refine?              value\n'
    2552             for name in parmNames:
    2553                 parmData = parmDict[name]
    2554                 try:
    2555                     parmText += ' %s \t%12.4g \n'%(name.ljust(19)+'\t'+parmData[1],parmData[0])
    2556                 except TypeError:
    2557                     pass
    2558             parmTable = wx.TextCtrl(panel,-1,parmText,
    2559                 style=wx.TE_MULTILINE|wx.TE_READONLY,size=(290,400))
    2560             mainSizer = wx.BoxSizer(wx.VERTICAL)
    2561             mainSizer.Add(parmTable)
    2562             panel.SetSizer(mainSizer)
    2563                            
    2564     def OnViewLSParms(self,event):
    2565         '''Displays a window showing all parameters in the refinement.
    2566         Called from the Calculate/View LS Parms menu.
     2603    def MakeLSParmDict(self):
     2604        '''Load all parameters used for computation from the tree into a
     2605        dict
     2606
     2607        :returns: (parmDict,varyList) where:
     2608
     2609         * parmDict is a dict with values and refinement flags
     2610           for each parameter and
     2611         * varyList is a list of variables (refined parameters).
    25672612        '''
    25682613        parmDict = {}
     
    25712616            if 'pId' not in Phases[phase]:
    25722617                self.ErrorDialog('View parameter error','You must run least squares at least once')
    2573                 return
     2618                raise Exception,'No pId for phase '+str(phase)
    25742619        rigidbodyDict = self.PatternTree.GetItemPyData(   
    25752620            G2gd.GetPatternTreeItemId(self,self.root,'Rigid bodies'))
     
    25872632            if parm.split(':')[-1] in ['Azimuth','Gonio. radius','Lam1','Lam2',
    25882633                'Omega','Chi','Phi','nDebye','nPeaks']:
    2589                 parmDict[parm] = [parmDict[parm],' ']
     2634                parmDict[parm] = [parmDict[parm],'-']
    25902635            elif parm.split(':')[-2] in ['Ax','Ay','Az','SHmodel','SHord']:
    2591                 parmDict[parm] = [parmDict[parm],' ']
     2636                parmDict[parm] = [parmDict[parm],'-']
    25922637            elif parm in varyList:
    2593                 parmDict[parm] = [parmDict[parm],'True']
     2638                parmDict[parm] = [parmDict[parm],'T']
    25942639            else:
    2595                 parmDict[parm] = [parmDict[parm],'False']
    2596         parmDict[' Num refined'] = [len(varyList),'']
    2597         dlg = self.ViewParmDialog(self,'Parameters for least squares',parmDict)
    2598         try:
    2599             if dlg.ShowModal() == wx.ID_OK:
    2600                 print 'do something with changes?? - No!'
    2601         finally:
    2602             dlg.Destroy()
    2603        
     2640                parmDict[parm] = [parmDict[parm],'F']
     2641        return parmDict,varyList
     2642
     2643    def ShowLSParms(self,event):
     2644        '''Displays a window showing all parameters in the refinement.
     2645        Called from the Calculate/View LS Parms menu.
     2646        '''
     2647        parmDict,varyList = self.MakeLSParmDict()
     2648        dlg = G2gd.ShowLSParms(self,'Least Squares Parameters',parmDict,varyList)
     2649        dlg.ShowModal()
     2650        dlg.Destroy()
     2651       
    26042652    def OnRefine(self,event):
    26052653        '''Perform a refinement.
     
    26742722        Called from the Calculate/Sequential refine menu.
    26752723        '''       
    2676         Id = G2gd.GetPatternTreeItemId(self,self.root,'Sequental results')
     2724        Id = G2gd.GetPatternTreeItemId(self,self.root,'Sequential results')
    26772725        if not Id:
    2678             Id = self.PatternTree.AppendItem(self.root,text='Sequental results')
     2726            Id = self.PatternTree.AppendItem(self.root,text='Sequential results')
    26792727            self.PatternTree.SetItemPyData(Id,{})           
    26802728        self.OnFileSave(event)
Note: See TracChangeset for help on using the changeset viewer.