Пример #1
0
    def testConstruction(self):
        """ Test the construction of the unitcell """

        vector_a = [2.3, 0.0, 0.0]
        vector_b = [2.4, 3.0, 0.0]
        vector_c = [0.0, 0.0, 11.8]

        basis_points = [[0.0, 0.0, 0.0],
                        [0.5, 0.5, 0.5]]

        cell_vectors = [vector_a,
                        vector_b,
                        vector_c]

        cell = KMCUnitCell(cell_vectors=cell_vectors,
                           basis_points=basis_points)

        # Check the vectors stored on the class.
        ref_vectors = numpy.array(cell_vectors)
        check_vectors = cell._KMCUnitCell__cell_vectors
        self.assertAlmostEqual( numpy.linalg.norm(ref_vectors - check_vectors), 0.0, 10)

        # Check via the query function.
        ret_vectors = cell.cellVectors()
        self.assertAlmostEqual( numpy.linalg.norm(ref_vectors - ret_vectors), 0.0, 10)

        # Check the basis points stored on the class.
        ref_basis = numpy.array(basis_points)
        check_basis = cell._KMCUnitCell__basis_points
        self.assertAlmostEqual( numpy.linalg.norm(ref_basis - check_basis), 0.0, 10)
Пример #2
0
    def testConstructionFailBasis2(self):
        """ Make sure construction fails if there is a problem with the basis points. """
        vector_a = [2.3, 0.0, 0.0]
        vector_b = [2.4, 3.0, 0.0]
        vector_c = [0.0, 0.0, 11.8]
        basis_points = [
            [0.0, 0.0, 1.1],  # <- too large value
            [0.5, 0.5, 0.5]
        ]
        cell_vectors = [vector_a, vector_b, vector_c]
        self.assertRaises(
            Error, lambda: KMCUnitCell(cell_vectors=cell_vectors,
                                       basis_points=basis_points))

        vector_a = [2.3, 0.0, 0.0]
        vector_b = [2.4, 3.0, 0.0]
        vector_c = [0.0, 0.0, 11.8]
        basis_points = [
            [0.0, 0.0, 1.0],  # <- too large value
            [0.5, 0.5, 0.5]
        ]
        cell_vectors = [vector_a, vector_b, vector_c]
        self.assertRaises(
            Error, lambda: KMCUnitCell(cell_vectors=cell_vectors,
                                       basis_points=basis_points))

        vector_a = [2.3, 0.0, 0.0]
        vector_b = [2.4, 3.0, 0.0]
        vector_c = [0.0, 0.0, 11.8]
        basis_points = [[0.0, 0.0, 0.999999], [0.5, 0.5,
                                               -0.01]]  # <- too small value
        cell_vectors = [vector_a, vector_b, vector_c]
        self.assertRaises(
            Error, lambda: KMCUnitCell(cell_vectors=cell_vectors,
                                       basis_points=basis_points))
Пример #3
0
    def testConstruction(self):
        """ Test the construction of the unitcell """

        vector_a = [2.3, 0.0, 0.0]
        vector_b = [2.4, 3.0, 0.0]
        vector_c = [0.0, 0.0, 11.8]

        basis_points = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]]

        cell_vectors = [vector_a, vector_b, vector_c]

        cell = KMCUnitCell(cell_vectors=cell_vectors,
                           basis_points=basis_points)

        # Check the vectors stored on the class.
        ref_vectors = numpy.array(cell_vectors)
        check_vectors = cell._KMCUnitCell__cell_vectors
        self.assertAlmostEqual(numpy.linalg.norm(ref_vectors - check_vectors),
                               0.0, 10)

        # Check via the query function.
        ret_vectors = cell.cellVectors()
        self.assertAlmostEqual(numpy.linalg.norm(ref_vectors - ret_vectors),
                               0.0, 10)

        # Check the basis points stored on the class.
        ref_basis = numpy.array(basis_points)
        check_basis = cell._KMCUnitCell__basis_points
        self.assertAlmostEqual(numpy.linalg.norm(ref_basis - check_basis), 0.0,
                               10)
Пример #4
0
    def testTransformToCartesian(self):
        """
        Test the transformation from internal to cartesian coordinates.
        """
        # Setup a simple reference system.
        a = numpy.array([[1.0, 2.0, 3.0], [1.1, 0.4, 3.7], [1.2, 2.5, 0.8]])

        r = numpy.array([[1.2, 2.5, 3.8], [3.2, 4.5, 5.8]])

        ref_xyz = numpy.dot(r, a)

        # Cell vectors.
        vector_a = [1.0, 2.0, 3.0]
        vector_b = [1.1, 0.4, 3.7]
        vector_c = [1.2, 2.5, 0.8]

        cell_vectors = [vector_a, vector_b, vector_c]

        cell = KMCUnitCell(cell_vectors=cell_vectors,
                           basis_points=[[0.0, 0.0, 0.0]])

        # Transform r to cartesian coordinates.
        xyz = cell.transformToCartesian(r)
        diff = numpy.linalg.norm(xyz - ref_xyz)
        self.assertAlmostEqual(diff, 0.0, 10)
Пример #5
0
    def testTransformToCartesian(self):
        """
        Test the transformation from internal to cartesian coordinates.
        """
        # Setup a simple reference system.
        a = numpy.array([[1.0, 2.0, 3.0],
                         [1.1, 0.4, 3.7],
                         [1.2, 2.5, 0.8]])

        r = numpy.array([[1.2, 2.5, 3.8],
                         [3.2, 4.5, 5.8]])

        ref_xyz = numpy.dot(r, a)

        # Cell vectors.
        vector_a = [1.0, 2.0, 3.0]
        vector_b = [1.1, 0.4, 3.7]
        vector_c = [1.2, 2.5, 0.8]

        cell_vectors = [vector_a,
                        vector_b,
                        vector_c]

        cell = KMCUnitCell(cell_vectors=cell_vectors,
                           basis_points=[[0.0, 0.0, 0.0]])

        # Transform r to cartesian coordinates.
        xyz = cell.transformToCartesian(r)
        diff = numpy.linalg.norm(xyz - ref_xyz)
        self.assertAlmostEqual(diff, 0.0, 10)
Пример #6
0
    def testGlobalIndex(self):
        """ Test that the global index function returns correct values. """
        cell_vectors = [[2.3, 0.0, 0.0], [2.4, 3.0, 0.0], [0.0, 0.0, 11.8]]

        basis_points = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.0]]

        unit_cell = KMCUnitCell(cell_vectors=cell_vectors,
                                basis_points=basis_points)

        # Setup the repetitions.
        nI = 2
        nJ = 12
        nK = 3
        nB = 2
        repetitions = (nI, nJ, nK)
        periodic = (True, True, False)

        # Construct the KMCLattice object.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=repetitions,
                             periodic=periodic)

        # Loop through all indices and check that the globalIndex function computes them correctly.
        increment = 0
        for i in range(nI):
            for j in range(nJ):
                for k in range(nK):
                    for b in range(nB):
                        index = lattice._globalIndex(i, j, k, b)
                        self.assertEqual(index, increment)
                        increment += 1
Пример #7
0
    def testConstructionFailPeriodic(self):
        """ Test that construction of the lattice fails if the periodic parameter is incorrect."""
        # Setup a valid unitcell.
        cell_vectors = [[2.3, 0.0, 0.0], [2.4, 3.0, 0.0], [0.0, 0.0, 11.8]]

        basis_points = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.0]]

        unit_cell = KMCUnitCell(cell_vectors=cell_vectors,
                                basis_points=basis_points)

        repetitions = (10, 12, 45)

        # Fail because of not being a sequence.
        periodic = True
        self.assertRaises(
            Error, lambda: KMCLattice(unit_cell=unit_cell,
                                      repetitions=repetitions,
                                      periodic=periodic))

        # Fail because of wrong length.
        periodic = (True, True, True, True)
        self.assertRaises(
            Error, lambda: KMCLattice(unit_cell=unit_cell,
                                      repetitions=repetitions,
                                      periodic=periodic))

        # Fail because of wrong type.
        periodic = (True, True, 1)
        self.assertRaises(
            Error, lambda: KMCLattice(unit_cell=unit_cell,
                                      repetitions=repetitions,
                                      periodic=periodic))
Пример #8
0
    def testLatticeQuery(self):
        """ Test the query function for the lattice. """
        # Setup a valid KMCUnitCell.
        unit_cell = KMCUnitCell(cell_vectors=numpy.array([[2.8, 0.0, 0.0],
                                                          [0.0, 3.2, 0.0],
                                                          [0.0, 0.5, 3.0]]),
                                basis_points=[[0.0, 0.0, 0.0], [0.5, 0.5, 0.5],
                                              [0.25, 0.25, 0.75]])

        # Setup the lattice.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=(4, 4, 1),
                             periodic=(True, True, False))

        types = [
            'a', 'a', 'a', 'a', 'b', 'b', 'a', 'a', 'a', 'b', 'b', 'b', 'b',
            'b', 'a', 'a', 'b', 'a', 'b', 'b', 'b', 'a', 'b', 'a', 'b', 'a',
            'a', 'a', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'a', 'a', 'a',
            'a', 'b', 'b', 'b', 'b', 'a', 'b', 'b', 'a'
        ]

        # Setup the configuration.
        config = KMCConfiguration(lattice=lattice,
                                  types=types,
                                  possible_types=['a', 'c', 'b'])

        # Query for the lattice.
        ret_lattice = config.lattice()

        # Check by reference.
        self.assertTrue(lattice == ret_lattice)
Пример #9
0
    def testLatticeMap(self):
        """ Check that we can get a valid lattice map out. """
        cell_vectors = [[2.3, 0.0, 0.0], [2.4, 3.0, 0.0], [0.0, 0.0, 11.8]]

        basis_points = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.0]]

        unit_cell = KMCUnitCell(cell_vectors=cell_vectors,
                                basis_points=basis_points)

        # Setup the repetitions.
        nI = 2
        nJ = 12
        nK = 3
        nB = 2
        repetitions = (nI, nJ, nK)
        periodic = (True, True, False)

        # Construct the KMCLattice object.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=repetitions,
                             periodic=periodic)

        # Get the lattice map.
        cpp_lattice_map = lattice._map()

        # Check the type.
        self.assertTrue(isinstance(cpp_lattice_map, Backend.LatticeMap))

        # Get it again and check that we get the same instance.
        cpp_lattice_map2 = lattice._map()

        # Check the instance.
        self.assertTrue(cpp_lattice_map == cpp_lattice_map2)
Пример #10
0
    def testConstruction(self):
        """ Test that the XYZTrajectory object can be constructed. """
        filename = "abc123.xyz"
        name = os.path.abspath(os.path.dirname(__file__))
        name = os.path.join(name, "..", "..")
        name = os.path.join(name, "TestUtilities", "Scratch")
        filename = os.path.join(name, filename)

        if MPICommons.isMaster():
            self.__files_to_remove.append(filename)

        unit_cell = KMCUnitCell(cell_vectors=[[1.0, 0.0, 0.0],
                                              [0.0, 1.0, 0.0],
                                              [0.0, 0.0, 1.0]],
                                basis_points=[[0.0, 0.0, 0.0]])
        lattice = KMCLattice(unit_cell=unit_cell,
                             periodic=(True, True, True),
                             repetitions=(4,4,4))

        config = KMCConfiguration(lattice=lattice,
                                 types=["A","B","C","D"]*16)

        t = XYZTrajectory(trajectory_filename=filename,
                          configuration=config,
                          max_buffer_size=12345,
                          max_buffer_time=123.0)

        # Check that the internal memory buffers have been initiated.
        self.assertEqual(t._XYZTrajectory__atom_id_types, [])
        self.assertEqual(t._XYZTrajectory__atom_id_coordinates, [])
        self.assertEqual(t._XYZTrajectory__time, [])
        self.assertEqual(t._XYZTrajectory__step, [])
Пример #11
0
    def testLatticeMap(self):
        """ Make sure the lattice map we get correspond to the lattice we give. """
        # Setup a valid KMCUnitCell.
        unit_cell = KMCUnitCell(cell_vectors=numpy.array([[2.8, 0.0, 0.0],
                                                          [0.0, 3.2, 0.0],
                                                          [0.0, 0.5, 3.0]]),
                                basis_points=[[0.0, 0.0, 0.0], [0.5, 0.5, 0.5],
                                              [0.25, 0.25, 0.75]])

        # Setup the lattice.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=(4, 4, 1),
                             periodic=(True, True, False))

        types = [
            'a', 'a', 'a', 'a', 'b', 'b', 'a', 'a', 'a', 'b', 'b', 'b', 'b',
            'b', 'a', 'a', 'b', 'a', 'b', 'b', 'b', 'a', 'b', 'a', 'b', 'a',
            'a', 'a', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'a', 'a', 'a',
            'a', 'b', 'b', 'b', 'b', 'a', 'b', 'b', 'a'
        ]

        # Setup the configuration.
        config = KMCConfiguration(lattice=lattice,
                                  types=types,
                                  possible_types=['a', 'c', 'b'])

        # Get the lattice map.
        cpp_lattice_map = config._latticeMap()

        # Get the map from the lattice.
        cpp_lattice_map_ref = lattice._map()

        # Check that these two are references to the same underlying object.
        self.assertTrue(cpp_lattice_map == cpp_lattice_map_ref)
Пример #12
0
    def notestTypesBucketFormat(self):
        """ Test that the configuration accepts the bucket input format. """
        # Define the unit cell.
        unit_cell = KMCUnitCell(cell_vectors=numpy.array([[2.1, 0.0, 0.0],
                                                          [0.0, 1.0, 0.0],
                                                          [0.0, 0.0, 1.0]]),
                                basis_points=[[0.0, 0.0, 0.0]])

        # And a lattice.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=(10, 1, 1),
                             periodic=(True, False, False))

        # Populate the lattice with types.
        types = [(2, "A"), "B", ["B", "B", "A"], ["B", (2, "A")], "B", "empty",
                 [(3, "A")], [(1, "B"), "A"], [(2, "A")], "empty"]

        # Setup the configuration.
        config = KMCConfiguration(lattice=lattice,
                                  types=types,
                                  possible_types=['A', 'B', 'empty'])

        # Retrieve the types information from the configuration backend.
        # FXME: NEEDS IMPLEMENTATION
        print config.types()
Пример #13
0
    def testQueryUnitCell(self):
        """ Test that the unitcell query function returns correctly. """
        cell_vectors = [[2.3, 0.0, 0.0], [2.4, 3.0, 0.0], [0.0, 0.0, 11.8]]

        basis_points = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.0]]

        unit_cell = KMCUnitCell(cell_vectors=cell_vectors,
                                basis_points=basis_points)

        # Setup the repetitions.
        nI = 2
        nJ = 12
        nK = 3
        nB = 2
        repetitions = (nI, nJ, nK)
        periodic = (True, True, False)

        # Construct the KMCLattice object.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=repetitions,
                             periodic=periodic)

        # Query.
        ret_unit_cell = lattice.unitCell()

        # Test by reference.
        self.assertTrue(unit_cell == ret_unit_cell)
Пример #14
0
    def testConstructionLongFormat(self):
        """ Test that the KMCConfiguration class can be constructed with the long types format. """

        # Setup a valid KMCUnitCell.
        unit_cell = KMCUnitCell(cell_vectors=numpy.array([[2.8, 0.0, 0.0],
                                                          [0.0, 3.2, 0.0],
                                                          [0.0, 0.5, 3.0]]),
                                basis_points=[[0.0, 0.0, 0.0], [0.5, 0.5, 0.5],
                                              [0.25, 0.25, 0.75]])

        # Setup the lattice.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=(4, 3, 2),
                             periodic=(True, True, False))

        types = [(0, 0, 0, 0, 'g'), (3, 2, 1, 2, 'h')]
        default_type = 'a'

        # Setup the configuration.
        config = KMCConfiguration(lattice=lattice,
                                  types=types,
                                  default_type=default_type)

        # Get the types information out.
        ret_types = config.types()

        ref_types = [
            'g', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
            'a', 'a', 'a', 'a', 'a', 'a', 'h'
        ]

        # Check that they are what we inserted.
        self.assertEqual(ref_types, ret_types)

        # Check that the possible types are what we expect.
        self.assertEqual(set(['a', 'g', 'h', '*']),
                         set(config._KMCConfiguration__possible_types))

        # Check that the number of lattice sites corresponds
        # to the lattice.
        self.assertEqual(config._KMCConfiguration__n_lattice_sites,
                         len(lattice.sites()))

        # Construct again, now with a list of possible types.
        config = KMCConfiguration(lattice=lattice,
                                  types=types,
                                  default_type=default_type,
                                  possible_types=['aa', 'a', 'h', 'g'])

        # Check that the possible types are what we expect.
        self.assertEqual(set(['aa', 'a', 'g', 'h', '*']),
                         set(config._KMCConfiguration__possible_types))
Пример #15
0
 def testConstructionFailVectors(self):
     """ Make sure construction fails if there is a problem with the unitcell vectors. """
     vector_a = [2.3, 0.0, 0.0]
     vector_b = [2.4, 3.0, 0.0, 1.3]  # <- wrong shape
     vector_c = [0.0, 0.0, 11.8]
     basis_points = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]]
     cell_vectors = [vector_a, vector_b, vector_c]
     self.assertRaises(
         Error, lambda: KMCUnitCell(cell_vectors=cell_vectors,
                                    basis_points=basis_points))
Пример #16
0
    def testConstructionShortFormat(self):
        """ Test that the KMCConfiguration class can be constructed. """

        # Setup a valid KMCUnitCell.
        unit_cell = KMCUnitCell(cell_vectors=numpy.array([[2.8, 0.0, 0.0],
                                                          [0.0, 3.2, 0.0],
                                                          [0.0, 0.5, 3.0]]),
                                basis_points=[[0.0, 0.0, 0.0], [0.5, 0.5, 0.5],
                                              [0.25, 0.25, 0.75]])

        # Setup the lattice.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=(4, 4, 1),
                             periodic=(True, True, False))

        types = [
            'a', 'a', 'a', 'a', 'b', 'b', 'a', 'a', 'a', 'b', 'b', 'b', 'b',
            'b', 'a', 'a', 'b', 'a', 'b', 'b', 'b', 'a', 'b', 'a', 'b', 'a',
            'a', 'a', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'a', 'a', 'a',
            'a', 'b', 'b', 'b', 'b', 'a', 'b', 'b', 'a'
        ]

        # Setup the configuration.
        config = KMCConfiguration(lattice=lattice,
                                  types=types,
                                  possible_types=['a', 'c', 'b'])

        # Get the types information out.
        ret_types = config.types()

        # Check that they are what we inserted.
        self.assertEqual(types, ret_types)

        # Check that the possible types are what we expect.
        self.assertEqual(set(['a', 'c', 'b', '*']),
                         set(config._KMCConfiguration__possible_types.keys()))

        # Check that the number of lattice sites corresponds to the lattice.
        self.assertEqual(config._KMCConfiguration__n_lattice_sites,
                         len(lattice.sites()))

        # Check that the lattice site can be returned from the configuration.
        self.assertAlmostEqual(
            numpy.linalg.norm(
                numpy.array(config.sites()) - numpy.array(lattice.sites())),
            0.0, 10)

        # Construct without possible types and check that the list is set correctly
        # from the given types.
        config = KMCConfiguration(lattice=lattice, types=types)
        self.assertEqual(set(['a', 'b', '*']),
                         set(config._KMCConfiguration__possible_types.keys()))
