use of cbit.vcell.xml.XMLSource in project vcell by virtualcell.
the class ClientDocumentManager method getMathModelXML.
/**
* Insert the method's description here.
* Creation date: (3/29/2004 4:04:16 PM)
* @return java.lang.String
* @param vType cbit.sql.VersionableType
* @param vKey cbit.sql.KeyValue
*/
private XMLHolder<MathModel> getMathModelXML(KeyValue vKey) throws DataAccessException {
try {
String xmlString = (String) xmlHash.get(vKey);
if (xmlString == null) {
xmlString = sessionManager.getUserMetaDbServer().getMathModelXML(vKey).toString();
if (xmlString != null) {
MathModel mathModel = XmlHelper.XMLToMathModel(new XMLSource(xmlString));
String newXmlString = XmlHelper.mathModelToXML(mathModel);
xmlHash.put(vKey, newXmlString);
return new XMLHolder<MathModel>(newXmlString, mathModel);
} else {
throw new RuntimeException("unexpected: UserMetaDbServer.getMathModelXML() returned null");
}
} else {
return new XMLHolder<MathModel>(xmlString);
}
} catch (ObjectNotFoundException e) {
throw new DataAccessException("MathModel (id=" + vKey + ") does not exist. It either " + "has been deleted or its reference is outdated. Please use menu 'Server->Reconnect' to update document references.");
} catch (Exception e) {
e.printStackTrace(System.out);
throw FailToLoadDocumentExc.createException(e, vKey, this);
}
}
use of cbit.vcell.xml.XMLSource in project vcell by virtualcell.
the class ClientDocumentManager method getGeometry.
/**
* Insert the method's description here.
* Creation date: (11/14/00 4:02:44 PM)
* @return cbit.vcell.biomodel.BioModel
* @param bioModelInfo cbit.vcell.biomodel.BioModelInfo
*/
public Geometry getGeometry(GeometryInfo geometryInfo) throws DataAccessException {
Geometry geometry = null;
try {
XMLSource geomSource = new XMLSource(getGeometryXML(geometryInfo.getVersion().getVersionKey()));
geometry = XmlHelper.XMLToGeometry(geomSource);
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new DataAccessException(e.getMessage());
}
try {
if (geometry.getDimension() > 0 && geometry.getGeometrySurfaceDescription().getGeometricRegions() == null) {
geometry.getGeometrySurfaceDescription().updateAll();
}
} catch (Exception e) {
e.printStackTrace(System.out);
// throw new DataAccessException("Geometric surface generation error:\n"+e.getMessage());
}
return geometry;
}
use of cbit.vcell.xml.XMLSource in project vcell by virtualcell.
the class ClientDocumentManager method getGeometryFromDatabaseXML.
/**
* Insert the method's description here.
* Creation date: (9/22/2004 5:22:40 PM)
* @return cbit.vcell.mathmodel.MathModel
* @param mathModelXML java.lang.String
*/
private Geometry getGeometryFromDatabaseXML(String geometryXML) throws DataAccessException {
try {
Geometry geometry = XmlHelper.XMLToGeometry(new XMLSource(geometryXML));
geometry.refreshDependencies();
try {
if (geometry.getDimension() > 0) {
geometry.getGeometrySurfaceDescription().updateAll();
}
} catch (Exception e) {
e.printStackTrace(System.out);
throw new DataAccessException("Geometric surface generation error:\n" + e.getMessage());
}
return geometry;
} catch (XmlParseException e) {
e.printStackTrace();
throw new DataAccessException(e.getClass().getName() + ": " + e.getMessage());
}
}
use of cbit.vcell.xml.XMLSource in project vcell by virtualcell.
the class HybridSolverTester method runHybridTest.
public void runHybridTest(String site) {
try {
double[] timePoints = null;
File mathModelFile = new File(mathModelVCMLFileName);
XMLSource vcmlSource = new XMLSource(mathModelFile);
MathModel mathModel = XmlHelper.XMLToMathModel(vcmlSource);
File simDataDir = mathModelFile.getParentFile();
Simulation sim = mathModel.getSimulations()[0];
// run multiple trials and each run will have a simID = origSimID + i
for (int i = 0; i < numRuns; i++) {
System.out.println("--------------Trial No: " + (startTrialNo + i) + "----------------");
// replace random seed
sim.getSolverTaskDescription().getSmoldynSimulationOptions().setRandomSeed(new Integer(startTrialNo + i));
// create sim job
int jobIndex = startTrialNo + i;
SimulationTask simTask = new SimulationTask(new SimulationJob(sim, jobIndex, null), 0);
/*
* When you want to run the multiple trials on local uncomment the line below.
*/
// ResourceUtil.prepareSolverExecutable(sim.getSolverTaskDescription().getSolverDescription());
/*
* When you want to run the multiple trials on server (without VCell user interface), use the next line of code
* Corresponding changes should be made in the shell script runhybridtest for the location of executable on server
*/
FVSolverStandalone fvSolver = new FVSolverStandalone(simTask, simDataDir, false);
fvSolver.startSolver();
SolverStatus status = fvSolver.getSolverStatus();
while (status.getStatus() != SolverStatus.SOLVER_FINISHED && status.getStatus() != SolverStatus.SOLVER_ABORTED) {
System.out.println("progress: " + (int) (fvSolver.getProgress() * 100) + "%");
// ask status every 2 seconds
Thread.sleep(2000);
status = fvSolver.getSolverStatus();
}
if (status.getStatus() == SolverStatus.SOLVER_FINISHED) {
// get data
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(sim.getVersion().getVersionKey(), sim.getVersion().getOwner());
VCSimulationDataIdentifier vcSimDataID = new VCSimulationDataIdentifier(vcSimID, jobIndex);
File hdf5File = new File(simDataDir, vcSimDataID.getID() + SimDataConstants.DATA_PROCESSING_OUTPUT_EXTENSION_HDF5);
DataOperationResults.DataProcessingOutputInfo dataProcessingOutputInfo = (DataOperationResults.DataProcessingOutputInfo) DataSetControllerImpl.getDataProcessingOutput(new DataOperation.DataProcessingOutputInfoOP(vcSimDataID, false, null), hdf5File);
if (i == 0) {
// do only one time
timePoints = dataProcessingOutputInfo.getVariableTimePoints();
for (int j = 0; j < varNames.length; j++) {
// row: numTimePoints, col:first col time + numRuns
double[][] data = new double[numRuns + 1][timePoints.length];
data[0] = timePoints;
results.add(data);
}
}
// write into results after each run
for (int j = 0; j < varNames.length; j++) {
results.get(j)[i + 1] = dataProcessingOutputInfo.getVariableStatValues().get(varNames[j]);
}
// delete the file generated for this run
deleteSimFiles(simDataDir, vcSimDataID);
} else {
throw new Exception("Sover did not finish normally." + status);
}
}
// write to output file, tab delimited
if (results != null && results.size() > 0) {
for (int j = 0; j < varNames.length; j++) {
File file = new File(simDataDir, "SimID_" + sim.getVersion().getVersionKey().toString() + "_" + varNames[j] + "_" + startTrialNo + ".txt");
PrintWriter pw = new PrintWriter(file);
double[][] data = results.get(j);
if (data != null) {
for (int k = 0; k < data.length; k++) {
if (!bPrintTime && k == 0) {
continue;
}
String rowStr = (k == 0) ? "Time\t" : ("trialNo_" + (startTrialNo + k - 1) + "\t");
double[] rowData = data[k];
for (int q = 0; q < rowData.length; q++) {
rowStr += rowData[q] + "\t";
}
pw.println(rowStr);
}
}
pw.close();
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of cbit.vcell.xml.XMLSource in project vcell by virtualcell.
the class StochtestRunService method runOne.
public void runOne() throws IllegalArgumentException, SQLException, DataAccessException, XmlParseException, PropertyVetoException, ExpressionException, MappingException, GeometryException, ImageException, IOException {
StochtestRun stochtestRun = StochtestDbUtils.acceptNextWaitingStochtestRun(conFactory);
String biomodelXML = null;
if (stochtestRun != null) {
String networkGenProbs = null;
try {
User user = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new KeyValue(PropertyLoader.ADMINISTRATOR_ID));
ServerDocumentManager serverDocumentManager = new ServerDocumentManager(this.dbServerImpl);
biomodelXML = serverDocumentManager.getBioModelXML(new QueryHashtable(), user, stochtestRun.stochtest.biomodelRef, true);
BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(biomodelXML));
bioModel.refreshDependencies();
SimulationContext srcSimContext = null;
for (SimulationContext sc : bioModel.getSimulationContexts()) {
if (sc.getKey().equals(stochtestRun.stochtest.simContextRef)) {
srcSimContext = sc;
}
}
if (srcSimContext == null) {
throw new RuntimeException("cannot find simcontext with key=" + stochtestRun.stochtest.simContextRef);
}
//
for (SpeciesContextSpec scs : srcSimContext.getReactionContext().getSpeciesContextSpecs()) {
scs.setConstant(false);
}
SimulationContext simContext = srcSimContext;
StochtestMathType parentMathType = stochtestRun.parentMathType;
StochtestMathType mathType = stochtestRun.mathType;
if (parentMathType != mathType) {
if (parentMathType == StochtestMathType.nonspatialstochastic && mathType == StochtestMathType.rules) {
simContext = SimulationContext.copySimulationContext(srcSimContext, "generatedRules", false, Application.RULE_BASED_STOCHASTIC);
} else if (parentMathType == StochtestMathType.rules && mathType == StochtestMathType.nonspatialstochastic) {
simContext = SimulationContext.copySimulationContext(srcSimContext, "generatedSSA", false, Application.NETWORK_STOCHASTIC);
} else {
throw new RuntimeException("unexpected copy of simcontext from " + parentMathType + " to " + mathType);
}
bioModel.addSimulationContext(simContext);
}
MathMappingCallback mathMappingCallback = new MathMappingCallback() {
@Override
public void setProgressFraction(float fractionDone) {
}
@Override
public void setMessage(String message) {
}
@Override
public boolean isInterrupted() {
return false;
}
};
MathMapping mathMapping = simContext.createNewMathMapping(mathMappingCallback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
MathDescription mathDesc = mathMapping.getMathDescription(mathMappingCallback);
simContext.setMathDescription(mathDesc);
if (simContext.isInsufficientIterations()) {
networkGenProbs = "insufficientIterations";
} else if (simContext.isInsufficientMaxMolecules()) {
networkGenProbs = "insufficientMaxMolecules";
}
File baseDirectory = StochtestFileUtils.createDirFile(baseDir, stochtestRun);
try {
OutputTimeSpec outputTimeSpec = new UniformOutputTimeSpec(0.5);
double endTime = 10.0;
computeTrials(simContext, stochtestRun, baseDirectory, outputTimeSpec, endTime, numTrials);
StochtestDbUtils.finalizeAcceptedStochtestRun(conFactory, stochtestRun, StochtestRun.StochtestRunStatus.complete, null, networkGenProbs);
} finally {
StochtestFileUtils.clearDir(baseDirectory);
}
} catch (Exception e) {
StochtestDbUtils.finalizeAcceptedStochtestRun(conFactory, stochtestRun, StochtestRun.StochtestRunStatus.failed, e.getMessage(), networkGenProbs);
//
if (biomodelXML != null) {
XmlUtil.writeXMLStringToFile(biomodelXML, new File(baseDir, "stochtestrun_" + stochtestRun.stochtest.key + ".vcml").getPath(), false);
}
//
// write exception trace to .txt file
//
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
e.printStackTrace(printWriter);
printWriter.flush();
System.out.println(stringWriter.getBuffer().toString());
XmlUtil.writeXMLStringToFile(stringWriter.getBuffer().toString(), new File(baseDir, "stochtestrun_" + stochtestRun.stochtest.key + "_error.txt").getPath(), false);
}
} else {
System.out.println("no jobs waiting");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Aggregations