コード例 #1
0
    def testCheckSequenceOfPositiveIntegers(self):
        """ Test that the positive integer sequence checking works. """
        # This is a valid.
        sequence = [1, 2, 3, 12]
        checked_sequence = checkSequenceOfPositiveIntegers(sequence)
        self.assertEqual(checked_sequence, sequence)

        # This is not.
        sequence = numpy.array([[1, 1], [1, 4]])
        self.assertRaises(Error,
                          lambda: checkSequenceOfPositiveIntegers(sequence))

        # This is not.
        sequence = [1, 2, -4]
        self.assertRaises(Error,
                          lambda: checkSequenceOfPositiveIntegers(sequence))

        # And this is.
        sequence = numpy.array([1, 1, 1, 4])
        checked_sequence = checkSequenceOfPositiveIntegers(sequence)
        self.assertAlmostEqual(numpy.linalg.norm(checked_sequence - sequence),
                               0.0, 10)

        # But this is not.
        sequence = [1.0, 2.0, 0.0]
        self.assertRaises(Error,
                          lambda: checkSequenceOfPositiveIntegers(sequence))
コード例 #2
0
ファイル: DensHist.py プロジェクト: joshuahellier/PhDStuff
 def __init__(self, spec=None, inProc=None, outProc=None):
     self.__spec = spec
     msg = "The 'inProc' parameter must be given as a list of relevant input processes."
     self.__inProc = checkSequenceOfPositiveIntegers(inProc, msg)
     msg = "The 'outProc' parameter must be given as a list of relevant output processes."
     self.__outProc = checkSequenceOfPositiveIntegers(outProc, msg)
     self.__initTime = 0.0
     self.__lastTime = 0.0
     self.__currentTime = 0.0
コード例 #3
0
    def __init__(self,
                 processes=None,
                 time_interval=None,
                 spatially_resolved=None):
        """
        Constructor for the process statistics analysis.

        :param processes: List of process numbers to collect statistics from.
        :param time_interval: Time interval for binning results. Defaults to
                              1.0 if not specified.
        :type time_interval: float
        :param spatially_resolved: True if spatially resolved information about
                                   the total number of events per site should
                                   be collected. Defaults to False.
        :type spatially_resovled: bool
        """
        # Check and set the input.
        msg = "The 'processes' parameter must be given as a list of process numbers."
        self.__processes = checkSequenceOfPositiveIntegers(processes, msg)
        self.__time_interval = checkPositiveFloat(time_interval, 1.0,
                                                  'time_interval')
        if (spatially_resolved is None):
            spatially_resolved = False
        elif not isinstance(spatially_resolved, bool):
            raise Error(
                "The 'spatially_resolved' parameter to the ProcessStatistics analysis must be given as a bool."
            )

        # Done checking.
        self.__spatially_resolved = spatially_resolved
        self.__last_time = 0.0
        self.__data = []
        self.__spatial_data = None
        self.__current_count = 0
コード例 #4
0
ファイル: RateCalc.py プロジェクト: joshuahellier/PhDStuff
 def __init__(self, processes=None):
     msg = "The 'processes' parameter must be given as a list of process numbers."
     self.__processes = checkSequenceOfPositiveIntegers(processes, msg)
     self.__initTime = 0.0
     self.__lastTime = 0.0
     self.__currentTime = 0.0
     self.__current_count = 0
コード例 #5
0
ファイル: ProcessStatistics.py プロジェクト: PytLab/KMCLib
    def __init__(self,
                 processes=None,
                 time_interval=None,
                 spatially_resolved=None):
        """
        Constructor for the process statistics analysis.

        :param processes: List of process numbers to collect statistics from.
        :param time_interval: Time interval for binning results. Defaults to
                              1.0 if not specified.
        :type time_interval: float
        :param spatially_resolved: True if spatially resolved information about
                                   the total number of events per site should
                                   be collected. Defaults to False.
        :type spatially_resovled: bool
        """
        # Check and set the input.
        msg = "The 'processes' parameter must be given as a list of process numbers."
        self.__processes = checkSequenceOfPositiveIntegers(processes, msg)
        self.__time_interval = checkPositiveFloat(time_interval, 1.0, 'time_interval')
        if (spatially_resolved is None):
            spatially_resolved = False
        elif not isinstance(spatially_resolved, bool):
            raise Error("The 'spatially_resolved' parameter to the ProcessStatistics analysis must be given as a bool.")

        # Done checking.
        self.__spatially_resolved = spatially_resolved
        self.__last_time = 0.0
        self.__data = []
        self.__spatial_data = None
        self.__current_count = 0
