added a synapse with python

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
OronKotler
Posts: 13
Joined: Wed Oct 31, 2018 2:03 pm

added a synapse with python

Post by OronKotler »

Hi, I am trying to add a synapse while opening this HOC file. I get an error when trying to add the synapse.
In addition, when I load the hoc file I can't load the morphology of the cell.

Thank you a lot for your help :D

%%

Code: Select all

//Network cell templates
//   Pre_Cell
//   Post_Cell


begintemplate Pre_Cell
public is_art
public init, topol, basic_shape, subsets, geom, biophys, geom_nseg, biophys_inhomo
public synlist, x, y, z, position, connect2target

public AIS, soma, ApD, BasD, myelin, node
public all, axonal, myelins, nodes

objref synlist

proc init() {
  topol()
  subsets()
  geom()
  biophys()
  geom_nseg()
  biophys_inhomo()
  synlist = new List()
  synapses()
  x = y = z = 0 // only change via position
}

create AIS, soma, ApD, BasD[2], myelin[7], node[7]

proc topol() { local i
  connect soma(0), AIS(0)
  connect ApD(0), soma(1)
  for i = 0, 1 connect BasD[i](0), AIS(0)
  connect myelin(0), AIS(1)
  for i = 1, 6 connect myelin[i](0), node[i-1](1)
  for i = 0, 6 connect node[i](0), myelin[i](1)
  basic_shape()
}
proc basic_shape() {
  AIS {pt3dclear() pt3dadd(-125, 0, 0, 1) pt3dadd(15, 0, 0, 1)}
  soma {pt3dclear() pt3dadd(-125, 0, 0, 1) pt3dadd(-134, 0, 0, 1)}
  ApD {pt3dclear() pt3dadd(-134, 0, 0, 1) pt3dadd(-224, 0, 0, 1)}
  BasD {pt3dclear() pt3dadd(-125, 0, 0, 1) pt3dadd(-89, 75, 0, 1)}
  BasD[1] {pt3dclear() pt3dadd(-125, 0, 0, 1) pt3dadd(-89, -59, 0, 1)}
  myelin {pt3dclear() pt3dadd(15, 0, 0, 1) pt3dadd(90, 0, 0, 1)}
  node {pt3dclear() pt3dadd(90, 0, 0, 1) pt3dadd(105, 0, 0, 1)}
  myelin[1] {pt3dclear() pt3dadd(105, 0, 0, 1) pt3dadd(195, 0, 0, 1)}
  node[1] {pt3dclear() pt3dadd(195, 0, 0, 1) pt3dadd(210, 0, 0, 1)}
  myelin[2] {pt3dclear() pt3dadd(210, 0, 0, 1) pt3dadd(210, 45, 0, 1)}
  node[2] {pt3dclear() pt3dadd(210, 45, 0, 1) pt3dadd(210, 60, 0, 1)}
  myelin[3] {pt3dclear() pt3dadd(210, 60, 0, 1) pt3dadd(210, 90, 0, 1)}
  node[3] {pt3dclear() pt3dadd(210, 90, 0, 1) pt3dadd(210, 105, 0, 1)}
  myelin[4] {pt3dclear() pt3dadd(210, 105, 0, 1) pt3dadd(210, 150, 0, 1)}
  node[4] {pt3dclear() pt3dadd(210, 150, 0, 1) pt3dadd(210, 165, 0, 1)}
  myelin[5] {pt3dclear() pt3dadd(210, 165, 0, 1) pt3dadd(210, 225, 0, 1)}
  node[5] {pt3dclear() pt3dadd(210, 225, 0, 1) pt3dadd(210, 240, 0, 1)}
  myelin[6] {pt3dclear() pt3dadd(210, 240, 0, 1) pt3dadd(210, 270, 0, 1)}
  node[6] {pt3dclear() pt3dadd(210, 270, 0, 1) pt3dadd(210, 285, 0, 1)}
}

