18. GSAS-II Export Modules

Exports are implemented by deriving a class from GSASIIIO.ExportBaseClass. Initialization of self.exporttype determines the type of export that will be performed (‘project’, ‘phase’, ‘single’, ‘powder’, ‘image’, ‘map’ or (someday) ‘pdf’) and of self.multiple determines if only a single phase, data set, etc. can be exported at a time (when False) or more than one can be selected.

Powder export routines may optionally define a Writer() method that accepts the histogram tree name as well as a file name to be written. This allows ExportPowder() to use the exporter independent of the GUI.

18.1. Module G2export_examples: Examples

Code to demonstrate how GSAS-II data export routines are created. The classes defined here, ExportPhaseText, ExportSingleText, ExportPowderReflText, and ExportPowderText each demonstrate a different type of export. Also see G2export_map.ExportMapASCII for an example of a map export.

class G2export_examples.ExportPhaseText(G2frame)[source]

Used to create a text file for a phase

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export a phase as a text file

class G2export_examples.ExportPowderReflText(G2frame)[source]

Used to create a text file of reflections from a powder data set

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export a set of powder reflections as a text file

class G2export_examples.ExportPowderText(G2frame)[source]

Used to create a text file for a powder data set

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export a set of powder data as a text file

class G2export_examples.ExportSingleText(G2frame)[source]

Used to create a text file with single crystal reflection data skips user rejected & space group extinct reflections

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export a set of single crystal data as a text file

18.2. Module G2export_csv: Spreadsheet export

Code to create .csv (comma-separated variable) files for GSAS-II data export to a spreadsheet program, etc.

class G2export_csv.ExportMultiPowderCSV(G2frame)[source]

Used to create a csv file for a stack of powder data sets suitable for display purposes only; no y-calc or weights are exported only x & y-obs :param wx.Frame G2frame: reference to main GSAS-II frame

Exporter(event=None)[source]

Export a set of powder data as a single csv file

class G2export_csv.ExportPhaseCSV(G2frame)[source]

Used to create a csv file for a phase

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export a phase as a csv file

class G2export_csv.ExportPowderCSV(G2frame)[source]

Used to create a csv file for a powder data set

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export a set of powder data as a csv file

class G2export_csv.ExportPowderReflCSV(G2frame)[source]

Used to create a csv file of reflections from a powder data set

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export a set of powder reflections as a csv file

class G2export_csv.ExportREFDCSV(G2frame)[source]

Used to create a csv file for a reflectometry data set

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export a set of reflectometry data as a csv file

class G2export_csv.ExportSASDCSV(G2frame)[source]

Used to create a csv file for a small angle data set

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export a set of small angle data as a csv file

class G2export_csv.ExportSingleCSV(G2frame)[source]

Used to create a csv file with single crystal reflection data

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export a set of single crystal data as a csv file

class G2export_csv.ExportStrainCSV(G2frame)[source]

Used to create a csv file with single crystal reflection data

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export a set of single crystal data as a csv file

G2export_csv.WriteList(obj, headerItems)[source]

Write a CSV header

Parameters:
  • obj (object) – Exporter object
  • headerItems (list) – items to write as a header

18.3. Module G2export_PDB: Macromolecular export

Code to export a phase into the venerated/obsolete (pick one) ASCII PDB format. Also defines exporter ExportPhaseCartXYZ which writes atom positions in orthogonal coordinates for a phase.

class G2export_PDB.ExportPhaseCartXYZ(G2frame)[source]

Used to create a Cartesian XYZ file for a phase

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export as a XYZ file

class G2export_PDB.ExportPhasePDB(G2frame)[source]

Used to create a PDB file for a phase

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export as a PDB file

18.4. Module G2export_image: 2D Image data export

Demonstrates how an image is retrieved and written. Uses a SciPy routine to write a PNG format file.

class G2export_image.ExportImagePNG(G2frame)[source]

Used to create a PNG file for a GSAS-II image

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export an image

18.5. Module G2export_map: Map export

Code to write Fourier/Charge-Flip atomic density maps out in formats that can be read by external programs. At present a GSAS format that is supported by FOX and DrawXTL (ExportMapASCII) and the CCP4 format that is used by COOT (ExportMapCCP4) are implemented.

class G2export_map.ExportMapASCII(G2frame)[source]

Used to create a text file for a phase

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export a map as a text file

class G2export_map.ExportMapCCP4(G2frame)[source]

Used to create a text file for a phase

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export a map as a text file

Write(data, dtype)[source]

write a line of output, attaching a line-end character

Parameters:line (str) – the text to be written.

18.6. Module G2export_shelx: Examples

Code to export coordinates in the SHELX .ins format (as best as I can makes sense of it).

class G2export_shelx.ExportPhaseShelx(G2frame)[source]

Used to create a SHELX .ins file for a phase

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export as a SHELX .ins file

18.7. Module G2export_CIF: CIF Exports

