Skip to content

Commit 33afa7a

Browse files
authored
Merge pull request #59 from BrainAnnex/dev
Dev Beta 29
2 parents 3760aae + ecbc885 commit 33afa7a

39 files changed

+17694
-3301
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### BETA 28.2 (v0.28.2)
1+
### BETA 29 (v0.29.0)
22

33

44

experiments/reactions_single_compartment/down_regulate_2.ipynb

Lines changed: 22 additions & 21 deletions
Large diffs are not rendered by default.

experiments/reactions_single_compartment/down_regulate_2.log.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
el: '#vue-root-1',
4040

4141
data: {
42-
graph_json: [{"id": 3, "label": "Reaction", "name": "RXN", "kF": "8", "kR": "2", "Delta_G": "-3,436.56", "K": "4"}, {"id": 2, "label": "Chemical", "name": "Y", "diff_rate": null, "stoich": 1, "rxn_order": 1}, {"id": 4, "source": 3, "target": 2, "name": "produces"}, {"id": 0, "label": "Chemical", "name": "A", "diff_rate": null, "stoich": 1, "rxn_order": 1}, {"id": 5, "source": 0, "target": 3, "name": "reacts"}, {"id": 1, "label": "Chemical", "name": "B", "diff_rate": null, "stoich": 2, "rxn_order": 1}, {"id": 6, "source": 1, "target": 3, "name": "reacts"}],
42+
graph_json: [{"id": 3, "label": "Reaction", "name": "RXN", "kF": "8", "kR": "2", "delta_G": "-3,436.56", "K": "4"}, {"id": 2, "label": "Chemical", "name": "Y", "diff_rate": null, "stoich": 1, "rxn_order": 1}, {"id": 4, "source": 3, "target": 2, "name": "produces"}, {"id": 0, "label": "Chemical", "name": "A", "diff_rate": null, "stoich": 1, "rxn_order": 1}, {"id": 5, "source": 0, "target": 3, "name": "reacts"}, {"id": 1, "label": "Chemical", "name": "B", "diff_rate": null, "stoich": 2, "rxn_order": 1}, {"id": 6, "source": 1, "target": 3, "name": "reacts"}],
4343
color_mapping_json: {"Chemical": "neo4j_green", "Reaction": "neo4j_lightbrown"},
4444
component_id_json: 1
4545
}

experiments/reactions_single_compartment/down_regulate_2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#
2222
# See also 1D/reactions/down_regulation_1
2323
#
24-
# LAST REVISED: July 14, 2023
24+
# LAST REVISED: Nov. 4, 2023
2525

2626
# %%
2727
import set_path # Importing this module will add the project's home directory to sys.path
@@ -109,7 +109,7 @@
109109
# # 2. Now, let's suddenly increase [A]
110110

111111
# %%
112-
dynamics.set_chem_conc(species_name="A", conc=40., snapshot=True)
112+
dynamics.set_single_conc(species_name="A", conc=40., snapshot=True)
113113
dynamics.describe_state()
114114

115115
# %%
@@ -143,7 +143,7 @@
143143
# # 3. Let's again suddenly increase [A]
144144

145145
# %%
146-
dynamics.set_chem_conc(species_name="A", conc=30., snapshot=True)
146+
dynamics.set_single_conc(species_name="A", conc=30., snapshot=True)
147147
dynamics.describe_state()
148148

149149
# %%
@@ -178,7 +178,7 @@
178178
# Let's try it:
179179

180180
# %%
181-
dynamics.set_chem_conc(species_name="A", conc=0., snapshot=True) # Completely eliminate A
181+
dynamics.set_single_conc(species_name="A", conc=0., snapshot=True) # Completely eliminate A
182182
dynamics.describe_state()
183183

184184
# %%

experiments/reactions_single_compartment/enzyme_1.ipynb

Lines changed: 357 additions & 321 deletions
Large diffs are not rendered by default.

experiments/reactions_single_compartment/enzyme_1.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
# ---
1515

1616
# %% [markdown]
17-
# ## Comparing the reaction `A <-> B` with and without an enzyme
17+
# ## Comparing the reaction `A <-> B` , with and without an enzyme
1818
#
19-
# LAST REVISED: July 14, 2023
19+
# LAST REVISED: Nov. 3, 2023
2020

2121
# %%
2222
import set_path # Importing this module will add the project's home directory to sys.path
@@ -33,7 +33,8 @@
3333
# Initialize the system
3434
chem_data = ChemData(names=["A", "B"])
3535

36-
# Reaction A <-> B , with 1st-order kinetics, and a forward rate that is slower than it would be with the enzyme of part 2
36+
# Reaction A <-> B , with 1st-order kinetics, favorable thermodynamics in the forward direction,
37+
# and a forward rate that is much slower than it would be with the enzyme - as seen in part 2, below
3738
chem_data.add_reaction(reactants="A", products="B",
3839
forward_rate=1., delta_G=-3989.73)
3940

@@ -60,8 +61,8 @@
6061
dynamics.set_step_factors(upshift=1.5, downshift=0.5, abort=0.5)
6162
dynamics.set_error_step_factor(0.5)
6263