Пример #17
0
    def testQueryLatticeSites(self):
        """ Test that the returned lattice site data is coorect. """
        cell_vectors = [[2.3, 0.0, 0.0], [2.4, 3.0, 0.0], [0.0, 0.0, 11.8]]

        basis_points = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.0]]

        unit_cell = KMCUnitCell(cell_vectors=cell_vectors,
                                basis_points=basis_points)

        # Setup the other input.
        repetitions = (2, 1, 1)
        periodic = (True, True, False)

        # Construct the KMCLattice object.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=repetitions,
                             periodic=periodic)

        # These are all the sites in the lattice, given in
        # the fractional coordinates of the original cell.
        sites = lattice.sites()
        ref_sites = numpy.array([[0., 0., 0.], [0.5, 0.5, 0.], [1., 0., 0.],
                                 [1.5, 0.5, 0.]])

        # Check against a hardcoded reference.
        self.assertAlmostEqual(numpy.linalg.norm(sites - ref_sites), 0.0, 10)

        # Test with another repetition.
        repetitions = (2, 3, 4)
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=repetitions,
                             periodic=periodic)
        sites = lattice.sites()
        ref_sites = numpy.array([[0., 0., 0.], [0.5, 0.5, 0.], [0., 0., 1.],
                                 [0.5, 0.5, 1.], [0., 0., 2.], [0.5, 0.5, 2.],
                                 [0., 0., 3.], [0.5, 0.5, 3.], [0., 1., 0.],
                                 [0.5, 1.5, 0.], [0., 1., 1.], [0.5, 1.5, 1.],
                                 [0., 1., 2.], [0.5, 1.5, 2.], [0., 1., 3.],
                                 [0.5, 1.5, 3.], [0., 2., 0.], [0.5, 2.5, 0.],
                                 [0., 2., 1.], [0.5, 2.5, 1.], [0., 2., 2.],
                                 [0.5, 2.5, 2.], [0., 2., 3.], [0.5, 2.5, 3.],
                                 [1., 0., 0.], [1.5, 0.5, 0.], [1., 0., 1.],
                                 [1.5, 0.5, 1.], [1., 0., 2.], [1.5, 0.5, 2.],
                                 [1., 0., 3.], [1.5, 0.5, 3.], [1., 1., 0.],
                                 [1.5, 1.5, 0.], [1., 1., 1.], [1.5, 1.5, 1.],
                                 [1., 1., 2.], [1.5, 1.5, 2.], [1., 1., 3.],
                                 [1.5, 1.5, 3.], [1., 2., 0.], [1.5, 2.5, 0.],
                                 [1., 2., 1.], [1.5, 2.5, 1.], [1., 2., 2.],
                                 [1.5, 2.5, 2.], [1., 2., 3.], [1.5, 2.5, 3.]])

        # Check against a hardcoded reference.
        self.assertAlmostEqual(numpy.linalg.norm(sites - ref_sites), 0.0, 10)
Пример #18
0
    def testScript(self):
        """ Test that a valid script can be generated. """
        # Setup a valid cell.
        vector_a = [2.3, 1.0, 0.1]
        vector_b = [2.4, 3.0, 0.0]
        vector_c = [0.4, 0.3, 11.8]
        basis_points = [[0.4, 0.3, 0.2], [0.2, 0.33, 0.11], [0.6, 0.5, 0.1]]
        cell_vectors = [vector_a, vector_b, vector_c]
        cell = KMCUnitCell(cell_vectors=cell_vectors,
                           basis_points=basis_points)

        # Get the script.
        script = cell._script()

        # Check against the known reference script.
        ref_script = """
# -----------------------------------------------------------------------------
# Unit cell

cell_vectors = [[   2.300000e+00,   1.000000e+00,   1.000000e-01],
                [   2.400000e+00,   3.000000e+00,   0.000000e+00],
                [   4.000000e-01,   3.000000e-01,   1.180000e+01]]

basis_points = [[   4.000000e-01,   3.000000e-01,   2.000000e-01],
                [   2.000000e-01,   3.300000e-01,   1.100000e-01],
                [   6.000000e-01,   5.000000e-01,   1.000000e-01]]

unit_cell = KMCUnitCell(
    cell_vectors=cell_vectors,
    basis_points=basis_points)
"""
        self.assertEqual(script, ref_script)

        # Setup another valid cell.
        vector_a = [2.3, 1.0, 0.1]
        vector_b = [2.4, 3.0, 0.0]
        vector_c = [0.4, 0.3, 11.8]
        basis_points = [[0.4, 0.3, 0.2]]
        cell_vectors = [vector_a, vector_b, vector_c]
        cell = KMCUnitCell(cell_vectors=cell_vectors,
                           basis_points=basis_points)
        script = cell._script(variable_name="CELL_NAME_HERE")

        # Check against the known reference.
        ref_script = """
# -----------------------------------------------------------------------------
# Unit cell

cell_vectors = [[   2.300000e+00,   1.000000e+00,   1.000000e-01],
                [   2.400000e+00,   3.000000e+00,   0.000000e+00],
                [   4.000000e-01,   3.000000e-01,   1.180000e+01]]

basis_points = [[   4.000000e-01,   3.000000e-01,   2.000000e-01]]

CELL_NAME_HERE = KMCUnitCell(
    cell_vectors=cell_vectors,
    basis_points=basis_points)
"""
        self.assertEqual(script, ref_script)
Пример #19
0
    def testWriteHeader(self):
        """ Test the header output. """
        # Get a file name.
        name = os.path.abspath(os.path.dirname(__file__))
        name = os.path.join(name, "..", "..")
        name = os.path.join(name, "TestUtilities", "Scratch")
        trajectory_filename = os.path.join(name, "tmp_trajectory.xyz")

        if MPICommons.isMaster():
            self.__files_to_remove.append(trajectory_filename)

        # Setup the trajectory object.
        unit_cell = KMCUnitCell(cell_vectors=[[1.0, 0.0, 0.0],
                                              [0.0, 1.0, 0.0],
                                              [0.0, 0.0, 1.0]],
                                basis_points=[[0.0, 0.0, 0.0]])
        lattice = KMCLattice(unit_cell=unit_cell,
                             periodic=(True, True, True),
                             repetitions=(4,2,3))

        config = KMCConfiguration(lattice=lattice,
                                 types=["A","B","C"]*8)

        t = XYZTrajectory(trajectory_filename=trajectory_filename,
                          configuration=config,
                          max_buffer_size=12345,
                          max_buffer_time=123.0)

        if MPICommons.isMaster():

            # Check that the header was written.
            self.assertTrue(os.path.exists(trajectory_filename))

            # Check the content of the header.
            with open(trajectory_filename, "r") as f:
                content = f.read()

            ref_content = """KMCLib XYZ FORMAT VERSION 2013.10.15

CELL VECTORS
a: 1.0000000000e+00 0.0000000000e+00 0.0000000000e+00
b: 0.0000000000e+00 1.0000000000e+00 0.0000000000e+00
c: 0.0000000000e+00 0.0000000000e+00 1.0000000000e+00

REPETITIONS 4 2 3

PERIODICITY True True True

"""
            self.assertEqual( content, ref_content )
Пример #20
0
    def testQueryRepetitionsAndPeriodic(self):
        """ Test that the returned repetitions data is coorect. """
        cell_vectors = [[2.3, 0.0, 0.0], [2.4, 3.0, 0.0], [0.0, 0.0, 11.8]]

        basis_points = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.0]]

        unit_cell = KMCUnitCell(cell_vectors=cell_vectors,
                                basis_points=basis_points)

        # Setup the repetitions.
        repetitions = (2, 1, 1)
        periodic = (True, True, False)

        # Construct the KMCLattice object.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=repetitions,
                             periodic=periodic)

        # Check that the repetitions are the same.
        self.assertEqual(lattice.repetitions()[0], repetitions[0])
        self.assertEqual(lattice.repetitions()[1], repetitions[1])
        self.assertEqual(lattice.repetitions()[2], repetitions[2])

        # Check that the periodic is the same.
        self.assertTrue(lattice.periodic()[0])
        self.assertTrue(lattice.periodic()[1])
        self.assertFalse(lattice.periodic()[2])

        # Setup again with different periodicity and check.
        periodic = (True, False, True)

        # Construct the KMCLattice object.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=repetitions,
                             periodic=periodic)
        self.assertTrue(lattice.periodic()[0])
        self.assertFalse(lattice.periodic()[1])
        self.assertTrue(lattice.periodic()[2])

        # And again.
        periodic = (False, True, True)

        # Construct the KMCLattice object.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=repetitions,
                             periodic=periodic)
        self.assertFalse(lattice.periodic()[0])
        self.assertTrue(lattice.periodic()[1])
        self.assertTrue(lattice.periodic()[2])
