Ejemplo n.º 1
0
def placeNMDA(location, conductance):
    eSynlist.append(h.ProbAMPANMDA2_RATIO(float(location)))

    eSynlist[-1].gmax = conductance
    eSynlist[-1].mgVoltageCoeff = 0.08
    eNetconlist.append(h.NetCon(E_vcs[-1], eSynlist[-1]))
    eNetconlist[-1].weight[0] = 1
    eNetconlist[-1].delay = 0
Ejemplo n.º 2
0
Archivo: NMDA.py Proyecto: asuhag/HINT
def simulate_single_param(args):
    """
  Simulates a specific input parameter vector
  
  :param args: The parameters for the simulation: 
                 The list of excitatory presynpatic inputs,
                 The list of inhibitory presynpatic inputs,
                 and the input parameter dictionary
  :returns: The voltage trace of the simulation
  """
    from neuron import h
    from neuron import gui
    h.load_file("nrngui.hoc")
    h.load_file("import3d.hoc")

    param_dict = args

    h.dt = 0.025
    h("create soma")
    h("access soma")
    h("nseg = 1")
    h("L = 20")
    h("diam = 20")
    h("insert pas")
    h("cm = 1")
    h("Ra = 100")
    h("forall nseg = 1")
    h("g_pas = 0.00005")
    h("forall e_pas = -70")
    exec('h("tstop = {}")'.format(simulation_length))
    (e_ns, e_pc, e_syn) = (None, None, None)
    (i_ns, i_pc, i_syn) = (None, None, None)

    e_ns = h.NetStim()
    e_ns.interval = 1
    e_ns.number = 1
    e_ns.start = 100
    e_ns.noise = 0
    e_syn = h.ProbAMPANMDA2_RATIO(0.5)
    e_syn.gmax = 1
    e_syn.mgVoltageCoeff = 0.08
    e_pc = h.NetCon(e_ns, e_syn)
    e_pc.weight[0] = 1
    e_pc.delay = 0

    i_ns = h.NetStim()
    i_ns.interval = 1
    i_ns.number = 1
    i_ns.start = 100
    i_ns.noise = 0

    i_syn = h.ProbUDFsyn2_lark(0.5)
    i_syn.tau_r = 0.18
    i_syn.tau_d = 5
    i_syn.e = -80
    i_syn.Dep = 0
    i_syn.Fac = 0
    i_syn.Use = 0.6
    i_syn.u0 = 0
    i_syn.gmax = 1

    i_pc = (h.NetCon(i_ns, i_syn))
    i_pc.weight[0] = 1
    i_pc.delay = 0

    delaysVoltageVector = {}

    delayDiff = 1

    h.finitialize()

    nmda_cond = param_dict[0]
    gaba_cond = param_dict[1]
    delay = param_dict[2]

    start = time.time()
    e_syn.gmax = nmda_cond
    i_syn.gmax = gaba_cond
    i_ns.start = 100 + delay
    voltageVector = h.Vector()
    timeVector = h.Vector()
    timeVector.record(h._ref_t)
    voltageVector.record(eval("h.soma(0.5)._ref_v"))
    h.run()

    timeVector = np.array(timeVector)
    voltageVector = np.array(voltageVector)

    trace = {}
    trace['T'] = timeVector
    trace['V'] = np.array(voltageVector)

    del voltageVector, timeVector
    return trace
               0)  #connect the end of the soma to the start of the dendrite

# set number of segement
h("forall { nseg = int((L/(0.1*lambda_f(100))+0.9)/2)*2 + 1  }")
h.define_shape()

#########################
# # Set up experiment # #
#########################