objref all, axonal, myelins, nodes
proc subsets() { local i
  objref all, axonal, myelins, nodes
  all = new SectionList()
    AIS all.append()
    soma all.append()
    ApD all.append()
    for i=0, 1 BasD[i] all.append()
    for i=0, 6 myelin[i] all.append()
    for i=0, 6 node[i] all.append()

  axonal = new SectionList()
    AIS axonal.append()

  myelins = new SectionList()
    for i=0, 6 myelin[i] myelins.append()

  nodes = new SectionList()
    for i=0, 6 node[i] nodes.append()

}
proc geom() {
  forsec myelins {  L = 50  diam = 1.2  }
  forsec nodes {  L = 1  diam = 1.2  }
  AIS {  L = 48  diam = 1.2  }
  soma {  L = 35  diam = 23  }
  ApD {  L = 700  diam = 3.5  }
  BasD {  L = 200  diam = 1.2  }
  BasD[1] {  L = 200  diam = 1.2  }
}
external lambda_f
proc geom_nseg() {
   forsec myelins { nseg = 50  }
   forsec nodes { nseg = 5  }
   AIS { nseg = 240  }
   soma { nseg = 35  }
   ApD { nseg = 100  }
   BasD { nseg = 200  }
   BasD[1] { nseg = 200  }
}
proc biophys() {
  forsec all {
    insert pas
      g_pas = 6.6e-05
      e_pas = -75
    Ra = 150
    insert kv
      gbar_kv = 20
    insert Kv1
      gbar_Kv1 = 0.01
    insert nadifl
      D_nadifl = 0.6
  }
  forsec axonal {
    insert Kv1
      gbar_Kv1 = 0.002
    insert kv
      gbar_kv = 20
  }
  forsec myelins {
    cm = 1
    insert hh_Cs_scaled
      gnabar_hh_Cs_scaled = 0.02
      gkbar_hh_Cs_scaled = 0
      gl_hh_Cs_scaled = 0
      el_hh_Cs_scaled = -54.3
  }
  forsec nodes {
    insert hh_Cs_scaled
      gnabar_hh_Cs_scaled = 0.02
      gkbar_hh_Cs_scaled = 0
      gl_hh_Cs_scaled = 0
      el_hh_Cs_scaled = -54.3
    cm = 1
  }
  AIS {
    cm = 0.9
    insert hh_Cs_scaled
      gnabar_hh_Cs_scaled = 0.02
      gkbar_hh_Cs_scaled = 0
      gl_hh_Cs_scaled = 0
      el_hh_Cs_scaled = -54.3
  }
  soma {
    insert hh_Cs_scaled
      gnabar_hh_Cs_scaled = 0.02
      gkbar_hh_Cs_scaled = 0
      gl_hh_Cs_scaled = 0
      el_hh_Cs_scaled = -54.3
    cm = 0.9
  }
  ApD {
    insert hh_Cs_scaled
      gnabar_hh_Cs_scaled = 0.02
      gkbar_hh_Cs_scaled = 0
      gl_hh_Cs_scaled = 0
      el_hh_Cs_scaled = -54.3
    cm = 0.9
  }
  BasD {
    insert hh_Cs_scaled
      gnabar_hh_Cs_scaled = 0.02
      gkbar_hh_Cs_scaled = 0
      gl_hh_Cs_scaled = 0
      el_hh_Cs_scaled = -54.3
    cm = 0.9
  }
  BasD[1] {
    insert hh_Cs_scaled
      gnabar_hh_Cs_scaled = 0.02
      gkbar_hh_Cs_scaled = 0
      gl_hh_Cs_scaled = 0
      el_hh_Cs_scaled = -54.3
    cm = 0.9
  }
}
objref axonal_x
proc biophys_inhomo() {
  // Path Length from root translated so most proximal end at 0
  //   and normalized so most distal end at 1 ranges from 0 to 1
  axonal_x = new SubsetDomainIterator(axonal, 0, 1, 1)
  gbar_Kv1_axonal_x()
  gbar_kv_axonal_x()
}
proc gbar_Kv1_axonal_x() {local x, p, p0, p1, b, m
  axonal_x.update()
  p0 = axonal_x.p0  p1 = axonal_x.p1
  b = 0.002
  m = 0.2
  for axonal_x.loop() {
    x = axonal_x.x  p = axonal_x.p
    gbar_Kv1(x) = b + m*p/(p1 - p0)
  }
}
proc gbar_kv_axonal_x() {local x, p, p0, p1, b, m
  axonal_x.update()
  p0 = axonal_x.p0  p1 = axonal_x.p1
  b = 20
  m = 2000
  for axonal_x.loop() {
    x = axonal_x.x  p = axonal_x.p
    gbar_kv(x) = b + m*p/(p1 - p0)
  }
}
proc position() { local i
  AIS for i = 0, n3d()-1 {
    pt3dchange(i, $1-x+x3d(i), $2-y+y3d(i), $3-z+z3d(i), diam3d(i))
  }
  x = $1  y = $2  z = $3
}
obfunc connect2target() { localobj nc //$o1 target point process, optional $o2 returned NetCon
  AIS nc = new NetCon(&v(1), $o1)
  nc.threshold = 10
  if (numarg() == 2) { $o2 = nc } // for backward compatibility
  return nc
}
objref syn_
proc synapses() {
}
func is_art() { return 0 }

