The system starts out with a "concentration pulse" in just one bin - i.e. that bin is initially the only one with a non-zero concentration of the only chemical species. Then the system is left undisturbed, and followed to equilibrium.
(Note: this is the 2D counterpart of the 1D experiment by the same name)
LAST REVISED: Nov. 28, 2022
# Extend the sys.path variable, to contain the project's root directory
import set_path
set_path.add_ancestor_dir_to_syspath(3) # 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.life_2D.bio_sim_2d import BioSim2D
import plotly.express as px
import plotly.graph_objects as go
from src.modules.reactions.reaction_data import ReactionData as chem
# Prepare the initial system, with a single non-zero bin, near the left edge of the system, positioned halfway vertically
chem_data = chem(names=["A"], diffusion_rates=[0.02])
bio = BioSim2D(n_bins=(5, 8), chem_data=chem_data)
bio.inject_conc_to_bin(bin_address=(2, 1), species_index=0, delta_conc=10.)
bio.describe_state()
SYSTEM STATE at Time t = 0:
Species `A`:
0 1 2 3 4 5 6 7
0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
2 0.0 10.0 0.0 0.0 0.0 0.0 0.0 0.0
3 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
bio.system_snapshot()
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |
|---|---|---|---|---|---|---|---|---|
| 0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 1 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 2 | 0.0 | 10.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 3 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 4 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
fig = px.imshow(bio.system_snapshot(),
title= f"Diffusion. System snapshot as a heatmap at time t={bio.system_time}",
labels=dict(x="x (col. number)", y="y (row number)", color="Concentration"),
text_auto=True, color_continuous_scale="gray_r") # text_auto=’.2f’
fig.data[0].xgap=2
fig.data[0].ygap=2
fig.show()
delta_time = 10.
status = bio.diffuse(total_duration=delta_time, time_step=0.1)
print("\n", status)
bio.describe_state()
{'steps': 100}
SYSTEM STATE at Time t = 9.99999999999998:
Species `A`:
0 1 2 3 4 5 6 \
0 0.021467 0.101184 0.019573 0.001899 0.000122 0.000006 2.203662e-07
1 0.205745 0.959044 0.187423 0.018382 0.001194 0.000058 2.203531e-06
2 1.052394 4.856162 0.957855 0.094854 0.006221 0.000303 1.171495e-05
3 0.205745 0.959044 0.187423 0.018382 0.001194 0.000058 2.203531e-06
4 0.021467 0.101184 0.019573 0.001899 0.000122 0.000006 2.203662e-07
7
0 7.055683e-09
1 7.136569e-08
2 3.834040e-07
3 7.136569e-08
4 7.055683e-09
fig = px.imshow(bio.system_snapshot(),
title= f"Diffusion. System snapshot as a heatmap at time t={bio.system_time}",
labels=dict(x="x (col. number)", y="y (row number)", color="Concentration"),
text_auto='.2f', color_continuous_scale="gray_r")
fig.data[0].xgap=2
fig.data[0].ygap=2
fig.show()
for i in range(200):
status = bio.diffuse(total_duration=delta_time, time_step=0.1)
if i<2 or i==6 or i>=199:
bio.describe_state()
fig = px.imshow(bio.system_snapshot(),
title= f"Diffusion. System snapshot as a heatmap at time t={bio.system_time}",
labels=dict(x="x (col. number)", y="y (row number)", color="Concentration"),
text_auto='.2f', color_continuous_scale="gray_r")
fig.data[0].xgap=2
fig.data[0].ygap=2
fig.show()
SYSTEM STATE at Time t = 20.000000000000014:
Species `A`:
0 1 2 3 4 5 6 \
0 0.099450 0.227366 0.083545 0.016125 0.002093 0.000204 0.000016
1 0.454281 1.033156 0.381327 0.073972 0.009652 0.000945 0.000074
2 1.220265 2.763366 1.023643 0.199392 0.026127 0.002569 0.000202
3 0.454281 1.033156 0.381327 0.073972 0.009652 0.000945 0.000074
4 0.099450 0.227366 0.083545 0.016125 0.002093 0.000204 0.000016
7
0 0.000001
1 0.000005
2 0.000014
3 0.000005
4 0.000001
SYSTEM STATE at Time t = 30.000000000000156:
Species `A`:
0 1 2 3 4 5 6 \
0 0.201446 0.315009 0.158323 0.044518 0.008576 0.001250 0.000146
1 0.600798 0.936757 0.471904 0.133094 0.025724 0.003763 0.000442
2 1.161444 1.807104 0.911874 0.257745 0.049932 0.007322 0.000862
3 0.600798 0.936757 0.471904 0.133094 0.025724 0.003763 0.000442
4 0.201446 0.315009 0.158323 0.044518 0.008576 0.001250 0.000146
7
0 0.000015
1 0.000047
2 0.000092
3 0.000047
4 0.000015
SYSTEM STATE at Time t = 79.99999999999973:
Species `A`:
0 1 2 3 4 5 6 \
0 0.506124 0.470504 0.348500 0.196510 0.086253 0.030518 0.009056
1 0.651796 0.605845 0.448797 0.253152 0.111169 0.039355 0.011686
2 0.751013 0.698018 0.517108 0.291737 0.128146 0.045379 0.013480
3 0.651796 0.605845 0.448797 0.253152 0.111169 0.039355 0.011686
4 0.506124 0.470504 0.348500 0.196510 0.086253 0.030518 0.009056
7
0 0.002731
1 0.003527
2 0.004070
3 0.003527
4 0.002731
SYSTEM STATE at Time t = 2009.9999999992674:
Species `A`:
0 1 2 3 4 5 6 \
0 0.250896 0.250759 0.250507 0.250178 0.249822 0.249493 0.249241
1 0.250896 0.250759 0.250507 0.250178 0.249822 0.249493 0.249241
2 0.250896 0.250759 0.250507 0.250178 0.249822 0.249493 0.249241
3 0.250896 0.250759 0.250507 0.250178 0.249822 0.249493 0.249241
4 0.250896 0.250759 0.250507 0.250178 0.249822 0.249493 0.249241
7
0 0.249104
1 0.249104
2 0.249104
3 0.249104
4 0.249104
Notice the continued symmetry across the mid-row.
Mass conservations: the "10. units of concentration" are now uniformly spread across the 40 bins, leading to a near-constant concentration of 10./40
10./40
0.25