cms_n_contacts

mdtools.structure.cms_n_contacts(cms, dtype=int)[source]

Get the number of contacts per contact matrix and the number of contacts common in all contact matrices.

Parameters:
Returns:

n_contacts (numpy.ndarray) – Array of shape (len(cms)+1,) containing the number of non-zero elements of each array in cms. The last element of n_contacts is the number of non-zero elements of the product of all arrays in cms (i.e. the number of non-zero elements that are common in all arrays in cms).

See also

mdtools.structure.contact_matrix()

Construct a boolean contact matrix for two MDAnalysis AtomGroups

mdtools.structure.contact_matrices()

Construct a contact matrix for each frame in a trajectory

mdtools.structure.cms_n_common_contacts()

Get the number of contacts common in all contact matrices

Examples

NumPy arrays as input:

>>> cm0 = np.array([[ True,  True, False],
...                 [False,  True,  True]])
>>> cm1 = np.array([[ True, False, False],
...                 [False, False,  True]])
>>> cm2 = np.array([[ True,  True, False],
...                 [False, False,  True]])
>>> mdt.strc.cms_n_contacts([cm0,])
array([4, 4])
>>> cms = [cm0, cm1, cm2]
>>> mdt.strc.cms_n_contacts(cms)
array([4, 2, 3, 2])
>>> n_contacts = np.array([np.count_nonzero(cm) for cm in cms])
>>> n_contacts
array([4, 2, 3])
>>> np.array_equal(n_contacts, mdt.strc.cms_n_contacts(cms)[:-1])
True

SciPy sparse matrices as input:

>>> from scipy import sparse
>>> cms = [sparse.csr_matrix(cm) for cm in cms]
>>> mdt.strc.cms_n_contacts([cms[0],])
array([4, 4])
>>> mdt.strc.cms_n_contacts(cms)
array([4, 2, 3, 2])