Add missing bonds#

Inferring and adding covalent bonds based on distances and atomic types.

This function allows you to automatically add covalent bonds to a molecular system. It infers the bonding pattern based on interatomic distances and standard valence rules for known elements. Useful for structures with missing or incomplete topology.

Added in version 1.0.0.

How this function works#

API documentation

Follow this link for a detailed description of the input arguments, raised errors, and returned objects of this function molsysmt.build.add_missing_bonds().

This function analyzes atomic positions and element types to determine which atom pairs are close enough to form covalent bonds, based on standard distance thresholds specific to each element. Only atoms within the same molecule or connected fragment are considered.

The inferred bonds are added to the bonded_atoms attribute of the molecular system. No bond orders or types are assigned — only covalent connectivity is inferred.

This method is especially useful when loading structures that contain atomic coordinates but lack full bonding information, such as .pdb, .xyz, or trajectory files.

We will use the alanine dipeptide demo system, which includes coordinates and topology. To simulate a scenario with missing bonds, we will first remove all existing bonds.

import molsysmt as msm
molsys = msm.systems['alanine dipeptide']['alanine_dipeptide.h5msm']
molsys = msm.convert(molsys)

To demonstrate molsysmt.build.add_missing_bonds(), start by saving apart the list of bonded_atom_pairs and removing all existing covalent bonds from the molecular system.

bonded_atom_pairs = msm.get(molsys, bonded_atom_pairs=True)
msm.build.remove_bonds(molsys)
msm.get(molsys, n_bonds=True)
0

We now call molsysmt.build.add_missing_bonds() to infer covalent bonds based on interatomic distances and chemical knowledge. This updates the bonded_atoms attribute.

msm.build.add_missing_bonds(molsys)

Finnally, we check the list of bonded atom pairs to confirm that bonding information was restored successfully.

msm.get(molsys, n_bonds=True)
21
new_bonded_atom_pairs = msm.get(molsys, bonded_atom_pairs=True)
new_bonded_atom_pairs == bonded_atom_pairs
True

See also

User guide > Tools > Build > Add bonds: Manually define new bonds between specific atom pairs.

User guide > Tools > Build > Remove bonds:
Remove selected covalent bonds from a molecular system.

User guide > Tools > Build > Add missing bonds:
Automatically identify and add missing covalent bonds based on distances and atomic types.

User guide > Tools > Basic > Convert: Convert between different molecular system formats.

User guide > Tools > Basic > Get: Access attribute values like bonded_atoms, atom_name, etc.