proc celldef() {
  topol()
  subsets()
  geom()
  biophys()
  // geom_nseg()
}

create soma, ABD, axonstart, AIS, axon, axoD[2], axoD_sec[22]
create nABD[2], nABD_sec[14]

proc topol() { local i
  connect ABD(0), soma(0)
  connect axonstart(0), ABD(1)
  connect AIS(0), axonstart(1)
  connect axon(0), AIS(1)
  for i = 0, 1 connect axoD[i](0), ABD(1)
  for i = 0, 1 connect axoD_sec[i](0), axoD(1)
  for i = 2, 3 connect axoD_sec[i](0), axoD_sec(1)
  connect axoD_sec[4](0), axoD_sec[1](1)
  for i = 5, 6 connect axoD_sec[i](0), axoD_sec[4](1)
  connect axoD_sec[7](0), axoD_sec[1](1)
  for i = 8, 9 connect axoD_sec[i](0), axoD_sec[7](1)
  for i = 10, 11 connect axoD_sec[i](0), axoD_sec[9](1)
  for i = 12, 13 connect axoD_sec[i](0), axoD_sec[11](1)
  for i = 14, 15 connect axoD_sec[i](0), axoD[1](1)
  for i = 16, 17 connect axoD_sec[i](0), axoD_sec[15](1)
  for i = 18, 19 connect axoD_sec[i](0), axoD_sec[17](1)
  for i = 20, 21 connect axoD_sec[i](0), axoD_sec[14](1)
  for i = 0, 1 connect nABD[i](0), soma(1)
  for i = 0, 1 connect nABD_sec[i](0), nABD(1)
  for i = 2, 3 connect nABD_sec[i](0), nABD[1](1)
  for i = 4, 5 connect nABD_sec[i](0), nABD_sec[3](1)
  for i = 6, 7 connect nABD_sec[i](0), nABD_sec[5](1)
  for i = 8, 9 connect nABD_sec[i](0), nABD_sec[7](1)
  for i = 10, 11 connect nABD_sec[i](0), nABD_sec[4](1)
  for i = 12, 13 connect nABD_sec[i](0), nABD_sec[11](1)
  basic_shape()
}
proc basic_shape() {
  soma {pt3dclear() pt3dadd(0, 0, 0, 1) pt3dadd(15, 0, 0, 1)}
  ABD {pt3dclear() pt3dadd(0, 0, 0, 1) pt3dadd(-14, 30, 0, 1)}
  axonstart {pt3dclear() pt3dadd(-14, 30, 0, 1) pt3dadd(-29, 15, 0, 1)}
  AIS {pt3dclear() pt3dadd(-29, 15, 0, 1) pt3dadd(-44, 0, 0, 1)}
  axon {pt3dclear() pt3dadd(-44, 0, 0, 1) pt3dadd(-104, -59, 0, 1)}
  axoD {pt3dclear() pt3dadd(-14, 30, 0, 1) pt3dadd(-44, 45, 0, 1)}
  axoD[1] {pt3dclear() pt3dadd(-14, 30, 0, 1) pt3dadd(0, 60, 0, 1)}
  axoD_sec {pt3dclear() pt3dadd(-44, 45, 0, 1) pt3dadd(-44, 75, 0, 1)}
  axoD_sec[1] {pt3dclear() pt3dadd(-44, 45, 0, 1) pt3dadd(-89, 45, 0, 1)}
  axoD_sec[2] {pt3dclear() pt3dadd(-44, 75, 0, 1) pt3dadd(-59, 90, 0, 1)}
  axoD_sec[3] {pt3dclear() pt3dadd(-44, 75, 0, 1) pt3dadd(-29, 90, 0, 1)}
  axoD_sec[4] {pt3dclear() pt3dadd(-89, 45, 0, 1) pt3dadd(-104, 30, 0, 1)}
  axoD_sec[5] {pt3dclear() pt3dadd(-104, 30, 0, 1) pt3dadd(-104, 0, 0, 1)}
  axoD_sec[6] {pt3dclear() pt3dadd(-104, 30, 0, 1) pt3dadd(-134, 15, 0, 1)}
  axoD_sec[7] {pt3dclear() pt3dadd(-89, 45, 0, 1) pt3dadd(-104, 60, 0, 1)}
  axoD_sec[8] {pt3dclear() pt3dadd(-104, 60, 0, 1) pt3dadd(-134, 60, 0, 1)}
  axoD_sec[9] {pt3dclear() pt3dadd(-104, 60, 0, 1) pt3dadd(-104, 90, 0, 1)}
  axoD_sec[10] {pt3dclear() pt3dadd(-104, 90, 0, 1) pt3dadd(-119, 105, 0, 1)}
  axoD_sec[11] {pt3dclear() pt3dadd(-104, 90, 0, 1) pt3dadd(-89, 105, 0, 1)}
  axoD_sec[12] {pt3dclear() pt3dadd(-89, 105, 0, 1) pt3dadd(-89, 135, 0, 1)}
  axoD_sec[13] {pt3dclear() pt3dadd(-89, 105, 0, 1) pt3dadd(-59, 120, 0, 1)}
  axoD_sec[14] {pt3dclear() pt3dadd(0, 60, 0, 1) pt3dadd(0, 90, 0, 1)}
  axoD_sec[15] {pt3dclear() pt3dadd(0, 60, 0, 1) pt3dadd(30, 75, 0, 1)}
  axoD_sec[16] {pt3dclear() pt3dadd(30, 75, 0, 1) pt3dadd(30, 105, 0, 1)}
  axoD_sec[17] {pt3dclear() pt3dadd(30, 75, 0, 1) pt3dadd(60, 75, 0, 1)}
  axoD_sec[18] {pt3dclear() pt3dadd(60, 75, 0, 1) pt3dadd(75, 90, 0, 1)}
  axoD_sec[19] {pt3dclear() pt3dadd(60, 75, 0, 1) pt3dadd(75, 60, 0, 1)}
  axoD_sec[20] {pt3dclear() pt3dadd(0, 90, 0, 1) pt3dadd(15, 105, 0, 1)}
  axoD_sec[21] {pt3dclear() pt3dadd(0, 90, 0, 1) pt3dadd(-14, 105, 0, 1)}
  nABD {pt3dclear() pt3dadd(15, 0, 0, 1) pt3dadd(60, 15, 0, 1)}
  nABD[1] {pt3dclear() pt3dadd(15, 0, 0, 1) pt3dadd(0, -44, 0, 1)}
  nABD_sec {pt3dclear() pt3dadd(60, 15, 0, 1) pt3dadd(75, 30, 0, 1)}
  nABD_sec[1] {pt3dclear() pt3dadd(60, 15, 0, 1) pt3dadd(90, 0, 0, 1)}
  nABD_sec[2] {pt3dclear() pt3dadd(0, -44, 0, 1) pt3dadd(-29, -44, 0, 1)}
  nABD_sec[3] {pt3dclear() pt3dadd(0, -44, 0, 1) pt3dadd(0, -74, 0, 1)}
  nABD_sec[4] {pt3dclear() pt3dadd(0, -74, 0, 1) pt3dadd(-29, -89, 0, 1)}
  nABD_sec[5] {pt3dclear() pt3dadd(0, -74, 0, 1) pt3dadd(30, -89, 0, 1)}
  nABD_sec[6] {pt3dclear() pt3dadd(30, -89, 0, 1) pt3dadd(30, -119, 0, 1)}
  nABD_sec[7] {pt3dclear() pt3dadd(30, -89, 0, 1) pt3dadd(60, -89, 0, 1)}
  nABD_sec[8] {pt3dclear() pt3dadd(60, -89, 0, 1) pt3dadd(75, -74, 0, 1)}
  nABD_sec[9] {pt3dclear() pt3dadd(60, -89, 0, 1) pt3dadd(75, -104, 0, 1)}
  nABD_sec[10] {pt3dclear() pt3dadd(-29, -89, 0, 1) pt3dadd(-29, -119, 0, 1)}
  nABD_sec[11] {pt3dclear() pt3dadd(-29, -89, 0, 1) pt3dadd(-59, -104, 0, 1)}
  nABD_sec[12] {pt3dclear() pt3dadd(-59, -104, 0, 1) pt3dadd(-59, -134, 0, 1)}
  nABD_sec[13] {pt3dclear() pt3dadd(-59, -104, 0, 1) pt3dadd(-89, -89, 0, 1)}
}

