-
Notifications
You must be signed in to change notification settings - Fork 1
/
urakubo.go
1055 lines (907 loc) · 33.8 KB
/
urakubo.go
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
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2021, The Emergent Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
/*
urakubo: This simulation replicates the Urakubo et al, 2008 detailed model of spike-driven
learning, including intracellular Ca-driven signaling, involving CaMKII, CaN, PKA, PP1.
*/
package main
import (
"fmt"
"log"
"sort"
"strconv"
"strings"
"github.com/emer/axon/axon"
"github.com/emer/axon/chans"
"github.com/emer/emergent/emer"
"github.com/emer/emergent/netview"
"github.com/emer/emergent/params"
"github.com/emer/etable/eplot"
"github.com/emer/etable/etable"
"github.com/emer/etable/etensor"
_ "github.com/emer/etable/etview" // include to get gui views
"github.com/goki/gi/gi"
"github.com/goki/gi/gimain"
"github.com/goki/gi/giv"
"github.com/goki/ki/ki"
"github.com/goki/ki/kit"
"github.com/goki/mat32"
)
// this is the stub main for gogi that calls our actual mainrun function, at end of file
func main() {
gimain.Main(func() {
mainrun()
})
}
// LogPrec is precision for saving float values in logs -- requires 6 not 4!
const LogPrec = 6
// SimOpts has high-level simulation options that are accessed in the code
type SimOpts struct {
InitBaseline bool `def:"true" desc:"use 500 sec pre-compiled baseline for initialization"`
}
// TheOpts are the global sim options
var TheOpts SimOpts
func (so *SimOpts) Defaults() {
so.InitBaseline = true
}
// Sim encapsulates the entire simulation model, and we define all the
// functionality as methods on this struct. This structure keeps all relevant
// state information organized and available without having to pass everything around
// as arguments to methods, and provides the core GUI interface (note the view tags
// for the fields which provide hints to how things should be displayed).
type Sim struct {
Net *axon.Network `view:"no-inline" desc:"the network -- click to view / edit parameters for layers, prjns, etc"`
Spine Spine `desc:"the spine state with Urakubo intracellular model"`
Neuron *axon.Neuron `view:"no-inline" desc:"the neuron"`
NeuronEx NeuronEx `view:"no-inline" desc:"extra neuron state for additional channels: Vgcc, AK"`
Params params.Sets `view:"no-inline" desc:"full collection of param sets"`
Stim Stims `desc:"what stimulation to drive with"`
ISISec float64 `desc:"inter-stimulus-interval in seconds -- between reps"`
NReps int `desc:"number of repetitions -- takes 100 to produce classic STDP"`
FinalSecs float64 `def:"20,50,100" desc:"number of seconds to run after the manipulation -- results are strongest after 100, decaying somewhat after that point -- 20 shows similar qualitative results but weaker, 50 is pretty close to 100 -- less than 20 not recommended."`
DurMsec int `desc:"duration for activity window"`
SendHz float32 `desc:"sending firing frequency (used as minus phase for ThetaErr)"`
RecvHz float32 `desc:"receiving firing frequency (used as plus phase for ThetaErr)"`
GeStim float32 `desc:"stimulating current injection"`
DeltaT int `desc:"in msec, difference of Tpost - Tpre == pos = LTP, neg = LTD STDP"`
DeltaTRange int `desc:"range for sweep of DeltaT -- actual range is - to +"`
DeltaTInc int `desc:"increment for sweep of DeltaT"`
RGClamp bool `desc:"use Ge current clamping instead of distrete pulsing for firing rate-based manips, e.g., ThetaErr"`
Opts SimOpts `view:"inline" desc:"global simulation options controlling major differences in behavior"`
VmDend bool `desc:"use dendritic Vm signal for driving spine channels"`
NMDAAxon bool `desc:"use the Axon NMDA channel instead of the allosteric Urakubo one"`
NMDAGbar float32 `def:"0,0.15" desc:"strength of NMDA current -- 0.15 default for posterior cortex"`
GABABGbar float32 `def:"0,0.2" desc:"strength of GABAB current -- 0.2 default for posterior cortex"`
VgccGbar float32 `def:"0,0.12" desc:"strength of Vgcc current -- 0.12 default for posterior cortex"`
CaTarg CaState `desc:"target calcium level for CaTarg stim"`
InitWt float64 `inactive:"+" desc:"initial weight value: Trp_AMPA value at baseline"`
Logs map[string]*etable.Table `view:"no-inline" desc:"all logs"`
Plots map[string]*eplot.Plot2D `view:"-" desc:"all plots"`
// internal state - view:"-"
Msec int `inactive:"+" desc:"current cycle of updating"`
Win *gi.Window `view:"-" desc:"main GUI window"`
NetView *netview.NetView `view:"-" desc:"the network viewer"`
ToolBar *gi.ToolBar `view:"-" desc:"the master toolbar"`
IsRunning bool `view:"-" desc:"true if sim is running"`
StopNow bool `view:"-" desc:"flag to stop running"`
}
// this registers this Sim Type and gives it properties that e.g.,
// prompt for filename for save methods.
var KiT_Sim = kit.Types.AddType(&Sim{}, SimProps)
// TheSim is the overall state for this simulation
var TheSim Sim
// New creates new blank elements and initializes defaults
func (ss *Sim) New() {
ss.Opts.Defaults()
ss.Spine.Defaults()
ss.Spine.Init()
ss.InitWt = ss.Spine.States.AMPAR.Trp.Tot
ss.Net = &axon.Network{}
ss.Params = ParamSets
ss.Stim = ThetaErrComp
ss.ISISec = 0.8
ss.NReps = 10
ss.FinalSecs = 0
ss.DurMsec = 200
ss.SendHz = 50
ss.RecvHz = 25
ss.DeltaT = 16
ss.DeltaTRange = 50
ss.DeltaTInc = 5
ss.RGClamp = true
ss.Defaults()
}
// Defaults sets default params
func (ss *Sim) Defaults() {
ss.Opts.Defaults()
ss.Spine.Defaults()
ss.GeStim = 2
ss.NMDAGbar = 0.15 // 0.1 to 0.15 matches pre-spike increase in vm
ss.GABABGbar = 0.0 // 0.2
ss.VgccGbar = 0.12
ss.CaTarg.Cyt = 10
ss.CaTarg.PSD = 10
}
func (ss *Sim) Log(name string) *etable.Table {
if ss.Logs == nil {
ss.Logs = make(map[string]*etable.Table)
}
dt, ok := ss.Logs[name]
if ok {
return dt
}
dt = &etable.Table{}
ss.Logs[name] = dt
return dt
}
func (ss *Sim) Plot(name string) *eplot.Plot2D {
return ss.Plots[name]
}
func (ss *Sim) AddPlot(name string, plt *eplot.Plot2D) {
if ss.Plots == nil {
ss.Plots = make(map[string]*eplot.Plot2D)
}
ss.Plots[name] = plt
}
////////////////////////////////////////////////////////////////////////////////////////////
// Configs
// Config configures all the elements using the standard functions
func (ss *Sim) Config() {
ss.ConfigNet(ss.Net)
ss.ConfigDWtLog(ss.Log("DWtLog"))
ss.ConfigPhaseDWtLog(ss.Log("PhaseDWtLog"))
ss.ConfigTimeLog(ss.Log("MsecLog"))
ss.ConfigTimeLog(ss.Log("Msec10Log"))
ss.ConfigTimeLog(ss.Log("Msec100Log"))
ss.ConfigTimeLog(ss.Log("MsecLog2"))
ss.ConfigTimeLog(ss.Log("Msec10Log2"))
ss.ConfigTimeLog(ss.Log("Msec100Log2"))
ss.ConfigAutoKLog(ss.Log("AutoKLog"))
ss.Log("GenesisLog")
}
func (ss *Sim) ConfigNet(net *axon.Network) {
net.InitName(net, "Neuron")
ly := net.AddLayer2D("Neuron", 1, 1, emer.Hidden).(*axon.Layer)
net.Defaults()
err := net.Build()
if err != nil {
log.Println(err)
return
}
ss.InitWts(net)
ss.Neuron = &ly.Neurons[0]
}
// InitWts loads the saved weights
func (ss *Sim) InitWts(net *axon.Network) {
net.InitWts()
}
// SetParams sets the params for "Base" and then current ParamSet.
// If sheet is empty, then it applies all avail sheets (e.g., Network, Sim)
// otherwise just the named sheet
// if setMsg = true then we output a message for each param that was set.
func (ss *Sim) SetParams(sheet string, setMsg bool) error {
if sheet == "" {
// this is important for catching typos and ensuring that all sheets can be used
ss.Params.ValidateSheets([]string{"Network", "Sim"})
}
err := ss.SetParamsSet("Base", sheet, setMsg)
// if ss.ParamSet != "" && ss.ParamSet != "Base" {
// sps := strings.Fields(ss.ParamSet)
// for _, ps := range sps {
// err = ss.SetParamsSet(ps, sheet, setMsg)
// }
// }
return err
}
// SetParamsSet sets the params for given params.Set name.
// If sheet is empty, then it applies all avail sheets (e.g., Network, Sim)
// otherwise just the named sheet
// if setMsg = true then we output a message for each param that was set.
func (ss *Sim) SetParamsSet(setNm string, sheet string, setMsg bool) error {
pset, err := ss.Params.SetByNameTry(setNm)
if err != nil {
return err
}
if sheet == "" || sheet == "Network" {
netp, ok := pset.Sheets["Network"]
if ok {
ss.Net.ApplyParams(netp, setMsg)
}
}
if sheet == "" || sheet == "Sim" {
simp, ok := pset.Sheets["Sim"]
if ok {
simp.Apply(ss, setMsg)
}
}
// note: if you have more complex environments with parameters, definitely add
// sheets for them, e.g., "TrainEnv", "TestEnv" etc
return err
}
////////////////////////////////////////////////////////////////////////////////
// Init, utils
// Init restarts the run, and initializes everything, including network weights
// and resets the epoch log table
func (ss *Sim) Init() {
TheOpts = ss.Opts
ss.Spine.Init()
ss.InitWt = ss.Spine.States.AMPAR.Trp.Tot
ss.NeuronEx.Init()
ss.Msec = 0
ss.SetParams("", false) // all sheets
ly := ss.Net.LayerByName("Neuron").(axon.AxonLayer).AsAxon()
if ss.NMDAAxon {
ly.Act.NMDA.Gbar = ss.NMDAGbar
} else {
ly.Act.NMDA.Gbar = 0
}
ly.Act.GABAB.Gbar = ss.GABABGbar
ly.Act.VGCC.Gbar = ss.VgccGbar
ss.InitWts(ss.Net)
ss.StopNow = false
ss.UpdateView()
}
// Counters returns a string of the current counter state
// use tabs to achieve a reasonable formatting overall
// and add a few tabs at the end to allow for expansion..
func (ss *Sim) Counters() string {
return fmt.Sprintf("Msec:\t%d\t\t\t", ss.Msec)
}
func (ss *Sim) UpdateView() {
if ss.NetView != nil && ss.NetView.IsVisible() {
ss.NetView.Record(ss.Counters(), 0)
// note: essential to use Go version of update when called from another goroutine
ss.NetView.GoUpdate() // note: using counters is significantly slower..
}
}
////////////////////////////////////////////////////////////////////////////////
// Running the Network, starting bottom-up..
// RunStim runs current Stim selection
func (ss *Sim) RunStim() {
fn, has := StimFuncs[ss.Stim]
if !has {
fmt.Printf("Stim function: %s not found!\n", ss.Stim)
return
}
ss.StopNow = false
go fn()
}
// NeuronUpdt updates the neuron and spine for given msec
func (ss *Sim) NeuronUpdt(msec int, ge, gi float32) {
ss.Msec = msec
ly := ss.Net.LayerByName("Neuron").(axon.AxonLayer).AsAxon()
nrn := ss.Neuron
nex := &ss.NeuronEx
vbio := chans.VToBio(nrn.Vm) // dend
// note: Ge should only
geExt := float32(0)
nrn.GeRaw = ge
ly.Act.Dt.GeSynFmRaw(nrn.GeRaw, &nrn.GeSyn, ly.Act.Init.Ge)
nrn.Ge = nrn.GeSyn
nrn.Gi = gi
ly.Act.NMDAFmRaw(nrn, geExt)
ly.Act.GvgccFmVm(nrn)
ly.Learn.LrnNMDAFmRaw(nrn, geExt)
nrn.GABAB, nrn.GABABx = ly.Act.GABAB.GABAB(nrn.GABAB, nrn.GABABx, nrn.Gi)
nrn.GgabaB = ly.Act.GABAB.GgabaB(nrn.GABAB, nrn.VmDend)
nrn.Gak = ly.Act.AK.Gak(nrn.VmDend)
nrn.Gk += nrn.Gak
nrn.Ge += nrn.Gvgcc + nrn.Gnmda
if !ss.NMDAAxon {
nrn.Ge += ss.NMDAGbar * float32(ss.Spine.States.NMDAR.G)
}
nrn.Gi += nrn.GgabaB
// todo: Ca from NMDAAxon
ss.Spine.Ca.SetInject(float64(nex.VgccJcaPSD), float64(nex.VgccJcaCyt))
psd_pca := float32(1.7927e5 * 0.04) // SVR_PSD
cyt_pca := float32(1.0426e5 * 0.04) // SVR_CYT
nex.VgccJcaPSD = -vbio * psd_pca * nrn.Gvgcc
nex.VgccJcaCyt = -vbio * cyt_pca * nrn.Gvgcc
ss.Spine.States.VmS = float64(vbio)
ly.Act.VmFmG(nrn)
ly.Act.ActFmG(nrn)
ss.Spine.StepTime(0.001)
}
// LogDefault does default logging for current Msec
func (ss *Sim) LogDefault(n int) {
sfx := ""
if n == 1 {
sfx = "2"
}
msec := ss.Msec
ss.LogTime(ss.Log("MsecLog"+sfx), msec%1000)
if ss.Msec%10 == 0 {
ss.LogTime(ss.Log("Msec10Log"+sfx), (msec/10)%1000)
if ss.Msec%100 == 0 {
ss.LogTime(ss.Log("Msec100Log"+sfx), (msec / 100))
ss.UpdateTimePlots()
}
}
}
// Stop tells the sim to stop running
func (ss *Sim) Stop() {
ss.StopNow = true
}
// Stopped is called when a run method stops running -- updates the IsRunning flag and toolbar
func (ss *Sim) Stopped() {
ss.IsRunning = false
if ss.Win != nil {
vp := ss.Win.WinViewport2D()
if ss.ToolBar != nil {
ss.ToolBar.UpdateActions()
}
vp.SetNeedsFullRender()
}
}
func (ss *Sim) GraphRun(secs float64, n int) {
nms := int(secs / 0.001)
sms := ss.Msec
for msec := 0; msec < nms; msec++ {
ss.NeuronUpdt(sms+msec, 0, 0)
ss.LogDefault(n)
if ss.StopNow {
break
}
}
}
func (ss *Sim) RunQuiet(secs float64) {
nms := int(secs / 0.001)
sms := ss.Msec
for msec := 0; msec < nms; msec++ {
ss.NeuronUpdt(sms+msec, 0, 0)
if ss.StopNow {
break
}
}
}
//////////////////////////////////////////////
// Time Log
// LogTime adds data from current msec to the given table at given row
func (ss *Sim) LogTime(dt *etable.Table, row int) {
if dt.Rows <= row {
dt.SetNumRows(row + 1)
}
nrn := ss.Neuron
nex := &ss.NeuronEx
dt.SetCellFloat("Time", row, float64(ss.Msec)*0.001)
dt.SetCellFloat("Ge", row, float64(nrn.Ge))
dt.SetCellFloat("Inet", row, float64(nrn.Inet))
dt.SetCellFloat("Vm", row, float64(nrn.Vm))
dt.SetCellFloat("Act", row, float64(nrn.Act))
dt.SetCellFloat("Spike", row, float64(nrn.Spike))
dt.SetCellFloat("Gk", row, float64(nrn.Gk))
dt.SetCellFloat("ISI", row, float64(nrn.ISI))
dt.SetCellFloat("AvgISI", row, float64(nrn.ISIAvg))
dt.SetCellFloat("VmDend", row, float64(nrn.VmDend))
dt.SetCellFloat("SnmdaO", row, float64(nrn.SnmdaO))
dt.SetCellFloat("Gnmda", row, float64(nrn.Gnmda))
dt.SetCellFloat("GABAB", row, float64(nrn.GABAB))
dt.SetCellFloat("GgabaB", row, float64(nrn.GgabaB))
dt.SetCellFloat("Gvgcc", row, float64(nrn.Gvgcc))
dt.SetCellFloat("VgccM", row, float64(nrn.VgccM))
dt.SetCellFloat("VgccH", row, float64(nrn.VgccH))
dt.SetCellFloat("VgccJcaPSD", row, float64(nex.VgccJcaPSD))
dt.SetCellFloat("VgccJcaCyt", row, float64(nex.VgccJcaCyt))
dt.SetCellFloat("Gak", row, float64(nrn.Gak))
dt.SetCellFloat("AKm", row, float64(nex.AKm))
dt.SetCellFloat("AKh", row, float64(nex.AKh))
ss.Spine.Log(dt, row)
}
func (ss *Sim) ConfigTimeLog(dt *etable.Table) {
dt.SetMetaData("name", "Urakubo Time Log")
dt.SetMetaData("desc", "Record of neuron / spine data over time")
dt.SetMetaData("read-only", "true")
dt.SetMetaData("precision", strconv.Itoa(LogPrec))
sch := etable.Schema{
{"Time", etensor.FLOAT64, nil, nil},
{"Ge", etensor.FLOAT64, nil, nil},
{"Inet", etensor.FLOAT64, nil, nil},
{"Vm", etensor.FLOAT64, nil, nil},
{"Act", etensor.FLOAT64, nil, nil},
{"Spike", etensor.FLOAT64, nil, nil},
{"Gk", etensor.FLOAT64, nil, nil},
{"ISI", etensor.FLOAT64, nil, nil},
{"AvgISI", etensor.FLOAT64, nil, nil},
{"VmDend", etensor.FLOAT64, nil, nil},
{"NMDA", etensor.FLOAT64, nil, nil},
{"Gnmda", etensor.FLOAT64, nil, nil},
{"GABAB", etensor.FLOAT64, nil, nil},
{"GgabaB", etensor.FLOAT64, nil, nil},
{"Gvgcc", etensor.FLOAT64, nil, nil},
{"Vgccm", etensor.FLOAT64, nil, nil},
{"Vgcch", etensor.FLOAT64, nil, nil},
{"VgccJcaPSD", etensor.FLOAT64, nil, nil},
{"VgccJcaCyt", etensor.FLOAT64, nil, nil},
{"Gak", etensor.FLOAT64, nil, nil},
{"AKm", etensor.FLOAT64, nil, nil},
{"AKh", etensor.FLOAT64, nil, nil},
}
ss.Spine.ConfigLog(&sch)
dt.SetFromSchema(sch, 1000)
}
func (ss *Sim) ConfigTimePlot(plt *eplot.Plot2D, dt *etable.Table) *eplot.Plot2D {
plt.Params.Title = "Urakubo Time Plot"
plt.Params.XAxisCol = "Time"
plt.SetTable(dt)
// order of params: on, fixMin, min, fixMax, max
plt.SetColParams("Time", eplot.Off, eplot.FloatMin, 0, eplot.FloatMax, 0)
// plt.SetColParams("Time", eplot.Off, eplot.FixMin, .48, eplot.FixMax, .54)
plt.SetColParams("Ge", eplot.Off, eplot.FixMin, 0, eplot.FixMax, 1)
plt.SetColParams("Inet", eplot.Off, eplot.FixMin, -.2, eplot.FixMax, 1)
plt.SetColParams("Vm", eplot.On, eplot.FixMin, 0, eplot.FixMax, 1)
plt.SetColParams("Act", eplot.Off, eplot.FixMin, 0, eplot.FixMax, 1)
plt.SetColParams("Spike", eplot.On, eplot.FixMin, 0, eplot.FixMax, 1)
plt.SetColParams("Gk", eplot.Off, eplot.FixMin, 0, eplot.FixMax, 1)
plt.SetColParams("ISI", eplot.Off, eplot.FixMin, -2, eplot.FloatMax, 1)
plt.SetColParams("AvgISI", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("VmDend", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("NMDA", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("Gnmda", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("GABAB", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("GgabaB", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("Gvgcc", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("Vgccm", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("Vgcch", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("VgccJcaPSD", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("VgccJcaCyt", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("Gak", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("AKm", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("AKh", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
for _, cn := range dt.ColNames {
if cn != "Time" {
plt.SetColParams(cn, eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
}
}
plt.SetColParams("VmS", eplot.Off, eplot.FixMin, -70, eplot.FloatMax, 1)
plt.SetColParams("PreSpike", eplot.On, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("PSD_Ca", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("PSD_CaMact", eplot.On, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("Cyt_AC1act", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("PSD_AC1act", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("PSD_CaMKIIact", eplot.On, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("PSD_PP1act", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("PSD_CaNact", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("Cyt_CaMKIIact", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("Trp_AMPAR", eplot.On, eplot.FixMin, 0, eplot.FloatMax, 1)
return plt
}
func (ss *Sim) ResetTimePlots() {
for nm, dt := range ss.Logs {
if strings.HasPrefix(nm, "Msec") {
dt.SetNumRows(0)
}
}
ss.UpdateTimePlots()
}
func (ss *Sim) UpdateTimePlots() {
for nm, plt := range ss.Plots {
if strings.HasPrefix(nm, "Msec") {
plt.Update()
}
}
}
//////////////////////////////////////////////
// DWt Log
// LogDWt adds data for current dwt value as function of x, y values
func (ss *Sim) LogDWt(dt *etable.Table, x, y float64) {
row := dt.Rows
if dt.Rows <= row {
dt.SetNumRows(row + 1)
}
dt.SetCellFloat("X", row, x)
dt.SetCellFloat("Y", row, y)
wt := ss.Spine.States.AMPAR.Trp.Tot
dwt := (wt / ss.InitWt) - 1
dt.SetCellFloat("DWt", row, float64(dwt))
ss.Spine.Log(dt, row)
}
func (ss *Sim) ConfigDWtLog(dt *etable.Table) {
dt.SetMetaData("name", "Urakubo DWt Log")
dt.SetMetaData("desc", "Record of final proportion dWt change")
dt.SetMetaData("read-only", "true")
dt.SetMetaData("precision", strconv.Itoa(LogPrec))
sch := etable.Schema{
{"X", etensor.FLOAT64, nil, nil},
{"Y", etensor.FLOAT64, nil, nil},
{"DWt", etensor.FLOAT64, nil, nil},
}
ss.Spine.ConfigLog(&sch)
dt.SetFromSchema(sch, 0)
}
func (ss *Sim) ConfigDWtPlot(plt *eplot.Plot2D, dt *etable.Table) *eplot.Plot2D {
plt.Params.Title = "Urakubo DWt Plot"
plt.Params.XAxisCol = "X"
plt.Params.LegendCol = "Y"
plt.SetTable(dt)
// order of params: on, fixMin, min, fixMax, max
plt.SetColParams("DWt", eplot.On, eplot.FixMin, -0.5, eplot.FixMax, 0.5)
plt.SetColParams("PSD_CaMKIIact", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("PSD_PP1act", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("PSD_CaNact", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
return plt
}
//////////////////////////////////////////////
// PhaseDWt Log
// LogPhaseDWt adds data for current dwt value as function of phase and phase hz levels
func (ss *Sim) LogPhaseDWt(dt *etable.Table, sphz, rphz []int) {
row := dt.Rows
if dt.Rows <= row {
dt.SetNumRows(row + 1)
}
chl := (float64(sphz[1])/100.0)*(float64(rphz[1])/100.0) - (float64(sphz[0])/100.0)*(float64(rphz[0])/100.0)
dt.SetCellFloat("CHL", row, float64(chl))
dt.SetCellString("Cond", row, fmt.Sprintf("S:%d-%d R:%d-%d", sphz[0], sphz[1], rphz[0], rphz[1]))
dt.SetCellFloat("SMhz", row, float64(sphz[0]))
dt.SetCellFloat("SPhz", row, float64(sphz[1]))
dt.SetCellFloat("RMhz", row, float64(rphz[0]))
dt.SetCellFloat("RPhz", row, float64(rphz[1]))
wt := ss.Spine.States.AMPAR.Trp.Tot
dwt := (wt / ss.InitWt) - 1
dt.SetCellFloat("DWt", row, float64(dwt))
ss.Spine.Log(dt, row)
}
func (ss *Sim) ConfigPhaseDWtLog(dt *etable.Table) {
dt.SetMetaData("name", "Urakubo Phase DWt Log")
dt.SetMetaData("desc", "Record of final proportion dWt change")
dt.SetMetaData("read-only", "true")
dt.SetMetaData("precision", strconv.Itoa(LogPrec))
sch := etable.Schema{
{"CHL", etensor.FLOAT64, nil, nil},
{"Cond", etensor.STRING, nil, nil},
{"SMhz", etensor.FLOAT64, nil, nil},
{"SPhz", etensor.FLOAT64, nil, nil},
{"RMhz", etensor.FLOAT64, nil, nil},
{"RPhz", etensor.FLOAT64, nil, nil},
{"DWt", etensor.FLOAT64, nil, nil},
}
ss.Spine.ConfigLog(&sch)
dt.SetFromSchema(sch, 0)
}
func (ss *Sim) ConfigPhaseDWtPlot(plt *eplot.Plot2D, dt *etable.Table) *eplot.Plot2D {
plt.Params.Title = "Urakubo Phase DWt Plot"
plt.Params.XAxisCol = "CHL"
plt.Params.LegendCol = "Cond"
plt.Params.Scale = 3
plt.SetTable(dt)
plt.Params.Points = true
plt.Params.Lines = false
// order of params: on, fixMin, min, fixMax, max
plt.SetColParams("DWt", eplot.On, eplot.FixMin, -1, eplot.FixMax, 1)
plt.SetColParams("CHL", eplot.Off, eplot.FixMin, -1, eplot.FixMax, 2)
plt.SetColParams("PSD_CaMKIIact", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("PSD_PP1act", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
plt.SetColParams("PSD_CaNact", eplot.Off, eplot.FixMin, 0, eplot.FloatMax, 1)
return plt
}
func (ss *Sim) ResetDWtPlot() {
ss.Log("DWtLog").SetNumRows(0)
ss.Plot("DWtPlot").Update()
ss.Log("PhaseDWtLog").SetNumRows(0)
ss.Plot("PhaseDWtPlot").Update()
}
//////////////////////////////////////////////
// AutoK Log
func (ss *Sim) ConfigAutoKLog(dt *etable.Table) {
dt.SetMetaData("name", "Urakubo AutoK Plot")
dt.SetMetaData("desc", "autoK as function of diff variables")
dt.SetMetaData("read-only", "true")
dt.SetMetaData("precision", strconv.Itoa(LogPrec))
sch := etable.Schema{
{"Total", etensor.FLOAT64, nil, nil},
{"AutoK", etensor.FLOAT64, nil, nil},
}
dt.SetFromSchema(sch, 0)
}
func (ss *Sim) ConfigAutoKPlot(plt *eplot.Plot2D, dt *etable.Table) *eplot.Plot2D {
plt.Params.Title = "Urakubo AutoK Plot"
plt.Params.XAxisCol = "Total"
plt.SetTable(dt)
// order of params: on, fixMin, min, fixMax, max
plt.SetColParams("AutoK", eplot.On, eplot.FloatMin, 0, eplot.FloatMax, 1)
return plt
}
// AutoK plots AutoK as function of T total
func (ss *Sim) AutoK() {
dt := ss.Log("AutoKLog")
max := 1.0
inc := 0.01
n := int(max / inc)
dt.SetNumRows(n)
cb := 0.75
ct := 0.8
ca := 0.8
row := 0
for T := 0.0; T <= max; T += inc {
// this is a function that turns positive around 0.13 and is
// roughly parabolic after that but not quite..
tmp := T * (-0.22 + 1.826*T + -0.8*T*T)
if false {
Wb := .25 * T
Wp := .25 * T
Wt := .25 * T
Wa := .25 * T
tmp *= 0.75 * (cb*Wb + Wp + ct*Wt + ca*Wa)
// if tmp < 0 {
// tmp = 0
// }
}
// autok := 0.29 * tmp
autok := tmp
dt.SetCellFloat("AutoK", row, autok)
dt.SetCellFloat("Total", row, T)
row++
}
}
////////////////////////////////////////////////////////////////////////////////////////////
// Genesis Plots
func (ss *Sim) ConfigGenesisPlot(plt *eplot.Plot2D, dt *etable.Table) *eplot.Plot2D {
plt.Params.Title = "Urakubo Genesis Data Plot"
plt.Params.XAxisCol = "Time"
plt.SetTable(dt)
return plt
}
var GeneColMap = map[string]string{
"Time": "00_Time",
"Ca.Co12": "08 PSD_Ca",
"Ca.Co6": "07 Cyt_Ca",
"CaM-AC1.Co10": "31 PSD_AC1act",
"CaM-AC1.Co4": "26 Cyt_AC1act",
"CaMCa3.Co15": "22 PSD_Ca3CaM",
"I1_active.Co14": "36 PSD_I1P",
"Internal_AMPAR.Co16": "40 Int_AMPAR",
"Jca27": "13 NMDA_Jca",
"Jca31": "17 PSD_Vgcc_Jca",
"Jca32": "18 Cyt_Vgcc_Jca",
"Ji29": "17 NMDA_Ji",
"Memb_AMPAR.Co17": "41 Mbr_AMPAR",
"Mg30": "11 NMDA_Mg",
"Nopen26": "12 NMDA_Nopen",
"Nt023": "14 NMDA_Nt0",
"Nt124": "15 NMDA_Nt1",
"Nt225": "16 NMDA_Nt2",
"PP1_active.Co1": "35 Cyt_PP1act",
"PP1_active.Co7": "37 PSD_PP1act",
"PSD_AMPAR.Co18": "42 PSD_AMPAR",
"Trapped_AMPAR.Co19": "43 Trp_AMPAR",
"Vca28": "16 NMDA_Vca",
"Vm21": "01 Vsoma",
"Vm22": "02 Vdend",
"activeCaMKII.Co11": "23 PSD_CaMKIIact",
"activeCaMKII.Co5": "21 Cyt_CaMKIIact",
"activeCaN.Co3": "24 Cyt_CaNact",
"activeCaN.Co9": "25 PSD_CaNact",
"activePKA.Co2": "30 Cyt_PKAact",
"activePKA.Co8": "33 PSD_PKAact",
"cAMP.Co13": "32 PSD_cAMP",
"membrane_potential20": "03 Vdend2",
}
func (ss *Sim) RenameGenesisLog(dt *etable.Table) *etable.Table {
if dt.ColNames[1] != "Ca.Co12" {
return dt
}
omap := make(map[string]int)
for i, cn := range dt.ColNames {
if nn, ok := GeneColMap[cn]; ok {
dt.ColNames[i] = nn
}
omap[dt.ColNames[i]] = i
}
sort.Strings(dt.ColNames)
nc := make([]etensor.Tensor, len(dt.ColNames))
for i, cn := range dt.ColNames {
oi := omap[cn]
nc[i] = dt.Cols[oi]
dt.ColNames[i] = cn[3:]
}
dt.Cols = nc
dt.UpdateColNameMap()
if TheOpts.InitBaseline {
ix := etable.IdxView{}
ix.Table = dt
for ri := 0; ri < dt.Rows; ri++ {
t := dt.CellFloat("Time", ri)
if t > 500 {
ix.Idxs = append(ix.Idxs, ri)
}
dt.SetCellFloat("Time", ri, t-500)
}
dt = ix.NewTable()
ss.Logs["GenesisLog"] = dt
}
return dt
}
func (ss *Sim) OpenGenesisData(fname gi.FileName) {
dt := ss.Log("GenesisLog")
dt.OpenCSV(fname, etable.Tab)
dt = ss.RenameGenesisLog(dt)
dt.SetMetaData("name", string(fname))
dt.SetMetaData("desc", "Genesis Urakubo model data")
dt.SetMetaData("read-only", "true")
dt.SetMetaData("precision", strconv.Itoa(LogPrec))
ss.Plots["GenesisPlot"].SetTable(dt)
}
////////////////////////////////////////////////////////////////////////////////////////////
// Gui
func (ss *Sim) ConfigNetView(nv *netview.NetView) {
nv.ViewDefaults()
}
// ConfigGui configures the GoGi gui interface for this simulation,
func (ss *Sim) ConfigGui() *gi.Window {
width := 1600
height := 1200
gi.SetAppName("urakubo")
gi.SetAppAbout(`This simulation replicates the Urakubo et al, 2008 biophysical model of LTP / LTD.
See <a href="https://github.com/ccnlab/kinase/blob/master/sims/urakubo/README.md">README.md on GitHub</a>.</p>`)
win := gi.NewMainWindow("urakubo", "Urakubo", width, height)
ss.Win = win
vp := win.WinViewport2D()
updt := vp.UpdateStart()
mfr := win.SetMainFrame()
tbar := gi.AddNewToolBar(mfr, "tbar")
tbar.SetStretchMaxWidth()
ss.ToolBar = tbar
split := gi.AddNewSplitView(mfr, "split")
split.Dim = mat32.X
split.SetStretchMaxWidth()
split.SetStretchMaxHeight()
sv := giv.AddNewStructView(split, "sv")
sv.SetStruct(ss)
tv := gi.AddNewTabView(split, "tv")
nv := tv.AddNewTab(netview.KiT_NetView, "NetView").(*netview.NetView)
nv.Var = "Act"
nv.SetNet(ss.Net)
ss.NetView = nv
ss.ConfigNetView(nv) // add labels etc
plt := tv.AddNewTab(eplot.KiT_Plot2D, "DWtPlot").(*eplot.Plot2D)
ss.AddPlot("DWtPlot", ss.ConfigDWtPlot(plt, ss.Log("DWtLog")))
plt = tv.AddNewTab(eplot.KiT_Plot2D, "PhaseDWtPlot").(*eplot.Plot2D)
ss.AddPlot("PhaseDWtPlot", ss.ConfigPhaseDWtPlot(plt, ss.Log("PhaseDWtLog")))
plt = tv.AddNewTab(eplot.KiT_Plot2D, "Msec100Plot").(*eplot.Plot2D)
ss.AddPlot("Msec100Plot", ss.ConfigTimePlot(plt, ss.Log("Msec100Log")))
plt = tv.AddNewTab(eplot.KiT_Plot2D, "Msec100Plot2").(*eplot.Plot2D)
ss.AddPlot("Msec100Plot2", ss.ConfigTimePlot(plt, ss.Log("Msec100Log2")))
plt = tv.AddNewTab(eplot.KiT_Plot2D, "Msec10Plot").(*eplot.Plot2D)
ss.AddPlot("Msec10Plot", ss.ConfigTimePlot(plt, ss.Log("Msec10Log")))
plt = tv.AddNewTab(eplot.KiT_Plot2D, "Msec10Plot2").(*eplot.Plot2D)
ss.AddPlot("Msec10Plot2", ss.ConfigTimePlot(plt, ss.Log("Msec10Log2")))
plt = tv.AddNewTab(eplot.KiT_Plot2D, "MsecPlot").(*eplot.Plot2D)
ss.AddPlot("MsecPlot", ss.ConfigTimePlot(plt, ss.Log("MsecLog")))
plt = tv.AddNewTab(eplot.KiT_Plot2D, "MsecPlot2").(*eplot.Plot2D)
ss.AddPlot("MsecPlot2", ss.ConfigTimePlot(plt, ss.Log("MsecLog2")))
plt = tv.AddNewTab(eplot.KiT_Plot2D, "AutoKPlot").(*eplot.Plot2D)
ss.AddPlot("AutoKPlot", ss.ConfigAutoKPlot(plt, ss.Log("AutoKLog")))
plt = tv.AddNewTab(eplot.KiT_Plot2D, "GenesisPlot").(*eplot.Plot2D)
ss.AddPlot("GenesisPlot", ss.ConfigGenesisPlot(plt, ss.Log("GenesisLog")))
split.SetSplits(.2, .8)
tbar.AddAction(gi.ActOpts{Label: "Init", Icon: "update", Tooltip: "Initialize everything including network weights, and start over. Also applies current params.", UpdateFunc: func(act *gi.Action) {
act.SetActiveStateUpdt(!ss.IsRunning)
}}, win.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
ss.Init()
vp.SetNeedsFullRender()
})
tbar.AddAction(gi.ActOpts{Label: "Stop", Icon: "stop", Tooltip: "Interrupts running. Hitting Train again will pick back up where it left off.", UpdateFunc: func(act *gi.Action) {
act.SetActiveStateUpdt(ss.IsRunning)
}}, win.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
ss.Stop()
})
tbar.AddAction(gi.ActOpts{Label: "Run", Icon: "step-fwd", Tooltip: "Runs current Stim.", UpdateFunc: func(act *gi.Action) {
act.SetActiveStateUpdt(!ss.IsRunning)
}}, win.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
if !ss.IsRunning {
ss.IsRunning = true
tbar.UpdateActions()
ss.RunStim() // does go
}
})
tbar.AddSeparator("run-sep")
tbar.AddAction(gi.ActOpts{Label: "Reset Plots", Icon: "update", Tooltip: "Reset Time Plots.", UpdateFunc: func(act *gi.Action) {
act.SetActiveStateUpdt(!ss.IsRunning)
}}, win.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
if !ss.IsRunning {
ss.ResetTimePlots()
}
})
tbar.AddAction(gi.ActOpts{Label: "Reset DWt Plot", Icon: "update", Tooltip: "Reset DWt Plot.", UpdateFunc: func(act *gi.Action) {
act.SetActiveStateUpdt(!ss.IsRunning)
}}, win.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
if !ss.IsRunning {
ss.ResetDWtPlot()
}
})
tbar.AddAction(gi.ActOpts{Label: "AutoK Plot", Icon: "update", Tooltip: "Plot AutoK function.", UpdateFunc: func(act *gi.Action) {
act.SetActiveStateUpdt(!ss.IsRunning)
}}, win.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
if !ss.IsRunning {
ss.AutoK()
}
})
tbar.AddAction(gi.ActOpts{Label: "Genesis Plot", Icon: "file-open", Tooltip: "Open Genesis Urakubo model data from geneplot directory.", UpdateFunc: func(act *gi.Action) {
act.SetActiveStateUpdt(!ss.IsRunning)
}}, win.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
giv.CallMethod(ss, "OpenGenesisData", vp)
})
tbar.AddAction(gi.ActOpts{Label: "Defaults", Icon: "update", Tooltip: "Restore initial default parameters.", UpdateFunc: func(act *gi.Action) {
act.SetActiveStateUpdt(!ss.IsRunning)
}}, win.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
ss.Defaults()
ss.Init()
vp.SetNeedsFullRender()
})
tbar.AddAction(gi.ActOpts{Label: "README", Icon: "file-markdown", Tooltip: "Opens your browser on the README file that contains instructions for how to run this model."}, win.This(),
func(recv, send ki.Ki, sig int64, data interface{}) {
gi.OpenURL("https://github.com/ccnlab/kinase/blob/master/sims/urakubo/README.md")
})
vp.UpdateEndNoSig(updt)
// main menu
appnm := gi.AppName()
mmen := win.MainMenu
mmen.ConfigMenus([]string{appnm, "File", "Edit", "Window"})
amen := win.MainMenu.ChildByName(appnm, 0).(*gi.Action)
amen.Menu.AddAppMenu(win)
emen := win.MainMenu.ChildByName("Edit", 1).(*gi.Action)
emen.Menu.AddCopyCutPaste(win)
/*
inQuitPrompt := false
gi.SetQuitReqFunc(func() {
if inQuitPrompt {
return
}
inQuitPrompt = true
gi.PromptDialog(vp, gi.DlgOpts{Title: "Really Quit?",
Prompt: "Are you <i>sure</i> you want to quit and lose any unsaved params, weights, logs, etc?"}, gi.AddOk, gi.AddCancel,
win.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
if sig == int64(gi.DialogAccepted) {
gi.Quit()
} else {
inQuitPrompt = false
}
})