Changeset 1102 for trunk/GSASIIIO.py


Ignore:
Timestamp:
Oct 12, 2013 10:47:06 PM (8 years ago)
Author:
toby
Message:

change exports to always have lists of phases & histograms; new export examples; CIF export fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r1100 r1102  
    5454    else:
    5555        return 0
    56 
    5756
    5857def trim(val):
     
    14531452                style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.OK|wx.CENTRE)
    14541453        if size: dlg.SetSize(size)
     1454        dlg.CenterOnParent()
    14551455        if dlg.ShowModal() == wx.ID_OK:
    14561456            sel = dlg.GetSelection()
     
    14701470        dlg = wx.MultiChoiceDialog(ParentFrame,title, header,ChoiceList+['Select all'],
    14711471            wx.CHOICEDLG_STYLE)
     1472        dlg.CenterOnParent()
    14721473        if size: dlg.SetSize(size)
    14731474        if dlg.ShowModal() == wx.ID_OK:
     
    14971498        dlg = MultipleChoicesDialog(choicelist,headinglist,
    14981499            parent=ParentFrame, **kwargs)         
     1500        dlg.CenterOnParent()
    14991501        if dlg.ShowModal() == wx.ID_OK:
    15001502            result = dlg.chosen
     
    17591761        # updated in SetupExport, when used
    17601762        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.phasenam = None # a list of selected phases
     1764        self.histnam = None # a list of selected histograms
    17631765        self.filename = None # name of file to be written
    17641766       
     
    17661768        self.exporttype = []  # defines the type(s) of exports that the class can handle.
    17671769        # 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
     1770        self.multiple = False # set as True if the class can export multiple phases or histograms
    17691771        # ignored for "project" exports
    17701772
     
    17731775        or phases when needed.
    17741776
    1775         :param bool AskFile: if AskFile is True (default)
     1777        :param bool AskFile: if AskFile is True (default) get the name of the file
     1778          in a dialog
     1779        :returns: True in case of an error
    17761780        '''
    17771781        if event:
     
    17991803            else:
    18001804                if len(self.Phases) == 1:
    1801                     self.phasenam = self.Phases.keys()[0]
     1805                    self.phasenam = self.Phases.keys()
    18021806                else:
    18031807                    choices = sorted(self.Phases.keys())
    18041808                    phasenum = G2gd.ItemSelector(choices,self.G2frame)
    18051809                    if phasenum is None: return True
    1806                     self.phasenam = choices[phasenum]
     1810                    self.phasenam = [choices[phasenum]]
    18071811        elif self.currentExportType == 'single':
    18081812            if len(self.xtalDict) == 0:
     
    18211825            else:
    18221826                if len(self.xtalDict) == 1:
    1823                     self.histnam = self.xtalDict.values()[0]
     1827                    self.histnam = self.xtalDict.values()
    18241828                else:
    18251829                    choices = sorted(self.xtalDict.values())
    18261830                    hnum = G2gd.ItemSelector(choices,self.G2frame)
    18271831                    if hnum is None: return True
    1828                     self.histnam = choices[hnum]
     1832                    self.histnam = [choices[hnum]]
    18291833        elif self.currentExportType == 'powder':
    18301834            if len(self.powderDict) == 0:
     
    18431847            else:
    18441848                if len(self.powderDict) == 1:
    1845                     self.histnam = self.powderDict.values()[0]
     1849                    self.histnam = self.powderDict.values()
    18461850                else:
    18471851                    choices = sorted(self.powderDict.values())
    18481852                    hnum = G2gd.ItemSelector(choices,self.G2frame)
    18491853                    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                    self.histnam = [choices[hnum]]
    18541855    def loadParmDict(self):
    18551856        '''Load the GSAS-II refinable parameters from the tree into a dict (self.parmDict). Update
     
    19931994            self.longFormatName+' (*'+self.extension+')|*'+self.extension,
    19941995            wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT|wx.CHANGE_DIR)
     1996        dlg.CenterOnParent()
    19951997        try:
    19961998            if dlg.ShowModal() == wx.ID_OK:
     
    20042006        return filename
    20052007
     2008    # Tools for file writing.
    20062009    def OpenFile(self,fil=None):
    20072010        '''Open the output file
     2011
     2012        :param str fil: The name of the file to open. If None (default)
     2013          the name defaults to self.filename.
     2014        :returns: the file object opened by the routine which is also
     2015          saved as self.fp
    20082016        '''
    20092017        if not fil:
     
    20122020        return self.fp
    20132021    def Write(self,line):
     2022        '''write a line of output, attaching a line-end character
     2023
     2024        :param str line: the text to be written.
     2025        '''
    20142026        self.fp.write(line+'\n')
    20152027    def CloseFile(self,fp=None):
     2028        '''Close a file opened in OpenFile
     2029
     2030        :param file fp: the file object to be closed. If None (default)
     2031          file object self.fp is closed.
     2032        '''
    20162033        if fp is None:
    20172034            fp = self.fp
    20182035            self.fp = None
    20192036        fp.close()
     2037    # Tools to pull information out of the data arrays
     2038    def GetCell(self,phasenam):
     2039        """Gets the unit cell parameters and their s.u.'s for a selected phase
     2040
     2041        :param str phasenam: the name for the selected phase
     2042        :returns: `cellList,cellSig` where each is a 7 element list corresponding
     2043          to a, b, c, alpha, beta, gamma, volume where `cellList` has the
     2044          cell values and `cellSig` has their uncertainties.
     2045        """
     2046        phasedict = self.Phases[phasenam] # pointer to current phase info           
     2047        pfx = str(phasedict['pId'])+'::'
     2048        A,sigA = G2stIO.cellFill(pfx,phasedict['General']['SGData'],self.parmDict,self.sigDict)
     2049        cellSig = G2stIO.getCellEsd(pfx,
     2050                                    phasedict['General']['SGData'],A,
     2051                                    self.OverallParms['Covariance'])  # returns 7 vals, includes sigVol
     2052        cellList = G2lat.A2cell(A) + (G2lat.calc_V(A),)
     2053        return cellList,cellSig
    20202054   
     2055    def GetAtoms(self,phasenam):
     2056        """Gets the atoms associated with a phase. Can be used with standard
     2057        or macromolecular phases
     2058
     2059        :param str phasenam: the name for the selected phase
     2060        :returns: a list of items for eac atom where each item is a list containing:
     2061          label, typ, mult, xyz, and td, where
     2062
     2063          * label and typ are the atom label and the scattering factor type (str)
     2064          * mult is the site multiplicity (int)
     2065          * xyz is contains a list with four pairs of numbers:
     2066            x, y, z and fractional occupancy and
     2067            their standard uncertainty (or a negative value)
     2068          * td is contains a list with either one or six pairs of numbers:
     2069            if one number it is U\ :sub:`iso` and with six it is
     2070            U\ :sub:`11`, U\ :sub:`22`, U\ :sub:`33`, U\ :sub:`12`, U\ :sub:`13` & U\ :sub:`23`
     2071            paired with their standard uncertainty (or a negative value)
     2072        """
     2073        phasedict = self.Phases[phasenam] # pointer to current phase info           
     2074        cx,ct,cs,cia = phasedict['General']['AtomPtrs']
     2075        cfrac = cx+3
     2076        fpfx = str(phasedict['pId'])+'::Afrac:'       
     2077        atomslist = []
     2078        for i,at in enumerate(phasedict['Atoms']):
     2079            if phasedict['General']['Type'] == 'macromolecular':
     2080                label = '%s_%s_%s_%s'%(at[ct-1],at[ct-3],at[ct-4],at[ct-2])
     2081            else:
     2082                label = at[ct-1]
     2083            fval = self.parmDict.get(fpfx+str(i),at[cfrac])
     2084            fsig = self.sigDict.get(fpfx+str(i),-0.009)
     2085            mult = at[cs+1]
     2086            typ = at[ct]
     2087            xyz = []
     2088            for j,v in enumerate(('x','y','z')):
     2089                val = at[cx+j]
     2090                pfx = str(phasedict['pId'])+'::dA'+v+':'+str(i)
     2091                sig = self.sigDict.get(pfx,-0.000009)
     2092                xyz.append((val,sig))
     2093            xyz.append((fval,fsig))
     2094            td = []
     2095            if at[cia] == 'I':
     2096                pfx = str(phasedict['pId'])+'::AUiso:'+str(i)
     2097                val = self.parmDict.get(pfx,at[cia+1])
     2098                sig = self.sigDict.get(pfx,-0.0009)
     2099                td.append((val,sig))
     2100            else:
     2101                for i,var in enumerate(('AU11','AU22','AU33','AU12','AU13','AU23')):
     2102                    pfx = str(phasedict['pId'])+'::'+var+':'+str(i)
     2103                    val = self.parmDict.get(pfx,at[cia+2+i])
     2104                    sig = self.sigDict.get(pfx,-0.0009)
     2105                    td.append((val,sig))
     2106            atomslist.append((label,typ,mult,xyz,td))
     2107        return atomslist
    20212108######################################################################
    20222109
Note: See TracChangeset for help on using the changeset viewer.