schrodinger.application.matsci.gsas.GSASIIfiles module

# Third-party code. No Schrodinger Copyright.

GSASIIfiles: data (non-GUI) I/O routines

Module with miscellaneous routines for input and output from files.

This module should not contain any references to wxPython so that it can be imported for scriptable use or potentially on clients where wx is not installed.

Future refactoring: This module and needs some work to move non-wx routines here. It may will likely make sense to rename the module(s) at that point.


Convert a string to float. An empty field or a unconvertable value is treated as zero

schrodinger.application.matsci.gsas.GSASIIfiles.G2printLevel = 'all'

This defines the level of output from calls to G2Print(), which should be used in place of print() within this module. Settings for this are ‘all’, ‘warn’, ‘error’ or ‘none’. Also see: G2Print() and G2SetPrintLevel().


Set the level of output from calls to G2Print(), which should be used in place of print() within GSASII. Settings for the mode are ‘all’, ‘warn’, ‘error’ or ‘none’


level (str) – a string used to set the print level, which may be ‘all’, ‘warn’, ‘error’ or ‘none’. Note that capitalization and extra letters in level are ignored, so ‘Warn’, ‘warnings’, etc. will all set the mode to ‘warn’

schrodinger.application.matsci.gsas.GSASIIfiles.G2Print(*args, **kwargs)

Print with filtering based level of output (see G2SetPrintLevel()). Use G2Print() as replacement for print().


mode (str) – if specified, this should contain the mode for printing (‘error’, ‘warn’ or anything else). If not specified, the first argument of the print command (args[0]) should contain the string ‘error’ for error messages and ‘warn’ for warning messages (capitalization and additional letters ignored.)

schrodinger.application.matsci.gsas.GSASIIfiles.makeInstDict(names, data, codes)
schrodinger.application.matsci.gsas.GSASIIfiles.SetPowderInstParms(Iparm, rd)

extracts values from instrument parameters in rd.instdict or in array Iparm. Create and return the contents of the instrument parameter tree entry.

schrodinger.application.matsci.gsas.GSASIIfiles.ReadPowderInstprm(instLines, bank, databanks, rd)

Read lines from a GSAS-II (new) instrument parameter file similar to G2pwdGUI.OnLoad If instprm file has multiple banks each with header #Bank n: …, this finds matching bank no. to load - problem with nonmatches?

Note that this routine performs a similar role to GSASIIdataGUI.GSASII.ReadPowderInstprm(), but that will call a GUI routine for selection when needed. This routine will raise exceptions on errors and will select the first bank when a choice might be appropriate. TODO: refactor to combine the two routines.

  • instLines (list) – strings from GSAS-II parameter file; can be concatenated with ‘;’

  • bank (int) – bank number to check when instprm file has ‘#BANK n:…’ strings when bank = n then use parameters; otherwise skip that set. Ignored if BANK n: not present. NB: this kind of instprm file made by a Save all profile command in Instrument Par ameters

Return dict

Inst instrument parameter dict if OK, or str: Error message if failed

(transliterated from (rev 3008), function of the same name)

schrodinger.application.matsci.gsas.GSASIIfiles.LoadImportRoutines(prefix, errprefix=None, traceback=False)

Routine to locate GSASII importers matching a prefix string

schrodinger.application.matsci.gsas.GSASIIfiles.LoadExportRoutines(parent, traceback=False)

Routine to locate GSASII exporters


Reads image metadata from a column-oriented metadata table (1-ID style .par file). Called by GetColumnMetadata()

The .par file has any number of columns separated by spaces. The directory for the file must be specified in Config variable config_example.Column_Metadata_directory. As an index to the .par file a second “label file” must be specified with the same file root name as the .par file but the extension must be .XXX_lbls (where .XXX is the extension of the image) or if that is not present extension .lbls.


imagefile (str) – the full name of the image file (with extension, directory optional)


a dict with parameter values. Named parameters will have the type based on the specified Python function, named columns will be character strings

The contents of the label file will look like this:

# define keywords
filename:lambda x,y: "{}_{:0>6}".format(x,y)|33,34
distance: float | 75
wavelength:lambda keV: 12.398425/float(keV)|9
pixelSize:lambda x: [74.8, 74.8]|0
ISOlikeDate: lambda dow,m,d,t,y:"{}-{}-{}T{} ({})".format(y,m,d,t,dow)|0,1,2,3,4
Temperature: float|53
FreePrm2: int | 34 | Free Parm2 Label
# define other variables
This file contains three types of lines in any order.
  • Named parameters are evaluated with user-supplied Python code (see subsequent information). Specific named parameters are used to determine values that are used for image interpretation (see table, below). Any others are copied to the Comments subsection of the Image tree item.

  • Column labels are defined with a column number (integer) followed by a colon (:) and a label to be assigned to that column. All labeled columns are copied to the Image’s Comments subsection.

  • Comments are any line that does not contain a colon.

Note that columns are numbered starting at zero.

Any named parameter may be defined provided it is not a valid integer, but the named parameters in the table have special meanings, as descibed. The parameter name is followed by a colon. After the colon, specify Python code that defines or specifies a function that will be called to generate a value for that parameter.

Note that several keywords, if defined in the Comments, will be found and placed in the appropriate section of the powder histogram(s)’s Sample Parameters after an integration: Temperature, Pressure, Time, FreePrm1, FreePrm2, FreePrm3, Omega, Chi, and Phi.