63-
dynamics.single_compartment_react(initial_step=0.1, reaction_duration=3.0,
64-
variable_steps=True, explain_variable_steps=False)
64+
dynamics.single_compartment_react(reaction_duration=3.0,
65+
initial_step=0.1, variable_steps=True, explain_variable_steps=False)
6566

6667
# %%
6768
#dynamics.explain_time_advance()
@@ -70,7 +71,7 @@
7071
dynamics.plot_curves(colors=['darkorange', 'green'], show_intervals=True, title_prefix="WITHOUT enzyme")
7172

7273
# %% [markdown]
73-
# #### Note how the time steps get automatically adjusted, as needed by the amount of change - include a complete step abort/redo at time=0
74+
# #### Note how the time steps get automatically adjusted, as needed by the amount of change - including a complete step abort/redo at time=0
7475

7576
# %%
7677
dynamics.curve_intersection("A", "B", t_start=0, t_end=1.0)
@@ -86,7 +87,7 @@
8687
# ### `A` + `E` <-> `B` + `E`
8788

8889
# %% [markdown]
89-
# ### Note: for the sake of the demo, we'll completely ignore the concomitant reaction A <-> B
90+
# ### Note: for the sake of the demo, we'll completely ignore the concomitant (much slower) direct reaction A <-> B
9091
# This in an approximation that we'll drop in later experiments
9192

9293
# %%
@@ -101,10 +102,10 @@
101102
chem_data.describe_reactions() # Notice how the enzyme `E` is noted in the printout below
102103

103104
# %% [markdown]
104-
# ### Notice how, while the ratio kF/kR is the same as it was without the enzyme (since it's dictated by the energy difference), the individual values of kF and kR are now each 10 times bigger
105+
# ### Notice how, while the ratio kF/kR is the same as it was without the enzyme (since it's dictated by the energy difference), the individual values of kF and kR now are each 10 times bigger than before
105106

106107
# %% [markdown]
107-
# ### Set the initial concentrations of all the chemicals
108+
# ### Set the initial concentrations of all the chemicals (to what they originally were)
108109

109110
# %%
110111
dynamics = ReactionDynamics(chem_data=chem_data)
@@ -124,8 +125,8 @@
124125
dynamics.set_step_factors(upshift=1.2, downshift=0.5, abort=0.4)
125126
dynamics.set_error_step_factor(0.25)
126127

127-
dynamics.single_compartment_react(initial_step=0.1, reaction_duration=0.1,
128-
variable_steps=True, explain_variable_steps=False)
128+
dynamics.single_compartment_react(reaction_duration=0.1,
129+
initial_step=0.1, variable_steps=True, explain_variable_steps=False)
129130

130131
# %% [markdown]
131132
# #### Note how the (proposed) initial step - kept the same as the previous run - is now _extravagantly large_, given the much-faster reaction dynamics. However, the variable-step engine intercepts and automatically corrects the problem!

experiments/reactions_single_compartment/enzyme_2.ipynb