This implements a complex exporter ExportCIF that can implement an entire project in a complete CIF intended for submission as a publication. In addition, there are three subclasses of ExportCIF: ExportProjectCIF, ExportPhaseCIF and ExportDataCIF where extra parameters for the _Exporter() determine if a project, single phase or data set are written.

G2export_CIF.CIF2dict(cf)[source]

copy the contents of a CIF out from a PyCifRW block object into a dict

Returns:cifblk, loopstructure where cifblk is a dict with CIF items and loopstructure is a list of lists that defines which items are in which loops.
class G2export_CIF.CIFdefHelp(parent, msg, helpwin, helptxt)[source]

Create a help button that displays help information on the current data item

Parameters:
  • parent – the panel which will be the parent of the button
  • msg (str) – the help text to be displayed
  • helpwin (wx.Dialog) – Frame for CIF editing dialog
  • helptxt (wx.TextCtrl) – TextCtrl where help text is placed
class G2export_CIF.CIFtemplateSelect(frame, panel, tmplate, G2dict, repaint, title, defaultname='')[source]

Create a set of buttons to show, select and edit a CIF template

Parameters:
  • frame – wx.Frame object of parent
  • panel – wx.Panel object where widgets should be placed
  • tmplate (str) – one of ‘publ’, ‘phase’, or ‘instrument’ to determine the type of template
  • G2dict (dict) – GSAS-II dict where CIF should be placed. The key “CIF_template” will be used to store either a list or a string. If a list, it will contain a dict and a list defining loops. If an str, it will contain a file name.
  • repaint (function) – reference to a routine to be called to repaint the frame after a change has been made
  • title (str) – A line of text to show at the top of the window
  • defaultname (str) – specifies the default file name to be used for saving the CIF.
class G2export_CIF.EditCIFpanel(parent, cifblk, loopstructure, cifdic={}, OKbuttons=[], **kw)[source]

Creates a scrolled panel for editing CIF template items

Parameters:
  • parent (wx.Frame) – parent frame where panel will be placed
  • cifblk – dict or PyCifRW block containing values for each CIF item
  • loopstructure (list) –

    a list of lists containing the contents of each loop, as an example:

    [ ["_a","_b"], ["_c"], ["_d_1","_d_2","_d_3"]]
    

    this describes a CIF with this type of structure:

    loop_ _a _b <a1> <b1> <a2> ...
    loop_ _c <c1> <c2>...
    loop _d_1 _d_2 _d_3 ...
    

    Note that the values for each looped CIF item, such as _a, are contained in a list, for example as cifblk[“_a”]

  • cifdic (dict) – optional CIF dictionary definitions
  • OKbuttons (list) – A list of wx.Button objects that should be disabled when information in the CIF is invalid
  • (other) – optional keyword parameters for wx.ScrolledPanel
CIFEntryWidget(dct, item, dataname)[source]

Create an entry widget for a CIF item. Use a validated entry for numb values where int is required when limits are integers and floats otherwise. At present this does not allow entry of the special CIF values of “.” and “?” for numerical values and highlights them as invalid. Use a selection widget when there are specific enumerated values for a string.

ControlOKButton(setvalue)[source]

Enable or Disable the OK button(s) for the dialog. Note that this is passed into the ValidatedTxtCtrl for use by validators.

Parameters:setvalue (bool) – if True, all entries in the dialog are checked for validity. The first invalid control triggers disabling of buttons. If False then the OK button(s) are disabled with no checking of the invalid flag for each control.
DoLayout()[source]

Update the Layout and scroll bars for the Panel. Clears self.LayoutCalled so that next change to panel can request a new update

OnAddRow(event)[source]

add a row to a loop

OnLayoutNeeded(event)[source]

Called when an update of the panel layout is needed. Calls self.DoLayout after the current operations are complete using CallAfter. This is called only once, according to flag self.LayoutCalled, which is cleared in self.DoLayout.

class G2export_CIF.EditCIFtemplate(parent, cifblk, loopstructure, defaultname)[source]

Create a dialog for editing a CIF template. The edited information is placed in cifblk. If the CIF is saved as a file, the name of that file is saved as self.newfile.

Parameters:
  • parent (wx.Frame) – parent frame or None
  • cifblk – dict or PyCifRW block containing values for each CIF item
  • loopstructure (list) –

    a list of lists containing the contents of each loop, as an example:

    [ ["_a","_b"], ["_c"], ["_d_1","_d_2","_d_3"]]
    

    this describes a CIF with this type of structure:

    loop_ _a _b <a1> <b1> <a2> ...
    loop_ _c <c1> <c2>...
    loop _d_1 _d_2 _d_3 ...
    

    Note that the values for each looped CIF item, such as _a, are contained in a list, for example as cifblk[“_a”]

  • defaultname (str) – specifies the default file name to be used for saving the CIF.
Post()[source]

Display the dialog

Returns:True unless Cancel has been pressed.
class G2export_CIF.ExportCIF(G2frame, formatName, extension, longFormatName=None)[source]

Base class for CIF exports

ShowHstrainCells(phasenam, datablockidDict)[source]

