Skip to content

feat: compute and plot normalised g-V curve with Boltzmann fit (#177)#207

Merged
JCorson merged 7 commits into
mainfrom
issue-177-gv-curve
Apr 13, 2026
Merged

feat: compute and plot normalised g-V curve with Boltzmann fit (#177)#207
JCorson merged 7 commits into
mainfrom
issue-177-gv-curve

Conversation

@JCorson
Copy link
Copy Markdown
Owner

@JCorson JCorson commented Apr 13, 2026

Summary

  • Adds patch_sim/analysis/gv_curve.py with compute_gv() and boltzmann() — computes chord conductance G = I / (V − E_rev), normalises to G/Gmax, and fits a two-parameter Boltzmann sigmoid via scipy.optimize.curve_fit
  • Wires E_Na (core_channels[0].reversal_potential(neuron)) into run_simulation() so g-V is computed automatically after every voltage-clamp multi-sweep run
  • Adds build_gv_figure() (green scatter + dashed Boltzmann fit curve + V½/k annotation) and embeds it below the existing I-V plot in a scrollable container in the I-V Curve analysis tab
  • 16 new tests covering boltzmann() properties, compute_gv() unit behaviour (chord conductance, normalisation, driving-force filtering, Boltzmann parameter recovery, edge cases), and an HH integration test

Test plan

  • All 877 existing tests pass (uv run --frozen --group ui -m pytest)
  • ruff check . and ruff format --check . pass
  • ty check passes
  • Manual: run voltage clamp Step multi-sweep in the UI → I-V Curve tab shows I-V plot followed by g-V plot with Boltzmann fit curve and V½/k annotation
  • Single-sweep and current-clamp runs leave the g-V panel empty (no plot shown)

Closes #177

JCorson added 6 commits April 12, 2026 20:19
Adds GVPoint, BoltzmannFit, GVAnalysisResult dataclasses and
compute_gv() / boltzmann() functions to patch_sim.analysis.
Exports them from both the analysis subpackage and top-level
patch_sim namespace.
16 tests covering boltzmann(), compute_gv() unit behaviour (chord
conductance, normalisation, driving-force filtering, Boltzmann fit
recovery), edge cases (empty input, <2 valid points), and an
integration test against a real HH multi-sweep simulation.
Refactors _compute_iv_data() to return the raw IVAnalysisResult
alongside the serialised dict. Adds _compute_gv_data() which calls
compute_gv() and pre-computes the Boltzmann fit curve. The neuron's
Na+ reversal potential (core_channels[0]) is used as E_rev. gv_data
is stored in AnalysisState and cleared in all non-voltage-clamp paths.
- AnalysisState gets gv_data, has_gv_data, and gv_figure
- build_gv_figure() renders G/Gmax scatter + Boltzmann fit curve
  with V_half and k annotation
- _iv_curve_tab() embeds the g-V plot below the I-V plot in a
  scroll_area when g-V data is available
- Replace Union[float, np.ndarray] with float | np.ndarray in boltzmann()
- Fix __all__ ordering in analysis/__init__.py (boltzmann/compute_gv now
  sorted alphabetically among function names)
- Add explanatory comment on _null_fit sentinel in compute_gv()
- Replace hardcoded core_channels[0] with an explicit Na+ channel lookup
  via NernstSpec/IonSpecies.SODIUM in simulation.py and integration test
Comment thread patch_sim_ui/state/simulation.py Outdated
Instead of silently falling back to core_channels[0] (which could be
any channel), set gv_data to {} so the plot stays empty rather than
showing a g-V curve computed against an arbitrary reversal potential.
@JCorson JCorson merged commit f8dd0a6 into main Apr 13, 2026
1 check passed
@JCorson JCorson deleted the issue-177-gv-curve branch April 13, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compute and plot normalised conductance vs. voltage (g-V curve)

1 participant