Beispiel #1
0
    def __init__(self, input_output_handler: InputOutputHandler, state_handler: StateHandler, scheduler: Scheduler,
                 activator: Activator) -> None:
        """
        The constructor of the SingleProcessMediator class.

        Parameters
        ----------
        input_output_handler : input_output_handler.InputOutputHandler
            The input-output handler.
        state_handler : state_handler.StateHandler
            The state handler.
        scheduler : scheduler.Scheduler
            The scheduler.
        activator : activator.Activator
            The activator.
        """
        self._logger = logging.getLogger(__name__)
        self._logger_enabled_for_debug = self._logger.isEnabledFor(logging.DEBUG)
        log_init_arguments(self._logger.debug, self.__class__.__name__,
                           input_output_handler=input_output_handler.__class__.__name__,
                           state_handler=state_handler.__class__.__name__,
                           scheduler=scheduler.__class__.__name__,
                           activator=activator.__class__.__name__)
        # Obtain nodes from input handler (via the input-output handler) and hands them over to the state handler
        state_handler.initialize(input_output_handler.read())
        super().__init__(input_output_handler, state_handler, scheduler, activator)
Beispiel #2
0
    def __init__(self, filename: str, charge: str) -> None:
        """
        The constructor of the PolarizationOutputHandler class.

        This class uses a HardBufferedTextWriter to first write the polarization to a temporary file.

        Parameters
        ----------
        filename : str
            The filename of the file this output handler is connected to.
        charge : str
            The charge used to calculate the polarization.

        Raises
        ------
        base.exceptions.ConfigurationError
            If the number of node levels is not two or the number of nodes per root node is not three.
        """
        log_init_arguments(logging.getLogger(__name__).debug, self.__class__.__name__, filename=filename, charge=charge)
        super().__init__(filename)
        self._file = HardBufferedTextWriter(filename)
        self._charge = charge
        if setting.number_of_node_levels != 2 or setting.number_of_nodes_per_root_node == 1:
            raise ConfigurationError("The output handler {0} can only be used with charge neutral composite point"
                                     " objects.".format(self.__class__.__name__))
        print("# Polarization Vector", file=self._file)
    def __init__(self, end_of_run_time: float, output_handler: str = None) -> None:
        """
        The constructor of the FinalTimeEndOfRunEventHandler class.

        Parameters
        ----------
        end_of_run_time : float
            The event time at which the run is ended.
        output_handler : str or None, optional
            The name of the output handler.

        Raises
        ------
        base.exceptions.ConfigurationError
            If the end of run time is not greater than or equal to zero (the latter case logs a warning).
        """
        log_init_arguments(logging.getLogger(__name__).debug, self.__class__.__name__,
                           end_of_run_time=end_of_run_time, output_handler=output_handler)
        super().__init__(output_handler=output_handler)
        if not end_of_run_time >= 0.0:
            raise ConfigurationError("The end_of_run_time in the event handler {0} has to be >= 0.0."
                                     .format(self.__class__.__name__))
        if end_of_run_time == 0.0:
            logging.getLogger(__name__).warning("The end_of_run_time in the event handler {0} is equal to 0.0. The "
                                                "simulation will stop immediately once the run is started."
                                                .format(self.__class__.__name__))
        self._event_time = Time.from_float(end_of_run_time)