コード例 #6
0
ファイル: RateCalc.py プロジェクト: joshuahellier/PhDStuff
 def __init__(self, processes=None):
     msg = "The 'processes' parameter must be given as a list of process numbers."
     self.__processes = checkSequenceOfPositiveIntegers(processes, msg)
     self.__initTime = 0.0
     self.__lastTime = 0.0
     self.__currentTime = 0.0
     self.__current_count = 0
コード例 #7
0
ファイル: CheckUtilitiesTest.py プロジェクト: PytLab/KMCLib
    def testCheckSequenceOfPositiveIntegers(self):
        """ Test that the positive integer sequence checking works. """
        # This is a valid.
        sequence = [1,2,3,12]
        checked_sequence = checkSequenceOfPositiveIntegers(sequence)
        self.assertEqual(checked_sequence, sequence)

        # This is not.
        sequence = numpy.array([[1,1],[1,4]])
        self.assertRaises(Error, lambda: checkSequenceOfPositiveIntegers(sequence))

        # This is not.
        sequence = [1,2,-4]
        self.assertRaises(Error, lambda: checkSequenceOfPositiveIntegers(sequence))

        # And this is.
        sequence = numpy.array([1,1,1,4])
        checked_sequence = checkSequenceOfPositiveIntegers(sequence)
        self.assertAlmostEqual( numpy.linalg.norm(checked_sequence-sequence), 0.0, 10)

        # But this is not.
        sequence = [1.0,2.0,0.0]
        self.assertRaises(Error, lambda: checkSequenceOfPositiveIntegers(sequence))
コード例 #8
0
ファイル: KMCBaseProcess.py プロジェクト: PytLab/KMCLib
    def __init__(self,
                 coordinates=None,
                 basis_sites=None,
                 rate_constant=None):
        """
        Constructor for the KMCBaseProcess.

        :param coordinates: The local coordinates, corresponding to the lattice
                            positions of the surrounding of the center where
                            the process will be preformed.

        :param basis_sites: The basis sites in the lattice at which the process
                            can possibly be applied. Only if the length of this
                            list is 1 can implicit wildcards be used for the
                            matching.

        :param rate_constant: The rate constant associated with this process.
        :type rate_constant: float

        """
        # Check the coordinates.
        coordinates = checkCoordinateList(coordinates)

        # Center the coordinates on the first entry.
        center = 0
        self._coordinates = centerCoordinates(coordinates, center)

        # Check the list of basis sites.
        basis_sites = checkSequenceOfPositiveIntegers(basis_sites,
                                                      msg="The basis_sites must be given as a list of positive integers.")

        if len(basis_sites) == 0:
            msg = "The list of available basis sites for a process may not be empty."

        # Passed the  tests.
        self._basis_sites = basis_sites

        # Check the rate constant.
        self._rate_constant = checkPositiveFloat(rate_constant,
                                                 default_parameter=None,
                                                 parameter_name="rate_constant")

        # To be updated by the derrived classes.
        self._elements_before      = None
        self._elements_after       = None
        self._move_vectors         = None
        self._all_present_types    = None
        self._local_configurations = None
