def run_case(call_file, antimony_str, phrasedml_str, py_code=False, working_dir=None): """ Run one of the example phrasedml cases. :param case_id: :param antimony_str: :param phrasedml_str: :return: """ # run as omex # FIXME: convert to combine archive inline_omex = '\n'.join([antimony_str, phrasedml_str]) # output dir relative to call file if not working_dir: working_dir = os.path.join(os.path.dirname(call_file), './results') if not os.path.exists(working_dir): os.makedirs(working_dir) # FIXME: not working # write python code if py_code: fname = os.path.basename(call_file) py_file = os.path.join(working_dir, fname + 'code.py') print(py_file) with open(py_file, 'w') as f: f.write(exp._toPython(phrasedml_str, workingDir=working_dir)) # execute python te.executeInlineOmex(inline_omex)
def test_repressilatorToInlineOmex(self): importer = convert_omex.inlineOmexImporter.fromFile(OMEX_REPRESSILATOR) assert importer is not None inline_omex = importer.toInlineOmex() assert inline_omex is not None print(inline_omex) te.executeInlineOmex(inline_omex)
def test_kisao_rk45_2(self): p = """ model0 = model "m1" sim0 = simulate uniform(0, 10, 100) sim0.algorithm = kisao.435 task0 = run sim0 on model0 plot task0.time vs task0.S1 """ inline_omex = '\n'.join([self.a1, p]) self.checkKisaoIntegrator(inline_omex, 'KISAO:0000435', 'rk45') te.executeInlineOmex(inline_omex)
def test_kisao_gillespie_3(self): """ Default of uniform_stochastic is gillespie.""" p = """ model0 = model "m1" sim0 = simulate uniform_stochastic(0, 10, 100) task0 = run sim0 on model0 plot task0.time vs task0.S1 """ inline_omex = '\n'.join([self.a1, p]) self.checkKisaoIntegrator(inline_omex, 'KISAO:0000241', 'gillespie') te.executeInlineOmex(inline_omex)
def test_kisao_cvode_4(self): """ Default of onestep is cvode. """ p = """ model0 = model "m1" sim0 = simulate onestep(10) task0 = run sim0 on model0 plot task0.time vs task0.S1 """ inline_omex = '\n'.join([self.a1, p]) self.checkKisaoIntegrator(inline_omex, 'KISAO:0000019', 'cvode') te.executeInlineOmex(inline_omex)
def test_kisao_variable_step_size_2(self): p = """ model0 = model "m1" sim0 = simulate uniform(0, 10, 100) sim0.algorithm.107 = true task0 = run sim0 on model0 plot task0.time vs task0.S1 """ inline_omex = '\n'.join([self.a1, p]) self.checkKisaoAlgorithmParameter(inline_omex, 'KISAO:0000107', 'variable_step_size', True) te.executeInlineOmex(inline_omex)
def test_kisao_gillespie_1(self): p = """ model0 = model "m1" sim0 = simulate uniform(0, 10, 100) sim0.algorithm = gillespie task0 = run sim0 on model0 plot task0.time vs task0.S1 """ inline_omex = '\n'.join([self.a1, p]) self.checkKisaoIntegrator(inline_omex, 'KISAO:0000241', 'gillespie') te.executeInlineOmex(inline_omex)
def test_kisao_initial_time_step_2(self): p = """ model0 = model "m1" sim0 = simulate uniform(0, 10, 100) sim0.algorithm.332 = 0.01 task0 = run sim0 on model0 plot task0.time vs task0.S1 """ inline_omex = '\n'.join([self.a1, p]) self.checkKisaoAlgorithmParameter(inline_omex, 'KISAO:0000332', 'initial_time_step', 0.01) te.executeInlineOmex(inline_omex)
def test_kisao_absolute_tolerance_2(self): p = """ model0 = model "m1" sim0 = simulate uniform(0, 10, 100) sim0.algorithm.211 = 1E-8 task0 = run sim0 on model0 plot task0.time vs task0.S1 """ inline_omex = '\n'.join([self.a1, p]) self.checkKisaoAlgorithmParameter(inline_omex, 'KISAO:0000211', 'absolute_tolerance', 1E-8) te.executeInlineOmex(inline_omex)
def test_kisao_maximum_adams_order_2(self): p = """ model0 = model "m1" sim0 = simulate uniform(0, 10, 100) sim0.algorithm.219 = 5 task0 = run sim0 on model0 plot task0.time vs task0.S1 """ inline_omex = '\n'.join([self.a1, p]) self.checkKisaoAlgorithmParameter(inline_omex, 'KISAO:0000219', 'maximum_adams_order', 5) te.executeInlineOmex(inline_omex)
def test_kisao_minimum_time_step_2(self): p = """ model0 = model "m1" sim0 = simulate uniform(0, 10, 100) sim0.algorithm.485 = 1E-6 task0 = run sim0 on model0 plot task0.time vs task0.S1 """ inline_omex = '\n'.join([self.a1, p]) self.checkKisaoAlgorithmParameter(inline_omex, 'KISAO:0000485', 'minimum_time_step', 1E-6) te.executeInlineOmex(inline_omex)
def test_kisao_maximum_num_steps_1(self): p = """ model0 = model "m1" sim0 = simulate uniform(0, 10, 100) sim0.algorithm.maximum_num_steps = 10000 task0 = run sim0 on model0 plot task0.time vs task0.S1 """ inline_omex = '\n'.join([self.a1, p]) self.checkKisaoAlgorithmParameter(inline_omex, 'KISAO:0000415', 'maximum_num_steps', 10000) te.executeInlineOmex(inline_omex)
def test_kisao_minimum_damping_2(self): p = """ model0 = model "m1" sim0 = simulate steadystate sim0.algorithm.487 = 1 task0 = run sim0 on model0 plot task0.time vs task0.S1 """ inline_omex = '\n'.join([self.a1, p]) self.checkKisaoAlgorithmParameter(inline_omex, 'KISAO:0000487', 'minimum_damping', 1.0) te.executeInlineOmex(inline_omex)
def test_kisao_maximum_iterations_2(self): p = """ model0 = model "m1" sim0 = simulate steadystate sim0.algorithm.486 = 10 task0 = run sim0 on model0 plot task0.time vs task0.S1 """ inline_omex = '\n'.join([self.a1, p]) self.checkKisaoAlgorithmParameter(inline_omex, 'KISAO:0000486', 'maximum_iterations', 10) te.executeInlineOmex(inline_omex)
def test_kisao_seed_2(self): p = """ model0 = model "m1" sim0 = simulate uniform_stochastic(0, 10, 100) sim0.algorithm.488 = 1234 task0 = run sim0 on model0 plot task0.time vs task0.S1 """ inline_omex = '\n'.join([self.a1, p]) self.checkKisaoAlgorithmParameter(inline_omex, 'KISAO:0000488', 'seed', 1234) te.executeInlineOmex(inline_omex)
def test_2Model1PhrasedML(self): """ Test multiple models and multiple phrasedml files. """ p1 = """ model1 = model "m1" model2 = model "m2" model3 = model model1 with S1=S2+20 sim1 = simulate uniform(0, 6, 100) task1 = run sim1 on model1 task2 = run sim1 on model2 plot "Timecourse test1" task1.time vs task1.S1, task1.S2 plot "Timecourse test2" task2.time vs task2.X1, task2.X2 """ inline_omex = '\n'.join([self.a1, self.a2, p1]) te.executeInlineOmex(inline_omex)
def test_1Model1PhrasedML(self): """ Minimal example which should work. """ antimony_str = """ model test J0: S1 -> S2; k1*S1; S1 = 10.0; S2=0.0; k1 = 0.1; end """ phrasedml_str = """ model0 = model "test" sim0 = simulate uniform(0, 10, 100) task0 = run sim0 on model0 plot task0.time vs task0.S1 """ inline_omex = '\n'.join([antimony_str, phrasedml_str]) te.executeInlineOmex(inline_omex)
def test_kisao_adams(self): p = """ model0 = model "m1" sim0 = simulate uniform(0, 10, 100) sim0.algorithm = nonstiff task0 = run sim0 on model0 plot task0.time vs task0.S1 """ inline_omex = '\n'.join([self.a1, p]) self.checkKisaoIntegrator(inline_omex, 'KISAO:0000280', 'cvode') te.executeInlineOmex(inline_omex) omex_file = os.path.join(self.test_dir, "test.omex") te.exportInlineOmex(inline_omex, omex_file) pycode_dict = tesedml.combineArchiveToPython(omex_file) pycode = six.next(six.itervalues(pycode_dict)) print(pycode) self.assertTrue("integrator.setValue('stiff', False)" in pycode)
def test_2Model2PhrasedML(self): """ Test multiple models and multiple phrasedml files. """ p1 = """ model1 = model "m1" model2 = model "m2" sim1 = simulate uniform(0, 6, 100) task1 = run sim1 on model1 task2 = run sim1 on model2 plot task1.time vs task1.S1, task1.S2, task2.time vs task2.X1, task2.X2 """ p2 = """ model1 = model "m1" model2 = model "m2" sim1 = simulate uniform(0, 20, 20) task1 = run sim1 on model1 task2 = run sim1 on model2 plot task1.time vs task1.S1, task1.S2, task2.time vs task2.X1, task2.X2 """ inline_omex = '\n'.join([self.a1, self.a2, p1, p2]) te.executeInlineOmex(inline_omex)
def export_omex(self, antimony_str, phrasedml_str, **kwargs): """Generate COMBINE OMEX file. Parameters: antimony_str: represent the SBML phrasedml_str: represent the SEDML Returns: execute the omex and export omex archive """ model = re.search("model (.*)\n", antimony_str) if model.group(1)[0] == "*": model = self.find_between(model.group(1), "*", "()") phrasedml_str = phrasedml_str.format(model) else: phrasedml_str = phrasedml_str.format(model.group(1)) inline_omex = "\n".join([antimony_str, phrasedml_str]) if "outputfile" in kwargs: filepath = kwargs["outputfile"] else: dirName = self.getOMEXfilename() try: os.mkdir(dirName) print("Directory ", dirName, " Created ") except FileExistsError: print("Directory ", dirName, " already exists") workingDir = os.path.join(self.workingdir0, dirName) filepath = os.path.join(workingDir, "archive.omex") print("The output file path: ", filepath) te.exportInlineOmex(inline_omex, filepath) return inline_omex, te.executeInlineOmex(inline_omex)
def test_1Model2PhrasedML(self): """ Test multiple models and multiple phrasedml files. """ p1 = """ model1 = model "m1" sim1 = simulate uniform(0, 6, 100) task1 = run sim1 on model1 plot task1.time vs task1.S1, task1.S2 """ p2 = """ model1 = model "m1" model2 = model model1 with S1=S2+20 sim1 = simulate uniform(0, 6, 100) task1 = run sim1 on model2 plot task1.time vs task1.S1, task1.S2 """ inline_omex = '\n'.join([self.a1, p1]) te.executeInlineOmex(inline_omex) inline_omex = '\n'.join([self.a1, p2]) te.executeInlineOmex(inline_omex) inline_omex = '\n'.join([self.a1, p1, p2]) te.executeInlineOmex(inline_omex)
def test_execute(self): """Test execute.""" inline_omex = '\n'.join([self.antimony, self.phrasedml]) te.executeInlineOmex(inline_omex)
def execute_inlineomex(inline_omex): """Execute the inline omex and generate the simulation figures. """ return te.executeInlineOmex(inline_omex)
model myModel S1 -> S2; k1*S1 S1 = 10; S2 = 0 k1 = 1 end ''' phrasedml_str = ''' model1 = model "myModel" sim1 = simulate uniform(0, 5, 100) task1 = run sim1 on model1 plot "Figure 1" time vs S1, S2 ''' # create an inline OMEX (inline representation of a COMBINE archive) # from the antimony and phrasedml strings inline_omex = '\n'.join([antimony_str, phrasedml_str]) # execute the inline OMEX te.executeInlineOmex(inline_omex) # export to a COMBINE archive workingDir = tempfile.mkdtemp(suffix="_omex") te.exportInlineOmex(inline_omex, os.path.join(workingDir, 'archive.omex')) # In[2]: te.executeCombineArchive(os.path.join(workingDir, 'archive.omex'))
get_ipython().magic(u'matplotlib inline') antimony_str = ''' model myModel S1 -> S2; k1*S1 S1 = 10; S2 = 0 k1 = 1 end ''' phrasedml_str = ''' model1 = model "myModel" sim1 = simulate uniform(0, 5, 100) task1 = run sim1 on model1 plot "Figure 1" time vs S1, S2 ''' # create an inline OMEX (inline representation of a COMBINE archive) # from the antimony and phrasedml strings inline_omex = '\n'.join([antimony_str, phrasedml_str]) # execute the inline OMEX te.executeInlineOmex(inline_omex) # export to a COMBINE archive workingDir = tempfile.mkdtemp(suffix="_omex") te.exportInlineOmex(inline_omex, os.path.join(workingDir, 'archive.omex')) # In[2]: te.executeCombineArchive(os.path.join(workingDir, 'archive.omex'))