Beispiel #4
0
    def __init__(
        self,
        bond_length: float = 1.012,
        bond_angle: float = 1.9764,
        charge_values: Sequence[ChargeValues] = ()
    ) -> None:
        """
        The constructor of the WaterRandomNodeCreator class.

        Parameters
        ----------
        bond_length : float, optional
            The bond length.
        bond_angle : float, optional
            The bond angle.
        charge_values : Sequence[input_output_handler.input_handler.charge_values.ChargeValues], optional
            The sequence of charge values.
        """
        log_init_arguments(logging.getLogger(__name__).debug,
                           self.__class__.__name__,
                           bond_length=bond_length,
                           bond_angle=bond_angle,
                           charge_values=[
                               charge_value.__class__.__name__
                               for charge_value in charge_values
                           ])
        super().__init__(charge_values)
        self._bond_length = bond_length
        self._bond_angle = bond_angle
    def __init__(self, equilibrium_separation: float, power: int, prefactor: float = 1.0) -> None:
        """
        The constructor of the DisplacedEvenPowerPotential class.

        Parameters
        ----------
        equilibrium_separation : float
            The absolute value r_0 of the equilibrium separation of the potential.
        power : int
            The power p of the potential.
        prefactor : float, optional
            The prefactor k of the potential.

        Raises
        ------
        base.exceptions.ConfigurationError
            If the power p is not larger than 0 or if p is odd.
        """
        log_init_arguments(logging.getLogger(__name__).debug, self.__class__.__name__,
                           equilibrium_separation=equilibrium_separation, power=power, prefactor=prefactor)
        super().__init__(prefactor=prefactor, equilibrium_separation=equilibrium_separation)
        if not (power > 0 and power % 2 == 0):
            raise ConfigurationError("The potential {0} can only be used with "
                                     "a power > 0 divisible by 2!".format(self.__class__.__name__))
        self._equilibrium_separation = equilibrium_separation
        self._equilibrium_separation_squared = equilibrium_separation * equilibrium_separation
        self._power = power
        self._inverse_power = 1.0 / power
    def __init__(self, filename: str):
        """
        The constructor of the BondLengthAndAngleOutputHandler class.

        This class uses a HardBufferedTextWriter to first write the bond lengths and angles to temporary files.

        Parameters
        ----------
        filename : str
            The filename of the file this output handler is connected to.

        Raises
        ------
        base.exceptions.ConfigurationError
            If the number of node levels is not two or the number of nodes per root node is not three.
        """
        log_init_arguments(logging.getLogger(__name__).debug, self.__class__.__name__, filename=filename)
        super().__init__(filename)
        filename_dot_position = self._output_filename.rfind('.')
        bond_length_filename = (self._output_filename[:filename_dot_position]
                                + '_Length' + self._output_filename[filename_dot_position:])
        bond_angle_filename = (self._output_filename[:filename_dot_position]
                               + '_Angle' + self._output_filename[filename_dot_position:])
        self._file_bond_lengths = HardBufferedTextWriter(bond_length_filename)
        self._file_bond_angles = HardBufferedTextWriter(bond_angle_filename)
        if setting.number_of_node_levels != 2 or setting.number_of_nodes_per_root_node != 3:
            raise ConfigurationError("The output handler {0} can only be used if each root node has 3 child nodes."
                                     .format(self.__class__.__name__))
Beispiel #7
0
    def __init__(
        self,
        create: Sequence[str],
        trash: Sequence[str],
        event_handler: EventHandler,
        number_event_handlers: int = 1,
        tag: str = None,
        activate: Sequence[str] = (),
        deactivate: Sequence[str] = ()
    ) -> None:
        """
        The constructor of the ActiveRootUnitInStateTagger class.

        Parameters
        ----------
        create : Sequence[str]
            Sequence of tags to create after an event handler of this tagger has committed an event to the global state.
        trash : Sequence[str]
            Sequence of tags to trash after an event handler of this tagger has committed an event to the global state.
        event_handler : event_handler.EventHandler
            A single event handler instance.
        number_event_handlers : int, optional
            Number of event handlers to prepare. The tagger will deepcopy the given event handler instance to create
            this number of event handlers.
        tag : str or None, optional
            Tag used in all four lists (also of other taggers). If None, the class name (or the alias set in the
            factory) will be used as the tag.
        activate : Sequence[str], optional
            Sequence of tags to activate after an event handler of this tagger has committed an event to the global
            state.
        deactivate : Sequence[str], optional
            Sequence of tags to deactivate after an event handler of this tagger has committed an event to the global
            state.

        Raises
        ------
        base.exceptions.ConfigurationError
            If no composite point objects are involved in the run (setting.number_of_node_levels not > 1).
        """
        log_init_arguments(logging.getLogger(__name__).debug,
                           self.__class__.__name__,
                           event_handler=event_handler.__class__.__name__,
                           number_event_handlers=number_event_handlers,
                           create=create,
                           trash=trash,
                           activate=activate,
                           deactivate=deactivate,
                           tag=tag)
        super().__init__(create,
                         trash,
                         event_handler,
                         number_event_handlers=number_event_handlers,
                         tag=tag,
                         activate=activate,
                         deactivate=deactivate)
        if not setting.number_of_node_levels > 1:
            raise ConfigurationError(
                "The tagger {0} can only be used when composite point objects are involved in the"
                "simulation (setting.number_of_node_levels > 1).".format(
                    self.__class__.__name__))