Displays the unit cell parameters for phases where Dij values create mutiple sets of lattice parameters. At present there is no way defined for this in CIF, so local data names are used.

ValidateAscii(checklist)[source]

Validate items as ASCII

class G2export_CIF.ExportHKLCIF(G2frame)[source]

Used to create a simple CIF containing diffraction data only. Uses exact same code as ExportCIF except that histOnly is set for the Exporter Shows up in menu as Quick CIF.

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
class G2export_CIF.ExportPhaseCIF(G2frame)[source]

Used to create a simple CIF with one phase. Uses exact same code as ExportCIF except that phaseOnly is set for the Exporter Shows up in menu as Quick CIF.

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
class G2export_CIF.ExportProjectCIF(G2frame)[source]

Used to create a CIF of an entire project

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
class G2export_CIF.ExportPwdrCIF(G2frame)[source]

Used to create a simple CIF containing diffraction data only. Uses exact same code as ExportCIF except that histOnly is set for the Exporter Shows up in menu as Quick CIF.

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Writer(hist, mode='w')[source]

Used for histogram CIF export of a sequential fit.

G2export_CIF.FmtAtomType(sym)[source]

Reformat a GSAS-II atom type symbol to match CIF rules

G2export_CIF.HillSortElements(elmlist)[source]

Sort elements in “Hill” order: C, H, others, (where others are alphabetical).

Params list elmlist:
 a list of element strings
Returns:a sorted list of element strings
G2export_CIF.LoadCIFdic()[source]

Create a composite core+powder CIF lookup dict containing information about all items in the CIF dictionaries, loading pickled files if possible. The routine looks for files named cif_core.cpickle and cif_pd.cpickle in every directory in the path and if they are not found, files cif_core.dic and/or cif_pd.dic are read.

Returns:the dict with the definitions
G2export_CIF.PickleCIFdict(fil)[source]

Loads a CIF dictionary, cherry picks out the items needed by local code and sticks them into a python dict and writes that dict out as a pickle file for later reuse. If the write fails a warning message is printed, but no exception occurs.

Parameters:fil (str) – file name of CIF dictionary, will usually end in .dic
Returns:the dict with the definitions
G2export_CIF.WriteAtomsMagnetic(fp, phasedict, phasenam, parmDict, sigDict, labellist)[source]

Write atom positions to CIF

G2export_CIF.WriteAtomsNuclear(fp, phasedict, phasenam, parmDict, sigDict, labellist, RBparms={})[source]

Write atom positions to CIF

G2export_CIF.WriteCIFitem(fp, name, value='')[source]

Helper function for writing CIF output. Translated from exports/G2export_CIF.py

G2export_CIF.WriteComposition(fp, phasedict, phasenam, parmDict, quickmode=True, keV=None)[source]

determine the composition for the unit cell, crudely determine Z and then compute the composition in formula units.

If quickmode is False, then scattering factors are added to the element loop.

If keV is specified, then resonant scattering factors are also computed and included.

G2export_CIF.dict2CIF(dblk, loopstructure, blockname='Template')[source]

Create a PyCifRW CIF object containing a single CIF block object from a dict and loop structure list.

Parameters:
  • dblk – a dict containing values for each CIF item
  • loopstructure (list) –

    a list of lists containing the contents of each loop, as an example:

    [ ["_a","_b"], ["_c"], ["_d_1","_d_2","_d_3"]]
    

    this describes a CIF with this type of structure:

    loop_ _a _b <a1> <b1> <a2> ...
    loop_ _c <c1> <c2>...
    loop _d_1 _d_2 _d_3 ...
    

    Note that the values for each looped CIF item, such as _a, are contained in a list, for example as cifblk[“_a”]

  • blockname (str) – an optional name for the CIF block. Defaults to ‘Template’
Returns:

the newly created PyCifRW CIF object

18.8. Module G2export_pwdr: Export powder input files

Creates files used by GSAS (FXYE) & TOPAS (XYE) as input

class G2export_pwdr.ExportPowderFXYE(G2frame)[source]

Used to create a FXYE file for a powder data set

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export one or more sets of powder data as FXYE file(s)

WriteInstFile(hist, Inst)[source]

Write an instrument parameter file

Writer(TreeName, filename=None, prmname='')[source]

Write a single PWDR entry to a FXYE file

class G2export_pwdr.ExportPowderXYE(G2frame)[source]

Used to create a Topas XYE file for a powder data set

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export one or more sets of powder data as XYE file(s)

18.9. Module G2export_FIT2D: Fit2D “Chi” export

Code to create .chi (Fit2D like) files for GSAS-II powder data export

class G2export_FIT2D.ExportPowderCHI(G2frame)[source]

Used to create a CHI file for a powder data set

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export a set of powder data as a Fit2D .qchi file

class G2export_FIT2D.ExportPowderQCHI(G2frame)[source]

Used to create a q-binned CHI file for a powder data set

Parameters:G2frame (wx.Frame) – reference to main GSAS-II frame
Exporter(event=None)[source]

Export a set of powder data as a q-bin Fit2D .qchi file