Exemplo n.º 1
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
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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))
Exemplo n.º 5
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)
Exemplo n.º 6
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 )
Exemplo n.º 7
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
Exemplo n.º 8
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) )
Exemplo n.º 9
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))
Exemplo n.º 10
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))
Exemplo n.º 11
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()))
Exemplo n.º 12
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()))
Exemplo n.º 13
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()
Exemplo n.º 14
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)
Exemplo n.º 15
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, [])
Exemplo n.º 16
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)
Exemplo n.º 17
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)
Exemplo n.º 18
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 )
Exemplo n.º 19
0
    def testConstructionFailUnitcell(self):
        """ Test that construction of the lattice fails if the unitcell parameter has the wrong type."""
        # Setup a wrong unitcell.
        unit_cell = "KMCUnitCell"

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

        # Construct the KMCLattice object.
        self.assertRaises(
            Error, lambda: KMCLattice(unit_cell=unit_cell,
                                      repetitions=repetitions,
                                      periodic=periodic))
Exemplo n.º 20
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)
Exemplo n.º 21
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)
Exemplo n.º 22
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)
Exemplo n.º 23
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)
Exemplo n.º 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))
Exemplo n.º 25
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))
Exemplo n.º 26
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())
Exemplo n.º 27
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)
Exemplo n.º 28
0
    def testScript(self):
        """ Check that we can generate a valid script. """
        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 script.
        script =  lattice._script()

        ref_script = """
# -----------------------------------------------------------------------------
# Unit cell

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

basis_points = [[   0.000000e+00,   0.000000e+00,   0.000000e+00],
                [   5.000000e-01,   5.000000e-01,   0.000000e+00]]

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

# -----------------------------------------------------------------------------
# Lattice

lattice = KMCLattice(
    unit_cell=unit_cell,
    repetitions=(2,12,3),
    periodic=(True, True, False))
"""
        self.assertEqual(script, ref_script)

        # Get the script.
        script =  lattice._script(variable_name="ANOTHER_NAME")

        ref_script = """
# -----------------------------------------------------------------------------
# Unit cell

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

basis_points = [[   0.000000e+00,   0.000000e+00,   0.000000e+00],
                [   5.000000e-01,   5.000000e-01,   0.000000e+00]]

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

# -----------------------------------------------------------------------------
# Lattice

ANOTHER_NAME = KMCLattice(
    unit_cell=unit_cell,
    repetitions=(2,12,3),
    periodic=(True, True, False))
"""
        self.assertEqual(script, ref_script)
