Hack to select simulations to plot via bamboost - tui
We will need a cleaner and more modular implementation (e.g. key bindings via config file), but this is a starting point.
import subprocess
import pyperclip as pc
from typing import Callable
import argparse
import urwid
parser = argparse.ArgumentParser(
description=("creates dataset following the readme template"))
parser.add_argument("--uid", )
args = parser.parse_args()
if args.uid is None:
from bamboostcli.app import enter_main_loop, WelcomeUI
from bamboostcli.pages.db import Database
from functools import wraps
# Monkey patch the key actions
def _extend_init(original_init: Callable):
@wraps(original_init)
def modified_init(self: Database, *args, **kwargs) -> None:
print("calling modified init")
def open_sim():
id = self.table._get_entry_in_focus()["id"]
full_id = self.db[id].get_full_uid()
subprocess.Popen(["python3", __file__, "--uid", full_id])
self.container.footer = urwid.Text(("footer", f"opened interactive view of <{full_id}>"))
self.open_sim = open_sim
original_init(self, *args, **kwargs)
# raise AssertionError
self.keybinds["ctrl o"] = (self.open_sim, "Interactive bond break view", [])
self._keybinds = {key: func for key, (func, _, _) in self.keybinds.items()}
self._keybinds.update(
{alias: func for func, _, aliases in self.keybinds.values() for alias in aliases}
)
return modified_init
print("test stdout")
Database.__init__ = _extend_init(Database.__init__)
enter_main_loop(WelcomeUI().frame)
import bamboost
import bamboost.extensions.remote_manager
from Visualisation.plot_pyvista import InteractiveForcePlotWithChartBondbreak, InteractiveForcePlot, pyvista
# InteractiveForcePlot
sim = bamboost.Simulation.fromUID(args.uid)
print(sim.globals["stretch"][:])
ip = InteractiveForcePlotWithChartBondbreak(sim,plotter=pyvista.Plotter(),
period_filter_length=2, show_chart=True, wireframe_style="force",
chart_xy=[sim.globals["stretch"][:], -sim.globals["pressure"][:]])
ip.plotter.camera_position = "xy"
ip.plotter.show(window_size=(16*140, 9*140),)