Пример #21
0
    def testGetScriptComponent(self):
        """ Test the general get script component function. """
        # Set the path to the file to read from.
        module_path = os.path.abspath(os.path.dirname(__file__))
        script_file_path = os.path.join(module_path, "..", "TestUtilities",
                                        "Scripts")
        script_file_path = os.path.join(script_file_path,
                                        "kmc_configuration_script.py")
        # Make sure the file exists.
        self.assertTrue(os.path.exists(script_file_path))

        # Get the KMCLattice out of this script.
        lattice = getScriptComponent(script_file_path, KMCLattice)

        # Check that it is the correct lattice by cheking its values
        # against these known references.
        unit_cell = KMCUnitCell(cell_vectors=[[2.8, 0.0, 0.0], [0.0, 3.2, 0.0],
                                              [0.0, 0.5, 3.0]],
                                basis_points=[[0.0, 0.0, 0.0], [0.5, 0.5, 0.5],
                                              [0.25, 0.25, 0.75]])
        ref_lattice = KMCLattice(unit_cell=unit_cell,
                                 repetitions=(4, 4, 1),
                                 periodic=(True, True, False))

        self.assertEqual(lattice.repetitions(), ref_lattice.repetitions())
        self.assertEqual(lattice.periodic(), ref_lattice.periodic())
        self.assertAlmostEqual(
            numpy.linalg.norm(
                numpy.array(lattice.sites()) -
                numpy.array(ref_lattice.sites())), 0.0, 12)
        self.assertEqual(
            numpy.linalg.norm(
                numpy.array(lattice.basis()) -
                numpy.array(ref_lattice.basis())), 0.0, 12)

        # Check that the function returns None if no component of the correct type is found.
        self.assertTrue(
            (getScriptComponent(script_file_path, numpy.ndarray) is None))

        # Check that we fail in a controlled way if there is a problme with the file.
        self.assertRaises(
            Error, lambda: getScriptComponent("THIS IS NOT A VALID PATH", numpy
                                              .ndarray))
Пример #22
0
    def testConstruction(self):
        """ Test the construction of the lattice """
        # Setup a valid unitcell.
        cell_vectors = [[2.3, 0.0, 0.0], [2.4, 3.0, 0.0], [0.0, 0.0, 11.8]]

        basis_points = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.0]]

        unit_cell = KMCUnitCell(cell_vectors=cell_vectors,
                                basis_points=basis_points)

        # Setup the other input.
        repetitions = (10, 12, 45)
        periodic = (True, True, False)

        # Construct the KMCLattice object.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=repetitions,
                             periodic=periodic)

        # Check that the unitcell object stored on the class
        # is the same one as constructed here (checked by reference)
        self.assertTrue(unit_cell == lattice._KMCLattice__unit_cell)
Пример #23
0
    def testQueryBasis(self):
        """ Test that the returned basis data is coorect. """
        cell_vectors = [[2.3, 0.0, 0.0], [2.4, 3.0, 0.0], [0.0, 0.0, 11.8]]

        basis_points = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.0]]

        unit_cell = KMCUnitCell(cell_vectors=cell_vectors,
                                basis_points=basis_points)

        # Setup the repetitions.
        repetitions = (2, 1, 1)
        periodic = (True, True, False)

        # Construct the KMCLattice object.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=repetitions,
                             periodic=periodic)

        # Check that the basis is the one from the unitcell.
        self.assertAlmostEqual(
            numpy.linalg.norm(lattice.basis() -
                              lattice._KMCLattice__unit_cell.basis()), 0.0, 10)
Пример #24
0
    def testBackend(self):
        """ Make sure the C++ backend is what we expect. """
        # Setup a valid KMCUnitCell.
        unit_cell = KMCUnitCell(cell_vectors=numpy.array([[2.8, 0.0, 0.0],
                                                          [0.0, 3.2, 0.0],
                                                          [0.0, 0.5, 3.0]]),
                                basis_points=[[0.0, 0.0, 0.0], [0.5, 0.5, 0.5],
                                              [0.25, 0.25, 0.75]])

        # Setup the lattice.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=(4, 4, 1),
                             periodic=(True, True, False))

        types = [
            'a', 'a', 'a', 'a', 'b', 'b', 'a', 'a', 'a', 'b', 'b', 'b', 'b',
            'b', 'a', 'a', 'b', 'a', 'b', 'b', 'b', 'a', 'b', 'a', 'b', 'a',
            'a', 'a', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'a', 'a', 'a',
            'a', 'b', 'b', 'b', 'b', 'a', 'b', 'b', 'a'
        ]

        # Setup the configuration.
        config = KMCConfiguration(lattice=lattice,
                                  types=types,
                                  possible_types=['a', 'c', 'b'])

        # Make sure that the backend stored on the config is None.
        self.assertTrue(config._KMCConfiguration__backend is None)

        # Query for the backend.
        cpp_backend = config._backend()

        # Check that the backend on the class is returned.
        self.assertTrue(config._KMCConfiguration__backend == cpp_backend)

        # Check the type of the cpp backend.
        self.assertTrue(isinstance(cpp_backend, Backend.Configuration))
Пример #25
0
    def testCalculation(self):
        """ Test a calculation with the on-the-fly MSD analysis. """
        # Setup a system, a periodic 10 atoms long 1D chain.
        unit_cell = KMCUnitCell(cell_vectors=numpy.array([[1.0,0.0,0.0],
                                                          [0.0,1.0,0.0],
                                                          [0.0,0.0,1.0]]),
                                basis_points=[[0.0,0.0,0.0]])

        # And a lattice.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=(10,10,10),
                             periodic=(True,True,True))

        # Setup an initial configuration with one B in a sea of A:s.
        types = ["A"]*10*10*10
        types[5] = "B"

        config = KMCConfiguration(lattice=lattice,
                                  types=types,
                                  possible_types=["A","B"])

        # Setup a diffusion process to the left.
        coordinates_p0 = [[0.0, 0.0, 0.0],[-1.0, 0.0, 0.0]]
        p0 = KMCProcess(coordinates=coordinates_p0,
                        elements_before=["B","A"],
                        elements_after=["A","B"],
                        move_vectors=None,
                        basis_sites=[0],
                        rate_constant=1.0)

        coordinates_p1 = [[0.0, 0.0, 0.0],[1.0, 0.0, 0.0]]
        p1 = KMCProcess(coordinates=coordinates_p1,
                        elements_before=["B","A"],
                        elements_after=["A","B"],
                        move_vectors=None,
                        basis_sites=[0],
                        rate_constant=1.0)

        coordinates_p2 = [[0.0, 0.0, 0.0],[0.0,-1.0, 0.0]]
        p2 = KMCProcess(coordinates=coordinates_p2,
                        elements_before=["B","A"],
                        elements_after=["A","B"],
                        move_vectors=None,
                        basis_sites=[0],
                        rate_constant=1.0)

        coordinates_p3 = [[0.0, 0.0, 0.0],[0.0, 1.0, 0.0]]
        p3 = KMCProcess(coordinates=coordinates_p3,
                        elements_before=["B","A"],
                        elements_after=["A","B"],
                        move_vectors=None,
                        basis_sites=[0],
                        rate_constant=1.0)

        coordinates_p4 = [[0.0, 0.0, 0.0],[0.0, 0.0,-1.0]]
        p4 = KMCProcess(coordinates=coordinates_p4,
                        elements_before=["B","A"],
                        elements_after=["A","B"],
                        move_vectors=None,
                        basis_sites=[0],
                        rate_constant=1.0)

        coordinates_p5 = [[0.0, 0.0, 0.0],[0.0, 0.0, 1.0]]
        p5 = KMCProcess(coordinates=coordinates_p5,
                        elements_before=["B","A"],
                        elements_after=["A","B"],
                        move_vectors=None,
                        basis_sites=[0],
                        rate_constant=1.0)

        interactions = KMCInteractions(processes=[p0, p1, p2, p3, p4, p5],
                                       implicit_wildcards=True)

        model = KMCLatticeModel(configuration=config,
                                interactions=interactions)

        # Setup the analysis.
        msd = OnTheFlyMSD(history_steps=400,
                          n_bins=10,
                          t_max=25.0,
                          track_type="B")

        # Setup the control parameters.
        control_parameters = KMCControlParameters(number_of_steps=4000,
                                                  dump_interval=100,
                                                  analysis_interval=1,
                                                  seed=2013)
        # Run the model.
        model.run(control_parameters=control_parameters,
                  analysis=[msd])

        # Get the results out.
        results      = msd.results()
        time_steps   = msd.timeSteps()
        std_dev      = msd.stdDev()
        bin_counters = msd.binCounters()

        # Compare against references.
        ref_results = numpy.array([[   2.77712331 ,   8.22333156 ,  14.21578638 ,  21.11949845 ,  27.57598537,
                                       33.81520414,   40.5640313 ,   47.35067074,   54.83134718,   63.0006103 ],
                                   [   2.80810946 ,   8.48503234 ,  13.7997313  ,  17.62812205 ,  22.37202018,
                                       29.12157221,   35.40750463,   41.44944591,   48.94392653,   56.67111894],
                                   [   2.98786918 ,   8.65022668 ,  14.01808716 ,  18.62678885 ,  22.65708384,
                                       26.03107861,   30.03937616,   35.1483    ,   40.68319007,   47.21074474],
                                   [   5.58523277 ,  16.70836389 ,  28.01551768 ,  38.74762049 ,  49.94800555,
                                       62.93677636,   75.97153593,   88.80011665,  103.77527371,  119.67172924],
                                   [   5.76499249 ,  16.87355824 ,  28.23387354 ,  39.7462873  ,  50.23306921,
                                       59.84628275,   70.60340745,   82.49897073,   95.51453725,  110.21135504],
                                   [   5.79597864 ,  17.13525902 ,  27.81781846 ,  36.2549109  ,  45.02910402,
                                       55.15265082,   65.44688079,   76.59774591,   89.62711659,  103.88186368],
                                   [   8.57310195 ,  25.35859057 ,  42.03360484 ,  57.37440934 ,  72.60508939,
                                       88.96785497,  106.01091209,  123.94841665,  144.45846377,  166.88247398]])

        diff = numpy.linalg.norm(ref_results - results)
        self.assertAlmostEqual(diff, 0.0, 6)

        ref_time_steps = numpy.array([  1.25,   3.75,   6.25,   8.75,  11.25,  13.75,  16.25,  18.75,  21.25,  23.75])
        diff = numpy.linalg.norm(ref_time_steps - time_steps)
        self.assertAlmostEqual(diff, 0.0, 8)

        ref_std_dev = numpy.array( [[  0.14837207,   0.7305895 ,   1.61912818,   2.84016862,   4.19935234,
                                       5.69504607,   7.43238623,   9.31932103,  11.49445671,  13.97165319],
                                    [  0.15002755,   0.75383991,   1.57174096,   2.37064526,   3.40687718,
                                       4.90455993,   6.48757634,   8.15787162,  10.26025939,  12.5679611 ],
                                    [  0.15963149,   0.76851636,   1.59661093,   2.50494685,   3.45028752,
                                       4.38406911,   5.5039955 ,   6.91771175,   8.52853689,  10.46993274],
                                    [  0.21100039,   1.04965011,   2.25628521,   3.68460183,   5.37841647,
                                       7.49505328,   9.84289993,  12.35824143,  15.38290727,  18.76634124],
                                    [  0.2177914 ,   1.06002792,   2.27387093,   3.77956739,   5.40911222,
                                       7.12701069,   9.14740325,  11.48131598,  14.15839455,  17.28281115],
                                    [  0.218962  ,   1.07646844,   2.24036311,   3.44756425,   4.84874766,
                                       6.56805258,   8.47932177,  10.66004723,  13.28568526,  16.29025096],
                                    [  0.26444438,   1.30073885,   2.76405291,   4.45469653,   6.38348309,
                                       8.65082886,  11.21442742,  14.08440462,  17.48404426,  21.36747194]])

        diff = numpy.linalg.norm(ref_std_dev - std_dev)
        self.assertAlmostEqual(diff, 0.0, 6)

        ref_bin_counters = (59930, 59996, 59545, 59256, 59064, 59076, 58284, 58294, 57817, 57349)
        self.assertEqual(bin_counters, ref_bin_counters)
