From 9102814f2244be2901014541250ce5a8ee2bc79b Mon Sep 17 00:00:00 2001 From: "Randall C. O'Reilly" Date: Fri, 15 Dec 2023 14:48:24 -0800 Subject: [PATCH] synca plot --- kinase/plot/gtigen.go | 39 +++++++++++++ kinase/plot/synca_plot.go | 113 ++++++++++---------------------------- 2 files changed, 69 insertions(+), 83 deletions(-) create mode 100644 kinase/plot/gtigen.go diff --git a/kinase/plot/gtigen.go b/kinase/plot/gtigen.go new file mode 100644 index 000000000..2a78aed5a --- /dev/null +++ b/kinase/plot/gtigen.go @@ -0,0 +1,39 @@ +// Code generated by "goki generate -add-types"; DO NOT EDIT. + +package main + +import ( + "goki.dev/gti" + "goki.dev/ordmap" +) + +var _ = gti.AddType(>i.Type{ + Name: "main.Sim", + ShortName: "main.Sim", + IDName: "sim", + Doc: "Sim holds the params, table, etc", + Directives: gti.Directives{}, + Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{ + {"CaDt", >i.Field{Name: "CaDt", Type: "github.com/emer/axon/kinase.CaParams", LocalType: "kinase.CaParams", Doc: "Ca time constants", Directives: gti.Directives{}, Tag: "view:\"inline\""}}, + {"Minit", >i.Field{Name: "Minit", Type: "float64", LocalType: "float64", Doc: "", Directives: gti.Directives{}, Tag: ""}}, + {"Pinit", >i.Field{Name: "Pinit", Type: "float64", LocalType: "float64", Doc: "", Directives: gti.Directives{}, Tag: ""}}, + {"Dinit", >i.Field{Name: "Dinit", Type: "float64", LocalType: "float64", Doc: "", Directives: gti.Directives{}, Tag: ""}}, + {"MdtAdj", >i.Field{Name: "MdtAdj", Type: "float64", LocalType: "float64", Doc: "adjustment to dt to account for discrete time updating", Directives: gti.Directives{}, Tag: "def:\"0,0.11\""}}, + {"PdtAdj", >i.Field{Name: "PdtAdj", Type: "float64", LocalType: "float64", Doc: "adjustment to dt to account for discrete time updating", Directives: gti.Directives{}, Tag: "def:\"0.0.03\""}}, + {"DdtAdj", >i.Field{Name: "DdtAdj", Type: "float64", LocalType: "float64", Doc: "adjustment to dt to account for discrete time updating", Directives: gti.Directives{}, Tag: "def:\"0.0.03\""}}, + {"TimeSteps", >i.Field{Name: "TimeSteps", Type: "int", LocalType: "int", Doc: "number of time steps", Directives: gti.Directives{}, Tag: ""}}, + {"Table", >i.Field{Name: "Table", Type: "*goki.dev/etable/v2/etable.Table", LocalType: "*etable.Table", Doc: "table for plot", Directives: gti.Directives{}, Tag: "view:\"no-inline\""}}, + {"Plot", >i.Field{Name: "Plot", Type: "*goki.dev/etable/v2/eplot.Plot2D", LocalType: "*eplot.Plot2D", Doc: "the plot", Directives: gti.Directives{}, Tag: "view:\"-\""}}, + {"TimeTable", >i.Field{Name: "TimeTable", Type: "*goki.dev/etable/v2/etable.Table", LocalType: "*etable.Table", Doc: "table for plot", Directives: gti.Directives{}, Tag: "view:\"no-inline\""}}, + {"TimePlot", >i.Field{Name: "TimePlot", Type: "*goki.dev/etable/v2/eplot.Plot2D", LocalType: "*eplot.Plot2D", Doc: "the plot", Directives: gti.Directives{}, Tag: "view:\"-\""}}, + }), + Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{}), + Methods: ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{ + {"Run", >i.Method{Name: "Run", Doc: "Run runs the equation.", Directives: gti.Directives{ + >i.Directive{Tool: "gti", Directive: "add", Args: []string{}}, + }, Args: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{}), Returns: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{})}}, + {"TimeRun", >i.Method{Name: "TimeRun", Doc: "TimeRun runs the equation over time.", Directives: gti.Directives{ + >i.Directive{Tool: "gti", Directive: "add", Args: []string{}}, + }, Args: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{}), Returns: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{})}}, + }), +}) diff --git a/kinase/plot/synca_plot.go b/kinase/plot/synca_plot.go index 6b37439b5..5889db84a 100644 --- a/kinase/plot/synca_plot.go +++ b/kinase/plot/synca_plot.go @@ -5,33 +5,32 @@ // synca_plot plots kinase SynCa update equations package main +//go:generate goki generate -add-types + import ( "math" "strconv" "github.com/emer/axon/kinase" - "github.com/emer/etable/eplot" - "github.com/goki/ki/ki" + "goki.dev/etable/v2/eplot" "goki.dev/etable/v2/etable" "goki.dev/etable/v2/etensor" - _ "goki.dev/etable/v2/vv2iew" // include to get gui views + _ "goki.dev/etable/v2/etview" // include to get gui views "goki.dev/gi/v2/gi" "goki.dev/gi/v2/gimain" "goki.dev/gi/v2/giv" _ "goki.dev/gosl/v2/slboolview" // ditto - "goki.dev/mat32/v2" + "goki.dev/icons" ) -func main() { - TheSim.Config() - gimain.Main(func() { // this starts gui -- requires valid OpenGL display connection (e.g., X11) - guirun() - }) -} +func main() { gimain.Run(app) } -func guirun() { - win := TheSim.ConfigGUI() - win.StartEventLoop() +func app() { + sim := &Sim{} + sim.Config() + sim.Run() + b := sim.ConfigGUI() + b.NewWindow().Run().Wait() } // LogPrec is precision for saving float values in logs @@ -69,17 +68,8 @@ type Sim struct { // the plot TimePlot *eplot.Plot2D `view:"-"` - - // main GUI window - Win *gi.Window `view:"-"` - - // the master toolbar - ToolBar *gi.ToolBar `view:"-"` } -// TheSim is the overall state for this simulation -var TheSim Sim - // Config configures all the elements using the standard functions func (ss *Sim) Config() { ss.CaDt.Defaults() @@ -102,7 +92,7 @@ func (ss *Sim) Update() { } // Run runs the equation. -func (ss *Sim) Run() { +func (ss *Sim) Run() { //gti:add ss.Update() dt := ss.Table @@ -161,7 +151,9 @@ func (ss *Sim) Run() { di += float64(ss.CaDt.Dt.DDt) * (pi - di) } - ss.Plot.Update() + if ss.Plot != nil { + ss.Plot.UpdatePlot() + } } func (ss *Sim) ConfigTable(dt *etable.Table) { @@ -205,7 +197,7 @@ func (ss *Sim) ConfigPlot(plt *eplot.Plot2D, dt *etable.Table) *eplot.Plot2D { ///////////////////////////////////////////////////////////////// // TimeRun runs the equation over time. -func (ss *Sim) TimeRun() { +func (ss *Sim) TimeRun() { //gti:add ss.Update() /* dt := ss.TimeTable @@ -257,72 +249,27 @@ func (ss *Sim) ConfigTimePlot(plt *eplot.Plot2D, dt *etable.Table) *eplot.Plot2D } // ConfigGUI configures the GoGi gui interface for this simulation, -func (ss *Sim) ConfigGUI() *gi.Window { - width := 1600 - height := 1200 - - // gi.WinEventTrace = true - - gi.SetAppName("synca_plot") - gi.SetAppAbout(`This plots an equation. See emergent on GitHub.

