begintemplate GranuleSpine
public head, neck, all
create head, neck
objref all
proc init() {
	all = new SectionList()
	head all.append()
	neck all.append()
	connect head(0), neck(1)
	neck { L = 2  diam = .2 }
	head { L = 1  diam = 1 }
	memb()
}
proc memb() {
	forsec all {
		insert pas 
		insert kamt gbar_kamt=0.008 ek=-90
		insert nax gbar_nax=0.02 sh_nax=15 ena=60
		Ra = 80
		cm = 1
		g_pas = 1/30000
		e_pas = -65
		ek = -90
	}
}
endtemplate GranuleSpine

begintemplate Granule

public soma, priden, priden2, external_syn
public prilist
public position, x, y, z
objref external_syn

//create soma, priden2[3], priden
create soma, priden2[1], priden

objref prilist

proc init() {
	npri = 1
	create priden2[npri]
	prilist = new SectionList()
	priden prilist.append()
	for i=0, npri-1 priden2[i] { prilist.append() }
topol()
geometry()
segments()
memb()
	x = y = z = 0 // only change via position
}


proc topol() {local i
	connect priden(0), soma(1)
	for i=0, npri-1 {connect priden2[i](0), priden(.8)}
}

proc segments() {local i
	soma.nseg= 1
	forsec "priden" nseg = 10
}

proc geometry() {local i
	basic_shape()
	soma { L = 8  diam = 8}
	priden {L=150 diam=.5}
	for i=0, npri-1 {priden2[i] {L=100 diam=.4}}
//	define_shape()
}
	
proc basic_shape() {local i
  soma {pt3dclear() pt3dadd(0, 0, 0, 1) pt3dadd(0, 1, 0, 1)}
  priden {pt3dclear() pt3dadd(0, 0, 0, 1) pt3dadd(0, 1, 0, 1)}
  for i=0,npri-1 {
	priden2[i] {pt3dclear() pt3dadd(0, 0, 0, 1) pt3dadd(i/npri, 1, 0, 1)}
  }
}

proc memb() {
	forall {
		insert pas 
		insert kamt gbar_kamt=0.008 ek=-90
		insert nax gbar_nax=0.02 sh_nax=15 ena=60
		Ra = 80
		cm = 1
		g_pas = 1/30000
		e_pas = -65
		ek = -90
	}

	soma {
		gbar_nax=0.04
       		insert kdrmt gbar_kdrmt=0.006
		gbar_kamt = 0.004
		cm = 4
		g_pas = cm/30000
	}

	forsec prilist {
		cm = 4
		g_pas = cm/30000
	}
	 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 Granule