Skip to content

Commit

Permalink
#33 : add missing simulation method
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergmann committed Jun 9, 2023
1 parent 456b953 commit da63f74
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
5 changes: 3 additions & 2 deletions basico/task_timecourse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions tests/test_timecourse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit da63f74

Please sign in to comment.