def testCheckIndexWithinBounds(self): """ Test the index within bounds checking function. """ # Shoud pass. index = 0 list = [0,12,'a',21.2] checked_index = checkIndexWithinBounds(index, list) self.assertEqual(checked_index, index) # This should also pass. index = 4 list = "ABCDE" checked_index = checkIndexWithinBounds(index, list) self.assertEqual(checked_index, index) # And this. index = 1 list = numpy.array([[12.0,1.3],[1.,4.3]]) checked_index = checkIndexWithinBounds(index, list) self.assertEqual(checked_index, index) # Should fail - index not within bounds. index = -1 self.assertRaises(Error, lambda: checkIndexWithinBounds(index, list)) index = 2 self.assertRaises(Error, lambda: checkIndexWithinBounds(index, list)) # Catch and check the error. msg = "Custom Error msg." try: checkIndexWithinBounds(index, list, msg) except Error as e: error_msg = str(e) self.assertEqual(error_msg, msg)
def testCheckIndexWithinBounds(self): """ Test the index within bounds checking function. """ # Shoud pass. index = 0 list = [0, 12, 'a', 21.2] checked_index = checkIndexWithinBounds(index, list) self.assertEqual(checked_index, index) # This should also pass. index = 4 list = "ABCDE" checked_index = checkIndexWithinBounds(index, list) self.assertEqual(checked_index, index) # And this. index = 1 list = numpy.array([[12.0, 1.3], [1., 4.3]]) checked_index = checkIndexWithinBounds(index, list) self.assertEqual(checked_index, index) # Should fail - index not within bounds. index = -1 self.assertRaises(Error, lambda: checkIndexWithinBounds(index, list)) index = 2 self.assertRaises(Error, lambda: checkIndexWithinBounds(index, list)) # Catch and check the error. msg = "Custom Error msg." try: checkIndexWithinBounds(index, list, msg) except Error as e: error_msg = str(e) self.assertEqual(error_msg, msg)
def __init__(self, coordinates=None, types=None, center=None): """ Constructor for the KMCLocalConfiguration. :param coordinates: The coordinates of the configuration given as a 3xN sequence of floating point numbers, where N is the number of local sites. :param types: The lattice site types at the specified coordinates given as a sequence of strings of length N. :param center: The coordinate in the list to treat as the central site indexed from zero. If not given it will default to the first coordinate (i.e. center == 0). :type center: int """ # ML: # FIXME: Must support bucket types information. # Check the coordinates. coordinates = checkCoordinateList(coordinates) # Set the center coordinate if not given. if center is None: center = 0 # Check the bounds of the center coordinate. center = checkIndexWithinBounds(center, coordinates, msg="The 'center' index paramter must be one in the coordinate list.") # Center the coordinates. self.__coordinates = centerCoordinates(coordinates, center) # Check the types. if len(types) != len(coordinates): raise Error("The length of the types must match the coordinates.") self.__types = [checkAndNormaliseBucketEntry(t) for t in types] # Set the backend to None, to generate it at first query. self.__backend = None