Changeset 1081
- Timestamp:
- Oct 3, 2013 10:33:07 PM (10 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/exports/G2export_CIF.py
r1080 r1081 1 1 #!/usr/bin/env python 2 2 # -*- coding: utf-8 -*- 3 #G2cif4 3 ########### SVN repository information ################### 5 4 # $Date$ … … 51 50 super(self.__class__,self).__init__( # fancy way to say <parentclass>.__init__ 52 51 G2frame=G2frame, 53 formatName = ' full CIF',52 formatName = 'Full CIF', 54 53 extension='.cif', 55 54 longFormatName = 'Export project as CIF' 56 55 ) 56 self.exporttype = ['project'] 57 57 self.author = '' 58 58 self.mode = 'full' 59 self.exporttype = 'project' 60 61 def export(self): 59 60 def Exporter(self,event=None): 62 61 '''Export a CIF. Export can be full or simple (as set by self.mode). 63 62 "simple" skips data, distances & angles, etc. and can only include 64 63 a single phase while "full" is intended for for publication submission. 65 64 ''' 66 67 # =====define functions for export method =======================================65 66 #***** define functions for export method ======================================= 68 67 def openCIF(filnam): 69 68 'opens the output file' … … 511 510 if phasedict['General']['Type'] == 'macromolecular': 512 511 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 513 513 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 516 515 fval = self.parmDict.get(fpfx+str(i),at[cfrac]) 517 516 if fval == 0.0: continue # ignore any atoms that have a occupancy set to 0 (exact) … … 857 856 WriteAtomsNuclear(phasenam) 858 857 else: 859 raise Exception,"no export for mmcoordinates implemented"858 raise Exception,"no export for "+str(phasedict['General']['Type'])+" coordinates implemented" 860 859 # report cell contents 861 860 WriteComposition(phasenam) … … 1263 1262 self.cifdefs.SetTitle('Edit CIF settings') 1264 1263 vbox = wx.BoxSizer(wx.VERTICAL) 1264 vbox.Add(wx.StaticText(self.cifdefs, wx.ID_ANY,'Creating file '+str(self.filename))) 1265 1265 but = wx.Button(self.cifdefs, wx.ID_ANY,'Edit CIF Author') 1266 1266 but.Bind(wx.EVT_BUTTON,EditAuthor) … … 1291 1291 0,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL) 1292 1292 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) 1295 1303 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 info1298 but.Bind(wx.EVT_BUTTON,EditRanges) # phase bond/angle ranges1299 but = wx.Button(cpnl, wx.ID_ANY,'Set distance/angle publication flags')1300 but.phase = phasenam # set a pointer to current phase info1301 but.Bind(wx.EVT_BUTTON,SelectDisAglFlags) # phase bond/angle ranges1302 cbox.Add((-1,2))1303 cbox.Add(but,0,wx.ALIGN_LEFT,0)1304 1304 for i in sorted(self.powderDict.keys()): 1305 1305 G2gd.HorizontalLine(cbox,cpnl) … … 1512 1512 dlg.ShowModal() 1513 1513 1514 # =====end of functions for export method =======================================1514 #***** end of functions for export method ======================================= 1515 1515 #================================================================================= 1516 1516 … … 1520 1520 # create a dict with refined values and their uncertainties 1521 1521 self.loadParmDict() 1522 if self.SetupExport(event, # set export parameters 1523 AskFile=(self.mode=='simple') 1524 ): return 1522 1525 1523 1526 # Someday: get restraint & constraint info … … 1529 1532 1530 1533 self.CIFdate = dt.datetime.strftime(dt.datetime.now(),"%Y-%m-%dT%H:%M") 1531 # index powder and single crystal histograms1532 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] = hist1538 elif hist.startswith("HKLF"):1539 self.xtalDict[i] = hist1540 1534 # is there anything to export? 1541 1535 if len(self.Phases) == len(self.powderDict) == len(self.xtalDict) == 0: 1542 1536 self.G2frame.ErrorDialog( 1543 1537 'Empty project', 1544 'Project does not contain interconnected data & phase(s)')1538 'Project does not contain any data or phases. Are they interconnected?') 1545 1539 return 1546 1540 # get the project file name … … 1640 1634 instnam = histblk["Instrument Parameters"][0]['InstrName'] 1641 1635 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: return1647 1636 if not self.quickmode: # give the user a chance to edit all defaults 1648 1637 self.cifdefs = wx.Dialog( … … 1658 1647 # Start writing the CIF - single block 1659 1648 #====================================================================== 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: 1663 1662 WriteCIFitem('data_'+self.CIFname) 1664 1663 if phasenam is None: # if not already selected, select the first phase (should be one) … … 1749 1748 instnam = histblk["Sample Parameters"]['InstrName'] 1750 1749 instnam = instnam.replace(' ','') 1751 i= histblk['hId']1750 j = histblk['hId'] 1752 1751 datablockidDict[hist] = (str(self.CIFdate) + "|" + str(self.CIFname) + "|" + 1753 1752 str(self.shortauthorname) + "|" + 1754 instnam + "_hist_"+str( i))1753 instnam + "_hist_"+str(j)) 1755 1754 WriteCIFitem(loopprefix,datablockidDict[hist]) 1756 1755 for i in sorted(self.xtalDict.keys()): … … 1837 1836 # end of CIF export 1838 1837 1839 class Export SimpleCIF(ExportCIF):1838 class ExportPhaseCIF(ExportCIF): 1840 1839 '''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 1842 1842 1843 1843 :param wx.Frame G2frame: reference to main GSAS-II frame … … 1846 1846 G2IO.ExportBaseclass.__init__(self, 1847 1847 G2frame=G2frame, 1848 formatName = ' fullCIF',1848 formatName = 'Quick CIF', 1849 1849 extension='.cif', 1850 longFormatName = 'Export project asCIF'1850 longFormatName = 'Export one phase in CIF' 1851 1851 ) 1852 self.exporttype = ['phase'] 1853 # CIF-specific items 1852 1854 self.author = '' 1853 1855 self.mode = 'simple' 1854 self.exporttype = 'phase' 1856 1857 class 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' 1855 1875 1856 1876 #===============================================================================
Note: See TracChangeset
for help on using the changeset viewer.