예제 #1
0
    def testBackend(self):
        """ Test that we can get a valid backend object out. """
        # Construct with coordinate list.
        coords = [[1.0,2.0,3.4],[1.1,1.2,1.3]]
        types = ["A","B"]
        local_config = KMCLocalConfiguration(coordinates=coords,
                                             types=types,
                                             center=1)

        # Setup a possible types dict.
        possible_types = {
            "A" : 0,
            "B" : 1,
            "C" : 2,
            }

        # Get the backend.
        backend = local_config._backend(possible_types)

        # Check its type.
        self.assertTrue( isinstance(backend, Backend.Configuration) )

        # Get the coordinates back out and check.
        cpp_coords = backend.coordinates()
        py_coords  = local_config.coordinates()

        self.assertAlmostEqual( cpp_coords[0][0], py_coords[0][0], 10 )
        self.assertAlmostEqual( cpp_coords[0][1], py_coords[0][1], 10 )
        self.assertAlmostEqual( cpp_coords[0][2], py_coords[0][2], 10 )

        # Get the types back out.
        cpp_types = list(backend.elements())
        py_types  = local_config.types()

        self.assertEqual(py_types, cpp_types)
예제 #2
0
    def testMemberDataQuery(self):
        """ Check that the correct member data is stored and returned. """
        # Setup the configuration.
        coords = [[1.0, 2.0, 3.0], [1.0, 1.0, 3.0], [3.0, 8.0, 9.0]]
        types = ["C", "B", "A"]
        local_config = KMCLocalConfiguration(coordinates=coords,
                                             types=types,
                                             center=1)

        # Define the reference data.
        ref_coords = numpy.array([[0.0, 1.0, 0.0], [0.0, 0.0, 0.0],
                                  [2.0, 7.0, 6.0]])
        ref_types = [[(1, "C")], [(1, "B")], [(1, "A")]]

        # Check the coordinates.
        self.assertAlmostEqual(
            numpy.linalg.norm(
                local_config._KMCLocalConfiguration__coordinates - ref_coords),
            0.0, 10)
        #
        self.assertAlmostEqual(
            numpy.linalg.norm(local_config.coordinates() - ref_coords), 0.0,
            10)

        # Check the types.
        self.assertEqual(local_config._KMCLocalConfiguration__types, ref_types)
        #
        self.assertEqual(local_config.types(), ref_types)
    def testBackend(self):
        """ Test that we can get a valid backend object out. """
        # Construct with coordinate list.
        coords = [[1.0, 2.0, 3.4], [1.1, 1.2, 1.3]]
        types = ["A", "B"]
        local_config = KMCLocalConfiguration(coordinates=coords,
                                             types=types,
                                             center=1)

        # Setup a possible types dict.
        possible_types = {
            "A": 0,
            "B": 1,
            "C": 2,
        }

        # Get the backend.
        backend = local_config._backend(possible_types)

        # Check its type.
        self.assertTrue(isinstance(backend, Backend.Configuration))

        # Get the coordinates back out and check.
        cpp_coords = backend.coordinates()
        py_coords = local_config.coordinates()

        self.assertAlmostEqual(cpp_coords[0][0], py_coords[0][0], 10)
        self.assertAlmostEqual(cpp_coords[0][1], py_coords[0][1], 10)
        self.assertAlmostEqual(cpp_coords[0][2], py_coords[0][2], 10)

        # Get the types back out.
        cpp_types = list(backend.elements())
        py_types = local_config.types()

        self.assertEqual(py_types, cpp_types)
예제 #4
0
    def testLocalConfigurations(self):
        """ Test that the local configurations are correctly set up """
        coordinates = numpy.array([[1.0, 2.0, 3.0], [2.3, 5.5, 3.2]])
        elements1 = ["First", "Second"]
        elements2 = ["Second", "First"]

        # Construct the process.
        process = KMCProcess(coordinates,
                             elements1,
                             elements2,
                             basis_sites=[9],
                             rate_constant=1.0)

        # Get the local configurations out.
        c1 = process.localConfigurations()[0]
        c2 = process.localConfigurations()[1]

        # Construct the two reference local configurations.
        ref_c1 = KMCLocalConfiguration(coordinates, elements1, center=0)
        ref_c2 = KMCLocalConfiguration(coordinates, elements2, center=0)

        # Check coordinates.
        self.assertAlmostEqual(
            numpy.linalg.norm(c1.coordinates() - ref_c1.coordinates()), 0.0,
            12)
        self.assertAlmostEqual(
            numpy.linalg.norm(c2.coordinates() - ref_c2.coordinates()), 0.0,
            12)

        # Check types.
        self.assertAlmostEqual(c1.types(), ref_c1.types())
        self.assertAlmostEqual(c2.types(), ref_c2.types())
