Order of Reactants and Products — MobsPy 2.2 documentation

# Order of Reactants and Products

In this example, we will construct a model of how the order of reactants and products affects a meta-reaction. MobsPy uses a round-robin structure to assign reactant states to product states. In this example, we describe this structure in detail with examples.

    [1]:

    from mobspy import *

    Age = BaseSpecies(1)
    Age.young >> Age.old [1]

    Animal = Age
    Animal.a1, Animal.a2

    [1]:

    (<mobspy.modules.meta_class.Reacting_Species at 0x7f942baa3250>,
     <mobspy.modules.meta_class.Reacting_Species at 0x7f942baa3880>)

The Round-Robin mechanism is demonstrated with the reaction below:

    [2]:

    Animal.old + Animal.young >> Animal.old [1]

    [2]:

    <mobspy.modules.meta_class.Reactions at 0x7f942baa3970>

In this reaction, we want to define a competition between young and old animals. We want the old animal to survive the competition. However, how does MobsPy distinguish this case from where the young animal survives and becomes old? Simple, through the reactants order. The first reactant becomes the first species in the product, and it continues cyclically until all products have been mapped to a species.

If necessary, the .label() can be used to circumvent this default behavior, if required. In the next reaction, the young Animal kills the old and becomes old itself.

    [3]:

    # Animal.old + Animal.young.label(1) >> Animal.old.label(1) [1]

While arguably, the fact that once the old animal survives and once the young one does not make a difference in our setting, it does if additional characteristics are added to the Animal, e.g., it having a color.

The cyclic round-robin style is especially useful in reproduction reactions. Since the assignment cycles in a round-robin fashion, the first product will be assigned the first reactant, and the second product will cycle through the reactants and be assigned the first reactant as well. In the example below, the two products will be generated in the same state as the reactant

    [4]:

    Animal >> 2*Animal [1]

    [4]:

    <mobspy.modules.meta_class.Reactions at 0x7f9431b4a760>

Finally, the compilation:

    [5]:

    MySim = Simulation(Animal)
    print(MySim.compile())

    Species
    Age.a1,0
    Age.a2,0
    Age.old,0
    Age.young,0

    Mappings
    Age :
    Age.a1
    Age.a2
    Age.old
    Age.young

    Parameters
    volume,1

    Reactions
    reaction_0,{'re': [(1, 'Age.a1')], 'pr': [(2, 'Age.a1')], 'kin': 'Age.a1 * 1'}
    reaction_1,{'re': [(1, 'Age.a2')], 'pr': [(2, 'Age.a2')], 'kin': 'Age.a2 * 1'}
    reaction_2,{'re': [(1, 'Age.old'), (1, 'Age.young')], 'pr': [(1, 'Age.old')], 'kin': 'Age.old * Age.young * 1 * volume^-1'}
    reaction_3,{'re': [(1, 'Age.old')], 'pr': [(2, 'Age.old')], 'kin': 'Age.old * 1'}
    reaction_4,{'re': [(1, 'Age.young')], 'pr': [(1, 'Age.old')], 'kin': 'Age.young * 1'}
    reaction_5,{'re': [(1, 'Age.young')], 'pr': [(2, 'Age.young')], 'kin': 'Age.young * 1'}

    Compiling model
    WARNING: Automatic data-saving setup failed. Please save manually