mdtop
#
Store topological information about a system to simulate.
Modules:
-
tests
–
Classes:
-
Atom
–Represents atoms and virtual sites stored in a topology.
-
Bond
–Represents a bond between two atoms.
-
Chain
–Represents chains stored in a topology.
-
Residue
–Represents residues stored in a topology.
-
Topology
–Represents topological information about a system.
Functions:
-
box_from_geometry
–Convert box geometry parameters to a box.
-
box_to_geometry
–Convert a box to its geometry parameters.
Attributes:
-
AMINO_ACID_NAMES
(frozenset[str]
) –Common natural amino acid residue names.
-
ION_RES_NAMES
(frozenset[str]
) –Residue names for common ions.
-
WATER_RES_NAMES
(frozenset[str]
) –Common water residue names.
AMINO_ACID_NAMES
module-attribute
#
AMINO_ACID_NAMES: frozenset[str] = frozenset(
[
"ACE",
"NME",
"NMA",
"ALA",
"CYS",
"ASP",
"GLU",
"PHE",
"GLY",
"HIS",
"ILE",
"LYS",
"LEU",
"MET",
"ASN",
"PRO",
"GLN",
"ARG",
"SER",
"THR",
"VAL",
"TRP",
"TYR",
"CYD",
"CYZ",
"HID",
"HIE",
"HIP",
]
)
Common natural amino acid residue names.
ION_RES_NAMES
module-attribute
#
ION_RES_NAMES: frozenset[str] = frozenset(
[
"NA+",
"NA",
"K+",
"K",
"LI+",
"LI",
"CL-",
"CL",
"BR-",
"BR",
"I-",
"I",
"F-",
"F",
"MG+2",
"MG",
"CA+2",
"CA",
"ZN+2",
"ZN",
"FE+3",
"FE+2",
"FE",
]
)
Residue names for common ions.
WATER_RES_NAMES
module-attribute
#
Common water residue names.
Atom
#
Represents atoms and virtual sites stored in a topology.
Attributes:
-
name
(str
) –The name of the atom.
-
atomic_num
(int
) –The atomic number, or 0 if this is a virtual site.
-
formal_charge
(int | None
) –The formal charge on the atom.
-
serial
(int
) –The index of this atom in its original source (e.g. the serial defined
-
meta
(dict[str, str | float | int | bool]
) –Extra metadata associated with the atom.
-
symbol
(str
) –The chemical symbol of the atom, or 'X' if this is a virtual site.
-
residue
(Optional[Residue]
) –The residue that the atom belongs to.
-
chain
(Optional[Chain]
) –The chain that the atom belongs to.
-
index
(int | None
) –The index of the atom in the parent topology
Source code in mdtop/_top.py
atomic_num
instance-attribute
#
atomic_num: int = atomic_num
The atomic number, or 0 if this is a virtual site.
formal_charge
instance-attribute
#
formal_charge: int | None = formal_charge
The formal charge on the atom.
serial
instance-attribute
#
serial: int = serial
The index of this atom in its original source (e.g. the serial defined in a PDB). This may not be zero-index or contiguous.
meta
instance-attribute
#
Extra metadata associated with the atom.
Bond
#
Chain
#
Represents chains stored in a topology.
Attributes:
-
id
–The ID of the chain.
-
topology
(Optional[Topology]
) –The topology the chain belongs to (if any).
-
residues
(tuple[Residue, ...]
) –The residues associated with the chain.
-
n_residues
(int
) –The number of chains in the chain.
-
atoms
(tuple[Atom, ...]
) –The atoms associated with the chain.
-
n_atoms
(int
) –The number of atoms in the chain.
-
index
(int | None
) –The index of the chain in the parent topology
Source code in mdtop/_top.py
Residue
#
Represents residues stored in a topology.
Attributes:
-
name
–The name of the residue.
-
seq_num
–The sequence number of the residue.
-
insertion_code
–The insertion code of the residue.
-
chain
(Optional[Chain]
) –The chain the residue belongs to (if any).
-
topology
(Optional[Topology]
) –The topology the residue belongs to (if any).
-
atoms
(tuple[Atom, ...]
) –The atoms associated with the residue.
-
n_atoms
(int
) –The number of atoms in the residue.
-
index
(int | None
) –The index of the residue in the parent topology
Source code in mdtop/_top.py
insertion_code
instance-attribute
#
insertion_code = insertion_code
The insertion code of the residue.
Topology
#
Represents topological information about a system.
Methods:
-
add_chain
–Add a new chain to the topology.
-
add_residue
–Add a new residue to the topology.
-
add_atom
–Add a new atom to the topology.
-
add_bond
–Add a new bond to the topology.
-
from_openmm
–Create a topology from an OpenMM topology.
-
to_openmm
–Convert the topology to an OpenMM topology.
-
from_rdkit
–Create a topology from an RDKit molecule.
-
to_rdkit
–Convert the Topology to an RDKit Mol object.
-
from_openeye
–Create a topology from an OpenEye molecule.
-
to_openeye
–Convert the Topology to an OpenEye molecule object.
-
from_file
–Load the topology from a file.
-
to_file
–Write the topology to a file.
-
select
–Select atoms from the topology using a selection expression.
-
subset
–Create a subset of the topology.
-
split
–Split the topology into multiple topologies, such that bound atoms are
-
merge
–Merge multiple topologies.
Attributes:
-
meta
(dict[str, str | float | int | bool]
) –Extra metadata associated with the atom.
-
chains
(tuple[Chain, ...]
) –The chains associated with the topology.
-
n_chains
(int
) –The number of chains in the topology.
-
residues
(tuple[Residue, ...]
) –The residues associated with the topology.
-
n_residues
(int
) –The number of residues in the topology.
-
atoms
(tuple[Atom, ...]
) –The atoms associated with the topology.
-
n_atoms
(int
) –The number of atoms in the topology.
-
bonds
(tuple[Bond, ...]
) –The bonds associated with the topology.
-
n_bonds
(int
) –The number of bonds in the topology.
-
xyz
(Quantity | None
) –The coordinates of the atoms in the topology.
-
box
(Quantity | None
) –The box vectors of the simulation box.
Source code in mdtop/_top.py
meta
instance-attribute
#
Extra metadata associated with the atom.
add_chain
#
add_chain(id_: str) -> Chain
Add a new chain to the topology.
Parameters:
-
id_
(str
) –The ID of the chain to add.
Returns:
-
Chain
–The newly created chain.
Source code in mdtop/_top.py
add_residue
#
Add a new residue to the topology.
Parameters:
-
name
(str
) –The name of the residue to add
-
seq_num
(int | None
) –The sequence number of the residue. If
None
, the index in the topology will be used. -
insertion_code
(str
) –The insertion code of the residue.
-
chain
(Chain
) –The parent chain to add to.
Returns:
-
Residue
–The newly created residue.
Source code in mdtop/_top.py
add_atom
#
add_atom(
name: str,
atomic_num: int,
formal_charge: int | None,
serial: int | None,
residue: Residue,
) -> Atom
Add a new atom to the topology.
Parameters:
-
name
(str
) –The name of the atom to add
-
atomic_num
(int
) –The atomic number of the atom to add, or 0 for virtual sites.
-
formal_charge
(int | None
) –The formal charge on the atom (if defined).
-
serial
(int | None
) –The index of this atom in its original source (e.g. the serial defined in a PDB), which may not be zero-index or contiguous. If
None
, the index in the topology will be used. -
residue
(Residue
) –The parent residue to add to.
Returns:
-
Atom
–The newly created atom
Source code in mdtop/_top.py
add_bond
#
add_bond(idx_1: int, idx_2: int, order: int | None) -> Bond
Add a new bond to the topology.
Parameters:
-
idx_1
(int
) –The index of the first atom.
-
idx_2
(int
) –The index of the second atom.
-
order
(int | None
) –The formal bond order (if defined).
Returns:
-
Bond
–The newly created bond.
Source code in mdtop/_top.py
from_openmm
classmethod
#
from_openmm(topology_omm: Topology) -> Topology
Create a topology from an OpenMM topology.
Parameters:
-
topology_omm
(Topology
) –The OpenMM topology to convert.
Returns:
-
Topology
–The converted topology.
Source code in mdtop/_top.py
to_openmm
#
Convert the topology to an OpenMM topology.
Returns:
-
Topology
–The OpenMM topology.
from_rdkit
classmethod
#
from_rdkit(
mol: Mol, residue_name: str = "LIG", chain: str = ""
) -> Topology
Create a topology from an RDKit molecule.
Parameters:
-
mol
(Mol
) –The RDKit molecule to convert.
-
residue_name
(str
, default:'LIG'
) –The residue name to use for the ligand.
-
chain
(str
, default:''
) –The chain ID to use for the ligand.
Returns:
-
Topology
–The converted topology.
Source code in mdtop/_top.py
to_rdkit
#
Convert the Topology to an RDKit Mol object.
Notes
- Currently this requires formal charges to be set on the atoms, and formal bond orders to be set on the bonds.
Returns:
-
Mol
–The RDKit Mol object.
Source code in mdtop/_top.py
from_openeye
classmethod
#
from_openeye(mol: OEMol) -> Topology
Create a topology from an OpenEye molecule.
Parameters:
-
mol
(OEMol
) –The RDKit molecule to convert.
Returns:
-
Topology
–The converted topology.
Source code in mdtop/_top.py
to_openeye
#
Convert the Topology to an OpenEye molecule object.
Notes
- Currently this requires formal charges to be set on the atoms, and formal bond orders to be set on the bonds.
Returns:
-
OEMol
–The OpenEye molecule.
Source code in mdtop/_top.py
_from_pdb
classmethod
#
_from_pdb(path: Path) -> Topology
Load the topology from a PDB file.
Source code in mdtop/_top.py
from_file
classmethod
#
from_file(path: Path | str) -> Topology
Load the topology from a file.
Notes
- Currently PDB, SDF, and MOL2 files are supported.
Parameters:
-
path
(Path | str
) –The path to the file to load.
Returns:
-
Topology
–The loaded topology.
Source code in mdtop/_top.py
to_file
#
Write the topology to a file.
Notes
- Currently PDB, MOL, and SDF files are supported.
- SDF / MOL writing requires that all atoms have formal charges set, and all bonds have formal bond orders set, as reading and writing is via RDKit.
- Not all metadata will be preserved when writing to files, including residue and chain information.
Parameters:
-
path
(Path | str
) –The path to write the topology to.
Source code in mdtop/_top.py
select
#
Select atoms from the topology using a selection expression.
The selection expression should be expressed in terms of the PyMol selection language. For example, to select all atoms in chain A:
or all atoms within 5 Å of the ligand:
Notes
An Amber-style selection mask can also be used, but this is deprecated and will be removed in a future version.
Parameters:
-
expr
(str
) –The selection expression.
Source code in mdtop/_top.py
subset
#
subset(idxs: Iterable[int]) -> Topology
Create a subset of the topology.
Parameters:
-
idxs
(Iterable[int]
) –The indices of the atoms to include in the subset. Note the order of the atoms in the subset will be the same as in the original topology, regardless of the order of the indices.
Returns:
-
Topology
–The subset of the topology.
Source code in mdtop/_top.py
split
#
split() -> list[Topology]
Split the topology into multiple topologies, such that bound atoms are in the same topology.
This is useful, for example, when your topology contains multiple ligands, and you want to split them into separate topologies.
Returns:
-
list[Topology]
–An list of the split topologies.
Source code in mdtop/_top.py
merge
classmethod
#
Merge multiple topologies.
Notes
- The box vectors of the first topology will be used.
- Topologies without coordinates will be treated as if they have all zero coordinates.
Parameters:
-
topologies
(Topology
, default:()
) –The topologies to merge together.
Returns:
-
Topology
–The merged topology.
Source code in mdtop/_top.py
box_from_geometry
#
box_from_geometry(
a: float,
b: float,
c: float,
alpha: float,
beta: float,
gamma: float,
) -> Quantity
Convert box geometry parameters to a box.
Parameters:
-
a
(float
) –The length [Å] of the first box vector.
-
b
(float
) –The length [Å] of the second box vector.
-
c
(float
) –The length [Å] of the third box vector.
-
alpha
(float
) –The angle [deg] between the second and third box vectors.
-
beta
(float
) –The angle [deg] between the third and first box vectors.
-
gamma
(float
) –The angle [deg] between the first and second box vectors.
Returns:
-
Quantity
–The box vectors with
shape=(3, 3)
.
Source code in mdtop/_utils.py
box_to_geometry
#
Convert a box to its geometry parameters.
Parameters:
-
box
(Quantity
) –The box vectors with
shape=(3, 3)
.
Returns:
-
tuple[float, float, float, float, float, float]
–The box lengths and angles in the order
(a, b, c, alpha, beta, gamma)
, where all lengths are in angstroms and all angles are in degrees.