Drosophila Connectome Embodiment Engine
Browser simulation of a male fruit fly driven by a 23-neuron spiking network from connectome papers.
6 min read
This project is a browser simulation of a male fruit fly (Drosophila melanogaster). A network of 23 spiking neurons controls the body of the fly in a round arena. The fly sees, tastes, and smells the arena. Its neurons fire. The spikes move its legs, wings, and proboscis.
The simulation runs in the browser with no server. The stack is TypeScript, Vite, Canvas 2D, and the Web Audio API.
What the simulation models
The neuron model
Each neuron is a leaky integrate-and-fire (LIF) neuron with conductance-based synapses.
- The engine integrates the membrane equation with exponential Euler. The result stays stable at any step size.
- A spike sets the voltage to +20 mV for one step. The neuron then resets and stays refractory for 1.5 ms to 3.5 ms.
- Each synapse has a weight, a sign (ACh excitatory or GABA inhibitory), and a conduction delay.
- Sensory input enters as a current in mV per second. The response does not change with frame rate or speed.
The circuits
| Pathway | Neurons | Behavior |
|---|---|---|
| Courtship | LC10 → AOTU008 → P1 → pIP10 | The male sees the female, and P1 drives wing song. |
| Steering | LC10 → DNg13 (same side) | The male turns toward a target. |
| Pheromone | GRN_Pheromone_Female → SEZ_PN_Phero → P1 | Female scent drives courtship. |
| Feeding | GRN_Sugar → SEZ_PN_Sweet → MN_Proboscis | Sugar at the front legs extends the proboscis. |
| Bitter | GRN_Bitter ⊣ MN_Proboscis, P1 | Bitter taste stops feeding and courtship. |
| Escape | LC4, LPLC2 → GF | A looming shadow fires the Giant Fiber, and the fly jumps. |
| Priority | GF ⊣ P1 | An escape stops courtship. |
Three neuromodulators change the circuits. Dopamine lowers the P1 and pIP10 thresholds. Octopamine lowers the sensory and motor thresholds. Serotonin increases inhibition.
The senses
- Eyes: Each eye has 36 facets. Each facet averages light over its field, so a moving edge gives a smooth signal. The looming detectors respond to net darkening only. As a result, the fly does not escape from its own turns.
- Taste and smell: A 60 × 60 grid holds three chemicals: sugar, bitter, and pheromone. Each chemical diffuses and decays at a rate per second.
- Sound: pIP10 spikes play 220 Hz pulse clicks. P1 activity with wing song plays a 165 Hz sine tone.
Calibration
Each sensory gain gives a held input of gain × drive × τm above rest. The table shows the result.
| Input | Gain (mV/s) | Range for a spike |
|---|---|---|
| LC10 (vision) | 2000 | Female closer than about 95 px ahead |
| Sugar | 25000 | Leg closer than about 22 px to the food center |
| Pheromone | 80000 | Female closer than about 35 px |
Two synapse weights come from measured scans. P1 → pIP10 is 6.5, and SEZ_PN_Phero → P1 is 9.5. At these weights, one spike does not fire the target, but a sustained train does.
Requirements
- Node.js 22.12 or later (Vitest 5 requires this version)
- npm 10 or later
Install and run
- Open a terminal in the project folder.
- Install the packages with
npm install. - Start the development server with
npm run dev. - Open
http://localhost:3000in a browser.
Test and build
- Run the test suite with
npm test. - Run the coverage report with
npx vitest run --coverage. - Build the production files with
npm run build. - Serve the production files with
npm run preview.
The build writes the production files to dist/.
Controls
Mouse
| Control | Result |
|---|---|
| Speed buttons | Set the speed: pause, 0.5×, 1×, 2×, 5×, or 10×. |
| Tool buttons | Select a tool for the arena. |
| Arena click | Apply the selected tool at the click point. |
| Graph node click | Inject 25 mV into the neuron. |
| Stimulate P1 | Inject 28 mV into P1_L and P1_R. |
| Stimulate Giant Fiber | Inject 35 mV into GF_L and GF_R. |
| Trigger looming predator | Start a looming shadow near the male. |
| Audio button | Turn the sound on or off. The sound starts muted. |
| Preset list | Set all three neuromodulators to a preset. |
| Sliders | Set one neuromodulator from 0.0× to 3.0×. |
| Reset | Put the arena and the neurons back to the start state. |
The arena tools are sucrose, bitter, pheromone, four block types, spawn male, spawn female, lightning, and erase.
Keyboard
- Press Tab to move between the controls.
- On the arena, press an arrow key to move the cursor. Hold Shift to move the cursor farther.
- On the arena, press Enter or Space to apply the selected tool at the cursor.
- On the graph, press an arrow key to select a neuron.
- On the graph, press Enter or Space to stimulate the selected neuron.
A screen reader announces each cursor move, tool action, reset, and preset change.
Deployment
The app is a static site. Upload the contents of dist/ to a static host.
- Serve all pages over HTTPS with TLS 1.3.
- Configure the host to send the security headers below.
- Configure the host to serve
404.htmlfor unknown paths.
Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; font-src 'self'; img-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'none'
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
X-Content-Type-Options: nosniff
Referrer-Policy: no-referrer
The policy needs 'unsafe-inline' for styles because index.html holds its CSS in a <style> block. The app loads no external scripts, fonts, or data.
Project layout
| Path | Contents |
|---|---|
src/neural/ |
Neuron definitions, the connectome, the LIF engine, and the neuromodulator presets |
src/physics/ |
The arena, the fly body, the eyes, and the chemical grid |
src/audio/ |
The courtship song synthesizer |
src/ui/ |
The four canvas views and the HUD cards |
src/main.ts |
The controller: the event wiring, the frame loop, and the sensory-to-motor step |
tests/ |
177 tests in 12 files, with 100% statement, branch, function, and line coverage |
Sources
The circuits follow three papers in research-notes/:
- Sexual dimorphism in the complete Drosophila male central nervous system (
Sexual-dimorphism-in-the-complete-Drosophila-male-*.pdf). Figure 4I gives the DNg13 steering rule: unilateral activation turns the fly to the same side. - The complete gustatory connectome of the adult Drosophila (
The-complete-gustatory-connectome-of-adult-Drosoph*.pdf). - The organization of visual pathways in Drosophila (
The-organization-of-visual-pathways*.pdf).
The Giant Fiber circuit is not in these three papers. The model uses the standard GF escape pathway from the wider literature.