// mitral.tem
// Template for four-compartment mitral cell model
// as described in:
//    Davison, AP, Feng J and Brown D (2000)
//    A reduced compartmental model of the mitral cell
//      for use in network models of the olfactory bulb. 
//    Brain Research Bulletin 51(5): 393-399.
// Andrew Davison, The Babraham Institute, 2000


begintemplate Mit
  public soma, glom, prim, dend, AMPA, GABAA, spiketimes, spikecount
  public connect2target, synlist
  external thresh
  create soma, glom, prim, dend, s2d, s2p, p2g
  objref AMPA, GABAA, spikecount, spiketimes, synlist

  proc init() { local Len, Erest, RM, p, q, r, Atotal, gsp, gsd, gpg, AMPAtau, AMPArev, GABAAtau, GABAArev
    create soma, glom, prim, dend, s2d, s2p, p2g

	synlist = new List()
    spiketimes = new Vector()
    lastspikecount = 0

    Len 	= 100
    RM 		= 100000
    Erest	= -65		// mV
    Atotal	= 100000	// um2
    gsp		= 5.47e-11	// S/cm2
    gpg		= 5.86e-11
    gsd		= 1.94e-10
    RM		= 100000	// ohm.cm2
    p		= 0.051
    q		= 0.084
    r		= 0.328
    AMPAtau	= 10		//ms
    AMPArev	= 0		//mV
    GABAAtau	= 18		// 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)
	synlist.append(AMPA)
      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
    }
    dend {
      insert pas
      insert kfasttab
      insert nafast
      L			= Len
      diam 		= (1-p-q-r)*Atotal/(PI*Len)
      Ra 		= PI*diam*diam/(4*Len*Atotal)
      e_pas 		= Erest
      g_pas		= 1/RM
      gkbar_kfasttab	= 0.0330
      gnabar_nafast	= 0.0226
      GABAA = new ExpSyn(0.5)
	synlist.append(GABAA)
      GABAA.tau 	= GABAAtau
      GABAA.e 		= GABAArev
    }

    s2d { 
      diam 		= 1
      Ra = PI*diam*diam/(4*Len*Atotal) * ( 1/gsd )
      L 		= 1
    }
    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 s2d(0),1
    s2d connect dend(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
    }

  }	// end init()

proc connect2target() {
	dend $o2 = new NetCon(&v(0.5), $o1)
	$o2.threshold = thresh
}

endtemplate Mit