예제 #5
0
    def testScript(self):
        """ Test the scripting functionality. """
        # Setup the configuration.
        coords = [[1.0,2.0,3.0]]
        types = ["C"]
        local_config = KMCLocalConfiguration(coordinates=coords,
                                             types=types,
                                             center=0)

        ref_script = """
# -----------------------------------------------------------------------------
# Local configuration

coordinates = [[   0.000000e+00,   0.000000e+00,   0.000000e+00]]

types = ['C']

local_configuration = KMCLocalConfiguration(
    coordinates=coordinates,
    types=types)
"""
        # Check the script.
        self.assertEqual(local_config._script(), ref_script)

        # Get another script.
        coords = [[1.0,2.0,3.0],[1.0,1.0,3.0],[3.0,8.0,9.0]]
        types = ["C","B","A"]
        local_config = KMCLocalConfiguration(coordinates=coords,
                                             types=types,
                                             center=0)
        ref_script2 = """
# -----------------------------------------------------------------------------
# Local configuration

coordinates = [[   0.000000e+00,   0.000000e+00,   0.000000e+00],
               [   0.000000e+00,  -1.000000e+00,   0.000000e+00],
               [   2.000000e+00,   6.000000e+00,   6.000000e+00]]

types = ['C', 'B', 'A']

local_config2 = KMCLocalConfiguration(
    coordinates=coordinates,
    types=types)
"""
        # Check.
        self.assertEqual(local_config._script(variable_name="local_config2"), ref_script2)
예제 #6
0
 def testConstructionFails(self):
     """ Make sure the construction fails in the correct way with wrong arguments. """
     # Data do use.
     coords = [[1.0, 2.0, 3.4], [1.1, 1.2, 1.3]]
     types = ["A", "B"]
     center = -1
     # No arguments.
     self.assertRaises(Error, lambda: KMCLocalConfiguration())
     # Center out of bounds.
     self.assertRaises(Error,
                       lambda: KMCLocalConfiguration(coords, types, center))
     # Missing types information.
     self.assertRaises(
         Error,
         lambda: KMCLocalConfiguration(coordinates=coords, center=center))
     # Missing coordinate information.
     self.assertRaises(
         Error, lambda: KMCLocalConfiguration(types=types, center=center))
     # Wrong type of types.
     self.assertRaises(
         Error, lambda: KMCLocalConfiguration(coords, coords, center))
     # Wrong type of coordinates.
     self.assertRaises(Error,
                       lambda: KMCLocalConfiguration(types, types, center))
     # Wrong type of center.
     self.assertRaises(
         Error, lambda: KMCLocalConfiguration(coords, types, center="A"))
예제 #7
0
    def testConstruction(self):
        """ Test that the KMCLocalConfiguration class can be constructed. """
        # Construct with coordinate list.
        coords = [[1.0, 2.0, 3.4], [1.1, 1.2, 1.3]]
        types = ["A", "B"]
        local_config = KMCLocalConfiguration(coordinates=coords,
                                             types=types,
                                             center=1)

        # Test.
        self.assertTrue(isinstance(local_config, KMCLocalConfiguration))

        # Construct with numpy coordinates.
        coords = numpy.array([[1.0, 2.0, 3.4], [1.1, 1.2, 1.3]])
        local_config = KMCLocalConfiguration(coordinates=coords,
                                             types=types,
                                             center=0)

        # Test.
        self.assertTrue(isinstance(local_config, KMCLocalConfiguration))
예제 #8
0
    def testLocalConfigurations(self):
        """ Test that the local configurations are correctly set up """
        coordinates = numpy.array([[1.0,2.0,3.0], [2.3,5.5,3.2]])
        elements1 = ["First", "Second"]
        elements2 = ["Second", "First"]

        # Construct the process.
        process = KMCProcess(coordinates,
                             elements1,
                             elements2,
                             basis_sites=[9],
                             rate_constant=1.0)

        # Get the local configurations out.
        c1 = process.localConfigurations()[0]
        c2 = process.localConfigurations()[1]

        # Construct the two reference local configurations.
        ref_c1 = KMCLocalConfiguration(coordinates, elements1, center=0)
        ref_c2 = KMCLocalConfiguration(coordinates, elements2, center=0)

        # Check coordinates.
        self.assertAlmostEqual( numpy.linalg.norm(c1.coordinates() - ref_c1.coordinates()), 0.0, 12 )
        self.assertAlmostEqual( numpy.linalg.norm(c2.coordinates() - ref_c2.coordinates()), 0.0, 12 )

        # Check types.
        self.assertAlmostEqual( c1.types(), ref_c1.types() )
        self.assertAlmostEqual( c2.types(), ref_c2.types() )
