Exemplo n.º 1
0
    def _get_split_reaction(self):
        def reaction_function(topology):
            recipe = readdy.StructuralReactionRecipe(topology)
            if topology.get_n_particles() > 1:
                edge = np.random.randint(0, topology.get_n_particles() - 1)
                recipe.remove_edge(edge, edge + 1)
            return recipe._get()

        def rate_function(topology):
            if topology.get_n_particles() > 1:
                return topology.get_n_particles() / 20.
            else:
                return .0

        fun1 = top.ReactionFunction(reaction_function)
        fun2 = top.RateFunction(rate_function)

        reaction = top.StructuralTopologyReaction("split", fun1, fun2)
        reaction.create_child_topologies_after_reaction()
        return reaction
Exemplo n.º 2
0
    def _get_split_reaction(self):
        def reaction_function(topology):
            recipe = top.Recipe(topology)
            if topology.get_n_particles() > 1:
                edge = np.random.randint(0, topology.get_n_particles() - 1)
                recipe.remove_edge(edge, edge + 1)
            return recipe

        def rate_function(topology):
            if topology.get_n_particles() > 1:
                return topology.get_n_particles() / 20.
            else:
                return .0

        fun1 = top.ReactionFunction(reaction_function)
        fun2 = top.RateFunction(rate_function)

        reaction = top.TopologyReaction(fun1, fun2)
        reaction.roll_back_if_invalid()
        reaction.create_child_topologies_after_reaction()
        return reaction
Exemplo n.º 3
0
    def add_structural_reaction(self,
                                topology_type,
                                reaction_function,
                                rate_function,
                                raise_if_invalid=True,
                                expect_connected=False):
        """
        Adds a spatially independent structural topology reaction for a certain topology type. It basically consists
        out of two functions:

        * the reaction function, taking a topology object as input and returning a reaction recipe describing what
          the structural changes are to be applied to the topology
        * the rate function, which takes a topology object as input and returns a corresponding fixed rate

        It should be noted that the rate function will only be evaluated upon changes of the topology, i.e., as rarely
        as possible. The reaction function is evaluated when the actual reaction takes place. Also the rate is expected
        to be returned in terms of the magnitude w.r.t. the default units.

        :param topology_type: the topology type for which this reaction is evaluated
        :param reaction_function: the reaction function, as described above
        :param rate_function: the rate function, as described above
        :param raise_if_invalid: raises an error if the outcome of the reaction function is invalid and set to True,
                                 otherwise it will just roll back to the state of before the reaction and print a
                                 warning into the log
        :param expect_connected: can trigger a raise if set to true and the topology's connectivity graph decayed into
                                 two or more independent components, depending on the value of `raise_if_invalid`.
        """
        fun1, fun2 = _top.ReactionFunction(
            reaction_function), _top.RateFunction(rate_function)
        reaction = _top.StructuralTopologyReaction(fun1, fun2)
        if raise_if_invalid:
            reaction.raise_if_invalid()
        else:
            reaction.roll_back_if_invalid()
        if expect_connected:
            reaction.expect_connected_after_reaction()
        else:
            reaction.create_child_topologies_after_reaction()
        self._registry.add_structural_reaction(topology_type, reaction)