use of cbit.vcell.geometry.GeometryException 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();
}
}
}
use of cbit.vcell.geometry.GeometryException in project vcell by virtualcell.
the class ClientRequestManager method createMathModelFromApplication.
/**
* Insert the method's description here.
* Creation date: (5/24/2004 12:22:11 PM)
* @param windowID java.lang.String
*/
public void createMathModelFromApplication(final BioModelWindowManager requester, final String name, final SimulationContext simContext) {
if (simContext == null) {
PopupGenerator.showErrorDialog(requester, "Selected Application is null, cannot generate corresponding math model");
return;
}
switch(simContext.getApplicationType()) {
case NETWORK_STOCHASTIC:
break;
case RULE_BASED_STOCHASTIC:
case NETWORK_DETERMINISTIC:
}
AsynchClientTask task1 = new AsynchClientTask("Creating MathModel from BioModel Application", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
MathModel newMathModel = new MathModel(null);
// Get corresponding mathDesc to create new mathModel.
MathDescription mathDesc = simContext.getMathDescription();
MathDescription newMathDesc = null;
newMathDesc = new MathDescription(name + "_" + (new java.util.Random()).nextInt());
try {
if (mathDesc.getGeometry().getDimension() > 0 && mathDesc.getGeometry().getGeometrySurfaceDescription().getGeometricRegions() == null) {
mathDesc.getGeometry().getGeometrySurfaceDescription().updateAll();
}
} catch (ImageException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Geometric surface generation error:\n" + e.getMessage());
} catch (GeometryException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Geometric surface generation error:\n" + e.getMessage());
}
newMathDesc.setGeometry(mathDesc.getGeometry());
newMathDesc.read_database(new CommentStringTokenizer(mathDesc.getVCML_database()));
newMathDesc.isValid();
newMathModel.setName(name);
newMathModel.setMathDescription(newMathDesc);
hashTable.put("newMathModel", newMathModel);
}
};
AsynchClientTask task2 = new AsynchClientTask("Creating MathModel from BioModel Application", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
MathModel newMathModel = (MathModel) hashTable.get("newMathModel");
DocumentWindowManager windowManager = createDocumentWindowManager(newMathModel);
if (simContext.getBioModel().getVersion() != null) {
((MathModelWindowManager) windowManager).setCopyFromBioModelAppVersionableTypeVersion(new VersionableTypeVersion(VersionableType.BioModelMetaData, simContext.getBioModel().getVersion()));
}
DocumentWindow dw = getMdiManager().createNewDocumentWindow(windowManager);
setFinalWindow(hashTable, dw);
}
};
ClientTaskDispatcher.dispatch(requester.getComponent(), new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, false);
}
use of cbit.vcell.geometry.GeometryException in project vcell by virtualcell.
the class SmoldynFileWriter method write.
@Override
public void write(String[] parameterNames) throws ExpressionException, MathException, SolverException, DataAccessException, IOException, ImageException, PropertyVetoException, GeometryException {
init();
setupMolecules();
if (bUseMessaging) {
writeJms(simulation);
}
writeRandomSeed();
writeSpecies();
writeDiffusions();
writeGraphicsOpenGL();
if (simulation.getSolverTaskDescription().getSmoldynSimulationOptions().isUseHighResolutionSample()) {
try {
writeHighResVolumeSamples();
} catch (Exception ex) {
ex.printStackTrace(System.out);
throw new SolverException(ex.getMessage() + "\n" + "Problem may be solved by disable \'fast mesh sampling\'. It may take much longer time to complete the simulation." + "\n" + "Select \'Edit Simulation\' -> \'Solver\' -> \'Advanced Solver Options\' -> uncheck \'fast mesh sampling\'.");
}
}
writeSurfaces();
writeCompartments();
// needs to be after dim=3 in input file (after geometry is written).
writeDrifts();
writeReactions();
writeMolecules();
writeSimulationTimes();
writeRuntimeCommands();
writeSimulationSettings();
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.end_file);
// SimulationWriter.write(SimulationJobToSmoldyn.convertSimulationJob(simulationJob, outputFile), printWriter, simulationJob);
}
Aggregations