Reaction-diffusion networks

class strengths.Species(label, D=0, density=0, chstt=False, units_system=<strengths.units.UnitsSystem object>)

A chemical species.

Parameters:
  • label (str) – unique label identifying the species in a reaction network

  • D (see D property) – species diffusion coefficient (default 0).

  • density (see density property) – species initial quantity (default 0).

  • chstt (see chstt property) – species chemostate (default False).

  • units_system (UnitSystem or dict) – default units system (default UnitsSystem())

property D

Diffusion coefficient of the species (UnitValue or dict of UnitValue). In term of unit dimensions, it have to be {“space” : 2, “time” : -1}.

It can be defined by a number, a UnitValue, a str or environment wise by using a dict (of numbers, UnitValue and str). ie.

rdnetwork.D = 0.5
rdnetwork.D = "0.5 µm2.s-1"
rdnetwork.D = UnitValue(0.5, "µm2/s")
rdnetwork.D = {"env_1" : "0.5 µm2.s-1",
               "env_2" :  5}
property chstt

tells if the quantity of this species should be by default considered constant (bool or dict of bool). it can be a boolean (True is the species is chemostated, False otherwise), or a dictionary associating a boolean to some environment. ie.

{ "membrane" : True,
  "cytoplasm" : False }
copy()

returns a deepcopy of the instance.

instance.copy()

# is equivalent to
# import copy

copy.deepcopy(instance)
property density

default density of the species in systems (UnitValue or dict of UnitValue). In term of unit dimensions, it have to be a density. It can be define by a number, a UnitValue, a str or environment wise by using a dict (of numbers, UnitValue and str). ie.

rdnetwork.D = 5
rdnetwork.D = "0.5 µM"
rdnetwork.D = UnitValue(0.5, "µM")
rdnetwork.D = {"env_1" : "0.5 µM",
               "env_2" : "5 nM"}
property label

string identifyling the species inside a reaction network (str). can be thought as the name of the species. a species must have one.

property units_system

default units system used when value that require units are given without (UnitsSystem). can be defined from a UnitsSystem or a dict. ie.

species.units_system = UnitsSystem(space="µm", time="s", quantity="molecule")
species.units_system = {"space"="µm", "time"="s", "quantity"="molecule"}
class strengths.Reaction(stoechiometry, kf=0, kr=0, label=None, environments=None, units_system=<strengths.units.UnitsSystem object>)

A reversible chemical transformation that converts some species into others with respect to a forward and a reverse kinetic rate constants.

Parameters:
  • stoechiometry – stoechiometry of the reaction. can be a string the “substrate -> product” (ie. “A + 2 B -> C”) or an array of two dictonaries, the first representing the subtrates, and the second the products. each dictionary must then contain species labels as keys and numbres as values. (ie. [{“A”:1, “B”:2}, {“C”:1}]).

  • kf – forward reaction rate constant

  • kr – reverse reaction rate constant (default 0)

  • label (str or None) – unique identifier for the reaction in a reaction network. (default None)

  • environments (None or list[str].) – list of environment in which the reaction can occur (default None). if None, the reaction can occur everywhere.

  • units_system (UnitSystem or dict) – default units system (default UnitsSystem())

property K

Equilibrium constant of the reaction in the forward direction. It is an alias for the equilibrium_constant method, except is is a read-only property.

copy()

returns a deepcopy of the instance.

instance.copy()

# is equivalent to
# import copy

copy.deepcopy(instance)
dsto(species_labels)

Returns the transformation change (products-substrates) stoechiometry array corresponding to species_labels.

Parameters:

species_labels (array of str) – list of species labels. For a given RDNetwork rdn, it must be ordered as in rdn.species_labels.

Returns:

product-substrate stoechiometry coefficient for each species.

Return type:

array of int

property environments

tuple of environments labels in which the reaction can happen. if None, the reaction can happen in any environment.

equilibrium_constant()

Returns the reaction equilibrium constant K = kf/kr.

