Units — MobsPy 2.2 documentation

# Units

MobsPy supports units. One can assign units to rates using the reserved u object from the Pint Unit Registry reserved for units.

    [25]:

    from mobspy import *

    Ball, Child, Bacteria = BaseSpecies(3)

    Ball(10/u.meter**2)
    Child(1/u.meter**2)
    Bacteria(1*u.mol)
    print(Ball, Child, Bacteria)

    Ball Child Bacteria

For value assigments, species can receive either concentrations or direct counts. For concentrations, MobsPy will convert them into counts for the simulation by multiplying them by the volume of the simulation. Also, one can assign area-based (counts/u.meter^2) or linear-based (counts/u.meter) (or even four dimensional if you feel like simulating truly alien species) concentrations to the counts. However, it’s expected that the simulation maintains dimensional consistensy. If one assings an area-base concentration to one and a volume-based concentration to other the model will not compile. The same also holds if one assigns a volume to a area-based model. For instance, the line bellow yields an error:

    [19]:

    S_error = Simulation(Ball | Child)
    S_error.volume = 3*u.m**3
    S_error.compile()

    Compiling model
    ERROR: The dimensions are not consistent. There are at least two units given for different dimension models

    An exception has occurred, use %tb to see the full traceback.

    SystemExit: 1

As explained one can also assign counts to rates. The units for rates are [count]o/([Time]x[Space]o) where o is the reaction order (the reaction order is equal to the number of reactants).

    [26]:

    Bacteria >> Zero [1*u.mol/u.second]

    Ball + Child + Child >> Ball + Child [1e-3*u.meter**4/u.hour]

    [26]:

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

For the compilation. MobsPy converts all provided units into decimeter (which yields liters for volume), seconds and counts. In the compilation, we can see the provided values in MobsPy standard units:

    [27]:

    S = Simulation(Ball | Child)
    S.volume = 2*u.meter**2
    print(S.compile())

    Species
    Ball,20.0
    Child,2.0

    Mappings
    Ball :
    Ball
    Child :
    Child

    Parameters
    volume,199.99999999999997

    Reactions
    reaction_0,{'re': [(1, 'Ball'), (2, 'Child')], 'pr': [(1, 'Ball'), (1, 'Child')], 'kin': 'Ball * Child * Child * 0.0027777777777777775 * volume^-2'}

    Compiling model

    [ ]: