// 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, CRGraph

// define membrane mechanisms
proc SetMembrane() {
  strdef OutLine
  OutLine = "Soma {insert PasSA}"
  execute1(OutLine)
  OutLine = "Axon {insert PasSA}"
  execute1(OutLine)
  OutLine = "Dendrite {insert PasD}"
  execute1(OutLine)
} // SetMembrane()

func CalcEq() { local Gm, Eq
  if (issection("Dendrite")) {
    Gm = gs_PasD($1) + g_PasD($1)
    Eq = ((gs_PasD($1) / Gm) * es_PasD($1)) + ((g_PasD($1) / Gm) * erev_PasD($1))
  } else {
    Eq = erev_PasSA($1)
  }
  return Eq
} // CalcEq()

// make graphics for Fig.1. A
proc MakeVRGraph() {
  strdef OutLine
  VRGraph = new Graph(0)
  VRGraph.xaxis()
  VRGraph.yaxis()
  RRGraph = new RangeVarPlot("v")
  OutLine = "Axon RRGraph.begin(0) Dendrite RRGraph.end(1)"
  execute1(OutLine)
  VRGraph.addobject(RRGraph, 1, 1, 1, 1)
  RRGraph = new RangeVarPlot("CalcEq($1)")
  OutLine = "Axon RRGraph.begin(0) Dendrite RRGraph.end(1)"
  execute1(OutLine)
  VRGraph.addobject(RRGraph, 3, 1, 1, 3)
  VRGraph.size(-200, 800, -70, -30)
  VRGraph.view(-200, -72, 1000, 42, 268, 200, 300.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.21, "um", 2, 1, 0, 1, 1)
  VRGraph.label(0.9, 0.95, "Eq", 2, 1, 0, 1, 3)
  VRGraph.label(0.9, 0.65, "E", 2, 1, 0, 1, 1)
  VRGraph.yaxis(3)
  VRGraph.xaxis(-200, 800, -70, 10, 0, 0, 1)
  VRGraph.yaxis(-70, -30, -200, 4, 0, 0, 1)
  flush_list.append(VRGraph)
  VRGraph.save_name("flush_list.")
  objectvar RRGraph
} // MakeVRGraph()

func CalcGs() { // mS/cm2
  return gs_PasD($1) * 1000
} // CalcGs()

func CalcGpd() { // mS/cm2
  return g_PasD($1) * 1000
} // CalcGpd()

func CalcGm() { // mS/cm2
  return ((gs_PasD($1) + g_PasD($1)) * 1000)
} // CalcGm()

// make graphics for Fig.1. C
proc MakeCRGraph() {
  strdef OutLine
  CRGraph = new Graph(0)
  CRGraph.xaxis()
  CRGraph.yaxis()
  RRGraph = new RangeVarPlot("CalcGs($1)")
  OutLine = "Dendrite RRGraph.begin(0) Dendrite RRGraph.end(1)"
  execute1(OutLine)
  CRGraph.addobject(RRGraph, 1, 1, 1, 1)
  RRGraph = new RangeVarPlot("CalcGpd($1)")
  OutLine = "Dendrite RRGraph.begin(0) Dendrite RRGraph.end(1)"
  execute1(OutLine)
  CRGraph.addobject(RRGraph, 1, 1, 1, 1)
  RRGraph = new RangeVarPlot("CalcGm($1)")
  OutLine = "Dendrite RRGraph.begin(0) Dendrite RRGraph.end(1)"
  execute1(OutLine)
  CRGraph.addobject(RRGraph, 3, 1, 1, 3)
  CRGraph.size(-200, 800, 0, 0.3)
  CRGraph.view(-220, -0.01, 1020, 0.31, 683, 200, 300.0, 215.0)
  CRGraph.label(0.5, 1, "C", 2, 1, 0, 1, 1)
  CRGraph.label(0.05, 1, "mS/cm2", 2, 1, 0, 1, 1)
  CRGraph.label(0.9, 0.2, "um", 2, 1, 0, 1, 1)
  CRGraph.label(0.9, 0.55, "Gm", 2, 1, 0, 1, 3)
  CRGraph.label(0.9, 0.40, "Gs", 2, 1, 0, 1, 1)
  CRGraph.label(0.9, 0.35, "Gp,d", 2, 1, 0, 1, 1)
  CRGraph.yaxis(3)
  CRGraph.xaxis(-200, 800, 0, 10, 0, 0, 1)
  CRGraph.yaxis(0, 0.3, -200, 3, 0, 0, 1)
  flush_list.append(CRGraph)
  CRGraph.save_name("flush_list.")
  objectvar RRGraph
} // MakeCRGraph()

proc Destroy() {
  VRGraph.unmap()
  CRGraph.unmap()
} // Destroy()

proc MainExec() {
  GetModelTopology(1)
  SetMembrane()
  OutLine = "access Soma"
  execute1(OutLine)
  tstop = 100
  MakeVRGraph()
  MakeCRGraph()
} // MainExec()

MainExec()