name | arguments | returns |
__init__ | self, n_bins=None, chem_data=None, reactions=None | |
:param n_bins: A pair with the bin size in the x- and y- coordinates
:param chem_data:
:param reactions:
|
name | arguments | returns |
initialize_system | self, n_bins: (int, int), chem_data=None, reactions=None | None |
Initialize all concentrations to zero.
:param n_bins: The number of compartments (bins) to use in the simulation,
in the x- and y- dimensions, as a pair of integers
:param chem_data: (OPTIONAL) Object of class "Chemicals";
if not specified, it will get extracted from the "Reactions" class
:param reactions: (OPTIONAL) Object of class "Reactions";
if not specified, it'll get instantiated here
:return: None
|
name | arguments | returns |
system_size | self | (int, int) |
Return a pair of integers with the system size in the x- and y-dimensions
Note: the bin numbers will range between 0 and system_size - 1
:return: The pair (x-dimension, y-dimension)
|
name | arguments | returns |
system_snapshot | self, species_index=0 | pd.DataFrame |
Return a snapshot of all the concentrations of the given species, across all bins,
as a Pandas dataframe
:return: A Pandas dataframe with the concentration data for the single specified chemical;
rows and columns correspond to the system's rows and columns
|
name | arguments | returns |
set_bin_conc | self, bin_x: int, bin_y: int, species_index: int, conc: float | None |
Assign the requested concentration value to the cell with the given index, for the specified species
:param bin_x: The zero-based bin number of the desired cell
:param bin_y: The zero-based bin number of the desired cell
:param species_index: Zero-based index to identify a specific chemical species
:param conc: The desired concentration value to assign to the specified location
:return: None
|
name | arguments | returns |
set_bin_conc_all_species | self, bin_x: int, bin_y: int, conc_list: [float] | None |
Assign the requested concentration values to the cell with the given index,
for all the species in their index order
:param bin_x: The zero-based bin number of the desired cell
:param bin_y: The zero-based bin number of the desired cell
:param conc_list: A list with the desired concentration values to assign to the specified location
:return: None
|
name | arguments | returns |
set_species_conc | self, conc_data: Union[list, tuple, np.ndarray], species_index=None, species_name=None | None |
For the single specified species, assign the requested list of concentration values to all the bins,
in row order first (top to bottom) and then in column order.
EXAMPLE: set_species_conc([[1, 2, 3], [4, 5, 6]], species_index=0)
will set the system state, for the specified chemical, to:
[1, 2, 3]
[4, 5, 6]
:param conc_data: A list, tuple or Numpy array with the desired concentration values
to assign to all the bins.
The dimensions must match the system's dimensions.
:param species_index: Zero-based index to identify a specific chemical species
:param species_name: (OPTIONAL) If provided, it over-rides the value for species_index
:return: None
|
name | arguments | returns |
inject_conc_to_bin | self, bin_address: (int, int), species_index: int, delta_conc: float, zero_clip = False | None |
Add the requested concentration to the cell with the given address, for the specified chem species
:param bin_address: A pair with the zero-based bin numbers of the desired cell, in the x- and y-coordinates
:param species_index: Zero-based index to identify a specific chemical species
:param delta_conc: The concentration to add to the specified location
:param zero_clip: If True, any requested increment causing a concentration dip below zero, will make the concentration zero;
otherwise, an Exception will be raised
:return: None
|
name | arguments | returns |
describe_state | self, concise=False | None |
For each chemical species, show its name (or index, if name is missing),
followed by the matrix of concentrations values for that chemical
:param concise: Not yet used
:return: None
|
name | arguments | returns |
lookup_species | self, species_index=None, species_name=None, copy=False | np.array |
Return the NumPy array of concentration values across the all bins
(from top to bottom, and then left to right),
for the single specified chemical species.
NOTE: what is being returned NOT a copy, unless specifically requested
:param species_index: The index order of the chemical species of interest
:param species_name: (OPTIONAL) If provided, it over-rides the value for species_index
:param copy: If True, an independent numpy array will be returned: a *copy* rather than a view
:return: A NumPy 2-D array of concentration values across the bins
(from top to bottom, and then left to right);
the size of the array is (n_bins_y x n_bins_x)
|
name | arguments | returns |
bin_snapshot_array | self, bin_address: (int, int) | np.array |
Extract the concentrations of all the chemical species at the specified bin,
as a Numpy array in the index order of the species
EXAMPLE: np.array([10., 50.)]
:param bin_address: A pair with the zero-based bin numbers of the desired cell, in the x- and y-coordinates
:return: A Numpy array of concentration values, in the index order of the species
|
name | arguments | returns |
diffuse | self, total_duration=None, time_step=None, n_steps=None, h=1, algorithm="5_point" | dict |
Uniform-step diffusion, with 2 out of 3 criteria specified:
1) until reaching, or just exceeding, the desired time duration
2) using the given time step
3) carrying out the specified number of steps
:param total_duration: The overall time advance (i.e. time_step * n_steps)
:param time_step: The size of each time step
:param n_steps: The desired number of steps
:param h: Distance between consecutive bins in both the x- and y-directions
(For now, they must be equal)
:param algorithm: (OPTIONAL) String with a name specifying the method to use to solve the diffusion equation.
Currently available options: "5_point"
:return: A dictionary with data about the status of the operation
(for now, just the number of steps run; key: "steps")
|
name | arguments | returns |
diffuse_step | self, time_step, h=1, algorithm="5_point" | None |
Diffuse all the species for the given time step, across all bins;
clear the delta_diffusion array, and then re-compute it from all the species.
IMPORTANT: the actual system concentrations are NOT changed.
:param time_step: Time step over which to carry out the diffusion
If too large - as determined by the method is_excessive() - an Exception will be raised
:param h: Distance between consecutive bins in both the x- and y-directions
(For now, they must be equal)
:param algorithm: String with a name specifying the method to use to solve the diffusion equation.
Currently available options: "5_point"
:return: None (the array in the class variable "delta_diffusion" gets set)
|
name | arguments | returns |
diffuse_step_single_species | self, time_step: float, h: float, species_index=0, algorithm="5_point" | np.array |
Diffuse the specified single chemical species, for the given time step, across all bins,
and return a 2-D array of the changes in concentration ("Delta concentration")
for the given species across all bins.
IMPORTANT: the actual system concentrations are NOT changed.
We're assuming an isolated environment, with nothing diffusing thru the "walls"
EXPLANATION of the methodology: https://life123.science/diffusion
TODO: also test on tiny systems smaller than 3x3
:param time_step: Delta time over which to carry out this single diffusion step;
TODO: add - if too large, an Exception will be raised.
:param species_index: ID (in the form of an integer index) of the chemical species under consideration
:param h: Distance between consecutive bins, ASSUMED the same in both directions
:param algorithm: String with a name specifying the method to use to solve the diffusion equation.
Currently available options: "5_point"
:return: A 2-D Numpy array with the CHANGE in concentration for the given species across all bins
|
name | arguments | returns |
convolution_5_point_stencil | self, increment_matrix, species_index, effective_diff | None |
Carry out a 2-D convolution operation on increment_matrix,
with a tile of size 3 that implements a 5-point stencil
TODO: maybe pass self.system[species_index] as argument
TODO: move the x effective_diff to the calling function
:param increment_matrix:
:param species_index:
:param effective_diff:
:return: None (increment_matrix gets modified)
|
name | arguments | returns |
react | self, total_duration=None, time_step=None, n_steps=None, snapshots=None | None |
Update the system concentrations as a result of all the reactions in all bins.
CAUTION : NO diffusion is taken into account.
The duration and granularity of the reactions is specified with 2 out of the 3 parameters:
total_duration, time_step, n_steps
For each bin, process all the reactions in it - based on
the INITIAL concentrations (prior to this reaction step),
which are used as the basis for all the reactions.
TODO: in case of any Exception, the state of the system is still valid, as of the time before this call
:param total_duration: The overall time advance (i.e. time_step * n_steps)
:param time_step: The size of each time step
:param n_steps: The desired number of steps
:param snapshots: NOT YET USED
OPTIONAL dict with the keys: "frequency", "sample_bin", "sample_species"
If provided, take a system snapshot after running a multiple of "frequency" runs
:return: None
|
name | arguments | returns |
reaction_step | self, delta_time: float | None |
Compute and store the incremental concentration changes in all bins,
from all reactions,
for a single time step of duration delta_time.
The incremental concentration changes are stored in the class variable
"delta_reactions", which contains a Numpy array that gets cleared and set.
IMPORTANT: the actual system concentrations are NOT changed.
For each bin, process all the reactions in it - based on
the INITIAL concentrations (prior to this reaction step),
which are used as the basis for all the reactions.
:param delta_time: The time duration of the reaction step - assumed to be small enough that the
concentration won't vary significantly during this span
:return: None (note: the class variable "delta_reactions" gets updated)
|