Esempio n. 1
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)
Esempio n. 2
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()
Esempio n. 3
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)
Esempio n. 4
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 )
Esempio n. 5
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()
Esempio n. 6
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))
Esempio n. 7
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))
Esempio n. 8
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()))
Esempio n. 9
0
    def testQueries(self):
        """ Test the configuration's query functions. """
        config = KMCConfiguration.__new__(KMCConfiguration)

        c0_ref = numpy.random.random()
        c1_ref = numpy.random.random()
        c2_ref = numpy.random.random()

        # Set the backend proxy.
        class BackendProxy(object):
            def __init__(self):
                pass

            def elements(self):
                return ("B", "F", "A")

            def atomIDElements(self):
                return ("A", "B", "F")

            def atomIDCoordinates(self):
                return (Backend.Coordinate(c0_ref, c1_ref, c2_ref), )

        config._KMCConfiguration__backend = BackendProxy()

        # Query and check.
        atom_id_types = config.atomIDTypes()
        atom_id_coords = config.atomIDCoordinates()
        lattice_types = config.types()

        self.assertEqual(atom_id_types, ("A", "B", "F"))
        self.assertEqual(lattice_types, ["B", "F", "A"])

        self.assertAlmostEqual(atom_id_coords[0][0], c0_ref, 10)
        self.assertAlmostEqual(atom_id_coords[0][1], c1_ref, 10)
        self.assertAlmostEqual(atom_id_coords[0][2], c2_ref, 10)
Esempio n. 10
0
    def testConstruction(self):
        """ Test that the XYZTrajectory object can be constructed. """
        filename = "abc123.xyz"
        name = os.path.abspath(os.path.dirname(__file__))
        name = os.path.join(name, "..", "..")
        name = os.path.join(name, "TestUtilities", "Scratch")
        filename = os.path.join(name, filename)

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

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

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

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

        # Check that the internal memory buffers have been initiated.
        self.assertEqual(t._XYZTrajectory__atom_id_types, [])
        self.assertEqual(t._XYZTrajectory__atom_id_coordinates, [])
        self.assertEqual(t._XYZTrajectory__time, [])
        self.assertEqual(t._XYZTrajectory__step, [])
Esempio n. 11
0
    def testQueries(self):
        """ Test the configuration's query functions. """
        config = KMCConfiguration.__new__(KMCConfiguration)

        c0_ref = numpy.random.random()
        c1_ref = numpy.random.random()
        c2_ref = numpy.random.random()

        # Set the backend proxy.
        class BackendProxy(object):
            def __init__(self):
                pass
            def elements(self):
                return ("B", "F", "A")
            def atomIDElements(self):
                return ("A", "B", "F")
            def atomIDCoordinates(self):
                return (Backend.Coordinate(c0_ref,c1_ref,c2_ref),)

        config._KMCConfiguration__backend = BackendProxy()

        # Query and check.
        atom_id_types  = config.atomIDTypes()
        atom_id_coords = config.atomIDCoordinates()
        lattice_types  = config.types()

        self.assertEqual(atom_id_types, ("A","B","F"))
        self.assertEqual(lattice_types, ["B","F","A"])

        self.assertAlmostEqual(atom_id_coords[0][0], c0_ref, 10)
        self.assertAlmostEqual(atom_id_coords[0][1], c1_ref, 10)
        self.assertAlmostEqual(atom_id_coords[0][2], c2_ref, 10)
Esempio n. 12
0
    def testQueries(self):
        """ Test the configuration's query functions. """
        config = KMCConfiguration.__new__(KMCConfiguration)
        config._KMCConfiguration__use_buckets = False

        c0_ref = numpy.random.random()
        c1_ref = numpy.random.random()
        c2_ref = numpy.random.random()

        # Set the backend proxy.
        class BackendProxy(object):
            def __init__(self):
                pass

            def elements(self):
                return ("B", "F", "A")

            def atomIDElements(self):
                return ("A", "B", "F")

            def atomIDCoordinates(self):
                return (Backend.Coordinate(c0_ref, c1_ref, c2_ref), )

            def movedAtomIDs(self):
                return (123, 234)

            def latestEventProcess(self):
                return 995976943

            def latestEventSite(self):
                return 556462676

            def particlesPerType(self):
                return (123, 467, 432)

        config._KMCConfiguration__backend = BackendProxy()

        # Query and check.
        atom_id_types = config.atomIDTypes()
        atom_id_coords = config.atomIDCoordinates()
        lattice_types = config.types()
        moved_atom_ids = config.movedAtomIDs()
        latest_event_process = config.latestEventProcess()
        latest_event_site = config.latestEventSite()
        particles_per_type = config.particlesPerType()

        self.assertEqual(atom_id_types, ("A", "B", "F"))
        self.assertEqual(lattice_types, ["B", "F", "A"])

        self.assertAlmostEqual(atom_id_coords[0][0], c0_ref, 10)
        self.assertAlmostEqual(atom_id_coords[0][1], c1_ref, 10)
        self.assertAlmostEqual(atom_id_coords[0][2], c2_ref, 10)

        self.assertEqual(moved_atom_ids, (123, 234))
        self.assertEqual(latest_event_process, 995976943)
        self.assertEqual(latest_event_site, 556462676)
        self.assertEqual(particles_per_type, (123, 467, 432))
