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)
-
__init__
(counter, object_f, n_x, n_y)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
(counter, object_f, n_x, n_y)Initialize self. filter
(idx)New ContactCount filtered to idx. 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) plot_axes
(ax[, cmap, vmin, vmax, with_colorbar])Plot contact matrix on a matplotlib.axes Attributes
counter
keys use index number; count is contact occurrences df
DataFrame representation of the contact matrix sparse_matrix
sparse matrix representation of contacts -
counter
¶ keys use index number; count is contact occurrences
Type: collections.Counter
-
df
¶ DataFrame representation of the contact matrix
Rows/columns correspond to indices and the values correspond to the count
Type: pandas.SparseDataFrame
-
filter
(idx)[source]¶ New ContactCount filtered to idx.
Returns a new ContactCount with the only the counter keys/values where both the keys are in idx
-
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, **kwargs)[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 (
-
plot_axes
(ax, cmap='seismic', vmin=-1.0, vmax=1.0, with_colorbar=True)[source]¶ Plot contact matrix on a matplotlib.axes
Parameters: - ax (matplotlib.axes) – axes to plot the contact matrix on
- cmap (str) – color map name, default ‘seismic’
- vmin (float) – minimum value for color map interpolation; default -1.0
- vmax (float) – maximum value for color map interpolation; default 1.0
- with_colorbar (bool) – If a colorbar is added to the axes
-
sparse_matrix
¶ sparse matrix representation of contacts
Rows/columns correspond to indices and the values correspond to the count
Type: scipy.sparse.dok.dok_matrix
- counter (