contact_map.ContactTrajectory

class contact_map.ContactTrajectory(trajectory, query=None, haystack=None, cutoff=0.45, n_neighbors_ignored=2)[source]

Track all the contacts over a trajectory, frame-by-frame.

Internally, this has a single-frame ContactFrequency for each frame of the trajectory.

Parameters:
  • trajectory (mdtraj.Trajectory) – the trajectory to calculate contacts for
  • query (list of int) – Indices of the atoms to be included as query. Default None means all heavy, non-water atoms.
  • haystack (list of int) – Indices of the atoms to be included as haystack. Default None means all heavy, non-water atoms.
  • cutoff (float) – Cutoff distance for contacts, in nanometers. Default 0.45.
  • n_neighbors_ignored (int) – Number of neighboring residues (in the same chain) to ignore. Default 2.
__init__(trajectory, query=None, haystack=None, cutoff=0.45, n_neighbors_ignored=2)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(trajectory[, query, haystack, …]) Initialize self.
contact_frequency() Create a ContactFrequency from this contact trajectory
count(value)
from_contact_maps(maps)
from_contacts(atom_contacts, …[, query, …])
from_dict(dct) Create object from dict.
from_file(filename) Load this object from a given file
from_json(json_string) Create object from JSON string
index(value, [start, [stop]]) Raises ValueError if the value is not present.
join(others) Concatenate ContactTrajectory instances
most_common_atoms_for_contact(contact_pair) Most common atom contacts for a given residue contact pair
most_common_atoms_for_residue(residue) Most common atom contact pairs for contacts with the given residue
rolling_frequency([window_size, step]) RollingContactFrequency iterator for this trajectory
save_to_file(filename[, mode]) Save this object to the given file.
to_dict() Convert object to a dict.
to_json() JSON-serialized version of this object.

Attributes

all_atoms all atom indices used in the contact map
atom_contacts
contacts contact dict for these contacts
cutoff cutoff distance for contacts, in nanometers
haystack indices of atoms to include as haystack
haystack_range return an tuple with the (min, max+1) of haystack
haystack_residue_range min and (max + 1) of haystack residue indices
haystack_residues residues for atoms in the haystack
n_neighbors_ignored number of neighbor residues (in same chain) to ignore
query indices of atoms to include as query
query_range return an tuple with the (min, max+1) of query
query_residue_range min and (max + 1) of query residue indices
query_residues residues for atoms in the query
residue_contacts
topology topology object for this system
use_atom_slice Indicates if mdtraj.atom_slice() is used before calculating the contact map
all_atoms

all atom indices used in the contact map

Type:list of int
contact_frequency()[source]

Create a ContactFrequency from this contact trajectory

contacts

contact dict for these contacts

Type:ContactsDict
count(value) → integer -- return number of occurrences of value
cutoff

cutoff distance for contacts, in nanometers

Type:float
classmethod from_dict(dct)[source]

Create object from dict.

Parameters:dct (dict) – dict-formatted serialization (see to_dict for details)

See also

to_dict()

classmethod from_file(filename)

Load this object from a given file

Parameters:filename (string) – the file to read from
Returns:the reloaded object
Return type:ContactObject

See also

save_to_file()
save to a file
classmethod from_json(json_string)

Create object from JSON string

Parameters:json_string (str) – JSON-serialized version of the object

See also

to_json()

haystack

indices of atoms to include as haystack

Type:list of int
haystack_range

return an tuple with the (min, max+1) of haystack

haystack_residue_range

min and (max + 1) of haystack residue indices

Type:(int, int)
haystack_residues

residues for atoms in the haystack

Type:list
index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

classmethod join(others)[source]

Concatenate ContactTrajectory instances

Parameters:others (List[:class:.ContactTrajectory]) – contact trajectories to concatenate
Returns:concatenated contact trajectory
Return type:ContactTrajectory
most_common_atoms_for_contact(contact_pair)

Most common atom contacts for a given residue contact pair

Parameters:contact_pair (length 2 list of Residue or int) – the residue contact pair for which the most common atom contact pairs will be calculated
Returns:Atom contact pairs for the residue contact pair, in order of frequency. Referring to the list as l, each element of the list l[e] consists of two parts: l[e][0] is a list containing the two MDTraj Atom objects that make up the contact, and l[e][1] is the measure of how often the contact occurs.
Return type:list
most_common_atoms_for_residue(residue)

Most common atom contact pairs for contacts with the given residue

Parameters:residue (Residue or int) – the Residue object or index representing the residue for which the most common atom contact pairs will be calculated
Returns:Atom contact pairs involving given residue, order of frequency. Referring to the list as l, each element of the list l[e] consists of two parts: l[e][0] is a list containing the two MDTraj Atom objects that make up the contact, and l[e][1] is the measure of how often the contact occurs.
Return type:list
n_neighbors_ignored

number of neighbor residues (in same chain) to ignore

Type:int
query

indices of atoms to include as query

Type:list of int
query_range

return an tuple with the (min, max+1) of query

query_residue_range

min and (max + 1) of query residue indices

Type:(int, int)
query_residues

residues for atoms in the query

Type:list
rolling_frequency(window_size=1, step=1)[source]

RollingContactFrequency iterator for this trajectory

Parameters:
  • window_size (int) – the number of frames in the window
  • step (int) – the number of frames between successive starting points of the window (like the step parameter in a Python slice object)
Returns:

windowed iterator for this trajectory

Return type:

RollingContactFrequency

save_to_file(filename, mode='w')

Save this object to the given file.

Parameters:
  • filename (string) – the file to write to
  • mode ('w' or 'a') – file writing mode. Use ‘w’ to overwrite, ‘a’ to append. Note that writing by bytes (‘b’ flag) is automatically added.

See also

from_file()
load from generated file
to_dict()[source]

Convert object to a dict.

Keys should be strings; values should be (JSON-) serializable.

See also

from_dict()

to_json()

JSON-serialized version of this object.

See also

from_json()

topology

topology object for this system

The topology includes information about the atoms, how they are grouped into residues, and how the residues are grouped into chains.

Type:mdtraj.Topology
use_atom_slice

Indicates if mdtraj.atom_slice() is used before calculating the contact map

Type:bool