use of cbit.vcell.resource.OperatingSystemInfo in project vcell by virtualcell.
the class DocumentWindow method startVCellVisIt.
private void startVCellVisIt() {
AsynchClientTask findVisitTask = new AsynchClientTask("Searching for VisIt...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
try {
VisitSupport.launchVisTool(VCellConfiguration.getFileProperty(PropertyLoader.visitExe));
} catch (Exception e) {
e.printStackTrace();
OperatingSystemInfo osi = OperatingSystemInfo.getInstance();
String executableName = ResourceUtil.getExecutableName(VisitSupport.VISIT_EXEC_NAME, false, osi);
File executableLocation = new ExecutableFinderDialog(DocumentWindow.this, "If VisIt is installed (from " + "https://wci.llnl.gov/codes/visit/" + ") but not in the system path, then press press '" + ExecutableFinderDialog.FIND + "' and navigate to '" + executableName + "'.\nElse please install VisIt, restart VCell, and try again").find(executableName);
VisitSupport.launchVisTool(executableLocation);
}
}
};
ProgressDialogListener progressDialogListener = new ProgressDialogListener() {
@Override
public void cancelButton_actionPerformed(EventObject newEvent) {
System.out.println(newEvent);
}
};
// ClientTaskDispatcher.dispatch(requester, hash, tasks, customDialog, bShowProgressPopup, bKnowProgress, cancelable, progressDialogListener, bInputBlocking);
ClientTaskDispatcher.dispatch(DocumentWindow.this, new Hashtable<>(), new AsynchClientTask[] { findVisitTask }, null, true, false, true, progressDialogListener, false);
}
use of cbit.vcell.resource.OperatingSystemInfo in project vcell by virtualcell.
the class VCellLookAndFeel method setVCellLookAndFeel.
public static void setVCellLookAndFeel() {
OperatingSystemInfo osi = OperatingSystemInfo.getInstance();
// changed to see if SystemLookAndFeel on Linux works better than the default CrossPlatformLookAndFeel (aka Metal)
try {
System.out.println("Operating system: " + osi.getOsType());
System.out.println("About to set the look and feel. Before setting, we're using: " + UIManager.getLookAndFeel().getName());
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
// }
final boolean isMac = osi.isMac();
if (defaultFont == null) {
defaultFont = UIManager.getFont("Label.font");
if (isMac) {
defaultFont = defaultFont.deriveFont(defaultFont.getSize2D() - 2);
}
}
if (isMac) {
UIManager.put("Button.font", defaultFont);
UIManager.put("CheckBox.font", defaultFont);
UIManager.put("CheckBoxMenuItem.font", defaultFont);
UIManager.put("ColorChooser.font", defaultFont);
UIManager.put("ComboBox.font", defaultFont);
UIManager.put("DesktopIcon.font", defaultFont);
UIManager.put("EditorPane.font", defaultFont);
UIManager.put("FileChooser.font", defaultFont);
UIManager.put("FormattedTextField.font", defaultFont);
UIManager.put("Label.font", defaultFont);
UIManager.put("List.font", defaultFont);
UIManager.put("Menu.font", defaultFont);
UIManager.put("MenuBar.font", defaultFont);
UIManager.put("MenuItem.font", defaultFont);
UIManager.put("OptionPane.font", defaultFont);
UIManager.put("Panel.font", defaultFont);
UIManager.put("PasswordField.font", defaultFont);
UIManager.put("PopupMenu.font", defaultFont);
UIManager.put("ProgressBar.font", defaultFont);
UIManager.put("RadioButton.font", defaultFont);
UIManager.put("RadioButtonMenuItem.font", defaultFont);
UIManager.put("TabbedPane.font", defaultFont);
UIManager.put("Table.font", defaultFont);
UIManager.put("TableHeader.font", defaultFont);
UIManager.put("TextArea.font", defaultFont);
UIManager.put("TextField.font", defaultFont);
UIManager.put("TextPane.font", defaultFont);
UIManager.put("TitledBorder.font", defaultFont);
UIManager.put("ToggleButton.font", defaultFont);
UIManager.put("ToolBar.font", defaultFont);
UIManager.put("ToolTip.font", defaultFont);
UIManager.put("Tree.font", defaultFont);
UIManager.put("Slider.font", defaultFont);
UIManager.put("ScrollPane.font", defaultFont);
UIManager.put("Viewport.font", defaultFont);
UIManager.put("CheckBoxMenuItem.acceleratorFont", defaultFont);
UIManager.put("InternalFrame.optionDialogTitleFont", defaultFont);
UIManager.put("InternalFrame.paletteTitleFont", defaultFont);
UIManager.put("InternalFrame.titleFont", defaultFont);
UIManager.put("Menu.acceleratorFont", defaultFont);
UIManager.put("MenuItem.acceleratorFont", defaultFont);
UIManager.put("OptionPane.buttonFont", defaultFont);
UIManager.put("OptionPane.messageFont", defaultFont);
UIManager.put("RadioButtonMenuItem.acceleratorFont", defaultFont);
UIManager.put("TabbedPane.useSmallLayout", Boolean.TRUE);
// System.setProperty("apple.laf.useScreenMenuBar", "true");
System.getProperties().put("swing.component.sizevariant", "small");
}
System.out.println("After setting, we're using: " + UIManager.getLookAndFeel().getName());
}
use of cbit.vcell.resource.OperatingSystemInfo in project vcell by virtualcell.
the class BNGExecutorServiceNative method executeBNG.
/**
* Insert the method's description here.
* Creation date: (6/23/2005 3:57:30 PM)
*/
@Override
public BNGOutput executeBNG() throws BNGException {
if (executable != null) {
throw new BNGException("You can only run BNG one at a time!");
}
BNGOutput bngOutput = null;
startTime = System.currentTimeMillis();
File workingDir = null;
try {
workingDir = Files.createTempDirectory("Bng_working_").toFile();
File bngInputFile = null;
FileOutputStream fos = null;
String tempFilePrefix = workingDir.getName();
try {
bngInputFile = new File(workingDir, tempFilePrefix + suffix_input);
fos = new java.io.FileOutputStream(bngInputFile);
} catch (java.io.IOException e) {
if (LG.isWarnEnabled()) {
LG.warn("error opening input file '" + bngInputFile, e);
}
e.printStackTrace(System.out);
throw new RuntimeException("error opening input file '" + bngInputFile.getName() + ": " + e.getMessage());
}
PrintWriter inputFile = new PrintWriter(fos);
System.out.println("Input file is: " + bngInputFile.getPath());
inputFile.print(bngInput.getInputString());
inputFile.close();
// System.out.println("BNGExecutorService.executeBNG(): input = \n"+bngInput.getInputString());
String[] cmd = null;
OperatingSystemInfo osi = OperatingSystemInfo.getInstance();
if (osi.isWindows()) {
System.out.println("BNGExecutorService.executeBNG() " + (osi.is64bit() ? "64bit" : "32bit") + " as standalone executable\n");
cmd = new String[] { ResourceUtil.getBNG2StandaloneWin(osi.is64bit()), bngInputFile.getAbsolutePath() };
} else {
// Execute as perl script
System.out.println("BNGExecutorService.executeBNG() as perl script\n");
String bngPerlFilePath = ResourceUtil.getBNG2_perl_file();
cmd = new String[] { ResourceUtil.getPerlExe().getAbsolutePath(), bngPerlFilePath, bngInputFile.getAbsolutePath() };
}
// run BNG
long timeoutMS = 0;
if (timeoutDurationMS != null) {
timeoutMS = timeoutDurationMS.longValue();
}
executable = new BioNetGenExecutable(cmd, timeoutMS, workingDir);
executable.addEnvironmentVariable("LD_LIBRARY_PATH", "");
executable.inheritCallbacks(getCallbacks());
int[] expectedReturnCodes = new int[] { 0 };
executable.start(expectedReturnCodes);
String stdoutString;
if (executable.getStatus() != org.vcell.util.exe.ExecutableStatus.STOPPED) {
stdoutString = executable.getStdoutString();
} else {
stdoutString = "Stopped by user. Output from BioNetGen may be truncated";
}
if (executable.getExitValue() == 1) {
String stderrString = executable.getStderrString();
if (stderrString.contains("run_network")) {
stdoutString = "run_network not supported on this operating system; partial data may be available\n" + executable.getStdoutString();
}
}
File[] files = workingDir.listFiles();
ArrayList<String> filenames = new ArrayList<String>();
ArrayList<String> filecontents = new ArrayList<String>();
for (File file : files) {
String filename = file.getName();
if (LG.isDebugEnabled()) {
LG.debug("BNG executor trying to read " + filename);
}
filenames.add(filename);
filecontents.add(FileUtils.readFileToString(file));
}
bngOutput = new BNGOutput(stdoutString, filenames.toArray(new String[0]), filecontents.toArray(new String[0]));
} catch (ExecutableException | IOException ex) {
if (LG.isWarnEnabled()) {
LG.warn("error executable BNG", ex);
}
if (executable == null || executable.getStderrString().trim().length() == 0) {
throw new BNGException("Error executing BNG", ex);
}
throw new BNGException(executable.getStderrString(), ex);
} finally {
if (workingDir != null) {
File[] files = workingDir.listFiles();
for (File file : files) {
file.delete();
}
workingDir.delete();
}
}
return bngOutput;
}
use of cbit.vcell.resource.OperatingSystemInfo in project vcell by virtualcell.
the class BiomodelsDB_TestSuite method main.
public static void main(String[] args) {
ys_runall();
System.exit(0);
try {
/*sanity check -- we currently only have a copasi_java dll for 32-bit, so let's make sure
* we're running on the right JVM. (Note we can run this on 64 bit machine, just have to install
* a 32 bit JVM...)
*/
OperatingSystemInfo osi = OperatingSystemInfo.getInstance();
// if (!osi.isWindows() || osi.is64bit()) {
// System.err.println("run on 32 bit JVM");
// System.exit(99);
// }
// following are set in command line processing
SortedSet<BiomodelsNetEntry> modelIDs = new TreeSet<BiomodelsNetEntry>();
BioModelsWebServices service = null;
File outDir = null;
boolean isDetailed;
{
// scope for command line processing
Options commandOptions = new Options();
Option help = new Option("help", false, "show help");
commandOptions.addOption(help);
Option detailed = new Option("detailed", false, "record detailed information");
commandOptions.addOption(detailed);
Option output = new Option("output", true, "output directory");
output.setRequired(true);
commandOptions.addOption(output);
OptionGroup primary = new OptionGroup();
LOption min = new LOption("min", true, "minimum number of model to import", true);
min.setType(Number.class);
LOption only = new LOption("only", true, "run only this model", false);
only.setType(Number.class);
LOption include = new LOption("include", true, "run on models in specified file", false);
include.setType(String.class);
LOption exclude = new LOption("exclude", true, "exclude models in specified file", true);
exclude.setType(String.class);
primary.addOption(min).addOption(only).addOption(include).addOption(exclude);
for (Object obj : primary.getOptions()) {
// CLI old, non-generic API
commandOptions.addOption((Option) obj);
}
CommandLine cmdLine = null;
try {
CommandLineParser parser = new DefaultParser();
cmdLine = parser.parse(commandOptions, args);
} catch (ParseException e1) {
e1.printStackTrace();
HelpFormatter hf = new HelpFormatter();
hf.printHelp("BiomodelsDB_TestSuite", commandOptions);
System.exit(2);
}
Option[] present = cmdLine.getOptions();
Set<Option> optionSet = new HashSet<Option>(Arrays.asList(present));
if (optionSet.contains(help)) {
HelpFormatter hf = new HelpFormatter();
hf.printHelp("BiomodelsDB_TestSuite", commandOptions);
System.exit(0);
}
// placeholder, avoid messing with nulls
LOption primaryOpt = new LOption("", false, "", true);
@SuppressWarnings("unchecked") Collection<? extends Option> priOpts = primary.getOptions();
priOpts.retainAll(optionSet);
if (!priOpts.isEmpty()) {
assert (priOpts.size() == 1);
primaryOpt = (LOption) priOpts.iterator().next();
}
outDir = new File(cmdLine.getOptionValue(output.getOpt()));
if (!outDir.exists()) {
outDir.mkdirs();
}
isDetailed = optionSet.contains(detailed);
BioModelsWebServicesServiceLocator locator = new BioModelsWebServicesServiceLocator();
service = locator.getBioModelsWebServices();
if (primaryOpt.downloads) {
String[] modelStrings = service.getAllCuratedModelsId();
for (String s : modelStrings) {
modelIDs.add(new BiomodelsNetEntry(s));
}
}
if (primaryOpt == only) {
Long only1 = (Long) cmdLine.getParsedOptionValue(only.getOpt());
modelIDs.add(new BiomodelsNetEntry(only1.intValue()));
} else if (primaryOpt == min) {
Long lv = (Long) cmdLine.getParsedOptionValue(min.getOpt());
int minimumModel = lv.intValue();
for (int m = 0; m < minimumModel; m++) {
modelIDs.remove(new BiomodelsNetEntry(m));
}
} else if (primaryOpt == include) {
FileBaseFilter fbf = new FileBaseFilter(cmdLine.getOptionValue(include.getOpt()));
modelIDs.addAll(fbf.models);
} else if (primaryOpt == exclude) {
FileBaseFilter fbf = new FileBaseFilter(cmdLine.getOptionValue(exclude.getOpt()));
modelIDs.removeAll(fbf.models);
}
}
// end command line processing
WriterFlusher flusher = new WriterFlusher(10);
PrintWriter detailWriter;
PrintWriter bngWriter;
PrintWriter sbmlWriter;
SBMLExceptionSorter sbmlExceptions;
if (isDetailed) {
detailWriter = new PrintWriter(new File(outDir, "compareDetail.txt"));
bngWriter = new PrintWriter(new File(outDir, "bngErrors.txt"));
sbmlWriter = new PrintWriter(new File(outDir, "sbmlErrors.txt"));
sbmlExceptions = new LiveSorter();
flusher.add(detailWriter);
flusher.add(bngWriter);
flusher.add(sbmlWriter);
} else {
detailWriter = new PrintWriter(new NullWriter());
bngWriter = new PrintWriter(new NullWriter());
sbmlWriter = new PrintWriter(new NullWriter());
sbmlExceptions = new NullSorter();
}
PropertyLoader.loadProperties();
/**
* example properties
*
* vcell.COPASI.executable = "C:\\Program Files\\COPASI\\bin\\CopasiSE.exe"
* vcell.mathSBML.directory = "c:\\developer\\eclipse\\workspace\\mathsbml\\"
* vcell.mathematica.kernel.executable = "C:\\Program Files\\Wolfram Research\\Mathematica\\7.0\\MathKernel.exe"
*/
ResourceUtil.setNativeLibraryDirectory();
PrintWriter printWriter = new PrintWriter(new FileWriter(new File(outDir, "summary.log"), true));
flusher.add(printWriter);
listModels(printWriter, modelIDs);
// SBMLSolver copasiSBMLSolver = new CopasiSBMLSolver();
SBMLSolver copasiSBMLSolver = new SBMLSolver() {
@Override
public File solve(String filePrefix, File outDir, String sbmlText, SimSpec testSpec) throws IOException, SolverException, SbmlException {
throw new RuntimeException("COPASI SOLVER REMOVED, REIMPLEMENT");
}
@Override
public String getResultsFileColumnDelimiter() {
throw new RuntimeException("COPASI SOLVER REMOVED, REIMPLEMENT");
}
};
try {
printWriter.println(" | *BIOMODEL ID* | *BioModel name* | *PASS* | *Rel Error (VC/COP)(VC/MSBML)(COP/MSBML)* | *Exception* | ");
removeToxic(modelIDs, printWriter);
for (BiomodelsNetEntry modelID : modelIDs) {
String modelName = service.getModelNameById(modelID.toString());
String modelSBML = service.getModelById(modelID.toString());
/*
modelSBML = modelSBML.replace("id=\"x\"", "id=\"s_x\"");
modelSBML = modelSBML.replace("id=\"y\"", "id=\"s_y\"");
modelSBML = modelSBML.replace("id=\"z\"", "id=\"s_z\"");
modelSBML = modelSBML.replace("species=\"x\"", "species=\"s_x\"");
modelSBML = modelSBML.replace("species=\"y\"", "species=\"s_y\"");
modelSBML = modelSBML.replace("species=\"z\"", "species=\"s_z\"");
modelSBML = modelSBML.replace("id=\"t\"", "id=\"s_t\"");
modelSBML = modelSBML.replace("species=\"t\"", "species=\"s_t\"");
modelSBML = modelSBML.replace("name=\"x\"", "name=\"s_x\"");
modelSBML = modelSBML.replace("name=\"y\"", "name=\"s_y\"");
modelSBML = modelSBML.replace("name=\"z\"", "name=\"s_z\"");
modelSBML = modelSBML.replace("name=\"t\"", "name=\"s_t\"");
modelSBML = modelSBML.replace("<ci> x ", "<ci> s_x ");
modelSBML = modelSBML.replace("<ci> y ", "<ci> s_y ");
modelSBML = modelSBML.replace("<ci> z ", "<ci> s_z ");
modelSBML = modelSBML.replace("<ci> t ", "<ci> s_t ");
*/
Element bioModelInfo = new Element(BioModelsNetPanel.BIOMODELINFO_ELEMENT_NAME);
bioModelInfo.setAttribute(BioModelsNetPanel.ID_ATTRIBUTE_NAME, modelID.toString());
bioModelInfo.setAttribute(BioModelsNetPanel.SUPPORTED_ATTRIBUTE_NAME, "false");
bioModelInfo.setAttribute("vcell_ran", "false");
bioModelInfo.setAttribute("COPASI_ran", "false");
bioModelInfo.setAttribute("mSBML_ran", "false");
bioModelInfo.setAttribute(BioModelsNetPanel.MODELNAME_ATTRIBUTE_NAME, modelName);
boolean bUseUTF8 = true;
File sbmlFile = new File(outDir, modelID + ".sbml");
XmlUtil.writeXMLStringToFile(modelSBML, sbmlFile.getAbsolutePath(), bUseUTF8);
PrintStream saved_sysout = System.out;
PrintStream saved_syserr = System.err;
PrintStream new_sysout = null;
PrintStream new_syserr = null;
try {
String filePrefix = modelID.toString();
String sbmlText = modelSBML;
File logFile = new File(outDir, filePrefix + ".log");
new_sysout = new PrintStream(logFile);
new_syserr = new_sysout;
System.setOut(new_sysout);
System.setErr(new_syserr);
StringBuffer combinedErrorBuffer = new StringBuffer();
SimSpec simSpec = SimSpec.fromSBML(modelSBML);
String[] varsToTest = simSpec.getVarsList();
/* for(int i=0; i<varsToTest.length; i++) {
if(varsToTest[i].contentEquals("x")) {
varsToTest[i] = "s_x";
} else if(varsToTest[i].contentEquals("y")) {
varsToTest[i] = "s_y";
} else if(varsToTest[i].contentEquals("z")) {
varsToTest[i] = "s_z";
} else if(varsToTest[i].contentEquals("t")) {
varsToTest[i] = "s_t";
}
}
*/
printWriter.print("ModelId: " + modelID + ": ");
// if a model crashes out the libSBML dll, we will terminate abruptly. Flush
// summary log before that happens
printWriter.flush();
try {
//
// get VCell solution with an embedded "ROUND TRIP" (time and species concentrations)
//
ODESolverResultSet vcellResults_RT = null;
try {
VCellSBMLSolver vcellSBMLSolver_RT = new VCellSBMLSolver();
vcellSBMLSolver_RT.setRoundTrip(false);
// TODO try with round-trip later.
String columnDelimiter = vcellSBMLSolver_RT.getResultsFileColumnDelimiter();
File resultFile = vcellSBMLSolver_RT.solve(filePrefix, outDir, sbmlFile.getAbsolutePath(), simSpec);
vcellResults_RT = readResultFile(resultFile, columnDelimiter);
bioModelInfo.setAttribute("vcell_ran", "true");
} catch (BNGException e) {
bngWriter.println(modelID + " " + e.getMessage());
throw e;
} catch (SBMLImportException e) {
ModelException me = new ModelException(modelID, e);
write(sbmlWriter, me);
sbmlExceptions.add(me);
throw e;
} catch (Exception e) {
printWriter.println("vcell solve(roundtrip=true) failed");
e.printStackTrace(printWriter);
System.out.println("vcell solve(roundtrip=true) failed");
e.printStackTrace(System.out);
combinedErrorBuffer.append(" *VCELL_RT* _" + e.getMessage() + "_ ");
Element vcellSolverReport = new Element("SolverReport");
vcellSolverReport.setAttribute("solverName", "vcell");
vcellSolverReport.setAttribute("errorMessage", e.getMessage());
bioModelInfo.addContent(vcellSolverReport);
bioModelInfo.setAttribute("vcell_ran", "false");
}
//
// get COPASI solution (time and species concentrations)
//
ODESolverResultSet copasiResults = null;
try {
String columnDelimiter = copasiSBMLSolver.getResultsFileColumnDelimiter();
File resultFile = copasiSBMLSolver.solve(filePrefix, outDir, sbmlText, simSpec);
copasiResults = readResultFile(resultFile, columnDelimiter);
bioModelInfo.setAttribute("COPASI_ran", "true");
} catch (Exception e) {
printWriter.println("Copasi solve() failed");
e.printStackTrace(printWriter);
System.out.println("Copasi solve() failed");
e.printStackTrace(System.out);
combinedErrorBuffer.append(" *COPASI* _" + e.getMessage() + "_ ");
Element copasiSolverReport = new Element("SolverReport");
copasiSolverReport.setAttribute("solverName", "COPASI");
copasiSolverReport.setAttribute("errorMessage", e.getMessage());
bioModelInfo.addContent(copasiSolverReport);
bioModelInfo.setAttribute("COPASI_ran", "false");
}
//
// get mSBML solution (time and species concentrations)
//
/*
ODESolverResultSet mSBMLResults = null;
if (idInt != 246 && idInt != 250 && idInt != 285 && idInt != 301) {
try {
MathSBMLSolver mSBMLSolver = new MathSBMLSolver();
String columnDelimiter = mSBMLSolver.getResultsFileColumnDelimiter();
org.sbml.libsbml.SBMLDocument sbmlDocument = new SBMLReader().readSBML(sbmlFile.getAbsolutePath());
long level = sbmlDocument.getLevel();
long version = sbmlDocument.getVersion();
String mathsbmlFilePrefix = filePrefix;
if (level!=2 || (level==2 && version>3)){
// sbmlDocument.setConsistencyChecksForConversion(libsbmlConstants.LIBSBML_CAT_MODELING_PRACTICE, false);
long numErrors = sbmlDocument.checkL2v3Compatibility();
if (numErrors==0){
boolean bConversionWorked = sbmlDocument.setLevelAndVersion(2, 3, false);
SBMLDocument doc = new SBMLDocument(sbmlDocument);
doc.setLevelAndVersion(2,3,false);
if (bConversionWorked){
mathsbmlFilePrefix = filePrefix+"_L2V3";
long newVersion = doc.getVersion();
SBMLWriter sbmlWriter = new SBMLWriter();
sbmlText = sbmlWriter.writeToString(doc);
try {
XmlUtil.writeXMLStringToFile(sbmlText, mathsbmlFilePrefix+".sbml", true);
} catch (IOException e1) {
e1.printStackTrace(System.out);
}
}else{
throw new RuntimeException("couldn't convert SBML from L"+level+"V"+version+" to L2V3");
}
}else{
throw new RuntimeException("couldn't convert SBML from L"+level+"V"+version+" to L2V3, not compatible: "+sbmlDocument.getError(0));
}
}
File resultFile = mSBMLSolver.solve(mathsbmlFilePrefix, outDir, sbmlText, simSpec);
mSBMLResults = readResultFile(resultFile, columnDelimiter);
bioModelInfo.setAttribute("mSBML_ran","true");
}catch (Exception e){
printWriter.println("mSBML solve() failed");
e.printStackTrace(printWriter);
System.out.println("mSBML solve() failed");
e.printStackTrace(System.out);
combinedErrorBuffer.append(" *mSBML* _"+e.getMessage()+"_ ");
Element mSBMLSolverReport = new Element("SolverReport");
mSBMLSolverReport.setAttribute("solverName","mSBML");
mSBMLSolverReport.setAttribute("errorMessage",e.getMessage());
bioModelInfo.addContent(mSBMLSolverReport);
bioModelInfo.setAttribute("mSBML_ran","false");
}
}
*/
//
// compare results from COPASI and VCELL_RT
//
Boolean bCOPASI_VCELL_matched = null;
if (copasiResults != null && vcellResults_RT != null) {
try {
SimulationComparisonSummary summary = MathTestingUtilities.compareResultSets(copasiResults, vcellResults_RT, varsToTest, TestCaseNew.REGRESSION, 1e-5, 1e-5);
double maxRelError = summary.getMaxRelativeError();
bioModelInfo.setAttribute("COPASI_VCELL_maxRelErr", Double.toString(maxRelError));
if (maxRelError < 1) {
bCOPASI_VCELL_matched = true;
} else {
detailWriter.println(modelID + " " + modelName);
bCOPASI_VCELL_matched = false;
Element solverComparison = new Element("SolverComparison");
solverComparison.setAttribute("solver1", "vcell");
solverComparison.setAttribute("solver2", "COPASI");
VariableComparisonSummary[] failedVCSummaries = summary.getFailingVariableComparisonSummaries(1e-5, 1e-5);
for (VariableComparisonSummary vcSummary : failedVCSummaries) {
Element failedVariableSummary = getVariableSummary(vcSummary);
solverComparison.addContent(failedVariableSummary);
String ss = vcSummary.toShortString();
detailWriter.print('\t');
detailWriter.println(ss);
System.out.println(ss);
}
detailWriter.println();
bioModelInfo.addContent(solverComparison);
}
} catch (Exception e) {
printWriter.println("COMPARE VC/COPASI failed");
e.printStackTrace(printWriter);
System.out.println("COMPARE VC/COPASI failed");
e.printStackTrace(System.out);
combinedErrorBuffer.append(" *COMPARE VC/COPASI* _" + e.getMessage() + "_ ");
Element solverComparison = new Element("SolverComparison");
solverComparison.setAttribute("solver1", "vcell");
solverComparison.setAttribute("solver2", "COPASI");
solverComparison.setAttribute("error", e.getMessage());
bioModelInfo.addContent(solverComparison);
}
}
/*
Boolean bmSBML_VCELL_matched = null;
if (mSBMLResults!=null && vcellResults_RT!=null){
try {
SimulationComparisonSummary summary = MathTestingUtilities.compareUnEqualResultSets(mSBMLResults, vcellResults_RT, varsToTest, 1e-5, 1e-5, 1);
double maxRelError = summary.getMaxRelativeError();
bioModelInfo.setAttribute("mSBML_VCELL_maxRelErr", Double.toString(maxRelError));
if (maxRelError<1){
bmSBML_VCELL_matched = true;
}else{
bmSBML_VCELL_matched = false;
Element solverComparison = new Element("SolverComparison");
solverComparison.setAttribute("solver1","vcell");
solverComparison.setAttribute("solver2","mSBML");
VariableComparisonSummary[] failedVCSummaries = summary.getFailingVariableComparisonSummaries(1e-5, 1e-5);
for (VariableComparisonSummary vcSummary : failedVCSummaries){
Element failedVariableSummary = getVariableSummary(vcSummary);
solverComparison.addContent(failedVariableSummary);
System.out.println(vcSummary.toShortString());
}
bioModelInfo.addContent(solverComparison);
}
} catch (Exception e) {
printWriter.println("COMPARE VCRT/mSBML failed");
e.printStackTrace(printWriter);
System.out.println("COMPARE VCRT/mSBML failed");
e.printStackTrace(System.out);
combinedErrorBuffer.append(" *COMPARE VCRT/mSBML* _"+e.getMessage()+"_ ");
Element solverComparison = new Element("SolverComparison");
solverComparison.setAttribute("solver1","vcell");
solverComparison.setAttribute("solver2","mSBML");
solverComparison.setAttribute("error",e.getMessage());
bioModelInfo.addContent(solverComparison);
}
}
//
// compare results from COPASI and mSBML
//
Boolean bCOPASI_mSBML_matched = null;
if (copasiResults!=null && mSBMLResults!=null){
try {
SimulationComparisonSummary summary = MathTestingUtilities.compareUnEqualResultSets(copasiResults, mSBMLResults, varsToTest, 1e-5, 1e-5, 1);
double maxRelError = summary.getMaxRelativeError();
bioModelInfo.setAttribute("COPASI_mSBML_maxRelErr", Double.toString(maxRelError));
if (maxRelError<1){
bCOPASI_mSBML_matched = true;
}else{
bCOPASI_mSBML_matched = false;
Element solverComparison = new Element("SolverComparison");
solverComparison.setAttribute("solver1","COPASI");
solverComparison.setAttribute("solver2","mSBML");
solverComparison.setAttribute("result","failed");
VariableComparisonSummary[] vcSummaries = summary.getVariableComparisonSummaries();
for (VariableComparisonSummary vcSummary : vcSummaries){
Element failedVariableSummary = getVariableSummary(vcSummary);
solverComparison.addContent(failedVariableSummary);
System.out.println(vcSummary.toShortString());
}
bioModelInfo.addContent(solverComparison);
}
} catch (Exception e) {
printWriter.println("COMPARE COPASI/mSBML failed");
e.printStackTrace(printWriter);
System.out.println("COMPARE COPASI/mSBML failed");
e.printStackTrace(System.out);
combinedErrorBuffer.append(" *COMPARE COPASI/mSBML* _"+e.getMessage()+"_ ");
Element solverComparison = new Element("SolverComparison");
solverComparison.setAttribute("solver1","COPASI");
solverComparison.setAttribute("solver2","mSBML");
solverComparison.setAttribute("error",e.getMessage());
}
}
*/
if ((bCOPASI_VCELL_matched != null && bCOPASI_VCELL_matched.booleanValue())) {
// || /*(bmSBML_VCELL_matched!=null && bmSBML_VCELL_matched.booleanValue()) */ )
bioModelInfo.setAttribute(BioModelsNetPanel.SUPPORTED_ATTRIBUTE_NAME, "true");
printWriter.println("PASS");
} else {
bioModelInfo.setAttribute(BioModelsNetPanel.SUPPORTED_ATTRIBUTE_NAME, "false");
printWriter.println("FAIL");
}
} catch (Exception e) {
e.printStackTrace(printWriter);
combinedErrorBuffer.append(" *UNKNOWN* _" + e.getMessage() + "_ ");
bioModelInfo.setAttribute(BioModelsNetPanel.SUPPORTED_ATTRIBUTE_NAME, "false");
bioModelInfo.setAttribute("exception", e.getMessage());
}
printWriter.flush();
// write for each model just in case files get corrupted (it happened).
write(bioModelInfo, new File(outDir, modelID + "_report.xml"));
} finally {
if (new_sysout != null) {
new_sysout.close();
new_sysout = null;
}
if (new_syserr != null) {
new_syserr.close();
new_syserr = null;
}
System.setOut(saved_sysout);
System.setOut(saved_syserr);
}
}
// this writes out the SBML import exceptions grouped by type
if (!sbmlExceptions.isEmpty()) {
Map<Category, Collection<ModelException>> map = sbmlExceptions.getMap();
try (PrintWriter pw = new PrintWriter(new File(outDir, "sbmlSorted.txt"))) {
// SBMLImportException.Category
for (Category c : Category.values()) {
Collection<ModelException> meCollection = map.get(c);
for (ModelException me : meCollection) {
write(pw, me);
}
}
}
}
} finally {
printWriter.close();
detailWriter.close();
bngWriter.close();
}
} catch (Throwable e) {
e.printStackTrace(System.out);
e.printStackTrace(System.err);
}
System.exit(0);
}
use of cbit.vcell.resource.OperatingSystemInfo in project vcell by virtualcell.
the class BiomodelsDB_TestSuite method ys_runall.
public static void ys_runall() {
System.out.println("testing");
try {
OperatingSystemInfo osi = OperatingSystemInfo.getInstance();
if (!osi.isWindows() || osi.is64bit()) {
System.err.println("run on 32 bit JVM");
// System.exit(99);
}
// File outDir = new File("C:\\Users\\yskaf\\Documents\\ModelFiles\\vcell_output\\runAll_10_21_19");
File outDir = new File("C:\\TEMP\\ddd\\274out");
if (!outDir.exists()) {
outDir.mkdirs();
}
WriterFlusher flusher = new WriterFlusher(10);
PrintWriter detailWriter;
PrintWriter bngWriter;
PrintWriter sbmlWriter;
SBMLExceptionSorter sbmlExceptions;
detailWriter = new PrintWriter(new File(outDir, "compareDetail.txt"));
bngWriter = new PrintWriter(new File(outDir, "bngErrors.txt"));
sbmlWriter = new PrintWriter(new File(outDir, "sbmlErrors.txt"));
sbmlExceptions = new LiveSorter();
flusher.add(detailWriter);
flusher.add(bngWriter);
flusher.add(sbmlWriter);
PropertyLoader.loadProperties();
ResourceUtil.setNativeLibraryDirectory();
PrintWriter printWriter = new PrintWriter(new FileWriter(new File(outDir, "summary.log"), true));
flusher.add(printWriter);
try {
File inDir = new File("C:\\TEMP\\ddd\\274");
// File inDir = new File("C:\\Users\\yskaf\\Documents\\ModelFiles\\temp");
File[] directoryListing = inDir.listFiles();
if (directoryListing != null) {
printWriter.println(" | *BIOMODEL ID* | *BioModel name* | *PASS* | *Rel Error (VC/COP)(VC/MSBML)(COP/MSBML)* | *Exception* | ");
for (File modelFile : directoryListing) {
String fileName = modelFile.getName();
int end = fileName.indexOf(".");
String modelName = fileName.substring(0, end);
String modelSBML = new Scanner(modelFile).useDelimiter("\\Z").next();
String modelID = modelName.replaceAll("[^0-9]", "");
// **********
// try {
// modelSBML = modelSBML.replace("id=\"x\"", "id=\"s_x\"");
// modelSBML = modelSBML.replace("id=\"y\"", "id=\"s_y\"");
// modelSBML = modelSBML.replace("id=\"z\"", "id=\"s_z\"");
// modelSBML = modelSBML.replace("species=\"x\"", "species=\"s_x\"");
// modelSBML = modelSBML.replace("species=\"y\"", "species=\"s_y\"");
// modelSBML = modelSBML.replace("species=\"z\"", "species=\"s_z\"");
//
// modelSBML = modelSBML.replace("id=\"t\"", "id=\"s_t\"");
// modelSBML = modelSBML.replace("species=\"t\"", "species=\"s_t\"");
//
// modelSBML = modelSBML.replace("name=\"x\"", "name=\"s_x\"");
// modelSBML = modelSBML.replace("name=\"y\"", "name=\"s_y\"");
// modelSBML = modelSBML.replace("name=\"z\"", "name=\"s_z\"");
// modelSBML = modelSBML.replace("name=\"t\"", "name=\"s_t\"");
//
// modelSBML = modelSBML.replace("<ci> x ", "<ci> s_x ");
// modelSBML = modelSBML.replace("<ci> y ", "<ci> s_y ");
// modelSBML = modelSBML.replace("<ci> z ", "<ci> s_z ");
// modelSBML = modelSBML.replace("<ci> t ", "<ci> s_t ");
//
// /*FileOutputStream fooStream = new FileOutputStream(modelFile, false); // true to append, false to overwrite
// byte[] myBytes = modelSBML.getBytes();
// fooStream.write(myBytes);
// fooStream.close();*/
//
// } catch (Exception e) {
// printWriter.print(modelName + ": error with SBML replacement.");
// printWriter.print(e.getMessage());
// }
Element bioModelInfo = new Element(BioModelsNetPanel.BIOMODELINFO_ELEMENT_NAME);
bioModelInfo.setAttribute(BioModelsNetPanel.ID_ATTRIBUTE_NAME, modelID);
bioModelInfo.setAttribute(BioModelsNetPanel.SUPPORTED_ATTRIBUTE_NAME, "false");
bioModelInfo.setAttribute("vcell_ran", "false");
bioModelInfo.setAttribute("COPASI_ran", "false");
bioModelInfo.setAttribute("mSBML_ran", "false");
bioModelInfo.setAttribute(BioModelsNetPanel.MODELNAME_ATTRIBUTE_NAME, modelName);
boolean bUseUTF8 = true;
File sbmlFile = new File(outDir, modelName + ".sbml");
XmlUtil.writeXMLStringToFile(modelSBML, sbmlFile.getAbsolutePath(), bUseUTF8);
PrintStream saved_sysout = System.out;
PrintStream saved_syserr = System.err;
PrintStream new_sysout = null;
PrintStream new_syserr = null;
try {
String filePrefix = modelName;
String sbmlText = modelSBML;
File logFile = new File(outDir, filePrefix + ".log");
new_sysout = new PrintStream(logFile);
new_syserr = new_sysout;
System.setOut(new_sysout);
System.setErr(new_syserr);
StringBuffer combinedErrorBuffer = new StringBuffer();
SimSpec simSpec = SimSpec.fromSBML(modelSBML);
String[] varsToTest = simSpec.getVarsList();
/* for(int i=0; i<varsToTest.length; i++) {
if(varsToTest[i].contentEquals("x")) {
varsToTest[i] = "s_x";
} else if(varsToTest[i].contentEquals("y")) {
varsToTest[i] = "s_y";
} else if(varsToTest[i].contentEquals("z")) {
varsToTest[i] = "s_z";
} else if(varsToTest[i].contentEquals("t")) {
varsToTest[i] = "s_t";
}
}
*/
printWriter.print(modelName + ": ");
printWriter.flush();
try {
// get VCell solution with an embedded "ROUND TRIP" (time and species concentrations)
ODESolverResultSet vcellResults_RT = null;
try {
VCellSBMLSolver vcellSBMLSolver_RT = new VCellSBMLSolver();
vcellSBMLSolver_RT.setRoundTrip(false);
// TODO try with round-trip later.
String columnDelimiter = vcellSBMLSolver_RT.getResultsFileColumnDelimiter();
File resultFile = vcellSBMLSolver_RT.solve(filePrefix, outDir, sbmlFile.getAbsolutePath(), simSpec);
vcellResults_RT = readResultFile(resultFile, columnDelimiter);
bioModelInfo.setAttribute("vcell_ran", "true");
} catch (BNGException e) {
bngWriter.println(modelID + " " + e.getMessage());
throw e;
} catch (SBMLImportException e) {
// sbmlExceptions.add(me);
throw e;
} catch (Exception e) {
printWriter.println("vcell solve(roundtrip=true) failed");
e.printStackTrace(printWriter);
System.out.println("vcell solve(roundtrip=true) failed");
e.printStackTrace(System.out);
combinedErrorBuffer.append(" *VCELL_RT* _" + e.getMessage() + "_ ");
Element vcellSolverReport = new Element("SolverReport");
vcellSolverReport.setAttribute("solverName", "vcell");
vcellSolverReport.setAttribute("errorMessage", e.getMessage());
bioModelInfo.addContent(vcellSolverReport);
bioModelInfo.setAttribute("vcell_ran", "false");
}
if (vcellResults_RT != null) {
bioModelInfo.setAttribute(BioModelsNetPanel.SUPPORTED_ATTRIBUTE_NAME, "true");
printWriter.println("PASS");
} else {
bioModelInfo.setAttribute(BioModelsNetPanel.SUPPORTED_ATTRIBUTE_NAME, "false");
printWriter.println("FAIL");
}
} catch (Exception e) {
e.printStackTrace(printWriter);
combinedErrorBuffer.append(" *UNKNOWN* _" + e.getMessage() + "_ ");
bioModelInfo.setAttribute(BioModelsNetPanel.SUPPORTED_ATTRIBUTE_NAME, "false");
bioModelInfo.setAttribute("exception", e.getMessage());
}
printWriter.flush();
// write for each model just in case files get corrupted (it happened).
write(bioModelInfo, new File(outDir, modelName + "_report.xml"));
} finally {
if (new_sysout != null) {
new_sysout.close();
new_sysout = null;
}
if (new_syserr != null) {
new_syserr.close();
new_syserr = null;
}
System.setOut(saved_sysout);
System.setOut(saved_syserr);
}
}
} else {
System.err.println("inDir not a directory");
System.exit(99);
}
// this writes out the SBML import exceptions grouped by type
if (!sbmlExceptions.isEmpty()) {
Map<Category, Collection<ModelException>> map = sbmlExceptions.getMap();
try (PrintWriter pw = new PrintWriter(new File(outDir, "sbmlSorted.txt"))) {
// SBMLImportException.Category
for (Category c : Category.values()) {
Collection<ModelException> meCollection = map.get(c);
for (ModelException me : meCollection) {
write(pw, me);
}
}
}
}
} finally {
printWriter.close();
detailWriter.close();
bngWriter.close();
}
} catch (Throwable e) {
e.printStackTrace(System.out);
e.printStackTrace(System.err);
}
System.exit(0);
}
Aggregations