def testCenterCoordinates(self): """ Test the coordinate centering function. """ # Setup some coordinates. coords = numpy.array([[1.0,2.0,3.0],[2.0,3.0,-1.1],[-8.9,12.0,4.0]]) # Center around an index. centered_coords = centerCoordinates(coords, 1) # This should get us these coordinates. ref_coords = numpy.array([[-1.0,-1.0,4.1],[0.0,0.0,0.0],[-10.9,9.0,5.1]]) # Check. self.assertAlmostEqual( numpy.linalg.norm(centered_coords-ref_coords), 0.0, 10)
def __init__(self, coordinates=None, basis_sites=None, rate_constant=None): """ Constructor for the KMCBaseProcess. :param coordinates: The local coordinates, corresponding to the lattice positions of the surrounding of the center where the process will be preformed. :param basis_sites: The basis sites in the lattice at which the process can possibly be applied. Only if the length of this list is 1 can implicit wildcards be used for the matching. :param rate_constant: The rate constant associated with this process. :type rate_constant: float """ # Check the coordinates. coordinates = checkCoordinateList(coordinates) # Center the coordinates on the first entry. center = 0 self._coordinates = centerCoordinates(coordinates, center) # Check the list of basis sites. basis_sites = checkSequenceOfPositiveIntegers(basis_sites, msg="The basis_sites must be given as a list of positive integers.") if len(basis_sites) == 0: msg = "The list of available basis sites for a process may not be empty." # Passed the tests. self._basis_sites = basis_sites # Check the rate constant. self._rate_constant = checkPositiveFloat(rate_constant, default_parameter=None, parameter_name="rate_constant") # To be updated by the derrived classes. self._elements_before = None self._elements_after = None self._move_vectors = None self._all_present_types = None self._local_configurations = None
def __init__(self, coordinates=None, basis_sites=None, rate_constant=None): """ Constructor for the KMCBaseProcess. :param coordinates: The local coordinates, corresponding to the lattice positions of the surrounding of the center where the process will be preformed. :param basis_sites: The basis sites in the lattice at which the process can possibly be applied. Only if the length of this list is 1 can implicit wildcards be used for the matching. :param rate_constant: The rate constant associated with this process. :type rate_constant: float """ # Check the coordinates. coordinates = checkCoordinateList(coordinates) # Center the coordinates on the first entry. center = 0 self._coordinates = centerCoordinates(coordinates, center) # Check the list of basis sites. basis_sites = checkSequenceOfPositiveIntegers( basis_sites, msg="The basis_sites must be given as a list of positive integers." ) if len(basis_sites) == 0: msg = "The list of available basis sites for a process may not be empty." # Passed the tests. self._basis_sites = basis_sites # Check the rate constant. self._rate_constant = checkPositiveFloat( rate_constant, default_parameter=None, parameter_name="rate_constant") # To be updated by the derrived classes. self._elements_before = None self._elements_after = None self._move_vectors = None self._all_present_types = None self._local_configurations = None
def testCenterCoordinates(self): """ Test the coordinate centering function. """ # Setup some coordinates. coords = numpy.array([[1.0, 2.0, 3.0], [2.0, 3.0, -1.1], [-8.9, 12.0, 4.0]]) # Center around an index. centered_coords = centerCoordinates(coords, 1) # This should get us these coordinates. ref_coords = numpy.array([[-1.0, -1.0, 4.1], [0.0, 0.0, 0.0], [-10.9, 9.0, 5.1]]) # Check. self.assertAlmostEqual(numpy.linalg.norm(centered_coords - ref_coords), 0.0, 10)
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
def __init__(self, coordinates=None, elements_before=None, elements_after=None, move_vectors=None, basis_sites=None, rate_constant=None): """ Constructor for the KMCProcess. :param coordinates: The local coordinates, corresponding to the lattice positions of the surrounding of the center where the process will be preformed. :param elements_before: The elements, as a list of strings, before the process is preformed. This list of elements will be used to match the local surroundings of each center in the simulation, to determine at which sites the process can be performed. :param elements_after: The elements, as a list of strings, after the process is preformed. This list of elements will be used to update the local surrounding of the site where the process is performed. :param move_vectors: A set of vectors in the local coordinates that define which elements are moved to which place in the move. The vectors are given as a list of tuples, where the first element in each tuple indicates which index is moved and the second element in the tuple is a vector in local coordinates indicating where the move is to. :param basis_sites: The basis sites in the lattice at which the process can possibly be applied. Only if the length of this list is 1 can implicit wildcards be used for the matching. :param rate_constant: The rate constant associated with this process. :type rate_constant: float """ # Check the coordinates. coordinates = checkCoordinateList(coordinates) # Center the coordinates on the first entry. center = 0 self.__coordinates = centerCoordinates(coordinates, center) # Check the types. elements_before = checkTypes(elements_before, len(coordinates)) elements_after = checkTypes(elements_after, len(coordinates)) # Check that the elements represents a valid move. self.__checkValidMoveElements(elements_before, elements_after) # All types checking done. self.__elements_before = elements_before self.__elements_after = elements_after # Check that the move vectors are compatible with the elements. self.__move_vectors = self.__checkValidMoveVectors(move_vectors) # Sort the coordinates and co-sort the elements and move vectors. self.__sortCoordinatesElementsAndMoveVectors() # Check the list of basis sites. basis_sites = checkSequenceOfPositiveIntegers(basis_sites, msg="The basis_sites must be given as a list of positive integers.") if len(basis_sites) == 0: msg = "The list of available basis sites for a process may not be empty." # Passed the tests. self.__basis_sites = basis_sites # Check the rate constant. self.__rate_constant = checkPositiveFloat(rate_constant, default_parameter=None, parameter_name="rate_constant") # Setup the local configurations. c1 = KMCLocalConfiguration(self.__coordinates, self.__elements_before, center) c2 = KMCLocalConfiguration(self.__coordinates, self.__elements_after, center) self.__local_configurations = (c1, c2)