use of cbit.vcell.geometry.GeometryException in project vcell by virtualcell.
the class ClientRequestManager method createMathModel.
/**
* Insert the method's description here. Creation date: (5/24/2004 12:22:11 PM)
*
* @param windowID java.lang.String
*/
private MathModel createMathModel(String name, Geometry geometry) {
MathModel mathModel = new MathModel(null);
MathDescription mathDesc = mathModel.getMathDescription();
try {
mathDesc.setGeometry(geometry);
if (geometry.getDimension() == 0) {
mathDesc.addSubDomain(new CompartmentSubDomain("Compartment", CompartmentSubDomain.NON_SPATIAL_PRIORITY));
} else {
try {
if (geometry.getDimension() > 0 && geometry.getGeometrySurfaceDescription().getGeometricRegions() == null) {
geometry.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());
}
SubVolume[] subVolumes = geometry.getGeometrySpec().getSubVolumes();
for (int i = 0; i < subVolumes.length; i++) {
mathDesc.addSubDomain(new CompartmentSubDomain(subVolumes[i].getName(), subVolumes[i].getHandle()));
}
//
// add only those MembraneSubDomains corresponding to surfaces that acutally
// exist in geometry.
//
GeometricRegion[] regions = geometry.getGeometrySurfaceDescription().getGeometricRegions();
for (int i = 0; i < regions.length; i++) {
if (regions[i] instanceof SurfaceGeometricRegion) {
SurfaceGeometricRegion surfaceRegion = (SurfaceGeometricRegion) regions[i];
SubVolume subVolume1 = ((VolumeGeometricRegion) surfaceRegion.getAdjacentGeometricRegions()[0]).getSubVolume();
SubVolume subVolume2 = ((VolumeGeometricRegion) surfaceRegion.getAdjacentGeometricRegions()[1]).getSubVolume();
CompartmentSubDomain compartment1 = mathDesc.getCompartmentSubDomain(subVolume1.getName());
CompartmentSubDomain compartment2 = mathDesc.getCompartmentSubDomain(subVolume2.getName());
MembraneSubDomain membraneSubDomain = mathDesc.getMembraneSubDomain(compartment1, compartment2);
if (membraneSubDomain == null) {
SurfaceClass surfaceClass = geometry.getGeometrySurfaceDescription().getSurfaceClass(subVolume1, subVolume2);
membraneSubDomain = new MembraneSubDomain(compartment1, compartment2, surfaceClass.getName());
mathDesc.addSubDomain(membraneSubDomain);
}
}
}
}
mathDesc.isValid();
mathModel.setName(name);
} catch (Exception e) {
e.printStackTrace(System.out);
}
return mathModel;
}
use of cbit.vcell.geometry.GeometryException in project vcell by virtualcell.
the class XmlReader method getGeometry.
/**
* This method returns a Geometry object from a XML representation.
* Creation date: (4/26/2001 12:12:18 PM)
* @return cbit.vcell.geometry.Geometry
* @param param org.jdom.Element
* @exception cbit.vcell.xml.XmlParseException The exception description.
*/
public Geometry getGeometry(Element param) throws XmlParseException {
// Get the Extent object
Extent newextent = getExtent(param.getChild(XMLTags.ExtentTag, vcNamespace));
// Get VCimage information
VCImage newimage = null;
if (param.getChild(XMLTags.ImageTag, vcNamespace) != null) {
try {
newimage = getVCImage(param.getChild(XMLTags.ImageTag, vcNamespace), newextent);
} catch (Throwable e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
// Get attributes
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
int newdimension = Integer.parseInt(param.getAttributeValue(XMLTags.DimensionAttrTag));
// Get Version
Version version = getVersion(param.getChild(XMLTags.VersionTag, vcNamespace));
// Try to construct the geometry upon four different cases
Geometry newgeometry = null;
if (version != null && newimage != null) {
newgeometry = new Geometry(version, newimage);
} else if (version != null) {
newgeometry = new Geometry(version, newdimension);
} else if (newimage != null) {
newgeometry = new Geometry(name, newimage);
} else {
newgeometry = new Geometry(name, newdimension);
}
// set attributes
try {
if (!newgeometry.getName().equalsIgnoreCase(name)) {
newgeometry.setName(name);
}
// String annotation = param.getAttributeValue(XMLTags.AnnotationAttrTag);
// if (annotation!=null) {
// newgeometry.setDescription( unMangle(annotation) );
// }
// Add annotation
String annotation = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
if (annotation != null && annotation.length() > 0) {
newgeometry.setDescription(unMangle(annotation));
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException occurred when setting the name " + name + " to a Geometry object!", e);
}
// Add the Extent
try {
newgeometry.getGeometrySpec().setExtent(newextent);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException occurred while trying to set the Extent for the Geometry " + name, e);
}
// Add the Origin
newgeometry.getGeometrySpec().setOrigin(getOrigin(param.getChild(XMLTags.OriginTag, vcNamespace)));
// Add the SubVolumes
List<Element> children = param.getChildren(XMLTags.SubVolumeTag, vcNamespace);
SubVolume[] newsubvolumes = new SubVolume[children.size()];
int subvolumeCounter = 0;
for (Element child : children) {
newsubvolumes[subvolumeCounter] = getSubVolume(child);
subvolumeCounter++;
}
try {
newgeometry.getGeometrySpec().setSubVolumes(newsubvolumes);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException was generated when ading the subvolumes to the Geometry " + name, e);
}
if (newgeometry.getDimension() > 0) {
// Add SurfaceClasses
List<Element> surfaceClassChildren = param.getChildren(XMLTags.SurfaceClassTag, vcNamespace);
SurfaceClass[] newSurfaceClassArr = new SurfaceClass[surfaceClassChildren.size()];
int surfClassCounter = 0;
for (Element surfClassChild : surfaceClassChildren) {
newSurfaceClassArr[surfClassCounter] = getSurfaceClass(surfClassChild, newgeometry);
surfClassCounter++;
}
try {
newgeometry.getGeometrySurfaceDescription().setSurfaceClasses(newSurfaceClassArr);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException was generated when ading the subvolumes to the Geometry " + name, e);
}
}
// read Filaments (if any)
Iterator<Element> iterator = param.getChildren(XMLTags.FilamentTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element tempElement = iterator.next();
String filname = unMangle(tempElement.getAttributeValue(XMLTags.NameAttrTag));
Iterator<Element> curveiterator = tempElement.getChildren().iterator();
while (curveiterator.hasNext()) {
ControlPointCurve curve = getControlPointCurve(curveiterator.next());
newgeometry.getGeometrySpec().getFilamentGroup().addCurve(filname, curve);
}
}
// read Surface description (if any)
Element sd = param.getChild(XMLTags.SurfaceDescriptionTag, vcNamespace);
if (sd != null) {
GeometrySurfaceDescription dummy = getGeometrySurfaceDescription(sd, newgeometry);
}
try {
newgeometry.precomputeAll(new GeometryThumbnailImageFactoryAWT(), false, false);
} catch (GeometryException e) {
e.printStackTrace(System.out);
} catch (ImageException e) {
e.printStackTrace(System.out);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
}
return newgeometry;
}
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 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.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);
}
Aggregations