Beispiel #8
0
    def __init__(self,
                 charge_values: Sequence[float],
                 charge_name: str = None) -> None:
        """
        The constructor of the ChargeValues class.

        If the charge name is None, the name of the class is used. If the JF factory included an alias in the classname,
        the alias is used.

        Parameters
        ----------
        charge_values : Sequence[float]
            The sequence of charges for each leaf node particle within a single tree.
        charge_name : str or None, optional
            The name of the charge.
        """
        log_init_arguments(logging.getLogger(__name__).debug,
                           self.__class__.__name__,
                           charge_values=charge_values,
                           charge_name=charge_name)
        # If no charge name is given, we want to use the alias of the .ini file which is included in the
        # __class__.__name__ property in the factory. get_alias() extracts this alias
        self._charge_name = (charge_name if charge_name is not None else
                             to_snake_case(get_alias(self.__class__.__name__)))
        self._charge_values = charge_values
    def __init__(
        self,
        min_initial_dipole_separation: float = 0.0,
        max_initial_dipole_separation: float = 0.05,
        charge_values: Sequence[ChargeValues] = ()
    ) -> None:
        """
        The constructor of the DipoleRandomNodeCreator class.

        Parameters
        ----------
        min_initial_dipole_separation : float, optional
            The minimum initial dipole separation.
        max_initial_dipole_separation : float, optional
            The maximum initial dipole separation.
        charge_values : Sequence[input_output_handler.input_handler.charge_values.ChargeValues], optional
            The sequence of charge values.
        """
        log_init_arguments(
            logging.getLogger(__name__).debug,
            self.__class__.__name__,
            min_initial_dipole_separation=min_initial_dipole_separation,
            max_initial_dipole_separation=max_initial_dipole_separation,
            charge_values=[
                charge_value.__class__.__name__
                for charge_value in charge_values
            ])
        super().__init__(charge_values)
        self._min_initial_dipole_separation = min_initial_dipole_separation
        self._max_initial_dipole_separation = max_initial_dipole_separation
    def __init__(self, power: float, prefactor: float) -> None:
        """
        The constructor of the InversePowerPotential.

        Parameters
        ----------
        power : float
            The power p of the potential.
        prefactor : float
            The prefactor k of the potential.

        Raises
        ------
        base.exceptions.ConfigurationError
            If the power p is not larger than 0.
        """
        log_init_arguments(logging.getLogger(__name__).debug, self.__class__.__name__,
                           power=power, prefactor=prefactor)
        super().__init__(prefactor=prefactor)
        if not power > 0.0:
            raise ConfigurationError("Give a power > 0.0 as the power for the potential {0}."
                                     .format(self.__class__.__name__))
        self._power = power
        self._two_over_power = 2.0 / self._power
        self._power_over_two = self._power / 2.0
        self._power_plus_two = self._power + 2
        self._infinity = float('inf')
    def __init__(self,
                 potential: Potential,
                 dipole_separation: float,
                 prefactor: float = 1.5,
                 empirical_bound: float = float('inf'),
                 number_trials: int = 10000,
                 dipole_charge: float = 1.0,
                 periodic_boundaries: bool = True) -> None:
        """
        The constructor of the InnerPointEstimator class.

        Parameters
        ----------
        potential : potential.Potential
            Potential whose derivative is to be bounded.
        dipole_separation : float
            Separation of the two point masses within the constructed dipole.
        prefactor : float, optional
            A constant which gets multiplied to the bounds.
        empirical_bound : float, optional
            If a bound exceeds this value, this value will be returned instead.
        number_trials : int, optional
            The number of separation samples taken.
        dipole_charge : float, optional
            The absolute value of the charges in the dipole.
        periodic_boundaries : bool
            Whether the separations in the given region should be corrected for periodic boundaries.

        Raises
        ------
        base.exceptions.ConfigurationError
            If the potential derivative method does not expect exactly one separation.
            If the potential derivative method does not expect exactly two charges.
        """
        log_init_arguments(logging.getLogger(__name__).debug,
                           self.__class__.__name__,
                           potential=potential.__class__.__name__,
                           dipole_separation=dipole_separation,
                           prefactor=prefactor,
                           empirical_bound=empirical_bound,
                           number_trials=number_trials,
                           dipole_charge=dipole_charge,
                           periodic_boundaries=periodic_boundaries)
        super().__init__(potential=potential,
                         prefactor=prefactor,
                         empirical_bound=empirical_bound)
        self._number_trials = number_trials
        self._dipole_separation = dipole_separation
        self._dipole_separation_over_two = dipole_separation / 2
        self._dipole_charge = dipole_charge
        if self._potential.number_separation_arguments != 1:
            raise ConfigurationError(
                "The estimator {0} expects a potential "
                "which handles exactly one separation!".format(
                    self.__class__.__name__))
        if self._potential.number_charge_arguments != 2:
            raise ConfigurationError(
                "The estimator {0} expects a potential "
                "which handles exactly two charges!".format(
                    self.__class__.__name__))
    def __init__(self, create: Sequence[str], trash: Sequence[str], event_handler: EventHandler,
                 number_event_handlers: int, internal_state_label: str, tag: str = None) -> None:
        """
        The constructor of the ExcludedCellsTagger class.

        This class uses an internal state and therefore inherits from the TaggerWithInternalState class. The
        internal_state_label should refer to a cell-occupancy system.

        Note that the activate and deactivate sequences are always empty for a tagger of this kind.

        Parameters
        ----------
        create : Sequence[str]
            Sequence of tags to create after an event handler of this tagger has committed an event to the global state.
        trash : Sequence[str]
            Sequence of tags to trash after an event handler of this tagger has committed an event to the global state.
        event_handler : event_handler.cell_boundary_event_handler.CellBoundaryEventHandler
            A single event handler instance.
        number_event_handlers : int
            Number of event handlers to prepare. The tagger will deepcopy the given event handler instance to create
            this number of event handlers.
        internal_state_label : str
            The label of the internal state this tagger wants to use.
        tag : str or None, optional
            Tag used in all four lists (also of other taggers). If None, the class name (or the alias set in the
            factory) will be used as the tag.
        """
        log_init_arguments(logging.getLogger(__name__).debug, self.__class__.__name__,
                           event_handler=event_handler.__class__.__name__, number_event_handlers=number_event_handlers,
                           internal_state_label=internal_state_label, create=create, trash=trash, tag=tag)
        super().__init__(create, trash, event_handler, internal_state_label=internal_state_label,
                         number_event_handlers=number_event_handlers, tag=tag)
