def generate(): dt = 0.025 simtime = 1000 ################################################################################ ### Build new network net = Network(id="Example7_Brunel2000") net.notes = "Example 7: based on network of Brunel 2000" net.parameters = { "g": 4, "eta": 1, "order": 5, "epsilon": 0.1, "J": 0.1, "delay": 1.5, "tauMem": 20.0, "tauSyn": 0.1, "tauRef": 2.0, "U0": 0.0, "theta": 20.0, } cell = Cell(id="ifcell", pynn_cell="IF_curr_alpha") cell.parameters = { "tau_m": "tauMem", "tau_refrac": "tauRef", "v_rest": "U0", "v_reset": "U0", "v_thresh": "theta", "cm": 0.001, "i_offset": 0, } # cell = Cell(id='hhcell', neuroml2_source_file='test_files/hhcell.cell.nml') net.cells.append(cell) poisson_input = Cell(id="poisson_input", pynn_cell="SpikeSourcePoisson") poisson_input.parameters = { "rate": "1000 * (eta*theta/(J*4*order*epsilon*tauMem)) * (4*order*epsilon)", "start": 0, "duration": 1e9, } net.cells.append(poisson_input) r1 = RectangularRegion(id="region1", x=0, y=0, z=0, width=1000, height=100, depth=1000) net.regions.append(r1) pE = Population( id="Epop", size="4*order", component=cell.id, properties={ "color": ".9 0 0", "radius": 5 }, random_layout=RandomLayout(region=r1.id), ) pEpoisson = Population( id="expoisson", size="4*order", component=poisson_input.id, properties={ "color": "0.9 0.7 0.7", "radius": 3 }, random_layout=RandomLayout(region=r1.id), ) pI = Population( id="Ipop", size="1*order", component=cell.id, properties={ "color": "0 0 .9", "radius": 5 }, random_layout=RandomLayout(region=r1.id), ) pIpoisson = Population( id="inpoisson", size="1*order", component=poisson_input.id, properties={ "color": "0.7 0.7 0.9", "radius": 3 }, random_layout=RandomLayout(region=r1.id), ) net.populations.append(pE) net.populations.append(pEpoisson) net.populations.append(pI) net.populations.append(pIpoisson) net.synapses.append( Synapse( id="ampa", pynn_receptor_type="excitatory", pynn_synapse_type="curr_alpha", parameters={"tau_syn": 0.1}, )) net.synapses.append( Synapse( id="gaba", pynn_receptor_type="inhibitory", pynn_synapse_type="curr_alpha", parameters={"tau_syn": 0.1}, )) delay_ext = dt downscale = 1 J_eff = "J*%s" % (downscale) # synaptic weights, scaled for alpha functions, such that # for constant membrane potential, charge J would be deposited fudge = 0.00041363506632638 # ensures dV = J at V=0 JE = "((%s)/tauSyn)*%s" % (J_eff, fudge) JI = "-1*g*%s" % (JE) net.projections.append( Projection( id="projEinput", presynaptic=pEpoisson.id, postsynaptic=pE.id, synapse="ampa", delay=delay_ext, weight=JE, one_to_one_connector=OneToOneConnector(), )) net.projections.append( Projection( id="projIinput", presynaptic=pIpoisson.id, postsynaptic=pI.id, synapse="ampa", delay=delay_ext, weight=JE, one_to_one_connector=OneToOneConnector(), )) net.projections.append( Projection( id="projEE", presynaptic=pE.id, postsynaptic=pE.id, synapse="ampa", delay="delay", weight=JE, random_connectivity=RandomConnectivity(probability="epsilon"), )) net.projections.append( Projection( id="projEI", presynaptic=pE.id, postsynaptic=pI.id, synapse="ampa", delay="delay", weight=JE, random_connectivity=RandomConnectivity(probability="epsilon"), )) net.projections.append( Projection( id="projIE", presynaptic=pI.id, postsynaptic=pE.id, synapse="gaba", delay="delay", weight=JI, random_connectivity=RandomConnectivity(probability="epsilon"), )) net.projections.append( Projection( id="projII", presynaptic=pI.id, postsynaptic=pI.id, synapse="gaba", delay="delay", weight=JI, random_connectivity=RandomConnectivity(probability="epsilon"), )) # print(net) # print(net.to_json()) new_file = net.to_json_file("%s.json" % net.id) ################################################################################ ### Build Simulation object & save as JSON sim = Simulation( id="SimExample7", network=new_file, duration=simtime, dt=dt, seed=123, record_traces={ pE.id: [0, 1], pI.id: [0, 1] }, record_spikes={ pE.id: "*", pI.id: "*", pEpoisson.id: [0, 1, 2, 3, 4], pIpoisson.id: [0, 1, 2, 3, 4], }, ) sim.to_json_file() return sim, net
from neuromllite import Network, Cell, InputSource, Population, Synapse from neuromllite import Projection, RandomConnectivity, Input, Simulation import sys ################################################################################ ### Build new network net = Network(id="Spikers") net.notes = "Example with spiking entities.." net.parameters = {"N": 10, "weightInput": 10, "input_rate": 40} cell = Cell(id="iafcell", pynn_cell="IF_cond_alpha") cell.parameters = {"tau_refrac": 10} net.cells.append(cell) input_cell = Cell(id="InputCell", pynn_cell="SpikeSourcePoisson") input_cell.parameters = { "start": 0, "duration": 10000000000, "rate": "input_rate" } net.cells.append(input_cell) input_cell_100 = Cell(id="InputCell100", pynn_cell="SpikeSourcePoisson") input_cell_100.parameters = {"start": 0, "duration": 10000000000, "rate": 100} net.cells.append(input_cell_100) input_source_p0 = InputSource(id="poissonFiringSyn", neuroml2_source_file="../test_files/inputs.nml") net.input_sources.append(input_source_p0)
from neuromllite import Projection, RandomConnectivity, Input, Simulation import sys ################################################################################ ### Build new network net = Network(id='PopExample') net.notes = 'Testing...' net.seed = 1234 net.parameters = { 'N': 10, 'fractionE': 0.8, 'weightInput': 1, 'Wei':0.01, 'Wie':0.01} cell = Cell(id='iafcell', pynn_cell='IF_cond_alpha') cell.parameters = { "tau_refrac":0} net.cells.append(cell) input_source = InputSource(id='poissonFiringSyn100Hz', neuroml2_source_file='inputs.nml') net.input_sources.append(input_source) net.input_sources.append(input_source) pE = Population(id='Epop', size='int(N*fractionE)', component=cell.id, properties={'color':'.7 0 0'}) pI = Population(id='Ipop', size='N - int(N*fractionE)', component=cell.id, properties={'color':'0 0 .7'}) net.populations.append(pE) net.populations.append(pI)
def generate(): dt = 0.025 simtime = 500 ################################################################################ ### Build new network net = Network(id='SpikingEI') net.notes = 'SpikingEI' net.parameters = { 'order': 5, 'wee': 8, 'wei': 12, 'wie': -12, 'wii': -3, 'w_scale': 0.001, 'in_rate': 400, 'epsilon': 0.5, 'tauMem': 20.0, 'tauSyn': 0.1, 'tauRef': 2.0 } cell = Cell(id='ifcell', pynn_cell='IF_curr_alpha') cell.parameters = { 'tau_m': 'tauMem', 'tau_refrac': 'tauRef', 'v_rest': -70, 'v_reset': -70, 'v_thresh': -50, 'cm': 0.001, "i_offset": 0 } #cell = Cell(id='hhcell', neuroml2_source_file='test_files/hhcell.cell.nml') net.cells.append(cell) poisson_input = Cell(id='poisson_input', pynn_cell='SpikeSourcePoisson') poisson_input.parameters = {'rate': 'in_rate', 'start': 0, 'duration': 1e9} net.cells.append(poisson_input) r1 = RectangularRegion(id='region1', x=0, y=0, z=0, width=1000, height=100, depth=1000) net.regions.append(r1) pE = Population(id='Excitatory', size='4*order', component=cell.id, properties={ 'color': '.9 0 0', 'radius': 5 }, random_layout=RandomLayout(region=r1.id)) pEpoisson = Population(id='expoisson', size='4*order', component=poisson_input.id, properties={ 'color': '0.9 0.7 0.7', 'radius': 3 }, random_layout=RandomLayout(region=r1.id)) pI = Population(id='Inhibitory', size='1*order', component=cell.id, properties={ 'color': '0 0 .9', 'radius': 5 }, random_layout=RandomLayout(region=r1.id)) pIpoisson = Population(id='inpoisson', size='1*order', component=poisson_input.id, properties={ 'color': '0.7 0.7 0.9', 'radius': 3 }, random_layout=RandomLayout(region=r1.id)) net.populations.append(pE) net.populations.append(pEpoisson) net.populations.append(pI) net.populations.append(pIpoisson) net.synapses.append( Synapse(id='ampa', pynn_receptor_type='excitatory', pynn_synapse_type='curr_alpha', parameters={'tau_syn': 0.1})) net.synapses.append( Synapse(id='gaba', pynn_receptor_type='inhibitory', pynn_synapse_type='curr_alpha', parameters={'tau_syn': 0.1})) delay_ext = dt net.projections.append( Projection(id='projEinput', presynaptic=pEpoisson.id, postsynaptic=pE.id, synapse='ampa', delay=delay_ext, weight=0.01, one_to_one_connector=OneToOneConnector())) net.projections.append( Projection(id='projIinput', presynaptic=pIpoisson.id, postsynaptic=pI.id, synapse='ampa', delay=delay_ext, weight=0.01, one_to_one_connector=OneToOneConnector())) net.projections.append( Projection( id='projEE', presynaptic=pE.id, postsynaptic=pE.id, synapse='ampa', delay=delay_ext, weight='wee * w_scale', random_connectivity=RandomConnectivity(probability='epsilon'))) net.projections.append( Projection( id='projEI', presynaptic=pE.id, postsynaptic=pI.id, synapse='ampa', delay=delay_ext, weight='wei * w_scale', random_connectivity=RandomConnectivity(probability='epsilon'))) net.projections.append( Projection( id='projIE', presynaptic=pI.id, postsynaptic=pE.id, synapse='gaba', delay=delay_ext, weight='wie * w_scale', random_connectivity=RandomConnectivity(probability='epsilon'))) net.projections.append( Projection( id='projII', presynaptic=pI.id, postsynaptic=pI.id, synapse='gaba', delay=delay_ext, weight='wii * w_scale', random_connectivity=RandomConnectivity(probability='epsilon'))) #print(net) #print(net.to_json()) new_file = net.to_json_file('%s.json' % net.id) ################################################################################ ### Build Simulation object & save as JSON sim = Simulation(id='SimSpiking', network=new_file, duration=simtime, dt=dt, seed=123, recordTraces={ pE.id: '*', pI.id: '*' }, recordSpikes={'all': '*'}) sim.to_json_file() return sim, net
from neuromllite import Network, Cell, InputSource, Population, Synapse from neuromllite import Projection, RandomConnectivity, Input, Simulation import sys ################################################################################ ### Build new network net = Network(id='IzhikevichTest') net.notes = 'Example Izhikevich' net.parameters = {'N': 1} cell = Cell(id='izhCell', neuroml2_cell='izhikevich2007Cell') cell.parameters = {} params = {'v0':'-60mV', 'C':'100 pF', 'k':'0.7 nS_per_mV', \ 'vr':'-60 mV', 'vt':'-40 mV', 'vpeak':'35 mV', \ 'a':'0.03 per_ms', 'b':'-2 nS', 'c':'-50 mV', 'd':'100 pA'} for p in params: cell.parameters[p] = p net.parameters[p] = params[p] net.cells.append(cell) pop = Population(id='izhPop', size='1', component=cell.id, properties={'color': '.7 0 0'}) net.populations.append(pop) net.parameters['delay'] = '100ms'
################################################################################ ### Build new network net = Network(id='ArborExample') net.notes = 'Example for testing Arbor' net.parameters = { 'v_init': -50, 'input_amp': 0.190, 'input_del': 100, 'input_dur': 800 } cell = Cell(id='test_arbor_cell', arbor_cell='cable_cell') cell.parameters = {'v_init': 'v_init', 'radius': 3, 'mechanism': 'hh'} net.cells.append(cell) ''' cell2 = Cell(id='testcell2', pynn_cell='IF_cond_alpha') cell2.parameters = { "tau_refrac":5, "i_offset":-.1 } net.cells.append(cell2)''' input_source = InputSource(id='i_clamp', pynn_input='DCSource', parameters={ 'amplitude': 'input_amp', 'start': 'input_del', 'stop': 'input_del+input_dur' })
### Build new network net = Network(id="ArborExample") net.notes = "Example for testing Arbor" net.parameters = { "v_init": -50, "scale": 3, "input_amp": 0.01, "input_del": 50, "input_dur": 5, } cell = Cell(id="test_arbor_cell", arbor_cell="cable_cell") cell.parameters = {"v_init": "v_init", "radius": 3, "mechanism": "hh"} net.cells.append(cell) """ cell2 = Cell(id='testcell2', pynn_cell='IF_cond_alpha') cell2.parameters = { "tau_refrac":5, "i_offset":-.1 } net.cells.append(cell2)""" input_source = InputSource( id="i_clamp", pynn_input="DCSource", parameters={ "amplitude": "input_amp", "start": "input_del", "stop": "input_del+input_dur", },
def generate(): ################################################################################ ### Build new network net = Network(id='Example7_Brunel2000') net.notes = 'Example 7: based on network of Brunel 2000' net.parameters = { 'g': 4, 'eta': 1, 'order': 5, 'epsilon': 0.1, 'J': 0.1, 'delay': 1.5, 'tauMem': 20.0, 'tauSyn': 0.1, 'tauRef': 2.0, 'U0': 0.0, 'theta': 20.0 } cell = Cell(id='ifcell', pynn_cell='IF_curr_alpha') cell.parameters = { 'tau_m': 'tauMem', 'tau_refrac': 'tauRef', 'v_rest': 'U0', 'v_reset': 'U0', 'v_thresh': 'theta', 'cm': 0.001, "i_offset": 0 } #cell = Cell(id='hhcell', neuroml2_source_file='test_files/hhcell.cell.nml') net.cells.append(cell) expoisson = Cell(id='expoisson', pynn_cell='SpikeSourcePoisson') expoisson.parameters = { 'rate': '1000 * (eta*theta/(J*4*order*epsilon*tauMem)) * (4*order*epsilon)', 'start': 0, 'duration': 1e9 } net.cells.append(expoisson) ''' input_source = InputSource(id='iclamp0', pynn_input='DCSource', parameters={'amplitude':0.002, 'start':100., 'stop':900.}) input_source = InputSource(id='poissonFiringSyn', neuroml2_input='poissonFiringSynapse', parameters={'average_rate':"eta", 'synapse':"ampa", 'spike_target':"./ampa"}) net.input_sources.append(input_source)''' pE = Population(id='Epop', size='4*order', component=cell.id, properties={'color': '1 0 0'}) pEpoisson = Population(id='Einput', size='4*order', component=expoisson.id, properties={'color': '.5 0 0'}) pI = Population(id='Ipop', size='1*order', component=cell.id, properties={'color': '0 0 1'}) net.populations.append(pE) net.populations.append(pEpoisson) net.populations.append(pI) net.synapses.append( Synapse(id='ampa', pynn_receptor_type='excitatory', pynn_synapse_type='curr_alpha', parameters={'tau_syn': 0.1})) net.synapses.append( Synapse(id='gaba', pynn_receptor_type='inhibitory', pynn_synapse_type='curr_alpha', parameters={'tau_syn': 0.1})) net.projections.append( Projection(id='projEinput', presynaptic=pEpoisson.id, postsynaptic=pE.id, synapse='ampa', delay=2, weight=0.02, one_to_one_connector=OneToOneConnector())) ''' net.projections.append(Projection(id='projEE', presynaptic=pE.id, postsynaptic=pE.id, synapse='ampa', delay=2, weight=0.002, random_connectivity=RandomConnectivity(probability=.5)))''' net.projections.append( Projection(id='projEI', presynaptic=pE.id, postsynaptic=pI.id, synapse='ampa', delay=2, weight=0.02, random_connectivity=RandomConnectivity(probability=.5))) ''' net.projections.append(Projection(id='projIE', presynaptic=pI.id, postsynaptic=pE.id, synapse='gaba', delay=2, weight=0.02, random_connectivity=RandomConnectivity(probability=.5))) net.inputs.append(Input(id='stim', input_source=input_source.id, population=pE.id, percentage=50))''' #print(net) #print(net.to_json()) new_file = net.to_json_file('%s.json' % net.id) ################################################################################ ### Build Simulation object & save as JSON sim = Simulation(id='SimExample7', network=new_file, duration='1000', dt='0.025', seed=123, recordTraces={ pE.id: '*', pI.id: '*' }, recordSpikes={'all': '*'}) sim.to_json_file() return sim, net
from neuromllite import Network, Cell, InputSource, Population, Synapse, RectangularRegion, RandomLayout from neuromllite import Projection, RandomConnectivity, Input, Simulation import sys ################################################################################ ### Build new network net = Network(id='Example4_PyNN') net.notes = 'Example 4: a network with PyNN cells & inputs' net.parameters = {'input_amp': 0.99} cell = Cell(id='testcell', pynn_cell='IF_cond_alpha') cell.parameters = {"tau_refrac": 5, "i_offset": .1} net.cells.append(cell) cell2 = Cell(id='testcell2', pynn_cell='IF_cond_alpha') cell2.parameters = {"tau_refrac": 5, "i_offset": -.1} net.cells.append(cell2) input_source = InputSource(id='i_clamp', pynn_input='DCSource', parameters={ 'amplitude': 'input_amp', 'start': 200., 'stop': 800. }) net.input_sources.append(input_source) r1 = RectangularRegion(id='region1', x=0, y=0,
from neuromllite import Network, Cell, InputSource, Population, Synapse from neuromllite import Projection, RandomConnectivity, Input, Simulation import sys ################################################################################ ### Build new network net = Network(id='Spikers') net.notes = 'Example with spiking entities..' net.parameters = { 'N': 10, 'weightInput': 10, 'input_rate': 40} cell = Cell(id='iafcell', pynn_cell='IF_cond_alpha') cell.parameters = { "tau_refrac":10 } net.cells.append(cell) input_cell = Cell(id='InputCell', pynn_cell='SpikeSourcePoisson') input_cell.parameters = { 'start': 0, 'duration': 10000000000, 'rate': 'input_rate' } net.cells.append(input_cell) input_cell_100 = Cell(id='InputCell100', pynn_cell='SpikeSourcePoisson') input_cell_100.parameters = { 'start': 0, 'duration': 10000000000, 'rate': 100 } net.cells.append(input_cell_100)
def generate(): dt = 0.025 simtime = 1000 ################################################################################ ### Build new network net = Network(id='ExampleIF') net.notes = 'Example with IF' net.parameters = { 'tauMem': 20.0, 'tauSyn': 0.1, 'tauRef': 2, 'V0': -70, 'theta': -50.0, 'scale': 1, 'in_weight': 0.01, 'in_rate': 50 } ifcell = Cell(id='ifcell', pynn_cell='IF_curr_alpha') ifcell.parameters = { 'tau_m': 'tauMem', 'tau_refrac': 'tauRef', 'v_rest': 'V0', 'v_reset': 'V0', 'v_thresh': 'theta', 'cm': 0.001, "i_offset": 0 } net.cells.append(ifcell) poisson_input = Cell(id='poisson_input', pynn_cell='SpikeSourcePoisson') poisson_input.parameters = {'rate': 'in_rate', 'start': 0, 'duration': 1e9} net.cells.append(poisson_input) r1 = RectangularRegion(id='region1', x=0, y=0, z=0, width=1000, height=100, depth=1000) net.regions.append(r1) pIF = Population(id='IFpop', size='1*scale', component=ifcell.id, properties={ 'color': '.9 0 0', 'radius': 5 }, random_layout=RandomLayout(region=r1.id)) net.populations.append(pIF) pLNP = Population(id='LNPpop', size='1*scale', component=ifcell.id, properties={ 'color': '.9 0.9 0', 'radius': 5 }, random_layout=RandomLayout(region=r1.id)) net.populations.append(pLNP) pEpoisson = Population(id='expoisson', size='10', component=poisson_input.id, properties={ 'color': '0.9 0.7 0.7', 'radius': 3 }, random_layout=RandomLayout(region=r1.id)) net.populations.append(pEpoisson) net.synapses.append( Synapse(id='ampa', pynn_receptor_type='excitatory', pynn_synapse_type='curr_alpha', parameters={'tau_syn': 0.1})) net.projections.append( Projection(id='proj0', presynaptic=pEpoisson.id, postsynaptic=pIF.id, synapse='ampa', delay=0, weight='in_weight', random_connectivity=RandomConnectivity(probability=0.7))) net.projections.append( Projection(id='proj1', presynaptic=pEpoisson.id, postsynaptic=pLNP.id, synapse='ampa', delay=0, weight='in_weight', random_connectivity=RandomConnectivity(probability=0.7))) #print(net) #print(net.to_json()) new_file = net.to_json_file('%s.json' % net.id) ################################################################################ ### Build Simulation object & save as JSON sim = Simulation(id='SimExampleIF', network=new_file, duration=simtime, dt=dt, seed=123, recordTraces={pIF.id: '*'}, recordSpikes={'all': '*'}) sim.to_json_file() return sim, net
def generate(ref='Example6_PyNN', add_inputs=True): ################################################################################ ### Build new network net = Network(id=ref, notes='Another network for PyNN - work in progress...') net.parameters = { 'N_scaling': 0.005, 'layer_height': 400, 'width': 100, 'depth': 100, 'input_weight': 0.1 } cell = Cell(id='CorticalCell', pynn_cell='IF_curr_exp') cell.parameters = { 'cm': 0.25, # nF 'i_offset': 0.0, # nA 'tau_m': 10.0, # ms 'tau_refrac': 2.0, # ms 'v_reset': -65.0, # mV 'v_rest': -65.0, # mV 'v_thresh': -50.0 # mV } net.cells.append(cell) if add_inputs: input_cell = Cell(id='InputCell', pynn_cell='SpikeSourcePoisson') input_cell.parameters = { 'start': 0, 'duration': 10000000000, 'rate': 150 } net.cells.append(input_cell) e_syn = Synapse(id='ampa', pynn_receptor_type='excitatory', pynn_synapse_type='curr_exp', parameters={'tau_syn': 0.5}) net.synapses.append(e_syn) i_syn = Synapse(id='gaba', pynn_receptor_type='inhibitory', pynn_synapse_type='curr_exp', parameters={'tau_syn': 0.5}) net.synapses.append(i_syn) N_full = { 'L23': { 'E': 20683, 'I': 5834 }, 'L4': { 'E': 21915, 'I': 5479 }, 'L5': { 'E': 4850, 'I': 1065 }, 'L6': { 'E': 14395, 'I': 2948 } } scale = 0.1 pops = [] input_pops = [] pop_dict = {} layers = ['L23'] layers = ['L23', 'L4', 'L5', 'L6'] for l in layers: i = 3 - layers.index(l) r = RectangularRegion(id=l, x=0, y=i * net.parameters['layer_height'], z=0, width=net.parameters['width'], height=net.parameters['layer_height'], depth=net.parameters['depth']) net.regions.append(r) for t in ['E', 'I']: try: import opencortex.utils.color as occ if l == 'L23': if t == 'E': color = occ.L23_PRINCIPAL_CELL if t == 'I': color = occ.L23_INTERNEURON if l == 'L4': if t == 'E': color = occ.L4_PRINCIPAL_CELL if t == 'I': color = occ.L4_INTERNEURON if l == 'L5': if t == 'E': color = occ.L5_PRINCIPAL_CELL if t == 'I': color = occ.L5_INTERNEURON if l == 'L6': if t == 'E': color = occ.L6_PRINCIPAL_CELL if t == 'I': color = occ.L6_INTERNEURON except: color = '.8 0 0' if t == 'E' else '0 0 1' pop_id = '%s_%s' % (l, t) pops.append(pop_id) ref = 'l%s%s' % (l[1:], t.lower()) exec( ref + " = Population(id=pop_id, size='int(%s*N_scaling)'%N_full[l][t], component=cell.id, properties={'color':color, 'type':t})" ) exec("%s.random_layout = RandomLayout(region = r.id)" % ref) exec("net.populations.append(%s)" % ref) exec("pop_dict['%s'] = %s" % (pop_id, ref)) if add_inputs: color = '.8 .8 .8' input_id = '%s_%s_input' % (l, t) input_pops.append(input_id) input_ref = 'l%s%s_i' % (l[1:], t.lower()) exec( input_ref + " = Population(id=input_id, size='int(%s*N_scaling)'%N_full[l][t], component=input_cell.id, properties={'color':color})" ) exec("%s.random_layout = RandomLayout(region = r.id)" % input_ref) exec("net.populations.append(%s)" % input_ref) #l23i = Population(id='L23_I', size=int(100*scale), component=cell.id, properties={'color':}) #l23ei = Population(id='L23_E_input', size=int(100*scale), component=input_cell.id) #l23ii = Population(id='L23_I_input', size=int(100*scale), component=input_cell.id) #net.populations.append(l23e) #net.populations.append(l23ei) #net.populations.append(l23i) #net.populations.append(l23ii) conn_probs = [ [0.1009, 0.1689, 0.0437, 0.0818, 0.0323, 0., 0.0076, 0.], [0.1346, 0.1371, 0.0316, 0.0515, 0.0755, 0., 0.0042, 0.], [0.0077, 0.0059, 0.0497, 0.135, 0.0067, 0.0003, 0.0453, 0.], [0.0691, 0.0029, 0.0794, 0.1597, 0.0033, 0., 0.1057, 0.], [0.1004, 0.0622, 0.0505, 0.0057, 0.0831, 0.3726, 0.0204, 0.], [0.0548, 0.0269, 0.0257, 0.0022, 0.06, 0.3158, 0.0086, 0.], [0.0156, 0.0066, 0.0211, 0.0166, 0.0572, 0.0197, 0.0396, 0.2252], [0.0364, 0.001, 0.0034, 0.0005, 0.0277, 0.008, 0.0658, 0.1443] ] if add_inputs: for p in pops: proj = Projection(id='proj_input_%s' % p, presynaptic='%s_input' % p, postsynaptic=p, synapse=e_syn.id, delay=2, weight='input_weight') proj.one_to_one_connector = OneToOneConnector() net.projections.append(proj) for pre_i in range(len(pops)): for post_i in range(len(pops)): pre = pops[pre_i] post = pops[post_i] prob = conn_probs[post_i][pre_i] ####### TODO: check!!!! weight = 1 syn = e_syn if prob > 0: if 'I' in pre: weight = -1 syn = i_syn proj = Projection(id='proj_%s_%s' % (pre, post), presynaptic=pre, postsynaptic=post, synapse=syn.id, delay=1, weight=weight) proj.random_connectivity = RandomConnectivity(probability=prob) net.projections.append(proj) print(net.to_json()) new_file = net.to_json_file('%s.json' % net.id) ################################################################################ ### Build Simulation object & save as JSON recordTraces = {} recordSpikes = {} from neuromllite.utils import evaluate for p in pops: forecast_size = evaluate(pop_dict[p].size, net.parameters) recordTraces[p] = list(range(min(2, forecast_size))) recordSpikes[p] = '*' for ip in input_pops: recordSpikes[ip] = '*' sim = Simulation(id='Sim%s' % net.id, network=new_file, duration='100', dt='0.025', seed=1234, recordTraces=recordTraces, recordSpikes=recordSpikes) sim.to_json_file() return sim, net
def generate(): ################################################################################ ### Build new network net = Network(id='RunStims') net.notes = 'Example with spike producers' net.parameters = { 'rate': 50, 'rateHz': '50Hz', 'periodms': '20ms'} ssp = Cell(id='ssp', pynn_cell='SpikeSourcePoisson') ssp.parameters = { 'rate': 'rate', 'start': 0, 'duration': 1e9} net.cells.append(ssp) sspPop = Population(id='sspPop', size=1, component=ssp.id, properties={'color':'.5 0 0'}) net.populations.append(sspPop) sg = Cell(id='sg', neuroml2_cell='SpikeGenerator') sg.parameters = { 'period': 'periodms'} net.cells.append(sg) sgPop = Population(id='sgPop', size=1, component=sg.id, properties={'color':'.5 0 0'}) net.populations.append(sgPop) sgp = Cell(id='sgp', neuroml2_cell='spikeGeneratorPoisson') sgp.parameters = { 'average_rate': 'rateHz'} net.cells.append(sgp) sgpPop = Population(id='sgpPop', size=1, component=sgp.id, properties={'color':'.5 0 0'}) net.populations.append(sgpPop) net.synapses.append(Synapse(id='ampa', pynn_receptor_type='excitatory', pynn_synapse_type='curr_alpha', parameters={'tau_syn':0.1})) net.synapses.append(Synapse(id='gaba', pynn_receptor_type='inhibitory', pynn_synapse_type='curr_alpha', parameters={'tau_syn':0.1})) #print(net) #print(net.to_json()) new_file = net.to_json_file('%s.json'%net.id) ################################################################################ ### Build Simulation object & save as JSON sim = Simulation(id='SimTest', network=new_file, duration='10000', dt='0.025', seed= 123, recordTraces={'xxx':'*'}, recordSpikes={'all':'*'}) sim.to_json_file() return sim, net
'bkg_rate': 9600 } cell = Cell(id='eifcell', pynn_cell='EIF_cond_alpha_isfa_ista') nesp = defaultParams.neuron_params_default cell.parameters = { 'cm': nesp['C_m'] / 1000, # Capacitance of the membrane in nF 'tau_refrac': nesp['t_ref'], # Duration of refractory period in ms. 'v_spike': 0.0, # Spike detection threshold in mV. https://github.com/nest/nest-simulator/blob/master/models/aeif_cond_alpha.cpp 'v_reset': nesp['V_reset'], # Reset value for V_m after a spike. In mV. 'v_rest': nesp['E_L'], # Resting membrane potential (Leak reversal potential) in mV. 'tau_m': nesp['C_m'] / nesp['g_L'], # Membrane time constant in ms = cm/tau_m*1000.0, C_m/g_L 'i_offset': nesp['I_e'] / 1000, # Offset current in nA 'a': 0, # Subthreshold adaptation conductance in nS. 'b': 0, # Spike-triggered adaptation in nA 'delta_T': 2, # Slope factor in mV. See https://github.com/nest/nest-simulator/blob/master/models/aeif_cond_alpha.cpp 'tau_w': 144.0, # Adaptation time constant in ms. See https://github.com/nest/nest-simulator/blob/master/models/aeif_cond_alpha.cpp 'v_thresh': nesp['V_th'], # Spike initiation threshold in mV } net.cells.append(cell) ssp_pre = Cell(id='ssp_pre', pynn_cell='SpikeSourcePoisson', parameters={
from neuromllite import Projection, RandomConnectivity, Input, Simulation import sys ################################################################################ ### Build new network net = Network(id='SonataExample') net.notes = 'Example for testing Sonata' net.parameters = {'input_amp': 0.190, 'input_del': 100, 'input_dur': 800} cell = Cell(id='testcell', pynn_cell='IF_cond_alpha') cell.parameters = { "i_offset": 0, "cm": 0.117, "tau_m": 22.1, "tau_refrac": 3, "v_reset": -50, "v_rest": -78, "v_thresh": -47 } net.cells.append(cell) ''' cell2 = Cell(id='testcell2', pynn_cell='IF_cond_alpha') cell2.parameters = { "tau_refrac":5, "i_offset":-.1 } net.cells.append(cell2)''' input_source = InputSource(id='i_clamp', pynn_input='DCSource', parameters={ 'amplitude': 'input_amp',
def generate(): dt = 0.025 simtime = 1000 ################################################################################ ### Build new network net = Network(id='Example7_Brunel2000') net.notes = 'Example 7: based on network of Brunel 2000' net.parameters = { 'g': 4, 'eta': 1, 'order': 5, 'epsilon': 0.1, 'J': 0.1, 'delay': 1.5, 'tauMem': 20.0, 'tauSyn': 0.1, 'tauRef': 2.0, 'U0': 0.0, 'theta': 20.0} cell = Cell(id='ifcell', pynn_cell='IF_curr_alpha') cell.parameters = { 'tau_m': 'tauMem', 'tau_refrac': 'tauRef', 'v_rest': 'U0', 'v_reset': 'U0', 'v_thresh': 'theta', 'cm': 0.001, "i_offset": 0} #cell = Cell(id='hhcell', neuroml2_source_file='test_files/hhcell.cell.nml') net.cells.append(cell) poisson_input = Cell(id='poisson_input', pynn_cell='SpikeSourcePoisson') poisson_input.parameters = { 'rate': '1000 * (eta*theta/(J*4*order*epsilon*tauMem)) * (4*order*epsilon)', 'start': 0, 'duration': 1e9} net.cells.append(poisson_input) r1 = RectangularRegion(id='region1', x=0,y=0,z=0,width=1000,height=100,depth=1000) net.regions.append(r1) pE = Population(id='Epop', size='4*order', component=cell.id, properties={'color':'.9 0 0', 'radius':5}, random_layout = RandomLayout(region=r1.id)) pEpoisson = Population(id='expoisson', size='4*order', component=poisson_input.id, properties={'color':'0.9 0.7 0.7', 'radius':3}, random_layout = RandomLayout(region=r1.id)) pI = Population(id='Ipop', size='1*order', component=cell.id, properties={'color':'0 0 .9', 'radius':5}, random_layout = RandomLayout(region=r1.id)) pIpoisson = Population(id='inpoisson', size='1*order', component=poisson_input.id, properties={'color':'0.7 0.7 0.9', 'radius':3}, random_layout = RandomLayout(region=r1.id)) net.populations.append(pE) net.populations.append(pEpoisson) net.populations.append(pI) net.populations.append(pIpoisson) net.synapses.append(Synapse(id='ampa', pynn_receptor_type='excitatory', pynn_synapse_type='curr_alpha', parameters={'tau_syn':0.1})) net.synapses.append(Synapse(id='gaba', pynn_receptor_type='inhibitory', pynn_synapse_type='curr_alpha', parameters={'tau_syn':0.1})) delay_ext = dt downscale = 1 J_eff = 'J*%s'%(downscale) # synaptic weights, scaled for alpha functions, such that # for constant membrane potential, charge J would be deposited fudge = 0.00041363506632638 # ensures dV = J at V=0 JE = '((%s)/tauSyn)*%s'%(J_eff,fudge) JI = '-1*g*%s'%(JE) net.projections.append(Projection(id='projEinput', presynaptic=pEpoisson.id, postsynaptic=pE.id, synapse='ampa', delay=delay_ext, weight=JE, one_to_one_connector=OneToOneConnector())) net.projections.append(Projection(id='projIinput', presynaptic=pIpoisson.id, postsynaptic=pI.id, synapse='ampa', delay=delay_ext, weight=JE, one_to_one_connector=OneToOneConnector())) net.projections.append(Projection(id='projEE', presynaptic=pE.id, postsynaptic=pE.id, synapse='ampa', delay='delay', weight=JE, random_connectivity=RandomConnectivity(probability='epsilon'))) net.projections.append(Projection(id='projEI', presynaptic=pE.id, postsynaptic=pI.id, synapse='ampa', delay='delay', weight=JE, random_connectivity=RandomConnectivity(probability='epsilon'))) net.projections.append(Projection(id='projIE', presynaptic=pI.id, postsynaptic=pE.id, synapse='gaba', delay='delay', weight=JI, random_connectivity=RandomConnectivity(probability='epsilon'))) net.projections.append(Projection(id='projII', presynaptic=pI.id, postsynaptic=pI.id, synapse='gaba', delay='delay', weight=JI, random_connectivity=RandomConnectivity(probability='epsilon'))) #print(net) #print(net.to_json()) new_file = net.to_json_file('%s.json'%net.id) ################################################################################ ### Build Simulation object & save as JSON sim = Simulation(id='SimExample7', network=new_file, duration=simtime, dt=dt, seed= 123, recordTraces={pE.id:[0,1],pI.id:[0,1]}, recordSpikes={pE.id:'*', pI.id:'*',pEpoisson.id:[0,1,2,3,4],pIpoisson.id:[0,1,2,3,4]}) sim.to_json_file() return sim, net
###################### Build the network ###################################### net = Network(id='Joglekar1Network_PyNN') net.notes = 'Joglekar network: a network with PyNN cells & inputs' net.parameters = {'scale': 0.01} ######################## Cell ################################################# cellE = Cell(id='excitatory', pynn_cell='IF_curr_alpha') cellI = Cell(id='inhibitory', pynn_cell='IF_curr_alpha') cellE.parameters = { "tau_m": tauE_m, "cm": cE_m, "v_rest": Vrest, "v_reset": Vreset, "v_thresh": Vt, "tau_refrac": tauRef, "i_offset": (VextE / R) } cellI.parameters = { "tau_m": tauI_m, "cm": cI_m, "v_rest": Vrest, "v_reset": Vreset, "v_thresh": Vt, "tau_refrac": tauRef, "i_offset": (VextI / R) }
def generate(ref="Example6_PyNN", add_inputs=True): ################################################################################ ### Build new network net = Network(id=ref, notes="Another network for PyNN - work in progress...") net.parameters = { "N_scaling": 0.005, "layer_height": 400, "width": 100, "depth": 100, "input_weight": 0.1, } cell = Cell(id="CorticalCell", pynn_cell="IF_curr_exp") cell.parameters = { "cm": 0.25, # nF "i_offset": 0.0, # nA "tau_m": 10.0, # ms "tau_refrac": 2.0, # ms "v_reset": -65.0, # mV "v_rest": -65.0, # mV "v_thresh": -50.0, # mV } net.cells.append(cell) if add_inputs: input_cell = Cell(id="InputCell", pynn_cell="SpikeSourcePoisson") input_cell.parameters = {"start": 0, "duration": 10000000000, "rate": 150} net.cells.append(input_cell) e_syn = Synapse( id="ampa", pynn_receptor_type="excitatory", pynn_synapse_type="curr_exp", parameters={"tau_syn": 0.5}, ) net.synapses.append(e_syn) i_syn = Synapse( id="gaba", pynn_receptor_type="inhibitory", pynn_synapse_type="curr_exp", parameters={"tau_syn": 0.5}, ) net.synapses.append(i_syn) N_full = { "L23": {"E": 20683, "I": 5834}, "L4": {"E": 21915, "I": 5479}, "L5": {"E": 4850, "I": 1065}, "L6": {"E": 14395, "I": 2948}, } scale = 0.1 pops = [] input_pops = [] pop_dict = {} layers = ["L23"] layers = ["L23", "L4", "L5", "L6"] for l in layers: i = 3 - layers.index(l) r = RectangularRegion( id=l, x=0, y=i * net.parameters["layer_height"], z=0, width=net.parameters["width"], height=net.parameters["layer_height"], depth=net.parameters["depth"], ) net.regions.append(r) for t in ["E", "I"]: try: import opencortex.utils.color as occ if l == "L23": if t == "E": color = occ.L23_PRINCIPAL_CELL if t == "I": color = occ.L23_INTERNEURON if l == "L4": if t == "E": color = occ.L4_PRINCIPAL_CELL if t == "I": color = occ.L4_INTERNEURON if l == "L5": if t == "E": color = occ.L5_PRINCIPAL_CELL if t == "I": color = occ.L5_INTERNEURON if l == "L6": if t == "E": color = occ.L6_PRINCIPAL_CELL if t == "I": color = occ.L6_INTERNEURON except: color = ".8 0 0" if t == "E" else "0 0 1" pop_id = "%s_%s" % (l, t) pops.append(pop_id) ref = "l%s%s" % (l[1:], t.lower()) exec( ref + " = Population(id=pop_id, size='int(%s*N_scaling)'%N_full[l][t], component=cell.id, properties={'color':color, 'type':t})" ) exec("%s.random_layout = RandomLayout(region = r.id)" % ref) exec("net.populations.append(%s)" % ref) exec("pop_dict['%s'] = %s" % (pop_id, ref)) if add_inputs: color = ".8 .8 .8" input_id = "%s_%s_input" % (l, t) input_pops.append(input_id) input_ref = "l%s%s_i" % (l[1:], t.lower()) exec( input_ref + " = Population(id=input_id, size='int(%s*N_scaling)'%N_full[l][t], component=input_cell.id, properties={'color':color})" ) exec("%s.random_layout = RandomLayout(region = r.id)" % input_ref) exec("net.populations.append(%s)" % input_ref) # l23i = Population(id='L23_I', size=int(100*scale), component=cell.id, properties={'color':}) # l23ei = Population(id='L23_E_input', size=int(100*scale), component=input_cell.id) # l23ii = Population(id='L23_I_input', size=int(100*scale), component=input_cell.id) # net.populations.append(l23e) # net.populations.append(l23ei) # net.populations.append(l23i) # net.populations.append(l23ii) conn_probs = [ [0.1009, 0.1689, 0.0437, 0.0818, 0.0323, 0.0, 0.0076, 0.0], [0.1346, 0.1371, 0.0316, 0.0515, 0.0755, 0.0, 0.0042, 0.0], [0.0077, 0.0059, 0.0497, 0.135, 0.0067, 0.0003, 0.0453, 0.0], [0.0691, 0.0029, 0.0794, 0.1597, 0.0033, 0.0, 0.1057, 0.0], [0.1004, 0.0622, 0.0505, 0.0057, 0.0831, 0.3726, 0.0204, 0.0], [0.0548, 0.0269, 0.0257, 0.0022, 0.06, 0.3158, 0.0086, 0.0], [0.0156, 0.0066, 0.0211, 0.0166, 0.0572, 0.0197, 0.0396, 0.2252], [0.0364, 0.001, 0.0034, 0.0005, 0.0277, 0.008, 0.0658, 0.1443], ] if add_inputs: for p in pops: proj = Projection( id="proj_input_%s" % p, presynaptic="%s_input" % p, postsynaptic=p, synapse=e_syn.id, delay=2, weight="input_weight", ) proj.one_to_one_connector = OneToOneConnector() net.projections.append(proj) for pre_i in range(len(pops)): for post_i in range(len(pops)): pre = pops[pre_i] post = pops[post_i] prob = conn_probs[post_i][pre_i] ####### TODO: check!!!! weight = 1 syn = e_syn if prob > 0: if "I" in pre: weight = -1 syn = i_syn proj = Projection( id="proj_%s_%s" % (pre, post), presynaptic=pre, postsynaptic=post, synapse=syn.id, delay=1, weight=weight, ) proj.random_connectivity = RandomConnectivity(probability=prob) net.projections.append(proj) print(net.to_json()) new_file = net.to_json_file("%s.json" % net.id) ################################################################################ ### Build Simulation object & save as JSON record_traces = {} record_spikes = {} from neuromllite.utils import evaluate for p in pops: forecast_size = evaluate(pop_dict[p].size, net.parameters) record_traces[p] = list(range(min(2, forecast_size))) record_spikes[p] = "*" for ip in input_pops: record_spikes[ip] = "*" sim = Simulation( id="Sim%s" % net.id, network=new_file, duration="100", dt="0.025", seed=1234, record_traces=record_traces, record_spikes=record_spikes, ) sim.to_json_file() return sim, net