diff --git a/pyproject.toml b/pyproject.toml index c3bd56c..cd02beb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,9 @@ dependencies = [ "python-libsbml", "matplotlib", "petab", - "qtawesome" + "qtawesome", + "copasi-basico", + "copasi-petab-importer" ] [build-system] diff --git a/src/petab_gui/controllers/mother_controller.py b/src/petab_gui/controllers/mother_controller.py index e8957df..db3d302 100644 --- a/src/petab_gui/controllers/mother_controller.py +++ b/src/petab_gui/controllers/mother_controller.py @@ -339,6 +339,12 @@ def setup_actions(self): # Recent Files actions["recent_files"] = self.recent_files_manager.tool_bar_menu + # simulate action + actions["simulate"] = QAction( + qta.icon("mdi6.play"), "Simulate", self.view + ) + actions["simulate"].triggered.connect(self.simulate) + # Filter widget filter_widget = QWidget() filter_layout = QHBoxLayout() @@ -930,6 +936,34 @@ def _on_simulation_selection_changed(self, selected, deselected): y_axis_col="simulation" ) + def simulate(self): + """Simulate the model.""" + # obtain petab problem + petab_problem = self.model.current_petab_problem + + # import petabsimualtor + from basico.petab import PetabSimulator + import basico + + # report current basico / COPASI version + self.logger.log_message(f"Simulate with basico: {basico.__version__}, COPASI: {basico.COPASI.__version__}", color="green") + + import tempfile + + # create temp directory in temp folder: + with tempfile.TemporaryDirectory() as temp_dir: + # settings is only current solution statistic for now: + settings = {'method' : {'name': basico.PE.CURRENT_SOLUTION}} + # create simulator + simulator = PetabSimulator(petab_problem, settings=settings, working_dir=temp_dir) + + # simulate + sim_df = simulator.simulate() + + # assign to simulation table + self.simulation_controller.overwrite_df(sim_df) + self.simulation_controller.model.reset_invalid_cells() + def _schedule_plot_update(self): """Start the plot schedule timer.""" self._plot_update_timer.start() diff --git a/src/petab_gui/views/main_view.py b/src/petab_gui/views/main_view.py index 8c5da4a..54206e1 100644 --- a/src/petab_gui/views/main_view.py +++ b/src/petab_gui/views/main_view.py @@ -180,6 +180,7 @@ def setup_toolbar(self, actions): tb.addAction(actions["delete_row"]) tb.addAction(actions["add_column"]) tb.addAction(actions["delete_column"]) + tb.addAction(actions["simulate"]) tb.addWidget(spacer) tb.addWidget(actions["filter_widget"]) diff --git a/src/petab_gui/views/task_bar.py b/src/petab_gui/views/task_bar.py index 8d910b8..1145ed5 100644 --- a/src/petab_gui/views/task_bar.py +++ b/src/petab_gui/views/task_bar.py @@ -91,6 +91,7 @@ def __init__(self, parent, actions): self.menu.addSeparator() # Reset Model self.menu.addAction(actions["reset_model"]) + self.menu.addAction(actions["simulate"]) self.menu.addSeparator() # Settings self.menu.addAction(actions["settings"])