LAST_REVISED = "May 19, 2025"
LIFE123_VERSION = "1.0.0rc3" # Library version this experiment is based on
#import set_path # Using MyBinder? Uncomment this before running the next cell!
#import sys, os
#os.getcwd()
#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
with a single chemical A
chem_data = ChemData(diffusion_rates=10.) # Name "A" automatically assigned to single chemical
bio = BioSim1D(n_bins=4, chem_data=chem_data)
initial_conc = [20, 50, 150, 250]
bio.set_species_conc(conc_list=initial_conc, chem_index=0)
bio.describe_state()
SYSTEM STATE at Time t = 0: 4 bins and 1 chemical species
| Species | Diff rate | Bin 0 | Bin 1 | Bin 2 | Bin 3 | |
|---|---|---|---|---|---|---|
| 0 | A | 10.0 | 20.0 | 50.0 | 150.0 | 250.0 |
bio.system_snapshot()
| A | |
|---|---|
| 0 | 20.0 |
| 1 | 50.0 |
| 2 | 150.0 |
| 3 | 250.0 |
bio.visualize_system() # Line curve view
bio.system_heatmaps()
bio.set_membranes(membranes=[ (1,2) ]) # By default impermeable
bio.membranes_obj
[(1, 2)]
bio.describe_state()
SYSTEM STATE at Time t = 0: 4 bins and 1 chemical species Membranes present: [(1, 2)]
| Species | Diff rate | Bin 0 | Bin 1 | Bin 2 | Bin 3 | |
|---|---|---|---|---|---|---|
| 0 | A | 10.0 | 20.0 | 50.0 | 150.0 | 250.0 |
bio.system_heatmaps()
bio.diffuse(time_step=0.02, n_steps=1)
{'steps': 1, 'system time': '0.02'}
bio.system_snapshot()
| A | |
|---|---|
| 0 | 20.0 |
| 1 | 50.0 |
| 2 | 170.0 |
| 3 | 230.0 |
bio.system_heatmaps()
By contrast, diffusion is progressing between the 2 rightmost bins
Technical side note: since we're using, by default, simple 3-1 stencils for the diffusion step, the concentration increment in bin 3, and its corresponding decrement in bin 2, is:
0.02 * 100 * 10 / (1*1) # (Time step) * (Delta concentration) * (Diffusion rate const) / (bin length squared)
20.0
The 150 initial value in bin 2 increased by 20 to 170, and the 250 value in bin 3 correspondingly decreased to 230
bio.diffuse(time_step=0.02, n_steps=14)
{'steps': 14, 'system time': '0.3'}
bio.system_heatmaps()
A to the membranes (by passive transport)¶bio.change_permeability("A", 1.)
bio.diffuse(time_step=0.02, n_steps=1)
{'steps': 1, 'system time': '0.32'}
bio.system_heatmaps()
Diffusion is continuing normally between the 2 rightmost bins
Technical side note - Passive membrane transport out of bin 1 (conc. 50) into bin 0 (conc. 20) in this single step was:
30 * 1 * 0.02 # (Delta conc) * Permeability * (Time step) , since all bin sizes are 1
0.6
The concentration of bin 0 has increased from 20 to 20.6 during this single step.
The concentration of bin 1 is also increasing, because its loss to bin 0 is more than compensated by its gain from bin 2 (bigger conc. difference)
bio.diffuse(time_step=0.02, n_steps=4)
{'steps': 4, 'system time': '0.4'}
bio.system_heatmaps()
bio.diffuse(time_step=0.02, n_steps=45)
{'steps': 45, 'system time': '1.3'}
bio.system_heatmaps()
bio.diffuse(time_step=0.02, n_steps=500)
{'steps': 500, 'system time': '11.3'}
bio.system_heatmaps()
bio.check_mass_conservation(expected=sum(initial_conc), chem_index=0)
True