def simulate_FSI_cell(par, par_sim): pid = os.getpid() b2.set_device('cpp_standalone', directory=join( "output", f"standalone-{pid}")) b2.get_device().reinit() b2.get_device().activate( directory=join("output", f"standalone-{pid}")) num = par['num'] input_current = par['i_ext'] eqs = ''' Iapp = input_current(t, i): amp m_inf = 1.0/(1.0+exp(-(vf+24*mV)/(11.5*mV))):1 h_inf = 1.0/(1.0+exp(-(vf+58.3*mV)/(-6.7*mV))):1 n_inf = 1.0/(1.0+exp(-(vf+12.4*mV)/(6.8*mV))):1 a_inf = 1.0/(1.0+exp(-(vf+50*mV)/(20.*mV))):1 b_inf = 1.0/(1.0+exp(-(vf+70*mV)/(-6.*mV))):1 tau_h=0.5*ms+14.0*ms/(1.0+exp(-(vf+60*mV)/(-12.*mV))):second tau_n=(0.087*ms+11.4*ms/(1.0+exp(-(vf+14.6*mV)/(-8.6*mV)))) *(0.087+11.4/(1.0+exp(-(vf-1.3*mV)/(18.7*mV)))) :second membrain_Im = -gNa*m_inf**3 *h*(vf-50*mV) -gK*(n**power_n)*(vf+90*mV) -gL*(vf+70*mV)-gA*a**3*b*(vf+90*mV)+Iapp:amp dh/dt=(h_inf-h)/tau_h :1 dn/dt=(n_inf-n)/tau_n :1 da/dt=(a_inf-a)/(2.*ms) :1 db/dt=(b_inf-b)/(150.*ms) :1 dvf/dt=membrain_Im/Cm :volt ''' neuron = b2.NeuronGroup(num, eqs, method=par_sim['integration_method'], dt=par_sim['dt'], threshold='vf>-20*mV', refractory='vf>-20*mV', namespace=par, ) neuron.vf = par['v0'] neuron.h = "h_inf" neuron.n = "n_inf" neuron.a = "a_inf" neuron.b = "b_inf" st_mon = b2.StateMonitor(neuron, ["vf", "Iapp"], record=True) net = b2.Network(neuron) net.add(st_mon) net.run(par_sim['simulation_time']) return st_mon
def timed_run(self, duration): ''' Do a timed run. This means that for RuntimeDevice it will run for defaultclock.dt before running for the rest of the duration. This means total run duration will be duration+defaultclock.dt. For standalone devices, this feature may or may not be implemented. ''' if isinstance(brian2.get_device(), brian2.devices.RuntimeDevice): brian2.run(brian2.defaultclock.dt, level=1) brian2.run(duration, level=1) else: brian2.run(duration, level=1)
def simulate(tau): b2.start_scope() if standalone_mode: b2.get_device().reinit() b2.get_device().activate(build_on_run=False, directory=directory_name) net = b2.Network() P = b2.PoissonGroup(num_inputs, rates=input_rate) G = b2.NeuronGroup(1, eqs, threshold='v>1', reset='v=0', method='euler') S = b2.Synapses(P, G, on_pre='v += weight') S.connect() M = b2.SpikeMonitor(G) net.add(P) net.add(G) net.add(S) net.add(M) net.run(1000 * b2.ms) if standalone_mode: b2.get_device().build(directory=directory_name, compile=True, run=True, debug=False) return M
def __init__(self, filterbank, targetvar, *args, **kwds): # Make sure we're not in standalone mode (which won't work) if not isinstance(get_device(), RuntimeDevice): raise RuntimeError("Cannot use standalone mode with brian2hears") self.targetvar = targetvar self.filterbank = filterbank filterbank.buffer_init() # Sanitize the clock - does it have the right dt value? if 'clock' in kwds: if int(1/kwds['clock'].dt)!=int(filterbank.samplerate): raise ValueError('Clock should have 1/dt=samplerate') elif 'dt' in kwds: if int(1 / kwds['dt']) != int(filterbank.samplerate): raise ValueError('Require 1/dt=samplerate') else: kwds['dt'] = 1/filterbank.samplerate buffersize = kwds.pop('buffersize', 32) if not isinstance(buffersize, int): if not have_same_dimensions(buffersize, second): raise DimensionMismatchError("buffersize argument should be an integer or in seconds") buffersize = int(buffersize*filterbank.samplerate) self.buffersize = buffersize self.apply_filterbank = ApplyFilterbank(self, targetvar, filterbank, buffersize) NeuronGroup.__init__(self, filterbank.nchannels, *args, **kwds) if self.variables[targetvar].dim is not DIMENSIONLESS: raise DimensionMismatchError("Target variable must be dimensionless") apply_filterbank_output = NetworkOperation(self.apply_filterbank.__call__, when='start', clock=self.clock) self.contained_objects.append(apply_filterbank_output)
def setup_fit(): """ Function sets up simulator in one of the two available modes: runtime or standalone. The `.Simulator` that will be used depends on the currently set `.Device`. In the case of `.CPPStandaloneDevice`, the device will also be reset if it has already run a simulation. Returns ------- simulator : `.Simulator` """ simulators = { 'CPPStandaloneDevice': CPPStandaloneSimulator(), 'RuntimeDevice': RuntimeSimulator() } if isinstance(get_device(), CPPStandaloneDevice): if device.has_been_run is True: get_device().reinit() get_device().activate() return simulators[get_device().__class__.__name__]
def network_sim(): # this line resets Brian's object tracking system, without it, the simulation will crash when run a second time # bb.core.tracking.InstanceFollower.instance_sets = defaultdict(bb.core.tracking.InstanceTrackerSet) bb.start_scope() if faster_run: bb.get_device().reinit() bb.get_device().activate(build_on_run=False, directory='PETH_standalone') network = bb.Network() Pe = bb.NeuronGroup(20000, eqs_exc, threshold='v > -50 * mV', reset='v = -60 * mV', refractory=2. * ms, method='euler', namespace=params) # Pi = bb.NeuronGroup(5000, eqs_inh, threshold='v > -50 * mV', # reset='v = -60 * mV', refractory=2. * ms, method='euler', # namespace=params) C_ee = bb.Synapses(Pe, Pe, model='w:siemens', on_pre='ge+=w') #C_ie = bb.Synapses(Pe, Pi, model='w:siemens', on_pre='ge+=w') i = np.random.randint(20000) j = np.random.randint(20000) C_ee.connect(i=i, j=j) C_ee.w = params['g_ee'] network.add(Pe) network.add(C_ee) network.run(1 * second) if faster_run: bb.get_device().build(directory='PETH_standalone', compile=True, run=True, debug=False) return network
def simulate_MSN_cell(par, par_sim): pid = os.getpid() b2.set_device('cpp_standalone', directory=join("output", f"standalone-{pid}")) b2.get_device().reinit() b2.get_device().activate(directory=join("output", f"standalone-{pid}")) num = par['num'] input_current = par['iapp'] eqs = ''' Iapp = input_current(t): amp am_Na = -0.1*(vm+28*mV)/(1*mV)/(exp(-0.1*(vm+28*mV)/(1*mV))-1) :1 Bm_Na = 4*exp(-(vm+53*mV)/(18.*mV)) :1 ah_Na = 0.07*exp(-(vm+51*mV)/(20.*mV)) :1 Bh_Na = 1/(1+exp(-0.1*(vm+21*mV)/(1.*mV))) :1 minf_Na = am_Na/(am_Na+Bm_Na) :1 dh_Na/dt= 5*(ah_Na*(1-h_Na)-Bh_Na*h_Na) * 1/ms :1 iNa = gnabar*minf_Na**3*h_Na*(vm - eNa) :amp an_K = (-0.01*(vm+27*mV)/(1*mV)/(exp(-0.1*(vm+27*mV)/(1*mV))-1)) :1 Bn_K = 0.125*exp(-(vm+37*mV)/(80.*mV)) :1 dn_K/dt=5*(an_K*(1-n_K)-Bn_K * n_K) * 1/ms :1 iK = gkbar*n_K**4*(vm - eK) :amp iLeak = gleak*(vm - eLeak) :amp minf_Kir=1/(1+exp(-(vm+100*mV)/(-10.*mV))) :1 dm_Kir/dt = (minf_Kir - m_Kir) / tau_m_Kir :1 iKir = gkirbar*m_Kir*(vm - eKir) :amp hinf_Kaf=1/(1+exp(-(vm+70.4*mV)/(-7.6*mV))) :1 minf_Kaf=1/(1+exp(-(vm+33.1*mV)/(7.5*mV))) :1 tau_m_Kaf = 1./tadj *1*ms :second tau_h_Kaf = 25./tadj *1*ms :second dm_Kaf/dt = (minf_Kaf - m_Kaf) / tau_m_Kaf :1 dh_Kaf/dt = (hinf_Kaf - h_Kaf) / tau_h_Kaf :1 iKaf = gkafbar * m_Kaf * h_Kaf*(vm - eKaf) :amp minf_Kas=1/(1+exp(-(vm+25.6*mV)/(13.3*mV))) :1 hinf_Kas=1/(1+exp(-(vm+78.8*mV)/(-10.4*mV))) :1 tau_m_Kas=131.4/(exp(-(vm+37.4*mV)/(27.3*mV))+exp((vm+37.4*mV)/(27.3*mV)))/tadj *1*ms :second tau_h_Kas=(1790+2930*exp(-((vm+38.2*mV)/(28*mV))**2)*((vm+38.2*mV)/(28*mV)))/tadj *1*ms :second dm_Kas/dt = ( minf_Kas - m_Kas ) / tau_m_Kas :1 dh_Kas/dt = ( hinf_Kas - h_Kas ) / tau_h_Kas :1 iKas = gkasbar*m_Kas*h_Kas*(vm - eKas) :amp minf_Krp=1/(1+exp(-(vm+13.4*mV)/(12.1*mV))) :1 hinf_Krp=1/(1+exp(-(vm+55*mV)/(-19*mV))) :1 tau_m_Krp=206.2/(exp(-(vm+53.9*mV)/(26.5*mV))+exp((vm+53.9*mV)/(26.5*mV)))/tadj *1*ms:second tau_h_Krp=3*(1790+2930*exp(-((vm+38.2*mV)/(28*mV))**2)*((vm+38.2*mV)/(28*mV)))/tadj *1*ms :second dm_Krp/dt = ( minf_Krp - m_Krp ) / tau_m_Krp :1 dh_Krp/dt = ( hinf_Krp - h_Krp ) / tau_h_Krp :1 iKrp = gkrpbar*m_Krp*h_Krp*(vm - eKrp) :amp minf_Nap=1/(1+exp(-(vm+47.8*mV)/(3.1*mV))) :1 tau_m_Nap=1/tadj *1*ms:second dm_Nap/dt = (minf_Nap - m_Nap) / tau_m_Nap :1 iNap = gnapbar*m_Nap*(vm - eNap) :amp minf_Nas=1/(1+exp(-(vm+16*mV)/(9.4*mV))) :1 tau_m_Nas=637.8/(exp(-(vm+33.5*mV)/(26.3*mV))+exp((vm+33.5*mV)/(26.3*mV)))/tadj_Nas *1*ms:second dm_Nas/dt = ( minf_Nas - m_Nas ) / tau_m_Nas :1 iNas = gnasbar * m_Nas *(vm - eNas) :amp membrain_Im = Iapp-iLeak-iNa-iK-iKir-iKaf-iKrp-iNap-iNas-iKas :amp dvm/dt = membrain_Im/Cm :volt ''' neuron = b2.NeuronGroup( num, eqs, method=par_sim['integration_method'], dt=par_sim['dt'], threshold='vm>-20*mV', refractory='vm>-20*mV', namespace=par, ) neuron.vm = par['v0'] neuron.h_Na = 'ah_Na/(ah_Na + Bh_Na)' # 'hinf_Na' neuron.n_K = 'an_K/(an_K + Bn_K)' # ninf_K neuron.m_Kir = 'minf_Kir' neuron.m_Kaf = 'minf_Kaf' neuron.h_Kaf = 'hinf_Kaf' neuron.m_Kas = 'minf_Kas' neuron.h_Kas = 'hinf_Kas' neuron.m_Krp = 'minf_Krp' neuron.h_Krp = 'hinf_Krp' neuron.m_Nap = 'minf_Nap' neuron.m_Nas = 'minf_Nas' st_mon = b2.StateMonitor(neuron, par['record_from'], record=True) net = b2.Network(neuron) net.add(st_mon) net.run(par_sim['simulation_time']) return st_mon
def simulate_GPe_cell(par, par_sim): pid = os.getpid() b2.set_device('cpp_standalone', directory=join("output", f"standalone-{pid}")) b2.get_device().reinit() b2.get_device().activate(directory=join("output", f"standalone-{pid}")) num = par['num'] if not par_sim['ADD_SPIKE_MONITOR']: input_current = par['iapp'] eqs = ''' Iapp = input_current(t, i): amp # Iapp :amp minf_Naf = 1.0 / (1.0 + exp((-39*mV - vg)/(5*mV))) :1 hinf_Naf = 1.0 / (1.0 + exp(((-48*mV) - vg)/(-2.8*mV))) :1 sinf_Naf = 0.15 + (1.0 - 0.15)/(1.0 + exp((-40*mV - vg)/(-5.4*mV))) :1 tauh_Naf = 0.25*ms + (3.75*ms)/(exp((-43*mV - vg)/(10.*mV)) + exp((-43*mV - vg)/(-5*mV))) :second taus_Naf = 10*ms + (990*ms)/(exp((-40*mV - vg)/(18.3*mV)) + exp((-40*mV - vg)/(-10*mV))) :second dm_Naf/dt = (minf_Naf - m_Naf)/(0.028*ms) :1 dh_Naf/dt = (hinf_Naf - h_Naf)/tauh_Naf :1 ds_Naf/dt = (sinf_Naf - s_Naf)/taus_Naf :1 iNaf = gnafbar*m_Naf**3*h_Naf*s_Naf*(vg-eNa) :amp minf_Nap = 1.0 / (1.0 + exp((-57.7*mV - vg)/(5.7*mV))) :1 hinf_Nap = 0.154 + (1.0 - 0.154)/ (1.0 + exp((-57*mV - vg)/(-4.*mV))) :1 # sinf_Nap = 1.0 / (1.0 + exp((-10*mV - vg)/(-4.9*mV))) :1 taum_Nap = 0.03*ms + (0.146*ms - 0.03*ms)/(exp((-42.6*mV - vg)/(14.4*mV)) + exp((-42.6*mV - vg)/(-14.4*mV))) :second tauh_Nap = 10*ms + (7*ms)/(exp((-34*mV - vg)/(26.*mV)) + exp((-34*mV - vg)/(-31.9*mV))):second # alphas_Nap = (-2.88e-6 * vg - 4.9e-5*mV)/mV/(1.0 - exp((vg + 17.014*mV)/(4.63*mV))) :1 # betas_Nap = 1/mV*(6.94e-6 * vg + 4.47e-4*mV)/(1.0 - exp((vg + (4.47e-4)/(6.94e-6) * 1*mV)/(2.63*mV))) :1 # taus_Nap = 1.0*ms / (alphas_Nap + betas_Nap) :second dm_Nap/dt = (minf_Nap - m_Nap)/taum_Nap :1 dh_Nap/dt = (hinf_Nap - h_Nap)/tauh_Nap :1 # ds_Nap/dt = (sinf_Nap - s_Nap)/taus_Nap :1 # iNap = gnapbar*m_Nap**3*h_Nap*s_Nap*(vg-eNa) :amp iNap = gnapbar*m_Nap**3*h_Nap*(vg-eNa) :amp iLeak = gleak * (vg-eLeak) :amp minf_Kv2 = 1.0 / (1.0 + exp((-33.2*mV - vg)/(9.1*mV))) :1 hinf_Kv2 = 0.2 + (0.8) / (1.0 + exp((-20*mV - vg)/(-10.*mV))) :1 taum_Kv2 = 0.1*ms + (2.9*ms)/(exp((-33.2*mV - vg)/(21.7*mV)) + exp((-33.2*mV - vg)/(-13.9*mV))) :second dm_Kv2/dt = (minf_Kv2 - m_Kv2)/taum_Kv2 :1 dh_Kv2/dt = (hinf_Kv2 - h_Kv2)/(3400.*ms) :1 iKv2 = gkv2bar*m_Kv2*4*h_Kv2*(vg-eK) :amp minf_Kv3 = 1.0 / (1.0 + exp((-26*mV - vg)/(7.8*mV))) :1 hinf_Kv3 = 0.6 + (0.4) / (1.0 + exp((-20*mV - vg)/(-10.*mV))) :1 taum_Kv3 = 0.1*ms + (13.9*ms)/(exp((-26*mV - vg)/(13.*mV)) + exp((-26*mV - vg)/(-12.*mV))) :second tauh_Kv3 = 7*ms + (26*ms)/(exp((-vg)/(10*mV)) + exp((-vg)/(-10*mV))): second dm_Kv3/dt = (minf_Kv3 - m_Kv3)/taum_Kv3 :1 dh_Kv3/dt = (hinf_Kv3 - h_Kv3)/tauh_Kv3 :1 iKv3 = gkv3bar*m_Kv3**4*h_Kv3*(vg-eK) :amp # this is merged with kv4s # minf_Kv4f = 1.0 / (1.0 + exp((-49*mV - vg)/(12.5*mV))) :1 # hinf_Kv4f = 1.0 / (1.0 + exp((-83*mV - vg)/(-10.*mV))) :1 # taum_Kv4f = 0.25*ms + (6.75*ms)/(exp((-49*mV - vg)/(29*mV)) + exp((-49*mV - vg)/(-29.*mV))) :second # tauh_Kv4f = 7*ms + (14*ms)/(exp((-83*mV - vg)/(10*mV)) + exp((-83*mV - vg)/(-10.*mV))) :second # dm_Kv4f/dt = (minf_Kv4f - m_Kv4f)/taum_Kv4f :1 # dh_Kv4f/dt = (hinf_Kv4f - h_Kv4f)/tauh_Kv4f :1 # iKv4f = gkv4fbar*m_Kv4f**4*h_Kv4f*(vg-eK) :amp minf_Kv4s = 1.0 / (1.0 + exp((-49*mV - vg)/(12.5*mV))) :1 hinf_Kv4s = 1.0 / (1.0 + exp((-83*mV - vg)/(-10.*mV))) :1 taum_Kv4s = 0.25*ms + (6.75*ms)/(exp((-49*mV - vg)/(29*mV)) + exp((-49*mV - vg)/(-29.*mV))) :second tauh_Kv4s = 15*ms + (85*ms)/(exp((-83*mV - vg)/(10*mV)) + exp((-83*mV - vg)/(-10.*mV))) :second dm_Kv4s/dt = (minf_Kv4s - m_Kv4s)/taum_Kv4s :1 dh_Kv4s/dt = (hinf_Kv4s - h_Kv4s)/tauh_Kv4s :1 iKv4s = gkv4sbar*m_Kv4s**4*h_Kv4s*(vg-eK) :amp minf_Kcnq = 1.0 / (1.0 + exp((-61*mV - vg)/(19.5*mV))) :1 taum_Kcnq = 6.7*ms + (93.3*ms)/(exp((-61*mV - vg)/(35.*mV)) + exp((-61*mV - vg)/(-25.*mV))) :second dm_Kcnq/dt = (minf_Kcnq - m_Kcnq)/taum_Kcnq :1 iKcnq = gkcnqbar*m_Kcnq**4*(vg-eK) :amp minf_Hcn = 1.0 / (1.0 + exp((-76.4*mV - vg)/(-3.3*mV))) :1 taumhcn = (3625*ms)/(exp((-76.4*mV - vg)/(6.56*mV)) + exp((-76.4*mV - vg)/(-7.48*mV))) :second taum_Hcn = taumhcn * int(taumhcn >= 0.01*ms) + 0.01*ms * int(taumhcn < 0.01*ms):second dm_Hcn/dt = (minf_Hcn - m_Hcn)/taum_Hcn :1 iHcn = ghcnbar*m_Hcn*(vg-eCat) :amp minf_Cah = 1.0 / (1.0 + exp((-20*mV - vg)/(7.*mV))) :1 dm_Cah/dt = (minf_Cah - m_Cah)/(0.2*ms) :1 iCah = gcahbar*m_Cah*(vg-eCa) :amp # Ca Concentration ---------------------------------------------- dc_Ca/dt = -iCah*3000/(2*96485)/(uA)*(molar/second)- 0.4/ms*(c_Ca - 0.00001*mmolar) : mmolar # SK Current (Ca-dependent) minf_Sk = c_Ca**4.6/(c_Ca**4.6 + Gcan50) :1 tau_m_Sk = (76*ms-72*ms*c_Ca/mmolar/5) * int(c_Ca/mmolar < 5.) + 4*ms * int(c_Ca/mmolar >= 5) :second # tau_m_Sk = 4.0*ms:second dm_Sk/dt = (minf_Sk - m_Sk) / tau_m_Sk :1 iSk = gskbar*m_Sk*(vg-eK) :amp # membrain_Im = Iapp-iNaf-iNap-iLeak-iKv2-iKv3-iKv4s # -iKcnq-iHcn-iCah-iSk :amp membrain_Im = Iapp-iNaf-iLeak-iNap-iKv2-iKv3-iKv4s -iKcnq-iHcn-iCah-iSk :amp dvg/dt = membrain_Im/Cm :volt ''' neuron = b2.NeuronGroup( num, eqs, method=par_sim['integration_method'], dt=par_sim['dt'], threshold='vg>-20*mV', refractory='vg>-20*mV', namespace=par, ) neuron.vg = par['v0'] neuron.m_Naf = 'minf_Naf' neuron.h_Naf = 'hinf_Naf' neuron.s_Naf = 'sinf_Naf' neuron.m_Nap = 'minf_Nap' neuron.h_Nap = 'hinf_Nap' neuron.m_Kv2 = 'minf_Kv2' neuron.h_Kv2 = 'hinf_Kv2' neuron.m_Kv3 = 'minf_Kv3' neuron.h_Kv3 = 'hinf_Kv3' # neuron.m_Kv4f = 'minf_Kv4f' # neuron.h_Kv4f = 'hinf_Kv4f' neuron.m_Kv4s = 'minf_Kv4s' neuron.h_Kv4s = 'hinf_Kv4s' neuron.m_Kcnq = 'minf_Kcnq' neuron.m_Hcn = 'minf_Hcn' neuron.m_Cah = 'minf_Cah' neuron.m_Sk = 'minf_Sk' if par_sim['ADD_SPIKE_MONITOR']: neuron.Iapp = par['iapp'] st_mon = b2.StateMonitor(neuron, par['record_from'], record=True) if par_sim['ADD_SPIKE_MONITOR']: sp_mon = b2.SpikeMonitor(neuron, variables='vg', record=True) net = b2.Network(neuron) net.add(st_mon) if par_sim['ADD_SPIKE_MONITOR']: net.add(sp_mon) net.run(par_sim['simulation_time']) if par_sim['ADD_SPIKE_MONITOR']: return sp_mon, neuron else: return st_mon
def simulate_STN_GPe_population(params): pid = os.getpid() b2.set_device( 'cpp_standalone', # build_on_run=False, directory=join("output", f"standalone-{pid}")) # b2.start_scope() par_s = params['par_s'] par_g = params['par_g'] par_syn = params['par_syn'] par_sim = params['par_sim'] if par_sim['standalone_mode']: b2.get_device().reinit() b2.get_device().activate( # build_on_run=False, directory=join("output", f"standalone-{pid}")) b2.defaultclock.dt = par_sim['dt'] eqs_s = ''' minf = 1/(1+exp(-(vs-thetam*mV)/(sigmam*mV))) : 1 hinf = 1/(1+exp(-(vs-thetah*mV)/(sigmah*mV))) : 1 ninf = 1/(1+exp(-(vs-thetan*mV)/(sigman*mV))) : 1 ainf = 1/(1+exp(-(vs-thetaa*mV)/(sigmaa*mV))) : 1 binf = 1/(1+exp((r-thetab)/sigmab))-1/(1+exp(-thetab/sigmab)) : 1 rinf = 1/(1+exp(-(vs-thetar*mV)/(sigmar*mV))) : 1 sinf = 1/(1+exp(-(vs-thetas*mV)/(sigmas*mV))) : 1 taun = taun0+taun1/(1+exp(-(vs-thn*mV)/(sigmant*mV))) : second tauh = tauh0+tauh1/(1+exp(-(vs-thh*mV)/(sigmaht*mV))) : second taur = taur0+taur1/(1+exp(-(vs-thr*mV)/(sigmart*mV))) : second il = gl * (vs - vl) : amp ina = gna * minf ** 3 * h * (vs - vna) : amp ik = gk * n ** 4 * (vs - vk) : amp iahp = gahp * ca / (ca + k1) * (vs - vk) : amp ica = gca * sinf ** 2 * (vs - vca) : amp it = gt * ainf ** 3 * binf ** 2 * (vs - vca) : amp i_exts : amp i_syn_GtoS : amp s_GtoS_sum : 1 tmp2 = vs - thetag_s *mV : volt # Hinf_s = 1 / (1 + exp(-(tmp2 - thetas*mV) / (sigmas*mV))) : 1 Hinf_s = 1 / (1 + exp(-(tmp2 - thetagH_s*mV) / (sigmagH_s*mV))) : 1 ds_StoG/dt = alphas * Hinf_s * (1 - s_StoG) - betas * s_StoG : 1 dh/dt = phi * (hinf - h) / tauh : 1 dn/dt = phi * (ninf - n) / taun : 1 dr/dt = phir * (rinf - r) / taur : 1 dca/dt = eps * ((-ica - it)/pA - kca* ca) : 1 membrane_Im = -(il + ina + ik + it + ica + iahp)+i_exts+i_syn_GtoS:amp dvs/dt = membrane_Im/C : volt ''' eqs_g = ''' i_extg : amp ainfg = 1 / (1 + exp(-(vg - thetaag*mV) / (sigag*mV))) : 1 sinfg = 1 / (1 + exp(-(vg - thetasg*mV) / (sigsg*mV))) : 1 rinfg = 1 / (1 + exp(-(vg - thetarg*mV) / (sigrg*mV))) : 1 minfg = 1 / (1 + exp(-(vg - thetamg*mV) / (sigmg*mV))) : 1 ninfg = 1 / (1 + exp(-(vg - thetang*mV) / (signg*mV))) : 1 hinfg = 1 / (1 + exp(-(vg - thetahg*mV) / (sighg*mV))) : 1 taung = taun0g + taun1g / (1 + exp(-(vg - thngt*mV) / (sng*mV))) : second tauhg = tauh0g + tauh1g / (1 + exp(-(vg - thhgt*mV) / (shg*mV))) : second dhg/dt = phihg*(hinfg-hg)/tauhg : 1 dng/dt = phing*(ninfg-ng)/taung : 1 drg/dt = phig*(rinfg-rg)/taurg : 1 dcag/dt= epsg*((-icag-itg)/pA - kcag*cag) : 1 dvg/dt = membrane_Im / C : volt tmp1 = vg - thetag_g *mV : volt # Hinf_g = 1 / (1 + exp(-(tmp1 - thetasg*mV) / (sigsg*mV))) : 1 Hinf_g = 1 / (1 + exp(-(tmp1 - thetagH_g*mV) / (sigmagH_g*mV))) : 1 ds_GtoS/dt = alphag * (1 - s_GtoS) * Hinf_g - betag * s_GtoS : 1 itg = gtg * (ainfg ** 3) * rg * (vg - vcag) : amp inag = gnag * (minfg ** 3) * hg * (vg - vnag) : amp ikg = gkg * (ng ** 4) * (vg - vkg) : amp iahpg = gahpg * (vg - vkg) * cag / (cag + k1g) : amp icag = gcag * (sinfg ** 2) * (vg - vcag) : amp ilg = glg * (vg - vlg) : amp s_StoG_sum : 1 i_syn_StoG : amp i_syn_GtoG : amp membrane_Im =-(itg+inag+ikg+iahpg+icag+ilg)+i_extg+i_syn_StoG+i_syn_GtoG : amp ''' eqs_syn_GtoS = ''' i_syn_GtoS_post = g_GtoS*s_GtoS_pre*(v_rev_GtoS-vs):amp (summed) ''' eqs_syn_StoG = ''' i_syn_StoG_post = g_StoG*s_StoG_pre*(v_rev_StoG-vg):amp (summed) ''' eqs_syn_GtoG = ''' i_syn_GtoG_post = g_GtoG*s_GtoS_pre*(v_rev_GtoG-vg):amp (summed) ''' #---------------------------------------------------------------# neurons_s = b2.NeuronGroup( par_s['num'], eqs_s, method=par_sim['integration_method'], dt=par_sim['dt'], threshold='vs>-20*mV', refractory='vs>-20*mV', namespace={ **par_s, **par_syn }, ) #---------------------------------------------------------------# neurons_g = b2.NeuronGroup( par_g['num'], eqs_g, method=par_sim['integration_method'], dt=par_sim['dt'], threshold='vg>-20*mV', refractory='vg>-20*mV', namespace={ **par_g, **par_syn }, ) # --------------------------------------------------------------- syn_GtoS = b2.Synapses(neurons_g, neurons_s, eqs_syn_GtoS, method=par_sim['integration_method'], dt=par_sim['dt'], namespace=par_syn) # --------------------------------------------------------------- cols, rows = np.nonzero(par_syn['adj_GtoS']) syn_GtoS.connect(i=rows, j=cols) # syn_GtoS.connect(j='i') # syn_GtoS.connect(j='k for k in range(i-1, i+2)', skip_if_invalid=True) # --------------------------------------------------------------- syn_StoG = b2.Synapses(neurons_s, neurons_g, eqs_syn_StoG, method=par_sim['integration_method'], dt=par_sim['dt'], namespace=par_syn) syn_StoG.connect(j='i') # --------------------------------------------------------------- syn_GtoG = b2.Synapses(neurons_g, neurons_g, eqs_syn_GtoG, method=par_sim['integration_method'], dt=par_sim['dt'], namespace=par_syn) # figure 5, T2002 cols, rows = np.nonzero(par_syn['adj_GtoG']) syn_GtoG.connect(i=rows, j=cols) # syn_GtoG.connect(p=par_syn['p_GtoG'], condition='i != j') # --------------------------------------------------------------- neurons_s.vs = par_s['v0'] neurons_s.h = "hinf" neurons_s.n = "ninf" neurons_s.r = "rinf" neurons_s.ca = 0 neurons_s.i_exts = par_s['i_ext'] neurons_g.vg = par_g['v0'] neurons_g.hg = "hinfg" neurons_g.ng = "ninfg" neurons_g.rg = "rinfg" neurons_g.cag = 0 neurons_g.i_extg = par_g['i_ext'] #---------------------------------------------------------------# state_mon_s = b2.StateMonitor(neurons_s, ["vs", "i_syn_GtoS", "ca"], record=True) state_mon_g = b2.StateMonitor(neurons_g, ["vg", "i_syn_StoG", "cag"], record=True) spike_mon_s = b2.SpikeMonitor(neurons_s) spike_mon_g = b2.SpikeMonitor(neurons_g) lfp_stn = b2.PopulationRateMonitor(neurons_s) lfp_gpe = b2.PopulationRateMonitor(neurons_g) net = b2.Network(neurons_s, neurons_g, state_mon_g, spike_mon_s, state_mon_s, spike_mon_g) net.add(syn_GtoS) net.add(syn_StoG) net.add(syn_GtoG) net.add(lfp_gpe) net.add(lfp_stn) net.run(par_sim['simulation_time']) # if par_sim['standalone_mode']: # b2.get_device().build(directory="output", # compile=True, # run=True, # debug=False) monitors = { "state_stn": state_mon_s, "state_gpe": state_mon_g, "spike_stn": spike_mon_s, "spike_gpe": spike_mon_g, "lfp_stn": lfp_stn, "lfp_gpe": lfp_gpe, } return monitors