cm_fill_missing_cmp_ix

mdtools.structure.cm_fill_missing_cmp_ix(cm, refix=None, selix=None)[source]

Insert elements in a contact matrix at missing intermediate compound indices.

The inserted matrix elements will evaluate to False.

Parameters:
  • cm (array_like) – (Boolean) contact matrix of shape (m, n) as e.g. generated by mdtools.structure.contact_matrix(), where m is the number of reference Atoms or compounds and n is the number of selection Atoms or compounds.

  • refix, selix (array_like of ints) – Array of compound indices corresponding to the reference/selection compounds contained in cm. If the indices contain gaps, these gaps will be filled by this function. Indices must not be negative, duplicate indices will be removed.

Returns:

cm (numpy.ndarray) – The input contact matrix with added rows for missing reference compound indices in refix and added columns for missing selection compound indices in selix. If both refix and selix do not have any gaps (i.e. the indices are contiguous), the input matrix is returned instead as numpy.ndarray.

See also

mdtools.structure.contact_matrix()

Construct a boolean contact matrix for two MDAnalysis AtomGroups

mdtools.structure.cmp_contact_matrix()

Convert an Atom contact matrix to a compound contact matrix

Examples

>>> cm = np.array([[ True,  True, False],
...                [False,  True,  True]])
>>> # 3 missing
>>> mdt.strc.cm_fill_missing_cmp_ix(cm, refix=[2, 4])
array([[ True,  True, False],
       [False, False, False],
       [False,  True,  True]])
>>> # 2, 3 missing
>>> mdt.strc.cm_fill_missing_cmp_ix(cm, selix=[0, 1, 4])
array([[ True,  True, False, False, False],
       [False,  True, False, False,  True]])

If both refix and selix do not have any gaps, the input contact matrix is returned as numpy.ndarray. If it already was a numpy.ndarray before, no copy is made.

>>> result = mdt.strc.cm_fill_missing_cmp_ix(
...     cm, refix=[2, 3], selix=[1, 2, 3]
... )
>>> result is cm
True