Skip to main content

sc_neurocore_engine/bindings/channels/
ih_neuron.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Commercial license available
3// © Concepts 1996–2026 Miroslav Šotek. All rights reserved.
4// © Code 2020–2026 Miroslav Šotek. All rights reserved.
5// ORCID: 0009-0009-3560-0851
6// Contact: www.anulum.li | protoscience@anulum.li
7// SC-NeuroCore — Hyperpolarisation-activated current neuron PyO3 binding
8
9use pyo3::exceptions::PyValueError;
10use pyo3::prelude::*;
11use pyo3::types::PyDict;
12
13use crate::neurons;
14
15#[pyclass(name = "IhNeuron", module = "sc_neurocore_engine.sc_neurocore_engine")]
16#[derive(Clone)]
17pub struct PyIhNeuron {
18    inner: neurons::IhNeuron,
19}
20
21#[pymethods]
22impl PyIhNeuron {
23    #[new]
24    fn new() -> Self {
25        Self {
26            inner: neurons::IhNeuron::default(),
27        }
28    }
29
30    fn step(&mut self, current: f64) -> PyResult<i32> {
31        self.inner.try_step(current).map_err(PyValueError::new_err)
32    }
33
34    fn reset(&mut self) {
35        self.inner.reset();
36    }
37
38    fn get_state(&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
39        let state = PyDict::new(py);
40        state.set_item("v", self.inner.v)?;
41        state.set_item("h", self.inner.h)?;
42        state.set_item("n", self.inner.n)?;
43        state.set_item("r", self.inner.r)?;
44        Ok(state.into_any().unbind())
45    }
46}
47
48/// Register the hyperpolarisation-activated current neuron class.
49pub(super) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
50    module.add_class::<PyIhNeuron>()?;
51    Ok(())
52}