def compareModels(sbmlModel, antModel):
    '''
    This code needs to be rewritten.
    '''

    import roadrunner, pylab, antimony

    sbmlModel = "00001-sbml-l2v4.xml"
    antModel = sbmlModel.replace(sbmlModel[-3:], "ant")

    # Make a round trip to and from Antimony
    antimony.loadSBMLFile(sbmlModel)
    antimony.writeAntimonyFile(antModel, antimony.getModuleNames()[1])
    antimony.loadAntimonyFile(antModel)
    antimony.writeSBMLFile("test.xml", antimony.getModuleNames()[1])

    rr1 = roadrunner.RoadRunner(sbmlModel)
    rr2 = roadrunner.RoadRunner("test.xml")

    result1 = rr1.simulate(0, 10, 101)
    result2 = rr2.simulate(0, 10, 101)

    result = result1 - result2

    pylab.plot(result[:, 0], result[:, 1:])

    pylab.show()
def convertSBML2Antimony(filename):

    if filename[-3:] == "xml":
        model_name = filename.replace(filename[-3:], "ant")
        antimony.loadSBMLFile(filename)
        antimony.writeAntimonyFile(model_name, antimony.getMainModuleName())

    elif filename[-3:] == "ant":
        model_name = filename.replace(filename[-3:], "xml")
        antimony.loadAntimonyFile(filename)
        antimony.writeSBMLFile(model_name, antimony.getMainModuleName())

    else:
        print("Error, input file not SBML '*.xml' or Antimony '*.ant' ")
Ejemplo n.º 3
0
def __antimony_to_sbml(ant):
    try:
        isfile = os.path.isfile(ant)
    except ValueError:
        isfile = False
    if isfile:
        code = antimony.loadAntimonyFile(ant)
    else:
        code = antimony.loadAntimonyString(ant)
    __check_antimony_return_code(code)
    mid = antimony.getMainModuleName()
    return antimony.getSBMLString(mid)
def antimonyToCellML(ant):
    """ Convert Antimony to CellML string.

    :param ant: Antimony string or file
    :type ant: str | file
    :return: CellML
    :rtype: str
    """
    if os.path.isfile(ant):
        code = antimony.loadAntimonyFile(ant)
    else:
        code = antimony.loadAntimonyString(ant)
    _checkAntimonyReturnCode(code)
    mid = antimony.getMainModuleName()
    return antimony.getCellMLString(mid)
Ejemplo n.º 5
0
def antimonyToCellML(ant):
    """ Convert Antimony to CellML string.

    :param ant: Antimony string or file
    :type ant: str | file
    :return: CellML
    :rtype: str
    """
    if os.path.isfile(ant):
        code = antimony.loadAntimonyFile(ant)
    else:
        code = antimony.loadAntimonyString(ant)
    _checkAntimonyReturnCode(code)
    mid = antimony.getMainModuleName()
    return antimony.getCellMLString(mid)
Ejemplo n.º 6
0
 def __init__(self, model_contents: str, content_type: str) -> None:
     if content_type == "ModelString":
         er_code = sb.loadAntimonyString(model_contents)
     elif content_type == "ModelFile":
         er_code = sb.loadAntimonyFile(model_contents)
     else:
         raise KeyError(f"Unsupported content_type: {content_type}")
     self.er_code = er_code
     if self.er_code == -1:
         error_msg = "Error while parsing model. Model variable names "
         error_msg += "might be antimony keywords (see docs at https://"
         error_msg += "cayenne.readthedocs.io/en/latest/tutorial.html)."
         raise ModelError(error_msg)
     self.sb_module = sb.getMainModuleName()
     self._parse_model()
Ejemplo n.º 7
0
def antimonyToSBML(ant):
    """ Convert Antimony to SBML string.

    :param ant: Antimony string or file
    :type ant: str | file
    :return: SBML
    :rtype: str
    """
    try:
        isfile = os.path.isfile(ant)
    except ValueError:
        isfile = False
    if isfile:
        code = antimony.loadAntimonyFile(ant)
    else:
        code = antimony.loadAntimonyString(ant)
    _checkAntimonyReturnCode(code)
    mid = antimony.getMainModuleName()
    return antimony.getSBMLString(mid)
Ejemplo n.º 8
0
def antimonyToSBML(ant):
    """ Convert Antimony to SBML string.

    :param ant: Antimony string or file
    :type ant: str | file
    :return: SBML
    :rtype: str
    """
    try:
        isfile = os.path.isfile(ant)
    except ValueError:
        isfile = False
    if isfile:
        code = antimony.loadAntimonyFile(ant)
    else:
        code = antimony.loadAntimonyString(ant)
    _checkAntimonyReturnCode(code)
    mid = antimony.getMainModuleName()
    return antimony.getSBMLString(mid)