Пример #26
0
    def testFlush2(self):
        """ Test the file output. """
        # Get a file name.
        name = os.path.abspath(os.path.dirname(__file__))
        name = os.path.join(name, "..", "..")
        name = os.path.join(name, "TestUtilities", "Scratch")
        trajectory_filename = os.path.join(name, "tmp_trajectory.xyz")

        if MPICommons.isMaster():
            self.__files_to_remove.append(trajectory_filename)

        # Setup the trajectory object.
        unit_cell = KMCUnitCell(cell_vectors=[[1.0, 0.0, 0.0],
                                              [0.0, 1.0, 0.0],
                                              [0.0, 0.0, 1.0]],
                                basis_points=[[0.0, 0.0, 0.0]])
        lattice = KMCLattice(unit_cell=unit_cell,
                             periodic=(True, False, True),
                             repetitions=(4,4,4))

        config = KMCConfiguration(lattice=lattice,
                                 types=["A","B","C","D"]*16)

        t = XYZTrajectory(trajectory_filename=trajectory_filename,
                          configuration=config,
                          max_buffer_size=12345,
                          max_buffer_time=123.0)

        # Set data directly on the class.
        t._XYZTrajectory__atom_id_types = [("A","B","C","D","E"),
                                          ("This","is","the","next","step")]

        t._XYZTrajectory__atom_id_coordinates = [numpy.zeros((5,3)),
                                                numpy.ones((5,3))*1.234]

        t._XYZTrajectory__step = [0, 12]

        t._XYZTrajectory__time = [12.123,75.43]

        # Flush.
        t.flush()

        ref_content = """KMCLib XYZ FORMAT VERSION 2013.10.15

CELL VECTORS
a: 1.0000000000e+00 0.0000000000e+00 0.0000000000e+00
b: 0.0000000000e+00 1.0000000000e+00 0.0000000000e+00
c: 0.0000000000e+00 0.0000000000e+00 1.0000000000e+00

REPETITIONS 4 4 4

PERIODICITY True False True

STEP 0
          5
    TIME 1.2123000000e+01
                A   0.0000000000e+00 0.0000000000e+00 0.0000000000e+00  0
                B   0.0000000000e+00 0.0000000000e+00 0.0000000000e+00  1
                C   0.0000000000e+00 0.0000000000e+00 0.0000000000e+00  2
                D   0.0000000000e+00 0.0000000000e+00 0.0000000000e+00  3
                E   0.0000000000e+00 0.0000000000e+00 0.0000000000e+00  4
STEP 12
          5
    TIME 7.5430000000e+01
             This   1.2340000000e+00 1.2340000000e+00 1.2340000000e+00  0
               is   1.2340000000e+00 1.2340000000e+00 1.2340000000e+00  1
              the   1.2340000000e+00 1.2340000000e+00 1.2340000000e+00  2
             next   1.2340000000e+00 1.2340000000e+00 1.2340000000e+00  3
             step   1.2340000000e+00 1.2340000000e+00 1.2340000000e+00  4
"""

        if MPICommons.isMaster():
            with open(trajectory_filename, "r") as f:
                content = f.read()
            self.assertEqual( content, ref_content )

        # Check that the buffers are empty.
        self.assertEqual(t._XYZTrajectory__atom_id_types, [])
        self.assertEqual(t._XYZTrajectory__atom_id_coordinates, [])
        self.assertEqual(t._XYZTrajectory__time, [])
        self.assertEqual(t._XYZTrajectory__step, [])
Пример #27
0
    def testBufferSize(self):
        """ Test the buffer size function. """
        # Get a file name.
        name = os.path.abspath(os.path.dirname(__file__))
        name = os.path.join(name, "..", "..")
        name = os.path.join(name, "TestUtilities", "Scratch")
        trajectory_filename = os.path.join(name, "tmp_trajectory.xyz")

        if MPICommons.isMaster():
            self.__files_to_remove.append(trajectory_filename)

        # Setup the trajectory object.
        unit_cell = KMCUnitCell(cell_vectors=[[1.0, 0.0, 0.0],
                                              [0.0, 1.0, 0.0],
                                              [0.0, 0.0, 1.0]],
                                basis_points=[[0.0, 0.0, 0.0]])
        lattice = KMCLattice(unit_cell=unit_cell,
                             periodic=(True, True, True),
                             repetitions=(4,4,4))

        config = KMCConfiguration(lattice=lattice,
                                 types=["A","B","C","D"]*16)

        t = XYZTrajectory(trajectory_filename=trajectory_filename,
                          configuration=config,
                          max_buffer_size=12345,
                          max_buffer_time=123.0)

        # Store a bunch of data.
        simulation_time = 1.234
        step = 123
        t._storeData(simulation_time, step, config)
        buffer_size = t._bufferSize()

        # Check the size again.
        ref_size =  sys.getsizeof(t._XYZTrajectory__atom_id_coordinates)
        ref_size += sys.getsizeof(t._XYZTrajectory__atom_id_coordinates[0])*len(t._XYZTrajectory__atom_id_coordinates)
        ref_size += sys.getsizeof(t._XYZTrajectory__atom_id_types)
        ref_size += sys.getsizeof(t._XYZTrajectory__atom_id_types[0])*len(t._XYZTrajectory__atom_id_types)
        ref_size += sys.getsizeof(t._XYZTrajectory__time)
        ref_size += sys.getsizeof(t._XYZTrajectory__time[0])*len(t._XYZTrajectory__time)
        ref_size += sys.getsizeof(t._XYZTrajectory__step)
        ref_size += sys.getsizeof(t._XYZTrajectory__step[0])*len(t._XYZTrajectory__step)

        self.assertEqual(buffer_size, ref_size)

        # Store more data.
        t._storeData(simulation_time, step, config)

        # Check the size again.
        t._storeData(simulation_time, step, config)
        t._storeData(simulation_time, step, config)
        t._storeData(simulation_time, step, config)
        t._storeData(simulation_time, step, config)
        t._storeData(simulation_time, step, config)

        ref_size =  sys.getsizeof(t._XYZTrajectory__atom_id_coordinates)
        ref_size += sys.getsizeof(t._XYZTrajectory__atom_id_coordinates[0])*len(t._XYZTrajectory__atom_id_coordinates)
        ref_size += sys.getsizeof(t._XYZTrajectory__atom_id_types)
        ref_size += sys.getsizeof(t._XYZTrajectory__atom_id_types[0])*len(t._XYZTrajectory__atom_id_types)
        ref_size += sys.getsizeof(t._XYZTrajectory__time)
        ref_size += sys.getsizeof(t._XYZTrajectory__time[0])*len(t._XYZTrajectory__time)
        ref_size += sys.getsizeof(t._XYZTrajectory__step)
        ref_size += sys.getsizeof(t._XYZTrajectory__step[0])*len(t._XYZTrajectory__step)

        buffer_size = t._bufferSize()

        self.assertEqual(buffer_size, ref_size)
