//SYNAPTIC CONNECTIONS FLEXORS - IPSILATERAL


objref nclist_hi, nclist_lo, nclist_hi_motor_Ex, nclist_hi_motor_S, nclist_lom

{nclist_hi_motor_S = new List() nclist_hi = new List()  nclist_lo = new List() nclist_lom = new List() nclist_hi_motor_Ex = new List()}

//DELAYS
tausyn=1
Ia=1+tausyn
II=2+tausyn


//WEIGHTS

hi= 0.0175  //EPSP found from parameter search

// From Harrison et al 1981 EPSP on MN due to Iaf is clearly related to the motor unit mechanical properties
// and he found that the EPSPs due to a single Iaf are: 
// - 212uV for type S units - 126uV for type FR units - 52uV for type FF units.

// In this model only the S type neuron are considered 
hi_motor_S = 0.0411  //--> 0.2112 mV f

// Contribution of the Iaf of synergistic muscles (Segev 1990)
Heter_contribution = 0.28
hi_motor_S += hi_motor_S*Heter_contribution

hi_motor_Ex= (hi_motor_S*FromAll_IAf_ToOne_MN/FromAll_EXIN_ToOne_MN)/3



// From Pratt et al 1987 I took max IPSP ~ -2.9/2 mV - From McIntyre 2002 IPSP -3mV
// With lom of 0.0023 and networkSize of 1 the IPSP is of: -3.0260 mV
lom=0.0023  //IPSP MOTORNEURON --> 3.0260 mV 

lo=0.007 //5  //IPSP found from a systematiuc search from 0.001 to 0.01
gamma=2

// END WEIGHTS


objref r, target, syn
r = new Random()
//time tau random delay based on diameter variance (20%)
objref taur
taur =new Random()
{taur.normal(0,0.03)}




//SYNAPSES BETWEEN IAf AND MOTONEURONS
//EACH MOTONEURON IS CONNECTED TO ALL Ia FIBERS
{r.uniform(0, nIAf-1)}
for i=0, nMN-1{
    if (!pc.gid_exists(i)) { continue }
    target = pc.gid2cell(i)//target cell
    for j=0, nIAf-1{
        syn = target.synlist.object(j)
        nc = pc.gid_connect(j+nMN, syn)
        nc.weight = hi_motor_S
        nc.delay = Ia+taur.normal(0,0.03)
        nclist_hi_motor_S.append(nc)
    }
}

//SYNAPSES BETWEEN IAf AND IAInt
{r.uniform(0, nIAf-1)}
for i=nMN+nIAf, nMN+nIAf+nIAint-1{
    if (!pc.gid_exists(i)) { continue }
    target = pc.gid2cell(i)//target cell
    for j=0, FromAll_IAf_ToOne_IAint-1{  
        nc = pc.gid_connect(nMN+int(r.repick()), target)
        nc.weight = hi
        nc.delay = Ia+taur.normal(0,0.03)
        nclist_hi.append(nc)
    }
}

//SYNAPSES BETWEEN EXIN AND MOTONEURONS
{r.uniform(0, nEXIN-1)}
for i=0, nMN-1{
    if (!pc.gid_exists(i)) { continue }
    target = pc.gid2cell(i)//target cell
    for j=0, FromAll_EXIN_ToOne_MN-1{
        syn = target.synlist.object(j+nIAf)
        nc = pc.gid_connect(nIAf+nMN+nIAint+nIIf+int(r.repick()), syn)
        nc.weight = hi_motor_Ex
        nc.delay = tausyn
        nclist_hi_motor_Ex.append(nc)
    }
}

//SYNAPSES BETWEEN  IIf AND EXIN
{r.uniform(0, nIIf-1)}
for i=nIAf+nMN+nIAint+nIIf, nIAf+nMN+nIAint+nIIf+nEXIN-1{
    if (!pc.gid_exists(i)) { continue }
    target = pc.gid2cell(i)//target cell
    for j=0, FromAll_IIf_ToOne_EXIN-1{
        nc = pc.gid_connect(nIAf+nMN+nIAint+int(r.repick()), target)
        nc.weight = hi
        nc.delay = II+taur.normal(0,0.03)
        nclist_hi.append(nc)
    }
}

//SYNAPSES BETWEEN  IIf AND IAint
{r.uniform(0, nIIf-1)}
for i=nMN+nIAf, nMN+nIAf+nIAint-1{
    if (!pc.gid_exists(i)) { continue }
    target = pc.gid2cell(i)//target cell
    for j=0, FromAll_IIf_ToOne_IAint-1{
        nc = pc.gid_connect(nIAf+nMN+nIAint+int(r.repick()), target)
        nc.weight = hi
        nc.delay = II+taur.normal(0,0.03)
        nclist_hi.append(nc)
    }
}