예제 #9
0
    def testMemberDataQuery(self):
        """ Check that the correct member data is stored and returned. """
        # Setup the configuration.
        coords = [[1.0,2.0,3.0],[1.0,1.0,3.0],[3.0,8.0,9.0]]
        types = ["C","B","A"]
        local_config = KMCLocalConfiguration(coordinates=coords,
                                             types=types,
                                             center=1)

        # Define the reference data.
        ref_coords    = numpy.array([[0.0,1.0,0.0],[0.0,0.0,0.0],[2.0,7.0,6.0]])
        ref_types     = ["C","B","A"]

        # Check the coordinates.
        self.assertAlmostEqual(numpy.linalg.norm(local_config._KMCLocalConfiguration__coordinates - ref_coords), 0.0, 10)
        #
        self.assertAlmostEqual(numpy.linalg.norm(local_config.coordinates() - ref_coords), 0.0, 10)

        # Check the types.
        self.assertEqual(local_config._KMCLocalConfiguration__types, ref_types)
        #
        self.assertEqual(local_config.types(), ref_types)
예제 #10
0
    def testScript(self):
        """ Test the scripting functionality. """
        # Setup the configuration.
        coords = [[1.0, 2.0, 3.0]]
        types = ["C"]
        local_config = KMCLocalConfiguration(coordinates=coords,
                                             types=types,
                                             center=0)

        ref_script = """
# -----------------------------------------------------------------------------
# Local configuration

coordinates = [[   0.000000e+00,   0.000000e+00,   0.000000e+00]]

types = [[(1, 'C')]]

local_configuration = KMCLocalConfiguration(
    coordinates=coordinates,
    types=types)
"""
        # Check the script.
        self.assertEqual(local_config._script(), ref_script)

        # Get another script.
        coords = [[1.0, 2.0, 3.0], [1.0, 1.0, 3.0], [3.0, 8.0, 9.0]]
        types = ["C", "B", "A"]
        local_config = KMCLocalConfiguration(coordinates=coords,
                                             types=types,
                                             center=0)
        ref_script2 = """
# -----------------------------------------------------------------------------
# Local configuration

coordinates = [[   0.000000e+00,   0.000000e+00,   0.000000e+00],
               [   0.000000e+00,  -1.000000e+00,   0.000000e+00],
               [   2.000000e+00,   6.000000e+00,   6.000000e+00]]

types = [[(1, 'C')], [(1, 'B')], [(1, 'A')]]

local_config2 = KMCLocalConfiguration(
    coordinates=coordinates,
    types=types)
"""
        # Check.
        self.assertEqual(local_config._script(variable_name="local_config2"),
                         ref_script2)
예제 #11
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)
예제 #12
0
    def __init__(self,
                 coordinates=None,
                 minimum_match=None,
                 update=None,
                 basis_sites=None,
                 rate_constant=None):
        """
        Constructor for the KMCBucketProcess.

        :param coordinates:   The local coordinates, corresponding to the lattice
                              positions of the surrounding of the center where
                              the process will be preformed.

        :param minimum_match: The list of minimal occupations to match.

        :param update:        List of positive and negative changes in occupations
                              due to performing the process.

        :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
        """
        # Call the base class constructor.
        super(KMCBucketProcess, self).__init__(coordinates, basis_sites,
                                               rate_constant)

        # Check the minimum match.
        self.__minimum_match = [
            checkAndNormaliseBucketEntry(m) for m in minimum_match
        ]

        if not len(self.__minimum_match) == len(coordinates):
            raise Error(
                "The types 'match' information to a KMCBucketProcess constructor must be of the same length as the coordinates."
            )

        # Check the update information.
        self.__update = self.__checkUpdateInfo(update)

        # Construct elements before based on the match and update.
        self._elements_before = self.__minimum_match

        # Get all present types.
        all_types = []
        for e in self._elements_before:
            if isinstance(e, str):
                all_types.append(e)
            else:
                for ee in e:
                    if isinstance(ee, str):
                        all_types.append(ee)
                    elif isinstance(ee, tuple):
                        all_types.append(ee[1])

        # Remove doublets and store on the class.
        self._all_present_types = list(set(all_types))

        # We are not allowed to use move vectors with bucket processes.
        self._move_vectors = []

        # Setup the local configurations.
        center = 0
        c1 = KMCLocalConfiguration(self._coordinates, self._elements_before,
                                   center)
        self._local_configurations = (c1, )

        # To be updated later.
        self.__cpp_update = None