list_of_cms

mdtools.check.list_of_cms(cms, shape=None, dim=None, amin=None, amax=None, dtype=None)[source]

Check if the input is a sequence of contact matrices (or arrays).

A sequence of contact matrices must meet the following requirements:

  • The sequence must be a tuple, list or numpy.ndarray instance containing the contact matrices either as NumPy arrays or as SciPy sparse matrices. A mix of NumPy arrays and SciPy sparse matrices is not permitted.

  • All arrays in the sequence must have the same shape. If shape is supplied, their shape must be equal to shape.

  • All arrays in the sequence must have a dimension equal to the supplied dim (usually 2 for contact matrices).

  • All array elements must be greater than or equal to amin (if supplied; usually 0 for contact matrices).

  • All array elements must be less than or equal to amax (if supplied; usually 1 for contact matrices).

  • All arrays in the sequence must have a data type equal to the supplied dtype.

Parameters:
  • cms (tuple or list or numpy.ndarray) – Sequence of contact matrices (or generally arrays) as e.g. generated with mdtools.structure.contact_matrices(). The contact matrices itself can be either NumPy arrays or SciPy sparse matrices. A mix of NumPy arrays and SciPy sparse matrices is not permitted.

  • shape (tuple, optional) – The shape expected for the arrays in cms. Default is None, which means that it is only checked whether all arrays in cms have the same shape, but not what shape that is.

  • dim (int, optional) – The dimension expected for the arrays in cms. If None, the dimension is not checked.

  • amin (scalar) – Minimum values that the elements of the arrays in cms must not undermine.

  • amax (scalar) – Maximum values that the elements of the arrays in cms must not exceed.

  • dtype (type, optional) – The data type expected for the arrays in cms. Default is None, which means that the data type is not checked.

Returns:

cms (tuple or list or numpy.ndarray) – The unmodified input.

Raises:
  • ValueError – If shape is not None and the shape of the arrays in cms is not shape; dim is not None and the dimension of the arrays in cms is not dim; The arrays in cms contain elements that are less than amin; The arrays in cms contain elements that are greater than amax. Or if the given combination of shape and dim is not satisfiable by any array; amax is less than amin.

  • TypeError – If cms is not a sequence of arrays; dtype is not None and the data type of the arrays in cms is not dtype; Not all arrays in cms are of the same instance.