/* This experiment is the same as the experiment 3 but we extended our
data to include NMDAR current simulated by NMDA16 (Clarke's and Johnson's Model)
when membrane voltage is clamped to an AP.

We did this because we wanted to make MgBlock degree in our model 
comparable to the previous kinetic model
*/

load_file("nrngui.hoc")
load_file("params.hoc")

cvode.cache_efficient(1)  

tstop = 1271
dt = .025
celsius = 18
v_init = 40

Tau1 = 1.0676
Tau2_0 = 32.693
Wtau2 = 0.65
Tau3_0 = 217.69
A2 = 2.2364
B2 = 0.0243
A3 = 43.495
B3 = 0.01
k0 = 2.8261
DELTA = 0.8
SynWeight = 0.57
gVDst = 0.007

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

objref sNMDA, stim, stim1, nc, nc1, vc
stim = new NetStim(.5)
	stim.interval = 600
	stim.number = 2
	stim.start 	= 0
	stim.noise 	= 0
	
stim1 = new NetStim(.5)
	stim1.interval = 50
	stim1.number = 2
	stim1.start = 1201.534 - 1
	stim1.noise = 0	
	
sNMDA = new Exp4NMDA2(.5)
nc = new NetCon(stim, sNMDA)
nc1 = new NetCon(stim1, sNMDA)

proc init_NMDA() {
	nc.weight = SynWeight
	nc.delay = .001
	
	nc1.weight = SynWeight
	nc1.delay = 1
	
	sNMDA.tau1 = Tau1
	sNMDA.tau2_0 = Tau2_0
	sNMDA.a2 = A2
	sNMDA.b2 = B2
	sNMDA.wtau2 = Wtau2
	sNMDA.tau3_0 = Tau3_0
	sNMDA.a3 = A3
	sNMDA.b3 = B3
	sNMDA.K0 = k0
	sNMDA.delta = DELTA
	sNMDA.gVDst = gVDst
}
objref FinNMDA
FinNMDA = new FInitializeHandler(3,"init_NMDA()")
	
//----------------------------------------------------	
// load data
//------------Action Potential Clamp---------------------------	
objref vc, vRec, tRec, vFile, tFile

vRec = new Vector(1026)
tRec = new Vector(1026)
vFile = new File()
tFile = new File()

vFile.ropen("./Data/Exp05/v.dat")
tFile.ropen("./Data/Exp05/t.dat")
vRec.scanf(vFile)
tRec.scanf(tFile)

vc = new VClamp(.5)
	vc.dur[0] = tstop
	vRec.play(&vc.amp[0],tRec)

//-------Graphs
	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)

//--------Record Current
// 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()

load_file("MRFExp4SynFull-AP.ses")