Type Checkers

This module defines functions for type, value, and/or attribute checking.

checkCoords(coords, csets=False, natoms=None, dtype=(<type 'float'>, <type 'numpy.float32'>), name='coords')[source]

Returns True if shape, dimensionality, and data type of coords array are as expected.

Parameters:
  • coords – coordinate array
  • csets – whether multiple coordinate sets (i.e. .ndim in (2, 3)) are allowed, default is False
  • natoms – number of atoms, if None number of atoms is not checked
  • dtype – allowed data type(s), default is (float, numpy.float32), if None data type is not checked
  • name – name of the coordinate argument
Raises:

TypeError when coords is not an instance of numpy.ndarray

Raises:

ValueError when wrong shape, dimensionality, or data type is encountered

checkWeights(weights, natoms, ncsets=None, dtype=<type 'float'>)[source]

Returns weights if it has correct shape ([ncsets, ]natoms, 1). after its shape and data type is corrected. otherwise raise an exception. All items of weights must be greater than zero.

checkTypes(args, **types)[source]

Returns True if types of all args match those given in types.

Raises:TypeError when type of an argument is not one of allowed types
def incr(n, i):
    '''Return sum of *n* and *i*.'''

    checkTypes(locals(), n=(float, int), i=(float, int))
    return n + i
checkAnisous(anisous, csets=False, natoms=None, dtype=(<type 'float'>, <type 'numpy.float32'>), name='anisous')[source]

Returns True if shape, dimensionality, and data type of anisous array are as expected.

Parameters:
  • anisous – anisous array
  • csets – whether multiple coordinate sets (i.e. .ndim in (2, 3)) are allowed, default is False
  • natoms – number of atoms, if None number of atoms is not checked
  • dtype – allowed data type(s), default is (float, numpy.float32), if None data type is not checked
  • name – name of the coordinate argument
Raises:

TypeError when anisous is not an instance of numpy.ndarray

Raises:

ValueError when wrong shape, dimensionality, or data type is encountered