TITLE kc :Fast Ca-dependent K current

NEURON { 
	SUFFIX kc
	USEION k READ ek WRITE ik
	USEION ca READ cai
	RANGE  gkc, ik, alpha, beta
}

UNITS { 
	(molar) = (1/liter)
	(mV) =	(millivolt)
	(mA) =	(milliamp)
	(mM) =	(millimolar)
        FARADAY	= 96485.309 (coul/mole)
	PI	= (pi) (1) 
}

INDEPENDENT {t FROM 0 TO 1 WITH 100 (ms)}

PARAMETER { 
	gkc = 0.0 	(mho/cm2)
} 

ASSIGNED { 
	ik 	(mA/cm2) 
	alpha   (/ms)
        beta	(/ms)
	ek 	(mV)
	diam	(um)
	v       (mV)
	cai	(mM)
}
 
STATE {	m qk }

BREAKPOINT { 
	SOLVE states METHOD cnexp
	ik = gkc*min(cai/250(mM),1)*m*(v-ek)
}

INITIAL { 
	settables(v) 
	m = alpha/(alpha+beta)
	ik = gkc*min(cai/250(mM),1)*m*(v-ek)
	qk = 0
}
 
DERIVATIVE states { 
	settables(v) 
	m' = alpha*(1-m)-beta*m
	qk' = (-ik*diam*PI*(1e4)/FARADAY)/(diam*diam*PI/4)
}

UNITSOFF

PROCEDURE settables(v (mV)) { 
	TABLE alpha, beta FROM -120 TO 40 WITH 641

	if( v <= -10.0 ) {
		alpha = 1/18.975*(exp((v-10+60)/11-(v-6.5+60)/27))
		beta  = 2*exp((-v+6.5-60)/27)
	}else{
		alpha = 2*exp((-v+6.5-60)/27)
		beta  = 0
	}
}

UNITSON

FUNCTION min(x,y) { if (x<=y){ min = x }else{ min = y } }