Beispiel #13
0
    def __init__(self, warn_on_equal_event_times: bool = False) -> None:
        """
        The constructor of the HeapScheduler class.

        Parameters
        ----------
        warn_on_equal_event_times : bool, optional
            Whether this scheduler should log a warning when succeeding event times are equal.

        Raises
        ------
        MemoryError
            If the C code fails to allocate memory.
        """
        self._logger = logging.getLogger(__name__)
        self._logger_enabled_for_debug = self._logger.isEnabledFor(
            logging.DEBUG)
        log_init_arguments(self._logger.debug, self.__class__.__name__)
        super().__init__()
        c_heap = lib.construct_heap()
        if c_heap == ffi.NULL:
            raise MemoryError(
                "Could not allocate memory for the class {0}.".format(
                    self.__class__.__name__))
        self._heap = ffi.gc(c_heap,
                            lib.destroy_heap,
                            size=lib.estimated_size(c_heap))
        self._minimal_valid_counter = {}
        self._last_returned_event = (Time(-float("inf"), -float("inf")), None)
        self._allocated_memory_bytes = 0
        self._scheduler_handle = _new_handle(self)
        self._event_handler_handles = {}
        self._warn_on_equal_event_times = warn_on_equal_event_times
    def __init__(self, cells: Cells, cell_level: int, maximum_number_occupants: int = 1, charge: str = None) -> None:
        """
        The constructor of the SingleActiveCellOccupancy class.

        Parameters
        ----------
        cells : activator.internal_state.cell_occupancy.cells.Cells
            The underlying cell system.
        cell_level : int
            The length of the global state identifiers which should be stored in this internal state.
        maximum_number_occupants : int, optional
            The maximum number of allowed occupants per cell. If this number is smaller than or equal to zero, this
            class allows for an infinite number of occupants per cell.
        charge : str or None, optional
            The charge of the unit that must be unequal zero in order for the corresponding identifier to be stored.
            If the charge is None, all global state identifiers with the correct length are stored.

        Raises
        ------
        base.exceptions.ConfigurationError
            If the cell_level corresponds to composite point objects which cannot have a charge but the charge is set.
        """
        log_init_arguments(logging.getLogger(__name__).debug, self.__class__.__name__, cells=cells.__class__.__name__,
                           cell_level=cell_level, maximum_number_occupants=maximum_number_occupants, charge=charge)
        super().__init__(cells, cell_level, maximum_number_occupants)
        if cell_level < setting.number_of_node_levels and charge is not None:
            raise ConfigurationError("Chosen cell level stores composite point objects which cannot have a charge!")
        self._surplus = {}
        self._occupants = {cell: [] for cell in self._cells.yield_cells()}
        self._active_unit_identifier = None
        self._is_relevant_unit = (lambda unit: unit.charge[charge] != 0) if charge is not None else lambda unit: True
        self._active_cell = None
    def __init__(self, minimum_separation: float, maximum_separation: float) -> None:
        """
        The constructor of the HardDipolePotential class.

        Parameters
        ----------
        minimum_separation : float
            The minimum separation r.
        maximum_separation : float
            The maximum separation R.

        Raises
        ------
        base.exceptions.ConfigurationError
            If the minimum separation r is not larger than 0.
            If the maximum separation R is not larger than 0.
            If the minimum separation r is not smaller than the maximum separation R.
        """
        log_init_arguments(logging.getLogger(__name__).debug, self.__class__.__name__,
                           minimum_separation=minimum_separation, maximum_separation=maximum_separation)
        if not minimum_separation > 0.0:
            raise ConfigurationError("The class {0} can only be used with a minimum separation bigger than 0.0."
                                     .format(self.__class__.__name__))
        if not maximum_separation:
            raise ConfigurationError("The class {0} can only be used with a maximum separation bigger than 0.0."
                                     .format(self.__class__.__name__))
        if not minimum_separation < maximum_separation:
            raise ConfigurationError("The class {0} can only be used with a minimum separation that is smaller than the"
                                     "maximum separation.".format(self.__class__.__name__))
        super().__init__()
        self._minimum_separation_squared = minimum_separation * minimum_separation
        self._maximum_separation_squared = maximum_separation * maximum_separation
    def __init__(self, random_node_creator: RandomNodeCreator,
                 number_of_root_nodes: int) -> None:
        """
        The constructor of the RandomInputHandler class.

        The constructor sets the number of root nodes, the number of nodes per root node and the number of node levels
        in the setting package.

        Parameters
        ----------
        random_node_creator : input_output_handler.input_handler.random_node_creator.RandomNodeCreator
            The random node creator which creates a single random root node.
        number_of_root_nodes : int
            The number of root nodes to create.
        """
        log_init_arguments(
            logging.getLogger(__name__).debug,
            self.__class__.__name__,
            random_node_creator=random_node_creator.__class__.__name__,
            number_of_root_nodes=number_of_root_nodes)
        super().__init__()
        setting.set_number_of_root_nodes(number_of_root_nodes)
        setting.set_number_of_nodes_per_root_node(
            random_node_creator.number_of_nodes_per_root_node)
        setting.set_number_of_node_levels(
            random_node_creator.number_of_node_levels)
        self._random_node_creator = random_node_creator
    def __init__(self,
                 system_lengths: Sequence[float],
                 beta: float = 1.0,
                 dimension: int = 3) -> None:
        """
        The constructor of the HypercuboidSetting setter class.

        Besides the arguments of this constructor, it initializes the setting package with an instance of
        HypercuboidPeriodicBoundaries as the periodic boundaries and the random position function of this class.

        Parameters
        ----------
        system_lengths : Sequence[float]
            The system lengths of the hypercuboid as a sequence.
        beta : float, optional
            The module which gets initialized.
        dimension : int, optional
            The dimension.
        """
        log_init_arguments(logging.getLogger(__name__).debug,
                           self.__class__.__name__,
                           system_lengths=system_lengths,
                           beta=beta,
                           dimension=dimension)
        super().__init__(sys.modules[__name__],
                         beta,
                         dimension,
                         periodic_boundaries=HypercuboidPeriodicBoundaries())
        _set_system_lengths(system_lengths)
