contact_hists
- mdtools.structure.contact_hists(cm, natms_per_refcmp=1, natms_per_selcmp=1, minlength=0, dtype=int)[source]
Bin the number of contacts between reference and selection compounds into histograms.
A compound is usually a chemically meaningful subgroup of an
AtomGroup. This can e.g. be aSegment,Residue,fragmentor a singleAtom. Refer to the MDAnalysis’ user guide for an explanation of these terms. Note that in any case, onlyAtomsbelonging to the originalAtomGroupare taken into account, even if the compound might comprise additionalAtomsthat are not contained in the originalAtomGroup.- Parameters:
cm (
array_like) – (Boolean) contact matrix of shape(m, n)as e.g. generated bymdtools.structure.contact_matrix(), wheremis the number of referenceAtomsandnis the number of selectionAtoms. Alternatively, cm can already be a compound contact count matrix as e.g. generated bymdtools.structure.cmp_contact_count_matrix(). In this case, you probably want to set natms_per_refcmp and natms_per_selcmp to1, to keep cm unaltered.natms_per_refcmp (
intorarray_like, optional) – Number ofAtomsper reference compound. Can be a single integer or an array of integers. If natms_per_refcmp is a single integer, all reference compounds are assumed to contain the same number ofAtoms. In this case, natms_per_refcmp must be an integer divisor ofcm.shape[0]. If natms_per_refcmp is an array of integers, it must contain the number of referenceAtomsfor each single reference compound. In this case,sum(natms_per_refcmp)must be equal tocm.shape[0].natms_per_selcmp (
intorarray_like, optional) – Same for selection compounds (natms_per_selcmp is checked againstcm.shape[1]).minlength (
int, optional) – A minimum number of bins for the output arrays. The output arrays will have at least this number of elements, though they will be longer if necessary. All output arrays will always have the same length.dtype (
dtype, optional) – Data type of the output array.
- Returns:
hist_refcmp_diff_selcmp (
numpy.ndarray) – Histogram of the number of contacts that reference compounds establish to different selection compounds. Multiple contacts with the same selection compound are not taken into account.hist_refcmp_same_selcmp (
numpy.ndarray) – Histogram of the number of contacts that reference compounds establish to the same selection compound. Different selection compounds that are connected to the same reference compound via the same number of “bonds” (Atom-Atomcontacts) are not taken into account.hist_refcmp_selcmp_tot (
numpy.ndarray) – Histogram of the total number of contacts that reference compounds establish to selection compounds. All contacts are taken into account.hist_refcmp_selcmp_pair (
numpy.ndarray) – Histogram of the number of “bonds” (Atom-Atomcontacts) between pairs of reference and selection compounds (refcmp-selcmp pairs). A refcmp-selcmp pair is defined as a reference and selection compound that are connected with each other via at least one “bond”.
See also
contact_histMDTools script to calculate contact histograms.
mdtools.structure.contact_matrix()Construct a boolean contact matrix for two MDAnalysis
AtomGroupsmdtools.structure.natms_per_cmp()Get the number of
Atomsof each compound in an MDAnalysisAtomGroupmdtools.structure.contact_hist_refcmp_diff_selcmp()Bin the number of contacts that reference compounds establish to different selection compounds into a histogram.
mdtools.structure.contact_hist_refcmp_same_selcmp()Bin the number of contacts that reference compounds establish to the same selection compound into a histogram.
mdtools.structure.contact_hist_refcmp_selcmp_tot()Bin the total number of contacts that reference compounds establish to selection compounds into a histogram.
mdtools.structure.contact_hist_refcmp_selcmp_pair()Bin the number of “bonds” (
Atom-Atomcontacts) between pairs of reference and selection compounds
Notes
Atomsbelonging to the same compound must form a contiguous set in the input contact matrix, otherwise the result will be wrong.This function gathers the output of
See there for further details about the returned histograms.
If both natms_per_refcmp and natms_per_selcmp are
1and cm is a true boolean contact matrix, hist_refcmp_same_selcmp and hist_refcmp_selcmp_pair are rather meaningless and hist_refcmp_diff_selcmp and hist_refcmp_selcmp_tot are equal. Thus, in this case it might be better to callmdtools.structure.contact_hist_refcmp_diff_selcmp()ormdtools.structure.contact_hist_refcmp_selcmp_tot()directly.Examples
>>> cm = np.tril(np.ones((5,4), dtype=bool), -1) >>> cm[3, 0] = 0 >>> cm array([[False, False, False, False], [ True, False, False, False], [ True, True, False, False], [False, True, True, False], [ True, True, True, True]]) >>> hists = mdt.strc.contact_hists(cm, minlength=7, dtype=np.uint32) >>> hists[0] array([1, 1, 2, 0, 1, 0, 0], dtype=uint32) >>> hists[1] array([1, 4, 0, 0, 0, 0, 0], dtype=uint32) >>> hists[2] array([1, 1, 2, 0, 1, 0, 0], dtype=uint32) >>> hists[3] array([0, 9, 0, 0, 0, 0, 0], dtype=uint32) >>> np.array_equal(hists[0], hists[2]) True >>> hists[1][1] == cm.shape[0] - hists[1][0] True >>> hists[3][1] == np.count_nonzero(cm) True
>>> mdt.strc.cmp_contact_count_matrix( ... cm=cm, natms_per_refcmp=[2, 2, 1], natms_per_selcmp=2 ... ) array([[1, 0], [3, 1], [2, 2]]) >>> hists = mdt.strc.contact_hists( ... cm=cm, natms_per_refcmp=[2, 2, 1], natms_per_selcmp=2 ... ) >>> hists[0] array([0, 1, 2, 0, 0]) >>> hists[1] array([0, 2, 1, 1, 0]) >>> hists[2] array([0, 1, 0, 0, 2]) >>> hists[3] array([0, 2, 2, 1, 0])
Edge cases:
>>> cm = np.array([], dtype=bool).reshape(0, 4) >>> mdt.strc.contact_hists(cm, natms_per_refcmp=[]) (array([], dtype=int64), array([], dtype=int64), array([], dtype=int64), array([], dtype=int64)) >>> mdt.strc.contact_hists(cm, natms_per_refcmp=1) (array([], dtype=int64), array([], dtype=int64), array([], dtype=int64), array([], dtype=int64))
>>> cm = np.array([], dtype=bool).reshape(6, 0) >>> mdt.strc.contact_hists(cm, ... natms_per_refcmp=3, ... natms_per_selcmp=[]) (array([2]), array([2]), array([2]), array([0]))