diffpy.structure.parsers package

Submodules

diffpy.structure.parsers.p_auto module

Parser for automatic file format detection

This Parser does not provide the the toLines() method.

class P_auto(**kw)

Bases: diffpy.structure.parsers.structureparser.StructureParser

Parser with automatic detection of structure format. When successful, it sets its format attribute to detected structure format.

parseLines(lines)

Detect format and create Structure instance from a list of lines. Set format attribute to the detected file format.

Return Structure object or raise StructureFormatError exception.

parse(s)

Detect format and create Structure instance from a string. Set format attribute to the detected file format.

Return Structure object or raise StructureFormatError exception.

parseFile(filename)

Detect format and create Structure instance from an existing file. Set format attribute to the detected file format.

filename – path to structure file

Return Structure object. Raise StructureFormatError or IOError.

getParser(**kw)

diffpy.structure.parsers.p_cif module

Parser for basic CIF file format

http://www.iucr.org/iucr-top/cif/home.html

class P_cif(eps=None)

Bases: diffpy.structure.parsers.structureparser.StructureParser

Simple parser for CIF structure format. Reads Structure from the first block containing _atom_site_label key. Following blocks, if any are ignored.

Data members:

format – structure format name ciffile – instance of CifFile from PyCifRW stru – Structure instance used for cif input or output

Data members used for input only:

spacegroup – instance of SpaceGroup used for symmetry expansion eps – resolution in fractional coordinates for non-equal

positions. Use for expansion of asymmetric unit.

eau – instance of ExpandAsymmetricUnit from SymmetryUtilities asymmetric_unit – list of atom instances for the original asymmetric

unit in the CIF file
labelindex – dictionary mapping unique atom label to index of atom
in self.asymmetric_unit
cif_sgname – space group name obtained by looking up the value of
_space_group_name_Hall, _symmetry_space_group_name_Hall, _space_group_name_H-M_alt, _symmetry_space_group_name_H-M items. None when neither is defined.
BtoU = 0.012665147955292222
parse(s)

Create Structure instance from a string in CIF format.

Return Structure instance or raise StructureFormatError.

parseLines(lines)

Parse list of lines in CIF format.

lines – list of strings stripped of line terminator

Return Structure instance or raise StructureFormatError.

parseFile(filename)

Create Structure from an existing CIF file.

filename – path to structure file

Return Structure object. Raise StructureFormatError or IOError.

toLines(stru)

Convert Structure stru to a list of lines in basic CIF format.

Return list of strings.

leading_float(s)

Obtain first float from a string and ignore any trailing characters. Useful for extracting values from “value(std)” syntax.

Return float.

getSymOp(s)

Create SpaceGroups.SymOp instance from a string.

s – formula for equivalent coordinates, for example ‘x,1/2-y,1/2+z’

Return instance of SymOp.

getParser(eps=None)

Return new parser object for CIF structure format.

eps – fractional coordinates cutoff for duplicate positions.
When None use the default for ExpandAsymmetricUnit.

diffpy.structure.parsers.p_discus module

Parser for DISCUS structure format

class P_discus

Bases: diffpy.structure.parsers.structureparser.StructureParser

Parser for DISCUS structure format. The parser chokes on molecule and generator records.

parseLines(lines)

Parse list of lines in DISCUS format.

Return PDFFitStructure instance or raise StructureFormatError.

toLines(stru)

Convert Structure stru to a list of lines in DISCUS format. Return list of strings.

getParser()

diffpy.structure.parsers.p_pdb module

Basic parser for PDB structure format.

References

class P_pdb

Bases: diffpy.structure.parsers.structureparser.StructureParser

Simple parser for PDB format. The parser understands following PDB records: TITLE, CRYST1, SCALE1, SCALE2, SCALE3, ATOM, SIGATM, ANISOU, SIGUIJ, TER, HETATM, END

Static data members:

orderOfRecords – order of PDB record labels validRecords – dictionary of valid PDB records

orderOfRecords = ['HEADER', 'OBSLTE', 'TITLE', 'CAVEAT', 'COMPND', 'SOURCE', 'KEYWDS', 'EXPDTA', 'AUTHOR', 'REVDAT', 'SPRSDE', 'JRNL', 'REMARK', 'REMARK', 'REMARK', 'REMARK', 'DBREF', 'SEQADV', 'SEQRES', 'MODRES', 'HET', 'HETNAM', 'HETSYN', 'FORMUL', 'HELIX', 'SHEET', 'TURN', 'SSBOND', 'LINK', 'HYDBND', 'SLTBRG', 'CISPEP', 'SITE', 'CRYST1', 'ORIGX1', 'ORIGX2', 'ORIGX3', 'SCALE1', 'SCALE2', 'SCALE3', 'MTRIX1', 'MTRIX2', 'MTRIX3', 'TVECT', 'MODEL', 'ATOM', 'SIGATM', 'ANISOU', 'SIGUIJ', 'TER', 'HETATM', 'ENDMDL', 'CONECT', 'MASTER', 'END']
validRecords = {'ANISOU': None, 'ATOM': None, 'AUTHOR': None, 'CAVEAT': None, 'CISPEP': None, 'COMPND': None, 'CONECT': None, 'CRYST1': None, 'DBREF': None, 'END': None, 'ENDMDL': None, 'EXPDTA': None, 'FORMUL': None, 'HEADER': None, 'HELIX': None, 'HET': None, 'HETATM': None, 'HETNAM': None, 'HETSYN': None, 'HYDBND': None, 'JRNL': None, 'KEYWDS': None, 'LINK': None, 'MASTER': None, 'MODEL': None, 'MODRES': None, 'MTRIX1': None, 'MTRIX2': None, 'MTRIX3': None, 'OBSLTE': None, 'ORIGX1': None, 'ORIGX2': None, 'ORIGX3': None, 'REMARK': None, 'REVDAT': None, 'SCALE1': None, 'SCALE2': None, 'SCALE3': None, 'SEQADV': None, 'SEQRES': None, 'SHEET': None, 'SIGATM': None, 'SIGUIJ': None, 'SITE': None, 'SLTBRG': None, 'SOURCE': None, 'SPRSDE': None, 'SSBOND': None, 'TER': None, 'TITLE': None, 'TURN': None, 'TVECT': None}
parseLines(lines)

