Life simulation of evolving unicellular organisms in a stochastic artificial chemistry.
https://zushah.github.io/Microcosm
Microcosm models matter as a discrete artificial chemistry built from six fundamental elements (A, B, C, D, E, and F). Each element carries intrinsic polarity and intrinsic elemental energy; masses are also defined as metadata, but the active dynamics in the current simulation are driven by composition, bond state, polarity, and enval coupling rather than by explicit mechanics.
- Energetic Species: D and E are the most energy-rich elements and therefore remain the most concentrated atomic fuel available to evolving cells.
- Terminal Sink: F is a low-energy terminal state and commonly accumulates as the endpoint of downhill transmutation.
- Molecular Energetics: A molecule is represented by an elemental composition together with a bond multiplier
$\beta$ . Its total stored energy$E_{\mathrm{mol}}$ is:
- Molecular Mobility: A molecule of size
$N$ and mean polarity$\bar{P}$ receives a diffusion parameter$D$ given by:
Larger molecules therefore move more slowly, while smaller and more polar molecules hop more readily through the lattice.
- Spatial Substrate Field: The world is a toroidal lattice. Each tile begins with a shared base enval and a seeded molecular inventory: A is always present, while B, C, D, E, F, and a small BC dimer appear stochastically.
- Diffusion Mode: Molecular diffusion is asynchronous and event-scheduled. Each diffusion event moves one molecule to a cardinal neighbor with locally lower composition density (with tie-rotation and short-term backtracking suppression), rather than globally re-sampling every molecule each tick.
Life is defined by the possession of a genome encoding functional proteins called enzymes together with a scalar environmental optimum called optimal enval. Each enzyme stores a class, a specificity mask over the six elements, an enval response width
- Specificity Rule: Let
$X(M)$ be the set of elements present in molecule$M$ , and let$S$ be the enzyme specificity mask. For anabolase and catabolase,
For transmutase,
Thus synthetic and degradative enzymes are exclusive over their allowed alphabet, whereas transmutases only require access to at least one allowed source element.
Anabolase enzymes perform anabolism by sampling accepted substrates from the extracellular and intracellular pools and polymerizing them into a single higher-bond product. The product composition is simply the summed elemental composition of the substrates, but its bond multiplier is elevated above unity. The energetic cost is the increase in bond storage, scaled by a bond-cost fraction
This makes anabolism endergonic unless it is subsidized by previously stored energy or by aligned enval harvesting.
Catabolase enzymes perform catabolism by selecting one accepted substrate of size at least two and fragmenting it into two lower-bond products. The current implementation does not perform the old catabolic isotope-transmutation step; catabolase now extracts only released bond energy, scaled by a harvest fraction
If the net usable gain is non-positive, the reaction is discarded.
Transmutase performs transmutation by acting on one accepted molecule and changing exactly one atom at a time along a directed artificial transmutation ladder.
- Uphill ladder:
- Downhill collapse:
If the raw elemental change is
The full cellular effect is then:
When both directions are available, transmutase biases more strongly toward uphill moves when aligned enval is abundant and the cell already has substantial energy reserves.
All enzyme classes may couple metabolism to the signed environmental scalar enval. Let
By default the harvested energy term is:
The reaction simultaneously pumps opposite-sign enval back into the environment. With baseline pump magnitude
Operationally, aligned enval is removed from the local tile while opposite-sign enval is deposited into one randomly sampled site in the local Moore neighborhood (including the source tile). Successful metabolism therefore does not merely consume a pre-existing field; it actively reshapes that field.
The primary environmental variable is a single unbounded signed scalar called enval. At initialization the world begins with a random base enval sampled from the interval
- Local Sensing:
$V_{\mathrm{loc}}$ is the mean enval over the$5 \times 5$ neighborhood surrounding the cell (Chebyshev radius of two). - Genomic Target:
$V_{\mathrm{opt}}$ is stored in the cell genome as optimal enval. - Enzyme Tolerance:
$\sigma$ is stored per enzyme as its enval response width.
The reaction attempt probability is scaled by this efficiency term:
Current base rates are 0.85 for anabolase, 0.98 for catabolase, and 0.30 for transmutase. Strong mismatch therefore suppresses metabolism primarily by preventing reactions from firing at all; enval harvesting falls indirectly because fewer reactions occur.
The enval field itself diffuses across the toroidal lattice by discrete local averaging:
Because reactions continuously remove aligned enval and emit opposite-sign enval, the field is both smoothed by diffusion and destabilized by metabolic feedback.
A cell is a stationary metabolic agent that occupies a tile, stores free energy, stores an internal molecular inventory, and executes its genome each tick.
- Basal Maintenance: Each cell continuously pays a maintenance cost in stored energy. If energy reaches zero, the cell dies and releases its internal molecules into the environment.
- Opportunistic Uptake: If internal elemental reserves fall below the desired reserve target, the cell passively grabs one random molecule from the tile into its internal pool.
- Enval Stress: In addition to basal maintenance, mismatch between local and optimal enval increases the cell's starvation/decay timer according to:
where
- Reproduction: Once stored free energy exceeds the reproduction threshold, the cell divides into a nearby empty tile within radius two. Energy is split stochastically around a 50/50 partition, and each internal molecule independently has a 50% chance to go to the offspring.
- Lineage Identity: Offspring inherit the parental lineage identifier, so lineage structure tracks ecological descent rather than instantaneous genotype identity.
Cells may now carry two non-metabolic combat enzymes: defensase and attackase. Founders always begin with one defensase, while attackase is absent from founder genomes and must appear later by mutation during reproduction. Each combat enzyme carries an integer level rather than an element-specificity mask. Founder defensase levels are drawn from a rounded Gaussian distribution centered on 100 (current implementation:
Predation is evaluated between edge-adjacent cells of different lineages after the ordinary metabolic step. Let
- If only one cell satisfies
$\text{attack} > \text{opponent defense}$ , that cell engulfs the other. - If both cells satisfy that inequality, the larger margin wins: compare
$A_{\mathrm{atk}} - B_{\mathrm{def}}$ against$B_{\mathrm{atk}} - A_{\mathrm{def}}$ . - If neither cell can exceed the opponent's defense, or if the two margins are equal, nothing happens.
Successful predation performs a phagocytosis-like assimilation event: the loser is removed from the world, while the winner absorbs the loser's stored free energy, internal molecules, and enzyme inventory. Because absorbed enzymes are appended to the predator genome, combat and metabolic repertoires can both expand through ecological interactions rather than by descent alone.
Founders are seeded with an optimal enval drawn from a narrow band around the current world-average enval and initially carry an anabolase, a catabolase, and one Gaussian-sampled defensase. The metabolic founders still begin with ABC specificity, while attackase remains absent until it appears later by mutation or by enzyme class switching.
During division, the offspring optimal enval is inherited by a biased midpoint rule. Let
Then the offspring receives:
Other genome parameters also mutate stochastically: reproduction threshold, decay time, default secretion probability, enval stress factor, enzyme specificity masks, enzyme class, combat-enzyme level, enval response width, secretion probability, enval throughput, anabolase bond multiplier, and transmutase downhill harvest fraction. Enzyme count may also increase or decrease over evolutionary time.
The central ecological consequence is that successful lineages tend to destabilize the very field regime they exploit. Positive-adapted cells deplete positive enval and emit negative enval; negative-adapted cells deplete negative enval and emit positive enval. The intended macrodynamics are therefore cyclical succession, lineage turnover, and repeated ecological boom-bust behavior.
Microcosm is a browser-native ES-module application with no backend and no build step in the repository itself. The runtime is organized into a small set of source files:
./src/sim/bio.jsdefines enzyme classes and reaction execution../src/sim/cell.jsdefines cellular physiology, reaction logging, division, and mutation../src/sim/chem.jsdefines the artificial chemistry and molecule construction../src/sim/eco.jsdefines predator-prey interactions and combat mechanisms../src/sim/rng.jsdefines a seeded pseudorandom number generator and its helpers../src/sim/world.jsdefines the toroidal world, molecule diffusion, enval diffusion, and spawning../src/render/canvas.jsdefines the WebGL2 renderer../src/main.jswires together the simulation loop, statistics, interaction, and inspector UI.
At startup the simulation builds a 320 x 240 world, spawns 32 founder cells, and advances the world at a fixed step of 10 ms. After initialization, additional founder cells are injected stochastically with a population-dependent spawn probability that declines toward a floor as occupancy rises. The renderer colors the background by local enval and colors cells by lineage identity; an interaction panel can switch tile coloring to per-element concentration channels (A through F). The HUD reports frame rate, tick rate, population, average energy, lineage count, enzyme functional diversity, elemental totals, and average enval. Left-clicking a cell opens a detailed inspector; in Explore mode right-clicking a cell selects its lineage, while in Edit mode right-click drag applies a rectangular enval brush. The inspector exposes internal molecules, genome parameters, recent reactions, and reaction-level energetic bookkeeping, and a button copies the recent reaction log to the clipboard.
