moleculekit.bondguesser module#
- moleculekit.bondguesser.bond_grid_search(coords: ndarray, grid_cutoff: float, is_hydrogen: ndarray, radii: ndarray, max_boxes: float = 4000000.0, cutoff_incr: float = 1.26) ndarray#
Find bonded atom pairs using a uniform spatial grid.
Atoms are binned into cubic grid boxes of side grid_cutoff and only atoms in neighboring boxes are tested for bonding, giving an efficient neighbor search. If the grid would contain more than max_boxes boxes (e.g. for an unwrapped trajectory spanning a large volume) the box size is enlarged by repeatedly multiplying it by cutoff_incr until the box count is acceptable.
- Parameters:
coords (numpy.ndarray) – A 2D array of shape (N, 3) with the atom coordinates. Must be finite.
grid_cutoff (float) – The initial grid box side length in Angstrom (typically a small multiple of the largest Van der Waals radius). Must be positive and finite.
is_hydrogen (numpy.ndarray) – A 1D array of length N flagging which atoms are hydrogens (non-zero where the atom is a hydrogen).
radii (numpy.ndarray) – A 1D array of length N with the per-atom Van der Waals radii in Angstrom.
max_boxes (float) – The maximum number of grid boxes allowed before the box size is increased.
cutoff_incr (float) – The factor by which the box size is multiplied each time the box count exceeds max_boxes.
- Returns:
bonds – A 2D array of shape (N, 2) and dtype uint32 with the bonded atom-index pairs. Empty if no bonds are found.
- Return type:
numpy.ndarray
- Raises:
ValueError – If coords contains non-finite values, or if grid_cutoff is not positive and finite.
- moleculekit.bondguesser.guess_bonds(mol: Molecule) ndarray#
Guess the bonds of a molecule from interatomic distances and VdW radii.
Two atoms are considered bonded when their distance is below a fraction of the sum of their Van der Waals radii. A uniform grid (see
bond_grid_search()) is used for efficient neighbor lookup. Only the coordinates of the currentmol.frameare used.- Parameters:
mol (
Moleculeobject) – The Molecule whose bonds should be guessed.- Returns:
bonds – A 2D array of shape (N, 2) and dtype uint32 with the atom-index pairs of the guessed bonds. Empty if the molecule has one atom or fewer.
- Return type:
numpy.ndarray
- Raises:
RuntimeError – If
mol.frameis out of range of the available coordinate frames.
- moleculekit.bondguesser.guess_bonds_rdkit(mol: Molecule) tuple[list, list]#
Guess the bonds and bond orders of a molecule using RDKit.
The molecule is written to a temporary PDB file and parsed by RDKit, whose perceived bonds and bond orders are then mapped back onto the molecule’s atom indices.
- Parameters:
mol (
Moleculeobject) – The Molecule whose bonds should be guessed.- Returns:
bonds (list) – A list of
[i, j]atom-index pairs (each pair sorted ascending) for the guessed bonds. Empty if the molecule has one atom or fewer.bondtypes (list) – A list of bond-order strings parallel to bonds, where
"1","2","3"and"ar"denote single, double, triple and aromatic bonds.