mdtraj.compute_contacts

mdtraj.compute_contacts(traj, contacts='all', scheme='closest-heavy', ignore_nonprotein=True)

Compute the distance between pairs of residues in a trajectory.

Parameters:

traj : md.Trajectory

An mdtraj trajectory. It must contain topology information.

contacts : np.ndarray or ‘all’

numpy array containing (0-indexed) residues to compute the contacts for. (e.g. np.array([[0, 10], [0, 11]]) would compute the contact between residue 0 and residue 10 as well as the contact between residue 0 and residue 11.) [NOTE: if no array is passed then ‘all’ contacts are calculated. This means that the result will contain all contacts between residues separated by at least 3 residues.]

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

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 suplied 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
Versions