# Kuznetsova and Deth, JCN, 2007
# 10-cell model: 8 E cells (Ve1, Ve2, ...Ve8) and 2 I (Vi1, Vi2) cells
# only EE neighbours are  connected, all E to I 
# variables: V-voltage, R-K channel, C-Ca channel, H- Ca dependent K chanel, S,F - synapse 
# different init condit

init Ve1=-0.75 Ve2=-0.745 Ve3=-0.73 Ve4=-0.74 Ve5=-0.72 Ve6=-0.735 Ve7=-0.71 Ve8=-0.715
init Vi1=-0.75 Vi1=-0.71
init Re[1...8]=0.26
init Ce[1...8]=0.1
init He[1...8]=0.1
init Ri[1...2]=0.26
init Ci[1...2]=0.1


par Ie=0.6
#continuos input in all E cells, canceled in I cells
par GCe=0.1, GCi=0.25
par GHe=4.0

par TRe[1]=2.1
par TRe[2]=2.2
par TRe[3]=2.3
par TRe[4]=2.15
par TRe[5]=2.25
par TRe[6]=2.16
par TRe[7]=2.12
par TRe[8]=2.22
 
# this is time constant for K channel in E cells, it is varied from 6 to 2

par GSee=3.
#6/2, 3
par GSei=1.5
#6/4
par GSi=3.
#from I to E and I to I
par TRi[1..2]=1.5
# the same for in I cells, usualy it is not varied 

par TSe=2., TSi=8.
#par ESe=0, ESi=-0.75
#excit=0  inhib=-0.75
par W=-0.1

AlE=Se1+Se2+Se3+Se4+Se5+Se6+Se7+Se8
Fe1'=(1./TSe)*(-Fe1+heav(Ve1-W))
Se1'=(1./TSe)*(-Se1+Fe1)
Fe2'=(1./TSe)*(-Fe2+heav(Ve2-W))
Se2'=(1./TSe)*(-Se2+Fe2)
Fe3'=(1./TSe)*(-Fe3+heav(Ve3-W))
Se3'=(1./TSe)*(-Se3+Fe3)
Fe4'=(1./TSe)*(-Fe4+heav(Ve4-W))
Se4'=(1./TSe)*(-Se4+Fe4)
Fe5'=(1./TSe)*(-Fe5+heav(Ve5-W))
Se5'=(1./TSe)*(-Se5+Fe5)
Fe6'=(1./TSe)*(-Fe6+heav(Ve6-W))
Se6'=(1./TSe)*(-Se6+Fe6)
Fe7'=(1./TSe)*(-Fe7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