mdciao.utils.bonds
Simple operations with bonds between the
residues of an mdtraj.Topology
Functions
|
Bonded neighbors of all the residues in the topology file. |
|
Return the connected components/sets of a an adjacency matrix |
Return neighborlists from an adjacency matrix. |
|
|
Return a symmetric residue-residue bond matrix from a |
|
Creates a naive (=linear) residue-residue bond-matrix, where a bond is assumed between the n-th and the n+1-th residue |
|
- mdciao.utils.bonds.bonded_neighborlist_from_top(top, n=1, residue_indices=None, 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] ifn
= 2residue_indices (iterable, default is None) – Compute the neighborlists only for these indices. None computes neighbors all indices. The returned neighborlist will have empty-lists for items not present in residue_indices.
- 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, indices=None)
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. The special case of n=0 returns no neighbors (not even the index with itself)
indices (iterable, default is None) – Compute the neighborlists only for these indices. None computes neighbors all indices. The returned neighborlist will have empty-lists for items not present in indices.
- 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. For items not present in indices, empty lists will be returned.- 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 theonly_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