def translate_to_sbml_string(self, model_file: str = '', model_string: str = ''): """ Returns string of SBML model specification translated from Antimony or CellML model specification file or string :param model_file: relative path to model specification file :param model_string: model specification string :return {str,str}: string of SBML model specification, string of main module name """ # Just to be sure, call clear previous loads antimony.clearPreviousLoads() # Loading from model string or file? if model_file == '': res_load = antimony.loadString(model_string) else: model_path_normalized = self.normalize_path(model_file) res_load = antimony.loadFile(model_path_normalized) if res_load == -1: AntimonyTranslatorError(self, getAntimonyMessage=True) # Get main loaded module main_module_name = antimony.getMainModuleName() if not main_module_name: AntimonyTranslatorError(self, getAntimonyMessage=True) # Return string of SBML model specification translated_model_string = antimony.getSBMLString(main_module_name) if not translated_model_string: AntimonyTranslatorError(self, getAntimonyMessage=True) else: return translated_model_string, main_module_name
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)
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)
def getSBMLStr(self): antimony.clearPreviousLoads() antimony.loadString(self.getRawStr()) return antimony.getSBMLString(antimony.getModuleNames()[-1])
// Species initializations: 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()