//xopen("$(NEURONHOME)/lib/hoc/noload.hoc") 

v_init = -80
tstop = 420100 
dt = 0.01
celsius = 30 
cvode.active(1)
cvode.atol(1e-5)
create acell_home_
access acell_home_
nsyn1=4

 //Single compartment cell
begintemplate Grc
public syn1,ampa,nmda,ltp1
objref synlist, syn1[1],ampa[1],nmda[1],stim0, ltp1[1]
public soma,stim0
public synlist, connect2target
create soma
proc init(){
nsyn =$1
objectvar syn1[nsyn],ampa[nsyn],nmda[nsyn],ltp1[nsyn]
synlist= new List()
soma { 
	nseg = 1 
	diam = 9.772 
	L = 9.772 
	cm = 1
	Ra = 100
Area = PI*diam*L*1e-8
insert GrC_Lkg1
insert GrG_Na
insert GrG_Nar
insert GrG_KV 
insert GrC_KA 
insert GrC_Kir 
insert GrC_KCa
insert GrC_CaHVA 
insert Calc
insert GrC_pNa
insert GrG_KM
insert GrC_Lkg2
 ena = 87.39
 ek = -84.69
cao0_ca_ion = 2
cai0_ca_ion=0.0001
ecl = -65
stim0 = new IClamp(0.5)
for i=0, nsyn-1 {
syn1[i]= new GrC_Glu1(0.5)
ampa[i]=new GrC_AMPA(0.5)
nmda[i]=new GrC_NMDA(0.5)
ltp1[i]= new Gr_LTP1(0.5)
setpointer ltp1[i].picanmda, nmda[i].icanmda
setpointer nmda[i].pNp, ltp1[i].Np
setpointer ampa[i].pNp, ltp1[i].Np
setpointer nmda[i].pNd, ltp1[i].Nd
setpointer ampa[i].pNd, ltp1[i].Nd 
setpointer ampa[i].pglu, syn1[i].glu
setpointer nmda[i].pglu, syn1[i].glu 
}
}
for i=0, nsyn-1 {
 synlist.append(syn1[i])
}
}
proc connect2target(){soma $o2=new NetCon(&v(1),$o1)}
endtemplate Grc
begintemplate S1Gen
public pp, connect2target
external acell_home_
objref pp
proc init(){
acell_home_ pp= new SpGen2(0.5)}
proc connect2target(){$o2=new NetCon(pp,$o1)}
endtemplate S1Gen
ncells=1
nmossy=4
objref Mossy[nmossy],GrCell[ncells]
GrCell[0] = new Grc(nsyn1)
for i=0, nmossy -1 { 
Mossy[i]= new S1Gen()
}
objref cells, nclist, netcon
{cells = new List()  nclist = new List()}
func cell_append() {cells.append($o1)  
	return cells.count - 1 }
func nc_append() {//srcindex, tarcelindex, synindex
cells.object($1).connect2target(cells.object($2).synlist.object($3),netcon)
netcon.weight = $4   netcon.delay = $5
nclist.append(netcon)
return nclist.count - 1
}
//Network instantiation
    for i=0, nmossy-1 {
     cell_append(Mossy[i])
}
cell_append(GrCell[0])
for i=0, nsyn1-1 {
nc_append(i, 4, i, 0.5,0)
}
load_proc("nrnmainmenu") 
nrnmainmenu() 
xopen("ltpd.hoc")
xopen("mossy.hoc") 
load_file("init.ses")
xopen("fig.hoc")

// Initialization
finitialize(v_init)