def createPulse(compname, pulsename, duration, amplitude, delay): pulsename = moose.PulseGen('%s' % pulsename) # Define pulse duration, amplitude, and delay (if desired) pulsename.width[0] = duration pulsename.level[0] = amplitude pulsename.delay[0] = delay # Connect the pulse with the compartment defined by user moose.connect(pulsename, 'output', compname, 'injectMsg') return pulsename
def setup_model(): model_container = moose.Neutral('/model') pulse = moose.PulseGen('/model/pulse') pulse.level[0] = 1.0 pulse.delay[0] = 0.5 pulse.width[0] = 0.5 table = moose.Table('%s/tab' % (pulse.path)) moose.connect(table, 'requestOut', pulse, 'getOutputValue') return table
def create_pulse_generator(comp_to_connect, duration, amplitude): ''' Create a pulse generator and connect to a moose compartment. ''' pulse = moose.PulseGen('pulse') pulse.delay[0] = 50E-3 # First delay. pulse.width[0] = duration # Pulse width. pulse.level[0] = amplitude # Pulse amplitude. moose.connect(pulse, 'output', comp_to_connect, 'injectMsg') return pulse
def setupDUT(dt): global cable comp = cable[0] data = moose.Neutral('/data') pg = moose.PulseGen('/data/pg') pg.firstWidth = 25e-3 pg.firstLevel = 1e-10 moose.connect(pg, 'output', comp, 'injectMsg') setupClocks(dt)
def importInputs(self, doc): minputs = moose.Neutral('%s/inputs' % (self.lib.path)) for pg_nml in doc.pulse_generators: pg = moose.PulseGen('%s/%s' % (minputs.path, pg_nml.id)) pg.firstDelay = SI(pg_nml.delay) pg.firstWidth = SI(pg_nml.duration) pg.firstLevel = SI(pg_nml.amplitude) pg.secondDelay = 1e9
def setup_two_cells(): """ Create two cells with leaky integrate and fire compartments. Each cell is a single compartment a1 and b2. a1 is stimulated by a step current injection. The compartment a1 is connected to the compartment b2 through a synaptic channel. """ model = moose.Neutral('/model') data = moose.Neutral('/data') a1 = LIFComp('/model/a1') b2 = LIFComp(moose.copy(a1, '/model', 'b2')) a1.Vthreshold = 10e-3 a1.Vreset = 0 b2.Vthreshold = 10e-3 b2.Vreset = 0 syn = moose.SynChan('%s/syn' % (b2.path)) syn.tau1 = 1e-3 syn.tau2 = 5e-3 syn.Ek = 90e-3 synh = moose.SimpleSynHandler(syn.path + '/synh') moose.connect(synh, 'activationOut', syn, 'activation') synh.synapse.num += 1 # syn.numSynapses = 1 synh.synapse.delay = delayMax moose.connect(b2, 'channel', syn, 'channel') ## Single message works most of the time but occassionally gives a ## core dump # m = moose.connect(a1.spikegen, 'spikeOut', # syn.synapse.vec, 'addSpike') ## With Sparse message and random connectivity I did not get core ## dump. m = moose.connect(a1.spikegen, 'spikeOut', synh.synapse.vec, 'addSpike', 'Sparse') m.setRandomConnectivity(1.0, 1) stim = moose.PulseGen('/model/stim') stim.delay[0] = 100e-3 stim.width[0] = 1e3 stim.level[0] = 11e-9 moose.connect(stim, 'output', a1, 'injectMsg') tables = [] data = moose.Neutral('/data') for c in moose.wildcardFind('/##[ISA=Compartment]'): tab = moose.Table('%s/%s_Vm' % (data.path, c.name)) moose.connect(tab, 'requestOut', c, 'getVm') tables.append(tab) syntab = moose.Table('%s/%s' % (data.path, 'Gk')) moose.connect(syntab, 'requestOut', syn, 'getGk') tables.append(syntab) synh.synapse[0].delay = 1e-3 syn.Gbar = 1e-6 return tables
def create_pulse_generator(gen_name, comp_to_connect, duration, amplitude, delay=50E-3, delay_1=1E9): ''' Create a pulse generator and connect to a moose compartment. ''' pulse = moose.PulseGen(gen_name) pulse.delay[0] = delay # First delay. pulse.width[0] = duration # Pulse width. pulse.level[0] = amplitude # Pulse amplitude. pulse.delay[1] = delay_1 #Don't start next pulse train. moose.connect(pulse, 'output', comp_to_connect, 'injectMsg') return pulse
def testDelete(self): print('Testing delete ...', end=' ') msg = self.src1.connect('raxial', self.dest1, 'axial') src2 = moose.PulseGen('/pulsegen') msg2 = moose.connect(src2, 'output', self.dest1, 'injectMsg') moose.delete(msg) # accessing deleted element should raise error with self.assertRaises(ValueError): p = msg.path p = msg2.path # this should not raise any error
def create_pulse(comp): pulse = moose.PulseGen('/model/stimulus') pulse.delay[0] = 0.01 pulse.level[0] = 7.2e-9 pulse.width[0] = 200e-03 pulse.delay[1] = 1e9 moose.connect(pulse, 'output', comp, 'injectMsg') data = moose.Neutral('/data') pulse_tab = moose.Table('/data/current') moose.connect(pulse_tab, 'requestOut', pulse, 'getOutputValue') return pulse_tab
def setup_stimulation(comp): stim = moose.PulseGen('/model/stimulus') stim.delay[0], stim.level[0] = 20e-3, 1e-9 #Start injection ar 20ms, with 1nanoAmp. stim.width[0], stim.delay[1] = 40e-3, 1e9 #Duration of current is 40ms. moose.connect(stim, 'output', comp, 'injectMsg') data = moose.Neutral('/data') current_tab = moose.Table('/data/current') moose.connect(current_tab, 'requestOut', stim, 'getOutputValue') vm_tab = moose.Table('/data/Vm') moose.connect(vm_tab, 'requestOut', comp, 'getVm') return (current_tab, vm_tab)
def make_pulsegen(containerpath): pulsegen = moose.PulseGen('%s/testpulse' % (containerpath)) pulsegen.firstLevel = 1e-12 pulsegen.firstDelay = 50e-3 pulsegen.firstWidth = 100e-3 pulsegen.secondLevel = -1e-12 pulsegen.secondDelay = 150e-3 pulsegen.secondWidth = 100e-3 pulsegen.count = 3 pulsegen.delay[2] = 1e9 return pulsegen
def stimulus(): global soma global vmtab pulse = moose.PulseGen('/model/pulse') pulse.delay[0] = 50e-3 pulse.width[0] = 100e-3 pulse.level[0] = 1e-9 pulse.delay[1] = 1e9 vmtab = moose.Table('/soma_Vm') moose.connect(pulse, 'output', soma, 'injectMsg') moose.connect(vmtab, 'requestOut', soma, 'getVm')
def test_hsolve_calcium(): for tick in range(0, 7): moose.setClock(tick, 10e-6) moose.setClock(8, 0.005) lib = moose.Neutral('/library') model = moose.loadModel(p_file, 'neuron') assert model, model pulse = moose.PulseGen('/neuron/pulse') inject = 100e-10 chan_proto.chan_proto('/library/SK', param_chan.SK) chan_proto.chan_proto('/library/CaL12', param_chan.Cal) pulse.delay[0] = 8. pulse.width[0] = 500e-12 pulse.level[0] = inject pulse.delay[1] = 1e9 for comp in moose.wildcardFind('/neuron/#[TYPE=Compartment]'): new_comp = moose.element(comp) new_comp.initVm = -.08 difs, difb = td.add_difshells_and_buffers(new_comp, difshell_no, difbuf_no) for name in cond: chan = td.addOneChan(name, cond[name], new_comp) if 'Ca' in name: moose.connect(chan, "IkOut", difs[0], "influx") if 'SK' in name: moose.connect(difs[0], 'concentrationOut', chan, 'concen') data = moose.Neutral('/data') vmtab = moose.Table('/data/Vm') shelltab = moose.Table('/data/Ca') caltab = moose.Table('/data/CaL_Gk') sktab = moose.Table('/data/SK_Gk') moose.connect(vmtab, 'requestOut', moose.element('/neuron/soma'), 'getVm') moose.connect(shelltab, 'requestOut', difs[0], 'getC') moose.connect(caltab, 'requestOut', moose.element('/neuron/soma/CaL12'), 'getGk') moose.connect(sktab, 'requestOut', moose.element('/neuron/soma/SK'), 'getGk') hsolve = moose.HSolve('/neuron/hsolve') hsolve.dt = 10e-6 hsolve.target = ('/neuron/soma') t_stop = 10. moose.reinit() moose.start(t_stop) vec1 = sktab.vector vec2 = shelltab.vector assert_stat(vec1, [0.0, 5.102834e-22, 4.79066e-22, 2.08408e-23]) assert_stat(vec2, [5.0e-5, 5.075007e-5, 5.036985e-5, 2.1950117e-7]) assert len(np.where(sktab.vector < 1e-19)[0]) == 2001 assert len(np.where(shelltab.vector > 50e-6)[0]) == 2000
def setUp(self): self.testId = uuid.uuid4().int self.container = moose.Neutral('test%d' % (self.testId)) self.model = moose.Neutral('%s/model' % (self.container.path)) self.data = moose.Neutral('%s/data' % (self.container.path)) self.soma = create_compartment('%s/soma' % (self.model.path), **compartment_propeties) self.tables = {} tab = moose.Table('%s/Vm' % (self.data.path)) self.tables['Vm'] = tab moose.connect(tab, 'requestOut', self.soma, 'getVm') for channelname, conductance in channel_density.items(): chanclass = eval(channelname) channel = insert_channel(self.soma, chanclass, conductance, density=True) if issubclass(chanclass, KChannel): channel.Ek = erev['K'] elif issubclass(chanclass, NaChannel): channel.Ek = erev['Na'] elif issubclass(chanclass, CaChannel): channel.Ek = erev['Ca'] elif issubclass(chanclass, AR): channel.Ek = erev['AR'] tab = moose.Table('%s/%s' % (self.data.path, channelname)) moose.connect(tab, 'requestOut', channel, 'getGk') self.tables['Gk_' + channel.name] = tab archan = moose.HHChannel(self.soma.path + '/AR') archan.X = 0.0 ca = insert_ca(self.soma, 2.6e7, 50e-3) tab = moose.Table('%s/Ca' % (self.data.path)) self.tables['Ca'] = tab moose.connect(tab, 'requestOut', ca, 'getCa') self.pulsegen = moose.PulseGen('%s/inject' % (self.model.path)) moose.connect(self.pulsegen, 'output', self.soma, 'injectMsg') tab = moose.Table('%s/injection' % (self.data.path)) moose.connect(tab, 'requestOut', self.pulsegen, 'getOutputValue') self.tables['pulsegen'] = tab self.pulsegen.count = len(stimulus) for ii in range(len(stimulus)): self.pulsegen.delay[ii] = stimulus[ii][0] self.pulsegen.width[ii] = stimulus[ii][1] self.pulsegen.level[ii] = stimulus[ii][2] setup_clocks(simdt, plotdt) assign_clocks(self.model, self.data) moose.reinit() start = datetime.now() moose.start(simtime) end = datetime.now() delta = end - start print 'Simulation of %g s finished in %g s' % ( simtime, delta.seconds + delta.microseconds * 1e-6)
def createInputs(self): for inputs in self.network.findall(".//{" + nml_ns + "}inputs"): units = inputs.attrib['units'] if units == 'Physiological Units': # see pg 219 (sec 13.2) of Book of Genesis Vfactor = 1e-3 # V from mV Tfactor = 1e-3 # s from ms Ifactor = 1e-6 # A from microA else: Vfactor = 1.0 Tfactor = 1.0 Ifactor = 1.0 for inputelem in inputs.findall(".//{" + nml_ns + "}input"): inputname = inputelem.attrib['name'] pulseinput = inputelem.find(".//{" + nml_ns + "}pulse_input") if pulseinput is not None: ## If /elec doesn't exists it creates /elec ## and returns a reference to it. If it does, ## it just returns its reference. moose.Neutral('/elec') pulsegen = moose.PulseGen('/elec/pulsegen_' + inputname) iclamp = moose.DiffAmp('/elec/iclamp_' + inputname) iclamp.saturation = 1e6 iclamp.gain = 1.0 pulsegen.trigMode = 0 # free run pulsegen.baseLevel = 0.0 pulsegen.firstDelay = float( pulseinput.attrib['delay']) * Tfactor pulsegen.firstWidth = float( pulseinput.attrib['duration']) * Tfactor pulsegen.firstLevel = float( pulseinput.attrib['amplitude']) * Ifactor pulsegen.secondDelay = 1e6 # to avoid repeat pulsegen.secondLevel = 0.0 pulsegen.secondWidth = 0.0 ## do not set count to 1, let it be at 2 by default ## else it will set secondDelay to 0.0 and repeat the first pulse! #pulsegen.count = 1 moose.connect(pulsegen, 'output', iclamp, 'plusIn') target = inputelem.find(".//{" + nml_ns + "}target") population = target.attrib['population'] for site in target.findall(".//{" + nml_ns + "}site"): cell_id = site.attrib['cell_id'] if 'segment_id' in site.attrib: segment_id = site.attrib['segment_id'] else: segment_id = 0 # default segment_id is specified to be 0 ## population is populationname, self.populationDict[population][0] is cellname cell_name = self.populationDict[population][0] segment_path = self.populationDict[population][1][int(cell_id)].path+'/'+\ self.cellSegmentDict[cell_name][0][segment_id][0] compartment = moose.Compartment(segment_path) moose.connect(iclamp, 'output', compartment, 'injectMsg')
def __init__(self, path, squid): self.path = path moose.Neutral(path) self.pulsegen = moose.PulseGen(path+"/pulse") # holding voltage/current generator self.pulsegen.count = 2 self.pulsegen.firstLevel = 25.0 self.pulsegen.firstWidth = 50.0 self.pulsegen.firstDelay = 2.0 self.pulsegen.secondDelay = 0.0 self.pulsegen.trigMode = 2 self.gate = moose.PulseGen(path + "/gate") # holding voltage/current generator self.gate.level[0] = 1.0 self.gate.delay[0] = 0.0 self.gate.width[0] = 1e9 moose.connect(self.gate, "output", self.pulsegen, "input") self.lowpass = moose.RC(path + "/lowpass") # lowpass filter self.lowpass.R = 1.0 self.lowpass.C = 0.03 self.vclamp = moose.DiffAmp(path + "/vclamp") self.vclamp.gain = 0.0 self.vclamp.saturation = 1e10 self.iclamp = moose.DiffAmp(path + "/iclamp") self.iclamp.gain = 0.0 self.iclamp.saturation = 1e10 self.pid = moose.PIDController(path + "/pid") self.pid.gain = 0.5 self.pid.tauI = 0.02 self.pid.tauD = 0.005 self.pid.saturation = 1e10 # Connect current clamp circuitry moose.connect(self.pulsegen, "output", self.iclamp, "plusIn") moose.connect(self.iclamp, "output", squid.C, "injectMsg") # Connect voltage clamp circuitry moose.connect(self.pulsegen, "output", self.lowpass, "injectIn") moose.connect(self.lowpass, "output", self.vclamp, "plusIn") moose.connect(self.vclamp, "output", self.pid, "commandIn") moose.connect(squid.C, "VmOut", self.pid, "sensedIn") moose.connect(self.pid, "output", squid.C, "injectMsg") current_table = moose.Table("/data/Im") moose.connect(current_table, "requestOut", squid.C, "getIm")
def setup_current_step_model(model_container, data_container, celltype, pulsearray): """Setup a single cell simulation. model_container: element to hold the model data_container: element to hold data celltype: str - cell type pulsearray: nx3 array - with row[i] = (delay[i], width[i], level[i]) of current injection. simdt: float - simulation time step plotdt: float - sampling interval for plotting solver: str - numerical method to use, can be `hsolve` or `ee` """ cell_class = eval('cells.%s' % (celltype)) cell = cell_class('%s/%s' % (model_container.path, celltype)) print '111111', cell.path pulsegen = moose.PulseGen('%s/pulse' % (model_container.path)) print '121221211', pulsegen.path pulsegen.count = len(pulsearray) print '7777777', pulsegen.count, pulsegen.id_ for ii in range(len(pulsearray)): print '999999', pulsegen.id_, pulsegen.count print '-', pulsegen.delay[ii] pulsegen.delay[ii] = pulsearray[ii][0] pulsegen.width[ii] = pulsearray[ii][1] pulsegen.level[ii] = pulsearray[ii][2] print '8888888', ii, pulsegen.delay[ii] moose.connect(pulsegen, 'outputOut', cell.soma, 'injectMsg') print '22222' presyn_vm = moose.Table('%s/presynVm' % (data_container.path)) print '33333' soma_vm = moose.Table('%s/somaVm' % (data_container.path)) print '44444' moose.connect(presyn_vm, 'requestData', cell.presynaptic, 'get_Vm') moose.connect(soma_vm, 'requestData', cell.soma, 'get_Vm') pulse_table = moose.Table('%s/injectCurrent' % (data_container.path)) moose.connect(pulse_table, 'requestData', pulsegen, 'get_output') print '55555' return {'cell': cell, 'stimulus': pulsegen, 'presynVm': presyn_vm, 'somaVm': soma_vm, 'injectionCurrent': pulse_table, }
def createNetwork(self): '''setting up of the cells and their connections''' hopfield = moose.Neutral('/hopfield') pg = moose.PulseGen('/hopfield/inPulGen') pgTable = moose.Table('/hopfield/inPulGen/pgTable') moose.connect(pgTable, 'requestOut', pg, 'getOutputValue') pg.firstDelay = 10e-3 pg.firstWidth = 2e-03 pg.firstLevel = 3.0 pg.secondDelay = 1.0 for i in range(self.numNeurons): cellPath = '/hopfield/cell_' + str(i) cell = moose.IntFire(cellPath) cell.setField('tau', 10e-3) cell.setField('refractoryPeriod', 5e-3) cell.setField('thresh', 0.99) cell.synapse.num = self.numNeurons #definite firing everytime ip is given cell.synapse[i].weight = 1.00 #synapse i = input synapse cell.synapse[i].delay = 0.0 #1e-3 #instantaneous #VmVals = moose.Table(cellPath+'/Vm_cell_'+str(i)) #moose.connect(VmVals, 'requestOut', cell, 'getVm') spikeVals = moose.Table(cellPath + '/spike_cell_' + str(i)) moose.connect(cell, 'spike', spikeVals, 'input') inSpkGen = moose.SpikeGen(cellPath + '/inSpkGen') inSpkGen.setField('edgeTriggered', True) inSpkGen.setField('threshold', 2.0) moose.connect(pg, 'output', inSpkGen, 'Vm') #inTable = moose.Table(cellPath+'/inSpkGen/inTable') #moose.connect(inTable, 'requestOut', inSpkGen, 'getHasFired') moose.connect(inSpkGen, 'spikeOut', cell.synapse[i], 'addSpike') #self connection is the input self.inSpike.append(inSpkGen) #self.inTables.append(inTable) #self.Vms.append(VmVals) self.cells.append(cell) self.allSpikes.append(spikeVals) for ii in range(self.numNeurons): for jj in range(self.numNeurons): if ii == jj: continue self.cells[jj].synapse[ii].weight = 0 self.cells[jj].synapse[ii].delay = 20e-3 moose.connect(self.cells[ii], 'spike', self.cells[jj].synapse[ii], 'addSpike')
def test_compartment(): n = moose.Neutral('/model') lib = moose.Neutral('/library') create_na_chan(lib.path) create_k_chan(lib.path) comp = create_compartment('/model/soma') pg = moose.PulseGen('/model/pulse') pg.firstDelay = 50e-3 pg.firstWidth = 40e-3 pg.firstLevel = 1e-9 moose.connect(pg, 'output', comp, 'injectMsg') d = moose.Neutral('/data') vm = moose.Table('/data/Vm') moose.connect(vm, 'requestOut', comp, 'getVm') gK = moose.Table('/data/gK') moose.connect(gK, 'requestOut', moose.element('%s/k' % (comp.path)), 'getGk') gNa = moose.Table('/data/gNa') moose.connect(gNa, 'requestOut', moose.element('%s/na' % (comp.path)), 'getGk') # utils.resetSim(['/model', '/data'], 1e-6, 1e-4, simmethod='ee') assign_clocks(['/model'], 1e-6, 1e-4) simtime = 100e-3 moose.start(simtime) t = np.linspace(0, simtime, len(vm.vector)) plt.subplot(221) plt.title('Vm') plt.plot(t, vm.vector) plt.subplot(222) plt.title('Conductance') plt.plot(t, gK.vector, label='GK') plt.plot(t, gNa.vector, label='GNa') plt.legend() plt.subplot(223) ma = moose.element('%s/na/gateX' % (comp.path)).tableA mb = moose.element('%s/na/gateX' % (comp.path)).tableB ha = moose.element('%s/na/gateY' % (comp.path)).tableA hb = moose.element('%s/na/gateY' % (comp.path)).tableB na = moose.element('%s/k/gateX' % (comp.path)).tableA nb = moose.element('%s/k/gateX' % (comp.path)).tableB plt.plot(1 / mb, label='tau_m') plt.plot(1 / hb, label='tau_h') plt.plot(1 / nb, label='tau_n') plt.legend() plt.subplot(224) plt.plot(ma / mb, label='m_inf') plt.plot(ha / hb, label='h_inf') plt.plot(na / nb, label='n_inf') plt.legend() plt.show() plt.close()
def test_hhcomp(): """Create and simulate a single spherical compartment with Hodgkin-Huxley Na and K channel. Plots Vm, injected current, channel conductances. """ model = moose.Neutral('/model') data = moose.Neutral('/data') comp, na, k = create_hhcomp(parent=model.path) print comp.Rm, comp.Cm, na.Ek, na.Gbar, k.Ek, k.Gbar pg = moose.PulseGen('%s/pg' % (model.path)) pg.firstDelay = 20e-3 pg.firstWidth = 40e-3 pg.firstLevel = 1e-9 pg.secondDelay = 1e9 moose.connect(pg, 'output', comp, 'injectMsg') inj = moose.Table('%s/pulse' % (data.path)) moose.connect(inj, 'requestOut', pg, 'getOutputValue') vm = moose.Table('%s/Vm' % (data.path)) moose.connect(vm, 'requestOut', comp, 'getVm') gK = moose.Table('%s/gK' % (data.path)) moose.connect(gK, 'requestOut', k, 'getGk') gNa = moose.Table('%s/gNa' % (data.path)) moose.connect(gNa, 'requestOut', na, 'getGk') simdt = 1e-6 plotdt = 1e-4 simtime = 100e-3 if (1): moose.showmsg( '/clock' ) for i in range(8): moose.setClock( i, simdt ) moose.setClock( 8, plotdt ) moose.reinit() else: utils.resetSim([model.path, data.path], simdt, plotdt, simmethod='ee') moose.showmsg( '/clock' ) moose.start(simtime) t = np.linspace(0, simtime, len(vm.vector)) plt.subplot(211) plt.plot(t, vm.vector * 1e3, label='Vm (mV)') plt.plot(t, inj.vector * 1e9, label='injected (nA)') plt.legend() plt.title('Vm') plt.subplot(212) plt.title('Conductance (uS)') plt.plot(t, gK.vector * 1e6, label='K') plt.plot(t, gNa.vector * 1e6, label='Na') plt.legend() plt.show() plt.close()
def setup_simulation(comp): stim = moose.PulseGen('/model/stimulus') stim.delay[0] = 20e-3 stim.level[0] = 1e-9 stim.width[0] = 40e-3 stim.delay[1] = 1e9 moose.connect(stim, 'output', comp, 'injectMsg') data = moose.Neutral('/data') # Did not understand this part. current_tab = moose.Table('/data/current') moose.connect(current_tab, 'requestOut', stim, 'getOutputValue') vm_tab = moose.Table('/data/Vm') moose.connect(vm_tab, 'requestOut', comp, 'getVm') return (current_tab, vm_tab)
def example(): pg = moose.PulseGen('pulse') pg.delay[0] = 1.0 pg.width[0] = 0.2 pg.level[0] = 0.5 tab = moose.Table('tab') moose.connect(tab, 'requestOut', pg, 'getOutputValue') moose.setClock(0, 0.01) moose.setClock(1, 0.01) moose.useClock(0, pg.path, 'process') moose.useClock(1, tab.path, 'process') moose.reinit() moose.start(5.0) tab.plainPlot('output_tabledemo.csv')
def _make_pulsegen(self, key, firstLevel, firstDelay, firstWidth=1e6, secondLevel=0, secondDelay=1e6, secondWidth=0, baseLevel=0): pulsegen = moose.PulseGen(self.model_container.path + '/' + key + '_input') pulsegen.firstLevel = firstLevel pulsegen.firstDelay = firstDelay pulsegen.firstWidth = firstWidth pulsegen.secondLevel = secondLevel pulsegen.secondDelay = secondDelay pulsegen.secondWidth = secondWidth pulsegen.baseLevel = baseLevel nrn = self._get_neuron(key) moose.connect(pulsegen, 'output', nrn, 'injectMsg') # self.stimulus_table = moose.Table(self.data_container.path + '/stimulus') # self.stimulus_table.connect('requestOut', pulsegen, 'getOutputValue') return pulsegen
def setup_electronics(model_container, data_container, compartment): """Setup voltage and current clamp circuit using DiffAmp and PID and RC filter""" command = moose.PulseGen('%s/command' % (model_container.path)) command.delay[0] = 20e-3 command.width[0] = 50e-3 command.level[0] = 100e-9 command.delay[1] = 1e9 lowpass = moose.RC('%s/lowpass' % (model_container.path)) lowpass.R = 1.0 lowpass.C = 5e-4 vclamp = moose.DiffAmp('%s/vclamp' % (model_container.path)) vclamp.saturation = 1e10 iclamp = moose.DiffAmp('%s/iclamp' % (model_container.path)) iclamp.gain = 0.0 iclamp.saturation = 1e10 pid = moose.PIDController('%s/pid' % (model_container.path)) pid.gain = compartment.Cm / 100e-6 # Cm/dt is a good number for gain pid.tauI = 100e-6 # same as dt pid.tauD = 0.0 pid.saturation = 1e10 # Current clamp circuit: connect command output to iclamp amplifier # and the output of the amplifier to compartment. moose.connect(command, 'output', iclamp, 'plusIn') moose.connect(iclamp, 'output', compartment, 'injectMsg') # Setup voltage clamp circuit: # 1. Connect command output (which is now command) to lowpass # filter. # 2. Connect lowpass output to vclamp amplifier. # 3. Connect amplifier output to PID's command input. # 4. Connect Vm of compartment to PID's sensed input. # 5. Connect PID output to compartment's injectMsg. moose.connect(command, 'output', lowpass, 'injectIn') moose.connect(lowpass, 'output', vclamp, 'plusIn') moose.connect(vclamp, 'output', pid, 'commandIn') moose.connect(compartment, 'VmOut', pid, 'sensedIn') moose.connect(pid, 'output', compartment, 'injectMsg') command_table = moose.Table('%s/command' % (data_container.path)) moose.connect(command_table, 'requestOut', command, 'getOutputValue') inject_table = moose.Table('%s/inject' % (data_container.path)) moose.connect(inject_table, 'requestOut', compartment, 'getIm') return { 'command_tab': command_table, 'inject_tab': inject_table, 'iclamp': iclamp, 'vclamp': vclamp, 'pid': pid, 'command': command }
def createInput(self, inputelem, Vfactor, Tfactor, Ifactor): """Create input """ inputname = inputelem.attrib['name'] pulseinput = inputelem.find(".//{" + nml_ns + "}pulse_input") if pulseinput is not None: ## If /elec doesn't exists it creates /elec ## and returns a reference to it. If it does, ## it just returns its reference. moose.Neutral('/elec') pulsegen = moose.PulseGen('/elec/pulsegen_' + inputname) iclamp = moose.DiffAmp('/elec/iclamp_' + inputname) iclamp.saturation = 1e6 iclamp.gain = 1.0 pulsegen.trigMode = 0 # free run pulsegen.baseLevel = 0.0 _logger.debug("Tfactor, Ifactor: %s, %s" % (Tfactor, Ifactor)) _logger.debug("Pulsegen attributes: %s" % str(pulseinput.attrib)) pulsegen.firstDelay = float(pulseinput.attrib['delay']) * Tfactor pulsegen.firstWidth = float( pulseinput.attrib['duration']) * Tfactor pulsegen.firstLevel = float( pulseinput.attrib['amplitude']) * Ifactor pulsegen.secondDelay = 1e6 # to avoid repeat pulsegen.secondLevel = 0.0 pulsegen.secondWidth = 0.0 ## do not set count to 1, let it be at 2 by default ## else it will set secondDelay to 0.0 and repeat the first pulse! #pulsegen.count = 1 moose.connect(pulsegen, 'output', iclamp, 'plusIn') target = inputelem.find(".//{" + nml_ns + "}target") population = target.attrib['population'] for site in target.findall(".//{" + nml_ns + "}site"): cell_id = site.attrib['cell_id'] if 'segment_id' in site.attrib: segment_id = site.attrib['segment_id'] else: segment_id = 0 # default segment_id is specified to be 0 ## population is populationname, self.populationDict[population][0] is cellname cell_name = self.populationDict[population][0] segment_path = self.populationDict[population][1][int(cell_id)].path+'/'+\ self.cellSegmentDict[cell_name][0][segment_id][0] compartment = moose.element(segment_path) _logger.debug("Adding pulse at {0}: {1}".format( segment_path, pulsegen.firstLevel)) _logger.debug("Connecting {0}:output to {1}:injectMst".format( iclamp, compartment)) moose.connect(iclamp, 'output', compartment, 'injectMsg')
def test_symcompartment(): """This example demonstrates the use of SymCompartment class of MOOSE.""" model = moose.Neutral('model') soma = moose.SymCompartment('%s/soma' % (model.path)) soma.Em = -60e-3 soma.Rm = 1000402560 soma.Cm = 2.375043912e-11 soma.Ra = 233957.7812 d1 = moose.SymCompartment('%s/d1' % (model.path)) d1.Rm = 397887392 d1.Cm = 2.261946489e-12 d1.Ra = 24867960 d2 = moose.SymCompartment('%s/d2' % (model.path)) d2.Rm = 2.877870285e+10 d2.Cm = 8.256105218e-13 d2.Ra = 20906072 moose.connect(d1, 'proximal', soma, 'distal') moose.connect(d2, 'proximal', soma, 'distal') moose.connect(d1, 'sibling', d2, 'sibling') pg = moose.PulseGen('/model/pulse') pg.delay[0] = 10e-3 pg.width[0] = 20e-3 pg.level[0] = 1e-6 pg.delay[1] = 1e9 moose.connect(pg, 'output', d1, 'injectMsg') data = moose.Neutral('/data') tab_soma = moose.Table('%s/soma_Vm' % (data.path)) tab_d1 = moose.Table('%s/d1_Vm' % (data.path)) tab_d2 = moose.Table('%s/d2_Vm' % (data.path)) moose.connect(tab_soma, 'requestOut', soma, 'getVm') moose.connect(tab_d1, 'requestOut', d1, 'getVm') moose.connect(tab_d2, 'requestOut', d2, 'getVm') moose.setClock(0, simdt) moose.setClock(1, simdt) moose.setClock(2, simdt) moose.useClock( 0, '/model/##[ISA=Compartment]', 'init' ) # This is allowed because SymCompartment is a subclass of Compartment moose.useClock(1, '/model/##', 'process') moose.useClock(2, '/data/##[ISA=Table]', 'process') moose.reinit() moose.start(simtime) t = np.linspace(0, simtime, len(tab_soma.vector)) data_matrix = np.vstack((t, tab_soma.vector, tab_d1.vector, tab_d2.vector)) np.savetxt('symcompartment.txt', data_matrix.transpose()) pylab.plot(t, tab_soma.vector, label='Vm_soma') pylab.plot(t, tab_d1.vector, label='Vm_d1') pylab.plot(t, tab_d2.vector, label='Vm_d2') pylab.show()
def multilevel_pulsegen(): pg = moose.PulseGen('pulsegen') pg.count = 5 for ii in range(pg.count): pg.level[ii] = ii + 1 pg.width[ii] = 0.1 pg.delay[ii] = 0.5 * (ii + 1) tab = moose.Table('tab') moose.connect(tab, 'requestOut', pg, 'getOutputValue') moose.setClock(0, 0.01) moose.useClock(0, '%s,%s' % (pg.path, tab.path), 'process') moose.reinit() moose.start(20.0) plt.plot(tab.vector) plt.show()
def importInputs(self, doc): epath = '%s/inputs' % (self.lib.path) if moose.exists(epath): minputs = moose.element(epath) else: minputs = moose.Neutral(epath) for pg_nml in doc.pulse_generators: epath = '%s/%s' % (minputs.path, pg_nml.id) pg = moose.element(epath) if moose.exists( epath) else moose.PulseGen(epath) pg.firstDelay = SI(pg_nml.delay) pg.firstWidth = SI(pg_nml.duration) pg.firstLevel = SI(pg_nml.amplitude) pg.secondDelay = 1e9
def test_other(): a1 = moose.Pool('/ada') assert a1.className == 'Pool', a1.className finfo = moose.getFieldDict(a1.className) s = moose.Streamer('/asdada') p = moose.PulseGen('pg1') assert p.delay[0] == 0.0 p.delay[1] = 0.99 assert p.delay[1] == 0.99, p.delay[1] c = moose.Stoich('/dadaa') v1 = moose.getFieldNames(c) v2 = c.getFieldNames() assert v1 == v2 assert len(v1) > 10, v1
def setup_vclamp(compartment, name, delay1, width1, level1, gain=0.5e-5): """ Sets up a voltage clamp with 'name' on MOOSE 'compartment' object: adapted from squid.g in DEMOS (moose/genesis) Specify the 'delay1', 'width1' and 'level1' of the voltage to be applied to the compartment. Typically you need to adjust the PID 'gain' For perhaps the Davison 4-compartment mitral or the Davison granule: 0.5e-5 optimal gain - too high 0.5e-4 drives it to oscillate at high frequency, too low 0.5e-6 makes it have an initial overshoot (due to Na channels?) Returns a MOOSE table with the PID output. """ ## If /elec doesn't exists it creates /elec and returns a reference to it. ## If it does, it just returns its reference. moose.Neutral("/elec") pulsegen = moose.PulseGen("/elec/pulsegen" + name) vclamp = moose.DiffAmp("/elec/vclamp" + name) vclamp.saturation = 999.0 vclamp.gain = 1.0 lowpass = moose.RC("/elec/lowpass" + name) lowpass.R = 1.0 lowpass.C = 50e-6 # 50 microseconds tau PID = moose.PIDController("/elec/PID" + name) PID.gain = gain PID.tau_i = 20e-6 PID.tau_d = 5e-6 PID.saturation = 999.0 # All connections should be written as source.connect('',destination,'') pulsegen.connect("outputSrc", lowpass, "injectMsg") lowpass.connect("outputSrc", vclamp, "plusDest") vclamp.connect("outputSrc", PID, "commandDest") PID.connect("outputSrc", compartment, "injectMsg") compartment.connect("VmSrc", PID, "sensedDest") pulsegen.trigMode = 0 # free run pulsegen.baseLevel = -70e-3 pulsegen.firstDelay = delay1 pulsegen.firstWidth = width1 pulsegen.firstLevel = level1 pulsegen.secondDelay = 1e6 pulsegen.secondLevel = -70e-3 pulsegen.secondWidth = 0.0 vclamp_I = moose.Table("/elec/vClampITable" + name) vclamp_I.stepMode = TAB_BUF # TAB_BUF: table acts as a buffer. vclamp_I.connect("inputRequest", PID, "output") vclamp_I.useClock(PLOTCLOCK) return vclamp_I