//Network cell templates
//   C_Cell

begintemplate C_Cell
public is_art
public init, topol, basic_shape, subsets, geom, biophys
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 {  /*area = 100 */ L = diam = 5.6419  }
}
external lambda_f
proc geom_nseg() {
  soma area(.5) // make sure diam reflects 3d points
   soma { nseg = 1  }
}
proc biophys() {
  soma {
    Ra = 80
    cm = 1
    insert caL
      Pbar_caL = 42
    insert kir2
      gbar_kir2 = 1.2
    insert ksi
      gbar_ksi = 0.45
    insert leak
      g_leak = 0.008
      e_leak = -90
  }
}
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
}
proc connect2target() { //$o1 target point process, $o2 returned NetCon
  soma $o2 = new NetCon(&v(1), $o1)
}
objref syn_
proc synapses() {
  /* ExpSyn0 */   soma syn_ = new ExpSyn(0.5)  synlist.append(syn_)
    syn_.tau = 3
  /* DAsyn1 */   soma syn_ = new DAsyn(0.5)  synlist.append(syn_)
  // attach all POINTERs to DAsyn.msg
  forsec all {
    if (issection("caL")) {
      for (x,0) { // skip the nodes at 0 and 1
	setpointer mu_caL(x), synlist.object(1).msg
      }
    }
    if (issection("kir2")) {
      for (x,0) { // skip the nodes at 0 and 1
	setpointer mu_kir2(x), synlist.object(1).msg
      }
    }
  }
}
func is_art() { return 0 }

endtemplate C_Cell