Reaction Inheritance — MobsPy 2.2 documentation

# Reaction Inheritance

MobsPy allows Meta-Species to inherit reactions from other Meta-Species

We start by defining the BaseSpecies we will use:

    [2]:

    from mobspy import *

    Duplicator, Mortal, Eater, Food = BaseSpecies(4)

Next, we define the reactions for each of the BaseSpecies. Zero is a meta-species that represents no species.

    [3]:

    Duplicator >> 2*Duplicator [1]
    Eater + Food >> Eater [1]
    Mortal >> Zero [1]

    [3]:

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

In MobsPy, the multiplication of meta-species allows for the inheritance of reactions from the factor species. For example, we would like to define a Bacteria species that is also a Duplicator, an Eater, and a Mortal. This is done via:

    [4]:

    Bacteria = Duplicator*Eater*Mortal

We now create new different types of bacteria from the previous ones, Ecoli and Strepto. As they will also be Bacteria, they inherit all the reactions. We can do this using the New call.

    [5]:

    Ecoli, Strepto = New(Bacteria, 2)

We also define two types of Food:

    [6]:

    Glucose, Amino = New(Food, 2)

MobsPy will create all possible combinations for inheritance when defining the model, which means that both Ecoli and Strepto will eat Glucose and Amino.

Finally, we define the species we want to simulate. Since Duplicator, Eater, Mortal, and Food were just defined to construct the other meta-species, we don’t pass them to Simulation.

    [9]:

    S = Simulation(Ecoli | Strepto | Glucose | Amino)

    # Adding some counts
    Ecoli(50), Strepto(25), Glucose(10), Amino(100)

    [9]:

    (<mobspy.modules.meta_class.Species at 0x7f94003403d0>,
     <mobspy.modules.meta_class.Species at 0x7f94003401f0>,
     <mobspy.modules.meta_class.Species at 0x7f9400340370>,
     <mobspy.modules.meta_class.Species at 0x7f9400340550>)

Now we compile the simulation to show all defined reactions:

    [10]:

    print(S.compile())

    Species
    Amino,100
    Ecoli,50
    Glucose,10
    Strepto,25

    Mappings
    Amino :
    Amino
    Ecoli :
    Ecoli
    Glucose :
    Glucose
    Strepto :
    Strepto

    Parameters
    volume,1

    Reactions
    reaction_0,{'re': [(1, 'Ecoli'), (1, 'Amino')], 'pr': [(1, 'Ecoli')], 'kin': 'Ecoli * Amino * 1 * volume^-1'}
    reaction_1,{'re': [(1, 'Ecoli'), (1, 'Glucose')], 'pr': [(1, 'Ecoli')], 'kin': 'Ecoli * Glucose * 1 * volume^-1'}
    reaction_2,{'re': [(1, 'Ecoli')], 'pr': [(2, 'Ecoli')], 'kin': 'Ecoli * 1'}
    reaction_3,{'re': [(1, 'Ecoli')], 'pr': [], 'kin': 'Ecoli * 1'}
    reaction_4,{'re': [(1, 'Strepto'), (1, 'Amino')], 'pr': [(1, 'Strepto')], 'kin': 'Strepto * Amino * 1 * volume^-1'}
    reaction_5,{'re': [(1, 'Strepto'), (1, 'Glucose')], 'pr': [(1, 'Strepto')], 'kin': 'Strepto * Glucose * 1 * volume^-1'}
    reaction_6,{'re': [(1, 'Strepto')], 'pr': [(2, 'Strepto')], 'kin': 'Strepto * 1'}
    reaction_7,{'re': [(1, 'Strepto')], 'pr': [], 'kin': 'Strepto * 1'}

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

    [ ]: