@@ -184,18 +184,16 @@ def __init__(self, message, original):
184184 self .original = original
185185
186186
187- class LFPySimulator (object ):
187+ class LFPySimulator (NrnSimulator ):
188188
189189 """LFPy simulator"""
190190
191- def __init__ (self , LFPyCellModel , electrode = None , cvode_active = True ,
192- cvode_minstep = None , random123_globalindex = None ,
193- mechanisms_directory = None ):
191+ def __init__ (self , dt = None , cvode_active = True , cvode_minstep = None ,
192+ random123_globalindex = None , mechanisms_directory = None ):
194193 """Constructor
194+
195195 Args:
196- LFPyCellModel (LFPyCellModel): the LFPy cell model
197- electrode (MEAutility.MEA): the MEAutility probe used to compute
198- extracellular signals
196+ dt (float): the integration time step used by neuron.
199197 cvode_active (bool): should neuron use the variable time step
200198 integration method
201199 cvode_minstep (float): the minimum time step allowed for a cvode
@@ -208,81 +206,30 @@ def __init__(self, LFPyCellModel, electrode=None, cvode_active=True,
208206 "./data/".
209207 """
210208
211- self .LFPyCellModel = LFPyCellModel
212- self .electrode = electrode
213- self .effective_electrode = electrode
214-
215- self .lfpyelectrode = None
216-
217- if platform .system () == "Windows" :
218- # hoc.so does not exist on NEURON Windows
219- # although \\hoc.pyd can work here, it gives an error for
220- # nrn_nobanner_ line
221- self .disable_banner = False
222- self .banner_disabled = False
223- else :
224- self .disable_banner = True
225- self .banner_disabled = False
226-
227- self .mechanisms_directory = mechanisms_directory
228- self .neuron .h .load_file ('stdrun.hoc' )
229-
230- self .cvode_active = cvode_active
231- self .cvode_minstep_value = cvode_minstep
232-
233- self .random123_globalindex = random123_globalindex
234-
235- @staticmethod
236- def _nrn_disable_banner ():
237- """Disable Neuron banner"""
238-
239- nrnpy_path = os .path .join (imp .find_module ("neuron" )[1 ])
240- import glob
241-
242- hoc_so_list = glob .glob (os .path .join (nrnpy_path , "hoc*.so" ))
243-
244- if len (hoc_so_list ) != 1 :
245- warnings .warn (
246- "Unable to find Neuron hoc shared library in %s, "
247- "not disabling banner" % nrnpy_path
248- )
249- else :
250- hoc_so = hoc_so_list [0 ]
251- nrndll = ctypes .cdll [hoc_so ]
252- ctypes .c_int .in_dll (nrndll , "nrn_nobanner_" ).value = 1
253-
254- @property
255- def neuron (self ):
256- """Return neuron module"""
257-
258- if self .disable_banner and not self .banner_disabled :
259- NrnSimulator ._nrn_disable_banner ()
260- self .banner_disabled = True
261-
262- import neuron # NOQA
263- if self .mechanisms_directory is not None :
264- neuron .load_mechanisms (
265- self .mechanisms_directory , warn_if_already_loaded = False
266- )
267-
268- return neuron
209+ super (LFPySimulator , self ).__init__ (
210+ dt = dt ,
211+ cvode_active = cvode_active ,
212+ cvode_minstep = cvode_minstep ,
213+ random123_globalindex = random123_globalindex ,
214+ mechanisms_directory = mechanisms_directory
215+ )
269216
270217 def run (
271218 self ,
219+ lfpy_cell ,
220+ lfpy_electrode ,
272221 tstop = None ,
273222 dt = None ,
274223 cvode_active = None ,
275224 random123_globalindex = None ):
276225 """Run protocol"""
277- import LFPy
278- # import neuron mechanisms
279226 _ = self .neuron
280227
281- self . LFPyCellModel . LFPyCell .tstart = 0.0
282- self . LFPyCellModel . LFPyCell .tstop = tstop
228+ lfpy_cell .tstart = 0.0
229+ lfpy_cell .tstop = tstop
283230
284231 if dt is not None :
285- self . LFPyCellModel . LFPyCell .dt = dt
232+ lfpy_cell .dt = dt
286233
287234 if cvode_active and dt is not None :
288235 raise ValueError (
@@ -302,12 +249,7 @@ def run(
302249 rng = self .neuron .h .Random ()
303250 rng .Random123_globalindex (random123_globalindex )
304251
305- if self .effective_electrode is not None :
306- self .lfpyelectrode = LFPy .RecExtElectrode (
307- self .LFPyCellModel .LFPyCell , probe = self .electrode )
308- probes = [self .lfpyelectrode ]
309- else :
310- probes = None
252+ probes = [lfpy_electrode ] if lfpy_electrode is not None else None
311253
312254 sim_params = {
313255 "probes" : probes ,
@@ -324,7 +266,7 @@ def run(
324266 }
325267
326268 try :
327- self . LFPyCellModel . LFPyCell .simulate (** sim_params )
269+ lfpy_cell .simulate (** sim_params )
328270 except Exception as e :
329271 raise LFPySimulatorException ("LFPy simulator error" , e )
330272
0 commit comments