objref all, all_biophys, all_ABD
proc subsets() { local i
  objref all, all_biophys,all_ABD
  all = new SectionList()
    soma all.append()
    ABD all.append()
    axonstart all.append()
    AIS all.append()
    axon all.append()
    for i=0, 1 axoD[i] all.append()
    for i=0, 21 axoD_sec[i] all.append()
    for i=0, 1 nABD[i] all.append()
    for i=0, 13 nABD_sec[i] all.append()

  all_biophys = new SectionList()
    ABD all_biophys.append()
    axonstart all_biophys.append()
    for i=0, 1 axoD[i] all_biophys.append()
    for i=0, 21 axoD_sec[i] all_biophys.append()
    for i=0, 1 nABD[i] all_biophys.append()
    for i=0, 13 nABD_sec[i] all_biophys.append()

      all_ABD= new SectionList()
     ABD all_ABD.append()
    axonstart all_ABD.append()
    for i=0, 1 axoD[i] all_ABD.append()
    for i=0, 21 axoD_sec[i] all_ABD.append()


}
proc geom() {

  soma {  L = 19    }
  ABD {  L = 11    }
  axonstart {  L = 24.2    }
  AIS {  L = 27.2    }
  axon {  L = 800    }
  axoD {  L = 6    }
  axoD[1] {  L = 39    }
  axoD_sec {  L = 122    }
  axoD_sec[1] {  L = 11    }
  axoD_sec[2] {  L = 23    }
  axoD_sec[3] {  L = 58    }
  axoD_sec[4] {  L = 52    }
  axoD_sec[5] {  L = 123    }
  axoD_sec[6] {  L = 43    }
  axoD_sec[7] {  L = 24    }
  axoD_sec[8] {  L = 263    }
  axoD_sec[9] {  L = 11    }
  axoD_sec[10] {  L = 102    }
  axoD_sec[11] {  L = 3    }
  axoD_sec[12] {  L = 34    }
  axoD_sec[13] {  L = 21    }
  axoD_sec[14] {  L = 28    }
  axoD_sec[15] {  L = 8    }
  axoD_sec[16] {  L = 68    }
  axoD_sec[17] {  L = 145    }
  axoD_sec[18] {  L = 71    }
  axoD_sec[19] {  L = 173    }
  axoD_sec[20] {  L = 146    }
  axoD_sec[21] {  L = 245    }
  nABD {  L = 15    }
  nABD[1] {  L = 13    }
  nABD_sec {  L = 26    }
  nABD_sec[1] {  L = 10    }
  nABD_sec[2] {  L = 321    }
  nABD_sec[3] {  L = 27    }
  nABD_sec[4] {  L = 23    }
  nABD_sec[5] {  L = 30    }
  nABD_sec[6] {  L = 35    }
  nABD_sec[7] {  L = 19    }
  nABD_sec[8] {  L = 219    }
  nABD_sec[9] {  L = 54    }
  nABD_sec[10] {  L = 26    }
  nABD_sec[11] {  L = 22    }
  nABD_sec[12] {  L = 221    }
  nABD_sec[13] {  L = 111    }

// nseg definition has to be launched before diam definition for tapering to be taken into account

  forsec all { nseg = int((L/(0.1*lambda_f(1000))+.999)/2)*2 + 1  }
  
  soma {    diam = 10  }
  ABD {   diam(0:1) = 2.2:2.1 }
  axonstart {     diam(0:1) = 1.35:1.13  }
  AIS {     diam(0:1) = 1.13:0.5  }
  axon {    diam = 0.5  }
  axoD {   diam = 1.7}
  axoD[1] { diam(0:1) = 1.7:1.5 }
  axoD_sec { diam = 1  }
  axoD_sec[1] {   diam = 1.5  }
  axoD_sec[2] {   diam = 0.8  }
  axoD_sec[3] {   diam = 0.8 }
  axoD_sec[4] {   diam = 1  }
  axoD_sec[5] {    diam = 0.8  }
  axoD_sec[6] {   diam = 0.8 }
  axoD_sec[7] {   diam = 1.5  }
  axoD_sec[8] {    diam = 0.8  }
  axoD_sec[9] {   diam = 1.5  }
  axoD_sec[10] {    diam = 0.8  }
  axoD_sec[11] {   diam = 1.5  }
  axoD_sec[12] {   diam = 0.8  }
  axoD_sec[13] {   diam = 0.8  }
  axoD_sec[14] {   diam = 1  }
  axoD_sec[15] {   diam = 1  }
  axoD_sec[16] {   diam = 0.8  }
  axoD_sec[17] {    diam = 1  }
  axoD_sec[18] {   diam = 0.8  }
  axoD_sec[19] {    diam = 0.8  }
  axoD_sec[20] {   diam = 0.8  }
  axoD_sec[21] {    diam = 0.8  }
  nABD {  diam(0:1) = 1.7:1.5  }
  nABD[1] {  diam(0:1) = 5.5:5  }
  nABD_sec {  diam = 0.8 }
  nABD_sec[1] {  diam = 0.8  }
  nABD_sec[2] {   diam(0:1) = 2:0.8  }
  nABD_sec[3] {   diam(0:1) = 3:2.5  }
  nABD_sec[4] {  diam(0:1) = 1.5:1  }
  nABD_sec[5] {   diam = 1.5  }
  nABD_sec[6] {   diam = 0.8  }
  nABD_sec[7] {   diam = 1 }
  nABD_sec[8] {    diam = 0.8   }
  nABD_sec[9] {   diam = 0.8   }
  nABD_sec[10] {   diam(0:1) = 1:0.8  }
  nABD_sec[11] {   diam = 1  }
  nABD_sec[12] {    diam = 0.8   }
  nABD_sec[13] {    diam = 0.8   }
}
proc biophys() {
  forsec all {
    Ra = 150
    cm = 0.75
    insert pasnts
      g_pasnts = 1e-05
      e_pasnts = -50
  }
  forsec all_biophys {
    insert CAV13
      gbar_CAV13 = 1.25
      iLCa_CAV13 = 0
    insert Ih
      gbar_Ih = 3
    insert kaDa
      gbar_kaDa = 50
      taurecov_kaDa = 25
    insert kdrDA
      gbar_kdrDA = 150
    insert Na12
      gbar_Na12 = 75
    insert cad
    insert kca
      gbar_kca = 0.1
        
  }
  soma {
    insert CAV13
      gbar_CAV13 = 1.25
      iLCa_CAV13 = 0
    insert Ih
      gbar_Ih = 3
    insert kaDasoma
      gbar_kaDasoma = 150
      taurecov_kaDasoma = 25
    insert kdrDA
      gbar_kdrDA = 150
    insert Na12
      gbar_Na12 = 75
    insert cad
    insert kca
      gbar_kca = 0.1
        
  }
  AIS {
    insert kdrDA
      gbar_kdrDA = 4000
    insert Na12
      gbar_Na12 = 4000
  }
  axon {
    insert kdrDA
      gbar_kdrDA = 400
    insert Na12
      gbar_Na12 = 400
  }
  forsec all { ek=-90
ena=60  }
}
access soma

celldef()