Simulations

Four Simulations You Can Run Here

Each of these reproduces a number from the lesson. They run in your browser — Python compiled to WebAssembly, nothing installed, nothing sent anywhere. Press Run, change the constants, run again.

The figure above each runner is the expected result, so you can see what should happen before waiting for anything to load. The numbers to check: λ = 602 nm, a Landau–Zener agreement of a few hundredths, and a first-spike latency near 9 ms at 5 mW/mm².

⬇ Download the full script (numpy + scipy + matplotlib)

The download uses scipy's adaptive integrator; the browser versions use a hand-written RK4, because scipy is not available in Pyodide. Simulation 2 says what that costs. Code is MIT-licensed.

Simulation 1 — Particle in a box

Steps 3–5 of the Part 1 derivation turned into code. For retinal (N = 12, L = 15.4 Å) it gives ΔE = 2.06 eV and λ = 602 nm, matching the hand calculation.

Particle-in-a-box energy levels with the HOMO to LUMO transition marked.
The six filled levels hold retinal's 12 π electrons. The model's 602 nm overshoots ChR2's measured 470 nm — the gap the protein environment and electron interactions account for.
Loading Python Runner...

Try it: add one bond length to L to mimic wavefunction leakage at the ends, and see how far λ moves.

Simulation 2 — Landau–Zener crossing

The time-dependent Schrödinger equation for the two-state Hamiltonian of Part 2, with the diabatic energies swept linearly through each other (ℏ = 1).

Hop probability against coupling strength: the numerical points lie on the Landau-Zener curve.
As V → 0, the limit of a conical intersection, P → 1: the wavepacket passes straight through, which is why retinal reaches the ground state in a single pass.
Loading Python Runner...

Why this one disagrees slightly. The browser version integrates to a fixed time with a fixed step and lands within a few hundredths of the formula; the downloadable scipy version, with adaptive steps, reaches 0.014. The residual is not step size but the Stückelberg oscillation that has not yet died away at finite time — integrate further with the same step and it gets worse, because the states oscillate faster the further you go.

Try it: halve α (a slower wavepacket) and check that P falls as exp(−2πV²/α) predicts.

Simulation 3 — A light-driven neuron

A two-state model of channelrhodopsin (closed ⇆ open) coupled to the membrane equation of Part 3, with a leaky integrate-and-fire rule. The opening rate comes straight from the photon physics, kopen = σΦ × quantum yield.

\[ \frac{dp}{dt} = k_{\text{open}}(t)\,(1-p) - k_{\text{close}}\,p, \qquad C\,\frac{dV}{dt} = -\frac{V - V_{\text{rest}}}{R} + g_{\max}\,p\,(E_{\text{rev}} - V) \]

Light pulses, channel open fraction and membrane voltage at three irradiances; only the brightest crosses threshold.
At 0.5 and 2 mW/mm² too few channels open and the membrane rises a few millivolts and decays. At 10 mW/mm² the open fraction reaches 0.57 and every pulse fires a spike — the threshold logic of Part 3 made visible, in the 1–10 mW/mm² range used in practice.
Loading Python Runner...

Try it: shorten the pulses to 1 ms, or raise the rate to 50 Hz. The channel's 10 ms closing time is the bottleneck.

Simulation 4 — Spike latency versus light intensity

The same model under continuous light, recording the time to the first spike across irradiances from 0.5 to 30 mW/mm².

First-spike latency falling from about forty milliseconds to a few milliseconds as irradiance rises.
Near the threshold intensity the latency is long, because the membrane creeps up to threshold, just as tth = −τ ln(1 − uth/IR) diverges when IR approaches uth.
Loading Python Runner...

Try it: overlay the analytical tth from Part 3, using I = gmax p∞ × 70 mV with p∞ = kopen / (kopen + kclose). Where and why does it differ?

Limits of these models

Real channelrhodopsin has at least four states, including a desensitised one that lowers the current during long pulses, and a real spike is shaped by voltage-gated Na⁺ and K⁺ channels rather than a reset rule. For research-grade work, swap in a four-state ChR2 model and a Hodgkin–Huxley neuron; the structure of the code stays the same.

Share:XRedditLinkedIn