contact_map.ContactCount¶
-
class
contact_map.
ContactCount
(counter, object_f, n_x, n_y)[source]¶ Return object when dealing with contacts (residue or atom).
This contains all the information about the contacts of a given type. This information can be represented several ways. One is as a list of contact pairs, each associated with the fraction of time the contact occurs. Another is as a matrix, where the rows and columns label the pair number, and the value is the fraction of time. This class provides several methods to get different representations of this data for further analysis.
In general, instances of this class shouldn’t be created by a user using
__init__
; instead, they will be returned by other methods. So users will often need to use this object for analysis.Parameters: - counter (
collections.Counter
) – the counter describing the count of how often the contact occurred; key is a frozenset of a pair of numbers (identifying the atoms/residues); value is the raw count of the number of times it occurred - object_f (callable) – method to obtain the object associated with the number used in
counter
; typicallymdtraj.Topology.residue()
ormdtraj.Topology.atom()
. - n_x (int) – number of objects in the x direction (used in plotting)
- n_y (int) – number of objects in the y direction (used in plotting)
Methods
__init__
(counter, object_f, n_x, n_y)most_common
([obj])Most common values (ordered) with object as keys. most_common_idx
()Most common values (ordered) with indices as keys. plot
([cmap, vmin, vmax, with_colorbar])Plot contact matrix (requires matplotlib) -
counter
¶ collections.Counter
– keys use index number; count is contact occurrences
-
df
¶ pandas.SparseDataFrame
– DataFrame representation of the contact matrixRows/columns correspond to indices and the values correspond to the count
-
most_common
(obj=None)[source]¶ Most common values (ordered) with object as keys.
This uses the objects for the contact pair (typically MDTraj
Atom
orResidue
objects), instead of numeric indices. This is more readable and can be easily used for further manipulation.Parameters: obj (MDTraj Atom or Residue) – if given, the return value only has entries including this object (allowing one to, for example, get the most common contacts with a specific residue) Returns: the most common contacts in order. If the list is l
, then each elementl[e]
is a tuple with two parts:l[e][0]
is the key, which is a pair of Atom or Residue objects, andl[e][1]
is the count of how often that contact occurred.Return type: list See also
most_common_idx()
- same thing, using index numbers as key
-
most_common_idx
()[source]¶ Most common values (ordered) with indices as keys.
Returns: the most common contacts in order. The if the list is l
, then each elementl[e]
consists of two parts:l[e][0]
is a pair of integers, representing the indices of the objects associated with the contact, andl[e][1]
is the count of how often that contact occurredReturn type: list See also
most_common()
- same thing, using objects as key
-
plot
(cmap='seismic', vmin=-1.0, vmax=1.0, with_colorbar=True)[source]¶ Plot contact matrix (requires matplotlib)
Parameters: Returns: - fig (
matplotlib.Figure
) – matplotlib figure object for this plot - ax (
matplotlib.Axes
) – matplotlib axes object for this plot
- fig (
-
sparse_matrix
¶ scipy.sparse.dok.dok_matrix
– sparse matrix representation of contactsRows/columns correspond to indices and the values correspond to the count
- counter (