use of cbit.vcell.xml.XmlParseException in project vcell by virtualcell.
the class VCellClientDataServiceImpl method getSimsFromOpenModels.
@Override
public List<SimulationDataSetRef> getSimsFromOpenModels() {
ArrayList<SimulationDataSetRef> simulationDataSetRefs = new ArrayList<SimulationDataSetRef>();
for (TopLevelWindowManager windowManager : vcellClient.getMdiManager().getWindowManagers()) {
Simulation[] simulations = null;
VCDocument modelDocument = null;
if (windowManager instanceof BioModelWindowManager) {
BioModelWindowManager selectedBioWindowManager = (BioModelWindowManager) windowManager;
BioModel bioModel = selectedBioWindowManager.getBioModel();
simulations = bioModel.getSimulations();
modelDocument = bioModel;
// simOwnerCount = bioModel.getNumSimulationContexts();
} else if (windowManager instanceof MathModelWindowManager) {
MathModelWindowManager selectedMathWindowManager = (MathModelWindowManager) windowManager;
MathModel mathModel = selectedMathWindowManager.getMathModel();
simulations = mathModel.getSimulations();
modelDocument = mathModel;
// simOwnerCount = 1;
}
if (simulations != null) {
for (Simulation simulation : simulations) {
if (!isVtkSupported(simulation)) {
continue;
}
Origin origin = simulation.getMathDescription().getGeometry().getOrigin();
Extent extent = simulation.getMathDescription().getGeometry().getExtent();
SimulationInfo simInfo = simulation.getSimulationInfo();
SimulationStatus simStatus = vcellClient.getRequestManager().getServerSimulationStatus(simInfo);
for (int jobIndex = 0; jobIndex < simulation.getScanCount(); jobIndex++) {
if (simStatus != null && simStatus.getHasData()) {
SimulationDataSetRef simulationDataSetReference = VCellClientDataServiceImpl.createSimulationDataSetRef(simulation, modelDocument, jobIndex, false);
simulationDataSetRefs.add(simulationDataSetReference);
}
}
}
}
}
File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
String[] simtaskFilenames = localSimDir.list((dir, name) -> (name.endsWith(".simtask.xml")));
for (String simtaskFilename : simtaskFilenames) {
try {
SimulationTask simTask = XmlHelper.XMLToSimTask(org.apache.commons.io.FileUtils.readFileToString(new File(localSimDir, simtaskFilename)));
VCDocument modelDocument = null;
SimulationDataSetRef simulationDataSetReference = VCellClientDataServiceImpl.createSimulationDataSetRef(simTask.getSimulation(), modelDocument, simTask.getSimulationJob().getJobIndex(), true);
simulationDataSetRefs.add(simulationDataSetReference);
} catch (ExpressionException | XmlParseException | IOException e) {
e.printStackTrace();
}
}
return simulationDataSetRefs;
}
use of cbit.vcell.xml.XmlParseException in project vcell by virtualcell.
the class HTCSolver method writeJavaInputFile.
protected void writeJavaInputFile() throws SolverException {
PrintWriter pw = null;
try {
File inputFile = new File(getBaseName() + JAVA_INPUT_EXTENSION);
if (!inputFile.exists()) {
// write input file which is just xml
String xmlString = XmlHelper.simToXML(simTask.getSimulation());
pw = new PrintWriter(inputFile);
pw.println(xmlString);
pw.close();
}
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new SolverException(e.getMessage());
} catch (FileNotFoundException e) {
e.printStackTrace(System.out);
throw new SolverException(e.getMessage());
} finally {
if (pw != null) {
pw.close();
}
}
}
use of cbit.vcell.xml.XmlParseException in project vcell by virtualcell.
the class StochtestCompareService method compareOne.
public void compareOne() throws IllegalArgumentException, SQLException, DataAccessException, XmlParseException, PropertyVetoException, ExpressionException, MappingException, GeometryException, ImageException, IOException {
StochtestCompare stochtestCompare = StochtestDbUtils.acceptNextWaitingStochtestCompare(conFactory);
String biomodelXML = null;
if (stochtestCompare != null) {
try {
StochtestRun stochtestRun1 = StochtestDbUtils.getStochtestRun(conFactory, stochtestCompare.stochtestRun1ref);
StochtestRun stochtestRun2 = StochtestDbUtils.getStochtestRun(conFactory, stochtestCompare.stochtestRun2ref);
if (stochtestRun1.status != StochtestRunStatus.complete) {
throw new RuntimeException("incomplete run status found: " + stochtestRun1.status.name());
}
if (stochtestRun2.status != StochtestRunStatus.complete) {
throw new RuntimeException("incomplete run status found: " + stochtestRun2.status.name());
}
TimeSeriesMultitrialData data1 = StochtestFileUtils.readData(StochtestFileUtils.getStochtestRunDataFile(baseDir, stochtestRun1));
TimeSeriesMultitrialData data2 = StochtestFileUtils.readData(StochtestFileUtils.getStochtestRunDataFile(baseDir, stochtestRun2));
SummaryStatistics results = TimeSeriesMultitrialData.statisticsSummary(data1, data2);
XmlUtil.writeXMLStringToFile(results.results(), new File(baseDir, "stochtestcompare_" + stochtestCompare.key + "_summary.txt").getPath(), false);
StochtestFileUtils.writeVarDiffData(new File(baseDir, "stochtestcompare_" + stochtestCompare.key + "_vardiff.csv"), data1, data2);
StochtestFileUtils.writeKolmogorovSmirnovTest(new File(baseDir, "stochtestcompare_" + stochtestCompare.key + "_kolmogorovSmirnov.csv"), data1, data2);
StochtestFileUtils.writeChiSquareTest(new File(baseDir, "stochtestcompare_" + stochtestCompare.key + "_chiSquared.csv"), data1, data2);
StochtestCompareStatus status = (results.pass()) ? StochtestCompareStatus.not_verydifferent : StochtestCompareStatus.verydifferent;
StochtestDbUtils.finalizeAcceptedStochtestCompare(conFactory, stochtestCompare, status, null, results);
} catch (Exception e) {
StochtestDbUtils.finalizeAcceptedStochtestCompare(conFactory, stochtestCompare, StochtestCompare.StochtestCompareStatus.failed, e.getMessage(), null);
//
// 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_" + stochtestCompare.key + "_error.txt").getPath(), false);
}
} else {
System.out.println("no compare jobs waiting");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
use of cbit.vcell.xml.XmlParseException 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.xml.XmlParseException in project vcell by virtualcell.
the class MicroscopyXmlReader method getUShortImage.
/**
* This method returns a VCIMage object from a XML representation.
* Creation date: (3/16/2001 3:41:24 PM)
* @param param org.jdom.Element
* @return VCImage
* @throws XmlParseException
*/
private UShortImage getUShortImage(Element param) throws XmlParseException {
// get the attributes
Element tempelement = param.getChild(XMLTags.ImageDataTag);
int aNumX = Integer.parseInt(tempelement.getAttributeValue(XMLTags.XAttrTag));
int aNumY = Integer.parseInt(tempelement.getAttributeValue(XMLTags.YAttrTag));
int aNumZ = Integer.parseInt(tempelement.getAttributeValue(XMLTags.ZAttrTag));
int compressSize = Integer.parseInt(tempelement.getAttributeValue(XMLTags.CompressedSizeTag));
final int BYTES_PER_SHORT = 2;
int UNCOMPRESSED_SIZE_BYTES = aNumX * aNumY * aNumZ * BYTES_PER_SHORT;
// getpixels
String hexEncodedBytes = tempelement.getText();
byte[] rawBytes = org.vcell.util.Hex.toBytes(hexEncodedBytes);
ByteArrayInputStream rawByteArrayInputStream = new ByteArrayInputStream(rawBytes);
InputStream rawInputStream = rawByteArrayInputStream;
if (compressSize != UNCOMPRESSED_SIZE_BYTES) {
rawInputStream = new InflaterInputStream(rawByteArrayInputStream);
}
byte[] shortsAsBytes = new byte[UNCOMPRESSED_SIZE_BYTES];
int readCount = 0;
try {
while ((readCount += rawInputStream.read(shortsAsBytes, readCount, shortsAsBytes.length - readCount)) != shortsAsBytes.length) {
}
} catch (Exception e) {
e.printStackTrace();
throw new XmlParseException("error reading image pixels: ", e);
} finally {
if (rawInputStream != null) {
try {
rawInputStream.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
ByteBuffer byteBuffer = ByteBuffer.wrap(shortsAsBytes);
short[] shortPixels = new short[aNumX * aNumY * aNumZ];
for (int i = 0; i < shortPixels.length; i++) {
shortPixels[i] = byteBuffer.getShort();
}
Element extentElement = param.getChild(XMLTags.ExtentTag);
Extent extent = null;
if (extentElement != null) {
extent = vcellXMLReader.getExtent(extentElement);
}
Element originElement = param.getChild(XMLTags.OriginTag);
Origin origin = null;
if (originElement != null) {
origin = vcellXMLReader.getOrigin(originElement);
}
// //set attributes
// String name = this.unMangle( param.getAttributeValue(XMLTags.NameAttrTag) );
// String annotation = param.getChildText(XMLTags.AnnotationTag);
UShortImage newimage;
try {
newimage = new UShortImage(shortPixels, origin, extent, aNumX, aNumY, aNumZ);
} catch (ImageException e) {
e.printStackTrace();
throw new XmlParseException("error reading image", e);
}
return newimage;
}
Aggregations