Exemplo n.º 29
0
    def testConstructionFailLongFormat(self):
        """ Test everything that can go wrong when constructing with the long fomat. """

        # 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)

        # This fails because the lattice is of wrong type.
        self.assertRaises(
            Error, lambda: KMCConfiguration(
                lattice=unit_cell, types=types, default_type=default_type))

        # This fails because no default type is given.
        self.assertRaises(
            Error, lambda: KMCConfiguration(lattice=lattice, types=types))

        # This fails because no default type is not a string.
        self.assertRaises(
            Error, lambda: KMCConfiguration(
                lattice=lattice, types=types, default_type=['a']))

        # This fails because the possible types are not set correctly.
        self.assertRaises(
            Error, lambda: KMCConfiguration(lattice=lattice,
                                            types=types,
                                            default_type=default_type,
                                            possible_types="agh"))

        # This fails because there are types missing in the possible types.
        self.assertRaises(
            Error, lambda: KMCConfiguration(lattice=lattice,
                                            types=types,
                                            default_type=default_type,
                                            possible_types=['a', 'h']))

        # This fails because there is a wildcard character in the possible types list.
        self.assertRaises(
            Error,
            lambda: KMCConfiguration(lattice=lattice,
                                     types=types,
                                     default_type=default_type,
                                     possible_types=['g', 'a', '*', 'h']))

        types_1 = [123, 345]
        # This fails because of wrong type in the types list.
        self.assertRaises(
            Error, lambda: KMCConfiguration(
                lattice=lattice, types=types_1, default_type=default_type))

        types_1 = [(0, 0, 0, 0, 'a'), (0, 0, 0, 'a')]
        # This fails because of wrong type in the types list.
        self.assertRaises(
            Error, lambda: KMCConfiguration(
                lattice=lattice, types=types_1, default_type=default_type))

        types_1 = [(0, 0, 0, 0, 'a'), (0, 0, 0, 1, 'b', 3)]
        # This fails because of wrong type in the types list.
        self.assertRaises(
            Error, lambda: KMCConfiguration(
                lattice=lattice, types=types_1, default_type=default_type))

        types_1 = [[0, 0, 0, 0, 'a'], [0, 0, 0, 1, 'b']]
        # This fails because of wrong type in the types list.
        self.assertRaises(
            Error, lambda: KMCConfiguration(
                lattice=lattice, types=types_1, default_type=default_type))

        types_1 = [(0, 0, 0, 0, 'a'), (-1, 0, 0, 0, 'b')]
        # This fails because of a negative first index.
        self.assertRaises(
            Error, lambda: KMCConfiguration(
                lattice=lattice, types=types_1, default_type=default_type))

        types_1 = [(100, 0, 0, 0, 'a'), (0, 0, 0, 0, 'b')]
        # This fails because of a too large firs index.
        self.assertRaises(
            Error, lambda: KMCConfiguration(
                lattice=lattice, types=types_1, default_type=default_type))

        types_1 = [(0, 0, 0, 0, 'a'), (0, -1, 0, 0, 'b')]
        # This fails because of a negative second index.
        self.assertRaises(
            Error, lambda: KMCConfiguration(
                lattice=lattice, types=types_1, default_type=default_type))

        types_1 = [(0, 100, 0, 0, 'a'), (0, 0, 0, 1, 'b')]
        # This fails because of a too large second index.
        self.assertRaises(
            Error, lambda: KMCConfiguration(
                lattice=lattice, types=types_1, default_type=default_type))

        types_1 = [(0, 0, 0, 0, 'a'), (0, 0, -1, 0, 'b')]
        # This fails because of a negative third index.
        self.assertRaises(
            Error, lambda: KMCConfiguration(
                lattice=lattice, types=types_1, default_type=default_type))

        types_1 = [(0, 0, 100, 0, 'a'), (0, 0, 0, 0, 'b')]
        # This fails because of a too large third index.
        self.assertRaises(
            Error, lambda: KMCConfiguration(
                lattice=lattice, types=types_1, default_type=default_type))

        types_1 = [(0, 0, 0, 0, 'a'), (0, 0, 0, -1, 'b')]
        # This fails because of a negative fourth index.
        self.assertRaises(
            Error, lambda: KMCConfiguration(
                lattice=lattice, types=types_1, default_type=default_type))

        types_1 = [(0, 0, 0, 100, 'a'), (0, 0, 0, 1, 'b')]
        # This fails because of a too large fourth index.
        self.assertRaises(
            Error, lambda: KMCConfiguration(
                lattice=lattice, types=types_1, default_type=default_type))