Esempio n. 13
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))
Esempio n. 14
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)
Esempio n. 15
0
    def testQueries(self):
        """ Test the configuration's query functions. """
        config = KMCConfiguration.__new__(KMCConfiguration)
        config._KMCConfiguration__use_buckets = False

        c0_ref = numpy.random.random()
        c1_ref = numpy.random.random()
        c2_ref = numpy.random.random()

        # Set the backend proxy.
        class BackendProxy(object):
            def __init__(self):
                pass
            def elements(self):
                return ("B", "F", "A")
            def atomIDElements(self):
                return ("A", "B", "F")
            def atomIDCoordinates(self):
                return (Backend.Coordinate(c0_ref,c1_ref,c2_ref),)
            def movedAtomIDs(self):
                return (123, 234)
            def latestEventProcess(self):
                return 995976943
            def latestEventSite(self):
                return 556462676
            def particlesPerType(self):
                return (123, 467, 432)

        config._KMCConfiguration__backend = BackendProxy()

        # Query and check.
        atom_id_types        = config.atomIDTypes()
        atom_id_coords       = config.atomIDCoordinates()
        lattice_types        = config.types()
        moved_atom_ids       = config.movedAtomIDs()
        latest_event_process = config.latestEventProcess()
        latest_event_site    = config.latestEventSite()
        particles_per_type   = config.particlesPerType()

        self.assertEqual(atom_id_types, ("A","B","F"))
        self.assertEqual(lattice_types, ["B","F","A"])

        self.assertAlmostEqual(atom_id_coords[0][0], c0_ref, 10)
        self.assertAlmostEqual(atom_id_coords[0][1], c1_ref, 10)
        self.assertAlmostEqual(atom_id_coords[0][2], c2_ref, 10)

        self.assertEqual(moved_atom_ids,      (123, 234))
        self.assertEqual(latest_event_process, 995976943)
        self.assertEqual(latest_event_site,    556462676)
        self.assertEqual(particles_per_type,  (123, 467, 432))
Esempio n. 16
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 )
Esempio n. 17
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))
Esempio n. 18
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()))
Esempio n. 19
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)
Esempio n. 20
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, [])
Esempio n. 21
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))
Esempio n. 22
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, [])
Esempio n. 23
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)
Esempio n. 24
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', '*']))
Esempio n. 25
0
    def testRunRngTypeDevice(self):
        """ Test to use the PRNG DEVICE. """
        # Cell.
        cell_vectors = [[   1.000000e+00,   0.000000e+00,   0.000000e+00],
                        [   0.000000e+00,   1.000000e+00,   0.000000e+00],
                        [   0.000000e+00,   0.000000e+00,   1.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=(4,4,1),
            periodic=(True, True, False))

        # Configuration.
        types = ['B']*16
        possible_types = ['A','B']
        configuration = KMCConfiguration(
            lattice=lattice,
            types=types,
            possible_types=possible_types)

        # Interactions.
        coordinates = [[   0.000000e+00,   0.000000e+00,   0.000000e+00]]
        process_0 = KMCProcess(coordinates,
                               ['A'],
                               ['B'],
                               basis_sites=[0],
                               rate_constant=4.0)
        process_1 = KMCProcess(coordinates,
                               ['B'],
                               ['A'],
                               basis_sites=[0],
                               rate_constant=1.0)

        processes = [process_0, process_1]
        interactions = KMCInteractions(processes)

        # Setup the model.
        ab_flip_model_DEVICE   = KMCLatticeModel(configuration, interactions)

        support_device = False

        if (not support_device):
            # If DEVICE is not supported on your system this is the test you should run.
            self.assertRaises( Error,
                               lambda: ab_flip_model_DEVICE.run(KMCControlParameters(number_of_steps=10000,
                                                                                     dump_interval=5000,
                                                                                     seed=2013,
                                                                                     rng_type="DEVICE")))

        else:
            # If DEVICE is supported the aboove test will fail, and you should run this tests instead.

            # Run the model for 10000 steps with DEVICE.
            ab_flip_model_DEVICE.run(KMCControlParameters(number_of_steps=10000,
                                                          dump_interval=5000,
                                                          seed=2013,
                                                          rng_type="DEVICE"))
            # Get the simulation time out.
            t_DEVICE = ab_flip_model_DEVICE._KMCLatticeModel__cpp_timer.simulationTime()
            self.assertTrue(t_DEVICE < 410.0 and t_DEVICE > 370.0)
Esempio n. 26
0
    def testConstruction(self):
        """ Test the construction of the lattice model """
        # Setup a unitcell.
        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'])

        # A first process.
        coords = [[1.0,2.0,3.4],[1.1,1.2,1.3]]
        types0 = ["A","B"]
        types1 = ["B","A"]
        sites  = [0,1,2]
        rate_0_1 = 3.5
        process_0 = KMCProcess(coords,
                               types0,
                               types1,
                               basis_sites=sites,
                               rate_constant=rate_0_1)

        # A second process.
        coords = [[1.0,2.0,3.4],[1.1,1.2,1.3]]
        types0 = ["A","C"]
        types1 = ["C","A"]
        sites  = [0,1,2]
        rate_0_1 = 1.5
        process_1 = KMCProcess(coords,
                               types0,
                               types1,
                               basis_sites=sites,
                               rate_constant=rate_0_1)

        # Construct the interactions object.
        processes = [process_0, process_1]
        interactions = KMCInteractions(processes=processes)

        # Construct the model.
        model = KMCLatticeModel(config, interactions)

        # Check that it has the attribute _backend which is None
        self.assertTrue(hasattr(model,"_KMCLatticeModel__backend"))
        self.assertTrue(model._KMCLatticeModel__backend is None)

        # Check that it has the correct interactions stored.
        self.assertTrue(model._KMCLatticeModel__interactions == interactions)

        # Check that it has the correct configuration stored.
        self.assertTrue(model._KMCLatticeModel__configuration == config)
Esempio n. 27
0
    def testRunTrajectory(self):
        """ Test the run of an A-B flip model with trajectory output. """
        # Cell.
        cell_vectors = [[   1.000000e+00,   0.000000e+00,   0.000000e+00],
                        [   0.000000e+00,   1.000000e+00,   0.000000e+00],
                        [   0.000000e+00,   0.000000e+00,   1.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=(4,4,1),
            periodic=(True, True, False))

        # Configuration.
        types = ['B']*16
        possible_types = ['A','B']
        configuration = KMCConfiguration(
            lattice=lattice,
            types=types,
            possible_types=possible_types)

        # Interactions.
        coordinates = [[   0.000000e+00,   0.000000e+00,   0.000000e+00]]
        process_0 = KMCProcess(coordinates,
                               ['A'],
                               ['B'],
                               basis_sites=[0],
                               rate_constant=4.0)
        process_1 = KMCProcess(coordinates,
                               ['B'],
                               ['A'],
                               basis_sites=[0],
                               rate_constant=1.0)

        processes = [process_0, process_1]
        interactions = KMCInteractions(processes)

        # Setup the model.
        ab_flip_model = KMCLatticeModel(configuration, interactions)

        # Construct the trajectory fileames.
        name = os.path.abspath(os.path.dirname(__file__))
        name = os.path.join(name, "..", "TestUtilities", "Scratch")

        lattice_trajectory_filename = os.path.join(name, "ab_flip_traj_lattice.py")
        xyz_trajectory_filename = os.path.join(name, "ab_flip_traj_xyz.xyz")

        self.__files_to_remove.append(lattice_trajectory_filename)
        self.__files_to_remove.append(xyz_trajectory_filename)

        # The control parameters.
        control_parameters = KMCControlParameters(number_of_steps=1000,
                                                  dump_interval=500,
                                                  seed=2013)

        # Run the model for 1000 steps with a lattice trajectory.
        ab_flip_model.run(control_parameters,
                          trajectory_filename=lattice_trajectory_filename,
                          trajectory_type='lattice')

        # Check the file content.
        ref_lattice = """
sites=[[       0.000000,       0.000000,       0.000000],
       [       0.000000,       1.000000,       0.000000],
       [       0.000000,       2.000000,       0.000000],
       [       0.000000,       3.000000,       0.000000],
       [       1.000000,       0.000000,       0.000000],
       [       1.000000,       1.000000,       0.000000],
       [       1.000000,       2.000000,       0.000000],
       [       1.000000,       3.000000,       0.000000],
       [       2.000000,       0.000000,       0.000000],
       [       2.000000,       1.000000,       0.000000],
       [       2.000000,       2.000000,       0.000000],
       [       2.000000,       3.000000,       0.000000],
       [       3.000000,       0.000000,       0.000000],
       [       3.000000,       1.000000,       0.000000],
       [       3.000000,       2.000000,       0.000000],
       [       3.000000,       3.000000,       0.000000]]
times=[]
steps=[]
types=[]
times.append(  0.0000000000e+00)
steps.append(0)
types.append(["B","B","B","B","B","B","B","B","B","B","B","B","B","B","B","B"])
times.append(  1.9093684175e+01)
steps.append(500)
types.append(["B","A","B","B","A","B","B","B","A","B","B","B","B","B","B","A"])
times.append(  4.0622006972e+01)
steps.append(1000)
types.append(["B","A","A","B","B","B","B","A","B","B","B","A","B","B","B","B"])
"""



        with open(lattice_trajectory_filename, "r") as t:
            lattice_data = t.read()

        # Check with "in" to avoid comparing dates.
        self.assertTrue(ref_lattice in lattice_data)

        # Run the model for 1000 steps with an xyz trajectory.
        ab_flip_model.run(control_parameters,
                          trajectory_filename=xyz_trajectory_filename,
                          trajectory_type='xyz')


        ref_xyz = """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 1 1

PERIODICITY True True False

STEP 0
          16
    TIME 4.0622006972e+01
                B   0.0000000000e+00 0.0000000000e+00 0.0000000000e+00  0
                A   0.0000000000e+00 1.0000000000e+00 0.0000000000e+00  1
                A   0.0000000000e+00 2.0000000000e+00 0.0000000000e+00  2
                B   0.0000000000e+00 3.0000000000e+00 0.0000000000e+00  3
                B   1.0000000000e+00 0.0000000000e+00 0.0000000000e+00  4
                B   1.0000000000e+00 1.0000000000e+00 0.0000000000e+00  5
                B   1.0000000000e+00 2.0000000000e+00 0.0000000000e+00  6
                A   1.0000000000e+00 3.0000000000e+00 0.0000000000e+00  7
                B   2.0000000000e+00 0.0000000000e+00 0.0000000000e+00  8
                B   2.0000000000e+00 1.0000000000e+00 0.0000000000e+00  9
                B   2.0000000000e+00 2.0000000000e+00 0.0000000000e+00  10
                A   2.0000000000e+00 3.0000000000e+00 0.0000000000e+00  11
                B   3.0000000000e+00 0.0000000000e+00 0.0000000000e+00  12
                B   3.0000000000e+00 1.0000000000e+00 0.0000000000e+00  13
                B   3.0000000000e+00 2.0000000000e+00 0.0000000000e+00  14
                B   3.0000000000e+00 3.0000000000e+00 0.0000000000e+00  15
STEP 500
          16
    TIME 5.9660935122e+01
                B   0.0000000000e+00 0.0000000000e+00 0.0000000000e+00  0
                A   0.0000000000e+00 1.0000000000e+00 0.0000000000e+00  1
                B   0.0000000000e+00 2.0000000000e+00 0.0000000000e+00  2
                B   0.0000000000e+00 3.0000000000e+00 0.0000000000e+00  3
                B   1.0000000000e+00 0.0000000000e+00 0.0000000000e+00  4
                B   1.0000000000e+00 1.0000000000e+00 0.0000000000e+00  5
                B   1.0000000000e+00 2.0000000000e+00 0.0000000000e+00  6
                A   1.0000000000e+00 3.0000000000e+00 0.0000000000e+00  7
                B   2.0000000000e+00 0.0000000000e+00 0.0000000000e+00  8
                B   2.0000000000e+00 1.0000000000e+00 0.0000000000e+00  9
                B   2.0000000000e+00 2.0000000000e+00 0.0000000000e+00  10
                B   2.0000000000e+00 3.0000000000e+00 0.0000000000e+00  11
                A   3.0000000000e+00 0.0000000000e+00 0.0000000000e+00  12
                A   3.0000000000e+00 1.0000000000e+00 0.0000000000e+00  13
                B   3.0000000000e+00 2.0000000000e+00 0.0000000000e+00  14
                B   3.0000000000e+00 3.0000000000e+00 0.0000000000e+00  15
STEP 1000
          16
    TIME 8.1189257919e+01
                A   0.0000000000e+00 0.0000000000e+00 0.0000000000e+00  0
                B   0.0000000000e+00 1.0000000000e+00 0.0000000000e+00  1
                B   0.0000000000e+00 2.0000000000e+00 0.0000000000e+00  2
                B   0.0000000000e+00 3.0000000000e+00 0.0000000000e+00  3
                B   1.0000000000e+00 0.0000000000e+00 0.0000000000e+00  4
                A   1.0000000000e+00 1.0000000000e+00 0.0000000000e+00  5
                B   1.0000000000e+00 2.0000000000e+00 0.0000000000e+00  6
                B   1.0000000000e+00 3.0000000000e+00 0.0000000000e+00  7
                B   2.0000000000e+00 0.0000000000e+00 0.0000000000e+00  8
                B   2.0000000000e+00 1.0000000000e+00 0.0000000000e+00  9
                A   2.0000000000e+00 2.0000000000e+00 0.0000000000e+00  10
                A   2.0000000000e+00 3.0000000000e+00 0.0000000000e+00  11
                B   3.0000000000e+00 0.0000000000e+00 0.0000000000e+00  12
                B   3.0000000000e+00 1.0000000000e+00 0.0000000000e+00  13
                B   3.0000000000e+00 2.0000000000e+00 0.0000000000e+00  14
                B   3.0000000000e+00 3.0000000000e+00 0.0000000000e+00  15
"""

        with open(xyz_trajectory_filename, "r") as t:
            xyz_data = t.read()

        self.assertEqual(ref_xyz, xyz_data)

        # Running with wrong trajectory_type input fails.
        self.assertRaises( Error,
                           lambda : ab_flip_model.run(control_parameters,
                                                      trajectory_filename=xyz_trajectory_filename,
                                                      trajectory_type='abc') )

        self.assertRaises( Error,
                           lambda : ab_flip_model.run(control_parameters,
                                                      trajectory_filename=xyz_trajectory_filename,
                                                      trajectory_type=123) )
Esempio n. 28
0
    def testCustomRatesRun(self):
        """ Test the run of an A-B flip model with custom rates. """
        # Cell.
        cell_vectors = [[   1.000000e+00,   0.000000e+00,   0.000000e+00],
                        [   0.000000e+00,   1.000000e+00,   0.000000e+00],
                        [   0.000000e+00,   0.000000e+00,   1.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=(10,10,1),
            periodic=(True, True, False))

        # Configuration.
        types = ['B']*100
        possible_types = ['A','B']
        configuration = KMCConfiguration(
            lattice=lattice,
            types=types,
            possible_types=possible_types)

        # Interactions.
        coordinates = [[   0.000000e+00,   0.000000e+00,   0.000000e+00]]
        process_0 = KMCProcess(coordinates, ['A'], ['B'], None, [0], 4.0)
        process_1 = KMCProcess(coordinates, ['B'], ['A'], None, [0], 1.0)
        processes = [process_0, process_1]
        interactions = KMCInteractions(processes,
                                       implicit_wildcards=True)

        # Custom rates.
        rate_calculator = CustomRateCalculator
        interactions.setRateCalculator(rate_calculator)

        # Setup the model.
        ab_flip_model = KMCLatticeModel(configuration, interactions)

        # Run the model with a trajectory file.
        name = os.path.abspath(os.path.dirname(__file__))
        name = os.path.join(name, "..", "TestUtilities", "Scratch")
        trajectory_filename = os.path.join(name, "ab_flip_traj_custom.py")
        self.__files_to_remove.append(trajectory_filename)

        # The control parameters.
        control_parameters = KMCControlParameters(number_of_steps=1000,
                                                  dump_interval=500,
                                                  seed=2013)

        # Run the model for 1000 steps.
        ab_flip_model.run(control_parameters,
                          trajectory_filename=trajectory_filename)

        # Read the first last frames from the trajectory file and check that
        # the fraction of A is close to 75% in the last, and 0 in the first.
        if MPICommons.isMaster():
            global_dict = {}
            local_dict  = {}
            execfile(trajectory_filename, global_dict, local_dict)

            # Count the first frame.
            elem = local_dict["types"][0]
            nA = len([ ee for ee in elem if ee == "A" ])
            nB = len([ ee for ee in elem if ee == "B" ])
            self.assertEqual(nA, 0)
            self.assertEqual(nB, 100)

            # Count the last frame.
            elem = local_dict["types"][-1]
            nA = len([ ee for ee in elem if ee == "A" ])
            nB = len([ ee for ee in elem if ee == "B" ])

            # Note that the average over a long simulation should be
            # 75% A using the modified rate function. In this particular
            # step the A population is 74%.
            value = 1.0 * nA / (nA + nB)
            self.assertAlmostEqual(0.74, value, 2)
Esempio n. 29
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)
Esempio 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)
Esempio n. 31
0
    def testRunRngType(self):
        """ Test that it is possible to run with each of the supported PRNG:s. """
        # Cell.
        cell_vectors = [[   1.000000e+00,   0.000000e+00,   0.000000e+00],
                        [   0.000000e+00,   1.000000e+00,   0.000000e+00],
                        [   0.000000e+00,   0.000000e+00,   1.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=(4,4,1),
            periodic=(True, True, False))

        # Configuration.
        types = ['B']*16
        possible_types = ['A','B']
        configuration = KMCConfiguration(
            lattice=lattice,
            types=types,
            possible_types=possible_types)

        # Interactions.
        coordinates = [[   0.000000e+00,   0.000000e+00,   0.000000e+00]]
        process_0 = KMCProcess(coordinates,
                               ['A'],
                               ['B'],
                               basis_sites=[0],
                               rate_constant=4.0)
        process_1 = KMCProcess(coordinates,
                               ['B'],
                               ['A'],
                               basis_sites=[0],
                               rate_constant=1.0)

        processes = [process_0, process_1]
        interactions = KMCInteractions(processes)

        # Setup the models.
        ab_flip_model_MT       = KMCLatticeModel(configuration, interactions)
        ab_flip_model_RANLUX24 = KMCLatticeModel(configuration, interactions)
        ab_flip_model_RANLUX48 = KMCLatticeModel(configuration, interactions)
        ab_flip_model_MINSTD   = KMCLatticeModel(configuration, interactions)
        ab_flip_model_DEVICE   = KMCLatticeModel(configuration, interactions)

        # Run the model for 10000 steps with MT.
        ab_flip_model_MT.run(KMCControlParameters(number_of_steps=10000,
                                                  dump_interval=5000,
                                                  seed=2013,
                                                  rng_type="MT"))

        # Get the simulation time out.
        t_MT = ab_flip_model_MT._KMCLatticeModel__cpp_timer.simulationTime()

        # Run the model for 10000 steps with RANLUX24.
        ab_flip_model_RANLUX24.run(KMCControlParameters(number_of_steps=10000,
                                                        dump_interval=5000,
                                                        seed=2013,
                                                        rng_type="RANLUX24"))
        # Get the simulation time out.
        t_RANLUX24 = ab_flip_model_RANLUX24._KMCLatticeModel__cpp_timer.simulationTime()


        # Run the model for 10000 steps with RANLUX48.
        ab_flip_model_RANLUX48.run(KMCControlParameters(number_of_steps=10000,
                                                        dump_interval=5000,
                                                        seed=2013,
                                                        rng_type="RANLUX48"))
        # Get the simulation time out.
        t_RANLUX48 = ab_flip_model_RANLUX48._KMCLatticeModel__cpp_timer.simulationTime()

        # Run the model for 10000 steps with MINSTD.
        ab_flip_model_MINSTD.run(KMCControlParameters(number_of_steps=10000,
                                                      dump_interval=5000,
                                                      seed=2013,
                                                      rng_type="MINSTD"))
        # Get the simulation time out.
        t_MINSTD = ab_flip_model_MINSTD._KMCLatticeModel__cpp_timer.simulationTime()

        # These values should be simillar but not equal. Check against hardcoded values.
        self.assertAlmostEqual(t_MT,       394.569398158, 5)
        self.assertAlmostEqual(t_RANLUX24, 389.712162523, 5)
        self.assertAlmostEqual(t_RANLUX48, 390.544423280, 5)
        self.assertAlmostEqual(t_MINSTD,   384.712302086, 5)
Esempio n. 32
0
    def testRunFailAnalysis(self):
        """ Test that the analyis plugins get called correctly. """
        # Cell.
        cell_vectors = [[   1.000000e+00,   0.000000e+00,   0.000000e+00],
                        [   0.000000e+00,   1.000000e+00,   0.000000e+00],
                        [   0.000000e+00,   0.000000e+00,   1.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=(10,10,1),
            periodic=(True, True, False))

        # Configuration.
        types = ['B']*100
        possible_types = ['A','B']
        configuration = KMCConfiguration(
            lattice=lattice,
            types=types,
            possible_types=possible_types)

        # Interactions.
        coordinates = [[   0.000000e+00,   0.000000e+00,   0.000000e+00]]
        process_0 = KMCProcess(coordinates,
                               ['A'],
                               ['B'],
                               basis_sites=[0],
                               rate_constant=4.0)
        process_1 = KMCProcess(coordinates,
                               ['B'],
                               ['A'],
                               basis_sites=[0],
                               rate_constant=1.0)

        processes = [process_0, process_1]
        interactions = KMCInteractions(processes)

        # Setup the model.
        ab_flip_model = KMCLatticeModel(configuration, interactions)

        # The control parameters.
        control_parameters = KMCControlParameters(number_of_steps=1000,
                                                  dump_interval=500)

        # Setup a valid minimal analysis object.
        class AnalysisProxy1(KMCAnalysisPlugin):
            def __init__(self):
                pass

        # Fail because of not instantitated analysis.
        self.assertRaises( Error,
                           lambda : ab_flip_model.run(control_parameters,
                                                      analysis=[AnalysisProxy1]) )
        # Fail because of empty analyis list.
        self.assertRaises( Error,
                           lambda : ab_flip_model.run(control_parameters,
                                                      analysis=[]) )
        # Fail because of not list.
        self.assertRaises( Error,
                           lambda : ab_flip_model.run(control_parameters,
                                                      analysis=AnalysisProxy1()) )
        # Fail because of wrong type.
        self.assertRaises( Error,
                           lambda : ab_flip_model.run(control_parameters,
                                                      analysis=[AnalysisProxy1(), "AP3"]) )
Esempio n. 33
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)
Esempio n. 34
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)
Esempio n. 35
0
    def testBackend(self):
        """ Test that the backend object is correctly constructed. """
        # Setup a unitcell.
        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'])


        # A first process.
        coords = [[1.0,2.0,3.4],[1.1,1.2,1.3]]
        types0 = ["A","B"]
        types1 = ["B","A"]
        sites  = [0,1,2,3,4]
        rate_0_1 = 3.5
        process_0 = KMCProcess(coords,
                               types0,
                               types1,
                               basis_sites=sites,
                               rate_constant=rate_0_1)

        # A second process.
        types0 = ["A","C"]
        types1 = ["C","A"]
        rate_0_1 = 1.5
        process_1 = KMCProcess(coords,
                               types0,
                               types1,
                               basis_sites=sites,
                               rate_constant=rate_0_1)

        # Construct the interactions object.
        processes = [process_0, process_1]
        interactions = KMCInteractions(processes=processes)

        # Construct the model.
        model = KMCLatticeModel(config, interactions)

        # Get the c++ backend out.
        cpp_model = model._backend()

        # Check that this backend object is stored on the class.
        self.assertTrue(model._KMCLatticeModel__backend == cpp_model)
Esempio n. 36
0
    def testRunWithAnalysis(self):
        """ Test that the analyis plugins get called correctly. """
        # Cell.
        cell_vectors = [[   1.000000e+00,   0.000000e+00,   0.000000e+00],
                        [   0.000000e+00,   1.000000e+00,   0.000000e+00],
                        [   0.000000e+00,   0.000000e+00,   1.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=(10,10,1),
            periodic=(True, True, False))

        # Configuration.
        types = ['B']*100
        possible_types = ['A','B']
        configuration = KMCConfiguration(
            lattice=lattice,
            types=types,
            possible_types=possible_types)

        # Interactions.
        coordinates = [[   0.000000e+00,   0.000000e+00,   0.000000e+00]]
        process_0 = KMCProcess(coordinates,
                               ['A'],
                               ['B'],
                               basis_sites=[0],
                               rate_constant=4.0)
        process_1 = KMCProcess(coordinates,
                               ['B'],
                               ['A'],
                               basis_sites=[0],
                               rate_constant=1.0)

        processes = [process_0, process_1]
        interactions = KMCInteractions(processes)

        # Setup the model.
        ab_flip_model = KMCLatticeModel(configuration, interactions)

        # Run the model with a trajectory file.
        name = os.path.abspath(os.path.dirname(__file__))
        name = os.path.join(name, "..", "TestUtilities", "Scratch")
        trajectory_filename = os.path.join(name, "ab_flip_traj.py")
        self.__files_to_remove.append(trajectory_filename)

        # The control parameters.
        control_parameters = KMCControlParameters(number_of_steps=1000,
                                                  dump_interval=500,
                                                  analysis_interval=300)


        # Setup a valid minimal analysis object.
        class AnalysisProxy1(KMCAnalysisPlugin):
            def __init__(self):
                pass

        # Setup a slightly larger analyis object.
        class AnalysisProxy2(KMCAnalysisPlugin):
            def __init__(self):
                self.setup_called = False
                self.finalize_called = False
                self.register_step_counts = 0

            def setup(self, step, time, configuration):
                self.setup_called = True

            def registerStep(self, step, time, configuration):
                self.register_step_counts += 1

            def finalize(self):
                self.finalize_called = True

        ap2 = AnalysisProxy2()
        analysis = [ AnalysisProxy1(), ap2 ]

        # Run the model for 1000 steps with the analysis objects.
        # With dump interval 500 the analysis objects should  be
        # called on startup, the at step 300, 600 and step 900 and
        # a finalization after that.
        ab_flip_model.run(control_parameters,
                          trajectory_filename=trajectory_filename,
                          analysis=analysis)

        self.assertTrue(ap2.setup_called)
        self.assertTrue(ap2.finalize_called)
        self.assertEqual(ap2.register_step_counts, 3)
Esempio n. 37
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)
Esempio n. 38
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)
Esempio n. 39
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())
Esempio n. 40
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)
Esempio n. 41
0
    def testScript(self):
        """ Test that a script can be created. """
        # Setup a unitcell.
        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'])

        # A first process.
        coords = [[1.0,2.0,3.4],[1.1,1.2,1.3]]
        types0 = ["A","B"]
        types1 = ["B","A"]
        rate_0_1 = 3.5
        process_0 = KMCProcess(coords,
                               types0,
                               types1,
                               basis_sites=[0],
                               rate_constant=rate_0_1)

        # A second process.
        types0 = ["A","C"]
        types1 = ["C","A"]
        rate_0_1 = 1.5
        process_1 = KMCProcess(coords,
                               types0,
                               types1,
                               basis_sites=[0],
                               rate_constant=rate_0_1)

        # Construct the interactions object.
        processes = [process_0, process_1]
        interactions = KMCInteractions(processes)

        # Construct the model.
        model = KMCLatticeModel(config, interactions)

        # Get the script.
        script = model._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)

# -----------------------------------------------------------------------------
# Interactions

coordinates = [[   0.000000e+00,   0.000000e+00,   0.000000e+00],
               [   1.000000e-01,  -8.000000e-01,  -2.100000e+00]]

elements_before = ['A','B']
elements_after  = ['B','A']
move_vectors    = [(  0,[   1.000000e-01,  -8.000000e-01,  -2.100000e+00]),
                   (  1,[  -1.000000e-01,   8.000000e-01,   2.100000e+00])]
basis_sites     = [0]
rate_constant   =    3.500000e+00

process_0 = KMCProcess(
    coordinates=coordinates,
    elements_before=elements_before,
    elements_after=elements_after,
    move_vectors=move_vectors,
    basis_sites=basis_sites,
    rate_constant=rate_constant)

coordinates = [[   0.000000e+00,   0.000000e+00,   0.000000e+00],
               [   1.000000e-01,  -8.000000e-01,  -2.100000e+00]]

elements_before = ['A','C']
elements_after  = ['C','A']
move_vectors    = [(  0,[   1.000000e-01,  -8.000000e-01,  -2.100000e+00]),
                   (  1,[  -1.000000e-01,   8.000000e-01,   2.100000e+00])]
basis_sites     = [0]
rate_constant   =    1.500000e+00

