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: May 26, 2023
import set_path # Importing this module will add the project's home directory to sys.path
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()
# All of these settings are currently close to the default values... but subject to change; set for repeatability
dynamics.set_thresholds(norm="norm_A", low=0.5, high=0.8, abort=1.44)
dynamics.set_thresholds(norm="norm_B", low=0.08, high=0.5, abort=1.5)
dynamics.set_step_factors(upshift=1.5, downshift=0.5, abort=0.5)
dynamics.set_error_step_factor(0.5)
dynamics.single_compartment_react(initial_step=0.03, target_end_time=0.5,
variable_steps=True, explain_variable_steps=False)
dynamics.get_history()
INFO: the tentative time step (0.03) leads to a least one norm value > its ABORT threshold:
-> will backtrack, and re-do step with a SMALLER delta time, multiplied by 0.5 (set to 0.015) [Step started at t=0, and will rewind there]
INFO: the tentative time step (0.015) leads to a least one norm value > its ABORT threshold:
-> will backtrack, and re-do step with a SMALLER delta time, multiplied by 0.5 (set to 0.0075) [Step started at t=0, and will rewind there]
INFO: the tentative time step (0.0075) leads to a least one norm value > its ABORT threshold:
-> will backtrack, and re-do step with a SMALLER delta time, multiplied by 0.5 (set to 0.00375) [Step started at t=0, and will rewind there]
INFO: the tentative time step (0.00375) leads to a least one norm value > its ABORT threshold:
-> will backtrack, and re-do step with a SMALLER delta time, multiplied by 0.5 (set to 0.001875) [Step started at t=0, and will rewind there]
Some steps were backtracked and re-done, to prevent negative concentrations or excessively large concentration changes
60 total step(s) taken
| SYSTEM TIME | U | X | D | caption | |
|---|---|---|---|---|---|
| 0 | 0.000000 | 50.000000 | 100.000000 | 0.000000 | Initial state |
| 1 | 0.001875 | 49.250000 | 98.875000 | 2.625000 | |
| 2 | 0.002812 | 48.885547 | 98.326211 | 3.902695 | |
| 3 | 0.003750 | 48.526223 | 97.784102 | 5.163452 | |
| 4 | 0.004687 | 48.171958 | 97.248589 | 6.407496 | |
| ... | ... | ... | ... | ... | ... |
| 56 | 0.245706 | 24.643947 | 53.475305 | 97.236801 | |
| 57 | 0.282239 | 24.546114 | 52.410700 | 98.497071 | |
| 58 | 0.337037 | 24.580376 | 51.371008 | 99.468240 | |
| 59 | 0.419235 | 24.768894 | 50.563716 | 99.898495 | |
| 60 | 0.542532 | 24.971820 | 50.109144 | 99.947215 |
61 rows × 5 columns
dynamics.explain_time_advance()
From time 0 to 0.001875, in 1 step of 0.00187 From time 0.001875 to 0.01219, in 11 steps of 0.000938 From time 0.01219 to 0.01781, in 4 steps of 0.00141 From time 0.01781 to 0.03469, in 8 steps of 0.00211 From time 0.03469 to 0.03785, in 1 step of 0.00316 From time 0.03785 to 0.03943, in 1 step of 0.00158 From time 0.03943 to 0.04418, in 2 steps of 0.00237 From time 0.04418 to 0.04774, in 1 step of 0.00356 From time 0.04774 to 0.04952, in 1 step of 0.00178 From time 0.04952 to 0.05219, in 1 step of 0.00267 From time 0.05219 to 0.05619, in 1 step of 0.004 From time 0.05619 to 0.0582, in 1 step of 0.002 From time 0.0582 to 0.0612, in 1 step of 0.003 From time 0.0612 to 0.0657, in 1 step of 0.00451 From time 0.0657 to 0.06796, in 1 step of 0.00225 From time 0.06796 to 0.07134, in 1 step of 0.00338 From time 0.07134 to 0.0764, in 1 step of 0.00507 From time 0.0764 to 0.07894, in 1 step of 0.00253 From time 0.07894 to 0.08274, in 1 step of 0.0038 From time 0.08274 to 0.08844, in 1 step of 0.0057 From time 0.08844 to 0.09129, in 1 step of 0.00285 From time 0.09129 to 0.09557, in 1 step of 0.00428 From time 0.09557 to 0.1212, in 4 steps of 0.00641 From time 0.1212 to 0.1308, in 1 step of 0.00962 From time 0.1308 to 0.1357, in 1 step of 0.00481 From time 0.1357 to 0.1429, in 1 step of 0.00722 From time 0.1429 to 0.1645, in 2 steps of 0.0108 From time 0.1645 to 0.197, in 2 steps of 0.0162 From time 0.197 to 0.2457, in 2 steps of 0.0244 From time 0.2457 to 0.2822, in 1 step of 0.0365 From time 0.2822 to 0.337, in 1 step of 0.0548 From time 0.337 to 0.4192, in 1 step of 0.0822 From time 0.4192 to 0.5425, in 1 step of 0.123 (60 steps total)
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.95 ; [U] = 24.97
1. Ratio of reactant/product concentrations, adjusted for reaction orders: 4.0024
Formula used: [D] / [U]
2. Ratio of forward/reverse reaction rates: 4.0
Discrepancy between the two values: 0.06 %
Reaction IS in equilibrium (within 1% tolerance)
X <-> D
Final concentrations: [D] = 99.95 ; [X] = 50.11
1. Ratio of reactant/product concentrations, adjusted for reaction orders: 1.99459
Formula used: [D] / [X]
2. Ratio of forward/reverse reaction rates: 2.0
Discrepancy between the two values: 0.2705 %
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.54253165: 3 species: Species 0 (U). Conc: 70.0 Species 1 (X). Conc: 50.10914435037049 Species 2 (D). Conc: 99.94721484673187
dynamics.get_history(tail=3)
| SYSTEM TIME | U | X | D | caption | |
|---|---|---|---|---|---|
| 59 | 0.419235 | 24.768894 | 50.563716 | 99.898495 | |
| 60 | 0.542532 | 24.971820 | 50.109144 | 99.947215 | |
| 61 | 0.542532 | 70.000000 | 50.109144 | 99.947215 | Set concentration of `U` |
dynamics.single_compartment_react(initial_step=0.03, target_end_time=1,
variable_steps=True, explain_variable_steps=False)
INFO: the tentative time step (0.03) leads to a least one norm value > its ABORT threshold:
-> will backtrack, and re-do step with a SMALLER delta time, multiplied by 0.5 (set to 0.015) [Step started at t=0.54253, and will rewind there]
INFO: the tentative time step (0.015) leads to a least one norm value > its ABORT threshold:
-> will backtrack, and re-do step with a SMALLER delta time, multiplied by 0.5 (set to 0.0075) [Step started at t=0.54253, and will rewind there]
INFO: the tentative time step (0.0075) leads to a least one norm value > its ABORT threshold:
-> will backtrack, and re-do step with a SMALLER delta time, multiplied by 0.5 (set to 0.00375) [Step started at t=0.54253, and will rewind there]
Some steps were backtracked and re-done, to prevent negative concentrations or excessively large concentration changes
32 total step(s) taken
#dynamics.get_history()
#dynamics.explain_time_advance()
dynamics.plot_curves(colors=['red', 'green', 'gray'])
# Verify that the reaction has reached equilibrium
dynamics.is_in_equilibrium()
U <-> 2 D
Final concentrations: [D] = 145.1 ; [U] = 36.37
1. Ratio of reactant/product concentrations, adjusted for reaction orders: 3.98913
Formula used: [D] / [U]
2. Ratio of forward/reverse reaction rates: 4.0
Discrepancy between the two values: 0.2717 %
Reaction IS in equilibrium (within 1% tolerance)
X <-> D
Final concentrations: [D] = 145.1 ; [X] = 72.21
1. Ratio of reactant/product concentrations, adjusted for reaction orders: 2.00937
Formula used: [D] / [X]
2. Ratio of forward/reverse reaction rates: 2.0
Discrepancy between the two values: 0.4683 %
Reaction IS in equilibrium (within 1% tolerance)
True
dynamics.set_chem_conc(species_name="U", conc=100., snapshot=True)
dynamics.describe_state()
SYSTEM STATE at Time t = 1.0973722: 3 species: Species 0 (U). Conc: 100.0 Species 1 (X). Conc: 72.21103524746438 Species 2 (D). Conc: 145.09842911303875
dynamics.get_history(tail=3)
| SYSTEM TIME | U | X | D | caption | |
|---|---|---|---|---|---|
| 92 | 0.981912 | 36.771516 | 71.151097 | 145.362231 | |
| 93 | 1.097372 | 36.373447 | 72.211035 | 145.098429 | |
| 94 | 1.097372 | 100.000000 | 72.211035 | 145.098429 | Set concentration of `U` |
dynamics.single_compartment_react(initial_step=0.03, target_end_time=1.6,
variable_steps=True, explain_variable_steps=False)
INFO: the tentative time step (0.03) leads to a least one norm value > its ABORT threshold:
-> will backtrack, and re-do step with a SMALLER delta time, multiplied by 0.5 (set to 0.015) [Step started at t=1.0974, and will rewind there]
INFO: the tentative time step (0.015) leads to a least one norm value > its ABORT threshold:
-> will backtrack, and re-do step with a SMALLER delta time, multiplied by 0.5 (set to 0.0075) [Step started at t=1.0974, and will rewind there]
INFO: the tentative time step (0.0075) leads to a least one norm value > its ABORT threshold:
-> will backtrack, and re-do step with a SMALLER delta time, multiplied by 0.5 (set to 0.00375) [Step started at t=1.0974, and will rewind there]
INFO: the tentative time step (0.00375) leads to a least one norm value > its ABORT threshold:
-> will backtrack, and re-do step with a SMALLER delta time, multiplied by 0.5 (set to 0.001875) [Step started at t=1.0974, and will rewind there]
Some steps were backtracked and re-done, to prevent negative concentrations or excessively large concentration changes
45 total step(s) taken
#dynamics.get_history()
#dynamics.explain_time_advance()
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] = 208.9 ; [U] = 52.56
1. Ratio of reactant/product concentrations, adjusted for reaction orders: 3.97443
Formula used: [D] / [U]
2. Ratio of forward/reverse reaction rates: 4.0
Discrepancy between the two values: 0.6392 %
Reaction IS in equilibrium (within 2% tolerance)
X <-> D
Final concentrations: [D] = 208.9 ; [X] = 103.3
1. Ratio of reactant/product concentrations, adjusted for reaction orders: 2.02304
Formula used: [D] / [X]
2. Ratio of forward/reverse reaction rates: 2.0
Discrepancy between the two values: 1.152 %
Reaction IS in equilibrium (within 2% tolerance)
True
dynamics.set_chem_conc(species_name="U", conc=5., snapshot=True)
dynamics.describe_state()
SYSTEM STATE at Time t = 1.6127957: 3 species: Species 0 (U). Conc: 5.0 Species 1 (X). Conc: 103.26703387633307 Species 2 (D). Conc: 208.9136350590719
dynamics.get_history(tail=3)
| SYSTEM TIME | U | X | D | caption | |
|---|---|---|---|---|---|
| 138 | 1.530598 | 53.067054 | 101.964742 | 209.210614 | |
| 139 | 1.612796 | 52.564398 | 103.267034 | 208.913635 | |
| 140 | 1.612796 | 5.000000 | 103.267034 | 208.913635 | Set concentration of `U` |
dynamics.single_compartment_react(initial_step=0.03, target_end_time=2.3,
variable_steps=True, explain_variable_steps=False)
INFO: the tentative time step (0.03) leads to a least one norm value > its ABORT threshold:
-> will backtrack, and re-do step with a SMALLER delta time, multiplied by 0.5 (set to 0.015) [Step started at t=1.6128, and will rewind there]
INFO: the tentative time step (0.015) leads to a least one norm value > its ABORT threshold:
-> will backtrack, and re-do step with a SMALLER delta time, multiplied by 0.5 (set to 0.0075) [Step started at t=1.6128, and will rewind there]
INFO: the tentative time step (0.0075) leads to a least one norm value > its ABORT threshold:
-> will backtrack, and re-do step with a SMALLER delta time, multiplied by 0.5 (set to 0.00375) [Step started at t=1.6128, and will rewind there]
Some steps were backtracked and re-done, to prevent negative concentrations or excessively large concentration changes
37 total step(s) taken
#dynamics.get_history()
#dynamics.explain_time_advance()
dynamics.plot_curves(colors=['red', 'green', 'gray'])
# Verify that the reaction has reached equilibrium
dynamics.is_in_equilibrium(explain=False)
True