Parse list of lines in PDB format.

Return Structure instance or raise StructureFormatError.

titleLines(stru)

build lines corresponding to TITLE record

cryst1Lines(stru)

build lines corresponding to CRYST1 record

atomLines(stru, idx)

build ATOM records and possibly SIGATM, ANISOU or SIGUIJ records for structure stru atom number aidx

toLines(stru)

Convert Structure stru to a list of lines in PDFFit format.

Return list of strings.

getParser()

diffpy.structure.parsers.p_pdffit module

Parser for PDFfit structure format

class P_pdffit

Bases: diffpy.structure.parsers.structureparser.StructureParser

Parser for PDFfit structure format.

stru – Structure instance used for cif input or output

parseLines(lines)

Parse list of lines in PDFfit format.

Return Structure object or raise StructureFormatError.

toLines(stru)

Convert Structure stru to a list of lines in PDFfit format.

Return list of strings.

getParser()

diffpy.structure.parsers.p_rawxyz module

Parser for raw XYZ file format. Raw XYZ is a 3 or 4 column text file with cartesian coordinates of atoms and an optional first column for atom types.

class P_rawxyz

Bases: diffpy.structure.parsers.structureparser.StructureParser

Parser –> StructureParser subclass for RAWXYZ format

parseLines(lines)

Parse list of lines in RAWXYZ format.

Return Structure object or raise StructureFormatError.

toLines(stru)

Convert Structure stru to a list of lines in XYZ format.

Return list of strings.

getParser()

diffpy.structure.parsers.p_xcfg module

Parser for extended CFG format used by atomeye

class P_xcfg

Bases: diffpy.structure.parsers.structureparser.StructureParser

Parser for AtomEye extended CFG format.

cluster_boundary – width of boundary around corners of non-periodic
cluster to avoid PBC effects in atomeye
cluster_boundary = 2
parseLines(lines)

Parse list of lines in PDB format.

Return Structure object or raise StructureFormatError.

toLines(stru)

Convert Structure stru to a list of lines in XCFG atomeye format.

Return list of strings.

getParser()

diffpy.structure.parsers.p_xyz module

Parser for XYZ file format, where first line gives number of atoms second one has optional title remaining lines contain element, x, y, z

class P_xyz

Bases: diffpy.structure.parsers.structureparser.StructureParser

Parser for standard XYZ structure format.

parseLines(lines)

Parse list of lines in XYZ format.

Return Structure object or raise StructureFormatError.

toLines(stru)

Convert Structure stru to a list of lines in XYZ format.

Return list of strings.

getParser()

diffpy.structure.parsers.parser_index_mod module

Index of recognized structure formats, their IO capabilities and associated modules where they are defined. Plugins for new structure formats need to be added to the parser_index dictionary in this module.

diffpy.structure.parsers.structureparser module

Definition of StructureParser, a base class for specific parsers.

class StructureParser

Bases: object

Base class for all structure parsers.

Data members:
format – format of particular parser filename – path to structure file that is read or written
parseLines(lines)

Create Structure instance from a list of lines.

Return Structure object or raise StructureFormatError exception. This method has to be overloaded in derived class.

toLines(stru)

Convert Structure stru to a list of lines. This method has to be overloaded in derived class.

Return list of strings.

parse(s)

Create Structure instance from a string.

Return Structure object or raise StructureFormatError exception.

tostring(stru)

Convert Structure instance to a string.

parseFile(filename)

Create Structure instance from an existing file.

filename – path to structure file

Return Structure object. Raise StructureFormatError or IOError.

Module contents

Conversion plugins for various structure formats

The recognized structure formats are defined by subclassing StructureParser, by convention these classes are named P_<format>. The parser classes should to override the parseLines() and toLines() methods of StructureParser. Any structure parser needs to be registered in parser_index module.

For normal usage it should be sufficient to use the routines provided in this module.

Content:
StructureParser – base class for a concrete Parser parser_index – dictionary of known structure formats getParser – factory for Parser at given format inputFormats – list of available input formats outputFormats – list of available output formats
getParser(format, **kw)

Return Parser instance for a given structure format.

kw – keyword arguments passed to the Parser init function.

Raises StructureFormatError exception when format is not defined.

inputFormats()

Return list of implemented input structure formats

outputFormats()

return list of implemented output structure formats