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))
Esempio n. 2
0
    def testQueryBasis(self):
        """ Test that the returned basis data is coorect. """
        cell_vectors = [[2.3, 0.0, 0.0], [2.4, 3.0, 0.0], [0.0, 0.0, 11.8]]

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

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

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

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

        # Check that the basis is the one from the unitcell.
        self.assertAlmostEqual(
            numpy.linalg.norm(lattice.basis() -
                              lattice._KMCLattice__unit_cell.basis()), 0.0, 10)
Esempio n. 3
0
    def testQueryBasis(self):
        """ Test that the returned basis data is coorect. """
        cell_vectors = [[2.3, 0.0, 0.0],
                        [2.4, 3.0, 0.0],
                        [0.0, 0.0, 11.8]]

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

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

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

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

        # Check that the basis is the one from the unitcell.
        self.assertAlmostEqual(numpy.linalg.norm(lattice.basis() - lattice._KMCLattice__unit_cell.basis()), 0.0, 10)
Esempio n. 4
0
    def testGetScriptComponent(self):
        """ Test the general get script component function. """
        # Set the path to the file to read from.
        module_path = os.path.abspath(os.path.dirname(__file__))
        script_file_path = os.path.join(module_path,"..","TestUtilities","Scripts")
        script_file_path = os.path.join(script_file_path, "kmc_configuration_script.py")
        # Make sure the file exists.
        self.assertTrue( os.path.exists(script_file_path) )

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

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

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

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

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