moleculekit.distance module#

moleculekit.distance.calculate_contacts(mol, sel1, sel2, periodic, threshold=4)#
moleculekit.distance.cdist(coords1, coords2)#
moleculekit.distance.find_clashes(mol, sel1=None, sel2=None, overlap=0.6, exclude_bonded=True, exclude_14=True, guess_bonds=True)#

Find pairs of atoms that sterically clash with each other.

A clash is defined as a pair of atoms whose interatomic distance is less than r_vdw_1 + r_vdw_2 - overlap where VdW radii come from moleculekit.periodictable. Uses the bundled cKDTree (ported from SciPy) for fast neighbor lookup.

Parameters:
  • mol (Molecule) – The molecule to analyze.

  • sel1 (str, ndarray of bool, or None, optional) – First selection. If None, all atoms are used.

  • sel2 (str, ndarray of bool, or None, optional) – Second selection. If None, uses sel1 (self-clashes).

  • overlap (float, optional) – How much VdW overlap is tolerated before flagging as a clash, in Angstroms. Default 0.6 – i.e. atoms clash when they overlap by more than 0.6 Å of their combined VdW radii. Set to 0 for strict contact (any overlap counts), or negative for looser definitions.

  • exclude_bonded (bool, optional) – If True, 1-2 (directly bonded) and 1-3 (angle) neighbors are excluded from the clash search. Default True.

  • exclude_14 (bool, optional) – If True, 1-4 (dihedral) neighbors are also excluded. Default True.

  • guess_bonds (bool, optional) – If True, supplements mol.bonds with moleculekit’s distance/covalent-radius based bond guesser. This catches inter-residue peptide bonds, disulfides, etc. that are often absent from mol.bonds on PDB-loaded structures. Set to False if mol.bonds is already complete (e.g. for systems built from a topology file) to skip the guessing overhead and avoid false positives from overlapping atoms. Default True.

Returns:

  • clashes (ndarray of shape (N, 2), dtype int) – Pairs of atom indices that clash. Pairs are ordered so the first index is always < the second. Empty array if no clashes.

  • distances (ndarray of shape (N,), dtype float32) – Distance (Å) for each clash pair.

  • overlaps (ndarray of shape (N,), dtype float32) – Overlap amount (r_vdw_1 + r_vdw_2) - distance for each pair. Pairs are returned sorted by overlap (most severe first).

Examples

>>> mol = Molecule("3ptb")
>>> clashes, distances, overlaps = find_clashes(mol)
>>> for (a, b), d, o in zip(clashes, distances, overlaps):
...     print(f"{mol.name[a]}({a}) <-> {mol.name[b]}({b}): "
...           f"d={d:.2f} overlap={o:.2f}")
moleculekit.distance.pdist(coords)#
moleculekit.distance.squareform(distances)#