コード例 #9
0
ファイル: KMCBaseProcess.py プロジェクト: zqhuang2014/KMCLib
    def __init__(self, coordinates=None, basis_sites=None, rate_constant=None):
        """
        Constructor for the KMCBaseProcess.

        :param coordinates: The local coordinates, corresponding to the lattice
                            positions of the surrounding of the center where
                            the process will be preformed.

        :param basis_sites: The basis sites in the lattice at which the process
                            can possibly be applied. Only if the length of this
                            list is 1 can implicit wildcards be used for the
                            matching.

        :param rate_constant: The rate constant associated with this process.
        :type rate_constant: float

        """
        # Check the coordinates.
        coordinates = checkCoordinateList(coordinates)

        # Center the coordinates on the first entry.
        center = 0
        self._coordinates = centerCoordinates(coordinates, center)

        # Check the list of basis sites.
        basis_sites = checkSequenceOfPositiveIntegers(
            basis_sites,
            msg="The basis_sites must be given as a list of positive integers."
        )

        if len(basis_sites) == 0:
            msg = "The list of available basis sites for a process may not be empty."

        # Passed the  tests.
        self._basis_sites = basis_sites

        # Check the rate constant.
        self._rate_constant = checkPositiveFloat(
            rate_constant,
            default_parameter=None,
            parameter_name="rate_constant")

        # To be updated by the derrived classes.
        self._elements_before = None
        self._elements_after = None
        self._move_vectors = None
        self._all_present_types = None
        self._local_configurations = None
コード例 #10
0
    def __init__(self,
                 coordinates=None,
                 elements_before=None,
                 elements_after=None,
                 move_vectors=None,
                 basis_sites=None,
                 rate_constant=None):
        """
        Constructor for the KMCProcess.

        :param coordinates: The local coordinates, corresponding to the lattice
                            positions of the surrounding of the center where
                            the process will be preformed.

        :param elements_before: The elements, as a list of strings,
                                before the process is preformed.
                                This list of elements will be used to match the
                                local surroundings of each center in the
                                simulation, to determine at which sites the
                                process can be performed.

        :param elements_after: The elements, as a list of strings,
                               after the process is preformed.
                               This list of elements will be used to update the
                               local surrounding of the site where the process
                               is performed.

        :param move_vectors: A set of vectors in the local coordinates that define
                             which elements are moved to which place in the move.
                             The vectors are given as a list of tuples, where the first
                             element in each tuple indicates which index is moved and
                             the second element in the tuple is a vector in local coordinates
                             indicating where the move is to.

        :param basis_sites: The basis sites in the lattice at which the process
                            can possibly be applied. Only if the length of this
                            list is 1 can implicit wildcards be used for the
                            matching.

        :param rate_constant: The rate constant associated with this process.
        :type rate_constant: float

        """
        # Check the coordinates.
        coordinates = checkCoordinateList(coordinates)

        # Center the coordinates on the first entry.
        center = 0
        self.__coordinates = centerCoordinates(coordinates, center)

        # Check the types.
        elements_before = checkTypes(elements_before, len(coordinates))
        elements_after  = checkTypes(elements_after,  len(coordinates))

        # Check that the elements represents a valid move.
        self.__checkValidMoveElements(elements_before, elements_after)

        # All types checking done.
        self.__elements_before = elements_before
        self.__elements_after  = elements_after

        # Check that the move vectors are compatible with the elements.
        self.__move_vectors = self.__checkValidMoveVectors(move_vectors)

        # Sort the coordinates and co-sort the elements and move vectors.
        self.__sortCoordinatesElementsAndMoveVectors()

        # Check the list of basis sites.
        basis_sites = checkSequenceOfPositiveIntegers(basis_sites,
                                                      msg="The basis_sites must be given as a list of positive integers.")

        if len(basis_sites) == 0:
            msg = "The list of available basis sites for a process may not be empty."

        # Passed the  tests.
        self.__basis_sites = basis_sites

        # Check the rate constant.
        self.__rate_constant = checkPositiveFloat(rate_constant,
                                                  default_parameter=None,
                                                  parameter_name="rate_constant")
        # Setup the local configurations.
        c1 = KMCLocalConfiguration(self.__coordinates, self.__elements_before, center)
        c2 = KMCLocalConfiguration(self.__coordinates, self.__elements_after,  center)
        self.__local_configurations = (c1, c2)