// Channel layout from Golding et al. (2001)
// Migliore et al. (1999) channels
// spine correction
// axon 3 instead of elaborate original axon
// ===============================================================================

// parameters
// ----------

v_init = -65
celsius = 34.0

Rm = 40000
RmDend = Rm
RmSoma = Rm
RmAx = Rm
RmAxMy = 50

Cm    = 0.75
CmSoma= Cm
CmAx  = Cm
CmAxMy = 0.075
CmDend = Cm

RaAll= 200
RaSoma = 200
RaAx = RaAll //50

EK = -90
ENa = 55

// ===============================================================================

// variable defaults
// -----------------

SGNa = 45/10000
SGKdr = 40/10000
SGKAp = 100/10000

AxGNa = 0.5
AxGKdr = 0.4
AxGKAp = SGKAp*0.2
AxL = 500
Axdiam = 10

DbGNa = SGNa
DbGKdr = SGKdr
DbGKAp = SGKAp

DaGNay0 = SGNa
DaGNay1 = SGNa
DaGKdr = SGKdr
DaGKApy0 = SGKAp
DaGKApy1 = SGKAp*4

Rampx1 = 300
// ===============================================================================
// user access flag; conductance parameter flag; [gui name]; [variable name];
// ([] - if user access flag==1)
// variable value; range distribution formula

subtree = new Subtree("Soma",soma_section_list)
	channel = new Channel("pas")
		channel.add_parameter(new Channel_Parameter(0,0,"e_pas",v_init,"e_pas=v_init"))
		channel.add_parameter(new Channel_Parameter(0,1,"g_pas",1/RmSoma,"g_pas=1/RmSoma"))
		channel.add_parameter(new Channel_Parameter(0,0,"Ra",RaSoma,"Ra=RaSoma"))
		channel.add_parameter(new Channel_Parameter(0,0,"cm",CmSoma,"cm=CmSoma"))
	subtree.add_channel(channel)
	channel = new Channel("na_M")
		channel.add_parameter(new Channel_Parameter(1,1,"gbar_na_M","g Na+ (fast)","SGNa",SGNa,"gbar_na_M=SGNa"))
		channel.add_parameter(new Channel_Parameter(0,0,"ena",ENa,"ena=ENa"))
	subtree.add_channel(channel)
	channel = new Channel("kdr_M")
		channel.add_parameter(new Channel_Parameter(1,1,"gkdrbar_kdr_M","g K+ (dr)","SGKdr",SGKdr,"gkdrbar_kdr_M=SGKdr"))
		channel.add_parameter(new Channel_Parameter(0,0,"ek",EK,"ek=EK"))
	subtree.add_channel(channel)
	channel = new Channel("kap_M")
		channel.add_parameter(new Channel_Parameter(1,1,"gkabar_kap_M","g K+ (Ap)","SGKAp",SGKAp,"gkabar_kap_M=SGKAp"))
		channel.add_parameter(new Channel_Parameter(0,0,"ek",EK,"ek=EK"))
	subtree.add_channel(channel)
LAYOUT.add_subtree(subtree)

subtree = new Subtree("Basal Dendrite",dendrite_basal_section_list)
	channel = new Channel("pas")
		channel.add_parameter(new Channel_Parameter(0,0,"e_pas",v_init,"e_pas=v_init"))
		channel.add_parameter(new Channel_Parameter(0,1,"g_pas",1/RmDend,"for (x,0) { g_pas(x)=1/RmDend if (distance(x)>100) { g_pas(x)*=2 }}")) // spine compensation
		channel.add_parameter(new Channel_Parameter(0,0,"Ra",RaAll,"Ra=RaAll"))
		channel.add_parameter(new Channel_Parameter(0,0,"cm",CmDend,"for (x,0) { cm(x)=CmDend if (distance(x)>100) { cm(x)*=2 }}")) // spine compensation
	subtree.add_channel(channel)
	channel = new Channel("na_M")
		channel.add_parameter(new Channel_Parameter(1,1,"gbar_na_M","g Na+","DbGNa",DbGNa,"gbar_na_M=DbGNa"))
		channel.add_parameter(new Channel_Parameter(0,0,"ena",ENa,"ena=ENa"))
	subtree.add_channel(channel)
	channel = new Channel("kdr_M")
		channel.add_parameter(new Channel_Parameter(1,1,"gkdrbar_kdr_M","g K+ (dr)","DbGKdr",DbGKdr,"gkdrbar_kdr_M=DbGKdr"))
		channel.add_parameter(new Channel_Parameter(0,0,"ek",EK,"ek=EK"))
	subtree.add_channel(channel)
	channel = new Channel("kap_M")
		channel.add_parameter(new Channel_Parameter(1,1,"gkabar_kap_M","g K+ (Ap)","DbGKAp",DbGKAp,"gkabar_kap_M=DbGKAp"))
		channel.add_parameter(new Channel_Parameter(0,0,"ek",EK,"ek=EK"))
	subtree.add_channel(channel)
LAYOUT.add_subtree(subtree)

