Source code for sbmlsim.simulator.rr_simulator_abstract

"""Classes for running simulations with SBML models."""
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Any, Iterator, List

import pandas as pd
from sbmlutils import log

from sbmlsim.simulation import ScanSim, TimecourseSim
from sbmlsim.xresult import XResult

# TODO: handle unit information
# from pint import Quantity
# from sbmlsim.units import UnitsInformation

[docs]logger = log.get_logger(__name__)
[docs]class SimulatorAbstractRR(ABC): """Abstract base class for roadrunner simulator.""" @staticmethod
[docs] def from_sbml(self, sbml_path: Path) -> Any: """Set model from SBML.""" raise NotImplementedError
[docs] def set_model(self, model_state: str) -> None: """Set model from state.""" pass
[docs] def set_timecourse_selections(self, selections: Iterator[str]) -> None: """Set timecourse selections.""" pass
[docs] def set_integrator_settings(self, **kwargs) -> None: """Set integrator settings.""" pass
[docs] def _run_timecourses(self, simulations: List[TimecourseSim]) -> List[pd.DataFrame]: """Execute timecourse simulations.""" pass
[docs] def run_timecourse(self, simulation: TimecourseSim) -> XResult: """Run single timecourse.""" if not isinstance(simulation, TimecourseSim): raise ValueError( f"'run_timecourse' requires TimecourseSim, but " f"'{type(simulation)}'" ) scan = ScanSim(simulation=simulation) return self.run_scan(scan)
[docs] def run_scan(self, scan: ScanSim) -> XResult: """Run scan simulation.""" # normalize the scan (simulation and dimensions) # FIXME: units # scan.normalize(uinfo=self.uinfo) # create all possible combinations of the scan indices, simulations = scan.to_simulations() # simulate (uses respective function of simulator) dfs = self._run_timecourses(simulations) # based on the indices the result structure must be created # FIXME: units # return XResult.from_dfs(dfs=dfs, scan=scan, uinfo=self.uinfo) return XResult.from_dfs(dfs=dfs, scan=scan)