contact_map.ContactFrequency¶
-
class
contact_map.ContactFrequency(trajectory, query=None, haystack=None, cutoff=0.45, n_neighbors_ignored=2, frames=None)[source]¶ Contact frequency (atomic and residue) for a trajectory.
The contact frequency is defined as fraction of the trajectory that a certain contact is made. This object calculates this quantity for all contacts with atoms in the query residue, with “contact” defined as being within a certain cutoff distance.
Parameters: - trajectory (mdtraj.Trajectory) – Trajectory (segment) to analyze
- query (list of int) – Indices of the atoms to be included as query. Default
Nonemeans all atoms. - haystack (list of int) – Indices of the atoms to be included as haystack. Default
Nonemeans all 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.
- frames (list of int) – The indices of the frames to use from the trajectory. Default all
-
__init__(trajectory, query=None, haystack=None, cutoff=0.45, n_neighbors_ignored=2, frames=None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__(trajectory[, query, haystack, …])Initialize self. add_contact_frequency(other)Add results from other to the internal counter. contact_map(trajectory, frame_number, …)Returns atom and residue contact maps for the given frame. convert_atom_contacts(atom_contacts)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 idx_to_s_idx(idx)function to convert a real atom index to a sliced one 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 s_idx_to_idx(idx)function to convert a sliced atom index back to real index save_to_file(filename[, mode])Save this object to the given file. slice_trajectory(trajectory)subtract_contact_frequency(other)Subtracts results from other from internal counter. to_dict()Convert object to a dict. to_json()JSON-serialized version of this object. Attributes
all_atomsall atom indices used in the contact map atom_contactsAtoms pairs mapped to fraction of trajectory with that contact contactscontact dict for these contacts cutoffcutoff distance for contacts, in nanometers haystackindices of atoms to include as haystack haystack_residue_rangemin and (max + 1) of haystack residue indices haystack_residuesresidues for atoms in the haystack n_framesNumber of frames in the mapped trajectory n_neighbors_ignorednumber of neighbor residues (in same chain) to ignore queryindices of atoms to include as query query_residue_rangemin and (max + 1) of query residue indices query_residuesresidues for atoms in the query residue_contactsResidue pairs mapped to fraction of trajectory with that contact residue_ignore_atom_idxsmaps query residue index to atom indices to ignore residue_query_atom_idxsmaps query residue index to atom indices in query topologytopology object for this system use_atom_sliceIndicates if mdtraj.atom_slice() is used before calculating the contact map -
add_contact_frequency(other)[source]¶ Add results from other to the internal counter.
Parameters: other ( ContactFrequency) – contact frequency made from the frames to remove from this contact frequency
-
all_atoms¶ all atom indices used in the contact map
Type: list of int
-
atom_contacts¶ Atoms pairs mapped to fraction of trajectory with that contact
-
contact_map(trajectory, frame_number, residue_query_atom_idxs, residue_ignore_atom_idxs)¶ Returns atom and residue contact maps for the given frame.
Parameters: Returns: - atom_contacts (collections.Counter)
- residue_contact (collections.Counter)
-
contacts¶ contact dict for these contacts
Type: ContactsDict
-
classmethod
from_dict(dct)¶ Create object from dict.
Parameters: dct (dict) – dict-formatted serialization (see to_dict for details) See also
-
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: ContactObjectSee 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
-
haystack¶ indices of atoms to include as haystack
Type: list of int
-
idx_to_s_idx(idx)¶ function to convert a real atom index to a sliced one
-
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 listl[e]consists of two parts:l[e][0]is a list containing the two MDTraj Atom objects that make up the contact, andl[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 listl[e]consists of two parts:l[e][0]is a list containing the two MDTraj Atom objects that make up the contact, andl[e][1]is the measure of how often the contact occurs.Return type: list
-
n_frames¶ Number of frames in the mapped trajectory
-
query¶ indices of atoms to include as query
Type: list of int
-
residue_contacts¶ Residue pairs mapped to fraction of trajectory with that contact
-
s_idx_to_idx(idx)¶ function to convert a sliced atom index back to real index
-
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
-
subtract_contact_frequency(other)[source]¶ Subtracts results from other from internal counter.
Note that this is intended for the case that you’re removing a subtrajectory of the already-calculated trajectory. If you want to compare two different contact frequency maps, use
ContactDifference.Parameters: other ( ContactFrequency) – contact frequency made from the frames to remove from this contact frequency
-
to_dict()[source]¶ Convert object to a dict.
Keys should be strings; values should be (JSON-) serializable.
See also
-
to_json()¶ JSON-serialized version of this object.
See also
-
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