Add bonds#
In this notebook, we will learn how to reconstruct covalent bonds in a molecular system, starting from a topology with no predefined bonds.
# Suppress warnings (optional)
import warnings
warnings.filterwarnings('ignore')
import molsysmt as msm
# Load the alanine dipeptide system from molsysmt's built-in systems
molsys = msm.systems['alanine dipeptide']['alanine_dipeptide.h5msm']
# Convert to standard MolSys format
molsys = msm.convert(molsys)
# Remove all covalent bonds from the system
msm.build.remove_bonds(molsys)
# Check that the number of bonds is now zero
msm.get(molsys, n_bonds=True)
# Add covalent bonds between specific atom pairs
msm.build.add_bonds(molsys, bonded_atom_pairs=[[0,1], [0,2], [1,4]])
# Confirm that the number of bonds is now 3
msm.get(molsys, n_bonds=True)
# Retrieve the bonded atom pairs
bonded_atom_pairs = msm.get(molsys, bonded_atom_pairs=True)
# Validate that the correct bonds were added
assert bonded_atom_pairs == [[0,1], [0,2], [1,4]]