opencadd.structure.core.Structure.add_bonds
- Structure.add_bonds(values, types=None, guessed=False, order=None)
Add new Bonds to this Universe.
- Parameters
values (iterable of tuples, AtomGroups, or Bonds; or TopologyGroup) – An iterable of: tuples of 2 atom indices, or AtomGroups with 2 atoms, or Bonds. If every value is a Bond, all keywords are ignored. If AtomGroups, Bonds, or a TopologyGroup are passed, they must be from the same Universe.
types (iterable (optional, default None)) – None, or an iterable of hashable values with the same length as
values
guessed (bool or iterable (optional, default False)) – bool, or an iterable of hashable values with the same length as
values
order (iterable (optional, default None)) – None, or an iterable of hashable values with the same length as
values
Example
Adding TIP4P water bonds with a list of AtomGroups:
import MDAnalysis as mda from MDAnalysis.tests.datafiles import GRO u = mda.Universe(GRO) sol = u.select_atoms('resname SOL') ow_hw1 = sol.select_atoms('name OW or name HW1').split('residue') ow_hw2 = sol.select_atoms('name OW or name HW2').split('residue') ow_mw = sol.select_atoms('name OW or name MW').split('residue') u.add_bonds(ow_hw1 + ow_hw2 + ow_mw)
You can only add bonds from the same Universe. If you would like to add AtomGroups, Bonds, or a TopologyGroup from a different Universe, convert them to indices first.
from MDAnalysis.tests.datafiles import PSF u2 = mda.Universe(PSF) # assuming you have already added bonds to u u2.add_bonds(u.bonds.to_indices())
New in version 1.0.0.