Skip to content

Commit

Permalink
#18 : add support for global variables in custom output on time courses
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergmann committed Apr 5, 2022
1 parent 818b8fa commit 0a01bde
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
2 changes: 1 addition & 1 deletion basico/task_timecourse.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def create_data_handler(output_selection, during=None, after=None, before=None,
logging.warning('no object for name {0}'.format(name))
continue

if isinstance(obj, COPASI.CModel):
if obj.getObjectType() != 'Reference':
obj = obj.getValueReference()

cn = obj.getCN().getString()
Expand Down
47 changes: 47 additions & 0 deletions tests/tellurium_sim.sbml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level3/version1/core" level="3" version="1">
<model metaid="__main" id="__main">
<listOfCompartments>
<compartment sboTerm="SBO:0000410" id="default_compartment" spatialDimensions="3" size="1" constant="true"/>
</listOfCompartments>
<listOfSpecies>
<species id="S1" compartment="default_compartment" initialAmount="0" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false"/>
<species id="S2" compartment="default_compartment" initialAmount="0" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false"/>
</listOfSpecies>
<listOfParameters>
<parameter id="k1" value="0" constant="false"/>
</listOfParameters>
<listOfReactions>
<reaction id="_J0" reversible="true" fast="false">
<listOfProducts>
<speciesReference species="S2" stoichiometry="1" constant="true"/>
</listOfProducts>
<kineticLaw>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<ci> k1 </ci>
</math>
</kineticLaw>
</reaction>
</listOfReactions>
<listOfEvents>
<event id="_E0" useValuesFromTriggerTime="true">
<trigger initialValue="false" persistent="true">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply>
<gt/>
<ci> S1 </ci>
<cn type="integer"> 1 </cn>
</apply>
</math>
</trigger>
<listOfEventAssignments>
<eventAssignment variable="k1">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<cn type="integer"> 1 </cn>
</math>
</eventAssignment>
</listOfEventAssignments>
</event>
</listOfEvents>
</model>
</sbml>
2 changes: 1 addition & 1 deletion tests/test_parameterestimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_get_data(self):
@unittest.skipIf(sys.version_info < (3, 6, 0), 'This test requires assertLogs which is not available before')
def test_change_bounds(self):
basico.set_fit_parameters([{'name': '(R1).k2', 'lower': 1, 'upper': 0.01}])
with self.assertLogs(level='ERROR') as cm:
with self.assertLogs(level='ERROR') as _:
sol = basico.as_dict(basico.run_parameter_estimation())
self.assertTrue(np.isnan(sol['sol']))

Expand Down
19 changes: 19 additions & 0 deletions tests/test_timecourse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import unittest
import basico
import os

THIS_DIR = os.path.dirname(__file__)


class TestTimeCourse(unittest.TestCase):
def setUp(self):
basico.load_model(os.path.join(THIS_DIR, 'tellurium_sim.sbml'))

def test_custom_output(self):
tc = basico.run_time_course_with_output(['Time', '[S1]', '[S2]', 'Values[k1]'], 0, 5, 5)
self.assertIsNotNone(tc)
self.assertListEqual(tc.columns.to_list(), ['Time', '[S1]', '[S2]', 'Values[k1]'])


if __name__ == '__main__':
unittest.main()

0 comments on commit 0a01bde

Please sign in to comment.