Exemplo n.º 30
0
    def testScript(self):
        """ Test that we can generate a valid script. """
        # 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 script.
        script = config._script()

        ref_script = """
# -----------------------------------------------------------------------------
# Unit cell

cell_vectors = [[   2.800000e+00,   0.000000e+00,   0.000000e+00],
                [   0.000000e+00,   3.200000e+00,   0.000000e+00],
                [   0.000000e+00,   5.000000e-01,   3.000000e+00]]

basis_points = [[   0.000000e+00,   0.000000e+00,   0.000000e+00],
                [   5.000000e-01,   5.000000e-01,   5.000000e-01],
                [   2.500000e-01,   2.500000e-01,   7.500000e-01]]

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

# -----------------------------------------------------------------------------
# Lattice

lattice = KMCLattice(
    unit_cell=unit_cell,
    repetitions=(4,4,1),
    periodic=(True, True, False))

# -----------------------------------------------------------------------------
# Configuration

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']

possible_types = ['a','c','b']

configuration = KMCConfiguration(
    lattice=lattice,
    types=types,
    possible_types=possible_types)
"""
        self.assertEqual(script, ref_script)

        # Try another one.

        # 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]])

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

        types = [
            'ThisIsTheTypeOfMyOnlySiteInThisUnrealisticallyShortStructure'
        ]

        possible_types = [
            'ThisIsTheTypeOfMyOnlySiteInThisUnrealisticallyShortStructure',
            "A", "B", "CDEFGHI"
        ]

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

        # Get the script.
        script = config._script(variable_name="config")

        ref_script = """
# -----------------------------------------------------------------------------
# Unit cell

cell_vectors = [[   2.800000e+00,   0.000000e+00,   0.000000e+00],
                [   0.000000e+00,   3.200000e+00,   0.000000e+00],
                [   0.000000e+00,   5.000000e-01,   3.000000e+00]]

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

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

# -----------------------------------------------------------------------------
# Lattice

lattice = KMCLattice(
    unit_cell=unit_cell,
    repetitions=(1,1,1),
    periodic=(False, False, False))

# -----------------------------------------------------------------------------
# Configuration

types = ['ThisIsTheTypeOfMyOnlySiteInThisUnrealisticallyShortStructure']

possible_types = ['A','CDEFGHI','ThisIsTheTypeOfMyOnlySiteInThisUnrealisticallyShortStructure',
                  'B']

config = KMCConfiguration(
    lattice=lattice,
    types=types,
    possible_types=possible_types)
"""
        self.assertEqual(script, ref_script)
Exemplo n.º 31
0
    def testATKScript1(self):
        """ Test that we can generate an ATK script from the configuration. """
        # 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.0, 0.5, 0.5],
                                              [0.5, 0.75, 0.75]])

        # Setup the lattice and types.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=(1, 1, 1),
                             periodic=(False, False, False))
        types = ['B', 'A', 'C']
        possible_types = ['C', "A", "B", "D"]

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

        # Determine a mapping between our types and valid ATK types.
        # Types not present in the mapping are ignored in the ATK script.
        types_mapping = {
            'A': 'Copper',
            'C': 'Iron',
            'D': 'Vanadium',
        }

        # Get the ATK script.
        atk_script = config._atkScript(types_mapping)

        # Check that it looks as we expect.

        ref_script = """# ----------------------------------------------------------
# ATK 12.8.2 BulkConfiguration script generated from KMCLib
# configuration version 1.0.
# ----------------------------------------------------------

# Specify the lattice parameters.
vector_a = [   2.80000000,   0.00000000,   0.00000000]*Angstrom
vector_b = [   0.00000000,   3.20000000,   0.00000000]*Angstrom
vector_c = [   0.00000000,   0.50000000,   3.00000000]*Angstrom
lattice = UnitCell(vector_a, vector_b, vector_c)

# Define the elements.
elements = [Copper, Iron]

# Define the coordinates.
coordinates = [[  0.00000000e+00,  5.00000000e-01,  5.00000000e-01],
               [  5.00000000e-01,  7.50000000e-01,  7.50000000e-01]]

# Setup the configuration.
bulk_configuration = BulkConfiguration(
    bravais_lattice=lattice,
    elements=elements,
    fractional_coordinates=coordinates )

# ----------------------------------------------------------
"""
        self.assertEqual(atk_script, ref_script)
