Exemplo n.º 1
0
    def writingAndReadingExecution(self):

        antimonyStr = '''
        model myModel
          S1 -> S2; k1*S1;
          S1 = 10; S2 = 0;
          k1 = 1;
        end
        '''
        phrasedmlStr = '''
          model1 = model "myModel"
          sim1 = simulate uniform(0, 5, 100)
          task1 = run sim1 on model1
          plot "Figure 1" time vs S1, S2
          report time vs S1, S2
        '''
        import tellurium as te

        # Create experiment
        exp = te.experiment(antimonyStr, phrasedmlStr)
        # Run and store with results
        tmpdir = tempfile.mkdtemp()
        exp.exportAsCombineWithOutputs(os.path.join(tmpdir, 'test.omex'))
        # Execute the created archive
        te.executeOMEX('test.omex', workingDir=tmpdir)
        shutil.rmtree(tmpdir)
 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
     """
     exp = te.experiment([self.a1, self.a2], [p1, p2])
     # execute first
     exp.execute(p1)
     # execute second
     exp.execute(p2)
     # execute all
     exp.execute()
Exemplo n.º 3
0
    def setUp(self):
        # create a test instance
        self.antimony = '''
        model myModel
          S1 -> S2; k1*S1
          S1 = 10; S2 = 0
          k1 = 1
        end
        '''
        self.newAntimony = '''
        model newAntimony
          S1 -> S2; k1*S1
          S1 = 10; S2 = 0
          k1 = 1
        end
        '''
        self.phrasedml = '''
          model1 = model "myModel"
          sim1 = simulate uniform(0, 5, 100)
          task1 = run sim1 on model1
          plot "Figure 1" time vs S1, S2
        '''
        self.newPhrasedml = '''
          model1 = model "newAntimony"
          sim1 = simulate uniform(0, 10, 100)
          task1 = run sim1 on model1
          plot "Figure 1" time vs S1, S2
        '''
        exp = te.experiment(self.antimony, self.phrasedml)

        self.tmpdir = tempfile.mkdtemp()
        self.tmparchive = os.path.join(self.tmpdir, 'test.zip')

        exp.exportAsCombine(self.tmparchive)
        self.com = te.combine(self.tmparchive)
def run_case(call_file, antimonyStr, phrasedmlStr, py_code=True):
    """ Run one of the example phrasedml cases.

    :param case_id:
    :param antimonyStr:
    :param phrasedmlStr:
    :return:
    """
    # phrasedml experiment
    exp = te.experiment(antimonyStr, phrasedmlStr)

    # output dir relative to call file
    workingDir = os.path.join(os.path.dirname(call_file), './results')
    if not os.path.exists(workingDir):
        os.makedirs(workingDir)

    # write python code

    if py_code:
        fname = os.path.basename(call_file)
        py_file = os.path.join(workingDir, fname + 'code.py')
        print(py_file)
        with open(py_file, 'w') as f:
            f.write(exp._toPython(phrasedmlStr, workingDir=workingDir))

    # execute python
    exp.execute(phrasedmlStr, workingDir=workingDir)
 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
     """
     exp = te.experiment(self.a1, p)
     self.checkKisaoAlgorithmParameter(exp, 'KISAO:0000219', 'maximum_adams_order', 5)
     exp.execute()
 def test_kisao_minimum_damping_1(self):
     p = """
         model0 = model "m1"
         sim0 = simulate steadystate
         sim0.algorithm.minimum_damping = 1.0
         task0 = run sim0 on model0
         plot task0.time vs task0.S1
     """
     exp = te.experiment(self.a1, p)
     self.checkKisaoAlgorithmParameter(exp, 'KISAO:0000487', 'minimum_damping', 1.0)
     exp.execute()
 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
     """
     exp = te.experiment(self.a1, p)
     self.checkKisaoAlgorithmParameter(exp, 'KISAO:0000107', 'variable_step_size', True)
     exp.execute()
 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
     """
     exp = te.experiment(self.a1, p)
     self.checkKisaoAlgorithmParameter(exp, 'KISAO:0000486', 'maximum_iterations', 10)
     exp.execute()
 def test_kisao_minimum_time_step_2(self):
     p = """
         model0 = model "m1"
         sim0 = simulate uniform(0, 10, 100)
         sim0.algorithm.485 = 1E-5
         task0 = run sim0 on model0
         plot task0.time vs task0.S1
     """
     exp = te.experiment(self.a1, p)
     self.checkKisaoAlgorithmParameter(exp, 'KISAO:0000485', 'minimum_time_step', 1E-5)
     exp.execute()
 def test_exportAsCombine(self):
     """ Test exportAsCombine. """
     exp = te.experiment(self.antimony, self.phrasedml)
     tmpdir = tempfile.mkdtemp()
     tmparchive = os.path.join(tmpdir, 'test.zip')
     exp.exportAsCombine(tmparchive)
     # try to re
     import zipfile
     zip = zipfile.ZipFile(tmparchive)
     zip.close()
     shutil.rmtree(tmpdir)
 def test_kisao_maximum_num_steps_2(self):
     p = """
         model0 = model "m1"
         sim0 = simulate uniform(0, 10, 100)
         sim0.algorithm.415 = 10000
         task0 = run sim0 on model0
         plot task0.time vs task0.S1
     """
     exp = te.experiment(self.a1, p)
     self.checkKisaoAlgorithmParameter(exp, 'KISAO:0000415', 'maximum_num_steps', 10000)
     exp.execute()
 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
     """
     exp = te.experiment(self.a1, p)
     self.checkKisaoIntegrator(exp, 'KISAO:0000241', 'gillespie')
     exp.execute()
 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
     """
     exp = te.experiment(self.a1, p)
     self.checkKisaoAlgorithmParameter(exp, 'KISAO:0000211', 'absolute_tolerance', 1E-8)
     exp.execute()
 def test_kisao_rk4_2(self):
     p = """
         model0 = model "m1"
         sim0 = simulate uniform(0, 10, 100)
         sim0.algorithm = kisao.32
         task0 = run sim0 on model0
         plot task0.time vs task0.S1
     """
     exp = te.experiment(self.a1, p)
     self.checkKisaoIntegrator(exp, 'KISAO:0000032', 'rk4')
     exp.execute()
 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
     """
     exp = te.experiment(self.a1, p)
     self.checkKisaoIntegrator(exp, 'KISAO:0000241', 'gillespie')
     exp.execute()
 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
     """
     exp = te.experiment(self.a1, p)
     self.checkKisaoIntegrator(exp, 'KISAO:0000019', 'cvode')
     exp.execute()
 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
     """
     exp = te.experiment(self.a1, p)
     self.checkKisaoAlgorithmParameter(exp, 'KISAO:0000488', 'seed', 1234)
     exp.execute()
 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
     """
     exp = te.experiment(self.a1, p)
     self.checkKisaoAlgorithmParameter(exp, 'KISAO:0000332', 'initial_time_step', 0.01)
     exp.execute()
 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
     """
     exp = te.experiment([self.a1, self.a2], p1)
     exp.execute(p1)
 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
     """
     exp = te.experiment(self.a1, p)
     self.checkKisaoIntegrator(exp, 'KISAO:0000280', 'cvode')
     exp.execute()
     pycode = exp._toPython(p)
     print(pycode)
     self.assertTrue("integrator.setValue('stiff', False)" in pycode)
 def test_1Model1PhrasedML(self):
     """ Minimal example which should work. """
     antimonyStr = """
     model test
         J0: S1 -> S2; k1*S1;
         S1 = 10.0; S2=0.0;
         k1 = 0.1;
     end
     """
     phrasedmlStr = """
         model0 = model "test"
         sim0 = simulate uniform(0, 10, 100)
         task0 = run sim0 on model0
         plot task0.time vs task0.S1
     """
     exp = te.experiment(antimonyStr, phrasedmlStr)
     exp.execute(phrasedmlStr)
    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
        """
        exp = te.experiment(self.a1, [p1, p2])
        # execute first
        exp.execute(p1)
        # execute second
        exp.execute(p2)
        # execute all
        exp.execute()
Exemplo n.º 23
0
  J0: S1 -> S2; k1*S1-k2*S2
  S1 = 10.0; S2 = 0.0;
  k1 = 0.5; k2=0.4
end
'''

phrasedmlStr = '''
  mod1 = model "case_03"
  mod2 = model mod1 with S2=S1+4
  sim1 = simulate uniform(0, 10, 100)
  task1 = run sim1 on mod1
  task2 = run sim1 on mod2
  plot "ComputeChanges" task1.time vs task1.S1, task1.S2, task2.S1, task2.S2
  report task1.time vs task1.S1, task1.S2, task2.S1, task2.S2
'''

# phrasedml experiment
exp = te.experiment(antimonyStr, phrasedmlStr)

# write python code
realPath = os.path.realpath(__file__)
workingDir = os.path.dirname(realPath)
with open(realPath + 'code.py', 'w') as f:
    f.write(exp._toPython(phrasedmlStr, workingDir=workingDir))

# execute python
exp.execute(phrasedmlStr, workingDir=workingDir)

# remove sedx (not hashable due to timestamp)
os.remove(os.path.join(workingDir, 'case_03.sedx'))
Exemplo n.º 24
0
'''
Lorenz attractor

This is a sample file that demonstrates the use of 
Antimony and phraSEDML to simulate Lorenz attractor.
This script requires Tellurium (http://tellurium.analogmachine.org/) to run.
'''

import tellurium as te

antimonyStr = '''
model lorenz
  x' = sigma*(y - x);
  y' = x*(rho - z) - y;
  z' = x*y - beta*z;
  x = 0.96259;  y = 2.07272;  z = 18.65888;
  sigma = 10;  rho = 28; beta = 2.67;
end
'''

phrasedmlStr = '''
model1 = model "lorenz"
sim1 = simulate uniform(0,15,2000)
task1 = run sim1 on model1
plot task1.z vs task1.x
'''

exp = te.experiment(antimonyStr, phrasedmlStr)
exp.execute(phrasedmlStr)
Exemplo n.º 25
0
# -*- coding: utf-8 -*-
"""
Testing phrasedml.
"""
from __future__ import print_function
import tellurium as te

ant = '''
model myModel
  S1 -> S2; k1*S1
  S1 = 10; S2 = 0
  k1 = 1
end
'''

phrasedml = '''
  model1 = model "myModel"
  sim1 = simulate uniform(0, 5, 100)
  task1 = run sim1 on model1
  plot "Figure 1" time vs S1, S2
'''

# create experiment
exp = te.experiment(ant, phrasedml)
exp.execute()
exp.printPython()
Exemplo n.º 26
0
antimony = '''
model myModel
  S1 -> S2; k1*S1
  S1 = 10; S2 = 0
  k1 = 1
end
'''

phrasedml = '''
  model1 = model "myModel"
  sim1 = simulate uniform(0, 5, 100)
  task1 = run sim1 on model1
  plot "Figure 1" time vs S1, S2
'''

import tellurium as te

exp = te.experiment(antimony, phrasedml)

exp.execute()
exp.printpython()

### export testing - put the full path of zip file you want to create
#exp.exportAsCombine() 

Exemplo n.º 27
0
model test()
    J0: S1 -> S2; k1*S1;
    S1 = 10.0; S2=0.0;
    k1 = 0.1;
end
"""

