mdtraj.compute_contacts¶
-
mdtraj.
compute_contacts
(traj, contacts='all', scheme='closest-heavy', ignore_nonprotein=True, periodic=True)¶ 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’}
- 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
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.
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 distance will match up with the indexing of residue_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
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)