Skip to content

Commit

Permalink
feat: updated and added amici process
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPatrie committed May 26, 2024
1 parent 5b255bc commit 06419c8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion biosimulator_processes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
('amici', 'amici_process.AmiciProcess')]

STEPS_TO_REGISTER = [
# ('get_sbml_step', 'get_sbml.GetSbmlStep'),
('copasi-step', 'ode_simulation.CopasiStep'),
('tellurium-step', 'ode_simulation.CopasiStep'),
('plotter', 'viz.CompositionPlotter'),
('plotter2d', 'viz.Plotter2d')]

Expand Down
52 changes: 49 additions & 3 deletions biosimulator_processes/steps/ode_simulation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import abc
import logging

from process_bigraph import Step
from process_bigraph.experiments.parameter_scan import RunProcess
Expand Down Expand Up @@ -51,7 +52,9 @@ def __init__(self, sbml_filepath: str = None, time_config: dict[str, float] = No
self.num_steps = time_config.get('num_steps')
self.duration = time_config.get('duration')
self._set_time_params()

super().__init__(config=configuration, core=core)

self.simulator = self._set_simulator(sbml_filepath)
self.floating_species_ids = self._get_floating_species_ids()
self.t = [float(n) for n in range(self.duration)]
Expand Down Expand Up @@ -119,8 +122,8 @@ def update(self, inputs):
class CopasiStep(OdeSimulation):
def __init__(self, sbml_filepath, time_config: dict[str, float], config=None, core=CORE):
super().__init__(sbml_filepath, time_config, config, core)
self.simulator = self._set_simulator(self.config['sbml_filepath'])
self.floating_species_ids = self._get_floating_species_ids()
# self.simulator = self._set_simulator(self.config['sbml_filepath'])
# self.floating_species_ids = self._get_floating_species_ids()

def _set_simulator(self, sbml_fp: str) -> object:
return load_model(sbml_fp)
Expand Down Expand Up @@ -153,7 +156,7 @@ def update(self, inputs):
class TelluriumStep(OdeSimulation):
def __init__(self, sbml_filepath, time_config: dict[str, float], config=None, core=CORE):
super().__init__(sbml_filepath, time_config, config, core)
self.simulator = self._set_simulator(sbml_filepath)
# self.simulator = self._set_simulator(sbml_filepath)

def _set_simulator(self, sbml_fp) -> object:
return te.loadSBMLModel(sbml_fp)
Expand All @@ -175,6 +178,49 @@ def update(self, inputs):
return results


class AmiciStep(OdeSimulation):
def __init__(self, sbml_filepath, time_config: dict[str, float], model_dir: str, config=None, core=CORE):
super().__init__(sbml_filepath, time_config, config, core)
self.simulator = self._set_simulator(sbml_filepath, model_dir)

def _set_simulator(self, sbml_fp, model_dir) -> amici.Model:
# get and compile libsbml model from fp
sbml_reader = libsbml.SBMLReader()
sbml_doc = sbml_reader.readSBML(model_fp)
self.sbml_model_object: libsbml.Model = sbml_doc.getModel()

# get model args from config
model_id = self.config['model'].get('model_id', None) \
or sbml_fp.split('/')[-1].replace('.', '_').split('_')[0]

model_output_dir = model_dir

# compile sbml to amici
sbml_importer = SbmlImporter(sbml_fp)
sbml_importer.sbml2amici(
model_name=model_id,
output_dir=model_output_dir,
verbose=logging.INFO)
# observables=self.config.get('observables'),
# constant_parameters=self.config.get('constant_parameters'),
# sigmas=self.config.get('sigmas'))
model_module = import_model_module(model_id, model_output_dir)

return model_module.getModel()

def _get_floating_species_ids(self) -> list[str]:
return self.simulator.getObservableIds()

def update(self, inputs):
results = {'time': self.t}
results['floating_species'] = {
mol_id: float(self.simulator.getValue(mol_id))
for mol_id in self.floating_species_list
}

return results



class ODEProcess(RunProcess):
def __init__(self,
Expand Down

0 comments on commit 06419c8

Please sign in to comment.