begintemplate ET

// Note that ET secondary dendrites are of length 1 instead of 1000 like the mc 

public soma, priden, secden, tuftden, hillock, initialseg
public dendritic, somatic, second, somden, synodor, external_syn
public dampa
public position, x, y, z


create soma, priden, secden[2], tuftden, hillock, initialseg

forall {Ra = 150}

objref dendritic, somatic, somden, synodor, external_syn
objref dampa

proc init() {

dendritic = new SectionList()
forsec "priden" dendritic.append()
forsec "secden" dendritic.append()
forsec "tuftden" dendritic.append()

somatic = new SectionList()
soma somatic.append
hillock somatic.append

somden = new SectionList()
forsec somatic somden.append()
forsec dendritic somden.append()

topol()
segments()
geometry()
memb()
	x = y = z = 0 // only change via position
}


proc topol() {local i
	connect secden[0](0), soma(.5)
	connect secden[1](0), soma(.5)
	connect priden(0), soma(1)
	connect tuftden(0), priden(1)

	connect hillock(0), soma(0)
	connect initialseg(0), hillock(1)
}

proc segments() {local i
	soma.nseg= 1
	priden.nseg = 5
	forsec "tuftden" nseg = 10
	forsec "secden" nseg = 50
	initialseg.nseg = 3
	hillock.nseg = 3
}

proc geometry() {local i
	basic_shape()
	soma { L = 25  diam = 20 }
	priden { L = 150  diam = 3 } // L half of mc primary dend length
	//forsec "tuftden" {rallbranch=20 L=300  diam(0:1)=.4:.4 }
	forsec "tuftden" {rallbranch=10 L=200  diam(0:1)=1:1 }
	forsec "secden" { L=1  diam=2 } // reduced from 1000 for ET cells
	initialseg{ L=30  diam=1.5}
	hillock { L=5  diam(0:1) = soma.diam(0) : initialseg.diam(0) }
	//define_shape()
}
	
proc basic_shape() {
  soma {pt3dclear() pt3dadd(0, 0, 0, 1) pt3dadd(0, 1, 0, 1)}
  priden {pt3dclear() pt3dadd(0, 0, 0, 1) pt3dadd(0, 1, 0, 1)}
  tuftden {pt3dclear() pt3dadd(0, 0, 0, 1) pt3dadd(0, 1, 0, 1)}
  secden[0] {pt3dclear() pt3dadd(0, 0, 0, 1) pt3dadd(1, 0, 0, 1)}
  secden[1] {pt3dclear() pt3dadd(0, 0, 0, 1) pt3dadd(-1, 0, 0, 1)}
  hillock {pt3dclear() pt3dadd(0, 0, 0, 1) pt3dadd(0, -1, 0, 1)}
  initialseg {pt3dclear() pt3dadd(0, 0, 0, 1) pt3dadd(0, -1, 0, 1)}
}

proc memb() {
	forall {insert pas }
	forsec somden {
		insert nax  insert kamt insert kdrmt
		ek = -90
		ena = 50
		gbar_nax = 0.04 sh_nax=10
	 	gbar_kdrmt = 0.0001
		gbar_kamt = 0.004
		}

	forall {Ra = 150}

	totarea=0
	forall {
		for (x) {totarea=totarea+area(x)}
		cm = 1.8
		g_pas = 1/12000
		e_pas = -65
	}

	initialseg {
		insert nax  insert kamt insert kdrmt
		ek = -90
		ena = 50
	        g_pas = 1/1000
	        gbar_nax = 0.8
		sh_nax = 0
	        gbar_kamt = 0.08
	        gbar_kdrmt = 0.0001
	}       

  
	tuftden {
	synodor = new Exp2Syn(.2)
	synodor.e=0
	synodor.tau1 = 20
            	synodor.tau2 = 200

}
            soma {
                external_syn = new Exp2Syn(.5)
                external_syn.e=0
                external_syn.tau1 = 5
                external_syn.tau2 = 50  
            }

}

proc position() { local i
  soma for i = 0, n3d()-1 {
    pt3dchange(i, $1-x+x3d(i), $2-y+y3d(i), $3-z+z3d(i), diam3d(i))
  }
  x = $1  y = $2  z = $3
}

endtemplate ET