"""Lab to Code — 2026 Nobel Prize in Physiology or Medicine (optogenetics): light makes a neuron fire.

A toy integrate-and-fire neuron with a light-gated conductance (not Hodgkin-Huxley, not real optogenetics).
"""
V_rest, V_th, V_reset = -70.0, -55.0, -80.0     # mV
g_leak, g_light, C, dt = 10.0, 8.0, 1.0, 0.1    # conductances, capacitance, time step (ms)

light = [0.0] * 120                             # two blue-light pulses of 1 ms
for k in list(range(20, 30)) + list(range(70, 80)):
    light[k] = 1.0

V, spikes, refractory = V_rest, [], 0
for i in range(120):
    g = g_light * light[i]
    I = -g_leak * (V - V_rest) + g * (0.0 - V)    # light adds a depolarizing conductance
    if refractory:
        V = V_reset
        refractory -= 1
    else:
        V += dt * I / C
        if V == max(V, V_th):                     # same as "V at or above the threshold"
            spikes.append(round(i * dt, 1))
            V = V_reset
            refractory = 3

print("light pulses: 2.0-2.9 ms and 7.0-7.9 ms")
print(f"spikes: {len(spikes)} at {spikes} ms")