Пример #28
0
    def testFlush(self):
        """ Test the file output. """
        # Get a file name.
        name = os.path.abspath(os.path.dirname(__file__))
        name = os.path.join(name, "..", "..")
        name = os.path.join(name, "TestUtilities", "Scratch")
        trajectory_filename = os.path.join(name, "tmp_trajectory.xyz")

        if MPICommons.isMaster():
            self.__files_to_remove.append(trajectory_filename)

        # Setup the trajectory object.
        unit_cell = KMCUnitCell(cell_vectors=[[1.0, 0.0, 0.0],
                                              [0.0, 1.0, 0.0],
                                              [0.0, 0.0, 1.0]],
                                basis_points=[[0.0, 0.0, 0.0]])
        lattice = KMCLattice(unit_cell=unit_cell,
                             periodic=(True, False, True),
                             repetitions=(4,4,4))

        config = KMCConfiguration(lattice=lattice,
                                 types=["A","B","C","D"]*16)

        t = XYZTrajectory(trajectory_filename=trajectory_filename,
                          configuration=config,
                          max_buffer_size=12345,
                          max_buffer_time=123.0)

        # Store data.
        simulation_time = 1.234
        step = 123
        t._storeData(simulation_time, step, config)

        # Flush.
        t.flush()

        # Check the file.

        ref_content = """KMCLib XYZ FORMAT VERSION 2013.10.15

CELL VECTORS
a: 1.0000000000e+00 0.0000000000e+00 0.0000000000e+00
b: 0.0000000000e+00 1.0000000000e+00 0.0000000000e+00
c: 0.0000000000e+00 0.0000000000e+00 1.0000000000e+00

REPETITIONS 4 4 4

PERIODICITY True False True

STEP 123
          64
    TIME 1.2340000000e+00
                A   0.0000000000e+00 0.0000000000e+00 0.0000000000e+00  0
                B   0.0000000000e+00 0.0000000000e+00 1.0000000000e+00  1
                C   0.0000000000e+00 0.0000000000e+00 2.0000000000e+00  2
                D   0.0000000000e+00 0.0000000000e+00 3.0000000000e+00  3
                A   0.0000000000e+00 1.0000000000e+00 0.0000000000e+00  4
                B   0.0000000000e+00 1.0000000000e+00 1.0000000000e+00  5
                C   0.0000000000e+00 1.0000000000e+00 2.0000000000e+00  6
                D   0.0000000000e+00 1.0000000000e+00 3.0000000000e+00  7
                A   0.0000000000e+00 2.0000000000e+00 0.0000000000e+00  8
                B   0.0000000000e+00 2.0000000000e+00 1.0000000000e+00  9
                C   0.0000000000e+00 2.0000000000e+00 2.0000000000e+00  10
                D   0.0000000000e+00 2.0000000000e+00 3.0000000000e+00  11
                A   0.0000000000e+00 3.0000000000e+00 0.0000000000e+00  12
                B   0.0000000000e+00 3.0000000000e+00 1.0000000000e+00  13
                C   0.0000000000e+00 3.0000000000e+00 2.0000000000e+00  14
                D   0.0000000000e+00 3.0000000000e+00 3.0000000000e+00  15
                A   1.0000000000e+00 0.0000000000e+00 0.0000000000e+00  16
                B   1.0000000000e+00 0.0000000000e+00 1.0000000000e+00  17
                C   1.0000000000e+00 0.0000000000e+00 2.0000000000e+00  18
                D   1.0000000000e+00 0.0000000000e+00 3.0000000000e+00  19
                A   1.0000000000e+00 1.0000000000e+00 0.0000000000e+00  20
                B   1.0000000000e+00 1.0000000000e+00 1.0000000000e+00  21
                C   1.0000000000e+00 1.0000000000e+00 2.0000000000e+00  22
                D   1.0000000000e+00 1.0000000000e+00 3.0000000000e+00  23
                A   1.0000000000e+00 2.0000000000e+00 0.0000000000e+00  24
                B   1.0000000000e+00 2.0000000000e+00 1.0000000000e+00  25
                C   1.0000000000e+00 2.0000000000e+00 2.0000000000e+00  26
                D   1.0000000000e+00 2.0000000000e+00 3.0000000000e+00  27
                A   1.0000000000e+00 3.0000000000e+00 0.0000000000e+00  28
                B   1.0000000000e+00 3.0000000000e+00 1.0000000000e+00  29
                C   1.0000000000e+00 3.0000000000e+00 2.0000000000e+00  30
                D   1.0000000000e+00 3.0000000000e+00 3.0000000000e+00  31
                A   2.0000000000e+00 0.0000000000e+00 0.0000000000e+00  32
                B   2.0000000000e+00 0.0000000000e+00 1.0000000000e+00  33
                C   2.0000000000e+00 0.0000000000e+00 2.0000000000e+00  34
                D   2.0000000000e+00 0.0000000000e+00 3.0000000000e+00  35
                A   2.0000000000e+00 1.0000000000e+00 0.0000000000e+00  36
                B   2.0000000000e+00 1.0000000000e+00 1.0000000000e+00  37
                C   2.0000000000e+00 1.0000000000e+00 2.0000000000e+00  38
                D   2.0000000000e+00 1.0000000000e+00 3.0000000000e+00  39
                A   2.0000000000e+00 2.0000000000e+00 0.0000000000e+00  40
                B   2.0000000000e+00 2.0000000000e+00 1.0000000000e+00  41
                C   2.0000000000e+00 2.0000000000e+00 2.0000000000e+00  42
                D   2.0000000000e+00 2.0000000000e+00 3.0000000000e+00  43
                A   2.0000000000e+00 3.0000000000e+00 0.0000000000e+00  44
                B   2.0000000000e+00 3.0000000000e+00 1.0000000000e+00  45
                C   2.0000000000e+00 3.0000000000e+00 2.0000000000e+00  46
                D   2.0000000000e+00 3.0000000000e+00 3.0000000000e+00  47
                A   3.0000000000e+00 0.0000000000e+00 0.0000000000e+00  48
                B   3.0000000000e+00 0.0000000000e+00 1.0000000000e+00  49
                C   3.0000000000e+00 0.0000000000e+00 2.0000000000e+00  50
                D   3.0000000000e+00 0.0000000000e+00 3.0000000000e+00  51
                A   3.0000000000e+00 1.0000000000e+00 0.0000000000e+00  52
                B   3.0000000000e+00 1.0000000000e+00 1.0000000000e+00  53
                C   3.0000000000e+00 1.0000000000e+00 2.0000000000e+00  54
                D   3.0000000000e+00 1.0000000000e+00 3.0000000000e+00  55
                A   3.0000000000e+00 2.0000000000e+00 0.0000000000e+00  56
                B   3.0000000000e+00 2.0000000000e+00 1.0000000000e+00  57
                C   3.0000000000e+00 2.0000000000e+00 2.0000000000e+00  58
                D   3.0000000000e+00 2.0000000000e+00 3.0000000000e+00  59
                A   3.0000000000e+00 3.0000000000e+00 0.0000000000e+00  60
                B   3.0000000000e+00 3.0000000000e+00 1.0000000000e+00  61
                C   3.0000000000e+00 3.0000000000e+00 2.0000000000e+00  62
                D   3.0000000000e+00 3.0000000000e+00 3.0000000000e+00  63
"""

        if MPICommons.isMaster():
            with open(trajectory_filename, "r") as f:
                content = f.read()
            self.assertEqual( content, ref_content )

        # Check that the buffers are empty.
        self.assertEqual(t._XYZTrajectory__atom_id_types, [])
        self.assertEqual(t._XYZTrajectory__atom_id_coordinates, [])
        self.assertEqual(t._XYZTrajectory__time, [])
        self.assertEqual(t._XYZTrajectory__step, [])
Пример #29
0
    def testStoreData(self):
        """ Test the data storage function. """
        # Get a file name.
        name = os.path.abspath(os.path.dirname(__file__))
        name = os.path.join(name, "..", "..")
        name = os.path.join(name, "TestUtilities", "Scratch")
        trajectory_filename = os.path.join(name, "tmp_trajectory.xyz")

        if MPICommons.isMaster():
            self.__files_to_remove.append(trajectory_filename)

        # Setup the trajectory object.
        unit_cell = KMCUnitCell(cell_vectors=[[1.0, 0.0, 0.0],
                                              [0.0, 1.0, 0.0],
                                              [0.0, 0.0, 1.0]],
                                basis_points=[[0.0, 0.0, 0.0]])
        lattice = KMCLattice(unit_cell=unit_cell,
                             periodic=(True, True, True),
                             repetitions=(4,4,4))

        config = KMCConfiguration(lattice=lattice,
                                 types=["A","B","C","D"]*16)

        t = XYZTrajectory(trajectory_filename=trajectory_filename,
                          configuration=config,
                          max_buffer_size=12345,
                          max_buffer_time=123.0)

        # Construct data to store.
        simulation_time = 1.234
        step = 123
        configuration = config

        # Store.
        t._storeData(simulation_time, step, configuration)

        # Check that the member data was updated.
        self.assertEqual(len(t._XYZTrajectory__atom_id_types), 1)
        self.assertEqual(len(t._XYZTrajectory__atom_id_coordinates), 1)
        self.assertEqual(len(t._XYZTrajectory__time), 1)
        self.assertEqual(len(t._XYZTrajectory__step), 1)

        # store again.
        simulation_time = 1.999
        step = 4444
        t._storeData(simulation_time, step, configuration)

        # Check that the member data was updated.
        self.assertEqual(len(t._XYZTrajectory__atom_id_types), 2)
        self.assertEqual(len(t._XYZTrajectory__atom_id_coordinates), 2)
        self.assertEqual(len(t._XYZTrajectory__time), 2)
        self.assertEqual(len(t._XYZTrajectory__step), 2)

        # Check the values of the stored data.
        self.assertAlmostEqual(t._XYZTrajectory__time[0], 1.234, 10)
        self.assertAlmostEqual(t._XYZTrajectory__time[1], 1.999, 10)

        self.assertEqual(t._XYZTrajectory__step[0],  123)
        self.assertEqual(t._XYZTrajectory__step[1], 4444)

        diff = numpy.linalg.norm(config.atomIDCoordinates() - t._XYZTrajectory__atom_id_coordinates[0])
        self.assertAlmostEqual(diff, 0.0, 10)

        diff = numpy.linalg.norm(config.atomIDCoordinates() - t._XYZTrajectory__atom_id_coordinates[1])
        self.assertAlmostEqual(diff, 0.0, 10)

        self.assertEqual(t._XYZTrajectory__atom_id_types[0], config.atomIDTypes())
        self.assertEqual(t._XYZTrajectory__atom_id_types[1], config.atomIDTypes())
