{load_file("nrngui.hoc")}  // load the GUI and standard run libraries

{load_file("../cells/bistratified_cell.hoc")} //load axoaxonic cell

{xopen("kblock.hoc")} //execute open.load_file just reads


strdef temp_mkdir, temp_dir
// Create the directory
sprint(temp_dir, "SynapticProperties/")
sprint(temp_mkdir, "mkdir -p %s", temp_dir)
system(temp_mkdir)

objectvar 	Cell1, Cell2, Cell3, Cell4, Cell5, Cell6, Cell7
objectvar 	syn1, syn2, syn3, syn4, syn5, syn6, syn7
objectvar   nclist, stim, sn1, sn2, sn3, sn4, sn5, sn6, sn7
objectvar   clamp1, clamp2, clamp3, clamp4, clamp5, clamp6, clamp7
objref 		sn1, i1_ca1, i2_ca1, i3_ca1, i4_ca1, i5_ca1, i6_ca1, i7_ca1
objref      FILE1, FILE2, FILE3, FILE4, FILE5, FILE6, FILE7
strdef 		tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7


Cell1 = new BistratifiedCell()  // template for synapse EC to BSC
Cell2 = new BistratifiedCell()  // template for synapse CA3 to BSC
Cell3 = new BistratifiedCell()  // template for synapse PC to BSC
Cell4 = new BistratifiedCell()  // template for synapse BC to BSC
Cell5 = new BistratifiedCell()  // template for synapse BSC to BSC
Cell6 = new BistratifiedCell()  // template for synapse OLM to BSC
Cell7 = new BistratifiedCell()  // template for synapse VIPCCK to BSC



stim = new NetStim (0.5)
stim.interval 	= 1
stim.number		= 1
stim.start		= 900


// Time parameters///////////////////////////////
tstop = 2000 //stop time in ms
steps_per_ms = 10
dt    = 0.1
n     = tstop*steps_per_ms



//Vclamp for AMPA & GABAA
print "Vclamp"
factor2 = 1.0

//making EC synapse to BSC at radMed1 dendrite
//weigth_ECtoBSC 
w1 = 1.5e-4

Cell1.radMed1  syn1 = new MyExp2Syn(0.5) 
syn1.tau1 = 2.0
syn1.tau2 = 6.3
syn1.e 	  = 0
//making the netcon
sn1	= new NetCon(stim, syn1, -20, 1, w1)



//making CA3 synapse to BSC at radMed1 dendrite
//weigth_CA3toBSC 
w2 = 1.5e-4

Cell2.radMed1 syn2 = new MyExp2Syn(0.5)
syn2.tau1 = 2.0
syn2.tau2 = 6.3
syn2.e    = 0
//making the netcon 
sn2	= new NetCon (stim,syn2,-20, 1, w2)  //..threshold,delay,weight)



//making PC synapse to BSC at oriProx1 dendrite
//weigth_PCtoBSC 
w3 = 1.9e-3

Cell3.oriProx1  syn3 = new MyExp2Syn(0.5) 
syn3.tau1 = 0.11
syn3.tau2 = 0.25
syn3.e 	  = 0
//making the netcon
sn3	= new NetCon(stim, syn3, -20, 1, w3)



//making BC synapse to BSC at soma
//weigth_BCtoBSC 
w4 = 2.9e-3*factor2

Cell4.soma  syn4 = new MyExp2Syn(0.5) 
syn4.tau1 = 0.29
syn4.tau2 = 2.67
syn4.e 	  = -75
//making the netcon
sn4	= new NetCon(stim, syn4, -20, 1, w4)



//making BSC synapse to BSC at radMed1 dendrite
//weigth_BSCtoBSC 
w5 = 5.1e-4*factor2

Cell5.radMed1   syn5 = new MyExp2Syn(0.5) 
syn5.tau1 = 0.29
syn5.tau2 = 2.67
syn5.e 	  = -75
//making the netcon
sn5	= new NetCon(stim, syn5, -20, 1, w5)



//making OLM synapse to BSC at radDist1 dendrite
//weigth_OLMtoBSC 
w6 = 1.1e-4*factor2

Cell6.radDist1  syn6 = new MyExp2Syn(0.5) 
syn6.tau1 = 0.60
syn6.tau2 = 15.0
syn6.e 	  = -75
//making the netcon
sn6	= new NetCon(stim, syn6, -20, 1, w6)



