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 diffpy.Structure.Parsers.P_auto.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.

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.

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.

diffpy.Structure.Parsers.P_auto.getParser(**kw)

diffpy.Structure.Parsers.P_bratoms module

Parser for Bruce Ravel’s Atoms structure format

class diffpy.Structure.Parsers.P_bratoms.P_bratoms

Bases: diffpy.Structure.Parsers.structureparser.StructureParser

Parser for Bruce Ravel’s Atoms structure format.

parseLines(lines)

Parse list of lines in atoms format.

Return Structure object or raise StructureFormatError.

plist = ['a', 'b', 'c', 'alpha', 'beta', 'gamma']
toLines(stru)

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

Return list of strings.

diffpy.Structure.Parsers.P_bratoms.getParser()

diffpy.Structure.Parsers.P_cif module

Parser for basic CIF file format

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

class diffpy.Structure.Parsers.P_cif.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.

parseFile(filename)

Create Structure from an existing CIF file.

filename – path to structure file

Return Structure object. Raise StructureFormatError or IOError.

parseLines(lines)

Parse list of lines in CIF format.

lines – list of strings stripped of line terminator

Return Structure instance or raise StructureFormatError.

toLines(stru)

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

Return list of strings.

diffpy.Structure.Parsers.P_cif.fixIfWindowsPath(filename)

Convert Windows-style path to valid local URL. CifFile loads files using urlopen, which fails for Windows-style paths.

filename – path to be fixed

Return fixed URL when run on Windows, otherwise return filename.

diffpy.Structure.Parsers.P_cif.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_cif.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.

diffpy.Structure.Parsers.P_cif.leading_float(s)

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

Return float.

diffpy.Structure.Parsers.P_discus module

Parser for DISCUS structure format

class diffpy.Structure.Parsers.P_discus.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.

diffpy.Structure.Parsers.P_discus.getParser()

diffpy.Structure.Parsers.P_pdb module

Basic parser for PDB structure format.

References

class diffpy.Structure.Parsers.P_pdb.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

atomLines(stru, idx)

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

cryst1Lines(stru)

build lines corresponding to CRYST1 record

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']
parseLines(lines)

Parse list of lines in PDB format.

Return Structure instance or raise StructureFormatError.

titleLines(stru)

build lines corresponding to TITLE record

toLines(stru)

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

Return list of strings.

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}
diffpy.Structure.Parsers.P_pdb.getParser()

diffpy.Structure.Parsers.P_pdffit module

Parser for PDFfit structure format

class diffpy.Structure.Parsers.P_pdffit.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.

diffpy.Structure.Parsers.P_pdffit.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 diffpy.Structure.Parsers.P_rawxyz.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.

diffpy.Structure.Parsers.P_rawxyz.getParser()

diffpy.Structure.Parsers.P_xcfg module

Parser for extended CFG format used by atomeye

class diffpy.Structure.Parsers.P_xcfg.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.

diffpy.Structure.Parsers.P_xcfg.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 diffpy.Structure.Parsers.P_xyz.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.

diffpy.Structure.Parsers.P_xyz.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 diffpy.Structure.Parsers.structureparser.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
parse(s)

Create Structure instance from a string.

Return Structure object or raise StructureFormatError exception.

parseFile(filename)

Create Structure instance from an existing file.

filename – path to structure file

Return Structure object. Raise StructureFormatError or IOError.

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.

tostring(stru)

Convert Structure instance to a string.

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 concrete Parsers 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
diffpy.Structure.Parsers.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.

diffpy.Structure.Parsers.inputFormats()

Return list of implemented input structure formats

diffpy.Structure.Parsers.outputFormats()

return list of implemented output structure formats