From 0da61ab28ccb9b420277061815de3fe415960c6b Mon Sep 17 00:00:00 2001 From: Tanguy Pierre Louis Damart Date: Tue, 15 Mar 2022 13:20:47 +0100 Subject: [PATCH] - Reaplace h.run by hfadvance in the NrnSimulator - Add a check that raises an exception if the voltage gets unrealistic --- bluepyopt/ephys/protocols.py | 5 ++++- bluepyopt/ephys/simulators.py | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/bluepyopt/ephys/protocols.py b/bluepyopt/ephys/protocols.py index 43752aff..a658eb7f 100644 --- a/bluepyopt/ephys/protocols.py +++ b/bluepyopt/ephys/protocols.py @@ -171,7 +171,10 @@ def _run_func(self, cell_model, param_values, sim=None): self.instantiate(sim=sim, icell=cell_model.icell) try: - sim.run(self.total_duration, cvode_active=self.cvode_active) + sim.run( + self.total_duration, + cvode_active=self.cvode_active, + icell=cell_model.icell) except (RuntimeError, simulators.NrnSimulatorException): logger.debug( 'SweepProtocol: Running of parameter set {%s} generated ' diff --git a/bluepyopt/ephys/simulators.py b/bluepyopt/ephys/simulators.py index 49deeca0..ca71326f 100644 --- a/bluepyopt/ephys/simulators.py +++ b/bluepyopt/ephys/simulators.py @@ -112,12 +112,19 @@ def neuron(self): return neuron + def check_voltage_valid(self, icell, voltage_bound=200.): + """Raises exception if voltage at soma is out of bound""" + + if icell and abs(icell.soma[0](0.5).v) > voltage_bound: + raise NrnSimulatorException('Membrane potential is out of bound') + def run( self, tstop=None, dt=None, cvode_active=None, - random123_globalindex=None): + random123_globalindex=None, + icell=None): """Run protocol""" self.neuron.h.tstop = tstop @@ -163,7 +170,10 @@ def run( rng.Random123_globalindex(random123_globalindex) try: - self.neuron.h.run() + self.neuron.h.finitialize() + while self.neuron.h.t < self.neuron.h.tstop: + self.neuron.h.fadvance() + self.check_voltage_valid(icell) except Exception as e: raise NrnSimulatorException('Neuron simulator error', e)