// The ball and stick model as a template with inputs length and v_init.
// NO SPINES

begintemplate Cell
public init, biophys

public soma, iseg, axon, dend

proc init() {
	// $1 is branch length in microns
	// $2 is v_init
	bLength = $1
	voltInput = $2
	biophys(bLength,voltInput)
}

create iseg[40]
create axon
create soma
create dend[1]

proc biophys() {
	length = $1 		// length of dendrite in microns
	v_init = $2 		// resting membrane potential
	celsius=37		// nominal temperature of simulation
	Ri=100    		// internal resistivity in ohm-cm
	Cm=1.0	      		// specific membrane capacitance in uF/cm^2
	Rm=15000      		// specific membrane resistivity in ohm/cm^2
	na_soma=100		// somatic Na channel density in pS/um^2
	kv_soma=100		// somatic k channel density in pS/um^2

	access soma
	distance()

	create dend[length]

	soma {
		nseg = 3
		diam = 10
		L = 20
		insert na 
		gbar_na=na_soma
		insert kv
		gbar_kv=kv_soma
		connect iseg[0](0), 0
		nao = 150
		ek = -96
	}

	for i = 0, 39 {
		iseg[i] {
			nseg = 1
			diam = 2 - (1.5*(i/40))
			L = 1
			insert na
			insert kv
			if (i<5) {
				gbar_na=na_soma
				gbar_kv=kv_soma
			} else {
				gbar_na = 8000
				gbar_kv = 2000
			}

			nao=105
			ek=-96

			if (i<39) connect iseg[i+1](0), 1
			if (i==39) connect axon(0),1
		}
	}

	axon {
		nseg = 201
		L = 2000
		diam = .5
		insert na
		gbar_na = 300
		insert kv
		gbar_kv = 60
		nao = 150
		ek = -96
	}


	for i = 0, length-1 {
		access soma
		distance()

		access dend[i] 
			nseg = 1
			L = 1
			diam = 5 - ((4*i)/(length-1))
			if (i == 0) {
			connect soma(1), 0
			} else {
			connect dend[i-1](1), 0
			}
	}

	forall {
		insert pas
		g_pas = 1/Rm
		cm = Cm
		Ra = Ri
		e_pas = v_init
	}

	access axon
}

endtemplate Cell