COMMENT
//****************************//
// Created by Alon Polsky 	//
//    apmega@yahoo.com		//
//		2007			//
//****************************//
ENDCOMMENT

TITLE NMDA synapse with depression

NEURON {
	POINT_PROCESS glutamate
	USEION ca READ cai WRITE ica VALENCE 2
	NONSPECIFIC_CURRENT inmda,iampa
	RANGE e, ntar,local_v,inmda,iampa,gh
	RANGE gnmdamax, gampamax
	RANGE del,Tspike,Nspike
	RANGE gnmda,gampa
	GLOBAL n, gama,tau1,tau2,tauh,cah
	GLOBAL tau3,tau4
}

UNITS {
	(nA) 	= (nanoamp)
	(mV)	= (millivolt)
	(nS) 	= (nanomho)
	(mM)    = (milli/liter)
        F	= 96480 (coul)
        R       = 8.314 (volt-coul/degC)

}

PARAMETER {
	gnmdamax=1	(nS)
	gampamax=1	(nS)
	e= 0.0	(mV)
	tau1=50	(ms)
	tau2=10	(ms)
	tau3=9	(ms)
	tau4=1	(ms)
	n=0.25 	(/mM)	
	gama=0.08 	(/mV) 
	dt (ms)
	ntar=1	:NMDA to AMPA ratio
	v		(mV)
	del=30	(ms)
	Tspike=10	(ms)
	Nspike=1
	cah   = 10	(/ms)		: max act rate  
	tauh   = 1000	(/ms)		: max deact rate 
}

ASSIGNED { 
	inmda		(nA)  
	iampa		(nA)  
	gnmda		(nS)
	gampa		(nS)
	gh		(nS)
	ica 		(mA/cm2)
	local_v	(mV):local voltage
	cai		(mM)	
}
STATE {
	A (nS)
	B (nS)
	C (nS)
	D (nS)
	h		(nS)

}

INITIAL {
      gnmda=0 
      gampa=0 
	h=0
	A=0
	B=0
	C=0
	D=0
}    

BREAKPOINT {  
    
	LOCAL count
	SOLVE state METHOD cnexp
	FROM count=0 TO Nspike-1 {
		IF(at_time(count*Tspike+del)){
			state_discontinuity( A, A+ gnmdamax)
			state_discontinuity( B, B+ gnmdamax)
			state_discontinuity( C, C+ gampamax/ntar)
			state_discontinuity( D, D+ gampamax/ntar)
		}
	}

	gnmda=(A-B)/(1+n*exp(-gama*v) )
	gh=(exp(-h))
	inmda =(1e-3)* gnmda * gh * (v-e)
	ica=inmda/10

	gampa=C-D

	iampa= (1e-3)*gampa*(v- e)
	local_v=v
}

DERIVATIVE state {
	A'=-A/tau1
	B'=-B/tau2
	C'=-C/tau3
	D'=-D/tau4
	h'=(cah*cai-h)/tauh
}