Пример #30
0
    def testFinalizeWithCoordinateTransform(self):
        """ Test finalization. """
        msd = OnTheFlyMSD.__new__(OnTheFlyMSD)

        # Replace the getBackendResults function.
        def dummy():
            pass
        msd._OnTheFlyMSD__getBackendResults = dummy

        # Set a unitcell on the class.
        unit_cell = KMCUnitCell(cell_vectors=numpy.array([[1.0,0.0,0.0],
                                                          [0.0,1.0,0.0],
                                                          [0.0,0.0,1.0]]),
                                basis_points=[[0.0,0.0,0.0]])
        msd._OnTheFlyMSD__unit_cell = unit_cell

        # Set the values.
        msd._OnTheFlyMSD__raw_histogram = numpy.array([[  171144.,   173906.,   188389.],
                                                       [  516721.,   497558.,   536213.],
                                                       [  851961.,   810151.,   836426.],
                                                       [ 1195930.,  1046238.,  1111184.],
                                                       [ 1507650.,  1366678.,  1434213.],
                                                       [ 1780731.,  1743443.,  1719186.],
                                                       [ 2155426.,  2154562.,  1980822.],
                                                       [ 2554205.,  2604757.,  2354967.],
                                                       [ 2954351.,  3032799.,  2698023.],
                                                       [ 3372070.,  3443433.,  3158002.]])
        bin_counters = (60283, 60628, 60461, 59779, 59683, 59178, 58856, 58752, 58162, 57881)
        msd._OnTheFlyMSD__bin_counters = bin_counters
        msd._OnTheFlyMSD__n_bins = 10
        msd._OnTheFlyMSD__binsize = 2.5

        hstep_counts = [8919,8918,8917,8916,8915,8914,8913,8912,8911,8910,8099,8908,8907,8906,8905,8904,8903,8902,8901]
        msd._OnTheFlyMSD__hstep_counts = hstep_counts

        history_bin_counters = [(1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
                                (0, 0, 0, 0, 0, 1, 87, 58752, 58162, 57881)]
        msd._OnTheFlyMSD__history_bin_counters = history_bin_counters
        msd._OnTheFlyMSD__n_eff = [1.12, 2.24, 3.36, 4.48, 5.60, 6.72, 7.84, 8.96, 9.0, 10.12]

        # Call the finalize function.
        msd.finalize()

        # Check a few results.
        result_0_3 =  1195930. / 59779.0
        self.assertAlmostEqual(result_0_3, msd._OnTheFlyMSD__results[0][3], 10)

        result_1_7 = 2604757.0 / 58752.0
        self.assertAlmostEqual(result_1_7, msd._OnTheFlyMSD__results[1][7], 10)

        result_2_0 = 188389.0 / 60283.0
        self.assertAlmostEqual(result_2_0, msd._OnTheFlyMSD__results[2][0], 10)

        result_3_4 =  ( 1507650.0 +  1366678.0) / 59683.0
        self.assertAlmostEqual(result_3_4, msd._OnTheFlyMSD__results[3][4], 10)

        result_4_4 =  (  1507650.0 + 1434213.0) /  59683.0
        self.assertAlmostEqual(result_4_4, msd._OnTheFlyMSD__results[4][4], 10)

        result_5_6 =  ( 2154562.0 + 1980822.0) / 58856.0
        self.assertAlmostEqual(result_5_6, msd._OnTheFlyMSD__results[5][6], 10)

        result_6_5 =  ( 1780731.0 + 1743443.0 + 1719186.0)/ 59178.0
        self.assertAlmostEqual(result_6_5, msd._OnTheFlyMSD__results[6][5], 10)

        # Check the corresponding standard deviation against hardcoded values.
        std_0_3 = 42.291401180595834
        std_1_7 =  0.813230156401512
        std_2_0 =  6.634050132990601
        std_3_4 = 71.931090096615776
        std_4_4 = 73.621177716983027
        std_5_6 =  7.877909031669120
        std_6_5 = 62.119638306131414

        self.assertAlmostEqual(std_0_3, msd._OnTheFlyMSD__std_dev[0][3], 10)
        self.assertAlmostEqual(std_1_7, msd._OnTheFlyMSD__std_dev[1][7], 10)
        self.assertAlmostEqual(std_2_0, msd._OnTheFlyMSD__std_dev[2][0], 10)
        self.assertAlmostEqual(std_3_4, msd._OnTheFlyMSD__std_dev[3][4], 10)
        self.assertAlmostEqual(std_4_4, msd._OnTheFlyMSD__std_dev[4][4], 10)
        self.assertAlmostEqual(std_5_6, msd._OnTheFlyMSD__std_dev[5][6], 10)
        self.assertAlmostEqual(std_6_5, msd._OnTheFlyMSD__std_dev[6][5], 10)
Пример #31
0
    def testFinalizeNoCoordinateTransform(self):
        """ Test finalization. """
        msd = OnTheFlyMSD.__new__(OnTheFlyMSD)

        # Replace the getBackendResults function.
        def dummy():
            pass
        msd._OnTheFlyMSD__getBackendResults = dummy

        # Set a unitcell on the class.
        unit_cell = KMCUnitCell(cell_vectors=numpy.array([[1.0,0.0,0.0],
                                                          [0.0,1.0,0.0],
                                                          [0.0,0.0,1.0]]),
                                basis_points=[[0.0,0.0,0.0]])
        msd._OnTheFlyMSD__unit_cell = unit_cell

        # Set the values.
        msd._OnTheFlyMSD__raw_histogram = numpy.array([[  171144.,   173906.,   188389.],
                                                       [  516721.,   497558.,   536213.],
                                                       [  851961.,   810151.,   836426.],
                                                       [ 1195930.,  1046238.,  1111184.],
                                                       [ 1507650.,  1366678.,  1434213.],
                                                       [ 1780731.,  1743443.,  1719186.],
                                                       [ 2155426.,  2154562.,  1980822.],
                                                       [ 2554205.,  2604757.,  2354967.],
                                                       [ 2954351.,  3032799.,  2698023.],
                                                       [ 3372070.,  3443433.,  3158002.]])
        bin_counters = (60283, 60628, 60461, 59779, 59683, 59178, 58856, 58752, 58162, 57881)
        msd._OnTheFlyMSD__bin_counters = bin_counters
        msd._OnTheFlyMSD__n_bins = 10
        msd._OnTheFlyMSD__binsize = 2.5
        hstep_counts = [8919,8918,8917,8916,8915,8914,8913,8912,8911,8910,8099,8908,8907,8906,8905,8904,8903,8902,8901]
        msd._OnTheFlyMSD__hstep_counts = hstep_counts

        history_bin_counters = [(1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
                                (0, 0, 0, 0, 0, 1, 87, 58752, 58162, 57881)]
        msd._OnTheFlyMSD__history_bin_counters = history_bin_counters
        msd._OnTheFlyMSD__n_eff = [1.12, 2.24, 3.36, 4.48, 5.60, 6.72, 7.84, 8.96, 9.0, 10.12]

        # Call the finalize function.
        msd.finalize()

        # Check a few results.
        result_0_3 =  1195930. / 59779.0
        self.assertAlmostEqual(result_0_3, msd._OnTheFlyMSD__results[0][3], 10)

        result_1_7 = 2604757.0 / 58752.0
        self.assertAlmostEqual(result_1_7, msd._OnTheFlyMSD__results[1][7], 10)

        result_2_0 = 188389.0 / 60283.0
        self.assertAlmostEqual(result_2_0, msd._OnTheFlyMSD__results[2][0], 10)

        # Check the corresponding standard deviation.
        n_eff = numpy.zeros(10)
        for i in range(len(n_eff)):
            for b in range(len(history_bin_counters)):
                fraction = float(history_bin_counters[b][i]) / float(bin_counters[i])
                n_eff[i] += fraction * (b+1.0)

        K1 = hstep_counts[int(n_eff[3]+1)]
        K2 = K1*K1
        std_0_3 = result_0_3 * numpy.sqrt(2.0) * numpy.sqrt((4*n_eff[3]*n_eff[3]*K1 + 2*K1 + n_eff[3] - n_eff[3]*n_eff[3]*n_eff[3])/(n_eff[3]*6*K2))
        self.assertAlmostEqual(std_0_3, msd._OnTheFlyMSD__std_dev[0][3], 10)

        K1 = hstep_counts[int(n_eff[7]+1)]
        K2 = K1*K1
        std_1_7 = result_1_7 * numpy.sqrt(2.0) * numpy.sqrt((4*n_eff[7]*n_eff[7]*K1 + 2*K1 + n_eff[7] - n_eff[7]*n_eff[7]*n_eff[7])/(n_eff[7]*6*K2))
        self.assertAlmostEqual(std_1_7, msd._OnTheFlyMSD__std_dev[1][7], 10)


        K1 = hstep_counts[int(n_eff[0]+1)]
        K2 = K1*K1
        std_2_0 = result_2_0 * numpy.sqrt(2.0) * numpy.sqrt((4*n_eff[0]*n_eff[0]*K1 + 2*K1 + n_eff[0] - n_eff[0]*n_eff[0]*n_eff[0])/(n_eff[0]*6*K2))
        self.assertAlmostEqual(std_2_0, msd._OnTheFlyMSD__std_dev[2][0], 10)
Пример #32
0
    def testScript(self):
        """ Test that a valid script can be generated. """
        # Setup a valid cell.
        vector_a = [2.3, 1.0, 0.1]
        vector_b = [2.4, 3.0, 0.0]
        vector_c = [0.4, 0.3, 11.8]
        basis_points = [[0.4, 0.3, 0.2],
                        [0.2, 0.33, 0.11],
                        [0.6, 0.5, 0.1]]
        cell_vectors = [vector_a,
                        vector_b,
                        vector_c]
        cell = KMCUnitCell(cell_vectors=cell_vectors,
                           basis_points=basis_points)

        # Get the script.
        script = cell._script()

        # Check against the known reference script.
        ref_script = """
# -----------------------------------------------------------------------------
# Unit cell

cell_vectors = [[   2.300000e+00,   1.000000e+00,   1.000000e-01],
                [   2.400000e+00,   3.000000e+00,   0.000000e+00],
                [   4.000000e-01,   3.000000e-01,   1.180000e+01]]

basis_points = [[   4.000000e-01,   3.000000e-01,   2.000000e-01],
                [   2.000000e-01,   3.300000e-01,   1.100000e-01],
                [   6.000000e-01,   5.000000e-01,   1.000000e-01]]

unit_cell = KMCUnitCell(
    cell_vectors=cell_vectors,
    basis_points=basis_points)
"""
        self.assertEqual(script, ref_script)

       # Setup another valid cell.
        vector_a = [2.3, 1.0, 0.1]
        vector_b = [2.4, 3.0, 0.0]
        vector_c = [0.4, 0.3, 11.8]
        basis_points = [[0.4, 0.3, 0.2]]
        cell_vectors = [vector_a,
                        vector_b,
                        vector_c]
        cell = KMCUnitCell(cell_vectors=cell_vectors,
                           basis_points=basis_points)
        script = cell._script(variable_name="CELL_NAME_HERE")

        # Check against the known reference.
        ref_script = """
# -----------------------------------------------------------------------------
# Unit cell

cell_vectors = [[   2.300000e+00,   1.000000e+00,   1.000000e-01],
                [   2.400000e+00,   3.000000e+00,   0.000000e+00],
                [   4.000000e-01,   3.000000e-01,   1.180000e+01]]

basis_points = [[   4.000000e-01,   3.000000e-01,   2.000000e-01]]

CELL_NAME_HERE = KMCUnitCell(
    cell_vectors=cell_vectors,
    basis_points=basis_points)
"""
        self.assertEqual(script, ref_script)
Пример #33
0
    def testCalculationNonOrthogonal(self):
        """ Test a calculation with the on-the-fly MSD analysis. """
        # Setup a system, a periodic 10 atoms long 1D chain.
        unit_cell = KMCUnitCell(cell_vectors=numpy.array([[2.0,1.0,0.0],
                                                          [0.0,1.0,0.0],
                                                          [0.0,2.0,1.0]]),
                                basis_points=[[0.0,0.0,0.0]])

        # And a lattice.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=(10,10,10),
                             periodic=(True,True,True))

        # Setup an initial configuration with one B in a sea of A:s.
        types = ["A"]*10*10*10
        types[5] = "B"

        config = KMCConfiguration(lattice=lattice,
                                  types=types,
                                  possible_types=["A","B"])

        # Setup a diffusion process to the left.
        coordinates_p0 = [[0.0, 0.0, 0.0],[-1.0, 0.0, 0.0]]
        p0 = KMCProcess(coordinates=coordinates_p0,
                        elements_before=["B","A"],
                        elements_after=["A","B"],
                        move_vectors=None,
                        basis_sites=[0],
                        rate_constant=1.0)

        coordinates_p1 = [[0.0, 0.0, 0.0],[1.0, 0.0, 0.0]]
        p1 = KMCProcess(coordinates=coordinates_p1,
                        elements_before=["B","A"],
                        elements_after=["A","B"],
                        move_vectors=None,
                        basis_sites=[0],
                        rate_constant=1.0)

        coordinates_p2 = [[0.0, 0.0, 0.0],[0.0,-1.0, 0.0]]
        p2 = KMCProcess(coordinates=coordinates_p2,
                        elements_before=["B","A"],
                        elements_after=["A","B"],
                        move_vectors=None,
                        basis_sites=[0],
                        rate_constant=1.0)

        coordinates_p3 = [[0.0, 0.0, 0.0],[0.0, 1.0, 0.0]]
        p3 = KMCProcess(coordinates=coordinates_p3,
                        elements_before=["B","A"],
                        elements_after=["A","B"],
                        move_vectors=None,
                        basis_sites=[0],
                        rate_constant=1.0)

        coordinates_p4 = [[0.0, 0.0, 0.0],[0.0, 0.0,-1.0]]
        p4 = KMCProcess(coordinates=coordinates_p4,
                        elements_before=["B","A"],
                        elements_after=["A","B"],
                        move_vectors=None,
                        basis_sites=[0],
                        rate_constant=1.0)

        coordinates_p5 = [[0.0, 0.0, 0.0],[0.0, 0.0, 1.0]]
        p5 = KMCProcess(coordinates=coordinates_p5,
                        elements_before=["B","A"],
                        elements_after=["A","B"],
                        move_vectors=None,
                        basis_sites=[0],
                        rate_constant=1.0)

        interactions = KMCInteractions(processes=[p0, p1, p2, p3, p4, p5],
                                       implicit_wildcards=True)

        model = KMCLatticeModel(configuration=config,
                                interactions=interactions)

        # Setup the analysis.
        msd = OnTheFlyMSD(history_steps=400,
                          n_bins=10,
                          t_max=25.0,
                          track_type="B")

        # Setup the control parameters.
        control_parameters = KMCControlParameters(number_of_steps=4000,
                                                  dump_interval=100,
                                                  analysis_interval=1,
                                                  seed=2013)
        # Run the model.
        model.run(control_parameters=control_parameters,
                  analysis=[msd])

        # Get the results out.
        results      = msd.results()
        time_steps   = msd.timeSteps()
        std_dev      = msd.stdDev()
        bin_counters = msd.binCounters()

        # Compare against references.
        ref_results = numpy.array([[  11.10849324 ,  32.89332622 ,  56.86314552 ,  84.47799379 , 110.30394149,
                                      135.26081658,  162.25612518,  189.40268295,  219.32538873,  252.00244119],
                                   [  17.33153679 ,  50.69982999 ,  82.74958435 , 111.33382274 , 136.44824258,
                                      164.84499628,  193.94367236,  234.25340515,  272.64453361,  302.94924061],
                                   [   2.98786918 ,   8.65022668 ,  14.01808716 ,  18.62678885 ,  22.65708384,
                                       26.03107861,   30.03937616,   35.1483    ,   40.68319007,   47.21074474],
                                   [  28.44003004 ,  83.59315621 , 139.61272987 , 195.81181652 , 246.75218407,
                                      300.10581285,  356.19979754,  423.65608811,  491.96992234,  554.95168181],
                                   [  14.09636242 ,  41.5435529  ,  70.88123268 , 103.10478264 , 132.96102533,
                                      161.29189519,  192.29550134,  224.55098295,  260.00857879,  299.21318593],
                                   [  20.31940597 ,  59.35005667 ,  96.76767151 , 129.96061158 , 159.10532643,
                                      190.87607489,  223.98304852,  269.40170515,  313.32772368,  350.15998535],
                                   [  31.42789922 ,  92.24338289 , 153.63081703 , 214.43860537 , 269.40926791,
                                      326.13689146,  386.2391737 ,  458.8043881 ,  532.65311241,  602.16242655]])

        diff = numpy.linalg.norm(ref_results - results)
        self.assertAlmostEqual(diff, 0.0, 6)

        ref_time_steps = numpy.array([  1.25,   3.75,   6.25,   8.75,  11.25,  13.75,  16.25,  18.75,  21.25,  23.75])
        diff = numpy.linalg.norm(ref_time_steps - time_steps)
        self.assertAlmostEqual(diff, 0.0, 8)

        ref_std_dev = numpy.array([[  0.59348826 ,  2.92235801 ,  6.47651272 , 11.36067446 , 16.79740936,
                                      22.78018427,  29.72954492,  37.27728411,  45.97782684,  55.88661276],
                                   [  0.92596389 ,  4.50435001 ,  9.42488725 , 14.97226982 , 20.7787406,
                                      27.76265504,  35.53552825,  46.10457783,  57.15527613,  67.18509081],
                                   [  0.15963149 ,  0.76851636 ,  1.59661093 ,  2.50494685 ,  3.45028752,
                                      4.38406911 ,  5.5039955  ,  6.91771175 ,  8.52853689 , 10.46993274],
                                   [  1.07441492 ,  5.2514756  , 11.24398775 , 18.62020347 , 26.57035045,
                                      35.73918442,  46.14937581,  58.95988   ,  72.92611647,  87.02483617],
                                   [  0.53253608 ,  2.60984229 ,  5.70856048 ,  9.80447485 , 14.31728377,
                                      19.20802777,  24.91387536,  31.25058126,  38.54181941,  46.9211633 ],
                                   [  0.76763185 ,  3.72847956 ,  7.7933761  , 12.35825842 , 17.13251009,
                                      22.73116664,  29.01932554,  37.49242051,  46.4454696 ,  54.91039375],
                                   [  0.96941939 ,  4.731515   , 10.1024813  , 16.6495642  , 23.68662473,
                                      31.71206536,  40.85854085,  52.13448317,  64.46787783,  77.10029967]])

        diff = numpy.linalg.norm(ref_std_dev - std_dev)
        self.assertAlmostEqual(diff, 0.0, 6)

        ref_bin_counters = (59930, 59996, 59545, 59256, 59064, 59076, 58284, 58294, 57817, 57349)
        self.assertEqual(bin_counters, ref_bin_counters)