Exemplo n.º 32
0
    def testConstructionFailShort(self):
        """ Test every thing that should fail when using the short 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 = [
            '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'
        ]

        default_type = 'a'

        # This fails because the lattice is of wrong type.
        self.assertRaises(
            Error, lambda: KMCConfiguration(lattice=unit_cell, types=types))

        # This fails because there is a default type given.
        self.assertRaises(
            Error, lambda: KMCConfiguration(
                lattice=lattice, types=types, default_type=default_type))

        # This fails becaulse of wrong length of the types.
        types_1 = ['g', 'a', 'a']
        self.assertRaises(
            Error, lambda: KMCConfiguration(lattice=lattice, types=types_1))

        types_1 = [
            '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', 3, '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', 1
        ]

        # This fails because of the wrong type of the types information.
        self.assertRaises(
            Error, lambda: KMCConfiguration(lattice=lattice, types=types_1))

        types_1 = "ABCDE"
        # And this also.
        self.assertRaises(
            Error, lambda: KMCConfiguration(lattice=lattice, types=types_1))

        # Use an incompatible possible types list.
        self.assertRaises(
            Error, lambda: KMCConfiguration(
                lattice=lattice, types=types, possible_types=['a']))

        # Use an incompatible possible types list.
        self.assertRaises(
            Error, lambda: KMCConfiguration(
                lattice=lattice, types=types, possible_types="ABCD"))

        # Use a possible types list with a wildcard.
        self.assertRaises(
            Error,
            lambda: KMCConfiguration(lattice=lattice,
                                     types=types,
                                     possible_types=['g', 'a', 'h', '*']))
Exemplo n.º 33
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)
Exemplo n.º 34
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, [])
Exemplo n.º 35
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])
Exemplo n.º 36
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, [])
Exemplo n.º 37
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)
Exemplo n.º 38
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)
Exemplo n.º 39
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] )
Exemplo n.º 40
0
    def testScript(self):
        """ Check that we can generate a valid script. """
        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 script.
        script = lattice._script()

        ref_script = """
# -----------------------------------------------------------------------------
# Unit cell

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

basis_points = [[   0.000000e+00,   0.000000e+00,   0.000000e+00],
                [   5.000000e-01,   5.000000e-01,   0.000000e+00]]

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

# -----------------------------------------------------------------------------
# Lattice

lattice = KMCLattice(
    unit_cell=unit_cell,
    repetitions=(2,12,3),
    periodic=(True, True, False))
"""
        self.assertEqual(script, ref_script)

        # Get the script.
        script = lattice._script(variable_name="ANOTHER_NAME")

        ref_script = """
# -----------------------------------------------------------------------------
# Unit cell

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

basis_points = [[   0.000000e+00,   0.000000e+00,   0.000000e+00],
                [   5.000000e-01,   5.000000e-01,   0.000000e+00]]

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

# -----------------------------------------------------------------------------
# Lattice

ANOTHER_NAME = KMCLattice(
    unit_cell=unit_cell,
    repetitions=(2,12,3),
    periodic=(True, True, False))