//making VIPCCK synapse to BSC at soma
//weigth_VIPCCKtoBSC 
w7 = 7.0e-4*factor2

Cell7.soma  syn7 = new MyExp2Syn(0.5) 
syn7.tau1 = 0.43
syn7.tau2 = 4.49 	
syn7.e 	  = -75
//making the netcon
sn7	= new NetCon(stim, syn7, -20, 1, w7)


//Vclamp at soma
Cell1.soma clamp1 = new VClamp(0.5)  
Cell2.soma clamp2 = new VClamp(0.5)  
Cell3.soma clamp3 = new VClamp(0.5)  
Cell4.soma clamp4 = new VClamp(0.5)  
Cell5.soma clamp5 = new VClamp(0.5)
Cell6.soma clamp6 = new VClamp(0.5)
Cell7.soma clamp7 = new VClamp(0.5)  


clamp1.dur[0]= 2000			//duration of clamp in ms
clamp1.amp[0]= -67       //voltage clamp amplitude / near to Vrest

clamp2.dur[0]= 2000			
clamp2.amp[0]= -67

clamp3.dur[0]= 2000			
clamp3.amp[0]= -67

clamp4.dur[0]= 2000			
clamp4.amp[0]= -67

clamp5.dur[0]= 2000			
clamp5.amp[0]= -67

clamp6.dur[0]= 2000			
clamp6.amp[0]= -67

clamp7.dur[0]= 2000			
clamp7.amp[0]= -67

//cutting potasium
//k_block()
//making the vectors	
i1_ca1 = new Vector(n)
i2_ca1 = new Vector(n)
i3_ca1 = new Vector(n)
i4_ca1 = new Vector(n)
i5_ca1 = new Vector(n)
i6_ca1 = new Vector(n)
i7_ca1 = new Vector(n)

//recording
i1_ca1.record(&clamp1.i)
i2_ca1.record(&clamp2.i)
i3_ca1.record(&clamp3.i)
i4_ca1.record(&clamp4.i)
i5_ca1.record(&clamp5.i)
i6_ca1.record(&clamp6.i)
i7_ca1.record(&clamp7.i)


run()

FILE1 = new File()
sprint(tmp1, "SynapticProperties/ECtoBSC_i_rec_soma.txt")
FILE1.wopen(tmp1)
for i=0, i1_ca1.size()-1 {FILE1.printf("%f\n",i1_ca1.x[i])}
FILE1.close()

FILE2 = new File()
sprint(tmp2, "SynapticProperties/CA3toBSC_i_rec_soma.txt")
FILE2.wopen(tmp2)
for i=0, i2_ca1.size()-1 {FILE2.printf("%f\n",i2_ca1.x[i])}
FILE2.close()	

FILE3 = new File()
sprint(tmp3, "SynapticProperties/PCtoBSC_i_rec_soma.txt")
FILE3.wopen(tmp3)
for i=0, i3_ca1.size()-1 {FILE3.printf("%f\n",i3_ca1.x[i])}
FILE3.close()	

FILE4 = new File()
sprint(tmp4, "SynapticProperties/BCtoBSC_i_rec_soma.txt")
FILE4.wopen(tmp4)
for i=0, i4_ca1.size()-1 {FILE4.printf("%f\n",i4_ca1.x[i])}
FILE4.close()	

FILE5 = new File()
sprint(tmp5, "SynapticProperties/BSCtoBSC_i_rec_soma.txt")
FILE5.wopen(tmp5)
for i=0, i5_ca1.size()-1 {FILE5.printf("%f\n",i5_ca1.x[i])}
FILE5.close()	

FILE6 = new File()
sprint(tmp6, "SynapticProperties/OLMtoBSC_i_rec_soma.txt")
FILE6.wopen(tmp6)
for i=0, i6_ca1.size()-1 {FILE6.printf("%f\n",i6_ca1.x[i])}
FILE6.close()	

FILE7 = new File()
sprint(tmp7, "SynapticProperties/VIPCCKtoBSC_i_rec_soma.txt")
FILE7.wopen(tmp7)
for i=0, i7_ca1.size()-1 {FILE7.printf("%f\n",i7_ca1.x[i])}
FILE7.close()