Package Scientific :: Package IO :: Module PDB :: Class PDBFile
[frames] | no frames]

Class PDBFile

PDB file with access at the record level

The low-level file access is handled by the module Scientific.IO.TextFile, therefore compressed files and URLs (for reading) can be used as well.

Instance Methods
 
__del__(self)
 
__init__(self, file_or_filename, mode='r', subformat=None)
 
close(self)
Close the file.
 
nextChain(self, chain_id=None, segment_id='')
Signal the beginning of a new chain.
 
nextResidue(self, name, number=None, terminus=None)
Signal the beginning of a new residue, starting with the next call to writeAtom.
tuple
readLine(self)
Return the contents of the next non-blank line (= record) The return value is a tuple whose first element (a string) contains the record type.
 
terminateChain(self)
Signal the end of a chain.
 
writeAtom(self, name, position, occupancy=0.0, temperature_factor=0.0, element='')
Write an ATOM or HETATM record using the information supplied.
 
writeComment(self, text)
Write text into one or several comment lines.
 
writeLine(self, type, data)
Write a line using record type and data dictionary in the same format as returned by readLine().
Method Details

__init__(self, file_or_filename, mode='r', subformat=None)
(Constructor)

 
Parameters:
  • file_or_filename (str or file) - the name of the PDB file, or a file object
  • mode (str) - the file access mode, 'r' (read) or 'w' (write)
  • subformat (str or NoneType) - indicates a specific dialect of the PDB format. Subformats are defined in Scientific.IO.PDBExportFilters; they are used only when writing.

close(self)

 

Close the file. This method must be called for write mode because otherwise the file will be incomplete.

nextChain(self, chain_id=None, segment_id='')

 

Signal the beginning of a new chain.

Parameters:
  • chain_id (str or NoneType) - a chain identifier. If None, consecutive letters from the alphabet are used.
  • segment_id (str) - a chain identifier

nextResidue(self, name, number=None, terminus=None)

 

Signal the beginning of a new residue, starting with the next call to writeAtom.

Parameters:
  • name (str) - the residue name
  • number (int or NoneType) - the residue number. If None, the residues will be numbered sequentially, starting from 1.
  • terminus - None, "C", or "N". This information is passed to export filters that can use this information in order to use different atom or residue names in terminal residues.

readLine(self)

 

Return the contents of the next non-blank line (= record) The return value is a tuple whose first element (a string) contains the record type. For supported record types (HEADER, CRYST1, SCALEn, MTRIXn, ATOM, HETATM, ANISOU, TERM, MODEL, CONECT), the items from the remaining fields are put into a dictionary which is returned as the second tuple element. Most dictionary elements are strings or numbers; atom positions are returned as a vector, and anisotropic temperature factors are returned as a rank-2 tensor, already multiplied by 1.e-4. White space is stripped from all strings except for atom names, whose correct interpretation can depend on an initial space. For unsupported record types, the second tuple element is a string containing the remaining part of the record.

Returns: tuple
the contents of one PDB record

writeAtom(self, name, position, occupancy=0.0, temperature_factor=0.0, element='')

 

Write an ATOM or HETATM record using the information supplied. The residue and chain information is taken from the last calls to the methods nextResidue and nextChain.

Parameters:
  • name (str) - the atom name
  • position (Scientific.Geometry.Vector) - the atom position
  • occupancy (float) - the occupancy
  • temperature_factor (float) - the temperature factor (B-factor)
  • element (str) - the chemical element

writeComment(self, text)

 

Write text into one or several comment lines. Each line of the text is prefixed with 'REMARK' and written to the file.

Parameters:
  • text (str) - the comment contents

writeLine(self, type, data)

 

Write a line using record type and data dictionary in the same format as returned by readLine(). Default values are provided for non-essential information, so the data dictionary need not contain all entries.

Parameters:
  • type (str) - PDB record type
  • data (tuple) - PDB record data