Esempio n. 1
0
    def __init__(self,
                 history_steps=None,
                 n_bins=None,
                 t_max=None,
                 track_type=None):
        """
        Constructor for the OnTheFlyMSD.

        :param history_steps: The number of steps per atom to store in the
                              history buffer.
        :type history_steps: int

        :param n_bins: The nuber of bins in the histogram.
        :type n_bins: int

        :param t_max: The starting value of the last bin.
        :type t_max: float

        :param track_type: The atom type to track during the simulation.
        :type track_type: str
        """
        # Check and set the history steps input.
        self.__history_steps = checkPositiveInteger(history_steps, 5, "history_step")

        # Check and set the number of bins.
        self.__n_bins = checkPositiveInteger(n_bins, 100, "n_bins")

        # Check and set the time maximum.
        self.__t_max   = checkPositiveFloat(t_max, 100.0, "t_max")

        # Check that the track type.
        if not isinstance(track_type, str):
            raise Error("The 'track_type' parameter must be a string.")
        self.__track_type = track_type

        # Calculate and store the binsize.
        self.__binsize = self.__t_max / self.__n_bins

        # Set the step counter to zero.
        self.__n_steps = 0

        # Set the blocksize to zero.
        self.__blocksize = 0
    def __init__(self,
                 number_of_steps=None,
                 dump_interval=None,
                 analysis_interval=None,
                 seed=None):
        """
        Constructuor for the KMCControlParameters object that
        holds all parameters controlling the flow of the KMC simulation.

        :param number_of_steps: The number of KMC steps to take. If not provided
                                the default value 0 will  be used.
        :type number_of_steps: int

        :param dump_interval: The number of steps between subsequent trajectory
                              dumps. The default value is 1, i.e. dump every step.
        :type dump_interval: int

        :param analysis_interval: The number of steps between subsequent calls to
                                  the custom analysis 'registerStep' functions.
                                  The default value is 1, i.e. analysis every step.
        :type analysis_interval: int

        :param seed: The seed value to use for the backend random number generator.
                     If no seed value is given the random numnber generator will be
                     seeded based on the wall-clock time.
        :type seed: int

        """
        # Check and set the number of steps.
        self.__number_of_steps = checkPositiveInteger(number_of_steps, 0,
                                                      "number_of_steps")

        self.__dump_interval = checkPositiveInteger(dump_interval, 1,
                                                    "dump_interval")

        self.__analysis_interval = checkPositiveInteger(
            analysis_interval, 1, "analysis_interval")

        self.__time_seed = (seed is None)
        self.__seed = checkPositiveInteger(seed, 1, "seed")
    def __init__(self,
                 processes=None,
                 time_interval=None,
                 spatially_resolved=None,
                 anal_Interval=None,
                 resultsPlace=None,
                 processesObject=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')
        self.__analInterval = checkPositiveInteger(anal_Interval, 1,
                                                   'anal_Interval')
        self.__resultsPlace = resultsPlace
        self.__processesObject = processesObject

        if (self.__resultsPlace is not None):
            if (self.__processesObject is None):
                raise Error(
                    "If this is the trajRecord-keeping processStatistics analysis instance, you need to specify what the processes are!"
                )
            self.__trajRecord = open(self.__resultsPlace + '/trajRecord.tr',
                                     'w')
        self.__floatAnalInterval = float(self.__analInterval)
        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
Esempio n. 4
0
    def __init__(self,
                 number_of_steps=None,
                 dump_interval=None):
        """
        Constructuor for the KMCControlParameters object that
        holds all parameters controlling the flow of the KMC simulation.

        :param number_of_steps: The number of KMC steps to take. If not provided
                                the default value 0 will  be used.
        :type number_of_steps: int

        :param dump_interval: The number of steps between subsequent trajectory
                              dumps. The default value is 1, i.e. dump every step.
        :type dump_interval: int
        """
        # Check and set the number of steps.
        self.__number_of_steps = checkPositiveInteger(number_of_steps,
                                                      0,
                                                      "number_of_steps")

        self.__dump_interval = checkPositiveInteger(dump_interval,
                                                    1,
                                                    "dump_interval")
    def __init__(self,
                 processes=None,
                 time_interval=None,
                 spatially_resolved=None,
                 anal_Interval=None,
                 resultsPlace=None,
                 processesObject=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')
        self.__analInterval = checkPositiveInteger(anal_Interval, 1, 'anal_Interval')
        self.__resultsPlace = resultsPlace
        self.__processesObject = processesObject
        
        if (self.__resultsPlace is not None):
            if(self.__processesObject is None):
                raise Error("If this is the trajRecord-keeping processStatistics analysis instance, you need to specify what the processes are!")
            self.__trajRecord = open(self.__resultsPlace+'/trajRecord.tr', 'w')
        self.__floatAnalInterval = float(self.__analInterval)
        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
Esempio n. 6
0
    def testCheckPositiveInteger(self):
        """ Test that the positive integer checking works. """
        # Test pass.
        integer0 = checkPositiveInteger(21, 1234, "integer0")
        self.assertEqual(integer0, 21)

        integer0 = checkPositiveInteger(0, 1234, "integer0")
        self.assertEqual(integer0, 0)

        # Test default.
        integer0 = checkPositiveInteger(None, 1234, "integer0")
        self.assertEqual(integer0, 1234)

        # Test fail negative.
        self.assertRaises(Error, lambda: checkPositiveInteger(-1, 12, "fail"))

        # Test fail wrong type.
        self.assertRaises(Error, lambda: checkPositiveInteger(1.1, 12, "fail"))

        # Test fail wrong type.
        self.assertRaises(Error, lambda: checkPositiveInteger("1", 12, "fail"))
Esempio n. 7
0
    def testCheckPositiveInteger(self):
        """ Test that the positive integer checking works. """
        # Test pass.
        integer0 = checkPositiveInteger(21, 1234, "integer0")
        self.assertEqual(integer0, 21)

        integer0 = checkPositiveInteger(0, 1234, "integer0")
        self.assertEqual(integer0, 0)

        # Test default.
        integer0 = checkPositiveInteger(None, 1234, "integer0")
        self.assertEqual(integer0, 1234)

        # Test fail negative.
        self.assertRaises( Error,
                           lambda: checkPositiveInteger(-1, 12, "fail") )

        # Test fail wrong type.
        self.assertRaises( Error,
                           lambda: checkPositiveInteger(1.1, 12, "fail") )

        # Test fail wrong type.
        self.assertRaises( Error,
                           lambda: checkPositiveInteger("1", 12, "fail") )
Esempio n. 8
0
    def __init__(self,
                 number_of_steps=None,
                 dump_interval=None,
                 analysis_interval=None,
                 seed=None,
                 dump_time_interval=None,
                 rng_type=None):
        """
        Constructuor for the KMCControlParameters object that
        holds all parameters controlling the flow of the KMC simulation.

        :param number_of_steps: The number of KMC steps to take. If not provided
                                the default value 0 will  be used.
        :type number_of_steps: int

        :param dump_interval: The number of steps between subsequent trajectory
                              dumps. The default value is 1, i.e. dump every step.
        :type dump_interval: int

        :param analysis_interval: The number of steps between subsequent calls to
                                  the custom analysis 'registerStep' functions.
                                  The default value is 1, i.e. analysis every step.
        :type analysis_interval: int

        :param seed: The seed value to use for the backend random number generator.
                     If no seed value is given the random numnber generator will be
                     seeded based on the wall-clock time.
        :type seed: int

        :param dump_time_interval: The simulation time between subsequent trajectory
                              dumps. The default value is None, causing the dump_interval parameter to determine the behavior.
        :type dump_interval: int

        :param rng_type: The type of pseudo random number generator to use.  The random
                         number generators are the once in the standard C++ library and
                         the supported types maps directly to the given C++ construction
                         as indicated here:

                         'MT' for Mersenne-Twister (Default) [rng = std::mt19937],
                         'MINSTD' for the 'minimum standard' rng [rng = std::minstd_rand],
                         'RANLUX24' for the 24-bit version of the ranlux rng [rng = std::ranlux24],
                         'RANLUX48' for the 48-bit version of the ranlux rng [rng = std::ranlux48].

                         The sequence of pseudo-random numbers is generated by repeated calls to
                         std::generate_canonical<double, 32>(rng);

                         See: http://en.cppreference.com/w/cpp/numeric/random for further details on
                         C++ random number generators.

                         There is also the option 'DEVICE' for using a random device
                         installed on the macine through [rng = std::random_device] in C++. Note
                         however that you should spend some time evaluating this option to make
                         sure it works as you expect if you have a random device installed, since this
                         has not been tested with a random device by the KMCLib developers.
        :type rng_type: str
        """
        # Check and set the number of steps.
        self.__number_of_steps = checkPositiveInteger(number_of_steps, 0,
                                                      "number_of_steps")

        self.__dump_interval = None
        if dump_interval is not None:
            self.__dump_interval = checkPositiveInteger(
                dump_interval, 1, "dump_interval")

        self.__analysis_interval = checkPositiveInteger(
            analysis_interval, 1, "analysis_interval")

        self.__time_seed = (seed is None)
        self.__seed = checkPositiveInteger(seed, 1, "seed")

        if dump_time_interval is not None:
            if not isinstance(dump_time_interval, float):
                raise Error(
                    "The 'dump_time_interval' parameter must be of type float."
                )
            if dump_time_interval <= 0:
                raise Error(
                    "The 'dump_time_interval' parameter must be greater than zero."
                )

        self.__dump_time_interval = dump_time_interval

        # Check that dump_time_interval and dump_interval not both are different from None.
        if (self.__dump_time_interval is not None) and (self.__dump_interval
                                                        is not None):
            raise Error(
                "The 'dump_time_interval' and the 'dump_interval' parameters can not both be used."
            )

        # If both are None, set the dump_interval to 1.
        if (self.__dump_interval is None) and (self.__dump_time_interval is
                                               None):
            self.__dump_interval = 1

        # Check and set the random number generator type.
        self.__rng_type = self.__checkRngType(rng_type, "MT")
Esempio n. 9
0
    def __init__(self,
                 number_of_steps=None,
                 dump_interval=None,
                 analysis_interval=None,
                 seed=None,
                 dump_time_interval=None,
                 rng_type=None):
        """
        Constructuor for the KMCControlParameters object that
        holds all parameters controlling the flow of the KMC simulation.

        :param number_of_steps: The number of KMC steps to take. If not provided
                                the default value 0 will  be used.
        :type number_of_steps: int

        :param dump_interval: The number of steps between subsequent trajectory
                              dumps. The default value is 1, i.e. dump every step.
        :type dump_interval: int

        :param analysis_interval: The number of steps between subsequent calls to
                                  the custom analysis 'registerStep' functions.
                                  The default value is 1, i.e. analysis every step.
        :type analysis_interval: int

        :param seed: The seed value to use for the backend random number generator.
                     If no seed value is given the random numnber generator will be
                     seeded based on the wall-clock time.
        :type seed: int

        :param dump_time_interval: The simulation time between subsequent trajectory
                              dumps. The default value is None, causing the dump_interval parameter to determine the behavior.
        :type dump_interval: int

        :param rng_type: The type of pseudo random number generator to use.  The random
                         number generators are the once in the standard C++ library and
                         the supported types maps directly to the given C++ construction
                         as indicated here:

                         'MT' for Mersenne-Twister (Default) [rng = std::mt19937],
                         'MINSTD' for the 'minimum standard' rng [rng = std::minstd_rand],
                         'RANLUX24' for the 24-bit version of the ranlux rng [rng = std::ranlux24],
                         'RANLUX48' for the 48-bit version of the ranlux rng [rng = std::ranlux48].

                         The sequence of pseudo-random numbers is generated by repeated calls to
                         std::generate_canonical<double, 32>(rng);

                         See: http://en.cppreference.com/w/cpp/numeric/random for further details on
                         C++ random number generators.

                         There is also the option 'DEVICE' for using a random device
                         installed on the macine through [rng = std::random_device] in C++. Note
                         however that you should spend some time evaluating this option to make
                         sure it works as you expect if you have a random device installed, since this
                         has not been tested with a random device by the KMCLib developers.
        :type rng_type: str
        """
        # Check and set the number of steps.
        self.__number_of_steps = checkPositiveInteger(number_of_steps,
                                                      0,
                                                      "number_of_steps")

        self.__dump_interval = None
        if dump_interval is not None:
            self.__dump_interval = checkPositiveInteger(dump_interval,
                                                        1,
                                                        "dump_interval")

        self.__analysis_interval = checkPositiveInteger(analysis_interval,
                                                        1,
                                                        "analysis_interval")

        self.__time_seed = (seed is None)
        self.__seed = checkPositiveInteger(seed,
                                           1,
                                           "seed")

        if dump_time_interval is not None:
            if not isinstance(dump_time_interval, float):
                raise Error("The 'dump_time_interval' parameter must be of type float.")
            if dump_time_interval <= 0:
                raise Error("The 'dump_time_interval' parameter must be greater than zero.")

        self.__dump_time_interval = dump_time_interval

        # Check that dump_time_interval and dump_interval not both are different from None.
        if (self.__dump_time_interval is not None) and (self.__dump_interval is not None):
            raise Error("The 'dump_time_interval' and the 'dump_interval' parameters can not both be used.")

        # If both are None, set the dump_interval to 1.
        if (self.__dump_interval is None) and (self.__dump_time_interval is None):
            self.__dump_interval = 1

        # Check and set the random number generator type.
        self.__rng_type  = self.__checkRngType(rng_type, "MT")