After the Python code, supply a vertical bar (|) and then a list of one more more columns that will be supplied as arguments to that function.

Note that the labels for the three FreePrm items can be changed by including that label as a third item with an additional vertical bar. Labels will be ignored for any other named parameters.

The examples above are discussed here:

filename:lambda x,y: "{}_{:0>6}".format(x,y)|33,34

Here the function to be used is defined with a lambda statement:

lambda x,y: "{}_{:0>6}".format(x,y)

This function will use the format function to create a file name from the contents of columns 33 and 34. The first parameter (x, col. 33) is inserted directly into the file name, followed by a underscore (_), followed by the second parameter (y, col. 34), which will be left-padded with zeros to six characters (format directive :0>6).

When there will be more than one image generated per line in the .par file, an alternate way to generate list of file names takes into account the number of images generated:

lambda x,y,z: ["{}_{:0>6}".format(x,int(y)+i) for i in range(int(z))]

Here a third parameter is used to specify the number of images generated, where the image number is incremented for each image.

distance: float | 75

Here the contents of column 75 will be converted to a floating point number by calling float on it. Note that the spaces here are ignored.

wavelength:lambda keV: 12.398425/float(keV)|9

Here we define an algebraic expression to convert an energy in keV to a wavelength and pass the contents of column 9 as that input energy

pixelSize:lambda x: [74.8, 74.8]|0

In this case the pixel size is a constant (a list of two numbers). The first column is passed as an argument as at least one argument is required, but that value is not used in the expression.

ISOlikeDate: lambda dow,m,d,t,y:"{}-{}-{}T{} ({})".format(y,m,d,t,dow)|0,1,2,3,4

This example defines a parameter that takes items in the first five columns and formats them in a different way. This parameter is not one of the pre-defined parameter names below. Some external code could be used to change the month string (argument m) to a integer from 1 to 12.

FreePrm2: int | 34 | Free Parm2 Label

In this example, the contents of column 34 will be converted to an integer and placed as the second free-named parameter in the Sample Parameters after an integration. The label for this parameter will be changed to “Free Parm2 Label”.

Pre-defined parameter names







str or list

generates the file name prefix for the matching image file (MyImage001 for file /tmp/MyImage001.tif) or a list of file names.




generates the polarization expected based on the monochromator angle, defaults to 0.99.



list of 2 floats

generates the approximate beam center on the detector in mm, such as [204.8, 204.8].




generates the distance from the sample to the detector in mm



list of 2 floats

generates the size of the pixels in microns such as [200.0, 200.0].




generates the wavelength in Angstroms


Read the .*lbls file and setup for metadata assignments

schrodinger.application.matsci.gsas.GSASIIfiles.evalColMetadataDicts(items, labels, lbldict, keyCols, keyExp, ShowError=False)

Evaluate the metadata for a line in the .par file


Add metadata to an image from a column-type metadata file using readColMetadata()


reader – a reader object from reading an image

schrodinger.application.matsci.gsas.GSASIIfiles.LoadControls(Slines, data)

Read values from a .imctrl (Image Controls) file

schrodinger.application.matsci.gsas.GSASIIfiles.WriteControls(filename, data)

Write current values to a .imctrl (Image Controls) file

schrodinger.application.matsci.gsas.GSASIIfiles.RereadImageData(ImageReaderlist, imagefile, ImageTag=None, FormatName='')

Read a single image with an image importer. This is called to reread an image after it has already been imported, so it is not necessary to reload metadata.

Based on GetImageData.GetImageData() which this can replace where imageOnly=True

  • ImageReaderlist (list) – list of Reader objects for images

  • imagefile (str) – name of image file

  • ImageTag (int/str) – specifies a particular image to be read from a file. First image is read if None (default).

  • formatName (str) – the image reader formatName


an image as a numpy array

schrodinger.application.matsci.gsas.GSASIIfiles.readMasks(filename, masks, ignoreThreshold)

Read a GSAS-II masks file

schrodinger.application.matsci.gsas.GSASIIfiles.PDFWrite(PDFentry, fileroot, PDFsaves, PDFControls, Inst={}, Limits=[])

Write PDF-related data (G(r), S(Q),…) into files, as selected.

  • PDFentry (str) – name of the PDF entry in the tree. This is used for comments in the file specifying where it came from; it can be arbitrary

  • fileroot (str) – name of file(s) to be written. The extension will be ignored.

  • PDFsaves (list) – flags that determine what type of file will be written: PDFsaves[0], if True writes a I(Q) file with a .iq extension PDFsaves[1], if True writes a S(Q) file with a .sq extension PDFsaves[2], if True writes a F(Q) file with a .fq extension PDFsaves[3], if True writes a G(r) file with a .gr extension PDFsaves[4], if True writes G(r) in a pdfGUI input file with a .gr extension. Note that if PDFsaves[3] and PDFsaves[4] are both True, the pdfGUI overwrites the G(r) file.

  • PDFControls (dict) – The PDF parameters and computed results

  • Inst (dict) – Instrument parameters from the PDWR entry used to compute the PDF. Needed only when PDFsaves[4] is True.

  • Limits (list) – Computation limits from the PDWR entry used to compute the PDF. Needed only when PDFsaves[4] is True.