phrasedmlStr = """
    model0 = model "test"
    sim0 = simulate uniform(0, 6, 100)
    task0 = run sim0 on model0
    plot "Timecourse test model" task0.time vs task0.S1
"""

# phrasedml experiment
exp = te.experiment(antimonyStr, phrasedmlStr)
exp.execute(phrasedmlStr)

# create Combine Archive
import tempfile
f = tempfile.NamedTemporaryFile()
exp.exportAsCombine(f.name)

# print the content of the Combine Archive
import zipfile
zip=zipfile.ZipFile(f.name)
print(zip.namelist())


# ### Create combine archive
# TODO
  J8_V9 = 0.5;
  J8_KK9 = 15;
  J9_V10 = 0.5;
  J9_KK10 = 15;
  // Other declarations:
  const compartment_, J0_V1, J0_Ki, J0_n, J0_K1, J1_V2, J1_KK2, J2_k3, J2_KK3;
  const J3_k4, J3_KK4, J4_V5, J4_KK5, J5_V6, J5_KK6, J6_k7, J6_KK7, J7_k8;
  const J7_KK8, J8_V9, J8_KK9, J9_V10, J9_KK10;
end
'''

# Describe the simulations we want to carry out
PhrasedMLstr = '''
// Created by libphrasedml v0.5beta
// Models
model1 = model "BorisEJB"
// Simulations
timecourse1 = simulate uniform(0, 9000, 9000)
// Tasks
task1 = run timecourse1 on model1
// Outputs
plot "Figure 5A" time vs MAPK, MAPK_PP
'''

import tellurium as te

# Package up the model and model simulations into a COMBINE archive.
exp = te.experiment([AntimonyModel], [PhrasedMLstr])
exp.execute(PhrasedMLstr)
exp.exportAsCombine('./BorisEJB.omex')
 def test_experiment(self):
     """Test experiment."""
     exp = te.experiment(self.antimony, self.phrasedml)
     pstr = exp._toPython(self.phrasedml)
     self.assertIsNotNone(pstr)