Beispiel #18
0
    def __init__(self, chain_time: float, delta_phi_degree: float) -> None:
        """
        The constructor of the SingleIndependentActiveSequentialDirectionEndOfChainEventHandler class.

        The rotation angle in degrees by which the two-dimensional velocity vector is rotated on each end-of-chain event
        should be greater than 0.0 and smaller than 360.0. Moreover, 180.0 degrees is excluded to assure irreducibility
        of the Markov chain.

        Parameters
        ----------
        chain_time : float
            The time interval after which a new end-of-chain event occurs.
        delta_phi_degree : float
            The rotation angle in degrees by which the two-dimensional velocity vector is rotated on each end-of-chain
            event.

        Raises
        ------
        base.exceptions.ConfigurationError:
            If the rotation angle in degrees is not in the interval (0, 360.0) or equal to 180.0.
            If the dimension in the setting package is not set to two.
        """
        log_init_arguments(logging.getLogger(__name__).debug, self.__class__.__name__, chain_time=chain_time,
                           delta_phi_degree=delta_phi_degree)
        super().__init__(chain_time=chain_time)
        if not 0.0 < delta_phi_degree < 360.0 or delta_phi_degree == 180.0:
            raise ConfigurationError("The rotation angle of the velocity after an end-of-chain event in the event "
                                     "handler {0} has to be larger than 0.0 and smaller than 360.0, and is further not "
                                     "allowed to be exactly 180.0.".format(self.__class__.__name__))
        if not setting.dimension == 2:
            raise ConfigurationError("The event handler {0} can only be used in two dimensions."
                                     .format(self.__class__.__name__))
        delta_phi = delta_phi_degree * math.pi / 180.0
        self._cos_delta_phi = math.cos(delta_phi)
        self._sin_delta_phi = math.sin(delta_phi)
