Get missing bonds#

Getting the missing bonds.

A molecular system can have missing bonds. The function molsysmt.build.get_missing_bonds() can detect this lack of bonds returning the pairs of atoms that should be covalently bonded.

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.get_missing_bonds().

Let’s see this function in action: We begin by converting the structure into a standard MolSysMT object.

import molsysmt as msm
#molsys = msm.convert(msm.systems['nglview']['md_1u19.pdb'],
#                     to_form='molsysmt.MolSys')

molsys = msm.build.build_peptide('AceAlaNme')
msm.get(molsys, element='bond', selection=[0,1,2], bonded_atoms=True)
[[0, 1], [1, 2], [1, 3]]
msm.info(molsys, element='atom')
index id name type group index group id group name group type component index chain index molecule index molecule type entity index entity name
0 1 H1 H 0 1 ACE terminal capping 0 0 0 peptide 0 peptide 0
1 2 CH3 C 0 1 ACE terminal capping 0 0 0 peptide 0 peptide 0
2 3 H2 H 0 1 ACE terminal capping 0 0 0 peptide 0 peptide 0
3 4 H3 H 0 1 ACE terminal capping 0 0 0 peptide 0 peptide 0
4 5 C C 0 1 ACE terminal capping 0 0 0 peptide 0 peptide 0
5 6 O O 0 1 ACE terminal capping 0 0 0 peptide 0 peptide 0
6 7 N N 1 2 ALA amino acid 0 0 0 peptide 0 peptide 0
7 8 H H 1 2 ALA amino acid 0 0 0 peptide 0 peptide 0
8 9 CA C 1 2 ALA amino acid 0 0 0 peptide 0 peptide 0
9 10 HA H 1 2 ALA amino acid 0 0 0 peptide 0 peptide 0
10 11 CB C 1 2 ALA amino acid 0 0 0 peptide 0 peptide 0
11 12 HB1 H 1 2 ALA amino acid 0 0 0 peptide 0 peptide 0
12 13 HB2 H 1 2 ALA amino acid 0 0 0 peptide 0 peptide 0
13 14 HB3 H 1 2 ALA amino acid 0 0 0 peptide 0 peptide 0
14 15 C C 1 2 ALA amino acid 0 0 0 peptide 0 peptide 0
15 16 O O 1 2 ALA amino acid 0 0 0 peptide 0 peptide 0
16 17 N N 2 3 NME terminal capping 0 0 0 peptide 0 peptide 0
17 18 H H 2 3 NME terminal capping 0 0 0 peptide 0 peptide 0
18 19 C C 2 3 NME terminal capping 0 0 0 peptide 0 peptide 0
19 20 H1 H 2 3 NME terminal capping 0 0 0 peptide 0 peptide 0
20 21 H2 H 2 3 NME terminal capping 0 0 0 peptide 0 peptide 0
21 22 H3 H 2 3 NME terminal capping 0 0 0 peptide 0 peptide 0
msm.build.remove_bonds(molsys, bond_indices=[0])
molsys.topology.groups
group_id group_name group_type component_index
0 1 ACE terminal capping 0
1 2 ALA amino acid 0
2 3 NME terminal capping 0
msm.info(molsys, element='atom')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[7], line 1
----> 1 msm.info(molsys, element='atom')

File ~/repos@uibcdf/molsysmt/molsysmt/_private/digestion/digest.py:122, in digest.<locals>.digestor.<locals>.wrapper(*args, **kwargs)
    120     return func(all_args['self'], **final_args)
    121 else:
--> 122     return func(**final_args)

File ~/repos@uibcdf/molsysmt/molsysmt/basic/info.py:112, in info(molecular_system, element, selection, syntax)
    103     molecular_system = [molecular_system]
    105 if element == 'atom':
    107     atom_index, atom_id, atom_name, atom_type, \
    108     group_index, group_id, group_name, group_type, \
    109     component_index, \
    110     chain_index, \
    111     molecule_index, molecule_type, \
--> 112     entity_index, entity_name = get(molecular_system, element=element, selection=selection,
    113                                     syntax=syntax, skip_digestion=True, atom_index=True, atom_id=True,
    114                                     atom_name=True, atom_type=True, group_index=True, group_id=True,
    115                                     group_name=True, group_type=True, component_index=True,
    116                                     chain_index=True, molecule_index=True, molecule_type=True,
    117                                     entity_index=True, entity_name=True,
    118                                     )
    120     if not attributes_filter['atom_index']: atom_index=None
    121     if not attributes_filter['atom_id']: atom_id=None

