Changeset 1084 for trunk/GSASIIIO.py


Ignore:
Timestamp:
Oct 4, 2013 4:19:03 PM (8 years ago)
Author:
toby
Message:

installer uses xterm on GNOME shortcut

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r1080 r1084  
    14091409E,SGData = G2spc.SpcGroup('P 1') # data structure for default space group
    14101410class ImportBaseclass(object):
    1411     '''Defines a base class for the importing of data files (diffraction
     1411    '''Defines a base class for the reading of input files (diffraction
    14121412    data, coordinates,...
    14131413    '''
     
    15591559            size,header)
    15601560
    1561 ######################################################################
    1562 class ExportBaseclass(object):
    1563     '''Defines a base class for the exporting of GSAS-II results
    1564     '''
    1565     def __init__(self,
    1566                  G2frame,
    1567                  formatName,
    1568                  extension,
    1569                  longFormatName=None,
    1570                  ):
    1571         self.G2frame = G2frame
    1572         self.formatName = formatName # short string naming file type
    1573         self.extension = extension
    1574         if longFormatName: # longer string naming file type
    1575             self.longFormatName = longFormatName
    1576         else:
    1577             self.longFormatName = formatName
    1578         self.OverallParms = {}
    1579         self.Phases = {}
    1580         self.Histograms = {}
    1581         self.powderDict = {}
    1582         self.xtalDict = {}
    1583         # updated in SetupExport, when used
    1584         self.currentExportType = None # type of export that has been requested
    1585         self.phasenam = None # name of selected phase or a list of phases
    1586         self.histnam = None # name of selected histogram or a list of histograms
    1587         self.filename = None # name of file to be written
    1588        
    1589         # items that should be defined in a subclass of this class
    1590         self.exporttype = []  # defines the type(s) of exports that the class can handle.
    1591         # The following types are defined: 'project', "phase", "powder", "single"
    1592         self.multiple = False # set as True if the class can export multiple phase or histograms
    1593         # ignored for "project" exports
    1594 
    1595     def SetupExport(self,event,AskFile=True):
    1596         '''Determines the type of menu that called the Exporter. Selects histograms
    1597         or phases when needed.
    1598 
    1599         :param bool AskFile: if AskFile is True (default)
    1600         '''
    1601         if event:
    1602             self.currentExportType = self.G2frame.ExportLookup.get(event.Id)
    1603         if AskFile:
    1604             self.filename = self.askSaveFile()
    1605         else:
    1606             self.filename = self.defaultSaveFile()
    1607         if not self.filename: return True
    1608        
    1609         if self.currentExportType == 'phase':
    1610             if len(self.Phases) == 0:
    1611                 self.G2frame.ErrorDialog(
    1612                     'Empty project',
    1613                     'Project does not contain any data or phases or they are not interconnected.')
    1614                 return True
    1615             elif self.multiple:
    1616                 if len(self.Phases) == 1:
    1617                     self.phasenam = self.Phases.keys()
    1618                 else:
    1619                     choices = sorted(self.Phases.keys())
    1620                     phasenum = G2gd.ItemSelector(choices,self.G2frame,multiple=True)
    1621                     if phasenum is None: return True
    1622                     self.phasenam = [choices[i] for i in phasenum]
    1623             else:
    1624                 if len(self.Phases) == 1:
    1625                     self.phasenam = self.Phases.keys()[0]
    1626                 else:
    1627                     choices = sorted(self.Phases.keys())
    1628                     phasenum = G2gd.ItemSelector(choices,self.G2frame)
    1629                     if phasenum is None: return True
    1630                     self.phasenam = choices[phasenum]
    1631         elif self.currentExportType == 'single':
    1632             if len(self.xtalDict) == 0:
    1633                 self.G2frame.ErrorDialog(
    1634                     'Empty project',
    1635                     'Project does not contain any single crystal data or data is not connected to a phase.')
    1636                 return True
    1637             elif self.multiple:
    1638                 if len(self.xtalDict) == 1:
    1639                     self.histnam = self.xtalDict.values()
    1640                 else:
    1641                     choices = sorted(self.xtalDict.values())
    1642                     hnum = G2gd.ItemSelector(choices,self.G2frame,multiple=True)
    1643                     if hnum is None: return True
    1644                     self.histnam = [choices[i] for i in hnum]
    1645             else:
    1646                 if len(self.xtalDict) == 1:
    1647                     self.histnam = self.xtalDict.values()[0]
    1648                 else:
    1649                     choices = sorted(self.xtalDict.values())
    1650                     hnum = G2gd.ItemSelector(choices,self.G2frame)
    1651                     if hnum is None: return True
    1652                     self.histnam = choices[hnum]
    1653         elif self.currentExportType == 'powder':
    1654             if len(self.powderDict) == 0:
    1655                 self.G2frame.ErrorDialog(
    1656                     'Empty project',
    1657                     'Project does not contain any powder data or data is not connected to a phase.')
    1658                 return True
    1659             elif self.multiple:
    1660                 if len(self.powderDict) == 1:
    1661                     self.histnam = self.powderDict.values()
    1662                 else:
    1663                     choices = sorted(self.powderDict.values())
    1664                     hnum = G2gd.ItemSelector(choices,self.G2frame,multiple=True)
    1665                     if hnum is None: return True
    1666                     self.histnam = [choices[i] for i in hnum]
    1667             else:
    1668                 if len(self.powderDict) == 1:
    1669                     self.histnam = self.powderDict.values()[0]
    1670                 else:
    1671                     choices = sorted(self.powderDict.values())
    1672                     hnum = G2gd.ItemSelector(choices,self.G2frame)
    1673                     if hnum is None: return True
    1674                     self.histnam = choices[hnum]
    1675             print 'selected histograms = ',self.histnam
    1676             print 'selected histograms = ',self.histnam
    1677             return True
    1678     def loadParmDict(self):
    1679         '''Load the GSAS-II refinable parameters from the tree into a dict (self.parmDict). Update
    1680         refined values to those from the last cycle and set the uncertainties for the
    1681         refined parameters in another dict (self.sigDict).
    1682 
    1683         Expands the parm & sig dicts to include values derived from constraints.
    1684         '''
    1685         self.parmDict = {}
    1686         self.sigDict = {}
    1687         rigidbodyDict = {}
    1688         covDict = {}
    1689         consDict = {}
    1690         Histograms,Phases = self.G2frame.GetUsedHistogramsAndPhasesfromTree()
    1691         if self.G2frame.PatternTree.IsEmpty(): return # nothing to do
    1692         item, cookie = self.G2frame.PatternTree.GetFirstChild(self.G2frame.root)
    1693         while item:
    1694             name = self.G2frame.PatternTree.GetItemText(item)
    1695             if name == 'Rigid bodies':
    1696                  rigidbodyDict = self.G2frame.PatternTree.GetItemPyData(item)
    1697             elif name == 'Covariance':
    1698                  covDict = self.G2frame.PatternTree.GetItemPyData(item)
    1699             elif name == 'Constraints':
    1700                  consDict = self.G2frame.PatternTree.GetItemPyData(item)
    1701             item, cookie = self.G2frame.PatternTree.GetNextChild(self.G2frame.root, cookie)
    1702         rbVary,rbDict =  G2stIO.GetRigidBodyModels(rigidbodyDict,Print=False)
    1703         self.parmDict.update(rbDict)
    1704         rbIds = rigidbodyDict.get('RBIds',{'Vector':[],'Residue':[]})
    1705         Natoms,atomIndx,phaseVary,phaseDict,pawleyLookup,FFtables,BLtables =  G2stIO.GetPhaseData(
    1706             Phases,RestraintDict=None,rbIds=rbIds,Print=False)
    1707         self.parmDict.update(phaseDict)
    1708         hapVary,hapDict,controlDict =  G2stIO.GetHistogramPhaseData(
    1709             Phases,Histograms,Print=False,resetRefList=False)
    1710         self.parmDict.update(hapDict)
    1711         histVary,histDict,controlDict =  G2stIO.GetHistogramData(Histograms,Print=False)
    1712         self.parmDict.update(histDict)
    1713         self.parmDict.update(zip(
    1714             covDict.get('varyList',[]),
    1715             covDict.get('variables',[])))
    1716         self.sigDict = dict(zip(
    1717             covDict.get('varyList',[]),
    1718             covDict.get('sig',[])))
    1719         # expand to include constraints: first compile a list of constraints
    1720         constList = []
    1721         for item in consDict:
    1722             constList += consDict[item]
    1723         # now process the constraints
    1724         G2mv.InitVars()
    1725         constDict,fixedList,ignored = G2stIO.ProcessConstraints(constList)
    1726         varyList = covDict.get('varyListStart')
    1727         if varyList is None and len(constDict) == 0:
    1728             # no constraints can use varyList
    1729             varyList = covDict.get('varyList')
    1730         elif varyList is None:
    1731             # old GPX file from before pre-constraint varyList is saved
    1732             print ' *** Old refinement: Please use Calculate/Refine to redo  ***'
    1733             raise Exception(' *** CIF creation aborted ***')
    1734         else:
    1735             varyList = list(varyList)
    1736         try:
    1737             groups,parmlist = G2mv.GroupConstraints(constDict)
    1738             G2mv.GenerateConstraints(groups,parmlist,varyList,constDict,fixedList)
    1739         except:
    1740             # this really should not happen
    1741             print ' *** ERROR - constraints are internally inconsistent ***'
    1742             errmsg, warnmsg = G2mv.CheckConstraints(varyList,constDict,fixedList)
    1743             print 'Errors',errmsg
    1744             if warnmsg: print 'Warnings',warnmsg
    1745             raise Exception(' *** CIF creation aborted ***')
    1746         # add the constrained values to the parameter dictionary
    1747         G2mv.Dict2Map(self.parmDict,varyList)
    1748         # and add their uncertainties into the esd dictionary (sigDict)
    1749         if covDict.get('covMatrix') is not None:
    1750             self.sigDict.update(G2mv.ComputeDepESD(covDict['covMatrix'],covDict['varyList'],self.parmDict))
    1751 
    1752     def loadTree(self):
    1753         '''Load the contents of the data tree into a set of dicts
    1754         (self.OverallParms, self.Phases and self.Histogram as well as self.powderDict
    1755         & self.xtalDict)
    1756        
    1757         * The childrenless data tree items are overall parameters/controls for the
    1758           entire project and are placed in self.OverallParms
    1759         * Phase items are placed in self.Phases
    1760         * Data items are placed in self.Histogram. The key for these data items
    1761           begin with a keyword, such as PWDR, IMG, HKLF,... that identifies the data type.
    1762         '''
    1763         self.OverallParms = {}
    1764         self.Histograms,self.Phases = self.G2frame.GetUsedHistogramsAndPhasesfromTree()
    1765         if self.G2frame.PatternTree.IsEmpty(): return # nothing to do
    1766         item, cookie = self.G2frame.PatternTree.GetFirstChild(self.G2frame.root)
    1767         while item:
    1768             name = self.G2frame.PatternTree.GetItemText(item)
    1769             item2, cookie2 = self.G2frame.PatternTree.GetFirstChild(item)
    1770             if not item2:
    1771                 self.OverallParms[name] = self.G2frame.PatternTree.GetItemPyData(item)
    1772             item, cookie = self.G2frame.PatternTree.GetNextChild(self.G2frame.root, cookie)
    1773         # index powder and single crystal histograms
    1774         self.powderDict = {}
    1775         self.xtalDict = {}
    1776         for hist in self.Histograms:
    1777             i = self.Histograms[hist]['hId']
    1778             if hist.startswith("PWDR"):
    1779                 self.powderDict[i] = hist
    1780             elif hist.startswith("HKLF"):
    1781                 self.xtalDict[i] = hist
    1782 
    1783     def dumpTree(self,mode='type'):
    1784         '''Print out information on the data tree dicts loaded in loadTree
    1785         '''
    1786         print '\nOverall'
    1787         if mode == 'type':
    1788             def Show(arg): return type(arg)
    1789         else:
    1790             def Show(arg): return arg
    1791         for key in self.OverallParms:
    1792             print '  ',key,Show(self.OverallParms[key])
    1793         print 'Phases'
    1794         for key1 in self.Phases:
    1795             print '    ',key1,Show(self.Phases[key1])
    1796         print 'Histogram'
    1797         for key1 in self.Histograms:
    1798             print '    ',key1,Show(self.Histograms[key1])
    1799             for key2 in self.Histograms[key1]:
    1800                 print '      ',key2,Show(self.Histograms[key1][key2])
    1801 
    1802     def defaultSaveFile(self):
    1803         return os.path.abspath(
    1804             os.path.splitext(self.G2frame.GSASprojectfile
    1805                              )[0]+self.extension)
    1806        
    1807     def askSaveFile(self):
    1808         '''Ask the user to supply a file name
    1809 
    1810         :returns: a file name (str)
    1811         '''
    1812         defnam = os.path.splitext(
    1813             os.path.split(self.G2frame.GSASprojectfile)[1]
    1814             )[0]+self.extension
    1815         dlg = wx.FileDialog(
    1816             self.G2frame, 'Input name for file to write', '.', defnam,
    1817             self.longFormatName+' (*'+self.extension+')|*'+self.extension,
    1818             wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT|wx.CHANGE_DIR)
    1819         try:
    1820             if dlg.ShowModal() == wx.ID_OK:
    1821                 filename = dlg.GetPath()
    1822                 # make sure extension is correct
    1823                 filename = os.path.splitext(filename)[0]+self.extension
    1824             else:
    1825                 filename = None
    1826         finally:
    1827             dlg.Destroy()
    1828         return filename
    1829        
    1830                    
    1831 ######################################################################
    18321561class ImportStructFactor(ImportBaseclass):
    18331562    '''Defines a base class for the reading of files with tables
     
    20071736        self.instdict = {} # place items here that will be transferred to the instrument parameters
    20081737######################################################################
     1738class ExportBaseclass(object):
     1739    '''Defines a base class for the exporting of GSAS-II results
     1740    '''
     1741    def __init__(self,
     1742                 G2frame,
     1743                 formatName,
     1744                 extension,
     1745                 longFormatName=None,
     1746                 ):
     1747        self.G2frame = G2frame
     1748        self.formatName = formatName # short string naming file type
     1749        self.extension = extension
     1750        if longFormatName: # longer string naming file type
     1751            self.longFormatName = longFormatName
     1752        else:
     1753            self.longFormatName = formatName
     1754        self.OverallParms = {}
     1755        self.Phases = {}
     1756        self.Histograms = {}
     1757        self.powderDict = {}
     1758        self.xtalDict = {}
     1759        # updated in SetupExport, when used
     1760        self.currentExportType = None # type of export that has been requested
     1761        self.phasenam = None # name of selected phase or a list of phases
     1762        self.histnam = None # name of selected histogram or a list of histograms
     1763        self.filename = None # name of file to be written
     1764       
     1765        # items that should be defined in a subclass of this class
     1766        self.exporttype = []  # defines the type(s) of exports that the class can handle.
     1767        # The following types are defined: 'project', "phase", "powder", "single"
     1768        self.multiple = False # set as True if the class can export multiple phase or histograms
     1769        # ignored for "project" exports
     1770
     1771    def SetupExport(self,event,AskFile=True):
     1772        '''Determines the type of menu that called the Exporter. Selects histograms
     1773        or phases when needed.
     1774
     1775        :param bool AskFile: if AskFile is True (default)
     1776        '''
     1777        if event:
     1778            self.currentExportType = self.G2frame.ExportLookup.get(event.Id)
     1779        if AskFile:
     1780            self.filename = self.askSaveFile()
     1781        else:
     1782            self.filename = self.defaultSaveFile()
     1783        if not self.filename: return True
     1784       
     1785        if self.currentExportType == 'phase':
     1786            if len(self.Phases) == 0:
     1787                self.G2frame.ErrorDialog(
     1788                    'Empty project',
     1789                    'Project does not contain any data or phases or they are not interconnected.')
     1790                return True
     1791            elif self.multiple:
     1792                if len(self.Phases) == 1:
     1793                    self.phasenam = self.Phases.keys()
     1794                else:
     1795                    choices = sorted(self.Phases.keys())
     1796                    phasenum = G2gd.ItemSelector(choices,self.G2frame,multiple=True)
     1797                    if phasenum is None: return True
     1798                    self.phasenam = [choices[i] for i in phasenum]
     1799            else:
     1800                if len(self.Phases) == 1:
     1801                    self.phasenam = self.Phases.keys()[0]
     1802                else:
     1803                    choices = sorted(self.Phases.keys())
     1804                    phasenum = G2gd.ItemSelector(choices,self.G2frame)
     1805                    if phasenum is None: return True
     1806                    self.phasenam = choices[phasenum]
     1807        elif self.currentExportType == 'single':
     1808            if len(self.xtalDict) == 0:
     1809                self.G2frame.ErrorDialog(
     1810                    'Empty project',
     1811                    'Project does not contain any single crystal data or data is not connected to a phase.')
     1812                return True
     1813            elif self.multiple:
     1814                if len(self.xtalDict) == 1:
     1815                    self.histnam = self.xtalDict.values()
     1816                else:
     1817                    choices = sorted(self.xtalDict.values())
     1818                    hnum = G2gd.ItemSelector(choices,self.G2frame,multiple=True)
     1819                    if hnum is None: return True
     1820                    self.histnam = [choices[i] for i in hnum]
     1821            else:
     1822                if len(self.xtalDict) == 1:
     1823                    self.histnam = self.xtalDict.values()[0]
     1824                else:
     1825                    choices = sorted(self.xtalDict.values())
     1826                    hnum = G2gd.ItemSelector(choices,self.G2frame)
     1827                    if hnum is None: return True
     1828                    self.histnam = choices[hnum]
     1829        elif self.currentExportType == 'powder':
     1830            if len(self.powderDict) == 0:
     1831                self.G2frame.ErrorDialog(
     1832                    'Empty project',
     1833                    'Project does not contain any powder data or data is not connected to a phase.')
     1834                return True
     1835            elif self.multiple:
     1836                if len(self.powderDict) == 1:
     1837                    self.histnam = self.powderDict.values()
     1838                else:
     1839                    choices = sorted(self.powderDict.values())
     1840                    hnum = G2gd.ItemSelector(choices,self.G2frame,multiple=True)
     1841                    if hnum is None: return True
     1842                    self.histnam = [choices[i] for i in hnum]
     1843            else:
     1844                if len(self.powderDict) == 1:
     1845                    self.histnam = self.powderDict.values()[0]
     1846                else:
     1847                    choices = sorted(self.powderDict.values())
     1848                    hnum = G2gd.ItemSelector(choices,self.G2frame)
     1849                    if hnum is None: return True
     1850                    self.histnam = choices[hnum]
     1851            print 'selected histograms = ',self.histnam
     1852            print 'selected histograms = ',self.histnam
     1853            return True
     1854    def loadParmDict(self):
     1855        '''Load the GSAS-II refinable parameters from the tree into a dict (self.parmDict). Update
     1856        refined values to those from the last cycle and set the uncertainties for the
     1857        refined parameters in another dict (self.sigDict).
     1858
     1859        Expands the parm & sig dicts to include values derived from constraints.
     1860        '''
     1861        self.parmDict = {}
     1862        self.sigDict = {}
     1863        rigidbodyDict = {}
     1864        covDict = {}
     1865        consDict = {}
     1866        Histograms,Phases = self.G2frame.GetUsedHistogramsAndPhasesfromTree()
     1867        if self.G2frame.PatternTree.IsEmpty(): return # nothing to do
     1868        item, cookie = self.G2frame.PatternTree.GetFirstChild(self.G2frame.root)
     1869        while item:
     1870            name = self.G2frame.PatternTree.GetItemText(item)
     1871            if name == 'Rigid bodies':
     1872                 rigidbodyDict = self.G2frame.PatternTree.GetItemPyData(item)
     1873            elif name == 'Covariance':
     1874                 covDict = self.G2frame.PatternTree.GetItemPyData(item)
     1875            elif name == 'Constraints':
     1876                 consDict = self.G2frame.PatternTree.GetItemPyData(item)
     1877            item, cookie = self.G2frame.PatternTree.GetNextChild(self.G2frame.root, cookie)
     1878        rbVary,rbDict =  G2stIO.GetRigidBodyModels(rigidbodyDict,Print=False)
     1879        self.parmDict.update(rbDict)
     1880        rbIds = rigidbodyDict.get('RBIds',{'Vector':[],'Residue':[]})
     1881        Natoms,atomIndx,phaseVary,phaseDict,pawleyLookup,FFtables,BLtables =  G2stIO.GetPhaseData(
     1882            Phases,RestraintDict=None,rbIds=rbIds,Print=False)
     1883        self.parmDict.update(phaseDict)
     1884        hapVary,hapDict,controlDict =  G2stIO.GetHistogramPhaseData(
     1885            Phases,Histograms,Print=False,resetRefList=False)
     1886        self.parmDict.update(hapDict)
     1887        histVary,histDict,controlDict =  G2stIO.GetHistogramData(Histograms,Print=False)
     1888        self.parmDict.update(histDict)
     1889        self.parmDict.update(zip(
     1890            covDict.get('varyList',[]),
     1891            covDict.get('variables',[])))
     1892        self.sigDict = dict(zip(
     1893            covDict.get('varyList',[]),
     1894            covDict.get('sig',[])))
     1895        # expand to include constraints: first compile a list of constraints
     1896        constList = []
     1897        for item in consDict:
     1898            constList += consDict[item]
     1899        # now process the constraints
     1900        G2mv.InitVars()
     1901        constDict,fixedList,ignored = G2stIO.ProcessConstraints(constList)
     1902        varyList = covDict.get('varyListStart')
     1903        if varyList is None and len(constDict) == 0:
     1904            # no constraints can use varyList
     1905            varyList = covDict.get('varyList')
     1906        elif varyList is None:
     1907            # old GPX file from before pre-constraint varyList is saved
     1908            print ' *** Old refinement: Please use Calculate/Refine to redo  ***'
     1909            raise Exception(' *** CIF creation aborted ***')
     1910        else:
     1911            varyList = list(varyList)
     1912        try:
     1913            groups,parmlist = G2mv.GroupConstraints(constDict)
     1914            G2mv.GenerateConstraints(groups,parmlist,varyList,constDict,fixedList)
     1915        except:
     1916            # this really should not happen
     1917            print ' *** ERROR - constraints are internally inconsistent ***'
     1918            errmsg, warnmsg = G2mv.CheckConstraints(varyList,constDict,fixedList)
     1919            print 'Errors',errmsg
     1920            if warnmsg: print 'Warnings',warnmsg
     1921            raise Exception(' *** CIF creation aborted ***')
     1922        # add the constrained values to the parameter dictionary
     1923        G2mv.Dict2Map(self.parmDict,varyList)
     1924        # and add their uncertainties into the esd dictionary (sigDict)
     1925        if covDict.get('covMatrix') is not None:
     1926            self.sigDict.update(G2mv.ComputeDepESD(covDict['covMatrix'],covDict['varyList'],self.parmDict))
     1927
     1928    def loadTree(self):
     1929        '''Load the contents of the data tree into a set of dicts
     1930        (self.OverallParms, self.Phases and self.Histogram as well as self.powderDict
     1931        & self.xtalDict)
     1932       
     1933        * The childrenless data tree items are overall parameters/controls for the
     1934          entire project and are placed in self.OverallParms
     1935        * Phase items are placed in self.Phases
     1936        * Data items are placed in self.Histogram. The key for these data items
     1937          begin with a keyword, such as PWDR, IMG, HKLF,... that identifies the data type.
     1938        '''
     1939        self.OverallParms = {}
     1940        self.Histograms,self.Phases = self.G2frame.GetUsedHistogramsAndPhasesfromTree()
     1941        if self.G2frame.PatternTree.IsEmpty(): return # nothing to do
     1942        item, cookie = self.G2frame.PatternTree.GetFirstChild(self.G2frame.root)
     1943        while item:
     1944            name = self.G2frame.PatternTree.GetItemText(item)
     1945            item2, cookie2 = self.G2frame.PatternTree.GetFirstChild(item)
     1946            if not item2:
     1947                self.OverallParms[name] = self.G2frame.PatternTree.GetItemPyData(item)
     1948            item, cookie = self.G2frame.PatternTree.GetNextChild(self.G2frame.root, cookie)
     1949        # index powder and single crystal histograms
     1950        self.powderDict = {}
     1951        self.xtalDict = {}
     1952        for hist in self.Histograms:
     1953            i = self.Histograms[hist]['hId']
     1954            if hist.startswith("PWDR"):
     1955                self.powderDict[i] = hist
     1956            elif hist.startswith("HKLF"):
     1957                self.xtalDict[i] = hist
     1958
     1959    def dumpTree(self,mode='type'):
     1960        '''Print out information on the data tree dicts loaded in loadTree
     1961        '''
     1962        print '\nOverall'
     1963        if mode == 'type':
     1964            def Show(arg): return type(arg)
     1965        else:
     1966            def Show(arg): return arg
     1967        for key in self.OverallParms:
     1968            print '  ',key,Show(self.OverallParms[key])
     1969        print 'Phases'
     1970        for key1 in self.Phases:
     1971            print '    ',key1,Show(self.Phases[key1])
     1972        print 'Histogram'
     1973        for key1 in self.Histograms:
     1974            print '    ',key1,Show(self.Histograms[key1])
     1975            for key2 in self.Histograms[key1]:
     1976                print '      ',key2,Show(self.Histograms[key1][key2])
     1977
     1978    def defaultSaveFile(self):
     1979        return os.path.abspath(
     1980            os.path.splitext(self.G2frame.GSASprojectfile
     1981                             )[0]+self.extension)
     1982       
     1983    def askSaveFile(self):
     1984        '''Ask the user to supply a file name
     1985
     1986        :returns: a file name (str)
     1987        '''
     1988        defnam = os.path.splitext(
     1989            os.path.split(self.G2frame.GSASprojectfile)[1]
     1990            )[0]+self.extension
     1991        dlg = wx.FileDialog(
     1992            self.G2frame, 'Input name for file to write', '.', defnam,
     1993            self.longFormatName+' (*'+self.extension+')|*'+self.extension,
     1994            wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT|wx.CHANGE_DIR)
     1995        try:
     1996            if dlg.ShowModal() == wx.ID_OK:
     1997                filename = dlg.GetPath()
     1998                # make sure extension is correct
     1999                filename = os.path.splitext(filename)[0]+self.extension
     2000            else:
     2001                filename = None
     2002        finally:
     2003            dlg.Destroy()
     2004        return filename
     2005
     2006    def OpenFile(self,fil=None):
     2007        '''Open the output file
     2008        '''
     2009        if not fil:
     2010            fil = self.filename
     2011        self.fp = open(fil,'w')
     2012        return self.fp
     2013    def Write(self,line):
     2014        self.fp.write(line+'\n')
     2015    def CloseFile(self,fp=None):
     2016        if fp is None:
     2017            fp = self.fp
     2018            self.fp = None
     2019        fp.close()
     2020   
     2021######################################################################
     2022
    20092023def ReadCIF(URLorFile):
    20102024    '''Open a CIF, which may be specified as a file name or as a URL using PyCifRW
Note: See TracChangeset for help on using the changeset viewer.