-
Notifications
You must be signed in to change notification settings - Fork 0
/
cellM1.hoc
407 lines (336 loc) · 9.73 KB
/
cellM1.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
/*
Created by BluePyOpt(1.6.56) at 2019-03-06 18:13:41.288583
*/
{load_file("stdrun.hoc")}
{load_file("import3d.hoc")}
/*
* Check that global parameters are the same as with the optimization
*/
proc check_parameter(/* name, expected_value, value */){
strdef error
if($2 != $3){
sprint(error, "Parameter %s has different value %f != %f", $s1, $2, $3)
execerror(error)
}
}
proc check_simulator() {
check_parameter("celsius", 34, celsius)
check_parameter("v_init", -70, v_init)
}
begintemplate CA1_PC_cAC_sig
public init, morphology, geom_nseg_fixed, geom_nsec, gid
public channel_seed, channel_seed_set
public soma, dend, apic, axon, myelin
create soma[1], dend[1], apic[1], axon[1], myelin[1]
objref this, CellRef, segCounts
public all, somatic, apical, axonal, basal, myelinated, APC
objref all, somatic, apical, axonal, basal, myelinated, APC
proc init(/* args: morphology_dir, morphology_name */) {
all = new SectionList()
apical = new SectionList()
axonal = new SectionList()
basal = new SectionList()
somatic = new SectionList()
myelinated = new SectionList()
//gid in this case is only used for rng seeding
gid = 0
//For compatibility with BBP CCells
CellRef = this
forall delete_section()
if(numarg() >= 2) {
load_morphology($s1, $s2)
} else {
// load_morphology($s1, "mpg141017_a1-2_idC.asc")
load_morphology("morphology", "mpg141017_a1-2_idC.asc")
}
geom_nseg()
replace_axon()
insertChannel()
biophys()
// Initialize channel_seed_set to avoid accidents
channel_seed_set = 0
// Initialize random number generators
re_init_rng()
}
proc load_morphology(/* morphology_dir, morphology_name */) {localobj morph, import, sf, extension
strdef morph_path
sprint(morph_path, "%s/%s", $s1, $s2)
sf = new StringFunctions()
extension = new String()
sscanf(morph_path, "%s", extension.s)
sf.right(extension.s, sf.len(extension.s)-4)
if( strcmp(extension.s, ".asc") == 0 ) {
morph = new Import3d_Neurolucida3()
} else if( strcmp(extension.s, ".swc" ) == 0) {
morph = new Import3d_SWC_read()
} else {
printf("Unsupported file format: Morphology file has to end with .asc or .swc" )
quit()
}
morph.quiet = 1
morph.input(morph_path)
import = new Import3d_GUI(morph, 0)
import.instantiate(this)
}
/*
* Assignment of mechanism values based on distance from the soma
* Matches the BluePyOpt method
*/
proc distribute_distance(){local x localobj sl
strdef stmp, distfunc, mech
sl = $o1
mech = $s2
distfunc = $s3
this.soma[0] distance(0, 0.5)
sprint(distfunc, "%%s %s(%%f) = %s", mech, distfunc)
forsec sl for(x, 0) {
sprint(stmp, distfunc, secname(), x, distance(x))
execute(stmp)
}
}
proc geom_nseg() {
this.geom_nsec() //To count all sections
//TODO: geom_nseg_fixed depends on segCounts which is calculated by
// geom_nsec. Can this be collapsed?
this.geom_nseg_fixed(40)
this.geom_nsec() //To count all sections
}
proc insertChannel() {
forsec this.all {
insert pas
insert kdr
insert nax
}
forsec this.apical {
insert kad
insert hd
insert can
insert cal
insert cat
insert kca
insert cagk
insert cacum
}
forsec this.axonal {
insert kmb
insert kap
}
forsec this.basal {
insert kad
insert hd
insert can
insert cal
insert cat
insert kca
insert cagk
insert cacum
}
forsec this.somatic {
insert kmb
insert kap
insert hd
insert can
insert cal
insert cat
insert kca
insert cagk
insert cacum
}
forsec this.myelinated {
}
}
proc biophys() {
forsec CellRef.all {
cm = 1
ena = 50
ek = -90
}
forsec CellRef.apical {
gkdrbar_kdr = 0.0051140701369551591
gcalbar_cal = 1.3433464444108534e-06
gcanbar_can = 9.1375529468386047e-06
gcatbar_cat = 5.2627884427712998e-06
gbar_kca = 0.00011632706997854596
gbar_cagk = 3.8813989222985606e-05
gbar_nax = 0.023865342299765658
Ra = 102.93574883917653
g_pas = 3.6662171792438072e-05
}
forsec CellRef.axonal {
gbar_nax = 0.15092656523953063
gkdrbar_kdr = 0.012773439165875373
gbar_kmb = 0.015708771639181624
gkabar_kap = 0.17033392959442739
Ra = 68.659727248098548
g_pas = 0.00019814434729699748
e_pas = -60.050622497180008
}
forsec CellRef.basal {
gkdrbar_kdr = 0.0051140701369551591
gcalbar_cal = 1.3433464444108534e-06
gcanbar_can = 9.1375529468386047e-06
gcatbar_cat = 5.2627884427712998e-06
gbar_kca = 0.00011632706997854596
gbar_cagk = 3.8813989222985606e-05
gbar_nax = 0.0050344912419360861
Ra = 196.53208992869335
g_pas = 4.8328456800280221e-05
}
forsec CellRef.somatic {
gkabar_kap = 0.077773803027485822
gbar_nax = 0.03324329826147978
gbar_kmb = 0.0015345761039855402
Ra = 191.49312086794978
g_pas = 6.4696735301537531e-05
gkdrbar_kdr = 0.0051140701369551591
gcalbar_cal = 1.3433464444108534e-06
gcanbar_can = 9.1375529468386047e-06
gcatbar_cat = 5.2627884427712998e-06
gbar_kca = 0.00011632706997854596
gbar_cagk = 3.8813989222985606e-05
}
forsec CellRef.myelinated {
}
distribute_distance(CellRef.apical, "ghdbar_hd", "(1. + 3./100. * %.17g)*1.9139190469809671e-05")
distribute_distance(CellRef.apical, "e_pas", "(-66.279120044807371-5*%.17g/150)")
distribute_distance(CellRef.apical, "gkabar_kad", "(15./(1. + exp((300-%.17g)/50)))*0.013537136988629043")
distribute_distance(CellRef.basal, "ghdbar_hd", "(1. + 3./100. * %.17g)*1.9139190469809671e-05")
distribute_distance(CellRef.basal, "e_pas", "(-67.859607336867882-5*%.17g/150)")
distribute_distance(CellRef.basal, "gkabar_kad", "(15./(1. + exp((300-%.17g)/50)))*0.013537136988629043")
distribute_distance(CellRef.somatic, "e_pas", "(-71.397169317070947-5*%.17g/150)")
distribute_distance(CellRef.somatic, "ghdbar_hd", "(1. + 3./100. * %.17g)*1.9139190469809671e-05")
}
func sec_count(/* SectionList */) { local nSec
nSec = 0
forsec $o1 {
nSec += 1
}
return nSec
}
/*
* Iterate over the section and compute how many segments should be allocate to
* each.
*/
proc geom_nseg_fixed(/* chunkSize */) { local secIndex, chunkSize
chunkSize = $1
soma area(.5) // make sure diam reflects 3d points
secIndex = 0
forsec all {
nseg = 1 + 2*int(L/chunkSize)
segCounts.x[secIndex] = nseg
secIndex += 1
}
}
/*
* Count up the number of sections
*/
proc geom_nsec() { local nSec
nSecAll = sec_count(all)
nSecSoma = sec_count(somatic)
nSecApical = sec_count(apical)
nSecBasal = sec_count(basal)
nSecMyelinated = sec_count(myelinated)
nSecAxonalOrig = nSecAxonal = sec_count(axonal)
segCounts = new Vector()
segCounts.resize(nSecAll)
nSec = 0
forsec all {
segCounts.x[nSec] = nseg
nSec += 1
}
}
/*
* Replace the axon built from the original morphology file with a stub axon
*/
proc replace_axon(){local nSec, L_chunk, dist, i1, i2, count, L_target, chunkSize, L_real localobj diams, lens
L_target = 60 // length of stub axon
nseg0 = 5 // number of segments for each of the two axon sections
nseg_total = nseg0 * 2
chunkSize = L_target/nseg_total
nSec = 0
forsec axonal{nSec = nSec + 1}
// Try to grab info from original axon
if(nSec < 1){ //At least two axon sections have to be present!
execerror("Less than two axon sections are present! Add an axon to the morphology and try again!")
} else {
diams = new Vector()
lens = new Vector()
// access axon[0]
// i1 = v(0.0001) // used when serializing sections prior to sim start
// access axon[1]
// i2 = v(0.0001) // used when serializing sections prior to sim start
count = 0
forsec axonal{ // loop through all axon sections
nseg = 1 + int(L/chunkSize/2.)*2 //nseg to get diameter
for (x) {
if (x > 0 && x < 1) {
count = count + 1
diams.resize(count)
diams.x[count-1] = diam(x)
lens.resize(count)
lens.x[count-1] = L/nseg
if( count == nseg_total ){
break
}
}
}
if( count == nseg_total ){
break
}
}
// get rid of the old axon
forsec axonal{delete_section()}
execute1("create axon[2]", CellRef)
L_real = 0
count = 0
// new axon dependant on old diameters
for i=0,1{
access axon[i]
L = L_target/2
nseg = nseg_total/2
for (x) {
if (x > 0 && x < 1) {
diam(x) = diams.x[count]
L_real = L_real+lens.x[count]
count = count + 1
}
}
all.append()
axonal.append()
if (i == 0) {
v(0.0001) = i1
} else {
v(0.0001) = i2
}
}
nSecAxonal = 2
soma[0] connect axon[0](0), 1
axon[0] connect axon[1](0), 1
print "Target stub axon length:", L_target, "um, equivalent length: ", L_real "um"
}
}
func hash_str() {localobj sf strdef right
sf = new StringFunctions()
right = $s1
n_of_c = sf.len(right)
hash = 0
char_int = 0
for i = 0, n_of_c - 1 {
sscanf(right, "%c", & char_int)
hash = (hash * 31 + char_int) % (2 ^ 31 - 1)
sf.right(right, 1)
}
return hash
}
proc re_init_rng() {localobj sf
strdef full_str, name
sf = new StringFunctions()
if(numarg() == 1) {
// We received a third seed
channel_seed = $1
channel_seed_set = 1
} else {
channel_seed_set = 0
}
}
endtemplate CA1_PC_cAC_sig