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' ")
def translate_sbml(cls, sbml_file: str): """ Translate SBML file to Antimony model specification. cayenne's model specification is loosely based on Antimony's model specification. """ er_code = sb.loadSBMLFile(sbml_file) if er_code == -1: raise ModelError("Error while parsing model") sb_module = sb.getMainModuleName() sb_string = sb.getAntimonyString(sb_module) return sb_string
def sbmlToCellML(sbml): """ Convert SBML to CellML string. :param sbml: SBML string or file :type sbml: str | file :return: CellML :rtype: str """ if os.path.isfile(sbml): code = antimony.loadSBMLFile(sbml) else: code = antimony.loadSBMLString(sbml) _checkAntimonyReturnCode(code) return antimony.getCellMLString(None)
def sbmlToAntimony(sbml): """ Convert SBML to antimony string. :param sbml: SBML string or file :type sbml: str | file :return: Antimony :rtype: str """ isfile = False try: isfile = os.path.isfile(sbml) except: pass if isfile: code = antimony.loadSBMLFile(sbml) else: code = antimony.loadSBMLString(str(sbml)) _checkAntimonyReturnCode(code) return antimony.getAntimonyString(None)
def sbmlFileToAntimony(self, sbml_path, addSBO=False): """ Converts a SBML file to Antimony source. :param sbml_path: The path to the SBML file :returns: A 2-tuple (module_name, antimony_source) """ import antimony as sb # try to load the Antimony code` code = sb.loadSBMLFile(sbml_path) # if errors, bail if self.checkAntimonyReturnCode(code): errors = sb.getLastError() raise RuntimeError('Errors encountered when trying to load model:\n{}'.format(errors)) module = sb.getMainModuleName() sb_source = sb.getAntimonyString(module) if addSBO: sb_source = self.tryAddSBOTerms(sb_source, sbml_file=sbml_path) return (module, sb_source)