PDB File
This module defines functions for parsing and writing PDB files.
- prody.proteins.pdbfile.parseChainsList(filename)[source]
Parse a set of PDBs and extract chains based on a list in a text file.
- Parameters:
filename (str) – the name of the file to be read
Returns: lists containing an :class:’.AtomGroup’ for each PDB, the headers for those PDBs, and the requested
Chainobjects
- prody.proteins.pdbfile.parsePDB(*pdb, **kwargs)[source]
Returns an
AtomGroupand/or dictionary containing header data parsed from a PDB file.This function extends
parsePDBStream().See parsepdb for a detailed usage example.
- Parameters:
pdb – one PDB identifier or filename, or a list of them. If needed, PDB files are downloaded using
fetchPDB()function.
You can also provide arguments that you would like passed on to fetchPDB().
- Parameters:
extend_biomol (bool) – whether to extend the list of results with a list rather than appending, which can create a mixed list, especially when biomol=True. Default value is False to reproduce previous behaviour. This value is ignored when result is not a list (header=True or model=0).
Please note that resnames are only taken as 3 characters and chids can be 2 by default. Hence, TIP3S is split into resname TIP and chid 3S.
This behaviour can be changed with the following two arguments:
- Parameters:
long_resname (bool) – whether to parse longer resnames instead of cutting at 3 chars
hexadecimal (bool) –
force serial numbers and residue numbers to be decoded as HEXADECIMAL, for every record, instead of auto-detecting. Use it for a file whose numbering is ENTIRELY hex-encoded; auto-detection mangles those badly (an uppercase hex serial is misread as hybrid36 and can come back negative). Default False = auto-detect: a field containing UPPERCASE letters is read as hybrid36, anything else as hex, and plain-decimal mode is left only once a resnum decrease from a value >= 9999 is observed.
LIMITATION, inherent rather than an implementation gap:
writePDB()emits MIXED numbering – decimal below the field width, hex at or above it – and2710is a valid decimal string as well as hex for 10000, so no reader can separate the two. With this flag the decimal prefix of such a file decodes wrongly (9999-> 0x9999 = 39321); without it the hex tail does. Preferhybrid36=Truewhen WRITING anything that exceeds the field width – the hybrid36 range always begins with a letter, so it stays unambiguous.NB this decodes PLAIN hex, which is what
writePDB()emits. It does NOT decode OpenMM’s SHIFTED hex ((i - 10**places + 10*16**(places-1)) % 16**places), a different convention used byopenmm.app.PDBFile.long_chid (bool) – whether to parse longer chain ids instead of cutting at 2 chars
packmol (bool) – whether to renumber chains like packmol, default is False
title (str) – title of the
AtomGroupinstance, default is the PDB filename or PDB identifierag (
AtomGroup) –AtomGroupinstance for storing data parsed from PDB file, number of atoms in ag and number of atoms parsed from the PDB file must be the same and atoms in ag and those in PDB file must be in the same order. Non-coordinate data stored in ag will be overwritten with those parsed from the file.chain (str) – chain identifiers for parsing specific chains, e.g.
chain='A',chain='B',chain='DE', by default all chains are parsedsubset (str) – a predefined keyword to parse subset of atoms, valid keywords are
'calpha'('ca'),'backbone'('bb'), or None (read all atoms), e.g.subset='bb'model (int, list) – model index or None (read all models), e.g.
model=10header (bool) – if True PDB header content will be parsed and returned
altloc (str) – if a location indicator is passed, such as
'A'or'B', only indicated alternate locations will be parsed as the single coordinate set of the AtomGroup, if altloc is set'all'then all alternate locations will be parsed and each will be appended as a distinct coordinate set, default is"A"biomol (bool) – if True, biomolecules are obtained by transforming the coordinates using information from header section will be returned. This option uses
buildBiomolecules()and as noted there, atoms in biomolecules are ordered according to the original chain IDs. Chains may have the same chain ID, in which case they are given different segment names. Default is Falsesecondary (bool) – if True, secondary structure information from header section will be assigned to atoms. Default is False
If
model=0andheader=True, return header dictionary only.
- prody.proteins.pdbfile.parsePDBStream(stream, **kwargs)[source]
Returns an
AtomGroupand/or dictionary containing header data parsed from a stream of PDB lines.- Parameters:
stream – Anything that implements the method
readlines(e.g.file, buffer, stdin)title (str) – title of the
AtomGroupinstance, default is the PDB filename or PDB identifierag (
AtomGroup) –AtomGroupinstance for storing data parsed from PDB file, number of atoms in ag and number of atoms parsed from the PDB file must be the same and atoms in ag and those in PDB file must be in the same order. Non-coordinate data stored in ag will be overwritten with those parsed from the file.chain (str) – chain identifiers for parsing specific chains, e.g.
chain='A',chain='B',chain='DE', by default all chains are parsedsubset (str) – a predefined keyword to parse subset of atoms, valid keywords are
'calpha'('ca'),'backbone'('bb'), or None (read all atoms), e.g.subset='bb'model (int, list) – model index or None (read all models), e.g.
model=10header (bool) – if True PDB header content will be parsed and returned
altloc (str) – if a location indicator is passed, such as
'A'or'B', only indicated alternate locations will be parsed as the single coordinate set of the AtomGroup, if altloc is set'all'then all alternate locations will be parsed and each will be appended as a distinct coordinate set, default is"A"biomol (bool) – if True, biomolecules are obtained by transforming the coordinates using information from header section will be returned. This option uses
buildBiomolecules()and as noted there, atoms in biomolecules are ordered according to the original chain IDs. Chains may have the same chain ID, in which case they are given different segment names. Default is Falsesecondary (bool) – if True, secondary structure information from header section will be assigned to atoms. Default is False
If
model=0andheader=True, return header dictionary only.
- prody.proteins.pdbfile.parsePQR(filename, **kwargs)[source]
Returns an
AtomGroupcontaining data parsed from PDB lines.- Parameters:
filename (str) – a PQR filename
title (str) – title of the
AtomGroupinstance, default is the PDB filename or PDB identifierag (
AtomGroup) –AtomGroupinstance for storing data parsed from PDB file, number of atoms in ag and number of atoms parsed from the PDB file must be the same and atoms in ag and those in PDB file must be in the same order. Non-coordinate data stored in ag will be overwritten with those parsed from the file.chain (str) – chain identifiers for parsing specific chains, e.g.
chain='A',chain='B',chain='DE', by default all chains are parsedsubset (str) – a predefined keyword to parse subset of atoms, valid keywords are
'calpha'('ca'),'backbone'('bb'), or None (read all atoms), e.g.subset='bb'
- prody.proteins.pdbfile.writeChainsList(chains, filename)[source]
Write a text file containing a list of chains that can be parsed.
- prody.proteins.pdbfile.writePDB(filename, atoms, csets=None, autoext=True, **kwargs)[source]
Write atoms in PDB format to a file with name filename and return filename. If filename ends with
.gz, a compressed file will be written.- Parameters:
renumber (bool) – whether to renumber atoms with serial indices Default is True
hybrid36 (bool) – whether to use hybrid36 format for atom residue numbers Default is False, which means using hexadecimal instead. NB: ChimeraX seems to prefer hybrid36 and may have problems with hexadecimal.
full_ter (bool) – whether to write full TER lines with atoms info Default is True
increment_ter (bool) – whether to increment serials with TER lines Default is True
Please note that resnames longer than 3 characters will be trimmed by default. This behaviour can be changed with the following argument:
- Parameters:
long_resname (bool) – whether to write 4-character resnames instead of cutting at 3 chars
box (tuple, list,
ndarray) – periodic unit cell written as aCRYST1record – three lengths(a, b, c)in Angstrom, six values(a, b, c, alpha, beta, gamma)with angles in degrees, or a 3x3 array of box vectors whose rows are a, b, c. Default None writes noCRYST1.atoms – an object with atom and coordinate data
csets – coordinate set indices, default is all coordinate sets
beta – a list or array of number to be outputted in beta column
occupancy – a list or array of number to be outputted in occupancy column
hybrid36 (bool) – whether to use hybrid36 format for atoms with serial greater than 99999. Hexadecimal is used otherwise. Default is False
autoext – when not present, append extension
.pdbto filename
- prody.proteins.pdbfile.writePDBStream(stream, atoms, csets=None, **kwargs)[source]
Write atoms in PDB format to a stream.
- Parameters:
stream – anything that implements a
write()method (e.g. file, buffer, stdout)renumber (bool) – whether to renumber atoms with serial indices Default is True
hybrid36 (bool) – whether to use hybrid36 format for atom residue numbers Default is False, which means using hexadecimal instead. NB: ChimeraX seems to prefer hybrid36 and may have problems with hexadecimal.
full_ter (bool) – whether to write full TER lines with atoms info Default is True
increment_ter (bool) – whether to increment serials with TER lines Default is True
write_remarks (bool) – whether to write REMARK lines Default is True
box (tuple, list,
ndarray) – periodic unit cell to write as aCRYST1record. Accepts three lengths(a, b, c)in Angstrom (angles then default to 90), six values(a, b, c, alpha, beta, gamma)with angles in degrees, or a 3x3 array of box VECTORS in Angstrom (rows are a, b, c), from which lengths and angles are computed. Default is None, which writes noCRYST1.atoms – an object with atom and coordinate data
csets – coordinate set indices, default is all coordinate sets
beta – a list or array of number to be outputted in beta column
occupancy – a list or array of number to be outputted in occupancy column
hybrid36 – whether to use hybrid36 format for atoms with serial greater than 99999. Hexadecimal is used otherwise. Default is False