TITLE na3
: Na current for axon. No slow inact.
: M.Migliore Jul. 1997

NEURON {
	SUFFIX naxDA
	USEION na READ ena WRITE ina
	RANGE  gbar
	GLOBAL minf, hinf, mtau, htau,thinf, qinf
}

PARAMETER {
	tone_period = 6000   
	DA_period = 2000
	DA_start = 96000		    : D1R(Low Affinity) Dopamine Effect after 6 conditioning trials (16*6000) = 96000)
	DA_t1 = -0.3            : Amount of DA effect- negative value decreases AP threshold / positive value increases threshold of AP

	DA_period2 = 200
	DA_start2 = 54001		   : D2R(High Affinity) Dopamine Effect during shock after 1 conditioning trial
	DA_t2 = -0.9           : Amount(%) of DA effect- negative value decreases AP threshold / positive value increases threshold of AP	
	
	gbar = 0.010   	(mho/cm2)	
								
	tha  = -30	(mV)		: v 1/2 for act	
	qa   = 7.2	(mV)		: act slope (4.5)		
	Ra   = 0.4	(/ms)		: open (v)		
	Rb   = 0.124 	(/ms)		: close (v)		

	thi1  = -45	(mV)		: v 1/2 for inact 	
	thi2  = -45 	(mV)		: v 1/2 for inact 	
	qd   = 1.5	(mV)	        : inact tau slope
	qg   = 1.5      (mV)
	mmin=0.02	
	hmin=0.5			
	q10=2
	Rg   = 0.01 	(/ms)		: inact recov (v) 	
	Rd   = .03 	(/ms)		: inact (v)	
	thinf  = -50 	(mV)		: inact inf slope	
	qinf  = 4 	(mV)		: inact inf slope 

	ena		(mV)            : must be explicitly def. in hoc
	celsius		(degC)
	v 		(mV)
}


UNITS {
	(mA) = (milliamp)
	(mV) = (millivolt)
	(pS) = (picosiemens)
	(um) = (micron)
} 

ASSIGNED {
	ina 		(mA/cm2)
	thegna		(mho/cm2)
	minf 		hinf 		
	mtau (ms)	htau (ms) 	
	tha1
}
 

STATE { m h}

BREAKPOINT {
        SOLVE states METHOD cnexp
        thegna = gbar*m*m*m*h
	ina = thegna * (v - ena)
} 

INITIAL {
	trates(v)
	m=minf  
	h=hinf
}

DERIVATIVE states {   
        trates(v)      
        m' = (minf-m)/mtau
        h' = (hinf-h)/htau
}

PROCEDURE trates(vm) {  
        LOCAL  a, b, qt
        qt=q10^((celsius-24)/10)
		tha1 = tha + DA1(t)+ DA2(t)
	a = trap0(vm,tha1,Ra,qa)
	b = trap0(-vm,-tha1,Rb,qa)
	mtau = 1/(a+b)/qt
        if (mtau<mmin) {mtau=mmin}
	minf = a/(a+b)

	a = trap0(vm,thi1,Rd,qd)
	b = trap0(-vm,-thi2,Rg,qg)
	htau =  1/(a+b)/qt
        if (htau<hmin) {htau=hmin}
	hinf = 1/(1+exp((vm-thinf)/qinf))
}

FUNCTION trap0(v,th,a,q) {
	if (fabs(v-th) > 1e-6) {
	        trap0 = a * (v - th) / (1 - exp(-(v - th)/q))
	} else {
	        trap0 = a * q
 	}
}	

FUNCTION DA1(t) {
	    if (t > DA_start && (t/tone_period-floor(t/tone_period)) >= (1-DA_period/tone_period)) {DA1 = DA_t1}
		else if (t > DA_start && (t/tone_period-floor(t/tone_period)) == 0) {DA1 = DA_t1}
		else  {DA1 = 0}
	}
FUNCTION DA2(t) {
	    if (t > DA_start2 && (t/tone_period-floor(t/tone_period)) >= (1-DA_period2/tone_period)) {DA2 = DA_t2}
		else if (t > DA_start2 && (t/tone_period-floor(t/tone_period)) == 0) {DA2 = DA_t2}
		else  {DA2 = 0}
	}