topology
A module containing the Topology class and related functions.
Summary
Classes:
A class for representing a topology. |
Reference
- class Topology(
- atoms: Atoms | None = None,
- residue_ids: Np1DIntArray | None = None,
- reference_residues: Residues | None = None,
- check_residues: bool = True,
- bonded_topology: BondedTopology | None = None,
Bases:
object
A class for representing a topology.
A topology is a collection of atoms, residues and residue ids. It is used to represent the topology of a system.
Examples
>>> import numpy as np >>> import warnings >>> from PQAnalysis.topology import Topology >>> from PQAnalysis.core import Atom, Residue >>> atoms = [Atom("H", 1), Atom("O", 8), Atom("H", 1), Atom("H", 1)] >>> residue_ids = np.array([1, 1, 2, 2]) >>> residue1 = Residue("HO", 1, 0, ["H", "O"], np.array([1, 2]), np.array([0, 0])) >>> residue2 = Residue("H2", 2, 0, ["H", "H"], np.array([1, 2]), np.array([0, 0])) >>> residues = [residue1, residue2] >>> with warnings.catch_warnings(): ... warnings.simplefilter("ignore") ... topology = Topology(atoms=atoms, residue_ids=residue_ids, reference_residues=residues)
All of the parameters are optional, if they are not given, they are initialized with empty values. It checks if the residue ids are compatible and contiguous regarding the given residues if the list is not empty.
It is also possible to initialize a Topology object with residues that are not referenced within the residue_ids. This means that it is possible to have a Topology object with residues that are not used in the system.
- Parameters:
atoms (Atoms | None, optional) – a list of atoms, by default None (empty list)
residue_ids (Np1DIntArray | None, optional) – a list of residue ids, by default None (empty list)
reference_residues (Residues | None, optional) – a list of residues, by default None (empty list)
check_residues (bool, optional) – If the residues should be checked, by default True
bonded_topology (BondedTopology | None, optional) – Contains the bonded topology information, by default None
- Raises:
TopologyError – If the number of atoms does not match the number of residue ids.
- Warns:
UserWarning – If the bonded topology is not None. There is no check yet if the bonded topology is compatible with the topology. Please make sure that the bonded topology is compatible with the topology!
- __eq__(other: Any) bool [source]
Checks whether the Topology is equal to another Topology.
- Parameters:
other (Topology) – The other Topology to compare to.
- Returns:
Whether the Topology is equal to the other Topology.
- Return type:
bool
- __getitem__(
- indices: Np1DIntArray | int,
Returns a new Topology with the given indices.
- Parameters:
indices (Np1DIntArray | int) – The indices of the atoms to return.
- Returns:
The new Topology with the given indices.
- Return type:
- __repr__() str [source]
Returns a string representation of the Topology.
- Returns:
The string representation of the Topology.
- Return type:
str
- __str__() str [source]
Returns a string representation of the Topology.
- Returns:
The string representation of the Topology.
- Return type:
str
- get_atom_indices_from_residue_names(
- residue_name: str,
Returns the atom indices for the given residue name.
- Parameters:
residue_name (str) – The name of the residue to get the atom indices for.
- Returns:
The atom indices for the given residue name.
- Return type:
- get_atom_indices_from_residue_numbers(
- residue_numbers: Np1DIntArray,
Returns the atom indices for the given residue numbers.
- Parameters:
residue_numbers (Np1DIntArray) – The residue numbers to get the atom indices for.
- Returns:
The atom indices for the given residue numbers.
- Return type:
- setup_residues(
- residue_ids: Np1DIntArray,
A method to set up the residues of the topology.
- Parameters:
residue_ids (Np1DIntArray) – The residue ids of the topology.
- Raises:
ResidueError – If the residue ids are not contiguous.
ResidueError – If the reference residues are not empty and residue_ids with 0 don’t have any element information. This problem can be avoided by setting ‘check_residues’ to False.
- property atomtype_names: list[str]
The atomtype names of the topology.
- Type:
List[str]
- property check_residues: bool
Whether the residues should be checked.
- Type:
bool
- logger = <CustomLogger PQAnalysis.Topology (INFO)>
- property n_atoms: int
The number of atoms in the topology.
- Type:
int
- property n_atoms_per_residue: Np1DIntArray
The number of atoms per residue.
- Type:
- property n_mm_residues: int
The number of MM residues in the topology.
- Type:
int
- property n_qm_residues: int
The number of QM residues in the topology.
- Type:
int
- property n_residues: int
The number of residues in the topology.
- Type:
int
- property n_unique_residues: int
The number of unique residues in the topology.
- Type:
int
- property reference_residue_ids: Np1DIntArray
The residue ids of the reference residues.
- Type:
- property residue_atom_indices: list[Np1DIntArray]
The residue atom indices of the topology.
- Type:
List[Np1DIntArray]
- property residue_ids: Np1DIntArray
The residue ids of the topology.
- Type:
- property residue_ids_per_residue: Np1DIntArray
The residue ids per residue.
- Type:
List[Np1DIntArray]
- property residue_numbers: Np1DIntArray
The residue numbers of the topology.
- Type: