Diffusion of a narrow, bell-shaped, initial concentration of a single chemical.
With increasing distance from the initial location of the transient signal, hardly any change with time is detected as the system goes to equilibrium
LAST_REVISED = "Aug. 10, 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(diffusion_rates=10.) # Name "A" automatically assigned to only chemical
bio = BioSim1D(n_bins=500, chem_data=chem_data)
# Set up the initial bell-shape concentration, with the very narrow peak close to one end of the system,
# centered at 1/10 of the width of the system, i.e. at bin 50
bio.inject_bell_curve(chem_label="A", center=0.1, sd=0.005, amplitude=0.1, bias=10.)
df = bio.describe_state()
df
SYSTEM STATE at Time t = 0: 500 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 490 | Bin 491 | Bin 492 | Bin 493 | Bin 494 | Bin 495 | Bin 496 | Bin 497 | Bin 498 | Bin 499 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | A | 10.0 | 10.0 | 10.0 | 10.0 | 10.0 | 10.0 | 10.0 | 10.0 | 10.0 | ... | 10.0 | 10.0 | 10.0 | 10.0 | 10.0 | 10.0 | 10.0 | 10.0 | 10.0 | 10.0 |
1 rows × 502 columns
df[df.columns[38:62:2]] # Zoom in where the action is
| Bin 36 | Bin 38 | Bin 40 | Bin 42 | Bin 44 | Bin 46 | Bin 48 | Bin 50 | Bin 52 | Bin 54 | Bin 56 | Bin 58 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 10.000001 | 10.000092 | 10.003041 | 10.053076 | 10.487152 | 12.351638 | 15.970526 | 17.972439 | 15.598946 | 12.068034 | 10.40174 | 10.041046 |
# Visualize the system state so far
bio.visualize_system(title_prefix="Initial strong, localized transient")
# Show as heatmap
bio.system_heatmaps(title_prefix="Initial strong, localized transient")
# Request to save the concentration history at the bins with the initial concentration injection,
# and the bins at, or near, both ends of the system
bio.enable_history(bins=[0, 25, 48, 50, 100, 200, 400], frequency=25, take_snapshot=True)
History enabled for bins [0, 25, 48, 50, 100, 200, 400], for ALL chemicals
bio.diffuse(total_duration=5, time_step=0.01)
{'steps': 500, 'system time': '5'}
bio.visualize_system()
bio.system_heatmaps()
bio.plot_history_single_bin(title_prefix="Bin with the concentration injection.", bin_address=50)
bio.plot_history_single_bin(title_prefix="Bin very close to the location of the concentration injection.", bin_address=48)
bio.plot_history_single_bin(title_prefix="Bin relatively far from the location of the concentration injection.", bin_address=25)
# Do several rounds of diffusion, over relatively small time steps
for _ in range(5):
bio.diffuse(total_duration=25, time_step=0.02)
bio.visualize_system(show=True)
# Do more rounds of diffusion, over larger time steps
for _ in range(5):
bio.diffuse(total_duration=400, time_step=0.025)
bio.visualize_system(show=True)
bio.system_heatmaps()
bio.plot_history_single_bin(title_prefix="Bin with the concentration injection.", bin_address=50)
NOTICE: Excessive number of data points (3471) - only showing 1 out of every 2
bio.plot_history_single_bin(title_prefix="Bin very close to the location of the concentration injection.", bin_address=48)
NOTICE: Excessive number of data points (3471) - only showing 1 out of every 2
bio.plot_history_single_bin(title_prefix="Bin relatively far from the location of the concentration injection.", bin_address=25)
NOTICE: Excessive number of data points (3471) - only showing 1 out of every 2
bio.plot_history_single_bin(title_prefix="Bin also relatively far from the location of the concentration injection (but on opposite side).",
bin_address=0)
NOTICE: Excessive number of data points (3471) - only showing 1 out of every 2
bio.plot_history_single_bin(title_prefix="Bin quite far from the location of the concentration injection.", bin_address=100)
NOTICE: Excessive number of data points (3471) - only showing 1 out of every 2
bio.plot_history_single_bin(title_prefix="Bin very far from the location of the concentration injection.", bin_address=200)
NOTICE: Excessive number of data points (3471) - only showing 1 out of every 2
bio.plot_history_single_bin(title_prefix="Bin hugely far from the location of the concentration injection.", bin_address=400)
NOTICE: Excessive number of data points (3471) - only showing 1 out of every 2
Transients that never make it far from their origin, because of chemical reactions consuming them, are explored in the experiment 1D/reaction_diffusion/transient_getting_mopped_up