# A neuron simulator in the browser, checked against NEURON

Part of [Neuron Lab: Tracing a Spike](../README.md).

A teaching tool. It simulates the voltage in a real, branching neuron shape, entirely in the
visitor's browser: no server, no account, no install, and it works with the network off. Its
numbers have been compared with NEURON, the standard research simulator, and the comparison is
published here with everything needed to rerun it.

**To use it:** double-click `index.html`.

![The page: a rat olfactory-bulb cell of 4,974 compartments a few milliseconds after a spike began at the soma](screenshots/page_largest_cell.png)

## The claim

It runs entirely in the browser and agrees with NEURON 9.0.2 to within 5.0 × 10⁻⁹ mV in voltage
and 3.4 × 10⁻¹² ms in spike time on these cells under these conditions.

- **These cells:** one Hodgkin–Huxley compartment, a ball-and-stick cell, a fork with a tapering
  branch, and three reconstructions from NeuroMorpho.Org with 319, 1,108 and 4,974 compartments
  (`CELLS.md`).
- **These conditions:** the same compartments in both simulators; NEURON's fixed-step,
  first-order implicit method at the same time step; NEURON's rate lookup tables switched off;
  Hodgkin–Huxley sodium, potassium and leak channels with NEURON's default values; one 50 ms
  current step; runs of 100 ms; the temperatures, current strengths and channel blocks listed in
  `VALIDATION.md`; and, as the review showed, currents not within about one part in a million
  of a firing threshold, and runs in which the cell does not magnify rounding (some strong,
  warm, long runs do, in NEURON as much as here).

Nothing is claimed outside those conditions. The numbers above are the ones in `VALIDATION.md`
on 22 November 2026; that file is regenerated by `./validate.sh` and is the authority if the two
ever differ.

### What did not pass

- **Two planned tests failed** (N2, N3). Against NEURON with its lookup tables left on, which is
  how most people run it, spike times drift by 0.029 and 0.068 ms over 100 ms. The pass mark,
  fixed beforehand, was 0.025 ms. The same drift appears between NEURON with tables on and
  NEURON with tables off, so it comes from NEURON's table approximation. The pass mark was not
  changed.
- **One failure was found and fixed.** On the first run of the real cells, compartment areas and
  axial resistances differed from NEURON's by up to 5.9 × 10⁻⁸ (relative) against a pass mark of
  10⁻⁹. Cause: NEURON subtracts coordinates in single precision. The code was changed to match,
  and both states are in the git history.

Counts: 110 planned tests passed and 2 failed. See `VALIDATION.md` for every number.

### What the attempt to break it found

A separate AI agent was asked to find cases where the two disagree (`review/REVIEW.md`). On its
first pass, 103 of 389 runs and 13 of 44 SWC files disagreed beyond the pass marks. The real
causes were fixed, and every test was rerun:

- time was kept differently, so a current switching exactly at the middle of a time step fell
  on different steps (up to 24 mV);
- at absurd currents the rates overflowed to NaN, and the judge would have scored that as a
  pass;
- four rules for reading SWC files differed from NEURON's importer.

What remains is stated as a condition or a limit:

- settings where the cell magnifies rounding (NEURON disagrees with itself there);
- currents tuned to a firing threshold to about one part in a billion;
- chain-shaped somas, and files written breadth-first, are read differently from NEURON's
  importer.

The review also made NEURON 9.0.2 itself crash, on one file whose lines are not in tree order.

## What the page does

- Shows the cell in 3D, coloured by membrane voltage, while the simulation runs in a Web Worker.
- A current electrode you place by clicking the cell; its strength and timing are adjustable.
- Up to four recording points, each drawing a voltage trace.
- Switches to block sodium channels, block potassium channels, or make the dendrites passive.
- Temperature, run length and playback speed.
- Three real cells built in, a made-up ball-and-stick cell, and "open an SWC file" for your own.
  A file you open is read by the page only. Nothing is uploaded.

On the laptop it was built on (Apple M5 Pro), the largest built-in cell ran about 59 ms of cell
time per second at 60 frames per second in headless Chrome. That is one measurement, not a
benchmark.

## Prior work

This project does not claim to be new in kind. Simulating a branching neuron in a browser has
been done before.

**Tools that compute on the visitor's machine**

