mdtraj.compute_contacts¶
- mdtraj.compute_contacts(traj, contacts='all', scheme='closest-heavy', ignore_nonprotein=True, periodic=True, soft_min=False, soft_min_beta=20)[source]¶
Compute the distance between pairs of residues in a trajectory.
- Parameters:
traj (md.Trajectory) – An mdtraj trajectory. It must contain topology information.
contacts (array-like, ndim=2 or 'all') – An array containing pairs of indices (0-indexed) of residues to compute the contacts between, or ‘all’. The string ‘all’ will select all pairs of residues separated by two or more residues (i.e. the i to i+1 and i to i+2 pairs will be excluded).
scheme ({'ca', 'closest', 'closest-heavy', 'sidechain', 'sidechain-heavy'}) –
- scheme to determine the distance between two residues:
- ’ca’distance between two residues is given by the distance
between their alpha carbons
- ’closest’distance is the closest distance between any
two atoms in the residues
- ’closest-heavy’distance is the closest distance between
any two non-hydrogen atoms in the residues
- ’sidechain’distance is the closest distance between any
two atoms in residue sidechains
- ’sidechain-heavy’distance is the closest distance between
any two non-hydrogen atoms in residue sidechains
ignore_nonprotein (bool) – When using contact==all, don’t compute contacts between “residues” which are not protein (i.e. do not contain an alpha carbon).
periodic (bool, default=True) – If periodic is True and the trajectory contains unitcell information, we will compute distances under the minimum image convention.
soft_min (bool, default=False) –
If soft_min is true, we will use a diffrentiable version of the scheme. The exact expression used
is d =
rac{eta}{logsum_i{exp(
where (rac{eta}{d_i}})}) – beta is user parameter which defaults to 20nm. The expression we use is copied from the plumed mindist calculator. http://plumed.github.io/doc-v2.0/user-doc/html/mindist.html
soft_min_beta (float, default=20nm) – The value of beta to use for the soft_min distance option. Very large values might cause small contact distances to go to 0.
- Returns:
distances (np.ndarray, shape=(n_frames, n_pairs), dtype=np.float32) – Distances for each residue-residue contact in each frame of the trajectory
residue_pairs (np.ndarray, shape=(n_pairs, 2), dtype=int) – Each row of this return value gives the indices of the residues involved in the contact. This argument mirrors the contacts input parameter. When all is specified as input, this return value gives the actual residue pairs resolved from all. Furthermore, when scheme==’ca’, any contact pair supplied as input corresponding to a residue without an alpha carbon (e.g. HOH) is ignored from the input contacts list, meanings that the indexing of the output distances may not match up with the indexing of the input contacts. But the indexing of distances will match up with the indexing of residue_pairs
Examples
>>> # To compute the contact distance between residue 0 and 10 and >>> # residues 0 and 11 >>> md.compute_contacts(t, [[0, 10], [0, 11]])
>>> # the itertools library can be useful to generate the arrays of indices >>> group_1 = [0, 1, 2] >>> group_2 = [10, 11] >>> pairs = list(itertools.product(group_1, group_2)) >>> print(pairs) [(0, 10), (0, 11), (1, 10), (1, 11), (2, 10), (2, 11)] >>> md.compute_contacts(t, pairs)
See also
mdtraj.geometry.squareform
turn the result from this function into a square “contact map”
Topology.residue
Get residues from the topology by index