Three scenarios:
LAST_REVISED = "Aug. 18, 2025"
LIFE123_VERSION = "1.0.0rc6" # Library version this experiment is based on
#import set_path # Using MyBinder? Uncomment this before running the next cell!
#import sys
#sys.path.append("C:/some_path/my_env_or_install") # CHANGE to the folder containing your venv or libraries installation!
# NOTE: If any of the imports below can't find a module, uncomment the lines above, or try: import set_path
from life123 import BioSim1D, ChemData, check_version
check_version(LIFE123_VERSION)
OK
# Initialize the system
chem_data = ChemData(names="A",
diffusion_rates=600.)
bio = BioSim1D(n_bins=100, chem_data=chem_data)
# Adding a gradient slanting to the left
bio.inject_gradient("A", conc_left = 10., conc_right = 60.)
bio.describe_state()
SYSTEM STATE at Time t = 0: 100 bins and 1 chemical species
| Species | Diff rate | Bin 0 | Bin 1 | Bin 2 | Bin 3 | Bin 4 | Bin 5 | Bin 6 | Bin 7 | ... | Bin 90 | Bin 91 | Bin 92 | Bin 93 | Bin 94 | Bin 95 | Bin 96 | Bin 97 | Bin 98 | Bin 99 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | A | 600.0 | 10.0 | 10.505051 | 11.010101 | 11.515152 | 12.020202 | 12.525253 | 13.030303 | 13.535354 | ... | 55.454545 | 55.959596 | 56.464646 | 56.969697 | 57.474747 | 57.979798 | 58.484848 | 58.989899 | 59.494949 | 60.0 |
1 rows × 102 columns
# Visualize the complete initial state
bio.visualize_system(title_prefix="Initial concentration gradient. NO membranes present")
# The first round of diffusion
bio.diffuse(total_duration=2.5, fraction_max_step=0.5, show_status=True)
bio.visualize_system()
{'steps': 9001, 'system time': '2.5003', 'time_step': 0.000277775}
# Continue the diffusion
bio.diffuse(total_duration=5, fraction_max_step=0.5, show_status=True)
bio.visualize_system()
{'steps': 18001, 'system time': '7.5005', 'time_step': 0.000277775}
saved_state_no_membranes = bio.snapshot_system()
saved_state_no_membranes
{'system_time': 7.500480549996486,
'concentrations': array([[34.75897705, 34.75921491, 34.75969039, 34.76040304, 34.76135213,
34.76253675, 34.76395571, 34.76560761, 34.76749084, 34.76960352,
34.77194358, 34.7745087 , 34.77729635, 34.78030379, 34.78352804,
34.78696592, 34.79061404, 34.79446879, 34.79852639, 34.80278281,
34.80723386, 34.81187515, 34.8167021 , 34.82170993, 34.82689372,
34.83224835, 34.83776852, 34.8434488 , 34.84928358, 34.85526709,
34.86139344, 34.86765657, 34.87405032, 34.88056835, 34.88720426,
34.89395148, 34.90080336, 34.90775313, 34.91479394, 34.92191883,
34.92912079, 34.93639269, 34.94372737, 34.95111758, 34.95855603,
34.96603538, 34.97354825, 34.98108722, 34.98864486, 34.99621371,
35.00378629, 35.01135514, 35.01891278, 35.02645175, 35.03396462,
35.04144397, 35.04888242, 35.05627263, 35.06360731, 35.07087921,
35.07808117, 35.08520606, 35.09224687, 35.09919664, 35.10604852,
35.11279574, 35.11943165, 35.12594968, 35.13234343, 35.13860656,
35.14473291, 35.15071642, 35.1565512 , 35.16223148, 35.16775165,
35.17310628, 35.17829007, 35.1832979 , 35.18812485, 35.19276614,
35.19721719, 35.20147361, 35.20553121, 35.20938596, 35.21303408,
35.21647196, 35.21969621, 35.22270365, 35.2254913 , 35.22805642,
35.23039648, 35.23250916, 35.23439239, 35.23604429, 35.23746325,
35.23864787, 35.23959696, 35.24030961, 35.24078509, 35.24102295]])}
# Further continue the diffusion
bio.diffuse(total_duration=12.5, fraction_max_step=0.9, show_status=True) # we'll take bigger steps now
bio.visualize_system()
{'steps': 25001, 'system time': '20.001', 'time_step': 0.000499995}
# Initialize the system
chem_data = ChemData(names="A",
diffusion_rates=600.)
bio = BioSim1D(n_bins=100, chem_data=chem_data)
bio.membranes().set_membranes(membranes=[ (20, 40) ])
bio.membranes().change_permeability("A", 600.) # ********* We'll use the same value as the diffusion rate in water
# Adding a gradient slanting to the left
bio.inject_gradient("A", conc_left = 10., conc_right = 60.)
bio.describe_state()
SYSTEM STATE at Time t = 0: 100 bins and 1 chemical species Membranes present: [(20, 40)]
| Species | Diff rate | Bin 0 | Bin 1 | Bin 2 | Bin 3 | Bin 4 | Bin 5 | Bin 6 | Bin 7 | ... | Bin 90 | Bin 91 | Bin 92 | Bin 93 | Bin 94 | Bin 95 | Bin 96 | Bin 97 | Bin 98 | Bin 99 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | A | 600.0 | 10.0 | 10.505051 | 11.010101 | 11.515152 | 12.020202 | 12.525253 | 13.030303 | 13.535354 | ... | 55.454545 | 55.959596 | 56.464646 | 56.969697 | 57.474747 | 57.979798 | 58.484848 | 58.989899 | 59.494949 | 60.0 |
1 rows × 102 columns
# Visualize the complete initial state
bio.visualize_system(title_prefix="Initial concentration gradient. Membranes shown in brown")
# The first round of diffusion
bio.diffuse(total_duration=2.5, fraction_max_step=0.5, show_status=True)
bio.visualize_system()
{'steps': 9001, 'system time': '2.5003', 'time_step': 0.000277775}
# Continue the diffusion
bio.diffuse(total_duration=5, fraction_max_step=0.5, show_status=True)
bio.visualize_system()
{'steps': 18001, 'system time': '7.5005', 'time_step': 0.000277775}
A across the length of the system) look familiar??¶It's absolutely identical to what we had in part 1 (with no membranes) - as if the membranes weren't there!
We can can verify below that they're indeed identical, from the previously-saved system snapshot at the same time in the simulation:
bio.snapshot_system()["system_time"] - saved_state_no_membranes["system_time"] # Indeed, the snapshots were taken at the same times
0.0
bio.snapshot_system()["concentrations"] - saved_state_no_membranes["concentrations"]
array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0.]])
# Further continue the diffusion
bio.diffuse(total_duration=12.5, fraction_max_step=0.9, show_status=True) # we'll take bigger steps now
bio.visualize_system()
{'steps': 25001, 'system time': '20.001', 'time_step': 0.000499995}
# Initialize the system
chem_data = ChemData(names="A",
diffusion_rates=600.)
bio = BioSim1D(n_bins=100, chem_data=chem_data)
bio.membranes().set_membranes(membranes=[ (20, 40) ])
bio.membranes().change_permeability("A", 30.) # ******** This time, MUCH smaller than before (1/20-th)
# Adding a gradient slanting to the left
bio.inject_gradient("A", conc_left = 10., conc_right = 60.)
bio.describe_state()
SYSTEM STATE at Time t = 0: 100 bins and 1 chemical species Membranes present: [(20, 40)]
| Species | Diff rate | Bin 0 | Bin 1 | Bin 2 | Bin 3 | Bin 4 | Bin 5 | Bin 6 | Bin 7 | ... | Bin 90 | Bin 91 | Bin 92 | Bin 93 | Bin 94 | Bin 95 | Bin 96 | Bin 97 | Bin 98 | Bin 99 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | A | 600.0 | 10.0 | 10.505051 | 11.010101 | 11.515152 | 12.020202 | 12.525253 | 13.030303 | 13.535354 | ... | 55.454545 | 55.959596 | 56.464646 | 56.969697 | 57.474747 | 57.979798 | 58.484848 | 58.989899 | 59.494949 | 60.0 |
1 rows × 102 columns
# Visualize the complete initial state
bio.visualize_system(title_prefix="Initial concentration gradient. Membranes shown in brown")
# The first round of diffusion
bio.diffuse(total_duration=2.5, fraction_max_step=0.5, show_status=True)
bio.visualize_system()
{'steps': 9001, 'system time': '2.5003', 'time_step': 0.000277775}
# Continue the diffusion
bio.diffuse(total_duration=5, fraction_max_step=0.5, show_status=True)
bio.visualize_system()
{'steps': 18001, 'system time': '7.5005', 'time_step': 0.000277775}
# Further continue the diffusion
bio.diffuse(total_duration=12.5, fraction_max_step=0.9, show_status=True) # we'll take bigger steps now
bio.visualize_system()
{'steps': 25001, 'system time': '20.001', 'time_step': 0.000499995}