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
    var species S3;
    var species S4;
    S3 = 0.5;
    PP_S = 0.0;
    S4 := 2*S3;

    // Rule for S1
    K1 = 0.5;    
    
    // Additional events for triggering re-integration
    E1: at(time>=2):  S3=5;  
    end
"""
model = antimony.loadString(model_txt)
sbml_file = "event_time.xml"
antimony.writeSBMLFile("event_time.xml", "event_time")

# load model in roadrunner and define the selection
r = roadrunner.RoadRunner(sbml_file)
r.selections = list(
    itertools.chain(
        ["time"], r.model.getBoundarySpeciesIds(), r.model.getFloatingSpeciesIds(), r.model.getReactionIds()
    )
)
print(r.selections)
absTol = 1e-6 * min(r.model.getCompartmentVolumes())
relTol = 1e-6

r.reset()
r.reset(SelectionRecord.ALL)
r.reset(SelectionRecord.INITIAL_GLOBAL_PARAMETER)
    t_duration = 5;
    peak_status = 0
   
    // Rule for PP_S
    PP_S := peak_status * 1.0 
    
    // Event to trigger the peak
    E0: at(time>=0):  peak_status=0;  
    E1: at(time>=t_peak):  peak_status=1;  
    E2: at(time>=t_peak+t_duration):  peak_status=0;

    end
"""
model = antimony.loadString(model_txt)
sbml_file = 'event_timepoint.xml'
antimony.writeSBMLFile(sbml_file, 'event_timepoint')

r = roadrunner.RoadRunner(sbml_file)
print(r.getSBML())
r.selections = ['time'] + r.model.getBoundarySpeciesIds() \
                        + r.model.getFloatingSpeciesIds() \
                        + r.model.getReactionIds()
print(r.selections)

# tolerances & integration
absTol = 1E-12 *min(r.model.getCompartmentVolumes())
relTol = 1E-12

# variable step size integration (reset just to be sure)
r.reset()
r.reset(SelectionRecord.ALL)
Ejemplo n.º 5
0
    // Rule for the function 
    PP_S := 1/(sigma *sqrt(2*pi)) * exp(-(time-mu)^2/(2*sigma^2));    
    //PP_S' = -(time - mu)/(sigma^3*sqrt(2*pi)) * exp(- (time-mu)^2/(2*sigma^2));
    
    // PP_S := sin(time);
    // Additional events for triggering re-integration
    E1: at(time>=t_peak-4*sigma):  K1=K1;  

    end
"""
model = antimony.loadString(model_txt)

out_dir = os.path.dirname(os.path.abspath(__file__))
sbml_path = str(os.path.join(out_dir, "time_peak.xml"))
print("SBML path:", sbml_path)
antimony.writeSBMLFile(sbml_path, "time_peak")
r = roadrunner.RoadRunner(sbml_path)

# display the generated and parsed SBML
# print(r.getSBML())
print("default selections:", r.selections)
r.selections = ["time"] + r.model.getBoundarySpeciesIds() + r.model.getFloatingSpeciesIds() + r.model.getReactionIds()
print("floating species:", r.model.getFloatingSpeciesIds())
print("selections:", r.selections)

# tolerances & integration
absTol = 1e-12 * min(r.model.getCompartmentVolumes())
relTol = 1e-12
print("absTol:", absTol, "; relTol:", relTol)

print("Naive VarStep")
Ejemplo n.º 6
0
"""
Create the SBML model.
"""
import antimony

model_id = 'vanderpol'
# ----------------------------
model_str = '''
model {}

var species x = -2; 
var species y = 0;
const mu = 1;

J1: -> x; y
J2: -> y; mu *(1-x^2)*y - x

end
'''.format(model_id)
# ----------------------------

antimony.setBareNumbersAreDimensionless(True)
antimony.loadAntimonyString(model_str)
model_file = './vanderpol-sbml.xml'
antimony.writeSBMLFile(model_file, model_id)
print(model_file)