Return type:

UnitValue

get_product_stoechiometry(species_label)

returns the product stoechimetry of a given species. :param species_label: label of the species :type species_label: str :returns: product side stoechiometric coefficient for the given species :rtype: int

get_substrate_stoechiometry(species_label)

returns the substrate stoechimetry of a given species. :param species_label: label of the species :type species_label: str :returns: substrate side stoechiometric coefficient for the given species :rtype: int

property kf

Forward reaction rate constant (UnitsSystem). can be set by a number, a str or a UnitValue. ie.

reaction.kf = 1
reaction.kf = UnitValue(1, "µM-1.s-1")
reaction.kf = "1 µM-1.s-1"
kf_units_dimensions()

Returns the units dimensions of the forward reaction rate (UnitsDimensions).

property kr

Reverse reaction rate constant (UnitsSystem). can be set by a number, a str or a UnitValue. see k+ example above.

kr_units_dimensions()

Returns the units dimensions of the reverse reaction rate (UnitsDimensions).

property label

string used to identiify the reation inside a rdNetwork. it is optional, and is None by default.

order()

Returns the order of the forward reaction.

property products

Returns a copy of the products dictionary. Keys are species labels and values are the corresponding stoechiometry coefficient.

psto(species_labels)

Returns the products stoechiometry array corresponding to species_labels.

Parameters:

species_labels (array of str) – list of species labels. For a given RDNetwork rdn, it must be ordered as in rdn.species_labels.

Returns:

product stoechiometry coefficient for each species.

Return type:

array of int

rorder()

Returns the order of the reverse reaction.

set_k(kf, kr)

Sets the reaction’s forward and reverse kinetics rate constants, respectively.

Parameters:
  • kf (number or UnitValue) – forward reaction rate.

  • kr (number or UnitValue) – reverse reaction rate.

split()

split the reaction into a pair of opposed irreversible reactions (with kr=0). returned reactions have the same properties than the splitted reaction, except for their label, which are NULL.

example :

r = Reaction("A + B -> C",
         kf=2,
         kr=1,
         label="association",
         environments=["env1"],
         units_system=UnitsSystem(space="m",
                                  time="min",
                                  quantity="mol")
         )

r_forward, r_reverse = r.split()

# is equivalent to

r_forward = Reaction("A + B -> C",
         kf=2,
         kr=0,
         label=None,
         environments=["env1"],
         units_system=UnitsSystem(space="m",
                                  time="min",
                                  quantity="mol")
         )

r_reverse = Reaction("C -> A + B",
         kf=1,
         kr=0,
         label=None,
         environments=["env1"],
         units_system=UnitsSystem(space="m",
                                  time="min",
                                  quantity="mol")
         )
Returns:

a list of two Reaction objects. The first corrspond to the forward irreversible reaction, the second, to the reverse irreversible reaction.

Return type:

list of Reaction

ssto(species_labels)

Returns the substrates stoechiometry array corresponding to species_labels.

Parameters:

species_labels (array of str) – list of species labels. For a given RDNetwork rdn, it must be ordered as in rdn.species_labels.

Returns:

substrate stoechiometry coefficient for each species.

Return type:

array of int

property substrates

Returns a copy of the substrate dictionary. Keys are species labels and values are the corresponding stoechiometry coefficient.

to_string()

Returns a string representing the reaction’s stoechimetric equation (str).

property units_system

default units system used when value that require units are given without (UnitsSystem). can be defined from a UnitsSystem or a dict. ie.

reaction.units_system = UnitsSystem(space="µm", time="s", quantity="molecule")
reaction.units_system = {"space"="µm", "time"="s", "quantity"="molecule"}
class strengths.RDNetwork(species, reactions, environments=[''], units_system=<strengths.units.UnitsSystem object>)

A network of chemical transformations (Reaction) and chemical species (Species).