process_1 = KMCProcess(
    coordinates=coordinates,
    elements_before=elements_before,
    elements_after=elements_after,
    move_vectors=move_vectors,
    basis_sites=basis_sites,
    rate_constant=rate_constant)

processes = [process_0,
             process_1]

interactions = KMCInteractions(
    processes=processes,
    implicit_wildcards=True)

# -----------------------------------------------------------------------------
# Lattice model

model = KMCLatticeModel(
    configuration=configuration,
    interactions=interactions)
"""
        self.assertEqual(script, ref_script)

        # Get the script again, with a different variable name.
        script = model._script(variable_name="my_model")

        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)

# -----------------------------------------------------------------------------
# Interactions

coordinates = [[   0.000000e+00,   0.000000e+00,   0.000000e+00],
               [   1.000000e-01,  -8.000000e-01,  -2.100000e+00]]

elements_before = ['A','B']
elements_after  = ['B','A']
move_vectors    = [(  0,[   1.000000e-01,  -8.000000e-01,  -2.100000e+00]),
                   (  1,[  -1.000000e-01,   8.000000e-01,   2.100000e+00])]
basis_sites     = [0]
rate_constant   =    3.500000e+00

process_0 = KMCProcess(
    coordinates=coordinates,
    elements_before=elements_before,
    elements_after=elements_after,
    move_vectors=move_vectors,
    basis_sites=basis_sites,
    rate_constant=rate_constant)

coordinates = [[   0.000000e+00,   0.000000e+00,   0.000000e+00],
               [   1.000000e-01,  -8.000000e-01,  -2.100000e+00]]

elements_before = ['A','C']
elements_after  = ['C','A']
move_vectors    = [(  0,[   1.000000e-01,  -8.000000e-01,  -2.100000e+00]),
                   (  1,[  -1.000000e-01,   8.000000e-01,   2.100000e+00])]
basis_sites     = [0]
rate_constant   =    1.500000e+00

process_1 = KMCProcess(
    coordinates=coordinates,
    elements_before=elements_before,
    elements_after=elements_after,
    move_vectors=move_vectors,
    basis_sites=basis_sites,
    rate_constant=rate_constant)

processes = [process_0,
             process_1]

interactions = KMCInteractions(
    processes=processes,
    implicit_wildcards=True)

# -----------------------------------------------------------------------------
# Lattice model

my_model = KMCLatticeModel(
    configuration=configuration,
    interactions=interactions)
"""

        # Check.
        self.assertEqual(script, ref_script)