//Migliore et al model with Kv4 CSI Markov model replacing kad and kap
cvode.active(1)

mid=12
dist=27
secondorder=2
FARADAY=96520
PI=3.14159

Rm = 28000
RmDend = Rm/2
RmSoma = Rm
RmAx = Rm

Cm    = 1
CmSoma= Cm
CmAx  = Cm
CmDend = Cm*2

RaAll= 150
RaSoma=150  
RaAx = 50

Vrest = -65
dt = 0.025
gna =  .032
AXONM = 2
gkdr = 0.01
celsius = 34.0  
KMULT =  0.144
KMULTP = 0.144

xopen("csin160_mod.nrn")             // geometry file for csi cell

tstop=200


csi_soma[5] distance()

access csi_soma[5]

csi_axon[1] {
                insert nax    gbar_nax=gna * AXONM ena=55
                insert kdr gkdrbar_kdr=gkdr ek=-90
                insert pas e_pas=Vrest g_pas = 1/RmAx Ra=RaAx cm=CmAx
                insert kv4csi gmax_kv4csi = KMULTP*0.2 ek=-90
}

csi_axon[0] {   
                insert nax  gbar_nax=gna * AXONM ena=55
                insert kdr  gkdrbar_kdr=gkdr ek=-90
                insert pas e_pas=Vrest g_pas = 1/RmAx Ra=RaAx cm=CmAx
                insert kv4csi gmax_kv4csi = KMULTP*0.2 ek=-90
}

for i=0,Numsoma-1 csi_soma[i] {   
                insert na3  gbar_na3=gna  ena=55
                insert kdr gkdrbar_kdr=gkdr ek=-90
		ar2_na3=0.8
                insert kv4csi gmax_kv4csi = KMULTP ek=-90
                insert pas e_pas=Vrest g_pas = 1/RmSoma Ra=RaSoma cm=CmSoma
}

for i=0,Numbasal-1 csi_basal[i] {
                insert na3    gbar_na3=gna ena=55
                insert kdr gkdrbar_kdr=gkdr ek=-90
		ar2_na3=1
                insert kv4csi gmax_kv4csi=KMULTP ek=-90
                insert pas e_pas=Vrest g_pas = 1/RmDend Ra=RaAll cm=CmDend
}
                
for i=0,Numapical-1 csi_apical[i] {
//if (i<40) {printf(" %d, %g \n",i,distance(0.5))}
              insert pas e_pas=Vrest g_pas = 1/RmDend Ra=RaAll  cm=CmDend
              for (x){ xdist = distance(x)
			}
			if (diam>0.5 && distance(0.5)<500) {
                insert na3 ena=55
		ar2_na3=0.5
		gbar_na3=gna
                insert kdr ek=-90
		gkdrbar_kdr=gkdr
		insert kv4csi ek=-90
		gmax_kv4csi=0

              for (x){ xdist = distance(x)
                if (xdist>500) {xdist=500}
                if (xdist > 100){
                        gmax_kv4csi(x) = KMULT*(1+xdist/100)
                } else {
                        gmax_kv4csi(x) = KMULTP*(1+xdist/100)
                	}
              				}
							}
				}