Beispiel #19
0
    def __init__(self, sampling_interval: float, output_handler: str, first_event_time_zero: bool = False) -> None:
        """
        The constructor of the FixedIntervalSamplingEventHandler class.

        Parameters
        ----------
        sampling_interval : float
            The time interval of the sampling.
        output_handler : str
            The name of the output handler.
        first_event_time_zero : bool, optional
            If the first returned candidate event time is zero.

        Raises
        ------
        base.exceptions.ConfigurationError:
            If the sampling interval is not greater than zero.
        """
        log_init_arguments(logging.getLogger(__name__).debug, self.__class__.__name__,
                           sampling_interval=sampling_interval, output_handler=output_handler)
        super().__init__(output_handler=output_handler)
        if not sampling_interval > 0.0:
            raise ConfigurationError("The sampling_interval in the event handler {0} has to be > 0.0."
                                     .format(self.__class__.__name__))
        self._sampling_interval = sampling_interval
        self._event_time = Time(0.0, 0.0) if not first_event_time_zero else Time.from_float(-sampling_interval)
    def __init__(self,
                 cells_per_side: Sequence[int],
                 neighbor_layers: int = 1) -> None:
        """
        The constructor of the CuboidPeriodicCells class.

        This constructor gets exactly the same arguments as the constructor of the CuboidCells base class and just
        passes all arguments through.

        Parameters
        ----------
        cells_per_side : Sequence[int]
            The number of cells per side of the simulation box that this class uses to construct the cuboid cell system.
            If fewer numbers than the dimension of the simulation are given, the first number is reused.
        neighbor_layers : int, optional
            The number of cells in each direction that are considered as nearby in this cell system.

        Raises
        ------
        base.exceptions.ConfigurationError
            If the hypercuboid_setting is not initialized.
        base.exceptions.ConfigurationError
            If zero or too many cells per side are given for the chosen dimension.
        base.exceptions.ConfigurationError
            If the number of neighbor layers is smaller than zero.
        """
        logger = logging.getLogger(__name__)
        log_init_arguments(logger.debug,
                           self.__class__.__name__,
                           cells_per_side=cells_per_side,
                           neighbor_layers=neighbor_layers)
        super().__init__(cells_per_side=cells_per_side,
                         neighbor_layers=neighbor_layers)
Beispiel #21
0
    def __init__(self, filename: str) -> None:
        """
        The constructor of the FactorTypeMaps class.

        If _instance is still None (nobody has called this constructor yet), construct an instance of the
        __FactorTypeMaps class and assign _instance to this.
        If _instance is already set (that means the constructor has been already called), check if the filename
        argument is the same as before. It is not allowed to try to construct several FactorTypeMaps reading from
        different files.

        Parameters
        ----------
        filename : str
            The filename out of which the factor type maps should be parsed.

        Raises
        ------
        AttributeError
            If it is tried to construct this class a second time with a different filename.
        """
        log_init_arguments(_logger.debug, self.__class__.__name__, filename=filename)
        if not FactorTypeMaps._instance:
            FactorTypeMaps._instance = FactorTypeMaps.__FactorTypeMaps(filename)
        else:
            if FactorTypeMaps._instance.filename != filename:
                raise AttributeError("Class {0} is created as a singleton and should only be created for one filename."
                                     .format(self.__class__.__name__))
Beispiel #22
0
    def __init__(self, filename: str) -> None:
        """
        The constructor of the SeparationOutputHandler class.

        This class uses a HardBufferedTextWriter to first write the separations to temporary files.

        Parameters
        ----------
        filename : str
            The filename of the file this output handler is connected to.

        Raises
        ------
        AssertionError
            If the filename does not contain a file format.
        """
        log_init_arguments(logging.getLogger(__name__).debug,
                           self.__class__.__name__,
                           filename=filename)
        super().__init__(filename)
        self._files = []
        split_filename = filename.split(".")
        assert len(split_filename) == 2
        for number in range(setting.number_of_nodes_per_root_node):
            if setting.number_of_nodes_per_root_node > 1:
                self._files.append(
                    HardBufferedTextWriter("{0}_1{1}.{2}".format(
                        split_filename[0],
                        number + setting.number_of_nodes_per_root_node + 1,
                        split_filename[1])))
            else:
                self._files.append(HardBufferedTextWriter(filename))
Beispiel #23
0
    def __init__(self, filename: str) -> None:
        """
        The constructor of the DumpingOutputHandler class.

        Parameters
        ----------
        filename : str
            The filename of the file this output handler is connected to.

        Raises
        ------
        AssertionError
            If the filename does not contain a file format.
        """
        log_init_arguments(logging.getLogger(__name__).debug,
                           self.__class__.__name__,
                           filename=filename)
        split_filename = filename.split(".")
        if len(split_filename) != 2:
            raise ConfigurationError(
                "The given filename {0} contains more than one '.'.".format(
                    filename))
        # Include python implementation and version (implementation_major_minor_macro in filename)
        dumping_filename = (
            split_filename[0] + "_" + sys.implementation.name + "_" +
            "_".join([str(sys.version_info[i])
                      for i in range(3)]) + "." + split_filename[1])

        super().__init__(dumping_filename)
    def __init__(self, dumping_interval: float, output_handler: str) -> None:
        """
        The constructor of the FixedIntervalDumpingEventHandler class.

        Parameters
        ----------
        dumping_interval : float
            The time interval of the dumping.
        output_handler :
            The name of the output handler.

        Raises
        ------
        base.exceptions.ConfigurationError:
            If the dumping interval is not greater than zero.
        """
        log_init_arguments(logging.getLogger(__name__).debug,
                           self.__class__.__name__,
                           dumping_interval=dumping_interval,
                           output_handler=output_handler)
        super().__init__(output_handler=output_handler)
        if not dumping_interval > 0.0:
            raise ConfigurationError(
                "The dumping_interval in the event handler {0} has to be > 0.0."
                .format(self.__class__.__name__))
        self._dumping_interval = dumping_interval
        self._event_time = Time(0.0, 0.0)
    def __init__(self, prefactor: float = 1.5837) -> None:
        """
        The constructor of the InversePowerCoulombBoundingPotential class.

        Parameters
        ----------
        prefactor : float, optional
            The prefactor k of the potential.

        Raises
        ------
        base.exceptions.ConfigurationError
            If the hypercubic setting is not initialized.
        base.exceptions.ConfigurationError
            If the dimension does not equal three.
        """
        log_init_arguments(logging.getLogger(__name__).debug,
                           self.__class__.__name__,
                           prefactor=prefactor)
        if not setting.initialized():
            raise ConfigurationError(
                "Potential {0} can only be used in a hypercubic setting.".
                format(self.__class__.__name__))
        if not setting.dimension == 3:
            raise ConfigurationError(
                "The potential {0} can only be used in 3 dimensions.".format(
                    self.__class__.__name__))
        super().__init__(prefactor=prefactor)