- [Arbor Online Playground](https://arbor-sim.org/playground) (2022): the Arbor research
  simulator compiled to WebAssembly with Pyodide. A Python editor and a plot, with an example
  that overlays an Arbor trace on a stored NEURON trace. It is a far more capable simulator than
  this one.
- [Dendrite Garden](https://gsnautilus.github.io/dendrite-garden/) (October 2026): WebGPU
  simulation of neurons grown from Allen Cell Types reconstructions, with more channel types and
  networks of up to 10,000 neurons. Its pages report no validation against NEURON.
- Smaller client-side projects: [NeuroPulse CableLab](https://github.com/kai9987kai/NeuroPulse-CableLab)
  (an unbranched chain), [brian2wasm](https://github.com/brian-team/brian2wasm) (Brian 2 models
  compiled to WebAssembly), and many single-compartment Hodgkin–Huxley pages.

**Tools that compute on a server and display in the browser**

- [BlueNaaS](https://github.com/BlueBrain/BlueNaaS-SingleCell) (single-cell simulations with
  NEURON on a backend)
- [Jardesigner](https://jardesigner.org) (MOOSE on a server)
- [DendroTweaks](https://dendrotweaks.dendrites.gr) (a web interface over NEURON or Jaxley;
  [paper](https://elifesciences.org/articles/103324))
- [NetPyNE-UI](https://ebrains.eu/tools/netpyne) (NetPyNE and NEURON on a server)
- [EBRAINS Hodgkin–Huxley Neuron Builder](https://doi.org/10.3389/fninf.2022.991609)
- [Open Source Brain](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4697478/)

**What this project adds, as far as the search in `PRIOR_WORK.md` found:** a page that needs no
code and no network, together with a validation of the browser code itself against NEURON, with
pass marks fixed in advance, a test ladder from exact formulas up to real cells, and one command
that regenerates every number. That search was limited (about 20 web searches and 30 repository
queries on 20 November 2026) and may have missed things.

**What it rests on:** NEURON (Hines & Carnevale), whose method and file-reading rules this code
follows on purpose; the Hodgkin–Huxley model (1952); and the reconstructions shared through
NeuroMorpho.Org.

## What this does not model

- **Any channel other than Hodgkin–Huxley sodium, potassium and leak.** These are squid-axon
  channels. Real mammalian neurons have many more kinds, in different amounts in different
  places. The shapes are real; the membranes are not a model of these cells.
- **Synapses.** The only input is a current electrode.
- **Changing ion concentrations.** Reversal potentials are fixed. No calcium.
- **Different properties in different parts of the cell.** One axial resistivity, one membrane
  capacitance, and the same channel densities wherever channels are present.
- **Temperature beyond the gate rates.** Temperature speeds up the gates (a factor of 3 per
  10 °C) and changes nothing else.
- **Some cell bodies.** A soma recorded as a branched set of points is refused; 7 of the 20
  files tried during cell selection were refused for this reason. So is a three-point soma that
  breaks NeuroMorpho's convention. For a soma recorded as a chain of points, branches are
  attached differently from NEURON's importer (`MODEL.md`).
- **Zero-radius points.** They are raised to 0.01 µm so current can flow. Those stretches are
  thinner than any real dendrite.
- **Extracellular fields, spines, channel noise, networks.**

## Limits of the validation

- It shows this code and NEURON compute the same discrete equations with the same arithmetic.
  How close both are to the exact solution is shown only where an exact formula exists (passive
  cases) and by halving the time step. At the usual time step, spike times in both were off by
  0.03 to 0.25 ms in the convergence tests, by 0.55 ms in one warmer case, and by much more over
  long runs (about 10 ms over 2 seconds, in the review). The time step is a trade of speed for
  accuracy.
- On the real cells, most test cases fire a single spike. Long spike trains were tested on the
  simple cells only.
- Compartment size on the real cells follows the d_lambda rule and was not refined further.
- One reference version (NEURON 9.0.2), one machine, one browser (Chrome) for the browser check.
- The reviewer that tried to break it was another AI agent, not a person (`DISCLOSURE.md`).
- Agreement depends on the run being calm enough. In some strong, warm, long runs the cell
  magnifies rounding, so the two programs (and NEURON against itself, nudged by 10⁻⁹ mV) end up
  whole spikes apart. That is a property of those settings, not of either program, but the
  page lets you reach them.

## Rerun everything

    ./validate.sh

Needs Node (built with 26) and Python 3.9 to 3.13. On first run it creates `.venv/` inside this
folder and installs NEURON 9.0.2 into it, which needs the network once. It then runs the
self-tests, both simulators on every case, the comparison, the figures, and rewrites
`VALIDATION.md`. The browser check also needs Google Chrome and `npm install` in `tools/`; if
they are missing the script says so and keeps the last recorded browser result.

Other checks: `node tests/selftest.js` (arithmetic and bookkeeping), `node tools/page_test.js`
(the page's controls, offline).

## What is in this folder

| File or folder | What it is |
|---|---|
| `index.html`, `app/` | The page. `app/sim.bundle.js` and `app/cells.js` are generated by `tools/build_page.js`. |
| `sim/` | The simulator: SWC reader, geometry, Hodgkin–Huxley rates, cell builder, solver. |
| `MODEL.md` | The equations, the rules and every unit. |
| `EXPLAINER.md` | How it works, in plain words. |
| `VALIDATION_PLAN.md` | The tests and pass marks, committed before any comparison. |
| `VALIDATION.md` | The results. Generated. |
| `validation/` | Cases, the NEURON scripts, the judge, the figures. |
| `CELLS.md`, `cells/` | The three reconstructions, their licence and citations. |
| `review/` | The attempt to break the validation. |
| `QUESTIONS.md` | Twenty questions a sceptical expert might ask, with answers and evidence. |
| `PRIOR_WORK.md` | The search for existing tools. |
| `DECISIONS.md`, `PROGRESS.md` | Every decision with its reason; where the work stands. |
| `DISCLOSURE.md` | Which AI tool built what. |

## Licences and credit

- The three cell shapes are from NeuroMorpho.Org (RRID:SCR_002145), shared under Creative Commons
  Attribution 4.0. The citations its terms require are in `CELLS.md` and shown on the page.
- The code is under the MIT licence of the repository it sits in ([`../LICENSE`](../LICENSE)).

## Not medical advice

This is an educational tool. It is not a model of any person's nervous system and nothing in it
is medical advice.
