Close
How it works
This page runs BAAIWorm (Zhao et al., Nature Computational Science 2024), a model of C. elegans that connects a detailed brain to a soft body in water. The original runs on a Linux workstation with NEURON and a CUDA viewer. Here both halves are new code, compiled to WebAssembly, and checked against the original's own data.
BAAIWorm swims and does not find food. On this page the same brain and body crawl on agar and find food. The parts that make this possible are ours, not BAAIWorm's. They are described under Crawling on agar and Finding food , with the measurements they were fit to.
The brain
136 neurons, each with its real 3D shape from the NeuroML connectome, cut into 23,848 compartments.
Each soma has up to 16 ion channels (Nicoletti et al. 2019): potassium, calcium and calcium-activated potassium channels, plus internal calcium.
3,076 connections: 1,992 graded chemical synapses (651 excitatory, 1,341 inhibitory) and 1,084 gap junctions, placed on specific compartments.
The solver repeats NEURON's fixed-step method: backward Euler on each cell's tree, 5/3 ms steps, 600 steps per second of brain time.
Check: driven by the same input, it matches the motor-neuron voltages that NEURON recorded for BAAIWorm to within 0.0001 mV over 23.8 s, for all 80 motor neurons.
Brain to muscles
Every 100 ms, the mean voltage of 80 motor neurons goes through BAAIWorm's fitted 80 × 96 readout. The result is the activation of 96 muscles: 24 along each of the four muscle quadrants.
The body
A finite-element mesh with 984 vertices and 3,341 tetrahedra, solved with projective dynamics, the method of SoftCon (Min et al. 2019) that BAAIWorm uses.
Each muscle segment pulls through about 50 fiber constraints inside the tetrahedra. A muscle with activation a wants its fibers shortened to (1 − a ) of their length.
In BAAIWorm, water pushes on each of the 1,466 surface triangles with SoftCon's drag and lift, and the body takes 8 steps of 1/240 s for every 100 ms of brain time.
Check: in water, given the same muscle signals, no vertex of this body is more than 0.0000002 units from the same vertex in BAAIWorm's own body code during 20 s. (The worm is 0.63 units long, so 1 mm = 0.63 units.) The page crawls on a symmetric mesh of its own; see below.
The skin
What you see is a drawn surface, not the simulation mesh. It is a smooth tube of 21,600 vertices that follows the mesh's outline, with a rounded nose and a tail that narrows to a point. Inside it are the organs that show through a real worm's cuticle: the pharynx with its two bulbs and the grinder, the intestine, and eggs on both sides of the vulva (positions from WormAtlas). Each vertex is fixed in one tetrahedron of the mesh, so it bends with the body. The shading copies transmitted light through a dissecting microscope: the edges are dark where the light bends, the middle is clear, and the cuticle has fine rings (annuli) and a ridge along each side (alae). The physics does not see any of this.
The whole loop, against the original
BAAIWorm's own code also runs here, outside the browser: its NEURON model and its SoftCon body, built without its CUDA viewer. Started the same way, the two runs give the same muscle signals to within 0.0001 at every step for 20 s (the range is 0 to 0.8). For the first 10 s, no vertex of the two bodies is more than 0.02 units apart (3% of the body length). Then the small differences in the brain grow, as they do between any two runs of a swimming body, and the paths separate.
The input
15 sensory neurons get a current clamp. Here it plays the 2 s pattern that BAAIWorm's readout was fit on. That is the pattern of the original's own demo, and it sets the rhythm of the gait. In the paper, this current comes from the change in odor at the head. That closed loop also runs here, and we ran it in BAAIWorm's own code too. It does not find food. In 100 runs with the food 2 units away in different directions, after 60 s the worm was no closer to its own food than to the food of the other runs. The reason is in the input: each step's change in odor is scaled by the range of the last 11 changes, so swimming toward the food and swimming away from it at the same speed give the same current. The readout was also fit to one forward gait, not to turning. The paper shows one closed-loop run and does not test reaching food.
Crawling on agar (ours)
Real worms are studied on agar plates, where they crawl on their side in a shallow groove. Three changes put BAAIWorm's worm on agar:
One clock. BAAIWorm runs 100 ms of brain for every 33 ms of body, so its body moves three times too fast for its brain. Its 1.5 Hz gait is the recorded 2 s input played at that speed. Here the body also takes 100 ms per step. The gait is then 0.5 Hz.
Agar drag. Each vertex is pulled back to where it was, 30 times more strongly across the body than along it, as in the resistive-force models of crawling. The drag is part of the solver, so the matrix is still factored only once. The body is also held on the plane of the plate.
A symmetric body. SoftCon's mesh is irregular and is not a mirror image of itself. In a segment, the dorsal and ventral muscle fibers can differ in strength by up to 20%. Even a perfectly symmetric wave made it crawl in a slow curve, and the brain's gait made it crawl in circles. The page now uses its own mesh: the same length and outline, built from one quarter of a regular tube and mirrored across the dorsal–ventral and left–right planes, so it is exactly symmetric. It has 1,008 vertices and 3,948 tetrahedra, about as many as SoftCon's (984 and 3,341). The 96 muscle segments are in the same places along the body, in four quadrants at 45° from the midlines. On it, the brain's gait keeps its heading to within 0.1° per second. Real worms turn by 0.4 ± 2.1° per second on average (Pierce-Shimomura et al. 1999).
This page Real worms on agar
Undulation 0.50 Hz 0.30 Hz (Fang-Yen et al. 2010); 0.55 Hz (Sawin et al. 2000)
Wavelength 0.60 body lengths 0.65 (Fang-Yen et al. 2010)
Speed 0.15 mm/s 0.12–0.15 mm/s (Iino & Yoshida 2009; Pierce-Shimomura et al. 1999)
Finding food (ours)
The food is a lawn of bacteria. Around it the attractant forms a hill: 2 mM on the open plate, rising to 6 mM at the food, about 1 cm wide. This is the radial gradient of Pierce-Shimomura et al. (1999). The worm senses the concentration at its nose. A layer between the brain's muscle signals and the body steers with the two strategies that real worms use, at the rates measured in them:
Pirouettes (Pierce-Shimomura et al. 1999). When the concentration falls, the worm turns more often. The rate per second is Iino and Yoshida's fit, 0.023 / (0.40 + e140 dC/dt ) + 0.0033. Each turn is a reversal: the brain's gait runs tail first and the worm backs up. Half of the reversals end in an omega turn, a deep ventral bend that points the worm in a new direction. Durations are from Zhao et al. (2003): 2.3 s, or 3.4 s before an omega turn.
Weathervaning (Iino & Yoshida 2009). While the head sweeps to one side, a rising concentration bends it further to that side, so the path curves up the gradient. The gain is set so the path curves 12.7°/mm for each mM/mm of gradient across the heading, as Iino and Yoshida measured. We set it in a test plate with a straight gradient across the worm's path, on each side in turn. On top of that, the heading wanders at random by 32°/mm, as theirs did.
The brain keeps making the forward gait. It does not make these decisions. Making them inside the circuit is our next step.
Test. We repeated Pierce-Shimomura's assay: worms start 22 mm from the peak, at 48 different headings, and we count how many reach the 5 mm zone around it within 20 minutes.
Reached the peak zone Pierce-Shimomura et al. 1999
Both strategies 73% (35 of 48) 56–60%
No gradient (control) 6% (3 of 48) 8.3%
Pirouettes only 58% (14 of 24) —
Weathervaning only 17% (4 of 24) —
The difference from the control is clear (Fisher's exact test, p = 8×10-12 ). In this shallow gradient, the pirouettes do most of the work, as Pierce-Shimomura et al. found (p = 3×10-6 against the control). Weathervaning alone does not differ clearly from the control (p = 0.2). At the start the gradient is only about 0.08 mM/mm, so Iino and Yoshida's gain curves the path by about 1°/mm, much less than the random wander. Their plates had steeper salt gradients. Near the food the gradient is steeper and weathervaning helps more: worms that reach the zone take 7 minutes (median) with both strategies, against 10 minutes with pirouettes only.
Cutting the wiring
The sliders scale the strength of every chemical synapse or every gap junction. At 0% every connection of that kind is gone, as in the paper's experiments that removed them. Weaker connections in between are this page's addition. On agar the intact worm crawls forward at 0.135 body lengths per second. With the gap junctions at half strength it almost stops (0.008). With them gone, or with the chemical synapses at half strength, it drifts backward. With no chemical synapses it does not move forward. The readout was fit to the intact circuit, so this shows the effect of the cut. It does not show how a real worm adapts.
What is not real
BAAIWorm models only 136 of the 302 neurons. The others are not in this circuit.
The input current is large for the small sensory cells. Some of them, such as URYVL, go several hundred millivolts below rest. This is a property of BAAIWorm's model, and the page keeps it.
The gait comes from BAAIWorm's recorded input, played in a loop, and its fitted readout. The brain does not make the rhythm by itself, and it does not feel the body bend.
The steering is a layer outside the brain, fit to the behavior of real worms (see above). The sensory neurons in the circuit still get the recorded input.
The body shortens by about a fifth while it crawls, because BAAIWorm's readout keeps the muscles on both sides partly contracted. A real worm keeps its length.
On the food the worm does not slow down or start feeding, as real worms do.
Every neuron starts at −65 mV, as in BAAIWorm. The body waits 3 s while the brain settles, because before that the head swings round by 130°.
The neurons are drawn by fitting the NeuroML coordinates into the mesh, so their place in the body is approximate.