// mitral.tem
// Template for n-compartment mitral cell model
// Modele avec Longue dendrite


begintemplate Mit
  public soma, glom, prim, dend, AMPA, GABAA, spiketimes, spikecount, gsp, gpg
  create soma, glom, prim, dend[100], s2d, s2p, p2g
  objref AMPA, GABAA[100], spikecount, spiketimes

  proc init() { local Len, Erest, RM, p, q, r, Atotal, AMPAtau, AMPArev, GABAAtau, GABAArev
    create soma, glom, prim, dend[$1], s2d, s2p, p2g

    spiketimes = new Vector()
    lastspikecount = 0

    Len 	= 100
    Erest	= -65		// mV
    Atotal	= 100000	// um2
    gsp		= 5.47e-11	// S/cm2
    gpg		= 5.86e-11	//
    RM		= 100000	// ohm.cm2
    p		= 0.051
    q		= 0.084
    r		= 0.328
    AMPAtau	= 10		//ms
    AMPArev	= 0		//mV
    GABAAtau	= 6		// from Sc&98
    GABAArev	= -70 		//

    soma {
      insert pas
      insert nafast
      insert kfasttab
      insert kslowtab
      insert kA
      insert kca
      insert lcafixed
      insert cad
      depth_cad 	= 8
      L			= Len
      diam 		= p*Atotal/(PI*Len)
      Ra 		= PI*diam*diam/(4*Len*Atotal)
      e_pas 		= Erest		// reversal potential mV
      g_pas 		= 1/RM		// membrane conductance siemen-cm^-2
      gnabar_nafast 	= 0.1532
      gkbar_kfasttab 	= 0.1956
      gkbar_kslowtab 	= 0.0028
      gkbar_kA 		= 0.00587
      gkbar_kca		= 0.0142
      gcabar_lcafixed 	= 0.0040
      spikecount = new APCount(0.5)
      spikecount.thresh = -30
      spikecount.record(spiketimes)
    }

    glom {
      insert pas
      insert kslowtab
      insert lcafixed
      insert cad
      L			= Len
      diam 		= q*Atotal/(PI*Len)
      Ra 		= PI*diam*diam/(4*Len*Atotal)
      e_pas 		= Erest
      g_pas		= 1/RM
      gkbar_kslowtab	= 0.02
      gcabar_lcafixed	= 0.0095
      AMPA = new ExpSyn(0.5)
      AMPA.tau 		= AMPAtau
      AMPA.e 		= AMPArev
    }

    prim {
      insert pas
      insert nafast
      insert kfasttab
      insert kslowtab
      insert lcafixed
      insert cad
      depth_cad 	= 8
      L			= Len
      diam 		= r*Atotal/(PI*Len)
      Ra 	= PI*diam*diam/(4*Len*Atotal)
      e_pas 		= Erest
      g_pas		= 1/RM
      gkbar_kfasttab	= 0.00123
      gnabar_nafast	= 0.00134
      gkbar_kslowtab	= 0.00174
      gcabar_lcafixed	= 0.0022
    }

for i=0,$1-1  {
    dend[i] {
      insert pas
      insert kfasttab
      insert nafast

      L    = 10	   // um instead of 100
      diam = 17.03 //instead of (1-p-q-r)*Atotal/(PI*Len)		 // um
      Ra   = 595 //1130 //2267 //850 //to keep an electronic length similar
      e_pas 		= Erest
      g_pas		= 1/RM

      gnabar_nafast	= 0.033		// 0.0226
      gkbar_kfasttab	= 0.0226	// 0.0330

      GABAA[i] 		= new ExpSyn(0.5)
      GABAA[i].tau 	= GABAAtau
      GABAA[i].e 	= GABAArev
    }
}

    s2p { 
      diam 		= 1
      Ra = PI*diam*diam/(4*Len*Atotal) * ( 1/gsp )
      L 		= 1
    }
    p2g { 
      diam 		= 1
      Ra = PI*diam*diam/(4*Len*Atotal) * ( 1/gpg )
      L 		= 1
    }
    soma connect s2p(0),0
     s2p connect prim(0),1
    prim connect p2g(0),1
     p2g connect glom(0),1

    soma connect dend[0](0),1

    for i= 0, $1-2 {
		dend[i] connect dend[i+1](0),1
    }

    // set reversal potentials, etc.
    forall if (ismembrane("ca_ion")) {
      eca = 70		// mV
      cai = 0.00001	// mM
      cao = 2		// mM
      ion_style("ca_ion",3,2,0,0,1)
    }

    forall if (ismembrane("na_ion")) {
      ena = 45		// mV
    }
    forall if (ismembrane("k_ion")) {
      ek  = -70		//  mV
    }

  }

endtemplate Mit