Beispiel #26
0
    def __init__(self,
                 create: Sequence[str],
                 trash: Sequence[str],
                 event_handler: EventHandler,
                 internal_state_label: str,
                 number_event_handlers: int = 1,
                 tag: str = None) -> None:
        """
        The constructor of the CellVetoTagger class.

        This class uses an internal state and therefore inherits from the TaggerWithInternalState class. The
        internal_state_label should refer to a cell-occupancy system.

        Note that the activate and deactivate sequences are always empty for a tagger of this kind.

        The event handler should be an instance of a CellVetoEventHandler. The number of event handlers should be
        set to the number of active units that are relevant to the cell-occupancy system.

        Parameters
        ----------
        create : Sequence[str]
            Sequence of tags to create after an event handler of this tagger has committed an event to the global state.
        trash : Sequence[str]
            Sequence of tags to trash after an event handler of this tagger has committed an event to the global state.
        event_handler : event_handler.cell_boundary_event_handler.CellBoundaryEventHandler
            A single event handler instance.
        internal_state_label : str
            The label of the internal state this tagger wants to use.
        number_event_handlers : int, optional
            Number of event handlers to prepare. The tagger will deepcopy the given event handler instance to create
            this number of event handlers.
        tag : str or None, optional
            Tag used in all four lists (also of other taggers). If None, the class name (or the alias set in the
            factory) will be used as the tag.

        Raises
        ------
        base.exceptions.ConfigurationError
            If the event handler is not an instance of a CellVetoEventHandler.
        """
        log_init_arguments(logging.getLogger(__name__).debug,
                           self.__class__.__name__,
                           event_handler=event_handler.__class__.__name__,
                           number_event_handlers=number_event_handlers,
                           internal_state_label=internal_state_label,
                           create=create,
                           trash=trash,
                           tag=tag)
        if not isinstance(event_handler, CellVetoEventHandler):
            raise ConfigurationError(
                "The class {0} can only be used with an instance of the class "
                "CellVetoEventHandler as the event handler".format(
                    self.__class__.__name__))
        super().__init__(create,
                         trash,
                         event_handler,
                         number_event_handlers=number_event_handlers,
                         internal_state_label=internal_state_label,
                         tag=tag)
Beispiel #27
0
 def __init__(self) -> None:
     """
     The constructor of the TreePhysicalState class.
     """
     log_init_arguments(
         logging.getLogger(__name__).debug, self.__class__.__name__)
     super().__init__()
     self._root_nodes = None
    def __init__(self,
                 potential: Potential,
                 bounding_potential: CellBoundingPotential,
                 charge: str = None) -> None:
        """
        The constructor of the TwoLeafUnitCellBoundingPotentialEventHandler class.

        Parameters
        ----------
        potential : potential.Potential
            The potential between the leaf units.
        bounding_potential : potential.cell_bounding_potential.CellBoundingPotential
            The invertible cell bounding potential between the leaf units.
        charge : str or None, optional
            The relevant charge for this event handler.

        Raises
        ------
        base.exceptions.ConfigurationError:
            If the cell bounding potential does not expect exactly one separation.
        base.exceptions.ConfigurationError:
            If the charge is not None but the potential or the cell bounding potential expects more than two charges.
        """
        log_init_arguments(
            logging.getLogger(__name__).debug,
            self.__class__.__name__,
            potential=potential.__class__.__name__,
            bounding_potential=bounding_potential.__class__.__name__,
            charge=charge)
        super().__init__(potential=potential,
                         bounding_potential=bounding_potential)
        self._charge = charge

        if self._bounding_potential.number_separation_arguments != 1:
            raise ConfigurationError(
                "The event handler {0} expects a cell bounding potential "
                "which handles exactly one separation!".format(
                    self.__class__.__name__))

        if charge is None:
            self._potential_charges = (lambda unit_one, unit_two: tuple(
                1.0 for _ in range(self._potential.number_charge_arguments)))
            self._bounding_potential_charges = (
                lambda unit_one, unit_two: tuple(1.0 for _ in range(
                    self._bounding_potential.number_charge_arguments)))
        else:
            if self._potential.number_charge_arguments == 2 and self._bounding_potential.number_charge_arguments == 2:
                self._potential_charges = lambda unit_one, unit_two: (
                    unit_one.charge[charge], unit_two.charge[charge])
                self._bounding_potential_charges = self._potential_charges
            else:
                raise ConfigurationError(
                    "The event handler {0} was initialized with a charge which is not None,"
                    " but its potential {1} and/or its bounding potential {2}"
                    "expects not exactly 2 charges.".format(
                        self.__class__.__name__,
                        self._potential.__class__.__name__,
                        self._bounding_potential.__class__.__name__))
