コード例 #1
0
ファイル: KMCUnitCell.py プロジェクト: PytLab/KMCLib
    def __init__(self,
                 cell_vectors=None,
                 basis_points=None):
        """
        Constructor for the KMCUnitCell class.

        :param cell_vectors: A 3x3 matrix, nested lists or numpy array with
                             rows corresponding to the a, b and c vectors in
                             cartesian coordinates.

        :param basis_points: A Nx3 matrix, nested lists or numpy array with
                             each row corresponding to the fractional coordinates
                             of a basis point.
        """
        # Check the cell vectors.
        self.__cell_vectors = checkCellVectors(cell_vectors)

        # Check the basis points are of correct format.
        basis_points = checkCoordinateList(basis_points, varname="basis_points")

        # Check that the basis points are given in fractional coordinates.
        for point in basis_points:
            if not all([b < 1.0 and b >= 0.0 for b in point]):
                raise Error("All basis points must be given in fractional coordinates in the range 0.0 <= basis_point < 1.0.")

        self.__basis_points = basis_points
コード例 #2
0
    def __init__(self, cell_vectors=None, basis_points=None):
        """
        Constructor for the KMCUnitCell class.

        :param cell_vectors: A 3x3 matrix, nested lists or numpy array with
                             rows corresponding to the a, b and c vectors in
                             cartesian coordinates.

        :param basis_points: A Nx3 matrix, nested lists or numpy array with
                             each row corresponding to the fractional coordinates
                             of a basis point.
        """
        # Check the cell vectors.
        self.__cell_vectors = checkCellVectors(cell_vectors)

        # Check the basis points are of correct format.
        basis_points = checkCoordinateList(basis_points,
                                           varname="basis_points")

        # Check that the basis points are given in fractional coordinates.
        for point in basis_points:
            if not all([b < 1.0 and b >= 0.0 for b in point]):
                raise Error(
                    "All basis points must be given in fractional coordinates in the range 0.0 <= basis_point < 1.0."
                )

        self.__basis_points = basis_points
コード例 #3
0
    def testCheckCellVectors(self):
        """ Test the cell vector checking function. """
        # The simplest possible vectors.
        trial_vectors = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
        numpy_vectors = numpy.array(trial_vectors)

        # This must pass.
        checked_vectors = checkCellVectors(trial_vectors)
        self.assertAlmostEqual(
            numpy.linalg.norm(checked_vectors - numpy_vectors), 0.0, 10)

        # This should also pass.
        checked_vectors = checkCellVectors(numpy_vectors)
        self.assertAlmostEqual(
            numpy.linalg.norm(checked_vectors - numpy_vectors), 0.0, 10)

        # This should fail because of wrong format / shape.
        trial_vectors = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 1.0]]
        self.assertRaises(Error, lambda: checkCellVectors(trial_vectors))

        # As well as this.
        trial_vectors = [1.0, 0.0, 0.0, 0.0, 1.0]
        self.assertRaises(Error, lambda: checkCellVectors(trial_vectors))

        # This should also fail, because of wrong shape.
        trial_vectors = numpy.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0],
                                     [0.0, 1.0]])
        self.assertRaises(Error, lambda: checkCellVectors(trial_vectors))

        # This should fail because of wrong type.
        trial_vectors = "ABC"
        self.assertRaises(Error, lambda: checkCellVectors(trial_vectors))

        # These should fail because of linear dependencies.
        trial_vectors = [[1.0, 0.0, 0.0], [0.0, 1.0, 2.0],
                         [0.5, 0.5, 1.000001]]
        self.assertRaises(Error, lambda: checkCellVectors(trial_vectors))

        trial_vectors = [[1.0, 0.0, 0.0], [0.5, 0.5, 1.0], [0.0, 1.0, 2.0]]
        self.assertRaises(Error, lambda: checkCellVectors(trial_vectors))
コード例 #4
0
ファイル: CheckUtilitiesTest.py プロジェクト: PytLab/KMCLib
    def testCheckCellVectors(self):
        """ Test the cell vector checking function. """
        # The simplest possible vectors.
        trial_vectors = [[1.0,0.0,0.0],[0.0,1.0,0.0],[0.0,0.0,1.0]]
        numpy_vectors = numpy.array(trial_vectors)

        # This must pass.
        checked_vectors = checkCellVectors(trial_vectors)
        self.assertAlmostEqual(numpy.linalg.norm(checked_vectors - numpy_vectors), 0.0, 10)

        # This should also pass.
        checked_vectors = checkCellVectors(numpy_vectors)
        self.assertAlmostEqual(numpy.linalg.norm(checked_vectors - numpy_vectors), 0.0, 10)

        # This should fail because of wrong format / shape.
        trial_vectors = [[1.0,0.0,0.0],[0.0,1.0,0.0,0.0],[0.0,1.0]]
        self.assertRaises(Error, lambda: checkCellVectors(trial_vectors))

        # As well as this.
        trial_vectors = [1.0,0.0,0.0,0.0,1.0]
        self.assertRaises(Error, lambda: checkCellVectors(trial_vectors))

        # This should also fail, because of wrong shape.
        trial_vectors = numpy.array([[1.0,0.0,0.0],[0.0,1.0,0.0,0.0],[0.0,1.0]])
        self.assertRaises(Error, lambda: checkCellVectors(trial_vectors))

        # This should fail because of wrong type.
        trial_vectors = "ABC"
        self.assertRaises(Error, lambda: checkCellVectors(trial_vectors))

        # These should fail because of linear dependencies.
        trial_vectors = [[1.0,0.0,0.0],[0.0,1.0,2.0],[0.5,0.5,1.000001]]
        self.assertRaises(Error, lambda: checkCellVectors(trial_vectors))

        trial_vectors = [[1.0,0.0,0.0],[0.5,0.5,1.0],[0.0,1.0,2.0]]
        self.assertRaises(Error, lambda: checkCellVectors(trial_vectors))