"""
        self.assertEqual(script, ref_script)
Exemplo n.º 41
0
    def testATKScript2(self):
        """ Test that we can generate an ATK script from the configuration. """
        # Setup a valid KMCUnitCell.

        cell_vectors = [[5.640000e+00, 0.330000e+00, 0.120000e+00],
                        [0.110000e+00, 5.460000e+00, 0.100000e+00],
                        [0.500000e+00, 0.430000e+00, 5.410000e+00]]

        basis_points = [[0.200000e+00, 0.300000e+00, 0.400000e+00],
                        [5.200000e-01, 5.400000e-01, 5.010000e-01]]

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

        # Setup the lattice and types.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=(4, 4, 4),
                             periodic=(True, True, True))

        types = [
            'Ce3', 'O', 'Empty', 'O', 'Ce', 'O', 'Empty', 'O', 'Empty', 'O',
            'Ce', 'O', 'Empty', 'Vacancy', 'Ce', 'O', 'Ce', 'O', 'Empty', 'O',
            'Ce', 'O', 'Empty', 'O', 'Empty', 'O', 'Ce', 'O', 'Empty', 'O',
            'Ce', 'O', 'Empty', 'O', 'Ce', 'O', 'Empty', 'O', 'Ce', 'O', 'Ce3',
            'O', 'Empty', 'O', 'Ce', 'O', 'Empty', 'O', 'Empty', 'O', 'Ce',
            'O', 'Empty', 'O', 'Ce', 'O', 'Ce', 'O', 'Empty', 'O', 'Ce', 'O',
            'Empty', 'O', 'Ce', 'O', 'Empty', 'O', 'Ce', 'O', 'Empty', 'O',
            'Empty', 'O', 'Ce', 'O', 'Empty', 'O', 'Ce', 'O', 'Ce', 'O',
            'Empty', 'O', 'Ce', 'O', 'Empty', 'O', 'Empty', 'O', 'Ce', 'O',
            'Empty', 'O', 'Ce', 'O', 'Empty', 'O', 'Ce', 'O', 'Empty', 'O',
            'Ce', 'O', 'Ce', 'O', 'Empty', 'O', 'Ce', 'O', 'Empty', 'O',
            'Empty', 'O', 'Ce', 'O', 'Empty', 'O', 'Ce', 'O', 'Ce', 'O',
            'Empty', 'O', 'Ce', 'O', 'Empty', 'O'
        ]

        possible_types = ['Ce3', 'Empty', 'O', 'Ce', 'Vacancy']

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

        # Determine a mapping between our types and valid ATK types.
        # Types not present in the mapping are ignored in the ATK script.

        type_map = {
            "Ce3": "Vanadium",
            "Ce": "Cerium",
            "O": "Oxygen",
        }

        # Get the ATK script.
        atk_script = configuration._atkScript(type_map)

        # Check that it looks as we expect.
        ref_script = """# ----------------------------------------------------------
# ATK 12.8.2 BulkConfiguration script generated from KMCLib
# configuration version 1.0.
# ----------------------------------------------------------

# Specify the lattice parameters.
vector_a = [  22.56000000,   1.32000000,   0.48000000]*Angstrom
vector_b = [   0.44000000,  21.84000000,   0.40000000]*Angstrom
vector_c = [   2.00000000,   1.72000000,  21.64000000]*Angstrom
lattice = UnitCell(vector_a, vector_b, vector_c)

# Define the elements.
elements = [Vanadium, Oxygen, Oxygen, Cerium, Oxygen, Oxygen,
            Oxygen, Cerium, Oxygen, Cerium, Oxygen, Cerium,
            Oxygen, Oxygen, Cerium, Oxygen, Oxygen, Oxygen,
            Cerium, Oxygen, Oxygen, Cerium, Oxygen, Oxygen,
            Cerium, Oxygen, Oxygen, Cerium, Oxygen, Vanadium,
            Oxygen, Oxygen, Cerium, Oxygen, Oxygen, Oxygen,
            Cerium, Oxygen, Oxygen, Cerium, Oxygen, Cerium,
            Oxygen, Oxygen, Cerium, Oxygen, Oxygen, Cerium,
            Oxygen, Oxygen, Cerium, Oxygen, Oxygen, Oxygen,
            Cerium, Oxygen, Oxygen, Cerium, Oxygen, Cerium,
            Oxygen, Oxygen, Cerium, Oxygen, Oxygen, Oxygen,
            Cerium, Oxygen, Oxygen, Cerium, Oxygen, Oxygen,
            Cerium, Oxygen, Oxygen, Cerium, Oxygen, Cerium,
            Oxygen, Oxygen, Cerium, Oxygen, Oxygen, Oxygen,
            Cerium, Oxygen, Oxygen, Cerium, Oxygen, Cerium,
            Oxygen, Oxygen, Cerium, Oxygen, Oxygen]