// non uniform density
// -------------------
proc apical_x() { local x1,y0,y1,m,xdist
	x1=$1 // ramp distance - where does it end
	y0=$2 // level at beginning of ramp
	y1=$3 // level at end of ramp
	if (x1>0) { m=(y1-y0)/x1 // ramp slope
	} else { m=0 }
	for (x,0) {
		xdist=distance(x)
		if (xdist>x1) {
			sprint(cmd,"%s(x)=%g",param.param_name,y1)
			execute(cmd)
		} else {
			sprint(cmd,"%s(x)=%g",param.param_name,y0+m*xdist)
			execute(cmd)
		}
	}
}

subtree = new Subtree("Apical Dendrite",dendrite_apical_section_list)
	channel = new Channel("pas")
		channel.add_parameter(new Channel_Parameter(0,0,"e_pas",v_init,"e_pas=v_init"))
		channel.add_parameter(new Channel_Parameter(0,1,"g_pas",1/RmDend,"for (x,0) { g_pas(x)=1/RmDend if (distance(x)>100) { g_pas(x)*=2 }}")) // spine compensation
		channel.add_parameter(new Channel_Parameter(0,0,"Ra",RaAll,"Ra=RaAll"))
		channel.add_parameter(new Channel_Parameter(0,0,"cm",CmDend,"for (x,0) { cm(x)=CmDend if (distance(x)>100) { cm(x)*=2 }}")) // spine compensation
	subtree.add_channel(channel)
	channel = new Channel("na_M")
		channel.add_parameter(new Channel_Parameter(1,0,"","g(0) Na+ (fast)","DaGNay0",DaGNay0,""))
		channel.add_parameter(new Channel_Parameter(1,1,"gbar_na_M","g(ramp) Na+ (fast)","DaGNay1",DaGNay1,"apical_x(Rampx1,DaGNay0,DaGNay1)"))
		channel.add_parameter(new Channel_Parameter(0,0,"ena",ENa,"ena=ENa"))
	subtree.add_channel(channel)
	channel = new Channel("kdr_M")
		channel.add_parameter(new Channel_Parameter(1,1,"gkdrbar_kdr_M","g K+ (dr)","DaGKdr",DaGKdr,"gkdrbar_kdr_M=DaGKdr"))
		channel.add_parameter(new Channel_Parameter(0,0,"ek",EK,"ek=EK"))
	subtree.add_channel(channel)
	channel = new Channel("kap_M")
		channel.add_parameter(new Channel_Parameter(1,0,"","g(0) K+ (Ap)","DaGKApy0",DaGKApy0,""))
		channel.add_parameter(new Channel_Parameter(1,1,"gkabar_kap_M","g(ramp) K+ (Ap)","DaGKApy1",DaGKApy1,"apical_x(Rampx1,DaGKApy0,DaGKApy1)"))
		channel.add_parameter(new Channel_Parameter(1,0,"","x(ramp)","Rampx1",Rampx1,""))
		channel.add_parameter(new Channel_Parameter(0,0,"ek",EK,"ek=EK"))
	subtree.add_channel(channel)
LAYOUT.add_subtree(subtree)

subtree = new Subtree("Axon",axon_section_list)
	channel = new Channel("pas")
		channel.add_parameter(new Channel_Parameter(0,0,"e_pas",v_init,"e_pas=v_init"))
		channel.add_parameter(new Channel_Parameter(0,1,"g_pas",1/RmAx,"g_pas=1/RmAx"))
		channel.add_parameter(new Channel_Parameter(0,0,"Ra",RaAx,"Ra=RaAx"))
		channel.add_parameter(new Channel_Parameter(0,0,"cm",CmAx,"cm=CmAx"))
		channel.add_parameter(new Channel_Parameter(1,0,"L","L","AxL",AxL,"L=AxL"))
		channel.add_parameter(new Channel_Parameter(1,0,"diam","diam","Axdiam",Axdiam,"diam=Axdiam"))
	subtree.add_channel(channel)
	channel = new Channel("nax_M")
		channel.add_parameter(new Channel_Parameter(1,1,"gbar_nax_M","g Na+ (fast)","AxGNa",AxGNa,"gbar_nax_M=AxGNa"))
		channel.add_parameter(new Channel_Parameter(0,0,"ena",ENa,"ena=ENa"))
	subtree.add_channel(channel)
	channel = new Channel("kdr_M")
		channel.add_parameter(new Channel_Parameter(1,1,"gkdrbar_kdr_M","g K+ (dr)","AxGKdr",AxGKdr,"gkdrbar_kdr_M=AxGKdr"))
		channel.add_parameter(new Channel_Parameter(0,0,"ek",EK,"ek=EK"))
	subtree.add_channel(channel)
	channel = new Channel("kap_M")
		channel.add_parameter(new Channel_Parameter(1,1,"gkabar_kap_M","g K+ (Ap)","AxGKAp",AxGKAp,"gkabar_kap_M=AxGKAp"))
		channel.add_parameter(new Channel_Parameter(0,0,"ek",EK,"ek=EK"))
	subtree.add_channel(channel)
LAYOUT.add_subtree(subtree)


// --------------------------------------------------------------------------------------