U ("Up-regulator") up-regulates X , by sharing a reaction product D ("Drain") across 2 separate reactions:¶U <-> 2 D and X <-> D (both mostly forward)¶1st-order kinetics throughout.
Invoking Le Chatelier's principle, it can be seen that, starting from equilibrium, when [U] goes up, so does [D]; and when [D] goes up, so does [X].
Conversely, when [U] goes down, so does [D]; and when [D] goes down, so does [X].
LAST REVISED: Feb. 11, 2023
# Extend the sys.path variable, to contain the project's root directory
import set_path
set_path.add_ancestor_dir_to_syspath(2) # The number of levels to go up
# to reach the project's home, from the folder containing this notebook
Added 'D:\Docs\- MY CODE\BioSimulations\life123-Win7' to sys.path
from experiments.get_notebook_info import get_notebook_basename
from src.modules.reactions.reaction_data import ReactionData as chem
from src.modules.reactions.reaction_dynamics import ReactionDynamics
import numpy as np
import plotly.express as px
from src.modules.visualization.graphic_log import GraphicLog
# Initialize the HTML logging
log_file = get_notebook_basename() + ".log.htm" # Use the notebook base filename for the log file
# Set up the use of some specified graphic (Vue) components
GraphicLog.config(filename=log_file,
components=["vue_cytoscape_1"],
extra_js="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.21.2/cytoscape.umd.js")
-> Output will be LOGGED into the file 'up_regulate_2.log.htm'
# Initialize the system
chem_data = chem(names=["U", "X", "D"])
# Reaction U <-> 2D , with 1st-order kinetics for all species
chem_data.add_reaction(reactants="U", products=[(2, "D")],
forward_rate=8., reverse_rate=2.)
# Reaction X <-> D , with 1st-order kinetics for all species
chem_data.add_reaction(reactants="X", products="D",
forward_rate=6., reverse_rate=3.)
chem_data.describe_reactions()
# Send the plot of the reaction network to the HTML log file
graph_data = chem_data.prepare_graph_network()
GraphicLog.export_plot(graph_data, "vue_cytoscape_1")
Number of reactions: 2 (at temp. 25 C) 0: U <-> 2 D (kF = 8 / kR = 2 / Delta_G = -3,436.56 / K = 4) | 1st order in all reactants & products 1: X <-> D (kF = 6 / kR = 3 / Delta_G = -1,718.28 / K = 2) | 1st order in all reactants & products [GRAPHIC ELEMENT SENT TO LOG FILE `up_regulate_2.log.htm`]
dynamics = ReactionDynamics(reaction_data=chem_data)
dynamics.set_conc(conc={"U": 50., "X": 100., "D": 0.})
dynamics.describe_state()
SYSTEM STATE at Time t = 0: 3 species: Species 0 (U). Conc: 50.0 Species 1 (X). Conc: 100.0 Species 2 (D). Conc: 0.0
dynamics.set_diagnostics() # To save diagnostic information about the call to single_compartment_react()
dynamics.single_compartment_react(time_step=0.03, stop_time=0.5,
dynamic_substeps=2, rel_fast_threshold=50)
df = dynamics.get_history()
df
single_compartment_react(): setting abs_fast_threshold to 16.666666666666668 17 total step(s) taken
| SYSTEM TIME | U | X | D | caption | |
|---|---|---|---|---|---|
| 0 | 0.015 | 44.000000 | 91.000000 | 21.000000 | Interm. step, due to the fast rxns: [0, 1] |
| 1 | 0.030 | 39.350000 | 83.755000 | 37.545000 | |
| 2 | 0.045 | 35.754350 | 77.906575 | 50.584725 | Interm. step, due to the fast rxns: [0, 1] |
| 3 | 0.060 | 32.981370 | 73.171296 | 60.865965 | |
| 4 | 0.075 | 30.849584 | 69.324848 | 68.975984 | Interm. step, due to the fast rxns: [0, 1] |
| 5 | 0.090 | 29.216914 | 66.189531 | 75.376642 | |
| 6 | 0.105 | 27.972183 | 63.624422 | 80.431212 | Interm. step, due to the fast rxns: [0, 1] |
| 7 | 0.120 | 27.028458 | 61.517628 | 84.425456 | |
| 8 | 0.135 | 26.317806 | 59.780187 | 87.584200 | Interm. step, due to the fast rxns: [0, 1] |
| 9 | 0.150 | 25.787196 | 58.341259 | 90.084349 | |
| 10 | 0.165 | 25.395263 | 57.144342 | 92.065133 | Interm. step, due to the fast rxns: [0, 1] |
| 11 | 0.180 | 25.109785 | 56.144282 | 93.636148 | |
| 12 | 0.195 | 24.905695 | 55.304923 | 94.883686 | Interm. step, due to the fast rxns: [0, 1] |
| 13 | 0.210 | 24.763522 | 54.597246 | 95.875709 | |
| 14 | 0.225 | 24.668171 | 53.997901 | 96.665757 | Interm. step, due to the fast rxns: [0, 1] |
| 15 | 0.240 | 24.607963 | 53.488049 | 97.296025 | |
| 16 | 0.255 | 24.573888 | 53.052446 | 97.799778 | Interm. step, due to the fast rxns: [1] |
| 17 | 0.270 | 24.539814 | 52.678715 | 98.241657 | |
| 18 | 0.285 | 24.542286 | 52.358506 | 98.556923 | Interm. step, due to the fast rxns: [1] |
| 19 | 0.300 | 24.544758 | 52.081302 | 98.829183 | |
| 20 | 0.315 | 24.564262 | 51.841298 | 99.030178 | Interm. step, due to the fast rxns: [1] |
| 21 | 0.330 | 24.583767 | 51.631939 | 99.200527 | |
| 22 | 0.360 | 24.635694 | 51.266237 | 99.462374 | |
| 23 | 0.390 | 24.690870 | 50.989928 | 99.628331 | |
| 24 | 0.420 | 24.742761 | 50.778291 | 99.736187 | |
| 25 | 0.450 | 24.788670 | 50.614455 | 99.808205 | |
| 26 | 0.480 | 24.827881 | 50.486592 | 99.857645 | |
| 27 | 0.510 | 24.860649 | 50.386193 | 99.892510 |
dynamics.explain_time_advance()
From time 0 to 0.33, in 22 substeps of 0.015 (each 1/2 of full step) From time 0.33 to 0.51, in 6 FULL steps of 0.03 (for a grand total of 17 full steps)
dynamics.plot_curves(colors=['red', 'green', 'gray'])
# Verify that the reaction has reached equilibrium
dynamics.is_in_equilibrium()
U <-> 2 D
Final concentrations: [D] = 99.89 ; [U] = 24.86
1. Ratio of reactant/product concentrations, adjusted for reaction orders: 4.0181
Formula used: [D] / [U]
2. Ratio of forward/reverse reaction rates: 4.0
Discrepancy between the two values: 0.4524 %
Reaction IS in equilibrium (within 1% tolerance)
X <-> D
Final concentrations: [D] = 99.89 ; [X] = 50.39
1. Ratio of reactant/product concentrations, adjusted for reaction orders: 1.98254
Formula used: [D] / [X]
2. Ratio of forward/reverse reaction rates: 2.0
Discrepancy between the two values: 0.8731 %
Reaction IS in equilibrium (within 1% tolerance)
True
dynamics.set_chem_conc(species_name="U", conc=70., snapshot=True)
dynamics.describe_state()
SYSTEM STATE at Time t = 0.51: 3 species: Species 0 (U). Conc: 70.0 Species 1 (X). Conc: 50.38619345748053 Species 2 (D). Conc: 99.89250950608736
dynamics.get_history(tail=3)
| SYSTEM TIME | U | X | D | caption | |
|---|---|---|---|---|---|
| 26 | 0.48 | 24.827881 | 50.486592 | 99.857645 | |
| 27 | 0.51 | 24.860649 | 50.386193 | 99.892510 | |
| 28 | 0.51 | 70.000000 | 50.386193 | 99.892510 | Set concentration of `U` |
dynamics.single_compartment_react(time_step=0.03, stop_time=1,
dynamic_substeps=2, rel_fast_threshold=50)
df = dynamics.get_history()
df
single_compartment_react(): setting abs_fast_threshold to 16.666666666666668 17 total step(s) taken
| SYSTEM TIME | U | X | D | caption | |
|---|---|---|---|---|---|
| 0 | 0.015 | 44.000000 | 91.000000 | 21.000000 | Interm. step, due to the fast rxns: [0, 1] |
| 1 | 0.030 | 39.350000 | 83.755000 | 37.545000 | |
| 2 | 0.045 | 35.754350 | 77.906575 | 50.584725 | Interm. step, due to the fast rxns: [0, 1] |
| 3 | 0.060 | 32.981370 | 73.171296 | 60.865965 | |
| 4 | 0.075 | 30.849584 | 69.324848 | 68.975984 | Interm. step, due to the fast rxns: [0, 1] |
| 5 | 0.090 | 29.216914 | 66.189531 | 75.376642 | |
| 6 | 0.105 | 27.972183 | 63.624422 | 80.431212 | Interm. step, due to the fast rxns: [0, 1] |
| 7 | 0.120 | 27.028458 | 61.517628 | 84.425456 | |
| 8 | 0.135 | 26.317806 | 59.780187 | 87.584200 | Interm. step, due to the fast rxns: [0, 1] |
| 9 | 0.150 | 25.787196 | 58.341259 | 90.084349 | |
| 10 | 0.165 | 25.395263 | 57.144342 | 92.065133 | Interm. step, due to the fast rxns: [0, 1] |
| 11 | 0.180 | 25.109785 | 56.144282 | 93.636148 | |
| 12 | 0.195 | 24.905695 | 55.304923 | 94.883686 | Interm. step, due to the fast rxns: [0, 1] |
| 13 | 0.210 | 24.763522 | 54.597246 | 95.875709 | |
| 14 | 0.225 | 24.668171 | 53.997901 | 96.665757 | Interm. step, due to the fast rxns: [0, 1] |
| 15 | 0.240 | 24.607963 | 53.488049 | 97.296025 | |
| 16 | 0.255 | 24.573888 | 53.052446 | 97.799778 | Interm. step, due to the fast rxns: [1] |
| 17 | 0.270 | 24.539814 | 52.678715 | 98.241657 | |
| 18 | 0.285 | 24.542286 | 52.358506 | 98.556923 | Interm. step, due to the fast rxns: [1] |
| 19 | 0.300 | 24.544758 | 52.081302 | 98.829183 | |
| 20 | 0.315 | 24.564262 | 51.841298 | 99.030178 | Interm. step, due to the fast rxns: [1] |
| 21 | 0.330 | 24.583767 | 51.631939 | 99.200527 | |
| 22 | 0.360 | 24.635694 | 51.266237 | 99.462374 | |
| 23 | 0.390 | 24.690870 | 50.989928 | 99.628331 | |
| 24 | 0.420 | 24.742761 | 50.778291 | 99.736187 | |
| 25 | 0.450 | 24.788670 | 50.614455 | 99.808205 | |
| 26 | 0.480 | 24.827881 | 50.486592 | 99.857645 | |
| 27 | 0.510 | 24.860649 | 50.386193 | 99.892510 | |
| 28 | 0.510 | 70.000000 | 50.386193 | 99.892510 | Set concentration of `U` |
| 29 | 0.525 | 64.596775 | 50.346599 | 110.738553 | Interm. step, due to the fast rxns: [0, 1] |
| 30 | 0.540 | 60.167319 | 50.798640 | 119.145425 | |
| 31 | 0.555 | 56.521603 | 51.588307 | 125.647190 | Interm. step, due to the fast rxns: [0, 1] |
| 32 | 0.570 | 53.508427 | 52.599482 | 130.662367 | |
| 33 | 0.585 | 51.007286 | 53.745336 | 134.518794 | Interm. step, due to the fast rxns: [0, 1] |
| 34 | 0.600 | 48.921976 | 54.961601 | 137.473150 | |
| 35 | 0.615 | 47.175533 | 56.201349 | 139.726288 | Interm. step, due to the fast rxns: [0, 1] |
| 36 | 0.630 | 45.706258 | 57.430910 | 141.435277 | |
| 37 | 0.645 | 44.464565 | 58.626716 | 142.722857 | Interm. step, due to the fast rxns: [0, 1] |
| 38 | 0.660 | 43.410503 | 59.772840 | 143.684857 | |
| 39 | 0.675 | 42.511788 | 60.859103 | 144.396023 | Interm. step, due to the fast rxns: [0, 1] |
| 40 | 0.690 | 41.742255 | 61.879605 | 144.914589 | |
| 41 | 0.705 | 41.080622 | 62.831597 | 145.285863 | Interm. step, due to the fast rxns: [0, 1] |
| 42 | 0.720 | 40.509523 | 63.714617 | 145.545040 | |
| 43 | 0.735 | 40.014731 | 64.529828 | 145.719412 | Interm. step, due to the fast rxns: [0, 1] |
| 44 | 0.750 | 39.584546 | 65.279517 | 145.830094 | |
| 45 | 0.765 | 39.209303 | 65.966715 | 145.893382 | Interm. step, due to the fast rxns: [0, 1] |
| 46 | 0.780 | 38.880988 | 66.594913 | 145.921814 | |
| 47 | 0.795 | 38.592924 | 67.167852 | 145.925003 | Interm. step, due to the fast rxns: [0, 1] |
| 48 | 0.810 | 38.339523 | 67.689371 | 145.910286 | |
| 49 | 0.825 | 38.116089 | 68.163290 | 145.883235 | Interm. step, due to the fast rxns: [0, 1] |
| 50 | 0.840 | 37.918655 | 68.593340 | 145.848053 | |
| 51 | 0.855 | 37.743858 | 68.983101 | 145.807885 | Interm. step, due to the fast rxns: [0, 1] |
| 52 | 0.870 | 37.588832 | 69.335977 | 145.765062 | |
| 53 | 0.885 | 37.451124 | 69.655167 | 145.721288 | Interm. step, due to the fast rxns: [0, 1] |
| 54 | 0.900 | 37.328628 | 69.943660 | 145.677788 | |
| 55 | 0.915 | 37.219526 | 70.204231 | 145.635420 | Interm. step, due to the fast rxns: [1] |
| 56 | 0.930 | 37.110424 | 70.439444 | 145.618410 | |
| 57 | 0.960 | 36.941027 | 70.866001 | 145.530648 | |
| 58 | 0.990 | 36.807019 | 71.207879 | 145.456785 | |
| 59 | 1.020 | 36.700742 | 71.481572 | 145.395648 |
dynamics.explain_time_advance()
From time 0 to 0.33, in 22 substeps of 0.015 (each 1/2 of full step) From time 0.33 to 0.51, in 6 FULL steps of 0.03 From time 0.51 to 0.93, in 28 substeps of 0.015 (each 1/2 of full step) From time 0.93 to 1.02, in 3 FULL steps of 0.03 (for a grand total of 34 full steps)
dynamics.plot_curves(colors=['red', 'green', 'gray'])
# Verify that the reaction has reached equilibrium
dynamics.is_in_equilibrium(tolerance=2)
U <-> 2 D
Final concentrations: [D] = 145.4 ; [U] = 36.7
1. Ratio of reactant/product concentrations, adjusted for reaction orders: 3.96165
Formula used: [D] / [U]
2. Ratio of forward/reverse reaction rates: 4.0
Discrepancy between the two values: 0.9586 %
Reaction IS in equilibrium (within 2% tolerance)
X <-> D
Final concentrations: [D] = 145.4 ; [X] = 71.48
1. Ratio of reactant/product concentrations, adjusted for reaction orders: 2.03403
Formula used: [D] / [X]
2. Ratio of forward/reverse reaction rates: 2.0
Discrepancy between the two values: 1.701 %
Reaction IS in equilibrium (within 2% tolerance)
True
dynamics.set_chem_conc(species_name="U", conc=100., snapshot=True)
dynamics.describe_state()
SYSTEM STATE at Time t = 1.02: 3 species: Species 0 (U). Conc: 100.0 Species 1 (X). Conc: 71.48157153405576 Species 2 (D). Conc: 145.39564765746923
dynamics.get_history(tail=3)
| SYSTEM TIME | U | X | D | caption | |
|---|---|---|---|---|---|
| 58 | 0.99 | 36.807019 | 71.207879 | 145.456785 | |
| 59 | 1.02 | 36.700742 | 71.481572 | 145.395648 | |
| 60 | 1.02 | 100.000000 | 71.481572 | 145.395648 | Set concentration of `U` |
dynamics.single_compartment_react(time_step=0.03, stop_time=1.6,
dynamic_substeps=2, rel_fast_threshold=120)
df = dynamics.history.get()
df
single_compartment_react(): setting abs_fast_threshold to 40.0 20 total step(s) taken
| SYSTEM TIME | U | X | D | caption | |
|---|---|---|---|---|---|
| 0 | 0.015 | 44.000000 | 91.000000 | 21.000000 | Interm. step, due to the fast rxns: [0, 1] |
| 1 | 0.030 | 39.350000 | 83.755000 | 37.545000 | |
| 2 | 0.045 | 35.754350 | 77.906575 | 50.584725 | Interm. step, due to the fast rxns: [0, 1] |
| 3 | 0.060 | 32.981370 | 73.171296 | 60.865965 | |
| 4 | 0.075 | 30.849584 | 69.324848 | 68.975984 | Interm. step, due to the fast rxns: [0, 1] |
| ... | ... | ... | ... | ... | ... |
| 88 | 1.500 | 52.843169 | 102.307495 | 208.883386 | |
| 89 | 1.530 | 52.693812 | 102.691651 | 208.797945 | |
| 90 | 1.560 | 52.575174 | 102.998969 | 208.727903 | |
| 91 | 1.590 | 52.480806 | 103.244666 | 208.670941 | |
| 92 | 1.620 | 52.405669 | 103.441011 | 208.624870 |
93 rows × 5 columns
dynamics.explain_time_advance()
From time 0 to 0.33, in 22 substeps of 0.015 (each 1/2 of full step) From time 0.33 to 0.51, in 6 FULL steps of 0.03 From time 0.51 to 0.93, in 28 substeps of 0.015 (each 1/2 of full step) From time 0.93 to 1.02, in 3 FULL steps of 0.03 From time 1.02 to 1.38, in 24 substeps of 0.015 (each 1/2 of full step) From time 1.38 to 1.62, in 8 FULL steps of 0.03 (for a grand total of 54 full steps)
dynamics.plot_curves(colors=['red', 'green', 'gray'])
# Verify that the reaction has reached equilibrium
dynamics.is_in_equilibrium(explain=False)
True
dynamics.set_chem_conc(species_name="U", conc=5., snapshot=True)
dynamics.describe_state()
SYSTEM STATE at Time t = 1.62: 3 species: Species 0 (U). Conc: 5.0 Species 1 (X). Conc: 103.44101051057498 Species 2 (D). Conc: 208.62487039926754
dynamics.get_history(tail=3)
| SYSTEM TIME | U | X | D | caption | |
|---|---|---|---|---|---|
| 91 | 1.59 | 52.480806 | 103.244666 | 208.670941 | |
| 92 | 1.62 | 52.405669 | 103.441011 | 208.624870 | |
| 93 | 1.62 | 5.000000 | 103.441011 | 208.624870 | Set concentration of `U` |
dynamics.single_compartment_react(time_step=0.03, stop_time=2.3,
dynamic_substeps=2, rel_fast_threshold=80)
df = dynamics.history.get()
df
single_compartment_react(): setting abs_fast_threshold to 26.666666666666668 23 total step(s) taken
| SYSTEM TIME | U | X | D | caption | |
|---|---|---|---|---|---|
| 0 | 0.015 | 44.000000 | 91.000000 | 21.000000 | Interm. step, due to the fast rxns: [0, 1] |
| 1 | 0.030 | 39.350000 | 83.755000 | 37.545000 | |
| 2 | 0.045 | 35.754350 | 77.906575 | 50.584725 | Interm. step, due to the fast rxns: [0, 1] |
| 3 | 0.060 | 32.981370 | 73.171296 | 60.865965 | |
| 4 | 0.075 | 30.849584 | 69.324848 | 68.975984 | Interm. step, due to the fast rxns: [0, 1] |
| ... | ... | ... | ... | ... | ... |
| 124 | 2.190 | 39.988395 | 81.223853 | 160.865238 | |
| 125 | 2.220 | 40.043094 | 81.081431 | 160.898261 | |
| 126 | 2.250 | 40.086647 | 80.967617 | 160.924969 | |
| 127 | 2.280 | 40.121350 | 80.876693 | 160.946487 | |
| 128 | 2.310 | 40.149015 | 80.804072 | 160.963778 |
129 rows × 5 columns
dynamics.explain_time_advance()
From time 0 to 0.33, in 22 substeps of 0.015 (each 1/2 of full step) From time 0.33 to 0.51, in 6 FULL steps of 0.03 From time 0.51 to 0.93, in 28 substeps of 0.015 (each 1/2 of full step) From time 0.93 to 1.02, in 3 FULL steps of 0.03 From time 1.02 to 1.38, in 24 substeps of 0.015 (each 1/2 of full step) From time 1.38 to 1.62, in 8 FULL steps of 0.03 From time 1.62 to 1.98, in 24 substeps of 0.015 (each 1/2 of full step) From time 1.98 to 2.31, in 11 FULL steps of 0.03 (for a grand total of 77 full steps)
dynamics.plot_curves(colors=['red', 'green', 'gray'])
# Verify that the reaction has reached equilibrium
dynamics.is_in_equilibrium(explain=False)
True