mdciao.utils.bonds

Simple operations with bonds between the residues of an mdtraj.Topology

Functions

bonded_neighborlist_from_top(top[, n, verbose])

Bonded neighbors of all the residues in the topology file.

connected_sets(mat)

Return the connected components/sets of a an adjacency matrix

neighborlists_from_adjacency_matrix(mat, n)

Return neighborlists from an adjacency matrix.

top2residue_bond_matrix(top[, …])

Return a symmetric residue-residue bond matrix from a Topology.

top2residue_bond_matrix_naive(top[, …])

Creates a naive (=linear) residue-residue bond-matrix, where a bond is assumed between the n-th and the n+1-th residue

top2residuebonds(top, …)

mdciao.utils.bonds.bonded_neighborlist_from_top(top, n=1, verbose=False)

Bonded neighbors of all the residues in the topology file.

Parameters
  • top (Topology) –

  • n (int, default is 1) – Number of bonded neighbors considered, i.e. A-B-C has only [B] as neighbors if n = 1, but [B,C] if n = 2

Returns

neighbor_list – Lisf of len top.n_residues. The i-th list contains the n -bonded neighbors of the i-th residue, in ascending order

Return type

list of lists

mdciao.utils.bonds.connected_sets(mat)

Return the connected components/sets of a an adjacency matrix

Uses connected_components under the hood with directed=False

Parameters

mat (2D _np.array, square matrix (M,M)) – Adjacency matrix, can be symmetric or not. Nodes are always self-adjacent, i.e. the diagonal of mat is ignored

Returns

sets – The connected components as 1D _np.ndarrays

Return type

list

mdciao.utils.bonds.neighborlists_from_adjacency_matrix(mat, n)

Return neighborlists from an adjacency matrix.

The diagonal of mat is ignored, i.e. it can be 0 or 1

Parameters
  • mat (2D _np.array, square matrix (M,M)) – Adjacency matrix, can be symmetric or not

  • n (int) – Connectedness.

Returns

neighbors – A list of len M where the i-th entry contains the indices of the nodes separated from the i-ith node by a maximum of n jumps. The indices are always in ascending order

Return type

list

mdciao.utils.bonds.top2residue_bond_matrix(top, force_resSeq_breaks=False, verbose=True, create_standard_bonds=False)

Return a symmetric residue-residue bond matrix from a Topology.

The bonds used are those found in bonds

Parameters
  • top (mdtraj.Topology) –

  • force_resSeq_breaks (boolean, default is False) – Delete bonds if there is a resSeq jump between residues.

  • verbose (boolean, default is True) – Print a statement if residue index has no bonds

  • create_standard_bonds (boolean, default is False) – Advanced users only, can easily lead to wrong results in case of .gro files, because create_standard_bonds needs chain information to avoid creating bonds between residues that follow one another

Returns

residue_bond_matrix – Returns a symmetric adjacency matrix with entries ij=1 and ji=1, if there is a bond between residue i and residue j.

Return type

2D np.ndarray

mdciao.utils.bonds.top2residue_bond_matrix_naive(top, only_protein=True, fragments=None)

Creates a naive (=linear) residue-residue bond-matrix, where a bond is assumed between the n-th and the n+1-th residue

Usually, one would resort to this method if the topology’s own create_standard_bonds() method does not work, e.g. because there’s only alpha Carbons

Parameters
  • top (Topology) –

  • only_protein (bool, default is True) – Only create bonds when both residues satisfy are protein residues. The check is done using the attribute mdtraj.core.topology.Residue.is_protein

  • fragments (iterable of ints, default is None) – Use fragment/chain definition to avoid bonds between fragments/chains. These definitions need to cover the entire Topology, i.e. each residue index must appear once (an and only once) in the :obj`fragments`. Note that breaks introduced via the only_protein argument will always be present, whether these residues are in the same fragment or not

Returns

mat – Symmetric residue-residue bond-matrix. The diagonal is filled with ones as well.

Return type

2D np.ndarray