Changeset 956 for trunk/GSASIIIO.py


Ignore:
Timestamp:
Jun 18, 2013 9:44:58 PM (9 years ago)
Author:
toby
Message:

snapshot of CIF dev

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r944 r956  
    3535import GSASIIpwdGUI as G2pdG
    3636import GSASIIElem as G2el
     37import GSASIIstrIO as G2stIO
     38import GSASIImapvars as G2mv
    3739import os
    3840import os.path as ospath
     
    15591561            self.longFormatName = formatName
    15601562        self.OverallParms = {}
    1561         self.GroupedParms = {}
     1563        self.Phases = {}
     1564        self.Histograms = {}
     1565
     1566    def loadParmDict(self):
     1567        '''Load the GSAS-II refinable parameters from the tree into a dict (self.parmDict). Update
     1568        refined values to those from the last cycle and set the uncertainties for the
     1569        refined parameters in another dict (self.sigDict).
     1570
     1571        Expands the parm & sig dicts to include values derived from constraints.
     1572        '''
     1573        self.parmDict = {}
     1574        self.sigDict = {}
     1575        rigidbodyDict = {}
     1576        covDict = {}
     1577        consDict = {}
     1578        Histograms,Phases = self.G2frame.GetUsedHistogramsAndPhasesfromTree()
     1579        if self.G2frame.PatternTree.IsEmpty(): return # nothing to do
     1580        item, cookie = self.G2frame.PatternTree.GetFirstChild(self.G2frame.root)
     1581        while item:
     1582            name = self.G2frame.PatternTree.GetItemText(item)
     1583            if name == 'Rigid bodies':
     1584                 rigidbodyDict = self.G2frame.PatternTree.GetItemPyData(item)
     1585            elif name == 'Covariance':
     1586                 covDict = self.G2frame.PatternTree.GetItemPyData(item)
     1587            elif name == 'Constraints':
     1588                 consDict = self.G2frame.PatternTree.GetItemPyData(item)
     1589            item, cookie = self.G2frame.PatternTree.GetNextChild(self.G2frame.root, cookie)
     1590        rbVary,rbDict =  G2stIO.GetRigidBodyModels(rigidbodyDict,Print=False)
     1591        self.parmDict.update(rbDict)
     1592        rbIds = rigidbodyDict.get('RBIds',{'Vector':[],'Residue':[]})
     1593        Natoms,atomIndx,phaseVary,phaseDict,pawleyLookup,FFtables,BLtables =  G2stIO.GetPhaseData(
     1594            Phases,RestraintDict=None,rbIds=rbIds,Print=False)
     1595        self.parmDict.update(phaseDict)
     1596        hapVary,hapDict,controlDict =  G2stIO.GetHistogramPhaseData(Phases,Histograms,Print=False)
     1597        self.parmDict.update(hapDict)
     1598        histVary,histDict,controlDict =  G2stIO.GetHistogramData(Histograms,Print=False)
     1599        self.parmDict.update(histDict)
     1600        self.parmDict.update(zip(
     1601            covDict.get('varyList',[]),
     1602            covDict.get('variables',[])))
     1603        self.sigDict = dict(zip(
     1604            covDict.get('varyList',[]),
     1605            covDict.get('sig',[])))
     1606        # expand to include constraints: first compile a list of constraints
     1607        constList = []
     1608        for item in consDict:
     1609            constList += consDict[item]
     1610        constDict,fixedList,ignored = G2stIO.ProcessConstraints(constList)
     1611        # now process the constraints
     1612        G2mv.InitVars()
     1613        varyList = covDict.get('varyList',[])
     1614        try:
     1615            groups,parmlist = G2mv.GroupConstraints(constDict)
     1616            G2mv.GenerateConstraints(groups,parmlist,varyList,constDict,fixedList)
     1617        except:
     1618            # this really should not happen
     1619            print ' *** ERROR - constraints are internally inconsistent ***'
     1620            errmsg, warnmsg = G2mv.CheckConstraints(varyList,constDict,fixedList)
     1621            print 'Errors',errmsg
     1622            if warnmsg: print 'Warnings',warnmsg
     1623            raise Exception(' *** CIF creation aborted ***')
     1624        # add the constrained values to the parameter dictionary
     1625        G2mv.Dict2Map(self.parmDict,varyList)
     1626        # and add their uncertainties into the esd dictionary (sigDict)
     1627        if covDict.get('covMatrix') is not None:
     1628            self.sigDict.update(G2mv.ComputeDepESD(covDict['covMatrix'],varyList,self.parmDict))
     1629
    15621630    def loadTree(self):
    1563         '''Load the contents of the data tree into a pair of dicts.
     1631        '''Load the contents of the data tree into a set of dicts
     1632        (self.OverallParms, self.Phases and self.Histogram)
    15641633       
    1565         The childrenless data tree items are overall parameters/controls for the
    1566         entire project and are placed in self.OverallParms
    1567 
    1568         The data tree items with children are either Phase items or are
    1569         data of some sort. Date entries begin with a key, such as
    1570         PWDR, IMG, HKLF,... that identifies the data type.
    1571         * Phase items are placed in self.GroupedParms["Phases"][item]
    1572         * Data items are placed in self.GroupedParms["Phases"][key][item]
    1573 
    1574           Note that there is no overall phase information, only information
    1575           stored for each phase, but there is overall information for each
    1576           data item. The overall data information is stored in
    1577           self.GroupedParms["Phases"][key][None]
    1578        
     1634        * The childrenless data tree items are overall parameters/controls for the
     1635          entire project and are placed in self.OverallParms
     1636        * Phase items are placed in self.Phases
     1637        * Data items are placed in self.Histogram. The key for these data items
     1638          begin with a keyword, such as PWDR, IMG, HKLF,... that identifies the data type.
    15791639        '''
    15801640        self.OverallParms = {}
    1581         self.GroupedParms = {}
    1582         G2frame = self.G2frame
    1583         if G2frame.PatternTree.IsEmpty(): return # nothing to do
    1584         item, cookie = G2frame.PatternTree.GetFirstChild(G2frame.root)
     1641        self.Histograms,self.Phases = self.G2frame.GetUsedHistogramsAndPhasesfromTree()
     1642        if self.G2frame.PatternTree.IsEmpty(): return # nothing to do
     1643        item, cookie = self.G2frame.PatternTree.GetFirstChild(self.G2frame.root)
    15851644        while item:
    1586             name = G2frame.PatternTree.GetItemText(item)
    1587             item2, cookie2 = G2frame.PatternTree.GetFirstChild(item)
    1588             if item2:
    1589                 key = name.split()[0]
    1590                 if name == "Phases":
    1591                     self.GroupedParms[name] = {}
    1592                     d = self.GroupedParms[name]
    1593                 else:
    1594                     if self.GroupedParms.get(key) is None:
    1595                         self.GroupedParms[key] = {}
    1596                     if self.GroupedParms[key].get(name):
    1597                         print("Aborting export: Histogram name repeated"+str(name))
    1598                         return
    1599                     self.GroupedParms[key][name] = {}
    1600                     self.GroupedParms[key][name][None] = G2frame.PatternTree.GetItemPyData(item)
    1601                     d = self.GroupedParms[key][name]
    1602                 while item2:
    1603                     name = G2frame.PatternTree.GetItemText(item2)
    1604                     if d.get(name):
    1605                         print("Aborting export: phase name repeated"+str(name))
    1606                         return
    1607                     d[name] = G2frame.PatternTree.GetItemPyData(item2)
    1608                     item2, cookie2 = G2frame.PatternTree.GetNextChild(item, cookie2)                           
    1609             else:
    1610                 self.OverallParms[name] = G2frame.PatternTree.GetItemPyData(item)
    1611             item, cookie = G2frame.PatternTree.GetNextChild(G2frame.root, cookie)
     1645            name = self.G2frame.PatternTree.GetItemText(item)
     1646            item2, cookie2 = self.G2frame.PatternTree.GetFirstChild(item)
     1647            if not item2:
     1648                self.OverallParms[name] = self.G2frame.PatternTree.GetItemPyData(item)
     1649            item, cookie = self.G2frame.PatternTree.GetNextChild(self.G2frame.root, cookie)
    16121650
    16131651    def dumpTree(self,mode='type'):
     
    16211659        for key in self.OverallParms:
    16221660            print '  ',key,Show(self.OverallParms[key])
    1623         print '\nGrouped'
    1624         for key in self.GroupedParms:
    1625             if key == "Phases":
    1626                 print '  Phases'
    1627                 for key1 in self.GroupedParms[key]:
    1628                     print '    ',key1,Show(self.GroupedParms[key][key1])
    1629             else:
    1630                 print '  ',key,Show(self.GroupedParms[key])
    1631                 for key1 in self.GroupedParms[key]:
    1632                     print '    ',key1,Show(self.GroupedParms[key][key1][None])
    1633                     for key2 in self.GroupedParms[key][key1]:
    1634                         print '      ',key2,Show(self.GroupedParms[key][key1][key2])
    1635 
     1661        print 'Phases'
     1662        for key1 in self.Phases:
     1663            print '    ',key1,Show(self.Phases[key1])
     1664        print 'Histogram'
     1665        for key1 in self.Histograms:
     1666            print '    ',key1,Show(self.Histograms[key1])
     1667            for key2 in self.Histograms[key1]:
     1668                print '      ',key2,Show(self.Histograms[key1][key2])
     1669                   
    16361670######################################################################
    16371671class ImportStructFactor(ImportBaseclass):
Note: See TracChangeset for help on using the changeset viewer.