File ~/repos@uibcdf/molsysmt/molsysmt/_private/digestion/digest.py:52, in digest.<locals>.digestor.<locals>.wrapper(*args, **kwargs)
     48 @functools.wraps(func)
     49 def wrapper(*args, **kwargs):
     51     if kwargs.get('skip_digestion', False):
---> 52         return func(*args, **kwargs)
     54     # Define caller
     56     caller = func.__module__+'.'+func.__name__

File ~/repos@uibcdf/molsysmt/molsysmt/basic/get.py:210, in get(molecular_system, element, selection, structure_indices, mask, syntax, get_missing_bonds, output_type, skip_digestion, **kwargs)
    208     else:
    209         aux_get = getattr(_dict_modules[aux_form], f'get_{in_attribute}_from_{element}')
--> 210         result = aux_get(aux_item, **dict_indices)
    212 else:
    214     result = None

File ~/repos@uibcdf/molsysmt/molsysmt/_private/digestion/digest.py:122, in digest.<locals>.digestor.<locals>.wrapper(*args, **kwargs)
    120     return func(all_args['self'], **final_args)
    121 else:
--> 122     return func(**final_args)

File ~/repos@uibcdf/molsysmt/molsysmt/form/molsysmt_MolSys/get_topological_attributes.py:123, in get_molecule_type_from_atom(item, indices, skip_digestion)
    119 @digest(form=form)
    120 def get_molecule_type_from_atom(item, indices='all', skip_digestion=False):
    122     from ..molsysmt_Topology import get_molecule_type_from_atom as aux_get
--> 123     return aux_get(item.topology, indices=indices, skip_digestion=True)

File ~/repos@uibcdf/molsysmt/molsysmt/_private/digestion/digest.py:52, in digest.<locals>.digestor.<locals>.wrapper(*args, **kwargs)
     48 @functools.wraps(func)
     49 def wrapper(*args, **kwargs):
     51     if kwargs.get('skip_digestion', False):
---> 52         return func(*args, **kwargs)
     54     # Define caller
     56     caller = func.__module__+'.'+func.__name__

File ~/repos@uibcdf/molsysmt/molsysmt/form/molsysmt_Topology/get_topological_attributes.py:205, in get_molecule_type_from_atom(item, indices, skip_digestion)
    201 @digest(form=form)
    202 def get_molecule_type_from_atom(item, indices='all', skip_digestion=False):
    204     aux_indices = get_molecule_index_from_atom(item, indices=indices, skip_digestion=True)
--> 205     aux_unique_indices, aux_new_indices = np.unique(aux_indices, return_inverse=True)
    206     aux_vals = get_molecule_type_from_molecule(item, indices=aux_unique_indices, skip_digestion=True)
    207     output = np.array(aux_vals)[aux_new_indices]

File /conda/miniconda3/envs/MolSysMT@uibcdf_3.12/lib/python3.12/site-packages/numpy/lib/arraysetops.py:274, in unique(ar, return_index, return_inverse, return_counts, axis, equal_nan)
    272 ar = np.asanyarray(ar)
    273 if axis is None:
--> 274     ret = _unique1d(ar, return_index, return_inverse, return_counts, 
    275                     equal_nan=equal_nan)
    276     return _unpack_tuple(ret)
    278 # axis was specified and not None

File /conda/miniconda3/envs/MolSysMT@uibcdf_3.12/lib/python3.12/site-packages/numpy/lib/arraysetops.py:333, in _unique1d(ar, return_index, return_inverse, return_counts, equal_nan)
    330 optional_indices = return_index or return_inverse
    332 if optional_indices:
--> 333     perm = ar.argsort(kind='mergesort' if return_index else 'quicksort')
    334     aux = ar[perm]
    335 else:

File missing.pyx:392, in pandas._libs.missing.NAType.__bool__()

TypeError: boolean value of NA is ambiguous
msm.element.component.get_component_index(molsys, redefine_indices=True)
msm.build.get_missing_bonds(molsys)
msm.info(molsys, element='atom')