From da63f74be071aac2eb73dc0bf1ee999a559f3ae6 Mon Sep 17 00:00:00 2001 From: "Frank T. Bergmann" Date: Fri, 9 Jun 2023 11:52:30 +0200 Subject: [PATCH] #33 : add missing simulation method --- basico/task_timecourse.py | 5 +++-- tests/test_timecourse.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/basico/task_timecourse.py b/basico/task_timecourse.py index ffd0a00..cf26d89 100644 --- a/basico/task_timecourse.py +++ b/basico/task_timecourse.py @@ -75,6 +75,7 @@ def __method_name_to_type(method_name): methods = { 'deterministic': COPASI.CTaskEnum.Method_deterministic, 'lsoda': COPASI.CTaskEnum.Method_deterministic, + 'hybrid': COPASI.CTaskEnum.Method_hybrid, 'hybridode45': COPASI.CTaskEnum.Method_hybridODE45, 'hybridlsoda': COPASI.CTaskEnum.Method_hybridLSODA, 'adaptivesa': COPASI.CTaskEnum.Method_adaptiveSA, @@ -117,7 +118,7 @@ def run_time_course_with_output(output_selection, *args, **kwargs): | * `deterministic` / `lsoda`: the LSODA implementation | * `stochastic`: the Gibson & Bruck Gillespie implementation | * `directMethod`: Gillespie Direct Method - | * others: `hybridode45`, `hybridlsoda`, `adaptivesa`, `tauleap`, `radau5`, `sde` + | * others: `hybrid`, `hybridode45`, `hybridlsoda`, `adaptivesa`, `tauleap`, `radau5`, `sde` - `duration` (float): the duration in time units for how long to simulate @@ -273,7 +274,7 @@ def run_time_course(*args, **kwargs): | * `deterministic` / `lsoda`: the LSODA implementation | * `stochastic`: the Gibson & Bruck Gillespie implementation | * `directMethod`: Gillespie Direct Method - | * others: `hybridode45`, `hybridlsoda`, `adaptivesa`, `tauleap`, `radau5`, `sde` + | * others: `hybrid`, `hybridode45`, `hybridlsoda`, `adaptivesa`, `tauleap`, `radau5`, `sde` - `duration` (float): the duration in time units for how long to simulate diff --git a/tests/test_timecourse.py b/tests/test_timecourse.py index a5e6089..286a2c2 100644 --- a/tests/test_timecourse.py +++ b/tests/test_timecourse.py @@ -14,6 +14,35 @@ def test_custom_output(self): self.assertIsNotNone(tc) self.assertListEqual(tc.columns.to_list(), ['Time', '[S1]', '[S2]', 'Values[k1]']) + def test_stochastic(self): + basico.new_model(name='Simple Model') + basico.add_reaction('R1', 'A ->') + basico.add_reaction('R2', 'B -> B + C') + basico.set_species('A', initial_particle_number=50) + basico.set_species('B', initial_particle_number=10) + basico.set_species('C', initial_particle_number=0) + basico.set_reaction_parameters('(R1).k1', value=1) + basico.set_reaction_parameters('(R2).k1', value=1) + basico.add_event('E1', 'A <= 10', [('B', '50')]) + result = basico.run_time_course(duration=10, method='stochastic', use_numbers=True) + self.assertIsNotNone(result) + + # test that we can set hybrid methods + result = basico.run_time_course(duration=1, method='hybrid', use_numbers=True) + self.assertIsNotNone(result) + settings = basico.get_task_settings(basico.T.TIME_COURSE) + self.assertEqual(settings['method']['name'], 'Hybrid (Runge-Kutta)') + + def test_stoch2(self): + basico.new_model(name='Simple Model', substance_unit='1') + basico.add_reaction('R1', 'A ->') + basico.set_species('A', initial_particle_number=50) + basico.set_reaction_parameters('(R1).k1', value=1) + basico.add_event('E1', 'A.ParticleNumber <= 1', [('A.ParticleNumber', '50')]) + + result = basico.run_time_course(duration=20, method='directMethod', use_numbers=True) + self.assertIsNotNone(result) + if __name__ == '__main__': unittest.main()