|
| 1 | +import os |
| 2 | +import subprocess as sp |
| 3 | + |
| 4 | +from omv.engines.jneuroml import JNeuroMLEngine |
| 5 | +from omv.engines.xpp import XppEngine |
| 6 | +from omv.common.inout import inform, trim_path, check_output, is_verbose |
| 7 | +from omv.engines.engine import EngineExecutionError |
| 8 | + |
| 9 | + |
| 10 | +class JNeuroMLXppEngine(JNeuroMLEngine): |
| 11 | + name = "jNeuroML_XPP" |
| 12 | + |
| 13 | + @staticmethod |
| 14 | + def is_installed(): |
| 15 | + if is_verbose(): |
| 16 | + inform( |
| 17 | + "Checking whether %s is installed..." % JNeuroMLXppEngine.name, |
| 18 | + indent=1, |
| 19 | + ) |
| 20 | + return JNeuroMLEngine.is_installed() and XppEngine.is_installed() |
| 21 | + |
| 22 | + @staticmethod |
| 23 | + def install(xpp_version): |
| 24 | + if not JNeuroMLEngine.is_installed(): |
| 25 | + JNeuroMLEngine.install(None) |
| 26 | + if not XppEngine.is_installed(): |
| 27 | + XppEngine.install(xpp_version) |
| 28 | + |
| 29 | + |
| 30 | + def run(self): |
| 31 | + self.environment_vars = XppEngine.get_xpp_environment() |
| 32 | + self.set_environment() |
| 33 | + try: |
| 34 | + inform( |
| 35 | + "Running file %s with %s" |
| 36 | + % (trim_path(self.modelpath), JNeuroMLXppEngine.name), |
| 37 | + indent=1, |
| 38 | + ) |
| 39 | + from omv.engines.jneuroml import JNeuroMLEngine |
| 40 | + |
| 41 | + jnml = JNeuroMLEngine.get_executable() |
| 42 | + self.stdout = check_output( |
| 43 | + [jnml, self.modelpath, "-xpp"], |
| 44 | + cwd=os.path.dirname(self.modelpath), |
| 45 | + env=JNeuroMLEngine.get_environment(), |
| 46 | + ) |
| 47 | + |
| 48 | + self.stdout = check_output( |
| 49 | + [self.environment_vars["XPP_HOME"] + "/xppaut", self.modelpath.replace('.xml','.ode'), '-silent'], |
| 50 | + cwd=os.path.dirname(self.modelpath), |
| 51 | + ) |
| 52 | + |
| 53 | + inform("Success with running ", JNeuroMLXppEngine.name, indent=1) |
| 54 | + self.returncode = 0 |
| 55 | + except sp.CalledProcessError as err: |
| 56 | + inform("Error with ", JNeuroMLXppEngine.name, indent=1) |
| 57 | + self.returncode = err.returncode |
| 58 | + self.stdout = err.output |
| 59 | + raise EngineExecutionError |
0 commit comments