Example #1
0
    def testQueryRepetitionsAndPeriodic(self):
        """ Test that the returned repetitions data is coorect. """
        cell_vectors = [[2.3, 0.0, 0.0],
                        [2.4, 3.0, 0.0],
                        [0.0, 0.0, 11.8]]

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

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

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

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

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

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

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

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

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

        # Construct the KMCLattice object.
        lattice = KMCLattice(unit_cell=unit_cell,
                             repetitions=repetitions,
                             periodic=periodic)
        self.assertFalse( lattice.periodic()[0] )
        self.assertTrue(  lattice.periodic()[1] )
        self.assertTrue(  lattice.periodic()[2] )
Example #2
0
    def testQueryRepetitionsAndPeriodic(self):
        """ Test that the returned repetitions data is coorect. """
        cell_vectors = [[2.3, 0.0, 0.0], [2.4, 3.0, 0.0], [0.0, 0.0, 11.8]]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        # Check that we fail in a controlled way if there is a problme with the file.
        self.assertRaises( Error,
                           lambda: getScriptComponent("THIS IS NOT A VALID PATH", numpy.ndarray) )
    def testGetScriptComponent(self):
        """ Test the general get script component function. """
        # Set the path to the file to read from.
        module_path = os.path.abspath(os.path.dirname(__file__))
        script_file_path = os.path.join(module_path, "..", "TestUtilities",
                                        "Scripts")
        script_file_path = os.path.join(script_file_path,
                                        "kmc_configuration_script.py")
        # Make sure the file exists.
        self.assertTrue(os.path.exists(script_file_path))

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

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

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

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

        # Check that we fail in a controlled way if there is a problme with the file.
        self.assertRaises(
            Error, lambda: getScriptComponent("THIS IS NOT A VALID PATH", numpy
                                              .ndarray))