/* Author: Xu Zhang @UConn, Jan., 2019
Synaptic mechanisms between PY (MC)-GrL
The 3 types of integrate-and-fire neurons in GrL are created in this script.
This script cannot be executed individually
*/

//////////////////////////////////////////////
// Relay of PYcell inputs by PN (mossy fiber)

double PY2PNnum[4]
PY2PNnum[0] = 2
PY2PNnum[1] = 8
PY2PNnum[2] = 13
PY2PNnum[3] = 19
//////////////////////////////////////////////

//////////////////////////////////////////////

objref GRcell[4], GOcell[4], STLcell[4]
objref syn_mfgrc_ampa[4], syn_mfgrc_nmda[4], syn_mfgoc_ampa[4]

for k = 0,3 {
	PY2PNtmp = PY2PNnum[k]
	PYcell[PY2PNtmp] GRcell[k] =  new GrC(0.92)
	PYcell[PY2PNtmp] GOcell[k] =  new GoC(0.95)
	PYcell[PY2PNtmp] STLcell[k] =  new StellC(0.98)

	PYcell[PY2PNtmp] syn_mfgoc_ampa[k] = new NetCon(&v(1), GOcell[k], -40, 3+1, 1*50) // Delay (3 ms) determined from Sasaki et al., 1970 (Ito 1970?)
	PYcell[PY2PNtmp] syn_mfgrc_ampa[k] = new NetCon(&v(1), GRcell[k], -40, 3+1, 0.87*4)
	PYcell[PY2PNtmp] syn_mfgrc_nmda[k] = new NetCon(&v(1), GRcell[k], -40, 3+1, 0.087*4)
}

////////// GRANULE CELL //////////
// Synaptic inputs to Granule cell
objref syn_gocgrc_gaba[4]
for k = 0,3 {
GOcell[k] syn_gocgrc_gaba[k] = new NetCon(GOcell[k], GRcell[k], -50, 0.5, 1.5*4)
}

// (Roundabout) spike detection mechanism in Granule cell
/* Not a very smart way of spike detection. Here it is achieved by sending a particular
	NetCon event which has the specific weight 0.02 after every NetStim interval. This 
	weight is recognized inside GrL cell mechanism (grl_grc.mod) to check whether to 
	trigger the spiking	event. Same for Golgi cell and stellate cell.
*/
objref grcspk[4] ,grcspknc[4]
for k = 0,3 {
GRcell[k] grcspk[k] = new NetStim(0.5)
grcspk[k].number=1e10
grcspk[k].interval=0.5
grcspk[k].start=0
grcspk[k].noise=0
grcspk[k] grcspknc[k] = new NetCon(grcspk[k], GRcell[k], 0, 0, 0.02)
}

////////// GOLGI CELL //////////
// Synaptic inputs to Golgi cell
objref syn_grcgoc_ampa[4], syn_scgoc_gaba[4]
for k = 0,3 {
GRcell[k] syn_grcgoc_ampa[k] = new NetCon(GRcell[k], GOcell[k], -40, 1, 3*100)
STLcell[k] syn_scgoc_gaba[k] = new NetCon(STLcell[k], GOcell[k], -40, 1, 0.25*50)
}
// Spike detection in Golgi cell
objref gocspk[4], gocspknc[4]
for k = 0,3 {
GOcell[k] gocspk[k] = new NetStim(0.5)
gocspk[k].number=1e10
gocspk[k].interval=0.5
gocspk[k].start=0
gocspk[k].noise=0
gocspk[k] gocspknc[k] = new NetCon(gocspk[k], GOcell[k], 0, 0, 0.02)
}

////////// STELLATE CELL //////////
// Synaptic inputs to Stellate cell
objref syn_grcsc_ampa[4]
for k = 0,3 {
GRcell[k] syn_grcsc_ampa[k] = new NetCon(GRcell[k], STLcell[k], -40, 1, 0.3*100)
}
// Spike detection in Stellate cell
objref scspk[4], scspknc[4]
for k = 0,3 {
STLcell[k] scspk[k] = new NetStim(0.5)
scspk[k].number=1e10
scspk[k].interval=0.5
scspk[k].start=0
scspk[k].noise=0
scspk[k] scspknc[k] = new NetCon(scspk[k], STLcell[k], 0, 0, 0.02)
}