mdtraj.formats.PDBTrajectoryFile

class mdtraj.formats.PDBTrajectoryFile(filename, mode='r', force_overwrite=True, standard_names=True)

Interface for reading and writing Protein Data Bank (PDB) files

Parameters
filenamestr

The filename to open. A path to a file on disk.

mode{‘r’, ‘w’}

The mode in which to open the file, either ‘r’ for read or ‘w’ for write.

force_overwritebool

If opened in write mode, and a file by the name of filename already exists on disk, should we overwrite it?

standard_namesbool, default=True

If True, non-standard atomnames and residuenames are standardized to conform with the current PDB format version. If set to false, this step is skipped.

See also

mdtraj.load_pdb

High-level wrapper that returns a md.Trajectory

Notes

When writing pdb files, mdtraj follows the PDB3.0 standard as closely as possible. During reading however, we try to be more lenient. For instance, we will parse common nonstandard atom names during reading, and convert them into the standard names. The replacement table used by mdtraj is at {mdtraj_source}/formats/pdb/data/pdbNames.xml.

Attributes
positionsnp.ndarray, shape=(n_frames, n_atoms, 3)

The cartesian coordinates of all of the atoms in each frame.

topologymdtraj.Topology

The topology from this PDB file.

closedbool

Whether the file is closed

Methods

close(self)

Close the PDB file

set_chain_names(values)

Set the cycle of chain names used when writing PDB files

write(self, positions, topology[, …])

Write a PDB file to disk

__init__(self, filename, mode='r', force_overwrite=True, standard_names=True)

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(self, filename[, mode, …])

Initialize self.

close(self)

Close the PDB file

set_chain_names(values)

Set the cycle of chain names used when writing PDB files

write(self, positions, topology[, …])

Write a PDB file to disk

Attributes

closed

Whether the file is closed

distance_unit

positions

The cartesian coordinates of all of the atoms in each frame.

topology

The topology from this PDB file.

unitcell_angles

The unitcell angles (3-tuple) in this PDB file.

unitcell_lengths

The unitcell lengths (3-tuple) in this PDB file.

close(self)

Close the PDB file

property closed

Whether the file is closed

property positions

The cartesian coordinates of all of the atoms in each frame. Available when a file is opened in mode=’r’

classmethod set_chain_names(values)

Set the cycle of chain names used when writing PDB files

When writing PDB files, PDBTrajectoryFile translates each chain’s index into a name – the name is what’s written in the file. By default, chains are named with the letters A-Z.

Parameters
valueslist

A list of chacters (strings of length 1) that the PDB writer will cycle through to choose chain names.

property topology

The topology from this PDB file. Available when a file is opened in mode=’r’

property unitcell_angles

The unitcell angles (3-tuple) in this PDB file. May be None

property unitcell_lengths

The unitcell lengths (3-tuple) in this PDB file. May be None

write(self, positions, topology, modelIndex=None, unitcell_lengths=None, unitcell_angles=None, bfactors=None)

Write a PDB file to disk

Parameters
positionsarray_like

The list of atomic positions to write.

topologymdtraj.Topology

The Topology defining the model to write.

modelIndex{int, None}

If not None, the model will be surrounded by MODEL/ENDMDL records with this index

unitcell_lengths{tuple, None}

Lengths of the three unit cell vectors, or None for a non-periodic system

unitcell_angles{tuple, None}

Angles between the three unit cell vectors, or None for a non-periodic system

bfactorsarray_like, default=None, shape=(n_atoms,)

Save bfactors with pdb file. Should contain a single number for each atom in the topology