Changeset 1081 for trunk/exports


Ignore:
Timestamp:
Oct 3, 2013 10:33:07 PM (8 years ago)
Author:
toby
Message:

revise export menu; add multiple selection to G2gd.ItemSelector?

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/exports/G2export_CIF.py

    r1080 r1081  
    11#!/usr/bin/env python
    22# -*- coding: utf-8 -*-
    3 #G2cif
    43########### SVN repository information ###################
    54# $Date$
     
    5150        super(self.__class__,self).__init__( # fancy way to say <parentclass>.__init__
    5251            G2frame=G2frame,
    53             formatName = 'full CIF',
     52            formatName = 'Full CIF',
    5453            extension='.cif',
    5554            longFormatName = 'Export project as CIF'
    5655            )
     56        self.exporttype = ['project']
    5757        self.author = ''
    5858        self.mode = 'full'
    59         self.exporttype = 'project'
    60 
    61     def export(self):
     59
     60    def Exporter(self,event=None):
    6261        '''Export a CIF. Export can be full or simple (as set by self.mode).
    6362        "simple" skips data, distances & angles, etc. and can only include
    6463        a single phase while "full" is intended for for publication submission.
    6564        '''
    66    
    67 # ===== define functions for export method =======================================
     65
     66#***** define functions for export method =======================================
    6867        def openCIF(filnam):
    6968            'opens the output file'
     
    511510                if phasedict['General']['Type'] == 'macromolecular':
    512511                    label = '%s_%s_%s_%s'%(at[ct-1],at[ct-3],at[ct-4],at[ct-2])
     512                    s = PutInCol(MakeUniqueLabel(label,self.labellist),15) # label
    513513                else:
    514                     label = at[ct-1]
    515                 s = PutInCol(MakeUniqueLabel(label,self.labellist),6) # label
     514                    s = PutInCol(MakeUniqueLabel(at[ct-1],self.labellist),6) # label
    516515                fval = self.parmDict.get(fpfx+str(i),at[cfrac])
    517516                if fval == 0.0: continue # ignore any atoms that have a occupancy set to 0 (exact)
     
    857856                WriteAtomsNuclear(phasenam)
    858857            else:
    859                 raise Exception,"no export for mm coordinates implemented"
     858                raise Exception,"no export for "+str(phasedict['General']['Type'])+" coordinates implemented"
    860859            # report cell contents
    861860            WriteComposition(phasenam)
     
    12631262            self.cifdefs.SetTitle('Edit CIF settings')
    12641263            vbox = wx.BoxSizer(wx.VERTICAL)
     1264            vbox.Add(wx.StaticText(self.cifdefs, wx.ID_ANY,'Creating file '+str(self.filename)))
    12651265            but = wx.Button(self.cifdefs, wx.ID_ANY,'Edit CIF Author')
    12661266            but.Bind(wx.EVT_BUTTON,EditAuthor)
     
    12911291                    0,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL)
    12921292                cpnl.SetSizer(cbox)
    1293                 but = wx.Button(cpnl, wx.ID_ANY,'Edit distance/angle ranges')
    1294                 #cbox.Add(but,0,wx.ALIGN_CENTER,3)
     1293                if phasedict['General']['Type'] == 'nuclear': 
     1294                    but = wx.Button(cpnl, wx.ID_ANY,'Edit distance/angle ranges')
     1295                    cbox.Add(but,0,wx.ALIGN_LEFT,0)
     1296                    cbox.Add((-1,2))
     1297                    but.phasedict = self.Phases[phasenam]  # set a pointer to current phase info
     1298                    but.Bind(wx.EVT_BUTTON,EditRanges)     # phase bond/angle ranges
     1299                    but = wx.Button(cpnl, wx.ID_ANY,'Set distance/angle publication flags')
     1300                    but.phase = phasenam  # set a pointer to current phase info     
     1301                    but.Bind(wx.EVT_BUTTON,SelectDisAglFlags)     # phase bond/angle ranges
     1302                    cbox.Add(but,0,wx.ALIGN_LEFT,0)
    12951303                cbox.Add((-1,2))
    1296                 cbox.Add(but,0,wx.ALIGN_LEFT,0)
    1297                 but.phasedict = self.Phases[phasenam]  # set a pointer to current phase info     
    1298                 but.Bind(wx.EVT_BUTTON,EditRanges)     # phase bond/angle ranges
    1299                 but = wx.Button(cpnl, wx.ID_ANY,'Set distance/angle publication flags')
    1300                 but.phase = phasenam  # set a pointer to current phase info     
    1301                 but.Bind(wx.EVT_BUTTON,SelectDisAglFlags)     # phase bond/angle ranges
    1302                 cbox.Add((-1,2))
    1303                 cbox.Add(but,0,wx.ALIGN_LEFT,0)
    13041304            for i in sorted(self.powderDict.keys()):
    13051305                G2gd.HorizontalLine(cbox,cpnl)         
     
    15121512            dlg.ShowModal()
    15131513           
    1514 # ===== end of functions for export method =======================================
     1514#***** end of functions for export method =======================================
    15151515#=================================================================================
    15161516
     
    15201520        # create a dict with refined values and their uncertainties
    15211521        self.loadParmDict()
     1522        if self.SetupExport(event,                         # set export parameters
     1523                            AskFile=(self.mode=='simple')
     1524                            ): return
    15221525
    15231526        # Someday: get restraint & constraint info
     
    15291532
    15301533        self.CIFdate = dt.datetime.strftime(dt.datetime.now(),"%Y-%m-%dT%H:%M")
    1531         # index powder and single crystal histograms
    1532         self.powderDict = {}
    1533         self.xtalDict = {}
    1534         for hist in self.Histograms:
    1535             i = self.Histograms[hist]['hId']
    1536             if hist.startswith("PWDR"):
    1537                 self.powderDict[i] = hist
    1538             elif hist.startswith("HKLF"):
    1539                 self.xtalDict[i] = hist
    15401534        # is there anything to export?
    15411535        if len(self.Phases) == len(self.powderDict) == len(self.xtalDict) == 0:
    15421536           self.G2frame.ErrorDialog(
    15431537               'Empty project',
    1544                'Project does not contain interconnected data & phase(s)')
     1538               'Project does not contain any data or phases. Are they interconnected?')
    15451539           return
    15461540        # get the project file name
     
    16401634                    instnam = histblk["Instrument Parameters"][0]['InstrName']
    16411635                    break # ignore all but 1st data histogram
    1642         if self.quickmode:
    1643             fil = self.askSaveFile()
    1644         else:
    1645             fil = self.defSaveFile()
    1646         if not fil: return
    16471636        if not self.quickmode: # give the user a chance to edit all defaults
    16481637            self.cifdefs = wx.Dialog(
     
    16581647        # Start writing the CIF - single block
    16591648        #======================================================================
    1660         print('Writing CIF output to file '+fil+"...")
    1661         openCIF(fil)
    1662         if oneblock:
     1649        print('Writing CIF output to file '+str(self.filename)+"...")
     1650        openCIF(self.filename)
     1651        if self.currentExportType == 'single' or self.currentExportType == 'powder':
     1652            hist = self.histnam
     1653            self.CIFname = self.histnam[5:40].replace(' ','')
     1654            WriteCIFitem('data_'+self.CIFname)
     1655            if hist.startswith("PWDR"):
     1656                WritePowderData(hist)
     1657            elif hist.startswith("HKLF"):
     1658                WriteSingleXtalData(hist)
     1659            else:
     1660                print "should not happen"
     1661        elif oneblock:
    16631662            WriteCIFitem('data_'+self.CIFname)
    16641663            if phasenam is None: # if not already selected, select the first phase (should be one)
     
    17491748                    instnam = histblk["Sample Parameters"]['InstrName']
    17501749                    instnam = instnam.replace(' ','')
    1751                     i = histblk['hId']
     1750                    j = histblk['hId']
    17521751                    datablockidDict[hist] = (str(self.CIFdate) + "|" + str(self.CIFname) + "|" +
    17531752                                             str(self.shortauthorname) + "|" +
    1754                                              instnam + "_hist_"+str(i))
     1753                                             instnam + "_hist_"+str(j))
    17551754                    WriteCIFitem(loopprefix,datablockidDict[hist])
    17561755                for i in sorted(self.xtalDict.keys()):
     
    18371836        # end of CIF export
    18381837
    1839 class ExportSimpleCIF(ExportCIF):
     1838class ExportPhaseCIF(ExportCIF):
    18401839    '''Used to create a simple CIF of at most one phase. Uses exact same code as
    1841     :class:`ExportCIF` except that `self.mode` is set to simple.
     1840    :class:`ExportCIF` except that `self.mode` is set to "simple". Shows up in menu as
     1841    Quick CIF
    18421842
    18431843    :param wx.Frame G2frame: reference to main GSAS-II frame
     
    18461846        G2IO.ExportBaseclass.__init__(self,
    18471847            G2frame=G2frame,
    1848             formatName = 'full CIF',
     1848            formatName = 'Quick CIF',
    18491849            extension='.cif',
    1850             longFormatName = 'Export project as CIF'
     1850            longFormatName = 'Export one phase in CIF'
    18511851            )
     1852        self.exporttype = ['phase']
     1853        # CIF-specific items
    18521854        self.author = ''
    18531855        self.mode = 'simple'
    1854         self.exporttype = 'phase'
     1856
     1857class ExportDataCIF(ExportCIF):
     1858    '''Used to create a simple CIF containing diffraction data only. Uses exact same code as
     1859    :class:`ExportCIF` except that `self.mode` is set to "simple" and `self.currentExportType`
     1860    is set to "single" or "powder" in `self.SetupExport`. Shows up in menus as Data-only CIF.
     1861
     1862    :param wx.Frame G2frame: reference to main GSAS-II frame
     1863    '''
     1864    def __init__(self,G2frame):
     1865        G2IO.ExportBaseclass.__init__(self,
     1866            G2frame=G2frame,
     1867            formatName = 'Data-only CIF',
     1868            extension='.cif',
     1869            longFormatName = 'Export data as CIF'
     1870            )
     1871        self.exporttype = ['single','powder']
     1872        # CIF-specific items
     1873        self.author = ''
     1874        self.mode = 'simple'
    18551875
    18561876#===============================================================================
Note: See TracChangeset for help on using the changeset viewer.