# Define the coordinates.
coordinates = [[  5.00000000e-02,  7.50000000e-02,  1.00000000e-01],
               [  1.30000000e-01,  1.35000000e-01,  1.25250000e-01],
               [  1.30000000e-01,  1.35000000e-01,  3.75250000e-01],
               [  5.00000000e-02,  7.50000000e-02,  6.00000000e-01],
               [  1.30000000e-01,  1.35000000e-01,  6.25250000e-01],
               [  1.30000000e-01,  1.35000000e-01,  8.75250000e-01],
               [  1.30000000e-01,  3.85000000e-01,  1.25250000e-01],
               [  5.00000000e-02,  3.25000000e-01,  3.50000000e-01],
               [  1.30000000e-01,  3.85000000e-01,  3.75250000e-01],
               [  5.00000000e-02,  3.25000000e-01,  8.50000000e-01],
               [  1.30000000e-01,  3.85000000e-01,  8.75250000e-01],
               [  5.00000000e-02,  5.75000000e-01,  1.00000000e-01],
               [  1.30000000e-01,  6.35000000e-01,  1.25250000e-01],
               [  1.30000000e-01,  6.35000000e-01,  3.75250000e-01],
               [  5.00000000e-02,  5.75000000e-01,  6.00000000e-01],
               [  1.30000000e-01,  6.35000000e-01,  6.25250000e-01],
               [  1.30000000e-01,  6.35000000e-01,  8.75250000e-01],
               [  1.30000000e-01,  8.85000000e-01,  1.25250000e-01],
               [  5.00000000e-02,  8.25000000e-01,  3.50000000e-01],
               [  1.30000000e-01,  8.85000000e-01,  3.75250000e-01],
               [  1.30000000e-01,  8.85000000e-01,  6.25250000e-01],
               [  5.00000000e-02,  8.25000000e-01,  8.50000000e-01],
               [  1.30000000e-01,  8.85000000e-01,  8.75250000e-01],
               [  3.80000000e-01,  1.35000000e-01,  1.25250000e-01],
               [  3.00000000e-01,  7.50000000e-02,  3.50000000e-01],
               [  3.80000000e-01,  1.35000000e-01,  3.75250000e-01],
               [  3.80000000e-01,  1.35000000e-01,  6.25250000e-01],
               [  3.00000000e-01,  7.50000000e-02,  8.50000000e-01],
               [  3.80000000e-01,  1.35000000e-01,  8.75250000e-01],
               [  3.00000000e-01,  3.25000000e-01,  1.00000000e-01],
               [  3.80000000e-01,  3.85000000e-01,  1.25250000e-01],
               [  3.80000000e-01,  3.85000000e-01,  3.75250000e-01],
               [  3.00000000e-01,  3.25000000e-01,  6.00000000e-01],
               [  3.80000000e-01,  3.85000000e-01,  6.25250000e-01],
               [  3.80000000e-01,  3.85000000e-01,  8.75250000e-01],
               [  3.80000000e-01,  6.35000000e-01,  1.25250000e-01],
               [  3.00000000e-01,  5.75000000e-01,  3.50000000e-01],
               [  3.80000000e-01,  6.35000000e-01,  3.75250000e-01],
               [  3.80000000e-01,  6.35000000e-01,  6.25250000e-01],
               [  3.00000000e-01,  5.75000000e-01,  8.50000000e-01],
               [  3.80000000e-01,  6.35000000e-01,  8.75250000e-01],
               [  3.00000000e-01,  8.25000000e-01,  1.00000000e-01],
               [  3.80000000e-01,  8.85000000e-01,  1.25250000e-01],
               [  3.80000000e-01,  8.85000000e-01,  3.75250000e-01],
               [  3.00000000e-01,  8.25000000e-01,  6.00000000e-01],
               [  3.80000000e-01,  8.85000000e-01,  6.25250000e-01],
               [  3.80000000e-01,  8.85000000e-01,  8.75250000e-01],
               [  5.50000000e-01,  7.50000000e-02,  1.00000000e-01],
               [  6.30000000e-01,  1.35000000e-01,  1.25250000e-01],
               [  6.30000000e-01,  1.35000000e-01,  3.75250000e-01],
               [  5.50000000e-01,  7.50000000e-02,  6.00000000e-01],
               [  6.30000000e-01,  1.35000000e-01,  6.25250000e-01],
               [  6.30000000e-01,  1.35000000e-01,  8.75250000e-01],
               [  6.30000000e-01,  3.85000000e-01,  1.25250000e-01],
               [  5.50000000e-01,  3.25000000e-01,  3.50000000e-01],
               [  6.30000000e-01,  3.85000000e-01,  3.75250000e-01],
               [  6.30000000e-01,  3.85000000e-01,  6.25250000e-01],
               [  5.50000000e-01,  3.25000000e-01,  8.50000000e-01],
               [  6.30000000e-01,  3.85000000e-01,  8.75250000e-01],
               [  5.50000000e-01,  5.75000000e-01,  1.00000000e-01],
               [  6.30000000e-01,  6.35000000e-01,  1.25250000e-01],
               [  6.30000000e-01,  6.35000000e-01,  3.75250000e-01],
               [  5.50000000e-01,  5.75000000e-01,  6.00000000e-01],
               [  6.30000000e-01,  6.35000000e-01,  6.25250000e-01],
               [  6.30000000e-01,  6.35000000e-01,  8.75250000e-01],
               [  6.30000000e-01,  8.85000000e-01,  1.25250000e-01],
               [  5.50000000e-01,  8.25000000e-01,  3.50000000e-01],
               [  6.30000000e-01,  8.85000000e-01,  3.75250000e-01],
               [  6.30000000e-01,  8.85000000e-01,  6.25250000e-01],
               [  5.50000000e-01,  8.25000000e-01,  8.50000000e-01],
               [  6.30000000e-01,  8.85000000e-01,  8.75250000e-01],
               [  8.80000000e-01,  1.35000000e-01,  1.25250000e-01],
               [  8.00000000e-01,  7.50000000e-02,  3.50000000e-01],
               [  8.80000000e-01,  1.35000000e-01,  3.75250000e-01],
               [  8.80000000e-01,  1.35000000e-01,  6.25250000e-01],
               [  8.00000000e-01,  7.50000000e-02,  8.50000000e-01],
               [  8.80000000e-01,  1.35000000e-01,  8.75250000e-01],
               [  8.00000000e-01,  3.25000000e-01,  1.00000000e-01],
               [  8.80000000e-01,  3.85000000e-01,  1.25250000e-01],
               [  8.80000000e-01,  3.85000000e-01,  3.75250000e-01],
               [  8.00000000e-01,  3.25000000e-01,  6.00000000e-01],
               [  8.80000000e-01,  3.85000000e-01,  6.25250000e-01],
               [  8.80000000e-01,  3.85000000e-01,  8.75250000e-01],
               [  8.80000000e-01,  6.35000000e-01,  1.25250000e-01],
               [  8.00000000e-01,  5.75000000e-01,  3.50000000e-01],
               [  8.80000000e-01,  6.35000000e-01,  3.75250000e-01],
               [  8.80000000e-01,  6.35000000e-01,  6.25250000e-01],
               [  8.00000000e-01,  5.75000000e-01,  8.50000000e-01],
               [  8.80000000e-01,  6.35000000e-01,  8.75250000e-01],
               [  8.00000000e-01,  8.25000000e-01,  1.00000000e-01],
               [  8.80000000e-01,  8.85000000e-01,  1.25250000e-01],
               [  8.80000000e-01,  8.85000000e-01,  3.75250000e-01],
               [  8.00000000e-01,  8.25000000e-01,  6.00000000e-01],
               [  8.80000000e-01,  8.85000000e-01,  6.25250000e-01],
               [  8.80000000e-01,  8.85000000e-01,  8.75250000e-01]]

# Setup the configuration.
bulk_configuration = BulkConfiguration(
    bravais_lattice=lattice,
    elements=elements,
    fractional_coordinates=coordinates )

# ----------------------------------------------------------
"""
        self.assertEqual(atk_script, ref_script)