Lines changed: 3845 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# ---
2+
# jupyter:
3+
# jupytext:
4+
# formats: ipynb,py:percent
5+
# text_representation:
6+
# extension: .py
7+
# format_name: percent
8+
# format_version: '1.3'
9+
# jupytext_version: 1.14.1
10+
# kernelspec:
11+
# display_name: Python 3 (ipykernel)
12+
# language: python
13+
# name: python3
14+
# ---
15+
16+
# %% [markdown]
17+
# ## Coupled pair of reactions: `A <-> B` , and `A` + `E` <-> `B` + `E`
18+
# A direct reaction and same reaction, catalyzed
19+
# ### Enzyme `E` initially zero, and then suddenly added mid-reaction
20+
#
21+
# LAST REVISED: Nov. 4, 2023
22+
23+
# %%
24+
import set_path # Importing this module will add the project's home directory to sys.path
25+
26+
# %% tags=[]
27+
from src.modules.chemicals.chem_data import ChemData
28+
from src.modules.reactions.reaction_dynamics import ReactionDynamics
29+
30+
# %%
31+
# Initialize the system
32+
chem_data = ChemData(names=["A", "B", "E"])
33+
34+
# Reaction A <-> B , with 1st-order kinetics, favorable thermodynamics in the forward direction,
35+
# and a forward rate that is much slower than it would be with the enzyme - as seen in the next reaction, below
36+
chem_data.add_reaction(reactants="A", products="B",
37+
forward_rate=1., delta_G=-3989.73)
38+
39+
# Reaction A + E <-> B + E , with 1st-order kinetics, and a forward rate that is faster than it was without the enzyme
40+
# Thermodynamically, there's no change from the reaction without the enzyme
41+
chem_data.add_reaction(reactants=["A", "E"], products=["B", "E"],
42+
forward_rate=10., delta_G=-3989.73)
43+
44+
chem_data.describe_reactions() # Notice how the enzyme `E` is noted in the printout below
45+
46+
# %% [markdown]
47+
# ### Set the initial concentrations of all the chemicals - starting with no enzyme
48+
49+
# %%
50+
dynamics = ReactionDynamics(chem_data=chem_data)
51+
dynamics.set_conc(conc={"A": 20., "B": 0., "E": 0.},
52+
snapshot=True) # Initially, no enzyme `E`
53+
dynamics.describe_state()
54+
55+
# %% [markdown] tags=[]
56+
# ### Advance the reactions (for now without enzyme), but stopping well before equilibrium
57+
58+
# %%
59+
dynamics.set_diagnostics() # To save diagnostic information about the call to single_compartment_react()
60+
61+
# All of these settings are currently close to the default values... but subject to change; set for repeatability
62+
dynamics.set_thresholds(norm="norm_A", low=0.5, high=0.8, abort=1.44)
63+
dynamics.set_thresholds(norm="norm_B", low=0.08, high=0.5, abort=1.5)
64+
dynamics.set_step_factors(upshift=1.2, downshift=0.5, abort=0.4)
65+
dynamics.set_error_step_factor(0.25)
66+
67+
# Perform the reactions
68+
dynamics.single_compartment_react(reaction_duration=0.25,
69+
initial_step=0.05, variable_steps=True, explain_variable_steps=False)
70+
71+
# %%
72+
#dynamics.explain_time_advance()
73+
74+
# %%
75+
dynamics.plot_curves(colors=['darkorange', 'green', 'violet'], show_intervals=True, title_prefix="WITH zero enzyme")
76+
77+
# %% [markdown]
78+
# ### The reactions, lacking enzyme, are proceeding slowly towards equilibrium, like reaction that was discussed in part 1 of the experiment "enzyme_1"
79+
80+
# %% [markdown]
81+
# # Now suddently add a lot of enzyme
82+
83+
# %%
84+
dynamics.set_single_conc(30., species_name="E", snapshot=True) # Plenty of enzyme `E`
85+
86+
# %%
87+
dynamics.describe_state()
88+
89+
# %% [markdown] tags=[]
90+
# ### Take the system to equilibrium
91+
92+
# %%
93+
dynamics.single_compartment_react(reaction_duration=0.04,
94+
initial_step=0.005, variable_steps=True, explain_variable_steps=False)
95+
96+
# %% [markdown]
97+
# #### Note how the (proposed) initial step - in spite of having been reduced from the earlier run - is now appearing _large_, given the much-faster reaction dynamics. However, the variable-step engine intercepts and automatically corrects the problem!
98+
99+
# %%
100+
#dynamics.explain_time_advance()
101+
102+
# %%
103+
dynamics.plot_curves(colors=['darkorange', 'green', 'violet'], show_intervals=True, title_prefix="WITH enzyme added mid-reaction")
104+
105+
# %% [markdown]
106+
# ## Notice the dramatic acceleration of the reaction as soon as the enzyme `E` is added at t = 0.275!
107+
# The reactions simulator automatically switches to small time steps is in order to handle the rapid amount of change
108+
109+
# %%
110+
# Verify that the reaction has reached equilibrium
111+
dynamics.is_in_equilibrium()
112+
113+
# %%
114+
dynamics.get_history()
115+
116+
# %%

experiments/reactions_single_compartment/macromolecules_1.ipynb

Lines changed: 22 additions & 20 deletions
Large diffs are not rendered by default.

experiments/reactions_single_compartment/macromolecules_1.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# %% [markdown]
1717
# ## Macromolecules : Binding Affinity and Fractional Occupancy
1818
#
19-
# LAST REVISED: July 14, 2023
19+
# LAST REVISED: Nov. 4, 2023
2020

2121
# %%
2222
import set_path # Importing this module will add the project's home directory to sys.path
@@ -51,7 +51,7 @@
5151
chem.set_binding_site_affinity("M2", site_number=2, ligand="A", Kd=0.01)
5252

5353
# %%
54-
chem.show_binding_affinities() # Review the values we have given for the binding affinities
54+
chem.show_binding_affinities() # Review the values we have given for the dissociation constants
5555

5656
# %%
5757
chem.get_binding_sites("M1")
@@ -135,7 +135,7 @@
135135
# ### Adjust the concentration of one ligand, [A], and update all the fractional occupancies accordingly
136136

137137
# %%
138-
dynamics.set_chem_conc(conc=1000., species_name="A", snapshot=False)
138+
dynamics.set_single_conc(conc=1000., species_name="A", snapshot=False)
139139

140140
# %%
141141
dynamics.update_occupancy()
@@ -171,7 +171,7 @@
171171
# %%
172172
# Set [A] to each of the above values in turn, and determine/store the applicable fractional occupancies (for the sites where A binds)
173173
for A_conc in log_values:
174-
dynamics.set_chem_conc(conc=A_conc, species_name="A", snapshot=False)
174+
dynamics.set_single_conc(conc=A_conc, species_name="A", snapshot=False)
175175
dynamics.update_occupancy()
176176
history.store(A_conc, {"M1 site 3": dynamics.get_occupancy(macromolecule="M1", site_number=3),
177177
"M1 site 15": dynamics.get_occupancy(macromolecule="M1", site_number=15),

0 commit comments

Comments
 (0)