rdtools.dist#
A module contains functions to manipulate distances in a molecule.
- rdtools.dist.get_adjacency_matrix(mol: Mol) ndarray[tuple[int, ...], dtype[int64]] #
Get the adjacency matrix of the molecule.
- Parameters:
mol (Chem.Mol) – The molecule to get the adjacency matrix of.
- Returns:
npt.NDArray[np.int_] – A square adjacency matrix of the molecule, where a 1 indicates that atoms are bonded and a 0 indicates that atoms aren’t bonded.
- rdtools.dist.get_bond_distance_matrix(mol: Mol) ndarray[tuple[int, ...], dtype[float64]] #
Get the bond distance matrix of the molecule.
- Parameters:
mol (Chem.Mol) – The molecule to get the bond distance matrix of.
- Returns:
npt.NDArray[np.float64] – A square bond distance matrix of the molecule, where the value of each element is the bond distance between the atoms.
- rdtools.dist.get_colliding_atoms(mol: Mol, conf_id: int = -1, threshold: float = 0.4, reference: Literal['vdw', 'covalent', 'bond'] = 'vdw') list[tuple[int, int]] #
Get the atom pairs that are considered colliding.
The atoms are considered to be colliding if the distance between two atoms <= threshold * reference distance. The reference distance is based on the van der Waals radius, covalent radius or bond radius.
- Parameters:
mol (Chem.Mol) – The molecule to check for colliding atoms.
conf_id (int, optional) – The conformer ID of the molecule to get the distance matrix of. Defaults to
-1
.threshold (float, optional) – A multiplier applied on the reference matrix . Defaults to
0.4
.reference (Literal["vdw", "covalent", "bond"], optional) – The reference matrix to use. Defaults to
"vdw"
. Options: -"vdw"
for reference distance based on van de Waals radius -"covalent"
for reference distance based on covalent radius -"bond"
for reference distance based on bond radius
- Returns:
list[tuple[int, int]] – A list of tuples of the atom indices that are potentially colliding.
- rdtools.dist.get_covalent_distance_matrix(mol: Mol) ndarray[tuple[int, ...], dtype[float64]] #
Generate a covalent matrix of the molecule.
- Parameters:
mol (Chem.Mol) – The molecule to generate the derived covalent matrix of.
- Returns:
npt.NDArray[np.float64] – A square covalent matrix of the molecule, where the value of each element is the covalent radius of the atoms.
- rdtools.dist.get_distance_matrix(mol: Mol, conf_id: int = -1, balaban: bool = False) ndarray[tuple[int, ...], dtype[float64]] #
Get the distance matrix of the molecule.
- Parameters:
mol (Chem.Mol) – The molecule to get the distance matrix of.
conf_id (int, optional) – The conformer ID of the molecule to get the distance matrix of. Defaults to
-1
.balaban (bool, optional) – Whether to use the Balaban distance. Defaults to
False
. IfTrue
, the distance matrix will be calculated using the Balaban distance.
- Returns:
npt.NDArray[np.float64] – A square distance matrix of the molecule, where the value of each element is the distance between the atoms.
- rdtools.dist.get_missing_bonds(mol: Mol, conf_id: int = -1, threshold: float = 1.5, reference: Literal['vdw', 'covalent', 'bond'] = 'covalent') list[tuple[int, int]] #
Check whether the molecule has missing bonds heuristically.
If the distance between two atoms <= threshold * reference distance, the bond between the atoms are considered to be missing.
- Parameters:
mol (Chem.Mol) – The molecule to check for missing bonds.
conf_id (int, optional) – The conformer ID of the molecule to get the distance matrix of. Defaults to
-1
.threshold (float, optional) – A multiplier applied on the reference matrix . Defaults to
1.5
.reference (Literal["vdw", "covalent", "bond"], optional) – The reference matrix to use. Defaults to
"covalent"
. Options: -"vdw"
for reference distance based on van de Waals radius -"covalent"
for reference distance based on covalent radius -"bond"
for reference distance based on bond radius
- Returns:
list[tuple[int, int]] – A list of tuples of the atom indices that are potentially missing bonds.
- rdtools.dist.get_shortest_path(mol: Mol, idx1: int, idx2: int) tuple[int, ...] #
Get the shortest path between two atoms in a molecule.
The RDKit
GetShortestPath
has a very long setup time ~ 0.5ms (on test machine) regardless of the size of the molecule. As a comparison, on the same machine, a naive python implementation of DFS (_find_shortest_path) takes ~0.5 ms for a 100-C normal alkane end to end. Therefore, it make more sense to use a method with a shorter setup time though scaling worse for smaller molecules while using GetShortestPath for larger molecules.- Parameters:
mol (Chem.Mol) – The molecule to be checked.
idx1 (int) – The index of the first atom.
idx2 (int) – The index of the second atom.
- Returns:
tuple[int, …] – A list of atoms in the shortest path between the two atoms.
- rdtools.dist.get_vdw_distance_matrix(mol: Mol) ndarray[tuple[int, ...], dtype[float64]] #
Generate a van der Waals matrix of the molecule.
- Parameters:
mol (Chem.Mol) – The molecule to generate the derived van der Waals matrix of.
- Returns:
npt.NDArray[np.float64] – A square van der Waals matrix of the molecule, where the value of each element is the van der Waals radius of the atoms.
- rdtools.dist.has_colliding_atoms(mol: Mol, conf_id: int = -1, threshold: float = 0.4, reference: Literal['vdw', 'covalent', 'bond'] = 'vdw') bool #
Check whether the molecule has colliding atoms.
If the distance between two atoms <= threshold * reference distance, the atoms are considered to be colliding.
- Parameters:
mol (Chem.Mol) – The molecule to check for colliding atoms.
conf_id (int, optional) – The conformer ID of the molecule to get the distance matrix of. Defaults to
-1
.threshold (float, optional) – A multiplier applied on the reference matrix . Defaults to
0.4
.reference (Literal["vdw", "covalent", "bond"], optional) – The reference matrix to use. Defaults to
"vdw"
. Options: -"vdw"
for reference distance based on van de Waals radius -"covalent"
for reference distance based on covalent radius -"bond"
for reference distance based on bond radius
- Returns:
bool – Whether the molecule has colliding atoms.