def example(model_id: str) -> None: """XPP example conversion.""" # convert xpp to sbml xpp_dir = Path(__file__).parent / "xpp_example" out_dir = xpp_dir / "results" xpp_file = xpp_dir / f"{model_id}.ode" sbml_file = out_dir / f"{model_id}.xml" xpp.xpp2sbml(xpp_file=xpp_file, sbml_file=sbml_file) sbmlreport.create_report(sbml_file, output_dir=out_dir, validate=False) # test simulation r = roadrunner.RoadRunner(str(sbml_file)) s = r.simulate(start=0, end=1000, steps=100) fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(14, 7)) axes = (ax1, ax2) for ax in axes: for sid in r.timeCourseSelections[1:]: ax.plot(s["time"], s[sid], label=sid) ax2.set_yscale("log") for ax in axes: ax.set_ylabel("Value [?]") ax.set_xlabel("Time [?]") ax.legend() fig.savefig(out_dir / f"{model_id}.png", bbox_inches="tight")
def example(model_id): # convert xpp to sbml xpp_dir = "./xpp_example" out_dir = "./xpp_example/results" xpp_file = os.path.join(xpp_dir, "{}.ode".format(model_id)) sbml_file = os.path.join(out_dir, "{}.xml".format(model_id)) xpp.xpp2sbml(xpp_file=xpp_file, sbml_file=sbml_file) sbmlreport.create_report(sbml_file, target_dir=out_dir, validate=False) # test simulation r = roadrunner.RoadRunner(sbml_file) s = r.simulate(start=0, end=1000, steps=100) fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(14, 7)) axes = (ax1, ax2) for ax in axes: for sid in r.timeCourseSelections[1:]: ax.plot(s["time"], s[sid], label=sid) ax2.set_yscale("log") for ax in axes: ax.set_ylabel("Value [?]") ax.set_xlabel("Time [?]") ax.legend() fig.savefig(os.path.join(out_dir, "{}.png".format(model_id)), bbox_inches="tight")
def example(model_id): # convert xpp to sbml xpp_dir = './xpp_example' out_dir = './xpp_example/results' xpp_file = os.path.join(xpp_dir, "{}.ode".format(model_id)) sbml_file = os.path.join(out_dir, "{}.xml".format(model_id)) xpp.xpp2sbml(xpp_file=xpp_file, sbml_file=sbml_file) sbmlreport.create_sbml_report(sbml_file, out_dir=out_dir, validate=False) # test simulation r = roadrunner.RoadRunner(sbml_file) s = r.simulate(start=0, end=1000, steps=100) fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(14, 7)) axes = (ax1, ax2) for ax in axes: for sid in r.timeCourseSelections[1:]: ax.plot(s['time'], s[sid], label=sid) ax2.set_yscale('log') for ax in axes: ax.set_ylabel('Value [?]') ax.set_xlabel('Time [?]') ax.legend() fig.savefig(os.path.join(out_dir, "{}.png".format(model_id)), bbox_inches='tight')
def xpp_check(tmp_path, ode_id, Nall=0, Nerr=0, Nwarn=0): sbml_file = tmp_path / f"{ode_id}.xml" xpp_file = DATA_DIR / "xpp" / f"{ode_id}.ode" xpp.xpp2sbml(xpp_file=xpp_file, sbml_file=sbml_file) vresults = validate_sbml(sbml_file, units_consistency=False) assert vresults.all_count == Nall assert vresults.error_count == Nerr assert vresults.warning_count == Nwarn
def xpp_check(self, ode_id, Nall=0, Nerr=0, Nwarn=0): tmp_dir = tempfile.mkdtemp(suffix="_xpp") sbml_file = os.path.join(tmp_dir, "{}.xml".format(ode_id)) xpp_file = os.path.join(xpp_dir, "{}.ode".format(ode_id)) xpp.xpp2sbml(xpp_file=xpp_file, sbml_file=sbml_file) Nall_res, Nerr_res, Nwarn_res = validation.check_sbml(sbml_file, ucheck=False) assert Nall_res == Nall assert Nerr_res == Nerr assert Nwarn_res == Nwarn
force_lower = True results = [] debug, show_errors = False, False # test single model # ode_all = ["./87762/Neuron_KATP/NeuronKATP_Stoch.ode"] # debug, show_errors = True, True for k, xpp_file in enumerate(sorted(ode_all)): # convert xpp to sbml basename = os.path.basename(xpp_file) sbml_file = os.path.join(out_dir, "{}.xml".format(basename)) try: print('[{}]'.format(k)) xpp.xpp2sbml(xpp_file=xpp_file, sbml_file=sbml_file, force_lower=force_lower, validate=False, debug=debug) success = True sbmlreport.create_sbml_report(sbml_file, out_dir=out_dir, validate=False) Nall, Nerr, Nwarn = validation.check_sbml(sbml_file, name=None, ucheck=False, show_errors=show_errors) valid = (Nerr == 0) simulates = False if valid: try: simulate(sbml_file) simulates = True except: # simulation exception simulates = False print() traceback.print_exc(file=sys.stdout) print()
#!/usr/bin/env python # coding: utf-8 # # SBML converters # `sbmlutils` provides functionality for converting formats to SBML and SBML to some formats. # In[1]: from sbmlutils.report import sbmlreport # ## XPP to SBML # In this example a given xpp model is converted to SBML. # In[2]: from sbmlutils.converters import xpp from sbmlutils import validation # convert to SBML xpp.xpp2sbml(xpp_file="./xpp/SkM_AP_KCa.ode", sbml_file="./xpp/SkM_AP_KCa.xml")