Ejemplo n.º 9
0
]  #zu welchen Zeitpunkten soll die Konfiguration gespeichert werden?
tStart = 0  #Start- und Endzeit der Simulation
tEnd = 3.01
doplot = True  #plotten?
plotlegend = True  #Legende plotten?
verbose = 2  #Verbose level: 0 = garnicht, 1 = Statistik 1x je outerLoop, 2 = Statistik nach jedem N, 3 = +Schleifenzaehler (Haengt sich die Simulation auf?)
Nscale = 100
#Produkt der naechsten 3 Variablen ist die Anzahl der insg. simulierten Pfade
outerLoop = 1  #Anzahl Wiederholungen festlegen (multipliziert sich mit AnzahlPfade zur Anzahl der simulierten Pfade je N)
Nrange = range(
    3
)  #Bereich von N festlegen. range(5) ==  0,1,2,3,4. Daher Multiplikator N = (N+1)*Nscale
AnzahlPfade = 40  #Anzahl Wiederholungen festlegen (multipliziert sich mit outerLoop). Fuer schoene Plots hier Wert 40-100. Fuer grosse N: doplot=False, hier 1, dafuer bei outerLoop gewuenschte Werte eintragen.
#--------------stay-above-this-line----- #Modell laden, kann auch URL sein z.B. von www.biomodels.net---------
if os.path.isfile(antStr):  #----------- start copy&paste from tellurium.py
    code = antimony.loadAntimonyFile(antStr)
else:
    code = antimony.loadAntimonyString(antStr)
if code < 0:
    raise Exception('Antimony: {}'.format(antimony.getLastError()))
mid = antimony.getMainModuleName()
sbml = antimony.getSBMLString(mid)
r = roadrunner.RoadRunner(sbml)  #----------- end copy&paste from tellurium.py
#----------------the-next-three-lines-should-be-user-adapted--------
r.setIntegrator(
    'gillespie')  #Integrator auswaehlen. Andere unterstuetzen z.B. ODEs
r.getIntegrator().setValue(
    'variable_step_size', True
)  #Parameter fuer Integrator setzen, anderer Integrator unterstuetzt andere Parameter
Config.setValue(Config.MAX_OUTPUT_ROWS, pow(
    10, 7))  #bei 64-bit pow(10,11) oder weniger bei wenig Arbeitsspeicher
Ejemplo n.º 10
0
path='W:\Sim\\' #Dateipfad festlegen
selectToPlot = ['time','Rn','Pn','Hn'] #welche Variablen sind von Interesse?
timePoints = [1.0, 2.0, 3.0] #zu welchen Zeitpunkten soll die Konfiguration gespeichert werden?
tStart = 0	#Start- und Endzeit der Simulation
tEnd = 3.01
doplot = True #plotten?
plotlegend = True #Legende plotten?
verbose = 2 #Verbose level: 0 = garnicht, 1 = Statistik 1x je outerLoop, 2 = Statistik nach jedem N, 3 = +Schleifenzaehler (Haengt sich die Simulation auf?)
Nscale=100
#Produkt der naechsten 3 Variablen ist die Anzahl der insg. simulierten Pfade
outerLoop = 1 #Anzahl Wiederholungen festlegen (multipliziert sich mit AnzahlPfade zur Anzahl der simulierten Pfade je N)
Nrange= range(3) #Bereich von N festlegen. range(5) ==  0,1,2,3,4. Daher Multiplikator N = (N+1)*Nscale
AnzahlPfade = 40 #Anzahl Wiederholungen festlegen (multipliziert sich mit outerLoop). Fuer schoene Plots hier Wert 40-100. Fuer grosse N: doplot=False, hier 1, dafuer bei outerLoop gewuenschte Werte eintragen.
#--------------stay-above-this-line----- #Modell laden, kann auch URL sein z.B. von www.biomodels.net---------
if os.path.isfile(antStr):   #----------- start copy&paste from tellurium.py
	code = antimony.loadAntimonyFile(antStr)
else:
	code = antimony.loadAntimonyString(antStr)
if code < 0:
	raise Exception('Antimony: {}'.format(antimony.getLastError()))
mid = antimony.getMainModuleName()
sbml = antimony.getSBMLString(mid)
r = roadrunner.RoadRunner(sbml) #----------- end copy&paste from tellurium.py
#----------------the-next-three-lines-should-be-user-adapted--------
r.setIntegrator('gillespie')  #Integrator auswaehlen. Andere unterstuetzen z.B. ODEs
r.getIntegrator().setValue('variable_step_size', True) #Parameter fuer Integrator setzen, anderer Integrator unterstuetzt andere Parameter
Config.setValue(Config.MAX_OUTPUT_ROWS,pow(10,7))  #bei 64-bit pow(10,11) oder weniger bei wenig Arbeitsspeicher
#-----------end-user-parameters-----------
Reactions = 0
start_time = time.time()
selectToSave = ['N'] + selectToPlot