def getMatlab(self, current=False): """ Matlab string of the original model loaded into roadrunner. See also: :func:`getCurrentMatlab` :returns: Matlab string :rtype: str """ sbml = self.__getSBML(current) if sbml2matlab is not None: return sbml2matlab(sbml) else: warnings.warn("'sbml2matlab' could not be imported, no support for Matlab code generation", RuntimeWarning, stacklevel=2) return ""
def getMatlab(self): """ Returns Matlab string for current model """ return sbml2matlab(self.getCurrentSBML())
def exportToMatlab (r, filename): if not isinstance (r, roadrunner.RoadRunner): raise Exception ('First argument must be a roadrunner variable') matlab_str = sbml2matlab(r.getCurrentSBML()) saveToFile (filename, matlab_str)
try: import sbml2matlab except Exception as e: print("Failed to import sbml2matlab:") print(e) try: import matlab.engine except Exception as e: print("Failed to import matlab:") print(e) time_map[sim] = {} for file_name in sbml_files: print("Benchmarking sbml2matlab: " + file_name) sbml_file = open(file_name) sbml = sbml_file.read() matlab_code = sbml2matlab.sbml2matlab(sbml) sbml_file.close() first_paren = 0 while matlab_code[first_paren] != "(": first_paren += 1 model_name_begin = first_paren while matlab_code[model_name_begin] != " ": model_name_begin -= 1 model_name_begin += 1 model_name = matlab_code[model_name_begin:first_paren] matlab_code = "function [time] = temp()\n\t options = odeset('RelTol'," + str(reltol) + ",'AbsTol'," + str(abstol) + "); tic;\n" + \ "\t{}(linspace({},{},{}), @ode15s, options); time = toc;\n".format( model_name, time_start, time_end, steps) + matlab_code fid = open("temp.m", "w+") fid.write(matlab_code) fid.close()