/* In our experiments we understand that voltage dependent change in
the condunctance of NMDAR alone cannot explain the voltage-dependnent change 
in the time constant: we understand that in a double-exponential model
tau1 and tau2 are also voltage dependent
tau1 has a exponential dacey in responce to voltage
tau2 has a exponential rise to a maximum in responce to voltage

Using data from Spruston95 data, in this experiment we want to find 
an estimate of these parameters in CA1 pyramidal cells.

note: SynExp3NMDA2.mod model resets itself after 590 ms from the start of
the simulation so that we can fit our model to both recordings at the same time
*/
load_file("nrngui.hoc")
load_file("params.hoc")

//fully activates cache efficiency
cvode.cache_efficient(1)  

tstop = 1200
dt = .025
celsius = 18	//room temperature in spruston95 experiment
v_init = 40

A1 = 1.5006
A2 = 27.954
Tau1_0 = 3.531
Tau2_0 = 462.39
SynWeight = 0.55376

// ------------------
create soma
access soma

objref sNMDA, stim, nc
stim = new NetStim(.5)
	stim.interval = 600	//ms (mean) time between spikes
	stim.number = 3	//(average) number of spikes
	stim.start 	= 0	//ms (most likely) start time of first spike
	stim.noise 	= 0		//---- range 0 to 1. Fractional randomness.
	//0 deterministic, 1 intervals have negexp distribution.
sNMDA = new Exp3NMDA2(.5)
nc = new NetCon(stim, sNMDA)

proc init_NMDA() {
	sNMDA.a1 = A1
	sNMDA.tau1_0 = Tau1_0
	sNMDA.a2 = A2
	sNMDA.tau2_0 = Tau2_0
	
	nc.weight = SynWeight
	nc.delay = .001
}
objref FinNMDA
FinNMDA = new FInitializeHandler(3,"init_NMDA()")
	
//----------------------------------------------------	
objref vc, vscr, tvec

vscr = new Vector(12)
tvec = new Vector(12)

vscr.x[0] = 40
tvec.x[0] = 0

vscr.x[1] = -80
tvec.x[1] = 510

vscr.x[2] = 40
tvec.x[2] = 647.175

vscr.x[3] = -80
tvec.x[3] = 652.743

vscr.x[4] = 40
tvec.x[4] = 745.74

vscr.x[5] = -80
tvec.x[5] = 751.352

vscr.x[6] = 40
tvec.x[6] = 845.027

vscr.x[7] = -80
tvec.x[7] = 850.629

vscr.x[8] = 40
tvec.x[8] = 944.315

vscr.x[9] = -80
tvec.x[9] = 950.179

vscr.x[10] = 40
tvec.x[10] = 1044.6659

vscr.x[11] = -80
tvec.x[11] = 1049.6795

vc = new VClamp(.5)
	vc.dur[0] = tstop
	vscr.play(&vc.amp[0],tvec)
/*
objref iNMDA, vSoma
iNMDA = new Graph()
iNMDA.size(0,tstop,-1,50)
iNMDA.addvar("sNMDA.i",3,0)
iNMDA.save_name("graphList[0].")
graphList[0].append(iNMDA)

vSoma = new Graph()
vSoma.size(0,tstop,-100,50)
vSoma.addvar("soma.v(.5)",3,0)
vSoma.save_name("graphList[0].")
graphList[0].append(vSoma)
*/

load_file("MRFExp3SynFull.ses")

// objref iNMDA, iFile, time, tFile
// iNMDA = new Vector()
// iNMDA.record(&sNMDA.i)
// iFile = new File("iFile.dat")
// iFile.wopen("iFile.dat")

// time = new Vector()
// time.record(&t)
// tFile = new File("tFile.dat")
// tFile.wopen("tFile.dat")

// init()
// run()

// iNMDA.printf(iFile)
// iFile.close()

// time.printf(tFile)
// tFile.close()