#We create 20 AMPA_NMDA synapses:
hotspot_NMDA_synapses = []
hotspot_NMDA_netcons = []
hotspot_NMDA_netstims = []
for j in range(20):
    hotspot_NMDA_synapses.append(h.ProbAMPANMDA2_RATIO(0.6, sec=h.dend))
    hotspot_NMDA_netstims.append(h.NetStim(0.5, sec=h.dend))
    hotspot_NMDA_netcons.append(
        h.NetCon(hotspot_NMDA_netstims[j], hotspot_NMDA_synapses[j]))

    hotspot_NMDA_synapses[j].tau_r_AMPA = 0.33  # AMPA rise time
    hotspot_NMDA_synapses[j].tau_d_AMPA = 1  # AMPA decay time
    hotspot_NMDA_synapses[j].e = 0
    hotspot_NMDA_synapses[j].tau_r_NMDA = 0.23  # NMDA rise time
    hotspot_NMDA_synapses[j].tau_d_NMDA = 55  # NMDA decay time

    hotspot_NMDA_netcons[j].weight[0] = 0.5  # strength of the synapse

    hotspot_NMDA_netstims[j].number = 9e9  # number of synaptic activation
    hotspot_NMDA_netstims[j].noise = 1  # randomness
    hotspot_NMDA_netstims[
def PutSyns(comp_obj, syn_locs, syn_type_string, weight=None):
    """
	Arguments (by order):
		- section object on which to put synapses
		- array of locations of synapses along the given section
		- string indicating which synapse (exc / inh)
	
	Outputs:
		- synapses: array of synapse objects
		- netstim: array of netstims
		- netcon: array of netcons
	"""

    synapses, netstim, netcon = [], [], []
    for loc in syn_locs:

        if syn_type_string == 'exc':
            if not weight:
                weight = 0.4  # Default value for exc. synapses

            synapses.append(h.ProbAMPANMDA2_RATIO(
                loc, sec=comp_obj))  # Go back to _RATIO!
            netstim.append(h.NetStim(loc, sec=comp_obj))
            netcon.append(h.NetCon(netstim[-1], synapses[-1]))

            # synapses[-1].mgVoltageCoeff = 0.08

            netstim[-1].number = 1
            netstim[-1].interval = 1
            netstim[-1].noise = 0
            netstim[-1].start = exc_tstart

            netcon[-1].weight[
                0] = weight  # Literature says ~30pS for 1 NMDAR which is 0.03 here (here it's [nS])
            netcon[-1].delay = 0

        elif syn_type_string == 'inh':
            if not weight:
                weight = 0.5  # Default value for inh. synapses

            synapses.append(h.ProbUDFsyn2_lark(
                loc, sec=comp_obj))  # Go back to _lark!
            netstim.append(h.NetStim(loc, sec=comp_obj))
            netcon.append(h.NetCon(netstim[-1], synapses[-1]))

            synapses[-1].tau_r = 0.18
            synapses[-1].tau_d = 5
            synapses[-1].e = -80
            synapses[-1].Dep = 0
            synapses[-1].Fac = 0
            synapses[-1].Use = 0.25
            synapses[-1].u0 = 0
            synapses[
                -1].gmax = 0.001  # don't touch - weight conversion factor to (us) times conductance in nS

            netstim[-1].number = 1
            netstim[-1].interval = 1
            netstim[-1].start = inh_tstart
            netstim[-1].noise = 0

            netcon[-1].weight[0] = weight
            netcon[-1].delay = 0

    return synapses, netstim, netcon
dend.connect(soma, 1, 0)  #connect the end of the soma to the start of the dendrite

# set number of segement
h("forall { nseg = int((L/(0.1*lambda_f(100))+0.9)/2)*2 + 1  }")
h.define_shape()

#########################
# # Set up experiment # #
#########################

#We create 20 AMPA_NMDA synapses:
hotspot_NMDA_synapses = []
hotspot_NMDA_netcons  = []
hotspot_NMDA_netstims = []
for j in range(20):
    hotspot_NMDA_synapses.append(h.ProbAMPANMDA2_RATIO(dend(0.6)))
    hotspot_NMDA_netstims.append(h.NetStim())
    hotspot_NMDA_netcons.append(h.NetCon(hotspot_NMDA_netstims[j], hotspot_NMDA_synapses[j]))

    hotspot_NMDA_synapses[j].tau_r_AMPA = 0.33 # AMPA rise time
    hotspot_NMDA_synapses[j].tau_d_AMPA = 1    # AMPA decay time
    hotspot_NMDA_synapses[j].e=0
    hotspot_NMDA_synapses[j].tau_r_NMDA = 0.23 # NMDA rise time
    hotspot_NMDA_synapses[j].tau_d_NMDA = 55   # NMDA decay time


    hotspot_NMDA_netcons[j].weight[0]= 0.5 # strength of the synapse

    hotspot_NMDA_netstims[j].number   = 9e9 # number of synaptic activation
    hotspot_NMDA_netstims[j].noise    = 1   # randomness
    hotspot_NMDA_netstims[j].interval = 50  # mean time between spikes |50 ms = 20 Hz|
Ejemplo n.º 6
0
Archivo: BAP.py Proyecto: asuhag/HINT
def simulate_single_param(args):  
  """
  Simulates a specific input parameter vector
  
  :param args: The parameters for the simulation: 
                 The list of excitatory presynpatic inputs,
                 The list of inhibitory presynpatic inputs,
                 and the input parameter dictionary
  :returns: The voltage trace of the simulation
  """   
  from neuron import h
  from neuron import gui
  h.load_file("nrngui.hoc")
  h.load_file("import3d.hoc")
  
  E_events_list = args[0]
  I_events_list = args[1]
  param_dict = args[2]  
  
  action_potential_at_soma = pickle.load(open('action_potential_at_soma.pickle', 'rb'))
  
  hoc_code = '''h("create soma")
h("access soma")
h("nseg = 1")
h("L = 20")
h("diam = 20")
h("insert pas")
h("cm = 1")
h("Ra = 150")
h("forall nseg = 1")
h("forall e_pas = -90")
h("soma insert Ca_LVAst")
h("soma insert Ca_HVA")
h("soma insert SKv3_1") 
h("soma insert SK_E2 ")
h("soma insert NaTa_t")
h("soma insert CaDynamics_E2")
h("soma insert Im ")
h("soma insert Ih")
h("ek = -85")
h("ena = 50")
h("gIhbar_Ih = 0.0128597")
h("g_pas = 1.0 / 12000 ")
h("celsius = 36")
'''
  
  exec(hoc_code)
  exec('h("tstop = {}")'.format(simulation_length))
  exec('h("v_init = {}")'.format(v_init))
  
  im = h.Impedance()
  h("access soma")
  im.loc(0.5)
  im.compute(0)
  Ri = im.input(0.5)

  h("access soma")
  h("nseg = 1")
  eSynlist = []
  eNetconlist = []
  iSynlist = []
  iNetconlist = []
  E_vcs = []
  I_vcs = []

  eSynlist.append(h.ProbAMPANMDA2_RATIO(0.5))  
  eSynlist[-1].gmax = 0.0004
  eSynlist[-1].mgVoltageCoeff = 0.08

  iSynlist.append(h.ProbUDFsyn2_lark(0.5))
  iSynlist[-1].tau_r = 0.18
  iSynlist[-1].tau_d = 5
  iSynlist[-1].e = - 80
  iSynlist[-1].gmax = 0.001
    
  
  semitrial_start = time.time()
  
  for key in param_dict.keys():
    if key is not "rate_E" and key is not "rate_I":
      h(key + " = " + str(param_dict[key]))
  
  E_events = np.array(E_events_list)[np.argmin(np.abs(np.array(E_events_list).mean(axis=1) - param_dict["rate_E"] / 1000.0))]
  I_events = np.array(I_events_list)[np.argmin(np.abs(np.array(I_events_list).mean(axis=1) - param_dict["rate_I"] / 1000.0))]

  E_vcs_events = []
  I_vcs_events = []
  E_vcs = h.VecStim()
  I_vcs = h.VecStim()

  I_vcs_events.append(h.Vector())
  events = np.where(I_events[:])[0] + 100
  for event in events:
    I_vcs_events[-1].append(event)

  E_vcs_events.append(h.Vector())
  events = np.where(E_events[:])[0] + 100
  for event in events:
    E_vcs_events[-1].append(event)
  
  eNetconlist = h.NetCon(E_vcs, eSynlist[-1])
  eNetconlist.weight[0] = 1
  eNetconlist.delay = 0
  E_vcs.play(E_vcs_events[-1])
  
  iNetconlist = h.NetCon(I_vcs, iSynlist[-1])
  iNetconlist.weight[0] = 1
  iNetconlist.delay = 0
  I_vcs.play(I_vcs_events[-1])

  ### Set the protocol
  
  h.finitialize()
  
  ### Simulate!
  
  prev_voltageVector = h.Vector()
  prev_voltageVector.record(eval("h.soma(0.5)._ref_v"))
  prev_timeVector = h.Vector()
  prev_timeVector.record(h._ref_t)

  h.tstop = 160
  h.run()
  h.tstop = 200

  voltageVector = h.Vector()
  voltageVector.record(eval("h.soma(0.5)._ref_v"))
  timeVector = h.Vector()
  timeVector.record(h._ref_t)

  # Simulate AP

  h('''objref clamp
  soma clamp = new SEClamp(.5)
  {clamp.dur1 = 1e9 clamp.rs=1e9}
  ''')
  
  active_timeVector = h.Vector(np.arange(0, h.tstop, 0.025))
  active_ones = np.array([float(1e9)] * len(active_timeVector))
  play_vector = np.array([0.0] * len(active_timeVector))
  
  action_potential_neuron_vector = h.Vector(list(np.maximum(np.array(prev_voltageVector)[int(150 / 0.025) : int(154 / 0.025)], attenuate_action_potential(np.array(np.copy(action_potential_at_soma)), param_dict["percentage_AP"]))))
  
  active_ones[int(ap_time / 0.025) : int((ap_time + 4) / 0.025)] = 0.00001
  play_vector[int(ap_time / 0.025) : int((ap_time + 4) / 0.025)] = action_potential_neuron_vector
  
  active_ones = h.Vector(active_ones)
  play_vector = h.Vector(play_vector)
  
  play_vector.play(h.clamp._ref_amp1, active_timeVector, 0)
  active_ones.play(h.clamp._ref_rs, active_timeVector, 0)

  h.run()
  
  timeVector = np.array(timeVector)
  voltageVector = np.array(voltageVector)
  
  trace = {}
  trace['T'] = timeVector[4000:]
  trace['V'] = np.array(voltageVector)[4000:]

  h.clamp = None
  active_ones = None
  play_vector = None
  del voltageVector, timeVector, prev_voltageVector, prev_timeVector, action_potential_neuron_vector
  return trace
from neuron import gui
import matplotlib.pyplot as plt
import numpy as np
plt.ion()

##=================== creating cell object ===========================
h.load_file("import3d.hoc")
morphology_file = "morphologies/cell1.asc"
h.load_file("models/L5PCbiophys3.hoc")
h.load_file("models/L5PCtemplate.hoc")
L5PC = h.L5PCtemplate(morphology_file)

##==================== create synapses ===========================

#NMDA synapse
NMDA_synapse = h.ProbAMPANMDA2_RATIO(0.5, sec=L5PC.soma[0])
NMDA_netstim = h.NetStim(0.5, sec=L5PC.soma[0])
NMDA_netcons = h.NetCon(NMDA_netstim, NMDA_synapse)
NMDA_synapse.tau_r_AMPA = 0.33
NMDA_synapse.tau_d_AMPA = 1
NMDA_synapse.e = 0
NMDA_synapse.mgVoltageCoeff = 0.08

NMDA_netstim.number = 1
NMDA_netstim.noise = 0
NMDA_netstim.start = 100

NMDA_netcons.weight[0] = 0.9

#GABA synapse
GABA_synapse = h.Exp2Syn(0.5, sec=L5PC.soma[0])