// Geometry-induced features of current transfer in neuronal dendrites with tonically activated conductances
// Sergey M. Korogod, Irina B. Kulagina
// Biol. Cybern. 79, 231-240 (1998)

objectvar VRGraph, JRGraph, IRGraph

// define membrane mechanisms
proc SetMembrane() {
  strdef OutLine
  OutLine = "Soma {insert PasSA}"
  execute1(OutLine)
  for i=0, 2 {
    sprint(OutLine, "Dendrite[%d] {insert PasD}", i)
    execute1(OutLine)
  }
} // SetMembrane()

// make graphics for Fig.3. A (symmetric)
proc MakeVRGraph() {
  strdef OutLine
  VRGraph = new Graph(0)
  VRGraph.xaxis()
  VRGraph.yaxis()
  RRGraph = new RangeVarPlot("v")
  OutLine = "Dendrite[0] RRGraph.begin(0) Dendrite[1] RRGraph.end(1)"
  execute1(OutLine)
  VRGraph.addobject(RRGraph, 1, 1, 1, 1)
  RRGraph = new RangeVarPlot("v")
  OutLine = "Dendrite[0] RRGraph.begin(0) Dendrite[2] RRGraph.end(1)"
  execute1(OutLine)
  VRGraph.addobject(RRGraph, 1, 1, 1, 1)
  VRGraph.size(0, 800, -48, -40)
  VRGraph.view(0, -48.1, 800, 8.1, 50, 200, 250.0, 215.0)
  VRGraph.label(0.5, 1, "A", 2, 1, 0, 1, 1)
  VRGraph.label(0.05, 1, "mV", 2, 1, 0, 1, 1)
  VRGraph.label(0.9, 0.18, "um", 2, 1, 0, 1, 1)
  VRGraph.label(0.9, 0.95, "E", 2, 1, 0, 1, 1)
  flush_list.append(VRGraph)
  VRGraph.save_name("flush_list.")
  objectvar RRGraph
} // MakeVRGraph()

func CalcJm() { local Gm, Eq, Jm // uA/cm2
  Gm = gs_PasD($1) + g_PasD($1)
  Eq = ((gs_PasD($1) / Gm) * es_PasD($1)) + ((g_PasD($1) / Gm) * erev_PasD($1))
  Jm = (Gm * (v($1) - Eq)) * 1000
  return Jm
} // CalcJm()

// make graphics for Fig.3. B (symmetric)
proc MakeJRGraph() {
  strdef OutLine
  JRGraph = new Graph(0)
  JRGraph.xaxis()
  JRGraph.yaxis()
  RRGraph = new RangeVarPlot("CalcJm($1)")
  OutLine = "Dendrite[0] RRGraph.begin(0) Dendrite[1] RRGraph.end(1)"
  execute1(OutLine)
  JRGraph.addobject(RRGraph, 1, 1, 1, 1)
  RRGraph = new RangeVarPlot("CalcJm($1)")
  OutLine = "Dendrite[0] RRGraph.begin(0) Dendrite[2] RRGraph.end(1)"
  execute1(OutLine)
  JRGraph.addobject(RRGraph, 1, 1, 1, 1)
  JRGraph.size(0, 800, -2, 0)
  JRGraph.view(-20, -2.05, 820, 2.05, 400, 200, 250.0, 215.0)
  JRGraph.label(0.5, 1, "B", 2, 1, 0, 1, 1)
  JRGraph.label(0.05, 1, "uA/cm2", 2, 1, 0, 1, 1)
  JRGraph.label(0.9, 0.18, "um", 2, 1, 0, 1, 1)
  JRGraph.yaxis(3)
  JRGraph.xaxis(0, 800, -2, 4, 0, 0, 1)
  JRGraph.yaxis(-2, 0, 0, 2, 0, 0, 1)
  flush_list.append(JRGraph)
  JRGraph.save_name("flush_list.")
  objectvar RRGraph
} // MakeJRGraph()

func CalcI() { local Gm, Eq, Jm, Im // 0.01*pA/um
  Gm = gs_PasD($1) + g_PasD($1)
  Eq = ((gs_PasD($1) / Gm) * es_PasD($1)) + ((g_PasD($1) / Gm) * erev_PasD($1))
  Jm = (Gm * (v($1) - Eq)) * 1000
  Im = -(PI * diam($1) * Jm)
  return Im
} // CalcI()

// make graphics for Fig.3. C (symmetric)
proc MakeIRGraph() {
  strdef OutLine
  IRGraph = new Graph(0)
  IRGraph.xaxis()
  IRGraph.yaxis()
  RRGraph = new RangeVarPlot("CalcI($1)")
  OutLine = "Dendrite[0] RRGraph.begin(0) Dendrite[1] RRGraph.end(1)"
  execute1(OutLine)
  IRGraph.addobject(RRGraph, 1, 1, 1, 1)
  RRGraph = new RangeVarPlot("CalcI($1)")
  OutLine = "Dendrite[0] RRGraph.begin(0) Dendrite[2] RRGraph.end(1)"
  execute1(OutLine)
  IRGraph.addobject(RRGraph, 1, 1, 1, 1)
  IRGraph.size(0, 800, 0, 30)
  IRGraph.view(0, -0.2, 800, 30.2, 750, 200, 250.0, 215.0)
  IRGraph.label(0.5, 1, "C", 2, 1, 0, 1, 1)
  IRGraph.label(0.05, 1, "0.01 pA/um", 2, 1, 0, 1, 1)
  IRGraph.label(0.9, 0.18, "um", 2, 1, 0, 1, 1)
  flush_list.append(IRGraph)
  IRGraph.save_name("flush_list.")
  objectvar RRGraph
} // MakeIRGraph()

proc Destroy() {
  VRGraph.unmap()
  JRGraph.unmap()
  IRGraph.unmap()
} // Destroy()

proc MainExec() {
  GetModelTopology(2)
  SetMembrane()
  OutLine = "access Soma"
  execute1(OutLine)
  tstop = 100
  MakeVRGraph()
  MakeJRGraph()
  MakeIRGraph()
} // MainExec()

MainExec()