use of org.vcell.util.exe.IExecutable in project vcell by virtualcell.
the class CopasiServicePython method runCopasiPython.
public static void runCopasiPython(File copasiOptProblemFile, File copasiResultsFile) throws IOException {
// It's 2015 -- forward slash works for all operating systems
File PYTHON = PythonSupport.getPythonExe();
InstallStatus copasiInstallStatus = PythonSupport.getPythonPackageStatus(PythonPackage.COPASI);
if (copasiInstallStatus == InstallStatus.FAILED) {
throw new RuntimeException("failed to install COPASI python package, consider re-installing VCell-managed python\n ...see Preferences->Python->Re-install");
}
if (copasiInstallStatus == InstallStatus.INITIALIZING) {
throw new RuntimeException("VCell is currently installing or verifying the COPASI python package ... please try again in a minute");
}
File vcellOptDir = ResourceUtil.getVCellOptPythonDir();
File optServicePythonFile = new File(vcellOptDir, "optService.py");
if (PYTHON == null || !PYTHON.exists()) {
throw new RuntimeException("python executable not specified, set python location in VCell menu File->Preferences...->Python Properties");
}
String[] cmd = new String[] { PYTHON.getAbsolutePath(), optServicePythonFile.getAbsolutePath(), copasiOptProblemFile.getAbsolutePath(), copasiResultsFile.getAbsolutePath() };
IExecutable exe = prepareExecutable(cmd);
try {
exe.start(new int[] { 0 });
if (exe.getExitValue() != 0) {
throw new RuntimeException("copasi python solver (optService.py) failed with return code " + exe.getExitValue() + ": " + exe.getStderrString());
}
} catch (ExecutableException e) {
e.printStackTrace();
throw new RuntimeException("optService.py invocation failed: " + e.getMessage(), e);
}
}
use of org.vcell.util.exe.IExecutable in project vcell by virtualcell.
the class VtkServicePython method writeVtkGridAndIndexData.
private void writeVtkGridAndIndexData(String visMeshType, VisMesh visMesh, String domainName, File vtkFile, File indexFile) throws IOException {
if (lg.isDebugEnabled()) {
lg.debug("writeVtkGridAndIndexData (python) for domain " + domainName);
}
File PYTHON = PythonSupport.getPythonExe();
InstallStatus copasiInstallStatus = PythonSupport.getPythonPackageStatus(PythonPackage.VTK);
if (copasiInstallStatus == InstallStatus.FAILED) {
throw new RuntimeException("failed to install VTK python package, consider re-installing VCell-managed python\n ...see Preferences->Python->Re-install");
}
if (copasiInstallStatus == InstallStatus.INITIALIZING) {
throw new RuntimeException("VCell is currently installing or verifying the VTK python package ... please try again in a minute");
}
String baseFilename = vtkFile.getName().replace(".vtu", ".visMesh");
File visMeshFile = new File(vtkFile.getParentFile(), baseFilename);
VisMeshUtils.writeVisMesh(visMeshFile, visMesh);
File vtkServiceFile = new File(ResourceUtil.getVCellVTKPythonDir(), "vtkService.py");
// It's 2015 -- forward slash works for all operating systems
String[] cmd = new String[] { PYTHON.getAbsolutePath(), vtkServiceFile.getAbsolutePath(), visMeshType, domainName, visMeshFile.getAbsolutePath(), vtkFile.getAbsolutePath(), indexFile.getAbsolutePath() };
IExecutable exe = prepareExecutable(cmd);
try {
exe.start(new int[] { 0 });
if (exe.getExitValue() != 0) {
throw new RuntimeException("mesh generation script for domain " + domainName + " failed with return code " + exe.getExitValue() + ": " + exe.getStderrString());
}
} catch (ExecutableException e) {
e.printStackTrace();
throw new RuntimeException("vtkService.py invocation failed: " + e.getMessage(), e);
}
}
use of org.vcell.util.exe.IExecutable in project vcell by virtualcell.
the class PythonSupport method checkPython.
private static boolean checkPython(File pythonExe) {
String[] cmd;
if (OperatingSystemInfo.getInstance().isWindows()) {
// cmd = new String[] {"cmd", "/C", managedMiniconda.pythonExe.getAbsolutePath(), "--version"};
cmd = new String[] { pythonExe.getAbsolutePath(), "--version" };
} else {
cmd = new String[] { pythonExe.getAbsolutePath(), "--version" };
}
IExecutable exe = new Executable(cmd);
try {
exe.start(new int[] { 0 });
System.out.println("Exit value: " + exe.getExitValue());
System.out.println("stdout=\"" + exe.getStdoutString() + "\"");
System.out.println("stderr=\"" + exe.getStderrString() + "\"");
if (exe.getExitValue() != 0) {
throw new RuntimeException("Python test failed with return code " + exe.getExitValue() + ": " + exe.getStderrString());
}
// }
return true;
} catch (ExecutableException e) {
e.printStackTrace();
throw new RuntimeException("Python test invocation failed: " + e.getMessage(), e);
}
}
use of org.vcell.util.exe.IExecutable in project vcell by virtualcell.
the class PythonSupport method checkPackage.
private static boolean checkPackage(File pythonExe, PythonPackage pythonPackage) {
String[] cmd;
if (OperatingSystemInfo.getInstance().isWindows()) {
// cmd = new String[] { "cmd", "/C", condaExe.getAbsolutePath(), "-c", "'import "+pythonPackage.pythonModuleName+"'"};
cmd = new String[] { pythonExe.getAbsolutePath(), "-c", "\"import " + pythonPackage.pythonModuleName + "\"" };
} else {
cmd = new String[] { "bash", "-c", pythonExe.getAbsolutePath() + " -c 'import " + pythonPackage.pythonModuleName + "'" };
}
System.out.println(Arrays.asList(cmd).toString());
IExecutable exe = new Executable(cmd);
try {
System.out.println("checking package " + pythonPackage.condaName);
exe.start(new int[] { 0 });
System.out.println("Exit value: " + exe.getExitValue());
System.out.println(exe.getStdoutString());
System.out.println(exe.getStderrString());
return true;
} catch (ExecutableException e) {
// e.printStackTrace();
System.out.println("Exit value: " + exe.getExitValue());
System.out.println(exe.getStdoutString());
System.out.println(exe.getStderrString());
return false;
}
}
Aggregations