The system starts out with a pulse in bins near the left and the right endpoints
LAST REVISED: June 23, 2024 (using v. 1.0 beta34.1)
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 life123 import BioSim1D
import plotly.express as px
from life123 import ChemData as chem
from life123 import HtmlLog as log
from life123 import GraphicLog
# Initialize the HTML logging
log_file = get_notebook_basename() + ".log.htm" # Use the notebook base filename for the log file
GraphicLog.config(filename=log_file,
components=["vue_heatmap_11", "vue_curves_3"])
-> Output will be LOGGED into the file 'reach_equilibrium_2.log.htm'
# Set the heatmap parameters
heatmap_pars = {"range": [0, 2.5],
"outer_width": 850, "outer_height": 150,
"margins": {"top": 30, "right": 30, "bottom": 30, "left": 55}
}
# Set the parameters of the line plots
lineplot_pars = {"range": [0, 10],
"outer_width": 850, "outer_height": 250,
"margins": {"top": 30, "right": 30, "bottom": 30, "left": 55}
}
# Initialize the system
chem_data = chem(names=["A"], diffusion_rates=[0.1])
bio = BioSim1D(n_bins=9, chem_data=chem_data)
bio.set_uniform_concentration(species_index=0, conc=0.)
# Start out with a pulse in bins near the *left* and the *right* endpoints.
# A total of 20 "units of concentration" is injected
bio.inject_conc_to_bin(species_index=0, bin_address=2, delta_conc=10.)
bio.inject_conc_to_bin(species_index=0, bin_address=6, delta_conc=10.)
bio.describe_state()
SYSTEM STATE at Time t = 0: 9 bins and 1 species: Species 0 (A). Diff rate: 0.1. Conc: [ 0. 0. 10. 0. 0. 0. 10. 0. 0.]
bio.show_system_snapshot()
SYSTEM SNAPSHOT at time 0:
A
0 0.0
1 0.0
2 10.0
3 0.0
4 0.0
5 0.0
6 10.0
7 0.0
8 0.0
fig = px.line(data_frame=bio.system_snapshot(), y=["A"],
title= f"Diffusion. System snapshot at time t={bio.system_time}",
color_discrete_sequence = ['red'],
labels={"value":"concentration", "variable":"Chemical", "index":"Bin number"})
fig.show()
# Output to the log file
log.write("1-D diffusion to equilibrium of a single species, with Diffusion rate 0.1. Time steps of 0.1",
style=log.h2)
log.write(f"System state at time t={bio.system_time}:", blanks_before=2, style=log.bold)
# Output a heatmap to the log file
bio.single_species_heatmap(species_index=0, heatmap_pars=heatmap_pars, header=f"Time {bio.system_time} :\n", graphic_component="vue_heatmap_11")
# Output a line plot the log file
bio.single_species_line_plot(species_index=0, plot_pars=lineplot_pars, graphic_component="vue_curves_3")
1-D diffusion to equilibrium of a single species, with Diffusion rate 0.1. Time steps of 0.1 System state at time t=0: [GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] [GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`]
delta_time = 3.
for i in range(15):
status = bio.diffuse(total_duration=delta_time, time_step=0.1)
print(f"\nAfter Delta time {delta_time}. TOTAL TIME {bio.system_time} ({status['steps']} steps taken):")
bio.describe_state(concise=True)
fig = px.line(data_frame=bio.system_snapshot(), y=["A"],
title= f"Diffusion. System snapshot at time t={bio.system_time}",
color_discrete_sequence = ['red'],
labels={"value":"concentration", "variable":"Chemical", "index":"Bin number"})
fig.show()
#if i<2 or i==6 or i>=14:
bio.single_species_heatmap(species_index=0, heatmap_pars=heatmap_pars, header=f"Time {bio.system_time}\n", graphic_component="vue_heatmap_11")
# Output a line plot the log file
bio.single_species_line_plot(species_index=0, plot_pars=lineplot_pars, graphic_component="vue_curves_3")
After Delta time 3.0. TOTAL TIME 3.0000000000000013 (30 steps taken): SYSTEM STATE at Time t = 3: [[0.27757451 1.74303541 5.96050983 1.76527256 0.5072154 1.76527256 5.96050983 1.74303541 0.27757451]]
[GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] [GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] After Delta time 3.0. TOTAL TIME 5.999999999999995 (30 steps taken): SYSTEM STATE at Time t = 6: [[0.73152765 2.1834153 4.18877184 2.28238941 1.22779161 2.28238941 4.18877184 2.1834153 0.73152765]]
[GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] [GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] After Delta time 3.0. TOTAL TIME 8.999999999999984 (30 steps taken): SYSTEM STATE at Time t = 9: [[1.12120196 2.24355388 3.33164561 2.4287678 1.7496615 2.4287678 3.33164561 2.24355388 1.12120196]]
[GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] [GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] After Delta time 3.0. TOTAL TIME 11.999999999999973 (30 steps taken): SYSTEM STATE at Time t = 12: [[1.40992642 2.21285813 2.88112821 2.46180799 2.06855851 2.46180799 2.88112821 2.21285813 1.40992642]]
[GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] [GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] After Delta time 3.0. TOTAL TIME 14.999999999999963 (30 steps taken): SYSTEM STATE at Time t = 15: [[1.61375804 2.17517282 2.62918072 2.4582931 2.24719065 2.4582931 2.62918072 2.17517282 1.61375804]]
[GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] [GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] After Delta time 3.0. TOTAL TIME 17.999999999999986 (30 steps taken): SYSTEM STATE at Time t = 18: [[1.75622069 2.14971234 2.4820061 2.44230075 2.33952022 2.44230075 2.4820061 2.14971234 1.75622069]]
[GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] [GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] After Delta time 3.0. TOTAL TIME 21.00000000000003 (30 steps taken): SYSTEM STATE at Time t = 21: [[1.8567287 2.13705992 2.39331754 2.42217874 2.38143019 2.42217874 2.39331754 2.13705992 1.8567287 ]]
[GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] [GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] After Delta time 3.0. TOTAL TIME 24.00000000000007 (30 steps taken): SYSTEM STATE at Time t = 24: [[1.92909045 2.13366871 2.33854991 2.40125523 2.39487141 2.40125523 2.33854991 2.13366871 1.92909045]]
[GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] [GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] After Delta time 3.0. TOTAL TIME 27.000000000000114 (30 steps taken): SYSTEM STATE at Time t = 27: [[1.98256145 2.13602714 2.30397039 2.38102863 2.39282476 2.38102863 2.30397039 2.13602714 1.98256145]]
[GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] [GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] After Delta time 3.0. TOTAL TIME 30.000000000000156 (30 steps taken): SYSTEM STATE at Time t = 30: [[2.0231929 2.14155643 2.28163209 2.3622001 2.38283695 2.3622001 2.28163209 2.14155643 2.0231929 ]]
[GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] [GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] After Delta time 3.0. TOTAL TIME 33.0000000000002 (30 steps taken): SYSTEM STATE at Time t = 33: [[2.05491235 2.14857175 2.26683188 2.34506617 2.36923571 2.34506617 2.26683188 2.14857175 2.05491235]]
[GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] [GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] After Delta time 3.0. TOTAL TIME 36.00000000000024 (30 steps taken): SYSTEM STATE at Time t = 36: [[2.0802789 2.15604676 2.2567439 2.32970151 2.35445786 2.32970151 2.2567439 2.15604676 2.0802789 ]]
[GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] [GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] After Delta time 3.0. TOTAL TIME 39.000000000000284 (30 steps taken): SYSTEM STATE at Time t = 39: [[2.1009805 2.16339318 2.24965092 2.31605836 2.33983408 2.31605836 2.24965092 2.16339318 2.1009805 ]]
[GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] [GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] After Delta time 3.0. TOTAL TIME 42.00000000000033 (30 steps taken): SYSTEM STATE at Time t = 42: [[2.11815199 2.1702984 2.24449902 2.30402493 2.32605132 2.30402493 2.24449902 2.1702984 2.11815199]]
[GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] [GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] After Delta time 3.0. TOTAL TIME 45.00000000000037 (30 steps taken): SYSTEM STATE at Time t = 45: [[2.13257541 2.1766169 2.24063469 2.29346029 2.31342543 2.29346029 2.24063469 2.1766169 2.13257541]]
[GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`] [GRAPHIC ELEMENT SENT TO LOG FILE `reach_equilibrium_2.log.htm`]
All cells now have essentially uniform concentration
The "20 units of concentration" are now uniformly spread across the 9 bins, leading to a near-constant concentration of 20/9 = 2.22