Parameters:
  • species (array of Species) – list of species

  • reactions (array of Reactions) – list of reactions

  • environments (array of str) – list of environment labels (default [“”])

  • units_system (UnitSystem or dict) – default units system (default UnitsSystem())

copy()

returns a deepcopy of the instance.

instance.copy()

# is equivalent to
# import copy

copy.deepcopy(instance)
property environments

Labels of the different environments of the network (array of str). it is a non-empty tuple of string. ie.

environments = []              # wrong : the array is empty
environments = [1]             # wrong : the 1 is not a string
environments = ["a", "b", "c"] # ok

means the systems have 3 environments labelled “a”, “b” and “c”. The order of the labels matters, as here, “a”, “b” and “c” have cell environment indices 0, 1 and 2, and those indices are the one used in RDSystem.cell_env.

get_environment_index(environment)

Returns the environment list index associated with the given input. if given a string, the index of the first environent with a matching label is returned. if given a number, int(environemnt) is returned if 0<=reaction<nenvironments. in case no index can be found, None is returned.

Parameters:

environment (number or str) – environment from which we want the index.

Returns:

index of the environment

Return type:

int or None

get_reaction(label)

Returns the first reaction with the given label, or none otherwise (Reaction() or None).

get_reaction_index(reaction)

Returns the Reaction list index associated with the given input. if reaction is a string or a Reaction, the index of the first reaction with a matching label is returned. if reaction is a number, int(reaction) is returned if 0<=reaction<nreactions. in case no index can be found, None is returned.

Parameters:

reaction (number, str or Reaction) – reaction from which we want the index.

Returns:

index of the reaction

Return type:

int or None

get_species(label)

Returns the first species with the given label, or none otherwise (Species() or None).

get_species_index(species)

Returns the species list index associated with the given input. if species is a string or a Species, the index of the first species with a matching label is returned. if species is a number, int(species) is returned if 0<=species<nspecies. in case no index can be found, None is returned.

Parameters:

species (number, str or Species) – species from which we want the index.

Returns:

index of the species

Return type:

int or None

nenvironments()

Returns the number of environments in the network.

nreactions()

Returns the number of reactions in the network.

nspecies()

Returns the number of species in the network.

property reactions

Reactions of the network (tuple of Reaction).

property species

Species of the network (tuple of Species).

species_labels()

Returns the array of the labels of the network’s species.

property units_system

default units system used when value that require units are given without (UnitsSystem). can be defined from a UnitsSystem or a dict. ie.

rdnetwork.units_system = UnitsSystem(space="µm", time="s", quantity="molecule")
rdnetwork.units_system = {"space"="µm", "time"="s", "quantity"="molecule"}
strengths.load_rdnetwork(path, parent_units_system=<strengths.units.UnitsSystem object>)

Returns a ReactionNetwork created acoording to the dictionnary d loaded from the JSON file at the given path.

Parameters:
  • path (str) – relative or absolute path to a json file.

  • units_system (UnitsSystem) – default units system (default UnitsSystem())

Returns:

reaction network built according to the JSON file.

strengths.save_rdnetwork(rdn, path)

Saves the dictionnary desctiption of the reaction network rdn as a JSON file at the given path.

Parameters:
  • rdn (ReactionNetwork) – reaction network to be saved as a JSON file.

  • path (str) – JSON save file relative or absolute path. a JSON is created at this location, or replaced if it already exists

Returns:

None

strengths.rdnetwork_to_dict(rdn)

Returns a dictionnary describing the reaction network.

Parameters:

rdn (ReactionNetwork) – reaction network to be converted

Returns:

dictionary representing rdn.

strengths.rdnetwork_from_dict(d, parent_units_system=<strengths.units.UnitsSystem object>, base_path=None)

Returns a RDNetwork created acoording to the dictionnary d.

Parameters:
  • d (dict) – dictionary representing the reaction network

  • units_system (UnitsSystem) – default units system (default UnitsSystem())

Returns:

reaction network created from d.

Return type:

RDNetwork