-
Notifications
You must be signed in to change notification settings - Fork 1
/
mgrs.hoc
242 lines (222 loc) · 5.87 KB
/
mgrs.hoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
//mitral-granule reciprocal synapse
//src, target
// assume src,target unique
func syn_gid() {local i
if ($1 < nmitral) { // target is granule
i = ($2 * nmitral + $1 + 1 + ncell) * 100 + 1
}else{ // target is mitral
i = ($1 * nmitral + $2 + 1 + ncell) * 100
}
return i
}
// gid, &mitral, &granule, &is_m2g
proc gid2mg() {local i, m, g, m2g
m2g = $1%2
i = $1 - m2g
i /=100
i -= ncell + 1
m = i%nmitral
i -= m
g = i/nmitral - nmitral
$&2 = m
$&3 = g
$&4 = m2g
}
// imitral, igranule, target_is_granule
proc test_gid2mg() {local gid, m, g, is_m2g
if ($3 == 0) {
gid = syn_gid($2+nmitral, $1)
}else{
gid = syn_gid($1, $2+nmitral)
}
gid2mg(gid, &m, &g, &is_m2g)
printf("gid2mg gid=%g m=%d g=%g is_m2g=%g\n", gid, m, g, is_m2g)
}
begintemplate MGRS
public md, gd, md_gid, gd_gid, clear, complete
public fi, ampanmda, mitral, granule, mitral_gid, granule_gid
public md2ampanmda, gd2fi, spine
public fi_exists, ampa_exists, mexist, gexist
public sm, sg, wm, wg, set_sm, set_sg, ws_str
public pr
external pc, pnm, syn_gid
external ncell, nmitral //, nil,amp, rel, inh,synst, nmdafactor
external gid2piece, piecegid
external global_fi_tau1, global_fi_tau2, global_exc_gmax, global_inh_gmax
objref mitral, granule
objref md2ampanmda, gd2fi
objref ampanmda, fi, md, gd, spine
objref this, nil, ws_str_
strdef tstr
proc clear() {
objref md2ampanmda, gd2fi
objref ampanmda, fi, md, gd
objref mitral, granule, spine
}
proc init() {
// if $7 == 1 then create fi and ampamda and put in cas
ws_str_ = new String()
mitral_gid = $1
granule_gid = $4
mexist = piecegid(mitral_gid) >= 0
gexist = piecegid(granule_gid) >= 0
md_gid = syn_gid(granule_gid, mitral_gid)
gd_gid = syn_gid(mitral_gid, granule_gid)
mitral = gid2piece(mitral_gid)
granule = gid2piece(granule_gid)
if (mexist) if (section_exists($s2, mitral)) {
// print mitral
create_syn("{mitral.%s { fi = new FastInhib(%-10.20g )}}",$s2, $3)
create_syn("{mitral.%s { md = new ThreshDetect(%-10.20g)}}",$s2, $3)
pc.set_gid2node(md_gid, pc.id)
pc.cell(md_gid, new NetCon(md, nil), 1)
// fi.gmax=0.003 // see update_netcon below
}
if (gexist) {
spine = new GranuleSpine()
create_syn("{granule.%s { connect spine.neck(0), (%-10.20g) }}", $s5, $6)
spine.head { ampanmda = new AmpaNmda(0.5) }
spine.head { gd = new ThreshDetect(0.5)}
pc.set_gid2node(gd_gid, pc.id)
pc.cell(gd_gid, new NetCon(gd, nil), 1)
// ampanmda.gmax=1 //default is 2 // see update_netcon below
}
// print pnm.myid, this, mexist, gexist
if ($7 == 1) { // for showing synapses and weights when cells do not exist
complete()
}
update_netcon()
}
proc complete() {
if (object_id(fi) == 0) {
fi = new FastInhib(0.5)
}
if (object_id(ampanmda) == 0) {
ampanmda = new AmpaNmda(0.5)
}
update_netcon()
}
proc update_netcon() {
if (object_id(ampanmda)) {
// print pnm.myid, this, mitral_gid, granule_gid
// print pnm.myid, this, md_gid,gd_gid
if (object_id(md2ampanmda) == 0) {
md2ampanmda = pc.gid_connect(md_gid, ampanmda)
}
// print pnm.myid, this, md2ampanmda,
ampanmda.mgid = mitral_gid
ampanmda.ggid = granule_gid
ampanmda.srcgid = md_gid
ampanmda.gmax = global_exc_gmax
}
if (object_id(fi)) {
// print pnm.myid, this, mitral_gid, granule_gid
// print pnm.myid, this, md_gid,gd_gid
if (object_id(gd2fi) == 0) {
gd2fi = pc.gid_connect(gd_gid, fi )
}
// print pnm.myid, this, gd2fi
fi.mgid = mitral_gid
fi.ggid = granule_gid
fi.srcgid = gd_gid
fi.gmax = global_inh_gmax
fi.tau1 = global_fi_tau1
fi.tau2 = global_fi_tau2
}
// print pnm.myid, this, mitral_gid, granule_gid, mitral, granule
if (object_id(md2ampanmda)) {
md2ampanmda.weight = 1 // normalized
md2ampanmda.delay = 1
}
if (object_id(gd2fi)) {
gd2fi.weight = 1 // normalized
gd2fi.delay = 1
}
}
proc create_syn() {
sprint(tstr, $s1, $s2, $3)
execute(tstr, this)
}
func fi_exists() {
return (fi != nil)
}
func ampa_exists() {
return (ampanmda != nil)
}
proc pr() {local x localobj s
s = new String()
if (object_id(md)) {
x = md.get_loc()
sprint(s.s, "%s(%g) %d --- ", secname(), x, mitral_gid)
pop_section()
}else{
sprint(s.s, "%27d --- ", mitral_gid)
}
if (object_id(gd)) {
x = gd.get_loc()
sprint(s.s, "%s%d %s(%g)", s.s, granule_gid, secname(), x)
pop_section()
}else{
sprint(s.s, "%s%d", s.s, granule_gid)
}
printf("%d %s\n", pnm.myid, s.s)
}
//returns volatile String in proper wsfile format
// srcid tarid s w
// may be one line or two, no trailing newline
obfunc ws_str() {
if (object_id(gd2fi)) {
if (object_id(md2ampanmda)) {
sprint(ws_str_.s, "%d %d %g %g\n%d %d %g %g",\
granule_gid, mitral_gid, sm(), wm(),\
mitral_gid, granule_gid, sg(), wg())
}else{
sprint(ws_str_.s, "%d %d %g %g",\
granule_gid, mitral_gid, sm(), wm())
}
}else if (object_id(md2ampanmda)) {
sprint(ws_str_.s, "%d %d %g %g", mitral_gid, granule_gid, sg(), wg())
}else{
ws_str_.s = ""
}
return ws_str_
}
proc set_sm() {
if (object_id(gd2fi)) {
gd2fi.weight[1] = $1
gd2fi.weight[2] = gd2fi.weight[0]*fi.plast($1)
}
}
proc set_sg() {
if (object_id(md2ampanmda)){
md2ampanmda.weight[1] = $1
md2ampanmda.weight[2] = md2ampanmda.weight[0]*ampanmda.plast($1)
}
}
func sm() {
return gd2fi.weight[1]
}
func sg() {
return md2ampanmda.weight[1]
}
func wm() {
return gd2fi.weight[2] * fi.gmax
}
func wg() {
return md2ampanmda.weight[2] * ampanmda.gmax
}
endtemplate MGRS
objref mgrs_list
mgrs_list = new List()
obfunc mk_mgrs() { local mitral_gid, granule_gid localobj mgrs
//$1 is the imitral, $s2 section name, $3 section arc position,
//$4 is the igranule, $s5 section name, $6 section arc position
mitral_gid = $1
granule_gid = $4 + ngranule_begin
if ($7 || exists(mitral_gid, $s2) || exists(granule_gid, $s5)) {
mgrs = new MGRS(mitral_gid, $s2, $3, granule_gid, $s5, $6, $7)
mgrs_list.append(mgrs)
return mgrs
}
return nil
}