def antimonyToSBML(self, sb_str, SBO=False): """ Converts an Antimony string to raw SBML. :param sb_str: The raw Antimony string :returns: A 2-tuple (module_name, raw_sbml) """ import antimony as sb if not SBO: sbo_parser = antimonySBOParser(sb_str) try: sb_str = sbo_parser.elideSBOTerms() except: pass # try to load the Antimony code` code = sb.loadAntimonyString(sb_str) # if errors, bail if self.checkAntimonyReturnCode(code): errors = sb.getLastError() raise RuntimeError('Errors encountered when trying to load model into Antimony:\n{}'.format(errors)) module = sb.getMainModuleName() sbml = sb.getSBMLString(module) if not SBO: sbml = sbo_parser.addSBOsToSBML(sbml) return (module, sbml)
def antimonyToSBML(self, sb_str, SBO=False): """ Converts an Antimony string to raw SBML. :param sb_str: The raw Antimony string :returns: A 2-tuple (module_name, raw_sbml) """ import antimony as sb if not SBO: sbo_parser = antimonySBOParser(sb_str) try: sb_str = sbo_parser.elideSBOTerms() except: pass # try to load the Antimony code` code = sb.loadAntimonyString(sb_str) # if errors, bail if self.checkAntimonyReturnCode(code): errors = sb.getLastError() raise RuntimeError( 'Errors encountered when trying to load model into Antimony:\n{}' .format(errors)) module = sb.getMainModuleName() sbml = sb.getSBMLString(module) if not SBO: sbml = sbo_parser.addSBOsToSBML(sbml) return (module, sbml)
def loada(sbstr): import antimony as sb r = sb.loadAntimonyString(sbstr) if r < 0: raise RuntimeError('Failed to load Antimony model: {}'.format( sb.getLastError())) return roadrunner.RoadRunner(sb.getSBMLString(sb.getModuleNames()[-1]))
def _checkAntimonyReturnCode(code): """ Helper for checking the antimony response code. Raises Exception if error in antimony. :param code: antimony response :type code: int """ if code < 0: raise Exception("Antimony: {}".format(antimony.getLastError()))
def cellmlStrToAntimony(CellMLStr): """Convert a cellml string into the equivalent antimony string: ant = cellMLStrToAntimony('mymodel.cellml') """ if antimony.loadCellMLFile(CellMLStr) < 0: raise Exception("Error calling cellMLStrToAntimony" + antimony.getLastError()) return antimony.getAntimonyString(None)
def cellmlStrToSBML(CellMLStr): """Convert a cellml string into the equivalent SBML string: sbmlStr = cellMLStrToSBML('mymodel.cellml') """ if antimony.loadCellMLFile(CellMLStr) < 0: raise Exception("Error calling cellMLStrToSBML" + antimony.getLastError()) return antimony.getSBMLString(None)
def _checkAntimonyReturnCode(code): """ Helper for checking the antimony response code. Raises Exception if error in antimony. :param code: antimony response :type code: int """ if code < 0: raise Exception('Antimony: {}'.format(antimony.getLastError()))
def cellmlFileToSBML(CellMLFileName): """Load a cellml file and return the equivalent SBML string: sbmlStr = cellMLToSBML('mymodel.cellml') """ if antimony.loadCellMLFile(CellMLFileName) < 0: raise Exception("Error calling loadCellMLFile" + antimony.getLastError()) return antimony.getSBMLString(None)
def sbmlToAntimony(str): """Convert a SBML string into Antimony: sbmlStr = sbmlToAntimony (antimonyStr) """ err = antimony.loadSBMLString(str) if err < 0: raise Exception("Antimony: " + antimony.getLastError()) return antimony.getAntimonyString(None)
def AntimonyTranslatorError(self, getAntimonyMessage=False, *args, **kwrds): import inspect line = inspect.stack()[1][2] call = inspect.stack()[1][4] error_string = 'AntimonyTranslatorError line :' + str(line) + ' call:' + str(call) if getAntimonyMessage: error_message = antimony.getLastError() error_string = error_string + ' Antimony returned an error with the following messages: \n' + error_message else: error_string = error_string + ' Trying to access one of the Antimony translator methods but Antimony libraries (e.g. libAntimony) has not been installed with your CompuCell3D package' raise AttributeError(error_string)
def antimonyTosbml(antStr): """Convert an antimony string into SBML: sbmlStr = antimonyTosbml (antimonyStr) """ err = antimony.loadAntimonyString(antStr) if err < 0: raise Exception("Antimony: " + antimony.getLastError()) Id = antimony.getMainModuleName() return antimony.getSBMLString(Id)
def loadAntimonyModel(antStr): """Load an Antimony string: r = loadAntModel (antimonyStr) """ err = antimony.loadAntimonyString(antStr) if err < 0: raise Exception("Antimony: " + antimony.getLastError()) Id = antimony.getMainModuleName() sbmlStr = antimony.getSBMLString(Id) rr = roadrunner.RoadRunner(sbmlStr) antimony.clearPreviousLoads() return rr
def cellmlFileToAntimony(self, sbml_path): """ Converts a CellML file to Antimony source. :param sbml_path: The path to the CellML file :returns: A 2-tuple (module_name, antimony_source) """ import antimony as sb # try to load the Antimony code` code = sb.loadCellMLFile(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) return (module, sb_source)
def antimonyToSBML(self, sb_str): """ Converts an Antimony string to raw SBML. :param sb_str: The raw Antimony string :returns: A 2-tuple (module_name, raw_sbml) """ import antimony as sb # try to load the Antimony code` code = sb.loadAntimonyString(sb_str) # 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() sbml = sb.getSBMLString(module) return (module, sbml)
def sbmlToAntimony(self, sbml, addSBO=False): """ Converts a raw SBML string to Antimony source. :param sbml: The raw SBML string :returns: A 2-tuple (module_name, antimony_source) """ import antimony as sb # try to load the Antimony code` code = sb.loadSBMLString(sbml) # 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_str=sbml) return (module, sb_source)
def __check_antimony_return_code(code): if code < 0: raise Exception('Antimony: {}'.format(antimony.getLastError()))
import antimony with open('../model/rnadecay.sb') as f: sb = f.read() print(sb) res = antimony.loadString(sb) if res < 0: print(antimony.getLastError()) print(res) print(antimony.getModuleNames()) print(antimony.getModuleNames()[-1]) sbml = antimony.getSBMLString(antimony.getModuleNames()[-1]) with open('../model/rnadecay_sbml.xml', 'w') as f: f.write(sbml)
import antimony with open('transcription.sb') as f: sb = f.read() #print(sb) res = antimony.loadString(sb) if res < 0: print(antimony.getLastError()) #print(res) #print(antimony.getModuleNames()) #print(antimony.getModuleNames()[-1]) sbml = antimony.getSBMLString(antimony.getModuleNames()[-1]) with open('transcription_sbml.xml', 'w') as f: f.write(sbml)
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
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 form=(1,len(selectToSave)) r.selections = selectToSave simuliertePfade = 0 PfadeGesamt=outerLoop*AnzahlPfade*len(Nrange)