コード例 #1
0
    def __init__(self, cell_vectors=None, basis_points=None):
        """
        Constructor for the KMCUnitCell class.

        :param cell_vectors: A 3x3 matrix, nested lists or numpy array with
                             rows corresponding to the a, b and c vectors in
                             cartesian coordinates.

        :param basis_points: A Nx3 matrix, nested lists or numpy array with
                             each row corresponding to the fractional coordinates
                             of a basis point.
        """
        # Check the cell vectors.
        self.__cell_vectors = checkCellVectors(cell_vectors)

        # Check the basis points are of correct format.
        basis_points = checkCoordinateList(basis_points,
                                           varname="basis_points")

        # Check that the basis points are given in fractional coordinates.
        for point in basis_points:
            if not all([b < 1.0 and b >= 0.0 for b in point]):
                raise Error(
                    "All basis points must be given in fractional coordinates in the range 0.0 <= basis_point < 1.0."
                )

        self.__basis_points = basis_points
コード例 #2
0
ファイル: KMCUnitCell.py プロジェクト: PytLab/KMCLib
    def __init__(self,
                 cell_vectors=None,
                 basis_points=None):
        """
        Constructor for the KMCUnitCell class.

        :param cell_vectors: A 3x3 matrix, nested lists or numpy array with
                             rows corresponding to the a, b and c vectors in
                             cartesian coordinates.

        :param basis_points: A Nx3 matrix, nested lists or numpy array with
                             each row corresponding to the fractional coordinates
                             of a basis point.
        """
        # Check the cell vectors.
        self.__cell_vectors = checkCellVectors(cell_vectors)

        # Check the basis points are of correct format.
        basis_points = checkCoordinateList(basis_points, varname="basis_points")

        # Check that the basis points are given in fractional coordinates.
        for point in basis_points:
            if not all([b < 1.0 and b >= 0.0 for b in point]):
                raise Error("All basis points must be given in fractional coordinates in the range 0.0 <= basis_point < 1.0.")

        self.__basis_points = basis_points
コード例 #3
0
ファイル: CheckUtilitiesTest.py プロジェクト: PytLab/KMCLib
    def testCheckCoordinateList(self):
        """ Test the coordinate list checking function. """
        # Setup some valid coordinates.
        valid_coordinates = [[1.0,2.0,3.4],[3.0,3.0,3.5]]

        # Make sure they pass the check.
        checked_coords = checkCoordinateList(valid_coordinates)
        self.assertAlmostEqual( numpy.linalg.norm(valid_coordinates-checked_coords), 0.0, 10)

        # Again, with numpy.
        valid_coordinates = numpy.array(valid_coordinates)
        checked_coords = checkCoordinateList(valid_coordinates)
        self.assertAlmostEqual( numpy.linalg.norm(valid_coordinates-checked_coords), 0.0, 10)

        # Test some things that fails.

        # Wrong type.
        invalid_coordinates = [[1.0,1.0,1.0],[1.0,1.0,1]]
        self.assertRaises(Error, lambda: checkCoordinateList(invalid_coordinates))

        # Wrong type.
        invalid_coordinates = "[[1.0,1.0,1.0],[1.0,1.0,1]]"
        self.assertRaises(Error, lambda: checkCoordinateList(invalid_coordinates))

        # Wrong size.
        invalid_coordinates = [[1.0,2.0,3.4],[3.0,3.0],[3.0,3.0,3.5]]
        self.assertRaises(Error, lambda: checkCoordinateList(invalid_coordinates))

        invalid_coordinates = [[1.0,2.0,3.4],[3.0,3.0,1.2],[3.0,3.0,3.5,32.3]]
        self.assertRaises(Error, lambda: checkCoordinateList(invalid_coordinates))
コード例 #4
0
ファイル: KMCBaseProcess.py プロジェクト: PytLab/KMCLib
    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
コード例 #5
0
ファイル: KMCBaseProcess.py プロジェクト: zqhuang2014/KMCLib
    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
コード例 #6
0
    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
コード例 #7
0
    def testCheckCoordinateList(self):
        """ Test the coordinate list checking function. """
        # Setup some valid coordinates.
        valid_coordinates = [[1.0, 2.0, 3.4], [3.0, 3.0, 3.5]]

        # Make sure they pass the check.
        checked_coords = checkCoordinateList(valid_coordinates)
        self.assertAlmostEqual(
            numpy.linalg.norm(valid_coordinates - checked_coords), 0.0, 10)

        # Again, with numpy.
        valid_coordinates = numpy.array(valid_coordinates)
        checked_coords = checkCoordinateList(valid_coordinates)
        self.assertAlmostEqual(
            numpy.linalg.norm(valid_coordinates - checked_coords), 0.0, 10)

        # Test some things that fails.

        # Wrong type.
        invalid_coordinates = [[1.0, 1.0, 1.0], [1.0, 1.0, 1]]
        self.assertRaises(Error,
                          lambda: checkCoordinateList(invalid_coordinates))

        # Wrong type.
        invalid_coordinates = "[[1.0,1.0,1.0],[1.0,1.0,1]]"
        self.assertRaises(Error,
                          lambda: checkCoordinateList(invalid_coordinates))

        # Wrong size.
        invalid_coordinates = [[1.0, 2.0, 3.4], [3.0, 3.0], [3.0, 3.0, 3.5]]
        self.assertRaises(Error,
                          lambda: checkCoordinateList(invalid_coordinates))

        invalid_coordinates = [[1.0, 2.0, 3.4], [3.0, 3.0, 1.2],
                               [3.0, 3.0, 3.5, 32.3]]
        self.assertRaises(Error,
                          lambda: checkCoordinateList(invalid_coordinates))
コード例 #8
0
    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)