Beispiel #29
0
    def __init__(
        self,
        filename: str,
        names_within_composite_object: Sequence[str] = (),
        bonds_within_composite_object: Sequence[int] = ()
    ) -> None:
        """
        The constructor of the DcdOutputHandler class.

        Parameters
        ----------
        filename : str
            The filename of the file this output handler is connected to.
        names_within_composite_object : Sequence[str], optional
            The sequence of names of the point masses within a composite object.
        bonds_within_composite_object : Sequence[int], optional
            The sequence of bonds of the point masses within the composite object. In the sequence, the bonds should be
            given in pairs of two. The point masses are numbered as they appear in the children sequence of the root
            node.

        Raises
        ------
        base.exceptions.ConfigurationError
            If the hypercuboid setting is not initialized.
        base.exceptions.ConfigurationError
            If the filename does not end with .dcd.
        base.exceptions.ConfigurationError
            If the setting package specifies a dimension larger than 3 which cannot be initialized with a .pdb file.
        base.exceptions.ConfigurationError
            If the bonds_within_composite_object sequence is not divisible by two.
        base.exceptions.ConfigurationError
            If the names_within_composite_object sequence does not specify a name for each point mass (if it is not
            empty).
        """
        logger = logging.getLogger(__name__)
        log_init_arguments(
            logger.debug,
            self.__class__.__name__,
            filename=filename,
            names_within_composite_object=names_within_composite_object,
            bonds_within_composite_object=bonds_within_composite_object)
        if not filename.endswith(".dcd"):
            raise ConfigurationError(
                "Output filename for output handler {0} should end with .dcd.".
                format(self.__class__.__name__))
        super().__init__(filename, names_within_composite_object,
                         bonds_within_composite_object)
        self._filename_without_ending = filename[:-4]
        self._pdb_file_created = False
        self._bonds_within_composite_object = bonds_within_composite_object
        self._names_within_composite_object = names_within_composite_object
        self._writer = Writer(filename,
                              self._number_of_atoms,
                              lengthunit="angstrom",
                              remarks="RUN IDENTIFICATION HASH: {0}".format(
                                  get_uuid()),
                              format="LAMMPS")
    def __init__(
        self,
        input_output_handler: InputOutputHandler,
        state_handler: StateHandler,
        scheduler: Scheduler,
        activator: Activator,
        number_cores: int = os.cpu_count()) -> None:
        """
        The constructor of the MultiProcessMediator class.

        Parameters
        ----------
        input_output_handler : input_output_handler.InputOutputHandler
            The input-output handler.
        state_handler : state_handler.StateHandler
            The state handler.
        scheduler : scheduler.Scheduler
            The scheduler.
        activator : activator.Activator
            The activator.
        number_cores : int, optional
            The number of cores to use.

        Raises
        ------
        base.exceptions.ConfigurationError
            If the number of cores is not larger than one.
        """
        self._logger = logging.getLogger(__name__)
        self._logger_enabled_for_debug = self._logger.isEnabledFor(
            logging.DEBUG)
        log_init_arguments(
            self._logger.debug,
            self.__class__.__name__,
            input_output_handler=input_output_handler.__class__.__name__,
            state_handler=state_handler.__class__.__name__,
            scheduler=scheduler.__class__.__name__,
            activator=activator.__class__.__name__)
        if not number_cores > 1:
            raise ConfigurationError(
                "The multi processing mediator should only be used "
                "when more than one processor is available.")
        state_handler.initialize(input_output_handler.read())
        super().__init__(input_output_handler, state_handler, scheduler,
                         activator)
        self._out_states = {}
        self._number_cores = number_cores
        self._pipes = {}
        self._event_handlers = {}
        self._os_processes = []
        self._start_events = {}
        self._send_out_state_events = {}
        self._event_handlers_state = {}
        for event_handler in self._event_handlers_list:
            event_handler.run_in_process = types.MethodType(
                run_in_process, event_handler)
        self._start_processes()