Reaction-diffusion systems¶
- class strengths.RDSystem(network, space=<strengths.rdgridspace.RDGridSpace object>, state=None, chemostats=None, units_system=<strengths.units.UnitsSystem object>)¶
Describes a reaction diffusion system, coupling a reaction_network with a space, characterized by a system state, which corresponds to the distribution of the chemical species quantities inside the system space, and chemostat maps for each species in the system.
reaction network and space sould no be changed. If a change of system size or number of species is required, creation of a new RDSystem is highly recomended.
- Parameters:
network (RDNetwork) – system reaction_diffusion network
space (RDSpace) – system space (default RDSpace())
state (array, UnitArray, None or dict) – system state to be used. if set to None or with a dict, the a default system state is generated from network and space (see generate_system_state) (default None).
chemostats (array, None or dict) – system chemostat map to be used. if set to None or with a dict, the a default system chemostat map is generated from network and space (see generate_system_chemostats) (default None).
units_system (UnitsSystem) – default units system (default UnitsSystem())
- apply_reaction(reaction, *, position=0, n=1, state=None, chemostats=None, update=False)¶
Apply the given reaction to the system state, at the given position, n times. Chemostats are taken into account. if n is negative, the reverse reaction is applied. The resulting state is returned.
- Parameters:
reaction – The reaction to be applied.
position – Position at which the reaction should be applied in the system. (default 0).
n (int or float) – Number of time the reaction should be applied. If n<0, the reverse reaction is applied. (default 1).
state (UnitArray, with quantity of matter as units.) – State to which the reaction should be applied. if None, the system state is used instead. (default None).
update (bool) – tells whether the resulting state should be set as the system state : True=yes, False=No. (default False).
- Param:
chemostats Chemostat map to be used. If None, the one of the system is used instead. (default None).
- Returns:
The modified state
- Return type:
UnitArray, with quantity of matter as units.
- property chemostats¶
Map of the chemostats for each species in the system (array of int). Can be set by a single value or an array. If set as an array, the array must match state_size.
- copy()¶
returns a deepcopy of the instance.
instance.copy() # is equivalent to # import copy copy.deepcopy(instance)
- get_cell_index(position)¶
Returns the linear index of a cell from its 3D coordinates (x, y, z).
- Parameters:
position (int, Coord like or tuple) – cell index or coordinates
- Returns:
index of the species at the given position.
- Return type:
int
ie.
rdsystem.get_cell_index((1,0,0)) rdsystem.get_cell_index(Coord(1,0,0)) rdsystem.get_cell_index(1)
- get_chemostat(species, position)¶
Returns the chemostat map value for a given species at a given position.
- Parameters:
species (Species, int or str) – species of which the chemostate map value must be returned
position (number (interpreted as a linear index (int)) or a class with x, y and z properties/members.) – position at which the chemostat map must be considered
value (int or bool) – value to be set
- Returns:
chemostat map value
- Return type:
int
- get_error()¶
Returns the error messages built during the previous call to the is_valid method.
- Return type:
str
- get_state(species, position)¶
Returns the state value for a given species at a given position.
- get_state_index(species, position)¶
Returns the linear index of the quantity of a given species in a given cell in the system state array from its 3D coordinates (x, y, z).
- Parameters:
species – species of interest. it must be part of the reaction network. if given as a str, it must be a species label. if given as a int, it must be a species index.
position (int or Coord like) – cell index or coordinates
- Returns:
index for the species state at the given position.
- Return type:
int
ie.
rdsystem.get_state_index(1, (1,0,0)) rdsystem.get_state_index("A", Coord(1,0,0)) rdsystem.get_state_index(rdsystem.network.get_species("A"), 1)
- is_valid()¶
Checks is the system is valid. Error messages are stored internally, and can be retrived by calling the get_error method.
- Return type:
bool
- Returns:
True : no problem have been found. False : the system is invalid.
- make_dxdtf(units_system=<strengths.units.UnitsSystem object>)¶
Returns a function dxdt = f(t, x) for systems with a system of size 1.
- reset_chemostats()¶
Sets all chemostat map values to False/0.
- reset_state()¶
Sets all species quantity to 0 in all cells.
- set_chemostat(species, position, value)¶
Sets the chemostat map value for a given species at a given position.
- Parameters:
species (Species, int or str) – species for which the value must be set
pos (number (interpreted as a linear index (int)) or a class with x, y and z properties/members.) – position at which the value must be set
value (int or bool) – value to be set
- set_default_chemostats(override_species_chstt_dict={})¶
Sets the default chemostat map (see generate_system_chemostats).
- Parameters:
override_species_chstt_dict (dict) – optionnal. species chemostat maps that should override the default state.
- set_default_state(override_species_state_dict={})¶
sets the default system state (see generate_system_chemostats).
- Parameters:
override_species_state_dict (dict) – optionnal. species states that should override the default state.
- set_state(species, position, value)¶
Sets the state value for a given species at a given position.
- Parameters:
species (Species, int or str) – species for which the value must be set
pos (number (interpreted as a linear index (int)) or a class with x, y and z properties/members.) – position at which the value must be set
value (number or UnitValue with quantity units dimensions.) – value to be set
- property space¶
system space (
RDSpace).
- property state¶
State of the system (
UnitArray). It corresponds to the quantity of each species in each cell of the system. It can be set with an array or a UnitArray with quantity units dimensions. ie.# considering rdsystem.state_size() == 8 rdsystem.state = [1,1,1,1,1,1,1,1] rdsystem.state = UnitArray([1,1,1,1,1,1,1,1], "molecule")
- state_size()¶
Returns the size of the system state (int).
size = w*h*d*nspecies
- property units_system¶
Default units system used when value that require units are given without (
UnitsSystem). can be defined from aUnitsSystemor adict. ie.rdsystem.units_system = UnitsSystem(space="µm", time="s", quantity="molecule") rdsystem.units_system = {"space"="µm", "time"="s", "quantity"="molecule"}
- strengths.generate_species_state(species, network, space, units_system)¶
Makes the default initial state for a given species. The default state is generated using the species density, the space environment map, and the cell volume :
\[x_{s,i} = [s]_{env_i} V\]with x the system state, s the species, i the cell position, env_i the environment of cell i, and v the cell volume.
- Parameters:
species (Species) – species for which the state is generated. Must be part of network.
network (RDNetwork) – reaction network the specied is part of.
space (RDSpace) – space for which the state must be generated
units_system (UnitsSystem) – units system in which the state should be experssed
- Returns:
defalut species state in the space.
- Return type:
- strengths.generate_system_state(network, space, units_system, state_dict={})¶
Makes the initial state for a given reaction network
- Parameters:
network (RDNetwork) – reaction network the specied is part of.
space (RDSpace) – space for which the state must be generated
units_system (UnitsSystem) – units system in which the state should be experssed
state_dict (dict) – dictionnary containing state to apply for the species, overriding the default species states. is empty by default.
- Returns:
full system state for the given reaction diffusion network and space.
- Return type:
- strengths.generate_species_chemostats(species, network, space)¶
Makes the default chemostat space map for a given species
- Parameters:
- Returns:
defalut species chemostate map in the space.
- Return type:
array of int
- strengths.generate_system_chemostats(network, space, chstt_dict={})¶
Makes the chemostat map for a given reaction network
- Parameters:
network (RDNetwork) – reaction network the specied is part of.
space (RDSpace) – space for which the state must be generated
chstt_dict (dict) – dictionnary containing chemostat map to apply for the species, overriding the default species states. is empty by default.
- Returns:
full system chemostate map for the given reaction diffusion network and space.
- Return type:
array of int
- strengths.load_rdsystem(path, parent_units_system=<strengths.units.UnitsSystem object>)¶
Returns a RDSystem 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.
- Returns:
reaction diffusion system built according to the JSON file.
- strengths.save_rdsystem(rds, path)¶
Saves the dictionnary desctiption of the reaction diffusion system rds as a JSON file at the given path.
- Parameters:
rds (RDSystem) – reaction diffusion system 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.rdsystem_to_dict(rds)¶
Returns a dictionnary describing the reaction network.
- Parameters:
network (RDNetwork) – reaction network to be converted
- Returns:
dictionary representing network.
- strengths.rdsystem_from_dict(d, parent_units_system=<strengths.units.UnitsSystem object>, base_path=None)¶
Returns a RDSystem created acoording to the dictionnary d.
- Parameters:
d (dict) – dictionary representing the reaction diffusion system
- Returns:
reaction diffusion system created from d.