endtemplate Pre_Cell

begintemplate Post_Cell
public is_art
public init, topol, basic_shape, subsets, geom, biophys, geom_nseg, biophys_inhomo
public synlist, x, y, z, position, connect2target

public soma
public all

objref synlist

proc init() {
  topol()
  subsets()
  geom()
  biophys()
  geom_nseg()
  synlist = new List()
  synapses()
  x = y = z = 0 // only change via position
}

create soma

proc topol() { local i
  basic_shape()
}
proc basic_shape() {
  soma {pt3dclear() pt3dadd(0, 0, 0, 1) pt3dadd(15, 0, 0, 1)}
}

objref all
proc subsets() { local i
  objref all
  all = new SectionList()
    soma all.append()

}
proc geom() {
  soma {  L = 32  diam = 23  }
}
external lambda_f
proc geom_nseg() {
   soma { nseg = 50  }
}
proc biophys() {
  soma {
    insert hh
      gnabar_hh = 0.12
      gkbar_hh = 0.036
      gl_hh = 0.0003
      el_hh = -54.3
  }
}
proc biophys_inhomo(){}
proc position() { local i
  soma for i = 0, n3d()-1 {
    pt3dchange(i, $1-x+x3d(i), $2-y+y3d(i), $3-z+z3d(i), diam3d(i))
  }
  x = $1  y = $2  z = $3
}
obfunc connect2target() { localobj nc //$o1 target point process, optional $o2 returned NetCon
  soma nc = new NetCon(&v(1), $o1)
  nc.threshold = 10
  if (numarg() == 2) { $o2 = nc } // for backward compatibility
  return nc
}
objref syn_
proc synapses() {
}
func is_art() { return 0 }

endtemplate Post_Cell

//Network specification interface

objref cells, nclist, netcon
{cells = new List()  nclist = new List()}

func cell_append() {cells.append($o1)  $o1.position($2,$3,$4)
	return cells.count - 1
}

func nc_append() {//srcindex, tarcelindex, synindex
  if ($3 >= 0) {
    netcon = cells.object($1).connect2target(cells.object($2).synlist.object($3))
    netcon.weight = $4   netcon.delay = $5
  }else{
    netcon = cells.object($1).connect2target(cells.object($2).pp)
    netcon.weight = $4   netcon.delay = $5
  }
  nclist.append(netcon)
  return nclist.count - 1
}

//Network instantiation

  /* Pre0 */  cell_append(new Pre_Cell(),	-73,	 0, 0)
  /* Post1 */  cell_append(new Post_Cell(),	-21,	 -1, 0)

%%%
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: added a synapse with python

Post by ted »

I get an error when trying to add the synapse.
What are you doing to "add the synapse"?
In addition, when I load the hoc file I can't load the morphology of the cell.
Not sure what this means. As soon as you create an instance of either of the cell classes defined in your example code, the sections are created exactly as specified by the corresponding template.

The following comments and questions are not related to your questions--

Strong suggestion: use odd values for nseg. Read about it in the Hot tips area of the NEURON Forum.

Why such large values for nseg? Have you run any simulations with an instance of the presynaptic cell to get an idea of what nseg values would be appropriate? Why not use the d_lambda rule? (should also be discussed in the Forum's Hot tips area). I bet you a nickel that none of the sections created by this code will need more than about 5 segments for spatial accuracy.
Post Reply