def _plot_9ML(self, sim_name): # @UnusedVariable nml_v = self.nml_cells[sim_name].recording(self.state_variable) plt.plot(nml_v.times, nml_v) for state_var in self.auxiliary_states: s = self.nml_cells[sim_name].recording(state_var) scaled = UnitHandlerNEURON.scale_value(s) plt.plot(s.times, scaled)
def _create_NEURON(self, neuron_name): # ----------------------------------------------------------------- # Set up NEURON section # ----------------------------------------------------------------- self.nrn_cell_sec = neuron.h.Section() try: self.nrn_cell = eval( 'neuron.h.{}(0.5, sec=self.nrn_cell_sec)'.format(neuron_name)) except TypeError: self.nrn_cell_sec.insert(neuron_name) self.nrn_cell = getattr(self.nrn_cell_sec(0.5), neuron_name) self.nrn_cell_sec.L = 10 self.nrn_cell_sec.diam = 10 / numpy.pi self.nrn_cell_sec.cm = 1.0 for mech_name in self.extra_mechanisms: self.nrn_cell_sec.insert(mech_name) if self.extra_point_process is not None: MechClass = getattr(neuron.h, self.extra_point_process) self.extra_point_process = MechClass(self.nrn_cell_sec(0.5)) for prop in self.properties.properties: name = prop.name value = prop.value try: varname, scale = self.neuron_translations[name] value = value * scale except (ValueError, KeyError): varname = self.neuron_translations.get(name, name) if varname in self.specific_params: specific_value = UnitHandlerNEURON.to_pq_quantity( Quantity(value, prop.units)) / (100 * (pq.um ** 2)) value = UnitHandlerNEURON.scale_value(specific_value) else: value = UnitHandlerNEURON.scale_value( Quantity(value, prop.units)) if varname is not None: if '.' in varname: mech_name, vname = varname.split('.') try: setattr(getattr(self.nrn_cell_sec(0.5), mech_name), vname, value) except AttributeError: setattr(self.extra_point_process, vname, value) elif varname == 'cm': self.nrn_cell_sec.cm = value else: try: setattr(self.nrn_cell, varname, value) except AttributeError: setattr(self.nrn_cell_sec, varname, value) for name, value in self.initial_states.iteritems(): try: varname, scale = self.neuron_translations[name] value = value * scale except (ValueError, KeyError): varname = self.neuron_translations.get(name, name) value = UnitHandlerNEURON.scale_value( UnitHandlerNEURON.from_pq_quantity(value)) if varname is not None: if '.' in varname: try: setattr(getattr(self.nrn_cell_sec(0.5), mech_name), vname, value) except AttributeError: setattr(self.point_process, vname, value) else: try: setattr(self.nrn_cell, varname, value) except (AttributeError, LookupError): setattr(self.nrn_cell_sec, varname, value) # Specify current injection if self.input_signal is not None: _, signal = self.input_signal self._nrn_iclamp = neuron.h.IClamp(0.5, sec=self.nrn_cell_sec) self._nrn_iclamp.delay = 0.0 self._nrn_iclamp.dur = 1e12 self._nrn_iclamp.amp = 0.0 self._nrn_iclamp_amps = neuron.h.Vector(pq.Quantity(signal, 'nA')) self._nrn_iclamp_times = neuron.h.Vector(pq.Quantity(signal.times, 'ms')) self._nrn_iclamp_amps.play(self._nrn_iclamp._ref_amp, self._nrn_iclamp_times) if self.input_train is not None: port_name, train, connection_properties = self.input_train try: _, scale = self.neuron_translations[port_name] except KeyError: scale = 1.0 # FIXME: Should scale units weight = connection_properties[0].value * scale self._vstim = neuron.h.VecStim() self._vstim_times = neuron.h.Vector(pq.Quantity(train, 'ms')) self._vstim.play(self._vstim_times) target = (self.extra_point_process if self.extra_point_process is not None else self.nrn_cell) self._vstim_con = neuron.h.NetCon( self._vstim, target, sec=self.nrn_cell_sec) self._vstim_con.weight[0] = weight # Record Time from NEURON (neuron.h.._ref_t) self._nrn_rec = self.NEURONRecorder(self.nrn_cell_sec, self.nrn_cell) self._nrn_rec.record(self.neuron_state_variable)