-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.hoc
916 lines (777 loc) · 32.3 KB
/
main.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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
{load_file("nrngui.hoc")} // loads the gui and standard run libraries
{load_file("netparmpi.hoc")} // parallelnetmanager definitions
objref nil
strdef modelName, datasetPrefix, datasetName, datasetPath, resultsPath
// parameters must be the name of a file specified on the command line
// as follows: nrniv -c "strdef parameters" -c "parameters=\"parameters.hoc\""
{load_file(parameters)}
{cvode.active(use_cvode)}
{cvode.use_local_dt(use_local_dt)}
{cvode.cache_efficient(use_cache_efficient)}
{xopen("lib.hoc")}
// path to the dataset directory
sprint(datasetPath, "%s/%s", datasetPrefix, datasetName)
//nrn_load_dll("mechanisms/x86_64/.libs/libnrnmech.so")
// used to calculate model construction times and run time
mkcellstime = 0
connectcellstime = 0
connectgjstime = 0
// used for executing command strings
strdef cmd
tstop = mytstop
// path for various datafiles (used for multiple files)
strdef datafilePath
// randomstream template
{load_file("./templates/ranstream.hoc")}
// stimulus cell template
{load_file("./templates/StimCell.hoc")}
// used for recording membrane potentials
objref indicesVrecord
if (!(name_declared("vrecordFraction"))) {
vrecordFraction = 0
}
if (vrecordFraction > 1) {
vrecordFraction = 1
}
if (vrecordFraction < 0) {
vrecordFraction = 0
}
if (!(name_declared("vrecordLimit"))) {
vrecordLimit = 100
}
if (vrecordLimit < 0) {
vrecordLimit = 0
}
// Builds a list of indices of cells to record from
proc mkvrecord() { local nCellTypes, numCells, numRec, i, j, k, offset, n, p, fraction localobj pnm, cellTypes, cellType, indices, rec_indices, rs
pnm = $o1
rec_indices = $o2
cellTypes = $o3
fraction = $4
nCellTypes = cellTypes.count()
for k=0, nCellTypes-1 {
rs = new RandomStream(k, 0, 0)
cellType = cellTypes.o(k)
numCells = cellType.getPropertyScalar("numCells")
numCellsPerHost = int(numCells / pnm.pc.nhost)
offset = cellType.getPropertyScalar("offset")
if ((numCellsPerHost < 1) ) {
if (pnm.myid < numCells) {
numRec = 1
} else {
numRec = 0
}
} else {
numRec = int(fraction * numCellsPerHost)
if (numRec < 1) {
numRec = 1
}
}
if ((vrecordLimit > 0) && (numRec > vrecordLimit)) {
numRec = vrecordLimit
}
if (verbose > 0) {
printf ("cell type %s: numCells = %d numRec = %d\n", cellType.getPropertyString("typeName").s, numCells, numRec)
}
if (cellType.hasProperty("indices")) {
indices = cellType.getPropertyObject("indices")
} else {
indices = new Vector()
indices.resize(numCells)
for i = 0, numCells-1 {
indices.x[i] = i+offset
}
}
if (numRec > 1) {
rs.r.discunif(0,numCellsPerHost-1)
for i=0, numRec-1 {
n = rs.repick()
j = pnm.myid + n * pnm.pc.nhost
rec_indices.prepend(new Value(0,indices.x[j]))
}
} else if (numRec == 1) {
rec_indices.prepend(new Value(0,indices.x[pnm.myid]))
}
}
}
// used to keep track of artificial stimulus cells
objref stimTypes
stimTypes = new List()
objref ncstimlist
// reads the cell types file and populates celltypes with the information
sprint (datafilePath, "%s/stim.dat", datasetPath)
sprint(cmd, "test -e %s", datafilePath) // check if the path exist
// status = system(cmd)
status = 0
if (status == 0) {
loadStimulationInfo (stimTypes, datafilePath, datasetPath)
if (verbose > 0) {
printf ("%s: loaded stimulation info\n", modelName)
}
}
// list with cell type information
objref cellTypes
cellTypes = new List()
// reads the cell types file and populates celltypes with the information
sprint (datafilePath, "%s/celltypes.dat", datasetPath)
loadCellCategoryInfo (cellTypes, datafilePath, datasetPath)
if (verbose > 0) {
printf ("%s: loaded cell info\n", modelName)
}
// used for synapse information
objref synapseTypes
synapseTypes = new List()
// reads the synapse types file and populates synapseTypes with the information
loadSynapseInfo (synapseTypes, datasetPath)
if (verbose > 0) {
printf ("%s: loaded synapse info\n", modelName)
}
// total number of cells in the network
ncells = 0
maxindex = 0
strdef templatename
objref celltype, indices
for i=0, cellTypes.count()-1 {
celltype = cellTypes.o(i)
if (celltype.hasProperty("indices")) {
indices = celltype.getPropertyObject("indices")
maxindex = indices.max()
if (ncells < maxindex) {
ncells = maxindex+1
}
} else {
ncells = ncells + celltype.getPropertyScalar("numCells") + 1
}
}
if (verbose > 0) {
printf ("%s: ncells = %d\n", modelName, ncells)
}
// list with connectivity information
objref connectivityTypes
connectivityTypes = new List()
// reads the connectivity types file and populates connectivitytypes with the information
sprint (datafilePath, "%s/connectivity.dat", datasetPath)
loadConnectivityInfo (connectivityTypes, datafilePath)
if (verbose > 0) {
printf ("connectivityTypes.count = %d\n", connectivityTypes.count())
}
// list with gap junction information
objref gjTypes
gjTypes = new List()
// reads the connectivity types file and populates connectivitytypes with the information
sprint (datafilePath, "%s/gapjunctions.dat", datasetPath)
loadGapJunctionInfo (gjTypes, datafilePath)
// pnm.cells is a list that holds all instances of network cells that
// exist on this host
// pnm.nclist holds all netcon instances that exist on this host
objref pnm
pnm = new ParallelNetManager(ncells)
ncells = 0
for i=0, cellTypes.count()-1 {
celltype = cellTypes.o(i)
if (celltype.hasProperty("indices")) {
indices = celltype.getPropertyObject("indices")
for j = 0, indices.size()-1 {
pnm.set_gid2node(indices.x[j], j % pnm.pc.nhost)
}
maxindex = indices.max()
if (ncells < maxindex) {
ncells = maxindex+1
}
} else {
for j = ncells, ncells+celltype.getPropertyScalar("numCells")-1 {
pnm.set_gid2node(j, j % pnm.pc.nhost)
}
ncells = ncells + celltype.getPropertyScalar("numCells") + 1
}
}
// connectivity list local to the current mpi process
objref conlist
if (makegraph > 0) {
conlist = new List()
}
// gap junction connectivity list local to the current mpi process
objref gjconlist
if (makegraph > 0) {
gjconlist = new List()
}
// gap junction list local to the current mpi process
objref gjlist
gjlist = new List()
/* mkcells and connectcells create the cells and connect the cells */
objref cell
// creates the cells and appends them to a list called cells
// argument is the number of cells to be created
proc mkcells() { local nCellTypes, numCells, i, j, p, gid, hasSynapseProps, templateType localobj f, cellTypes, cellType, datadirIndex, indices, synProps, synRiseTime, synDecayTime, synErev, synDend, synComp, rsdend, rscomp
strdef templateName, typeName, datadir, templatePath
cellTypes = $o1
nCellTypes = cellTypes.count()
for k=0, nCellTypes-1 {
cellType = cellTypes.o(k)
typeName = cellType.getPropertyString("typeName").s
templateName = cellType.getPropertyString("templateName").s
numCells = cellType.getPropertyScalar("numCells")
offset = cellType.getPropertyScalar("offset")
templateType = cellType.getPropertyScalar("templateType")
if (cellType.hasProperty("indices")) {
indices = cellType.getPropertyObject("indices")
} else {
indices = new Vector()
indices.resize(numCells)
for i = 0, numCells-1 {
indices.x[i] = i+offset
}
cellType.addPropertyObject("indices", indices)
}
hasSynapseProps = hasSynapseProperties(synapseTypes,typeName)
if (hasSynapseProps) {
synProps = getSynapseProperties(synapseTypes,typeName)
synRiseTime = synProps.getPropertyObject("rise time")
synDecayTime = synProps.getPropertyObject("decay time")
synErev = synProps.getPropertyObject("reversal potential")
synDend = synProps.getPropertyObject("dendrite")
synComp = synProps.getPropertyObject("compartment")
}
sprint(templatePath, "./templates/%s.hoc", templateName)
sprint(cmd, "load_file(\"%s\")", templatePath)
execute1(cmd)
for i=0, numCells-1 {
gid = indices.x(i)
if (pnm.gid_exists(gid)) {
if (verbose > 0) {
printf ("host %d: mkcells: i = %d gid = %d\n", pnm.myid, i, gid)
}
// used for choosing dendrite and compartment for synapses
rsdend = new RandomStream(gid, k, 1)
rscomp = new RandomStream(gid, k, 2)
sprint(cmd, "cell = new %s(%d, %d, %d, \"%s/%s/\")", templateName, i, gid, gid, datasetPath, typeName)
execute(cmd)
if (hasSynapseProps) {
mksyn(cell,synRiseTime,synDecayTime,synErev,synDend,synComp,rsdend,rscomp,typeName)
if (i == 0) { printCellSections (typeName,cell) }
}
pnm.register_cell(gid, cell)
pnm.spike_record(gid)
}
}
}
}
// connects the cells
// appends the NetCon objects to nclist
proc connectcells() {local i, k, status, srcid, destid, srcid1, destid1, del, dist, velocity, wdType, order, presynapticSize, postsynapticSize, stimsrc localobj presynapticType, postsynapticType, cellTypes, connectivityType, connectivityTypes, nc, edges, m, f, stim, synType, w, rs
strdef cmd, connectivityPath, connectivityName, presynapticPopulation, postsynapticPopulation
connectivityTypes = $o1
cellTypes = $o2
nConnectivityTypes = connectivityTypes.count()
if (verbose > 0) {
printf ("nConnectivityTypes = %d\n", nConnectivityTypes)
}
for k=0, nConnectivityTypes-1 {
connectivityType = connectivityTypes.o(k)
order = connectivityType.getPropertyScalar("order")
synType = connectivityType.getPropertyObject("synType")
wdType = connectivityType.getPropertyScalar("wdType")
connectivityName = connectivityType.getPropertyString("name").s
assert(synType.is_undefined == 0, "synType is undefined")
if (verbose >= 0) {
printf ("connectivityName = %s\n", connectivityName)
printf ("wdType = %d\n", wdType)
print "synType.is_number = ", synType.is_number
print "synType.is_list = ", synType.is_list
if (synType.is_number) {
printf ("synType.n = %d\n", synType.n)
}
printf ("pnm.nclist.count() = %d\n", pnm.nclist.count())
}
presynapticPopulation = connectivityType.getPropertyString("presynapticPopulation").s
presynapticType = cellTypes.o(findCellType(cellTypes,presynapticPopulation))
presynapticSize = presynapticType.getPropertyScalar("numCells")
presynapticOffset = presynapticType.getPropertyScalar("offset")
postsynapticPopulation = connectivityType.getPropertyString("postsynapticPopulation").s
postsynapticType = cellTypes.o(findCellType(cellTypes,postsynapticPopulation))
postsynapticSize = postsynapticType.getPropertyScalar("numCells")
postsynapticOffset = postsynapticType.getPropertyScalar("offset")
if (verbose >= 0) {
printf ("presynaptic population = %s\n", presynapticPopulation)
printf ("presynaptic size = %d\n", presynapticSize)
printf ("postsynaptic population = %s\n", postsynapticPopulation)
printf ("postsynaptic size = %d\n", postsynapticSize)
}
sprint(connectivityPath, "%s/%s.dat", datasetPath, connectivityName)
sprint(cmd, "test -e %s", connectivityPath) // check if the path exist
// status = system(cmd)
// on bg-q we can't run system commands on compute node
status = 0
if (status == 0) {
f = new File(connectivityPath)
pernode = 0
} else {
// Try connectivity file local to this MPI node
sprint(connectivityPath, "%s/%s.%d.dat", datasetPath, connectivityName, pnm.myid+1)
f = new File(connectivityPath)
pernode = 1
}
f.ropen()
m = new Matrix()
if (!f.eof()) {
m.scanf(f)
}
f.close()
if (m.nrow > 1) {
if (wdType == 1) {
for i=0, m.nrow-1 {
srcid = m.x[i][0]
destid = m.x[i][1]
if (order == 2) {
// relative numbering of pre-synaptic cells, absolute numbering of post synaptic cells
assert (srcid <= presynapticSize, "source cell id is greater than the size of the presynaptic population")
srcid1 = srcid + presynapticOffset
destid1 = destid
} else if (order == 1) {
// absolute numbering of pre/post synaptic cells
srcid1 = srcid
destid1 = destid
} else if (order == 0) {
// relative numbering of pre/post synaptic cells -- add the respective offsets
assert (srcid <= presynapticSize, "source cell id is greater than the size of the presynaptic population")
assert (destid <= postsynapticSize, "destination cell id is greater than the size of the postsynaptic population")
srcid1 = srcid + presynapticOffset
destid1 = destid + postsynapticOffset
} else {
execerror ("unknown connectivity order type")
}
if (!pnm.gid_exists(destid1)) {
if (!pernode) {
continue
} else {
printf("host %d: connectivityName = %s wdType = %d destid1 = %d\n", pnm.myid, connectivityName, wdType, destid1)
execerror ("destination id mismatch in per-node connectivity file")
}
}
w = m.x[i][2]
del = m.x[i][3]
nc_appendsyn(pnm, srcid1, destid1, synType, w, del)
if (verbose > 0) {
printf("host %d: connection src = %d dest = %d w = %g del = %g\n", pnm.myid, srcid1, destid1, w, del)
}
if (makegraph > 0) {
edges = new Vector(2)
edges.x[0] = srcid1
edges.x[1] = destid1
conlist.prepend(edges)
}
}
m.resize(1,1)
} else if (wdType == 2) {
w = connectivityType.getPropertyObject("standardWeight")
velocity = connectivityType.getPropertyScalar("standardVelocity")
for i=0, m.nrow-1 {
srcid = m.x[i][0]
destid = m.x[i][1]
if (order == 2) {
// relative numbering of pre-synaptic cells, absolute numbering of post synaptic cells
assert (srcid <= presynapticSize, "source cell id is greater than the size of the presynaptic population")
srcid1 = srcid + presynapticOffset
destid1 = destid
} else if (order == 1) {
// absolute numbering of pre/post synaptic cells
srcid1 = srcid
destid1 = destid
} else if (order == 0) {
// relative numbering of pre/post synaptic cells -- add the respective offsets
assert (srcid <= presynapticSize, "source cell id is greater than the size of the presynaptic population")
assert (destid <= postsynapticSize, "destination cell id is greater than the size of the postsynaptic population")
srcid1 = srcid + presynapticOffset
destid1 = destid + postsynapticOffset
} else {
execerror ("unknown connectivity order type")
}
if (!pnm.gid_exists(destid1)) {
if (!pernode) {
continue
} else {
printf("host %d: connectivityName = %s wdType = %d destid1 = %d\n", pnm.myid, connectivityName, wdType, destid1)
execerror ("destination id mismatch in per-node connectivity file")
}
}
dist = m.x[i][2] + m.x[i][3]
del = (dist / velocity) + 1.0
if (verbose > 0) {
printf("host %d: connection src = %d dest = %d del = %g\n", pnm.myid, srcid1, destid1, del)
}
nc_appendsyn(pnm, srcid1, destid1, synType, w, del)
if (makegraph > 0) {
edges = new Vector(2)
edges.x[0] = srcid1
edges.x[1] = destid1
conlist.prepend(edges)
}
}
m.resize(1,1)
} else if (wdType == 3) {
// connectivity of the form:
// src dest distance layer section node/point
w = connectivityType.getPropertyObject("weightHistogram")
velocity = connectivityType.getPropertyScalar("standardVelocity")
for i=0, m.nrow-1 {
srcid = m.x[i][0]
destid = m.x[i][1]
dist = m.x[i][2]
layer = m.x[i][3]
section = m.x[i][4]
node = m.x[i][5]
if (order == 2) {
// relative numbering of pre-synaptic cells, absolute numbering of post synaptic cells
assert (srcid <= presynapticSize, "source cell id is greater than the size of the presynaptic population")
srcid1 = srcid + presynapticOffset
destid1 = destid
} else if (order == 1) {
// absolute numbering of pre/post synaptic cells
srcid1 = srcid
destid1 = destid
} else if (order == 0) {
// relative numbering of pre/post synaptic cells -- add the respective offsets
assert (srcid <= presynapticSize, "source cell id is greater than the size of the presynaptic population")
assert (destid <= postsynapticSize, "destination cell id is greater than the size of the postsynaptic population")
srcid1 = srcid + presynapticOffset
destid1 = destid + postsynapticOffset
} else {
execerror ("unknown connectivity order type")
}
if (!pnm.gid_exists(destid1)) {
if (!pernode) {
continue
} else {
printf("host %d: connectivityName, wdType = %d destid1 = %d\n", pnm.myid, connectivityName, wdType, destid1)
execerror ("destination id mismatch in per-node connectivity file")
}
}
del = (dist / velocity) + 1.0
if (verbose > 0) {
printf("host %d: connection src = %d dest = %d del = %g\n", pnm.myid, srcid1, destid1, del)
}
nc_appendsyn_lsn(pnm, srcid1, destid1, synType, w, del, layer, section, node)
if (makegraph > 0) {
edges = new Vector(2)
edges.x[0] = srcid1
edges.x[1] = destid1
conlist.prepend(edges)
}
}
m.resize(1,1)
} else if (wdType == 4) {
w = connectivityType.getPropertyObject("standardWeight")
velocity = connectivityType.getPropertyScalar("standardVelocity")
for i=0, m.nrow-1 {
srcid = m.x[i][0]
destid = m.x[i][1]
if (order == 2) {
// relative numbering of pre-synaptic cells, absolute numbering of post synaptic cells
assert (srcid <= presynapticSize, "source cell id is greater than the size of the presynaptic population")
srcid1 = srcid + presynapticOffset
destid1 = destid
} else if (order == 1) {
// absolute numbering of pre/post synaptic cells
srcid1 = srcid
destid1 = destid
} else if (order == 0) {
// relative numbering of pre/post synaptic cells -- add the respective offsets
assert (srcid <= presynapticSize, "source cell id is greater than the size of the presynaptic population")
assert (destid <= postsynapticSize, "destination cell id is greater than the size of the postsynaptic population")
srcid1 = srcid + presynapticOffset
destid1 = destid + postsynapticOffset
} else {
execerror ("unknown connectivity order type")
}
if (!pnm.gid_exists(destid1)) {
if (!pernode) {
continue
} else {
printf("host %d: connectivityName = %s wdType = %d destid1 = %d\n", pnm.myid, connectivityName, wdType, destid1)
execerror ("destination id mismatch in per-node connectivity file")
}
}
dist = m.x[i][2]
del = (dist / velocity) + 1.0
if (verbose > 0) {
printf("host %d: connection src = %d dest = %d del = %g\n", pnm.myid, srcid1, destid1, del)
}
nc_appendsyn(pnm, srcid1, destid1, synType, w, del)
if (makegraph > 0) {
edges = new Vector(2)
edges.x[0] = srcid1
edges.x[1] = destid1
conlist.prepend(edges)
}
}
m.resize(1,1)
}
}
}
}
proc mkgap() { local gid, sgid, dgid, w localobj cell, gj, gjlist
gjlist = $o1
gid = $2
branch = $3
sec = $4
ggid = $5
w = $6
cell = pnm.pc.gid2cell(gid)
cell.dendrites[branch][sec] {
gj = new ggap(0.5)
pnm.pc.target_var(gj, &gj.vgap, ggid)
pnm.pc.source_var(&v(0.5), ggid)
}
gjlist.append(gj)
gj.g = w
if (verbose > 0) {
printf ("host %d: gap junction: gid = %d branch = %d sec = %d coupling = %g ggid = %d\n", pnm.myid, gid, branch, sec, w, ggid)
}
}
// creates the gap junctions between cells
proc connectgjs() {local i, k, w, ggid, srcid, destid, srcid1, destid1, srcbranch, destbranch, srcsec, destsec, order, srcSize, destSize localobj srcType, destType, cellTypes, gjType, gjTypes, edges, m, f
strdef gjPath, gjName, srcPopulation, destPopulation
gjTypes = $o1
cellTypes = $o2
nGJTypes = gjTypes.count()
ggid = 2*ncells
for k=0, nGJTypes-1 {
gjType = gjTypes.o(k)
order = gjType.getPropertyScalar("order")
gjName = gjType.getPropertyString("name").s
if (verbose > 0) {
printf ("gjName = %s\n", gjName)
}
srcPopulation = gjType.getPropertyString("srcPopulation").s
destPopulation = gjType.getPropertyString("destPopulation").s
if (verbose > 0) {
printf ("src population = %s\n", srcPopulation)
printf ("dest population = %s\n", destPopulation)
}
srcType = cellTypes.o(findCellType(cellTypes,srcPopulation))
destType = cellTypes.o(findCellType(cellTypes,destPopulation))
srcSize = srcType.getPropertyScalar("numCells")
destSize = destType.getPropertyScalar("numCells")
srcOffset = srcType.getPropertyScalar("offset")
destOffset = destType.getPropertyScalar("offset")
if (verbose > 0) {
printf ("src size = %d\n", srcSize)
printf ("dest size = %d\n", destSize)
}
sprint(gjPath, "%s/%s.dat", datasetPath, gjName)
print "gjPath = ", gjPath
m = new Matrix()
f = new File(gjPath)
f.ropen()
m.scanf(f)
f.close()
for i=0, m.nrow-1 {
srcid = m.x[i][0]
destid = m.x[i][1]
srcbranch = m.x[i][2]
srcsec = m.x[i][3]
destbranch = m.x[i][4]
destsec = m.x[i][5]
w = m.x[i][6]
if (order == 2) {
// relative numbering of pre-synaptic cells, absolute numbering of post synaptic cells
assert (srcid <= presynapticSize, "source cell id is greater than the size of the presynaptic population")
srcid1 = srcid + presynapticOffset
destid1 = destid
} else if (order == 1) {
// absolute numbering of pre/post synaptic cells
srcid1 = srcid
destid1 = destid
} else if (order == 0) {
// relative numbering of pre/post synaptic cells -- add the respective offsets
assert (srcid <= presynapticSize, "source cell id is greater than the size of the presynaptic population")
assert (destid <= postsynapticSize, "destination cell id is greater than the size of the postsynaptic population")
srcid1 = srcid + presynapticOffset
destid1 = destid + postsynapticOffset
} else {
execerror ("unknown connectivity order type")
}
if (pnm.gid_exists(srcid1)) {
mkgap(gjlist, srcid1, srcbranch, srcsec, ggid, w)
edges = new Vector(2)
edges.x[0] = srcid1
edges.x[1] = destid1
if (makegraph > 0) {
gjconlist.prepend(edges)
}
}
if (pnm.gid_exists(destid1)) {
mkgap(gjlist, destid1, destbranch, destsec, ggid+1, w)
}
ggid = ggid+2
}
}
}
proc mknet() { strdef fname
startsw()
mkcells(cellTypes) // create the cells
mkcellstime = stopsw()
if (pnm.myid == 0) {
printf ("*** Cells created in %g seconds\n", mkcellstime)
}
if (vrecordFraction > 0) {
indicesVrecord = new List()
mkvrecord(pnm,indicesVrecord,cellTypes,vrecordFraction)
}
startsw()
connectcells(connectivityTypes,cellTypes) // connect them together
connectcellstime = stopsw()
if (pnm.myid == 0) {
printf ("*** Synaptic connections created in %g seconds\n", connectcellstime)
}
startsw()
connectgjs(gjTypes,cellTypes) // creates the gap junctions
connectgjstime = stopsw()
if (pnm.myid == 0) {
printf ("*** Gap junctions created\n")
}
sprint(fname, "%s/%s_%d.dat", resultsPath, modelName, pnm.myid)
}
mknet(ncells)
// Configuration of artificial spiking cells
objref nc, stimcells
stimcells = new List()
ncstimlist = new List()
proc mkstim() { local i, k, nCellTypes, numStimTypes, gid, stimgid, weight, noise, number, start localobj stim, stimulationParameters, cellType, cellTypes, stimType, stimTypes, edges
strdef templateName, typeName
datasetPath = $s1
cellTypes = $o2
nCellTypes = cellTypes.count()
stimTypes = $o3
numStimTypes = stimTypes.count()
// Used to keep track of artificial stimulus cells
typeName = "stim"
sprint (cmd, "objref %slist, nc%slist", typeName, typeName)
execute(cmd)
sprint (cmd, "%slist = new List()", typeName)
execute(cmd)
sprint (cmd, "nc%slist = new List()", typeName)
execute(cmd)
stimgid = maxindex+1+pnm.myid*numStimTypes+1
if (verbose >= 0) {
printf ("host %d: mkstim: maxindex = %d numStimTypes = %d stimgid = %d\n", pnm.myid, maxindex, numStimTypes, stimgid)
}
for i=0, numStimTypes-1 {
stimType = stimTypes.o(i)
indices = stimType.getPropertyObject("indices")
weight = stimType.getPropertyScalar("weight")
noise = stimType.getPropertyScalar("noise")
number = stimType.getPropertyScalar("number")
start = stimType.getPropertyScalar("start")
rate = stimType.getPropertyScalar("rate")
if (verbose > 0) {
printf ("mkstim: i = %d stimgid = %d weight = %g noise = %g number = %g start = %g rate = %g\n", i, stimgid, weight, noise, number, start, rate)
}
stim = new StimCell(stimgid,0,0,rate,number,start,noise)
stimcells.append(stim)
//pnm.register_cell(stimgid, stim)
//pnm.spike_record(stimgid)
for j=0, indices.size()-1 {
gid = indices.x(j)
if (pnm.gid_exists(gid)) {
nc = stim.connect2target(pnm.pc.gid2obj(gid).syn_stim, nc)
nc.weight = weight
nc.delay = 0.1
ncstimlist.append(nc)
if (makegraph > 0) {
edges = new Vector(2)
edges.x[0] = stimgid
edges.x[1] = gid
conlist.prepend(edges)
}
}
}
stimgid = stimgid+1
}
}
if (stimTypes.count() > 0) {
mkstim(datasetPath, cellTypes, stimTypes)
}
if (pnm.myid == 0) {
printf ("*** Stimulus sources initialized\n")
}
if (makegraph > 0) {
graphout(fname,conlist)
conlist = nil
}
connectivityTypes = nil
cellTypes = nil
/* Simulation control */
{pnm.pc.setup_transfer()}
{pnm.pc.set_maxstep(10)}
print "dt = ", dt
objref fi_status
if (pnm.myid == 0) {
fi_status = new FInitializeHandler("simstatus()")
}
objref fi_vrecord
if (vrecordFraction > 0) {
fi_vrecord = new FInitializeHandler("vrecord(pnm)")
}
stdinit()
if (pnm.myid == 0) {
printf ("*** Initialization completed\n")
}
proc prun() { localobj po
if(dump_coreneuron_model) {
pnm.pc.nrnbbcore_write("coredat")
}
if (use_coreneuron || use_gpu) {
if (!nrnpython("from neuron import coreneuron")) {
printf("Python not available to run CoreNEURON\n")
return
}
po = new PythonObject()
po.coreneuron.enable = 1
if(use_gpu) {
po.coreneuron.gpu = 1
}
if(pnm.pc.id == 0) {
printf("nrncore_arg: |%s|\n", po.coreneuron.nrncore_arg(tstop))
}
} else {
tsav = startsw()
}
pnm.pc.psolve(tstop)
if (!use_coreneuron && pnm.pc.id == 0) {
printf("psolve time %g\n", startsw() - tsav)
}
if (pnm.myid == 0) {
printf ("*** Simulation completed\n")
}
}
prun()
/* Write simulation results */
strdef spikeout_fname
sprint(spikeout_fname, "%s/%s/%s_spikeout_%d.dat", outdir, resultsPath, modelName, pnm.myid)
spikeout(spikeout_fname,pnm.spikevec,pnm.idvec)
strdef vrecord_fname
if (vrecordFraction > 0) {
sprint(vrecord_fname, "%s/%s/%s_vrecord_%d.dat", outdir, resultsPath, modelName, pnm.myid)
vrecordout(vrecord_fname,indicesVrecord)
}
comptime = pnm.pc.step_time
avgcomp = pnm.pc.allreduce(comptime, 1)/pnm.pc.nhost
maxcomp = pnm.pc.allreduce(comptime, 2)
if (pnm.myid == 0) {
printf("Execution time summary for host 0:\n")
printf(" created cells in %g seconds\n", mkcellstime)
printf(" connected cells in %g seconds\n", connectcellstime)
printf(" created gap junctions in %g seconds\n", connectgjstime)
printf(" ran simulation in %g seconds\n", comptime)
if (maxcomp > 0) {
if (pnm.myid == 0) { printf(" load_balance = %g\n", avgcomp/maxcomp) }
}
}
if (pnm.myid == 0) {
printf ("*** Simulation results written\n")
}
pnm.pc.barrier()
if (pnm.myid == 0) {
printf ("*** Ending simulation\n")
}