Example #1
0
    def testCheckSequence(self):
        """ Test that the sequence checking works. """
        # This is a sequence.
        sequence = [1, 2, 3, 'a', 12.3, "ABC"]
        checked_sequence = checkSequence(sequence)
        self.assertEqual(checked_sequence, sequence)

        # This also.
        sequence = numpy.array([[12.0, 1.3], [1., 4.3]])
        checked_sequence = checkSequence(sequence)
        self.assertAlmostEqual(numpy.linalg.norm(checked_sequence - sequence),
                               0.0, 10)

        # And these.
        sequence = "A"
        checked_sequence = checkSequence(sequence)
        self.assertEqual(checked_sequence, sequence)

        sequence = []
        checked_sequence = checkSequence(sequence)
        self.assertEqual(checked_sequence, sequence)

        # But this is not.
        sequence = 1
        self.assertRaises(Error, lambda: checkSequence(sequence))
    def __checkPeriodic(self, periodic):
        """ """
        """
        Private helper routine to check the periodic input.
        """
        # Handle the default case.
        if periodic is None:
            periodic = (True, True, True)

        # Check that it is a sequence.
        periodic = checkSequence(
            periodic,
            "The 'periodic' input parametr is not given as a sequence of bools."
        )

        # Check its length.
        if len(periodic) != 3:
            raise Error(
                "The 'periodic' input parameter must have length == 3.")

        # Check the values.
        for val in periodic:
            if not isinstance(val, bool):
                raise Error(
                    "The 'periodic' input paramter must be given as a list or tuple of three bools, e.g. (True,True,False)."
                )

        # Done.
        return periodic
Example #3
0
    def __checkPeriodic(self, periodic):
        """ """
        """
        Private helper routine to check the periodic input.
        """
        # Handle the default case.
        if periodic is None:
            periodic = (True, True, True)

        # Check that it is a sequence.
        periodic = checkSequence(periodic, "The 'periodic' input parametr is not given as a sequence of bools.")

        # Check its length.
        if len(periodic) != 3:
            raise Error("The 'periodic' input parameter must have length == 3.")

        # Check the values.
        for val in periodic:
            if not isinstance(val, bool):
                raise Error(
                    "The 'periodic' input paramter must be given as a list or tuple of three bools, e.g. (True,True,False)."
                )

        # Done.
        return periodic
Example #4
0
    def __checkRepetitions(self, repetitions):
        """ """
        """
        Private helper routine to check the repetitions input.
        """
        # Handle the default case.
        if repetitions is None:
            repetitions = (1, 1, 1)

        # Check that it is a sequence.
        repetitions = checkSequence(
            repetitions, "The 'repetitions' input parametr is not given as a sequence of numbers."
        )

        # Check its length.
        if len(repetitions) != 3:
            raise Error("The 'repetitions' input parameter must have length == 3.")

        # Check the values.
        for val in repetitions:
            if not isinstance(val, int):
                raise Error(
                    "The 'repetitions' input paramter must be given as a list or tuple of three integers, e.g. (5,5,6)"
                )

        # Check for the occurance of too small values.
        for val in repetitions:
            if val < 1:
                raise Error("The all elements in the 'repetitions' parameter must be larger than zero.")

        # Done.
        return repetitions
Example #5
0
    def testCheckSequence(self):
        """ Test that the sequence checking works. """
        # This is a sequence.
        sequence = [1,2,3,'a',12.3, "ABC"]
        checked_sequence = checkSequence(sequence)
        self.assertEqual(checked_sequence, sequence)

        # This also.
        sequence = numpy.array([[12.0,1.3],[1.,4.3]])
        checked_sequence = checkSequence(sequence)
        self.assertAlmostEqual( numpy.linalg.norm(checked_sequence-sequence), 0.0, 10)

        # And these.
        sequence = "A"
        checked_sequence = checkSequence(sequence)
        self.assertEqual(checked_sequence, sequence)

        sequence = []
        checked_sequence = checkSequence(sequence)
        self.assertEqual(checked_sequence, sequence)

        # But this is not.
        sequence = 1
        self.assertRaises(Error, lambda: checkSequence(sequence))
Example #6
0
    def __checkMoveVectorsFormat(self, move_vectors):
        """
        Private helper function to check the format of the move vectors.

        :param move_vectors: The input to check.

        :returns: The validated move vectors, or None if None was given
                  and a reconstruction was not possible.
        """
        if move_vectors is None:
            # Try to reconstruct the move vectors from the before and after
            # elements information.
            move_vectors = self.__reconstructMoveVectors()

        # Return if still None.
        if move_vectors is None:
            return move_vectors

        # This is the error message.
        msg = """The 'move_vectors' input to the KMCProcess constructor must be a
list of tuples, where the first element of each tuple refers to an atom index
and the second element is a cartesian vector of length 3, in internal
coordinates defining where the moved index goes."""

        # Check that we have a sequence.
        move_vectors = checkSequence(move_vectors, msg)

        # Check the format of each element.
        for t in move_vectors:
            if not isinstance(t, tuple):
                raise Error(msg)
            elif not isinstance(t[0], int):
                raise Error(msg)
            # Check the vector.
            checkSequenceOfFloats(t[1], msg)
            if len(t[1]) != 3:
                raise Error(msg)
        # Passed all tests.
        return move_vectors
    def __checkRepetitions(self, repetitions):
        """ """
        """
        Private helper routine to check the repetitions input.
        """
        # Handle the default case.
        if repetitions is None:
            repetitions = (1, 1, 1)

        # Check that it is a sequence.
        repetitions = checkSequence(
            repetitions,
            "The 'repetitions' input parametr is not given as a sequence of numbers."
        )

        # Check its length.
        if len(repetitions) != 3:
            raise Error(
                "The 'repetitions' input parameter must have length == 3.")

        # Check the values.
        for val in repetitions:
            if not isinstance(val, int):
                raise Error(
                    "The 'repetitions' input paramter must be given as a list or tuple of three integers, e.g. (5,5,6)"
                )

        # Check for the occurance of too small values.
        for val in repetitions:
            if val < 1:
                raise Error(
                    "The all elements in the 'repetitions' parameter must be larger than zero."
                )

        # Done.
        return repetitions