`) - - win := gi.NewMainWindow("syncaplot", "Plotting Equations", width, height) - ss.Win = win - - vp := win.WinViewport2D() - updt := vp.UpdateStart() +func (ss *Sim) ConfigGUI() *gi.Body { + b := gi.NewAppBody("synca_plot").SetTitle("Plotting Equations") - mfr := win.SetMainFrame() - - tbar := gi.AddNewToolBar(mfr, "tbar") - tbar.SetStretchMaxWidth() - ss.ToolBar = tbar - - split := gi.AddNewSplitView(mfr, "split") - split.Dim = mat32.X - split.SetStretchMax() - - sv := giv.AddNewStructView(split, "sv") + split := gi.NewSplits(b, "split") + sv := giv.NewStructView(split, "sv") sv.SetStruct(ss) - tv := gi.AddNewTabView(split, "tv") + tv := gi.NewTabs(split, "tv") - plt := tv.AddNewTab(eplot.KiT_Plot2D, "T Exp Plot").(*eplot.Plot2D) - ss.Plot = ss.ConfigPlot(plt, ss.Table) + ss.Plot = eplot.NewSubPlot(tv.NewTab("T Exp Plot")) + ss.ConfigPlot(ss.Plot, ss.Table) - plt = tv.AddNewTab(eplot.KiT_Plot2D, "TimePlot").(*eplot.Plot2D) - ss.TimePlot = ss.ConfigTimePlot(plt, ss.TimeTable) + ss.TimePlot = eplot.NewSubPlot(tv.NewTab("TimePlot")) + ss.ConfigTimePlot(ss.TimePlot, ss.TimeTable) split.SetSplits(.3, .7) - tbar.AddAction(gi.ActOpts{Label: "T Exp Run", Icon: "update", Tooltip: "Run the equations and plot results."}, win.This(), func(recv, send ki.Ki, sig int64, data interface{}) { - ss.Run() - vp.SetNeedsFullRender() - }) - - tbar.AddAction(gi.ActOpts{Label: "Time Run", Icon: "update", Tooltip: "Run the equations and plot results."}, win.This(), func(recv, send ki.Ki, sig int64, data interface{}) { - ss.TimeRun() - vp.SetNeedsFullRender() + b.AddAppBar(func(tb *gi.Toolbar) { + giv.NewFuncButton(tb, ss.Run).SetIcon(icons.PlayArrow) + giv.NewFuncButton(tb, ss.TimeRun).SetIcon(icons.PlayArrow) }) - 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/emer/axon/blob/master/chans/synca_plot/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) - - win.MainMenuUpdated() - return win + return b }