moleculekit.bondguesser module#

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 (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 (ndarray) – A 1D array of length N flagging which atoms are hydrogens (non-zero where the atom is a hydrogen).

  • radii (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:

ndarray

Raises:

ValueError – If coords contains non-finite values, or if grid_cutoff is not positive and finite.

moleculekit.bondguesser.guess_bonds(mol)#

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 current mol.frame are used.

Parameters:

mol (Molecule) – 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:

ndarray

Raises:

RuntimeError – If mol.frame is out of range of the available coordinate frames.

moleculekit.bondguesser.guess_bonds_rdkit(mol)#

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 (Molecule) – The Molecule whose bonds should be guessed.

Return type:

tuple[list, list]

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.