atropy¶
Submodules¶
Classes¶
Represent model for reaction system. |
|
Generate partitioning for the reaction system. |
Functions¶
|
Generate sympy variables for species. |
|
Run the low rank simulation. |
Package Contents¶
- atropy.species(symbol_string: str)¶
Generate sympy variables for species.
The species of a rection network can be defined as sympy variables, which is needed for model generation. The type of output is dependent on the properties of input arguments.
Parameters¶
- symbol_stringstr
Names of species inside a string, seperated by a comma.
See Also¶
sympy.symbols : Transform strings into instances of Symbol class.
Examples¶
>>> from atropy import species >>> S0, S1, S2, S3, S4 = species("S0, S1, S2, S3, S4")
- class atropy.Model(_species)¶
Represent model for reaction system.
For a reaction system we can set up the model. Before initialization, the species need to be defined using atropy.species.
Parameters¶
- _speciestuple
Species from atropy.species.
Returns¶
- Model
Model for the reaction system.
See Also¶
atropy.species : Generate sympy variables for species. atropy.Model.add_reaction : Add single reaction to Model. atropy.Model.add_reactions : Add multiple reactions to Model. atropy.Model.generate_reaction_system : Generate the reaction system.
Examples¶
>>> from atropy import Model >>> model = Model((S0, S1, S2, S3, S4))
- reactions = []¶
- species¶
- add_reaction(reactants, products, propensities)¶
Add single reaction to Model.
For translating a single chemical reaction to implementation.
Parameters¶
- reactants
Sympy equation of reactants.
- products
Sympy equation of products.
- propensitiesdict, float or int
Propensity for specific reaction. Type of float or int can only be used if propensity described by mass action.
See Also¶
atropy.Model : Represent model for reaction system. atropy.Model.add_reactions : Add multiple reactions to Model. atropy.Model.generate_reaction_system : Generate the reaction system.
Examples¶
>>> from atropy import Model >>> model = Model((S0, S1, S2, S3, S4))
Adding a reaction using a dictionary for propensity:
>>> model.add_reaction(0, S1, {S0: 0.6 / (0.6 + S0), S4: 1.0 + S4})
Adding a reaction using a float value for propensity:
>>> model.add_reaction(S0, 0, 0.0025)
- add_reactions(reactants_list, products_list, propensities_list)¶
Add multiple reactions to Model.
For translating multiple chemical reactions to implementation.
Parameters¶
- reactants_listlist
List of Sympy equations of reactants.
- products_listlist
List of Sympy equations of products.
- propensities_listlist of dict, list of float or list of int
List of propensities for specific reactions. Type of list of float or list of int can only be used if propensities described by mass action.
See Also¶
atropy.Model : Represent model for reaction system. atropy.Model.add_reaction : Add single reaction to Model. atropy.Model.generate_reaction_system : Generate the reaction system.
Examples¶
>>> from atropy import Model >>> model = Model((S0, S1, S2, S3, S4)) >>> model.add_reactions([S0, S1], [0, 0], [0.0025, 0.0007])
- generate_reaction_system()¶
Generate the reaction system.
After the Model was initialized and the reactions were added using atropy.Model.add_reaction, the reaction system can be generated.
See Also¶
atropy.Model : Represent model for reaction system. atropy.Model.add_reaction : Add single reaction to Model.
Examples¶
>>> from atropy import Model >>> model = Model((S0, S1, S2, S3, S4)) >>> model.add_reaction(S0, 0, 0.0025) >>> model.generate_reaction_system()
- class atropy.Partitioning(_partition: str, _r: numpy.ndarray, _model: Model)¶
Generate partitioning for the reaction system.
To reduce computational complexity of the low rank solver a good partition is needed. Note that cuts should be chosen in a way that tightly coupled species are together in the same partition.
Parameters¶
- _partitionstr
Partitioning of the species. Each partition is inside a set of brackets.
- _rnumpy.ndarray
Ranks for each level of the partitioning.
- _modelatropy.Model
Model for the reaction system.
See Also¶
atropy.Partitioning.add_grid_params : Add grid parameters to Partitioning. atropy.Partitioning.generate_tree : Generate tree structure for reaction system. atropy.Partitioning.generate_initial_condition : Initialize the initial condition. atropy.Partitioning.set_initial_condition : Set values for inital condition.
Examples¶
>>> from atropy import Model, Partitioning
Set up the parameters (for model reactions can be added using atropy.Model.add_reaction):
>>> model = Model((S0, S1, S2, S3, S4)) >>> r = np.array([5, 4]) >>> p0 = "(S0 S1)((S2 S3)(S4))"
Initialize the partitioning:
>>> partitioning = Partitioning(p0, r, model)
- r¶
- model¶
- partition¶
- add_grid_params(n: numpy.ndarray, binsize: numpy.ndarray, liml: numpy.ndarray)¶
Add grid parameters to Partitioning.
Parameters¶
- nnumpy.ndarray
Amount of gridpoints for each species.
binsize : numpy.ndarray
- limlnumpy.ndarray
Lower limits of the population numbers.
See Also¶
atropy.Partitioning : Generate partition for the reaction system. atropy.Partitioning.generate_tree : Generate tree structure for reaction system. atropy.Partitioning.generate_initial_condition : Initialize the initial condition. atropy.Partitioning.set_initial_condition : Set values for inital condition.
Examples¶
>>> from atropy import Partitioning >>> partitioning = Partitioning(p0, r, model)
Define parameters and add grid parameters:
>>> n = np.array([16, 41, 11, 11, 11]) >>> d = n.size >>> binsize = np.ones(d, dtype=int) >>> liml = np.zeros(d) >>> partitioning.add_grid_params(n, binsize, liml)
- generate_tree()¶
Generate tree structure for reaction system.
The tree should be generated after setting up the Model and adding the grid parameters to the Partitioning.
See Also¶
atropy.Partitioning : Generate partition for the reaction system. atropy.Partitioning.add_grid_params : Add grid parameters to Partitioning. atropy.Partitioning.generate_initial_condition : Initialize the initial condition. atropy.Partitioning.set_initial_condition : Set values for inital condition.
Examples¶
>>> from atropy import Partitioning >>> partitioning = Partitioning(p0, r, model) >>> partitioning.add_grid_params(n, binsize, liml)
Generate the tree structure:
>>> partitioning.generate_tree()
- generate_initial_condition(n_basisfunctions: numpy.ndarray)¶
Initialize the initial condition.
Parameters¶
- n_basisfunctionsnumpy.ndarray
Number of basis functions.
See Also¶
atropy.Partitioning : Generate partition for the reaction system. atropy.Partitioning.add_grid_params : Add grid parameters to Partitioning. atropy.Partitioning.generate_tree : Generate tree structure for reaction system. atropy.Partitioning.set_initial_condition : Set values for inital condition.
Examples¶
>>> from atropy import Partitioning >>> partitioning = Partitioning(p0, r, model) >>> partitioning.add_grid_params(n, binsize, liml) >>> partitioning.generate_tree()
Initialize the initial condition:
>>> partitioning.generate_initial_condition(r)
- set_initial_condition(polynomials_dict)¶
Set values for inital condition.
Only possible for rank 1 inital condition, which can be split into a product of functions, each depending only on one species
Parameters¶
- polynomials_dictdict
Dictionary containing a function for each species.
See Also¶
atropy.Partitioning : Generate partition for the reaction system. atropy.Partitioning.add_grid_params : Add grid parameters to Partitioning. atropy.Partitioning.generate_tree : Generate tree structure for reaction system. atropy.Partitioning.generate_initial_condition : Initialize the initial condition.
Examples¶
>>> from atropy import Partitioning >>> partitioning = Partitioning(p0, r, model) >>> partitioning.add_grid_params(n, binsize, liml) >>> partitioning.generate_tree() >>> partitioning.generate_initial_condition(n_basisfunctions)
Assign a function to each species:
>>> polynomials_dict = { ... S0: sp.exp(-S0**2), ... S1: sp.exp(-S1**2), ... S2: sp.exp(-S2**2), ... S3: sp.exp(-S3**2), ... S4: sp.exp(-S4**2), ... }
Set values for the initial condition:
>>> partitioning.set_initial_condition(polynomials_dict)
- atropy.run(partitioning: Partitioning, output: str, tau: float, tfinal: float | int, snapshot: int = 2, substeps: int = 1, method: str = 'RK4')¶
Run the low rank simulation.
Generate multiple NetCDF output files, which simulate the reaction system described in partitioning.
Parameters¶
- partitioningPartitioning
Partitioning of the reaction system.
- outputstr
Name of the generated output files.
- taufloat
Timestep size for the simulation.
- tfinal: float or int
Final time for the simulation.
- snapshotint, default 2
Number of generated output files.
substeps : int, default 1
- methodstr, default “RK4”
Time integration method for the simulation. The 4 possible values are: “implicit_Euler”, “explicit_Euler”, “Crank_Nicolson” and “RK4”.
See Also¶
atropy.species : Generate sympy variables for species. atropy.Model : Represent model for reaction system. atropy.Partitioning : Generate partition for the reaction system.
Examples¶
After setting up Model and Partitioning one can run the simulation:
>>> run(partitioning, "output", 1e-3, 10, snapshot=10, method="implicit_Euler")