//Migliore et al model with Kv4 csiosi Markov model replacing kad and kap
//uses csiosi_n160_mod.nrn as the source neuron 
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("csiosin160_mod.nrn")             // geometry file for CSI+OSI cell


tstop=200


csiosi_soma[5] distance()

access csiosi_soma[5]

csiosi_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 kv4csiosi gmax_kv4csiosi = KMULTP*0.2 ek=-90
}

csiosi_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 kv4csiosi gmax_kv4csiosi = KMULTP*0.2 ek=-90
}

for i=0,Numsoma-1 csiosi_soma[i] {   
                insert na3  gbar_na3=gna  ena=55
                ar2_na3=0.8
                insert kv4csiosi gmax_kv4csiosi = KMULTP ek=-90
                insert pas e_pas=Vrest g_pas = 1/RmSoma Ra=RaSoma cm=CmSoma
}

for i=0,Numbasal-1 csiosi_basal[i] {
                insert na3    gbar_na3=gna ena=55
                insert kdr gkdrbar_kdr=gkdr ek=-90
		ar2_na3=1
                insert kv4csiosi gmax_kv4csiosi=KMULTP ek=-90
                insert pas e_pas=Vrest g_pas = 1/RmDend Ra=RaAll cm=CmDend
}
                
for i=0,Numapical-1 csiosi_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 kv4csiosi ek=-90
		gmax_kv4csiosi=0

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