-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-n400-Vbtim-simL-v8d-reduced-passive.hoc
executable file
·846 lines (755 loc) · 28.7 KB
/
main-n400-Vbtim-simL-v8d-reduced-passive.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
// Initialize
{
// load_file( "eTrace-p.hoc", "eTrace_loaded" )
chdir("/home/neuro/from_axon/")
load_file( "eTrace-p.hoc", "eTrace_loaded" )
load_file( "stdrun.hoc" )
load_file( "eMorph-p.hoc" )
load_file( "do_log.hoc" )
chdir("/Volumes/d1/Users/ximing/Projects/ParSims/pDE")
}
objref RunEnv
{
RunEnv = new str_obj()
RunEnv.nsystem( "echo $cNeuro", RunEnv.s1 ) // get value of cNeuro environment var into RunEnv.s1
RunEnv.nsystem( "arch", RunEnv.s2 ) // get arch of machine we're running on on RunEnv.s2
if( ! strcmp( RunEnv.s2, "ppc" ) ) { // NMOD_dll filename appropriate to our architecture on RunEnv.s3
sprint( RunEnv.s3, "%s/lib/nrn/NMOD/ca1n1-mod/powerpc/.libs/libnrnmech.so", RunEnv.s1 )
} else {
if( ! strcmp( RunEnv.s2, "i686" ) || ! strcmp( RunEnv.s2, "i386" ) ) {
sprint( RunEnv.s3, "/axon/d1/Users/ximing/cNeuro/lib/nrn/NMOD/ca1n1-mod/i686/.libs/libnrnmech.so", RunEnv.s1 )
} else {
if( ! strcmp( RunEnv.s2, "x86_64" ) ) {
//sprint( RunEnv.s3, "/axon/d1/Users/ximing/cNeuro/lib/nrn/NMOD/ca1n1-mod/x86_64/.libs/libnrnmech.so", RunEnv.s1 )
sprint( RunEnv.s3, "/home/neuro/from_axon/ca1n1-mod/x86_64/.libs/libnrnmech.so", RunEnv.s1)
print RunEnv.s3
} else {
printf( "\n\n\tUnknown architecture >>%s<<\n\n", RunEnv.s2 )
}
}
}
nrn_load_dll( RunEnv.s3 )
}
//================================================================================
func vdef(){
if( name_declared( $s1 ) == 5 ) return 1
return 0
}
//================================================================================
func Boltz(){
return 1/(1+exp(($1-$2)/$3))
}
func max(){ local i, im
im = $1
for i=1, numarg() if( $i>im ) im = $i
return im
}
func GaussLike(){ // x, A, W, D
return $2*exp(-($1-$4)^2/$3 )
}
// Perpendicular y distance
func ydistP(){
// if(ismembrane("morpho")){
// return abs(0.5*(y0_morpho+y1_morpho))
// }else { return abs( y3d(0)+y3d(n3d()-1) )/2}
return distance(0.5)
}
//================================================================================
objref eM
eM = new eMorph()
eM.idebug = 1
dfc_idebug = 0
proc mulfit_cell_init() {
soma { distance() } // set soma(0.5) as reference point
//adj_e_pas = G_e_pas - G_e_pas_slope * tgt_bldiff
//printf( "adj_e_pas %g G_e_pas %g G_e_pas_slope %g tgt_bldiff %g\n", adj_e_pas, G_e_pas, G_e_pas_slope, tgt_bldiff )
forall {
do_pas()
do_Naf() // does Naf and Nav16
do_h()
do_KDR()
do_KA()
}
// if( vdef( "RmCm_spine_gbar")) execute("eM.RmCm_spine_gbar = RmCm_spine_gbar") // defaults to 0 in template
Spnum = 30000
if( vdef( "Spine_number")) Spnum = Spine_number
eM.Spine_Comp_RmCm_f3d( "n400_af3d", Spnum ) // We perform Spine compensation after all else is set.
//eM.use_morpho_xyz=1
//eM.Spine_Comp_RmCm_n400_JAI(Spnum)
eM.idebug = 0 // show debug info only on first run
set_nseg( lambda_f_d )
//axon_hill {
// diam(0:1)=soma.diam(1):diam(0)
//}
}
//--------------------------------------------------------------------------------
proc set_nseg(){ local ns, lfd
nseg_tot = 0
lfd = $1
soma area( 0.5 )
forall {
if( lfd <= 0 ) ns = 1
if( lfd > 0 ) ns = int((L/($1 *lambda_f(100))+.9)/2)*2 + 1
if( ns > nseg ) nseg = ns
nseg_tot += nseg
}
printf( "lambda-d %g nseg_tot %d\n", lfd, nseg_tot )
}
//--------------------------------------------------------------------------------
proc do_pas(){
if( !ismembrane("epasn") ) insert epasn
//e_pas = adj_e_pas
g_epasn = 1 / ( G_Rm * 1000 )
Ra = G_Ra//*1000
cm = G_cm
ifsec "soma" {
if( vdef( "soma_l")) L=soma_l
if( vdef( "soma_diam")) diam=soma_diam
if( vdef( "soma_cm" )) cm = soma_cm
if( vdef( "soma_Rm" )) g_epasn = 1/ ( soma_Rm * 1000 )
if( vdef( "soma_Ra" )) Ra = soma_Ra//*1000
}
ifsec "axon" { // aX_ => generic for all axons but Hillock
if( vdef( "aX_cm" )) cm = aX_cm
if( vdef( "aX_Rm" )) g_epasn = 1/ ( aX_Rm * 1000 )
if( vdef( "aX_Ra" )) Ra = aX_Ra//*1000
}
ifsec "axon_mnode" { // aXm_ special for myelin can override generic
if( vdef("aXm_cm")) cm = aXm_cm
if( vdef("aXm_Rm")) g_epasn = 1/ ( aXm_Rm * 1000 )
if( vdef("aXm_Ra")) Ra = aXm_Ra//*1000
}
ifsec "axon_inode" { // aXr_ special for nodes of Ranvier can override generic
if( vdef("aXr_cm")) cm = aXr_cm
if( vdef("aXr_Rm")) g_epasn = 1/ ( aXr_Rm * 1000 )
if( vdef("aXr_Ra")) Ra = aXr_Ra//*1000
}
ifsec "axon_iseg[0]" {
//if(vdef("aX_iseg_l")) L=aX_iseg_l*0.5
L=30
diam=1
}
ifsec "axon_iseg[1]" {
//if(vdef("aX_iseg_l")) L=aX_iseg_l*0.5
L=40
diam=1
}
ifsec "axon_hill" {
if(vdef("axon_hill_l")){
L=axon_hill_l
}else{L=5}
diam(0:1)=2.8:1
}
}
//--------------------------------------------------------------------------------
proc do_Naf(){
if( vdef( "Gbar_Naf" )){
if( !ismembrane("Naf_i0")) insert Naf_i0
nai0_na_ion = 10
nao0_na_ion = 145
nai=nai0_na_ion
nao=nao0_na_ion
ena=nernst(nai0_na_ion, nao0_na_ion,1)
gbar_Naf_i0 = Gbar_Naf // default value unless overriden below
ifsec "soma" if(vdef("s0_Gbar_Naf")) gbar_Naf_i0 = s0_Gbar_Naf
ifsec "axon_hill" if(vdef("aXh_Gbar_Naf")) gbar_Naf_i0 = aXh_Gbar_Naf
ifsec "axon_mnode" if(vdef("aXm_Gbar_Naf")) gbar_Naf_i0 = aXm_Gbar_Naf
if( issection("axon_mnode.*") || issection("axon_hill.*" ) ) return
ifsec "axon_iseg" {
//if(!ismembrane("Naf_i1")) {
insert Naf_i1
uninsert Naf_i0
//}
ifsec "axon_iseg[0]" if( vdef("aXi0_Gbar_Naf")) gbar_Naf_i1 = aXi0_Gbar_Naf
ifsec "axon_iseg[1]" if( vdef("aXi1_Gbar_Naf")) gbar_Naf_i1 = aXi1_Gbar_Naf
}
ifsec "axon_inode" if( vdef("aXr_Gbar_Naf")) gbar_Naf_i0 =aXr_Gbar_Naf
}
}
//--------------------------------------------------------------------------------
proc do_KDR(){ local i
if( vdef( "Gbar_KDR" )){
if( !ismembrane("KDR_i1") ) insert KDR_i1
ki0_k_ion=140
ko0_k_ion=2.5
ki=ki0_k_ion
ko=ko0_k_ion
ek=nernst(ki0_k_ion, ko0_k_ion, 1)
gbar_KDR_i1 = Gbar_KDR
if(vdef("Gbar_KDR_dslope") && !issection("axon.*")) gbar_KDR_i1 = Gbar_KDR *(1+Gbar_KDR_dslope*ydistP())
ifsec "soma" if(vdef("s0_Gbar_KDR")) gbar_KDR_i1 = s0_Gbar_KDR
ifsec "axon_hill" if(vdef("s0_Gbar_KDR")) gbar_KDR_i1 = s0_Gbar_KDR
ifsec "axon_hill" if(vdef("aXh_Gbar_KDR")) gbar_KDR_i1 = aXh_Gbar_KDR
ifsec "axon" if( vdef("aX_Gbar_KDR")) gbar_KDR_i1 = aX_Gbar_KDR
ifsec "axon_iseg" {
if( vdef( "aXi_Gbar_KDR" )) gbar_KDR_i1 = aXi_Gbar_KDR
ifsec "axon_iseg[0]" if( vdef( "aXi0_Gbar_KDR" )) gbar_KDR_i1 = aXi0_Gbar_KDR
ifsec "axon_iseg[1]" if( vdef( "aXi1_Gbar_KDR" )) gbar_KDR_i1 = aXi1_Gbar_KDR
}
ifsec "axon_node" if( vdef( "aXr_Gbar_KDR" )) gbar_KDR_i1 = aXr_Gbar_KDR
ifsec "axon_myelin" if( vdef( "aXm_Gbar_KDR" )) gbar_KDR_i1 = aXm_Gbar_KDR
}
}
//--------------------------------------------------------------------------------
proc do_KA(){ local i
if( vdef( "Gbar_KA" )){
if( !ismembrane("KA_i1") ) insert KA_i1
ki0_k_ion = 140
ko0_k_ion = 2.5
ki=ki0_k_ion
ko=ko0_k_ion
ek = nernst(ki0_k_ion, ko0_k_ion, 1)
gbar_KA_i1 = Gbar_KA
if(vdef("Gbar_KA_dslope") && !issection("axon.*")) gbar_KA_i1 = Gbar_KA *(1+Gbar_KA_dslope*ydistP() )
ifsec "axon_hill" if(vdef("aXh_Gbar_KA")) gbar_KA_i1 = aXh_Gbar_KA
ifsec "axon_myelin" if(vdef("aXm_Gbar_KA")) gbar_KA_i1 = aXm_Gbar_KA
if( issection("axon_myelin.*") || issection("axon_hill.*" ) ) return
ifsec "axon" if( vdef("aX_Gbar_KA")) gbar_KA_i1 = aX_Gbar_KA
ifsec "axon_iseg" {
if( vdef( "aXi_Gbar_KA" )) gbar_KA_i1 = aXi_Gbar_KA
ifsec "axon_iseg[0]" if( vdef( "aXi0_Gbar_KA" )) gbar_KA_i1 = aXi0_Gbar_KA
ifsec "axon_iseg[1]" if( vdef( "aXi1_Gbar_KA" )) gbar_KA_i1 = aXi1_Gbar_KA
}
ifsec "axon_inode" if( vdef( "aXr_Gbar_KA" )) gbar_KA_i1 = aXr_Gbar_KA
ifsec "axon_mnode" if( vdef( "aXm_Gbar_KA" )) gbar_KA_i1 = aXm_Gbar_KA
}
}
//--------------------------------------------------------------------------------
proc do_h(){ local i
if( vdef( "Gbar_h" )){
if( !ismembrane("h_i0") ) insert h_i0
eh_i0 = G_eh
gbar_h_i0 = Gbar_h
if(vdef("Gbar_h_dslope") && !issection("axon.*")) gbar_h_i0 = Gbar_h *(1+Gbar_h_dslope*ydistP() )
//ifsec "axon_hill" if(vdef("aXh_Gbar_h")) gbar_h_i0 = aXh_Gbar_h
//ifsec "axon_myelin" if(vdef("aXm_Gbar_h")) gbar_h_i0 = aXm_Gbar_h
//if( issection("axon_myelin.*") || issection("axon_hill.*" ) ) return
//ifsec "axon" if( vdef("aX_Gbar_h")) gbar_h_i0 = aX_Gbar_h
//ifsec "axon_iseg" {
// if( vdef( "aXi_Gbar_h" )) gbar_h_i0 = aXi_Gbar_h
// ifsec "axon_iseg[0]" if( vdef( "aXi0_Gbar_h" )) gbar_h_i0 = aXi0_Gbar_h
// ifsec "axon_iseg[1]" if( vdef( "aXi0_Gbar_h" )) gbar_h_i0 = aXi1_Gbar_h
//}
//ifsec "axon_node" if( vdef( "aXr_Gbar_h" )) gbar_h_i0 = aXr_Gbar_h
//ifsec "axon_myelin" if( vdef( "aXm_Gbar_h" )) gbar_h_i0 = aXm_Gbar_h
}
}
//----------------------------------------------------------------------
objref iss
init_first = 1
iss_unstable = 0 // set 0 to find out; once set avoid running again
proc init() { local v0, v1
if( init_first ){
init_first = 0
// calculate G_e_pas_slope to adjust e_pas for each trace's baseline
//G_e_pas_slope = 0
//G_e_pas += 1
mulfit_cell_init()
iss.init_steady_state // init_steady_state()
if( check_iss_unstable()) return
v1 = v
//G_e_pas -= 1
mulfit_cell_init()
iss.init_steady_state // init_steady_state()
if( check_iss_unstable()) return
v0 = v
//G_e_pas_slope = 1/(v1-v0)
//printf( "init: G_e_pas_slope %g\n", G_e_pas_slope )
}
mulfit_cell_init()
init_last_call() // hook to insert changes just before run() call
iss.init_steady_state() // init_steady_state()
if( check_iss_unstable()) return
}
// Hook to insert changes just before run() call (can be redefined later)
proc init_last_call(){
}
//----------------------------------------------------------------------
func check_iss_unstable(){
if( iss.dV > iss_unstable_th ){
iss_unstable = 1
printf( ">>>init: UNSTABLE Steady State iss.dV=%g iss_unstable_th=%g; setting tstop=20<<<\n", \
iss.dV, iss_unstable_th )
tstop = 20
return 1
}
return 0
}
//----------------------------------------------------------------------
objref stim
proc do_cell(){
forall delete_section()
chdir("/home/neuro/from_axon/n400td")
load_file( 1, $s1 ) // load cell
if( numarg()>1 ) load_file( 1, $s2 ) // load axon
soma {
stim = new IClamp(0.5)
}
chdir("/Volumes/d1/Users/ximing/Projects/ParSims/pDE")
}
//================================================================================
// pDE interface related code
begintemplate pDE_fit_case
strdef id, Mtemplate, Mfunc, scaleF, hoc_var, hoc_before, hoc_after, tgt_file, tgt_before, tgt_after
public id, Mtemplate, Mfunc, scaleF, hoc_var, hoc_before, hoc_after, tgt_file, tgt_before, tgt_after
public scaleF, tgt_bldiff
proc init(){
id = $s1
Mtemplate = $s2
Mfunc = $s3
scaleF = $s4
hoc_var = $s5
hoc_before = $s6
hoc_after = $s7
tgt_file = $s8
tgt_before = $s9
tgt_after = $s10
tgt_bldiff = 0 // baseline differential from avg of tgt set
}
endtemplate pDE_fit_case
proc dfc_do_cmd(){ localobj so, sf
sf = new StringFunctions()
so = new str_obj()
sprint( so.s1, "%s;", $s1 )
while( strcmp( so.s1, "")){
sf.head( so.s1, ";", so.s2 )
if( strcmp( so.s2, "" )) {
if( dfc_idebug ) printf( "\ndfc_do_cmd: %s\n", so.s2 )
if( numarg() == 1 ) execute( so.s2 )
if( numarg() == 2 ) execute( so.s2, $o2 )
if( numarg() == 3 ) $o3.append( new str_obj( so.s2 ))
}
sf.tail( so.s1, ";", so.s1 )
}
}
//----------------------------------------------------------------------------------------------------
objref pDE_fc_list
objref dfc_tgt, dfc_tgtL
{ blmin=1 blMax=19 } // baseline limits (ms)
func dfc_load_dfc_tgt(){ local i localobj fc_i, sf, str, pDE_fc_i
pDE_fc_i=$o1
sf=new StringFunctions() str=new str_obj()
dfc_tgt = new eTrace()
dfc_tgt.idebug = dfc_idebug
dfc_do_cmd( pDE_fc_i.tgt_before )
if( sf.head( pDE_fc_i.tgt_file, ".txt$", str.s1 ) >= 0 ) dfc_tgt.load_file_home( pDE_fc_i.tgt_file )
if( sf.head( pDE_fc_i.tgt_file, ".htf$", str.s1 ) >= 0 ) dfc_tgt.load_htf_1p0c( pDE_fc_i.tgt_file, "HOME" )
dfc_do_cmd( pDE_fc_i.tgt_after )
return dfc_tgt.vec_v.mean( round(blmin/dfc_tgt.dt_sample), round(blMax/dfc_tgt.dt_sample)) // return mean from blmin to blMax
}
func round(){ return int( 0.5 + $1 ) }
proc dfc_load_traces(){ local i, j, tmp, bl_avg, bl_i localobj pDE_fc_i, blV
dfc_tgtL = new List()
blV = new Vector()
bl_avg = 0
for i=0, pDE_fc_list.count-1 {
bl_i = dfc_load_dfc_tgt( pDE_fc_list.o(i) )
dfc_tgtL.append( dfc_tgt )
blV.append( bl_i )
bl_avg += (bl_i - bl_avg)/(i+1) // clever way to compute running avg
}
printf( "dfc_load_traces: found bl_avg %g.\n", bl_avg )
if( vdef( "BL_avg" )) {
printf( "dfc_load_traces: Using preset BL_avg %g\n", BL_avg )
bl_avg = BL_avg // Use BL_avg if defined in pDE script
}
for i=0, pDE_fc_list.count-1 {
pDE_fc_list.o(i).tgt_bldiff = bl_avg - blV.x[i]
printf( "dfc_load_traces i %d bli %g bl_avg %g tgt_bldiff %g\n", i, blV.x[i], bl_avg, pDE_fc_list.o(i).tgt_bldiff )
}
}
//----------------------------------------------------------------------------------------------------
strdef cell_file_name, axon_file_name // so they can be defined in pDE VERBATIM
proc pDE_init_cell(){
// Not needed here. Out so that dfc_run_agai works pDE_asg() // so that do_cell can use name_declared() calls
// do_cell( "n420t-pc2-L10000-ignoreD-newsoma.hoc", "naceaxon-m-0-long.hoc" )
// do_cell( "n420t-pc2-L10000-ignoreD-newsoma.hoc", "Meeks-axon-0.hoc" )
// do_cell( "n420t-pc2-L10000-ignoreD-newsoma.hoc", "ca1b-rot-axon-750-aE-v2.hoc" )
// do_cell( "n420t-pc2-L10000-ignoreD-newsoma.hoc", "my-ca1-isegs-myelin.hoc" )
// do_cell( "n420t-pc2-L10000-DL.hoc", "my-ca1-isegs-myelin.hoc" )
if( strcmp(cell_file_name,"")==0 ) cell_file_name = "n420t-pc2-L10000-ignoreD-newsoma.hoc"
//if( strcmp(axon_file_name,"")==0 ) axon_file_name = "my-ca1-isegs-myelin.hoc"
do_cell( cell_file_name)
if( vdef( "soma_diam_f")) forsec "soma" { diam *= soma_diam_f printf( "soma diam %s %g\n", secname(), diam ) }
{ cvode.active(1) cvode.atol(1.e-10) }
iss = new initss( cvode, -80 ) // iss_v_init = -80
iss.idebug = 0.5
iss_unstable_th = 0.1
iss_unstable_penalty = 1e20
execute( "access soma" ) // avoid sintax error if soma is not created at compile time
}
//----------------------------------------------------------------------------------------------------
obfunc set_sim_stim(){ local i localobj eT, sT
{ eT = $o1 sT=$o2 }
{ eT.stim_amp=sT.amp eT.stim_del=sT.del eT.stim_dur=sT.dur }
return eT
}
//----------------------------------------------------------------------------------------------------
objref dfc_i, dfc_tgt_i, dfc_sim, dfc_sim_rec, dfc_simL, dfc_eD
objref dfc_recL, dfc_simL_i, dfc_sim_recL
dfc_first = 1
func pDE_do_fit_case(){ local i, icase, irec localobj str, sL
icase = $1
if( dfc_first ) {
dfc_first = 0
dfc_simL = new List()
pDE_asg() // so that init_cell and load_traces can use vdef() calls
dfc_load_traces()
pDE_init_cell()
}
dfc_i = pDE_fc_list.o( icase )
dfc_tgt_i = dfc_tgtL.o( icase )
str = new str_obj()
execute( str.sPrint( "dfc_eD = new %s()", dfc_i.Mtemplate ).s1 )
dfc_eD.idebug = dfc_idebug
tstop = dfc_tgt_i.vec_t.x[ dfc_tgt_i.vec_t.size-1 ] + dfc_tgt_i.dt_sample
dfc_recL = new List()
sL = str.split( dfc_i.hoc_var, ";" ) // split to get list of recording section locations
for i=0, sL.count-1 execute( str.sPrint( "%s dfc_recL.append( new SectionRef())", sL.o(i).s1 ).s1 )
dfc_do_cmd( dfc_i.hoc_before ) // hoc_before here; so stim parms can be set in hoc_before code
dfc_sim_recL = new List()
for irec=0, dfc_recL.count-1 {
dfc_sim_recL.append( new eTrace() )
set_sim_stim( dfc_sim_recL.o(irec), stim )
// dfc_sim_recL.o(irec).stim_amp = stim.amp
// dfc_sim_recL.o(irec).stim_dur = stim.dur
// dfc_sim_recL.o(irec).stim_del = stim.del
dfc_sim_recL.o(irec).idebug = dfc_idebug
dfc_sim_recL.o(irec).dt_sample = -1 // -1 => non-uniform for cvode
dfc_sim_recL.o(irec).name = sL.o(irec).s1 // place recording section in name
dfc_recL.o(irec).sec cvode.record( &v(0.5), dfc_sim_recL.o(irec).vec_v, dfc_sim_recL.o(irec).vec_t )
}
access dfc_recL.o(0).sec
if( ! iss_unstable ){ // run only if previous case was stable (ie not unstable); see init()
printf( "\n\t" )
system( "date" )
printf( "case %s\n", dfc_i.id )
tgt_bldiff = dfc_i.tgt_bldiff
pDE_asg()
run()
dfc_simL_i = new List()
for irec=0, dfc_recL.count-1 dfc_simL_i.append( dfc_sim_recL.o(irec).copy() )
dfc_simL.append( dfc_simL_i )
}
if( iss_unstable ){
dfc_err = iss.dV / iss_unstable_th * iss_unstable_penalty
}else{
dfc_do_cmd( dfc_i.hoc_after ) // hoc_after
dfc_err = 0
// dfc_err = dfc_eD.listM( dfc_i.Mfunc, dfc_sim, dfc_tgtLi )
dfc_eD.ilog = 1
printf( "id %s ", dfc_i.id )
// sprint( str.s1, "dfc_err = dfc_eD.%s( dfc_sim, dfc_tgt_i )", dfc_i.Mfunc )
// sprint( str.s1, "dfc_err = dfc_eD.%s( dfc_simL_i.o(0), dfc_tgt_i )", dfc_i.Mfunc )
// execute( str.s1 )
execute( str.sPrint( "dfc_err=%s", dfc_i.Mfunc).s1 )
}
execute( str.sPrint( "dfc_scaleF = %s", dfc_i.scaleF ).s1 )
printf( " dfc_scaleF %g pDE_do_fit_case %g\n", dfc_scaleF, dfc_err*dfc_scaleF )
return dfc_err * dfc_scaleF
}
//----------------------------------------------------------------------------------------------------
begintemplate recSpec
objref sr, eT
strdef name
public name, sr, vr, eT, dist, tzc
proc init(){
sr = new SectionRef()
name = secname()
vr = $1
dist = distance( vr )
eT = new eTrace()
}
public set_eT
obfunc set_eT(){
eT = $o1.copy()
eT.resample_dt(0.01)
eT.vec_dv.deriv( eT.vec_v, eT.dt_sample, 2 )
eT.vec_ddv = new Vector()
eT.vec_ddv.deriv( eT.vec_dv, eT.dt_sample, 2 )
tzc = eT.vec_t.x( eT.vec_v.indwhere(">=",0) )
return eT
}
public sort_dist
obfunc sort_dist(){ local i localobj iO, iOs, rL, rLs
rL = $o1
iO = new Vector()
for i=0, rL.count-1 iO.append( rL.o(i).dist )
iOs = iO.sortindex()
rLs = new List()
for i=0, rL.count-1 rLs.append( rL.o(iOs.x[i]) )
return rLs
}
endtemplate recSpec
//----------------------------------------------------------------------------------------------------
// Run again case icase and return eTrace results
obfunc dfc_run_againL(){ local i, icase localobj eT, eT1, dfc_i, dfc_tgt_i, rL, eTL
icase = $1
dfc_i = pDE_fc_list.o( icase )
dfc_tgt_i = dfc_tgtL.o( icase )
pDE_init_cell()
dfc_do_cmd( dfc_i.hoc_before )
tstop = dfc_tgt_i.vec_t.x[ dfc_tgt_i.vec_t.size-1 ] + dfc_tgt_i.dt_sample
tgt_bldiff = dfc_i.tgt_bldiff
rL = new List()
access soma
distance()
rL.append( new recSpec( x ))
forsec "axon" for (x) if(x>0&&x<1) rL.append( new recSpec( x ))
eTL = new List()
for i=0, rL.count-1 {
eTL.append( new eTrace() )
set_sim_stim( eTL.o(i), stim )
rL.o(i).sr.sec cvode.record( &v( rL.o(i).vr ), eTL.o(i).vec_v, eTL.o(i).vec_t )
}
run()
for i=0, rL.count-1 rL.o(i).set_eT( eTL.o(i) )
return rL
}
// Return (and plot if pG present) rL for each parm value variation runs vp+ivp*k1 to vp+ivp*k2 in ivp steps
// ( icase, "var", vp, ivp, k1, k2 [, pG [,opt]] )
obfunc dfc_var_runsL(){ local i, imin, tmin, icase, vp, ivp, nv, k, k1, k2, opt localobj eT, eT1, eTL, str, pG, rL, rLL
icase = $1
str = new str_obj( $s2 )
{ vp=$3 ivp=$4 k1=$5 k2=$6 }
rLL = new List()
for k=k1, k2 {
nv = vp + ivp * k
sprint( str.s2, "%s=%g", str.s1, nv )
execute( str.s2 )
rL = dfc_run_againL(icase)
rL.o(0).eT.name = str.s2
rLL.append( rL )
}
if( numarg()>6 ){
eT = plot_rLL_dt( rLL )
$o7 = eT.plotG
{ eT.plotG.view(0,0,10,10, 100+20+300*1.8, 100, 300*2.5, 200*3 ) eT.plotG.exec_menu( "View = plot" ) }
{ opt = 101 if( numarg()>8 ) opt = $9 }
pG = new Graph(0)
for k=0, rLL.count-1 pG = rLL.o(k).o(0).eT.iso_spike(dfc_seg_look_options(),1,-0.5,0).plot_ddv( pG, opt, k+1 )
{ pG.view(0,0,10,10, 100, 100, 300*1.8, 200*3 ) pG.exec_menu( "View = plot" ) }
$o8 = pG
}
return rLL
}
obfunc plot_rLL_dt(){ local k, i, imin, tmin localobj eT, eT1, rLL, rL
rLL = $o1
eT = new eTrace()
eT.plotG = new Graph(0)
for k=0, rLL.count-1 {
rL = rLL.o(k)
tmin = 1e70
for i=0, rL.count-1 {
eT.plotG.mark( rL.o(i).dist, rL.o(i).tzc, "s", 5, axon_color( rL.o(i).name), 1 )
if( rL.o(i).tzc<tmin ){ imin=i tmin=rL.o(i).tzc }
}
for i=0, rL.count-1 if( rL.o(i).tzc==tmin ) eT.plotG.mark( rL.o(i).dist, rL.o(i).tzc, "S", 6, axon_color( rL.o(i).name), 1 )
// if(k==0){ eT.plotG=new Graph() eT.plotG.align( 1, 1 ) eT.plotG.label( 1-1/22, 1-1/22 ) }
eT1 = rL_td_eT( rL )
sprint( eT1.name, "%s t=%4.2f vel=%4.2f", rL.o(0).eT.name, tmin, axon_speed(rL) )
eT.addplot_c( eT1, k%7+1 )
}
return eT
}
obfunc run_plot_all_axon_ddv(){ local i, icase, tspk, tL, tR localobj pG, rL, sf, eT
icase = $1
tL=-0.5 if( numarg()>1 )tL=$2
tR=0 if( numarg()>2 )tR=$3
sf = new StringFunctions()
rL = dfc_run_againL( icase ) // rL.o(0) is soma
pG = new Graph()
rL.o(0).eT.copy().iso_spike(dfc_seg_look_options(),1,-0.5,0, &tspk )
printf( "tspk %g\n", tspk )
for i=0, rL.count-1 {
if( sf.substr(rL.o(i).name, "node")>=0 || sf.substr(rL.o(i).name, "myelin")>=0 ) continue
pG.color( axon_color(rL.o(i).name ))
eT = rL.o(i).eT.copy().cut_at2( tspk+tR, tspk+tL )
eT.vec_t.add( tL )
// pG = rL.o(i).eT.copy().cut_at2(tspk+0.1,tspk-0.5).plot_ddv( pG, 001, axon_color(rL.o(i).name) )
eT.vec_ddv.line( pG , eT.vec_t )
}
pG.exec_menu( "View = plot" )
return pG
}
// calculate speed between nodes with min and max tzc
func axon_speed(){ local i, im, iM, vel localobj rL, sf
rL = $o1
sf = new StringFunctions()
im=iM=-1
for i=0, rL.count-1 if( sf.substr( rL.o(i).name, "node")>=0 ){
if( im<0 ) im=iM=i // set to first "node" match
if( rL.o(i).tzc < rL.o(im).tzc ) im=i
if( rL.o(i).tzc > rL.o(iM).tzc ) iM=i
}
vel = ( rL.o(iM).dist - rL.o(im).dist ) / ( rL.o(iM).tzc - rL.o(im).tzc ) * 1e-3 // um/ms * 1e-3 = m/s
printf( "axon_speed: i,tzc min %g %g Max %g %g vel %g\n", im, rL.o(im).tzc, iM, rL.o(iM).tzc, vel )
return vel
}
func axon_color(){ local i, col localobj str, sf
str = new str_obj( $s1 )
sf = new StringFunctions()
col = 1
if( sf.head( str.s1, "hill", str.s2 )> 0 ) col = 2
if( sf.head( str.s1, "iseg", str.s2 )> 0 ) col = 3
if( sf.head( str.s1, "prox", str.s2 )> 0 ) col = 4
if( sf.head( str.s1, "myelin", str.s2 )> 0 ) col = 5
if( sf.head( str.s1, "node", str.s2 )> 0 ) col = 6
return col
}
//----------------------------------------------------------------------------------------------------
// Run again case icase and return eTrace results
obfunc dfc_run_again(){ local icase localobj eT, eT1, dfc_i, dfc_tgt_i
icase = $1
dfc_i = pDE_fc_list.o( icase )
dfc_tgt_i = dfc_tgtL.o( icase )
pDE_init_cell()
dfc_do_cmd( dfc_i.hoc_before )
tstop = dfc_tgt_i.vec_t.x[ dfc_tgt_i.vec_t.size-1 ] + dfc_tgt_i.dt_sample
tgt_bldiff = dfc_i.tgt_bldiff
eT = new eTrace()
set_sim_stim( eT, stim )
soma cvode.record( &v(0.5), eT.vec_v, eT.vec_t )
run()
eT1 = eT.copy()
eT1.resample_dt(0.01)
eT1.vec_dv.deriv( eT1.vec_v, eT1.dt_sample, 2 )
eT1.vec_ddv = new Vector()
eT1.vec_ddv.deriv( eT1.vec_dv, eT1.dt_sample, 2 )
return eT1
}
//----------------------------------------------------------------------------------------------------
// Return (and plot if pG present) list of parm value variation runs vp+ivp*k1 to vp+ivp*k2 in ivp steps
obfunc dfc_var_runs(){ local icase, vp, ivp, nv, k, k1, k2, opt localobj eT, eTL, str, pG
icase = $1
str = new str_obj( $s2 )
{ vp=$3 ivp=$4 k1=$5 k2=$6 }
eTL = new List()
for k=k1, k2 {
nv = vp + ivp * k
sprint( str.s2, "%s = %g", str.s1, nv )
execute( str.s2 )
eT = dfc_run_again(icase)
eT.name = str.s2
eTL.append( eT )
}
if( numarg()>6 ){
{ opt = 101 if( numarg()>7 ) opt = $8 }
for k=0, eTL.count-1 pG=(eTL.o(k).iso_spike(dfc_seg_look_options(),1,1).plot_ddv( pG, opt, k+1 ))
// Note parens. below does not work
//for k=0, eTL.count-1 pG=eT.plot_ddv( pG, eTL.o(k).iso_spike(dfc_eD_options(),1,1), opt, k+1 )
$o7 = pG
}
return eTL
}
//----------------------------------------------------------------------------------------------------
proc dfc_plot_1(){ local i, n
$o1.plot_color = $3
$o1.plot_brush = $4
$o1.addplot( $o2 )
}
proc dfc_plot_place(){ local n
n = $2
$o1.plotG.unmap()
$o1.plotG.view(0,0,10,10, (n%5)*(300+20), 100+int(n/5)*(200+65), 300, 200 )
$o1.recenter()
}
func is_obj_name(){ local i localobj sf, str
str = new str_obj($s2) sf = new StringFunctions()
sprint( str.s2, "%s", $o1 )
if( sf.tail( str.s2, str.s1, str.s3 ) == sf.len(str.s1) ) return 1
return 0
}
objref igL
strdef pDE_log_name
obfunc plot_gen(){
igL = new pDE_log()
igL.read_n_plot( pDE_log_name, pDE_gen_N )
return igL
}
objref pG_axon, pG_sec
obfunc plot_axon(){ local i, in localobj str
pG_axon = new Graph()
pG_sec = new List()
str = new str_obj()
pG_sec.append( new str_obj( "axon_hill" ))
in = 19
if( vdef( "aX_iseg_n" )) in = aX_iseg_n
for i=0,in-1 pG_sec.append( str.copy().sPrint( "axon_iseg[%d]", i ) )
pG_sec.append( new str_obj( "axon_prox" ))
if( aX_node_n > 0 ){
pG_sec.append( new str_obj( "axon_node[0]" ))
pG_sec.append( new str_obj( "axon_myelin[0]" ))
}
pG_sec.append( new str_obj( "soma" )) // put last so that soma is accessed at the end below
for i=0, pG_sec.count-1 {
execute( pG_sec.o(0).sPrint( "access %s", pG_sec.o(i).s1 ).s1 )
pG_axon.mark( distance(0.5), gbar_Naf_i1, "+", 12, 2, 1 )
pG_axon.mark( distance(0.5), gbar_KDR_i1, "o", 12, 3, 1 )
}
pG_axon.exec_menu( "View = plot" )
return pG_axon
}
objref dfc_ddVpG
obfunc dfc_pG_ddV(){ local i, iopt localobj pG
pG = $o1
iopt = $2
if( iopt==0 ) for i=0,dfc_tgtL.count-1 { dfc_pG_one_ddV(pG,i,001,0,1) dfc_pG_one_ddV(pG,i,001,1,2) }
if( iopt==1 ) for i=0,dfc_tgtL.count-1 { dfc_pG_one_ddV(pG,i,001,0,i+1,1) dfc_pG_one_ddV(pG,i,001,1,i+1,2) }
if( iopt==2 ) for i=0,dfc_tgtL.count-1 { dfc_pG_one_ddV(pG,i,010,0,1) dfc_pG_one_ddV(pG,i,010,1,2) }
if( iopt==3 ) for i=0,dfc_tgtL.count-1 { dfc_pG_one_ddV(pG,i,010,0,i+1,1) dfc_pG_one_ddV(pG,i,010,1,i+1,2) }
return pG
}
obfunc dfc_pG_one_ddV(){ local icase, iopt, isel, icol, ibrush localobj eT, pG, eTc
if(numarg()>0 ) pG=$o1
if( object_id( pG )==0 ) { pG = new Graph() }
icase=$2 iopt=$3 isel=$4 icol=$5
dfc_i = pDE_fc_list.o( icase )
ibrush=1 if( numarg()>5 ) ibrush=$6
pG.brush( ibrush )
if( isel==0 ) eTc = dfc_tgtL.o(icase)
if( isel==1 ) eTc = dfc_simL.o(icase).o(0)
if( eTc.stim_amp<0.2 || eTc.stim_amp==0.75 ) return pG
eT = eTc.iso_spike( dfc_seg_look_options(), 1, -0.65, 0.45 )
if( object_id(eT)>0) eT.plot_ddv( pG, iopt, icol )
return pG
}
// per fit-case: dfc_simL has one list entry (with eTraces); dfc_tgtL has one eTrace
proc dfc_plot_all(){ local i, j localobj eTi
for i=0, dfc_simL.count-1 {
eTi = dfc_tgtL.o(i)
for j=0, dfc_simL.o(i).count-1 dfc_plot_1( eTi, dfc_simL.o(i).o(j), 2+j, 1 )
dfc_plot_1( eTi, eTi, 1, 1 )
// for j=0, dfc_tgtL.o(i).count-1 dfc_plot_1( eTi, dfc_tgtL.o(i).o(j), 1, 1 )
dfc_plot_place( eTi, i )
eTi.plotG.menu_action("plot_gen","plot_gen()" )
eTi.plotG.menu_action("plot_axon","plot_axon()" )
eTi.plotG.menu_action("plot_ddVs_all","dfc_ddVpG=new Graph() dfc_pG_ddV(dfc_ddVpG,0)" )
eTi.plotG.menu_action("plot_ddVs_color","dfc_ddVpG=new Graph() dfc_pG_ddV(dfc_ddVpG,1)" )
eTi.plotG.menu_action("plot_dVs","dfc_ddVpG=new Graph() dfc_pG_ddV(dfc_ddVpG,2)" )
eTi.plotG.menu_action("plot_dVs_color","dfc_ddVpG=new Graph() dfc_pG_ddV(dfc_ddVpG,3)" )
}
}
proc dfc_plot_all_old(){ local i
for i=0, dfc_simL.count-1 dfc_plot_one( dfc_simL.o(i), dfc_tgtL.o(i), i )
}
//================================================================================
obfunc rL_td_eT(){ local i localobj rL, eT, sIc, sI
rL = $o1
eT = new eTrace()
sIc = new Vector()
for i=0, rL.count-1 sIc.append( rL.o(i).dist )
sI = sIc.sortindex()
for i=0, rL.count-1 {
eT.vec_t.append( rL.o(sI.x[i]).dist)
eT.vec_v.append( rL.o(sI.x[i]).tzc )
}
return eT
}
//--------------------------------------------------------------------------------
// Usage above
// objref rLL, pGd, pG
// { pDE_asg() rLL = dfc_var_runsL( 0, "aXh_Gbar_Naf", aXh_Gbar_Naf, aXh_Gbar_Naf*0.1, -2, 2, pGd, pG ) }
// abort()
// end of pDE interface related code
//================================================================================