use of cbit.vcell.mapping.spatial.SpatialObject in project vcell by virtualcell.
the class SimulationContext method getLocalEntry.
/**
* Insert the method's description here.
* Creation date: (12/8/2003 10:17:30 AM)
* @return SymbolTableEntry
* @param identifier java.lang.String
*/
public SymbolTableEntry getLocalEntry(java.lang.String identifier) {
// try field function(s) first
if (identifier.equals(MathFunctionDefinitions.fieldFunctionDefinition.getName())) {
return MathFunctionDefinitions.fieldFunctionDefinition;
}
SymbolTableEntry ste = getSimulationContextParameter(identifier);
if (ste != null) {
return ste;
}
for (SpatialObject spatialObject : spatialObjects) {
SpatialQuantity appQuantity = spatialObject.getSpatialQuantity(identifier);
if (appQuantity != null) {
return appQuantity;
}
}
// if dataContext parameter exists, then return it
ste = getDataContext().getDataSymbol(identifier);
if (ste != null) {
return ste;
}
// if not found in simulationContext, try model level
ste = getModel().getLocalEntry(identifier);
if (ste != null) {
return ste;
}
return null;
}
use of cbit.vcell.mapping.spatial.SpatialObject in project vcell by virtualcell.
the class SimulationContext method refreshSpatialObjects.
public void refreshSpatialObjects() {
Geometry geometry = getGeometry();
if (geometry != null && geometry.getGeometrySurfaceDescription() != null && geometry.getGeometrySurfaceDescription().getGeometricRegions() != null) {
ArrayList<SpatialObject> unmappedSpatialObjects = new ArrayList<SpatialObject>(Arrays.asList(spatialObjects));
ArrayList<GeometricRegion> mappedRegions = new ArrayList<GeometricRegion>();
//
for (SpatialObject spatialObject : spatialObjects) {
if (spatialObject instanceof VolumeRegionObject) {
VolumeRegionObject volRegionObj = (VolumeRegionObject) spatialObject;
SubVolume existingSubvolume = volRegionObj.getSubVolume();
Integer existingRegionID = volRegionObj.getRegionID();
SubVolume newSubvolume = geometry.getGeometrySpec().getSubVolume(existingSubvolume.getName());
if (newSubvolume != null && geometry.getGeometrySurfaceDescription().getGeometricRegions() != null) {
for (GeometricRegion newRegion : geometry.getGeometrySurfaceDescription().getGeometricRegions(newSubvolume)) {
VolumeGeometricRegion newVolRegion = (VolumeGeometricRegion) newRegion;
if (newVolRegion.getRegionID() == existingRegionID) {
((VolumeRegionObject) spatialObject).setSubVolume(newSubvolume);
mappedRegions.add(newVolRegion);
unmappedSpatialObjects.remove(spatialObject);
}
}
}
}
if (spatialObject instanceof SurfaceRegionObject) {
SurfaceRegionObject surfaceRegionObj = (SurfaceRegionObject) spatialObject;
SubVolume existingInsideSubvolume = surfaceRegionObj.getInsideSubVolume();
SubVolume existingOutsideSubvolume = surfaceRegionObj.getOutsideSubVolume();
Integer existingInsideRegionID = surfaceRegionObj.getInsideRegionID();
Integer existingOutsideRegionID = surfaceRegionObj.getOutsideRegionID();
SubVolume newInsideSubvolume = geometry.getGeometrySpec().getSubVolume(existingInsideSubvolume.getName());
SubVolume newOutsideSubvolume = geometry.getGeometrySpec().getSubVolume(existingOutsideSubvolume.getName());
if (newInsideSubvolume != null && newOutsideSubvolume != null) {
SurfaceClass surfaceClass = geometry.getGeometrySurfaceDescription().getSurfaceClass(newInsideSubvolume, newOutsideSubvolume);
for (GeometricRegion newRegion : geometry.getGeometrySurfaceDescription().getGeometricRegions(surfaceClass)) {
SurfaceGeometricRegion newSurfaceRegion = (SurfaceGeometricRegion) newRegion;
GeometricRegion[] adjacentRegions = newSurfaceRegion.getAdjacentGeometricRegions();
if (adjacentRegions.length == 2 && adjacentRegions[0] instanceof VolumeGeometricRegion && adjacentRegions[1] instanceof VolumeGeometricRegion) {
VolumeGeometricRegion adjVolRegion0 = (VolumeGeometricRegion) adjacentRegions[0];
VolumeGeometricRegion adjVolRegion1 = (VolumeGeometricRegion) adjacentRegions[1];
if (adjVolRegion0.getSubVolume() == newInsideSubvolume && adjVolRegion0.getRegionID() == existingInsideRegionID && adjVolRegion1.getSubVolume() == newOutsideSubvolume && adjVolRegion1.getRegionID() == existingOutsideRegionID) {
surfaceRegionObj.setInsideSubVolume(newInsideSubvolume);
surfaceRegionObj.setOutsideSubVolume(newOutsideSubvolume);
mappedRegions.add(newSurfaceRegion);
unmappedSpatialObjects.remove(spatialObject);
}
if (adjVolRegion0.getSubVolume() == newOutsideSubvolume && adjVolRegion0.getRegionID() == existingOutsideRegionID && adjVolRegion1.getSubVolume() == newInsideSubvolume && adjVolRegion1.getRegionID() == existingInsideRegionID) {
surfaceRegionObj.setInsideSubVolume(newInsideSubvolume);
surfaceRegionObj.setOutsideSubVolume(newOutsideSubvolume);
mappedRegions.add(newSurfaceRegion);
unmappedSpatialObjects.remove(spatialObject);
}
}
}
}
}
}
//
// for geometric regions not represented as spatial objects, add them
//
ArrayList<GeometricRegion> unmappedRegions = new ArrayList<GeometricRegion>(Arrays.asList(geometry.getGeometrySurfaceDescription().getGeometricRegions()));
unmappedRegions.removeAll(mappedRegions);
for (GeometricRegion unmappedRegion : unmappedRegions) {
if (unmappedRegion instanceof VolumeGeometricRegion) {
VolumeGeometricRegion unmappedVolRegion = (VolumeGeometricRegion) unmappedRegion;
try {
VolumeRegionObject vro = new VolumeRegionObject(unmappedVolRegion.getSubVolume(), unmappedVolRegion.getRegionID(), this);
addSpatialObject(vro);
} catch (PropertyVetoException e) {
e.printStackTrace();
}
} else if (unmappedRegion instanceof SurfaceGeometricRegion) {
SurfaceGeometricRegion unmappedSurfRegion = (SurfaceGeometricRegion) unmappedRegion;
GeometricRegion[] adjacentRegions = unmappedSurfRegion.getAdjacentGeometricRegions();
if (adjacentRegions.length == 2 && adjacentRegions[0] instanceof VolumeGeometricRegion && adjacentRegions[1] instanceof VolumeGeometricRegion) {
VolumeGeometricRegion volRegion0 = (VolumeGeometricRegion) adjacentRegions[0];
VolumeGeometricRegion volRegion1 = (VolumeGeometricRegion) adjacentRegions[1];
SubVolume insideSubVolume = volRegion0.getSubVolume();
SubVolume outsideSubVolume = volRegion1.getSubVolume();
int insideRegionID = volRegion0.getRegionID();
int outsideRegionID = volRegion1.getRegionID();
SurfaceClass surfaceClass = geometry.getGeometrySurfaceDescription().getSurfaceClass(insideSubVolume, outsideSubVolume);
try {
addSpatialObject(new SurfaceRegionObject(insideSubVolume, insideRegionID, outsideSubVolume, outsideRegionID, this));
} catch (PropertyVetoException e) {
e.printStackTrace();
}
}
}
}
//
try {
for (SpatialObject unmappedSpatialObject : unmappedSpatialObjects) {
if (unmappedSpatialObject instanceof VolumeRegionObject) {
System.err.println("volume region spatial object '" + unmappedSpatialObject.getName() + "' not found in geometry, delete.");
removeSpatialObject(unmappedSpatialObject);
}
if (unmappedSpatialObject instanceof SurfaceRegionObject) {
System.err.println("surface region spatial object '" + unmappedSpatialObject.getName() + "' not found in geometry, delete.");
removeSpatialObject(unmappedSpatialObject);
}
if (unmappedSpatialObject instanceof PointObject) {
System.err.println("point spatial object '" + unmappedSpatialObject.getName() + "' not found in geometry, this is expected.");
// removeSpatialObject(unmappedSpatialObject);
}
}
} catch (PropertyVetoException e) {
e.printStackTrace();
}
}
}
use of cbit.vcell.mapping.spatial.SpatialObject in project vcell by virtualcell.
the class XmlReader method getSpatialObjects.
public SpatialObject[] getSpatialObjects(SimulationContext simContext, Element spatialObjectsElement) throws XmlParseException {
Iterator<Element> spatialObjectElementIterator = spatialObjectsElement.getChildren(XMLTags.SpatialObjectTag, vcNamespace).iterator();
ArrayList<SpatialObject> spatialObjectList = new ArrayList<SpatialObject>();
while (spatialObjectElementIterator.hasNext()) {
Element spatialObjectElement = (Element) spatialObjectElementIterator.next();
SpatialObject spatialObject = null;
String name = unMangle(spatialObjectElement.getAttributeValue(XMLTags.NameAttrTag));
String type = unMangle(spatialObjectElement.getAttributeValue(XMLTags.SpatialObjectTypeAttrTag));
if (type.equals(XMLTags.SpatialObjectTypeAttrValue_Point)) {
PointObject pointObject = new PointObject(name, simContext);
spatialObject = pointObject;
} else if (type.equals(XMLTags.SpatialObjectTypeAttrValue_Surface)) {
String insideSubvolumeName = unMangle(spatialObjectElement.getAttributeValue(XMLTags.SpatialObjectSubVolumeInsideAttrTag));
String insideRegionIDString = spatialObjectElement.getAttributeValue(XMLTags.SpatialObjectRegionIdInsideAttrTag);
String outsideSubvolumeName = unMangle(spatialObjectElement.getAttributeValue(XMLTags.SpatialObjectSubVolumeOutsideAttrTag));
String outsideRegionIDString = spatialObjectElement.getAttributeValue(XMLTags.SpatialObjectRegionIdOutsideAttrTag);
SubVolume insideSubvolume = null;
if (insideSubvolumeName != null) {
insideSubvolume = simContext.getGeometry().getGeometrySpec().getSubVolume(insideSubvolumeName);
}
Integer insideRegionID = null;
if (insideRegionIDString != null) {
insideRegionID = Integer.parseUnsignedInt(insideRegionIDString);
}
SubVolume outsideSubvolume = null;
if (outsideSubvolumeName != null) {
outsideSubvolume = simContext.getGeometry().getGeometrySpec().getSubVolume(outsideSubvolumeName);
}
Integer outsideRegionID = null;
if (outsideRegionIDString != null) {
outsideRegionID = Integer.parseUnsignedInt(outsideRegionIDString);
}
SurfaceRegionObject surfaceRegionObject = new SurfaceRegionObject(name, insideSubvolume, insideRegionID, outsideSubvolume, outsideRegionID, simContext);
spatialObject = surfaceRegionObject;
} else if (type.equals(XMLTags.SpatialObjectTypeAttrValue_Volume)) {
String subvolumeName = unMangle(spatialObjectElement.getAttributeValue(XMLTags.SpatialObjectSubVolumeAttrTag));
String regionIDString = spatialObjectElement.getAttributeValue(XMLTags.SpatialObjectRegionIdAttrTag);
SubVolume subvolume = null;
if (subvolumeName != null) {
subvolume = simContext.getGeometry().getGeometrySpec().getSubVolume(subvolumeName);
}
Integer regionID = null;
if (regionIDString != null) {
regionID = Integer.parseUnsignedInt(regionIDString);
}
VolumeRegionObject volumeRegionObject = new VolumeRegionObject(name, subvolume, regionID, simContext);
spatialObject = volumeRegionObject;
}
// set Quantity enables
Element quantityCategoryListElement = spatialObjectElement.getChild(XMLTags.QuantityCategoryListTag, vcNamespace);
List<Element> quantityCategoryElements = quantityCategoryListElement.getChildren(XMLTags.QuantityCategoryTag, vcNamespace);
for (Element quantityCategoryElement : quantityCategoryElements) {
String quantityCategoryName = unMangle(quantityCategoryElement.getAttributeValue(XMLTags.QuantityCategoryNameAttrTag));
Boolean enabled = Boolean.parseBoolean(quantityCategoryElement.getAttributeValue(XMLTags.QuantityCategoryEnabledAttrTag));
QuantityCategory category = QuantityCategory.fromXMLName(quantityCategoryName);
spatialObject.setQuantityCategoryEnabled(category, enabled);
}
spatialObjectList.add(spatialObject);
}
return spatialObjectList.toArray(new SpatialObject[0]);
}
use of cbit.vcell.mapping.spatial.SpatialObject in project vcell by virtualcell.
the class SimContextTable method getAppComponentsForDatabase.
/**
* getXMLStringForDatabase : this returns the XML string for the container element <AppComponents> for application-related protocols
* and other extra specifications. For now, BioEvents falls under this category, so the BioEvents element (list of bioevents)
* is obtained from the simContext (via the XMLProducer) and added as content to <AppComponents> element. The <AppComponents>
* element is converted to XML string which is the return value of this method. This string is stored in the database in the
* SimContextTable. Instead of creating new fields for each possible application component, it is convenient to store them
* all under a blanket XML element <AppComponents>.
* @param simContext
* @return
*/
public static String getAppComponentsForDatabase(SimulationContext simContext) {
Element appComponentsElement = new Element(XMLTags.ApplicationComponents);
// for now, create the element only if application is stochastic. Can change it later.
if (simContext.isStoch()) {
// add 'randomizeInitCondition' flag only if simContext is non-spatial
if (simContext.getGeometry().getDimension() == 0) {
Element appRelatedFlagsElement = new Element(XMLTags.ApplicationSpecificFlagsTag);
if (simContext.isRandomizeInitCondition()) {
appRelatedFlagsElement.setAttribute(XMLTags.RandomizeInitConditionTag, "true");
} else {
appRelatedFlagsElement.setAttribute(XMLTags.RandomizeInitConditionTag, "false");
}
appComponentsElement.addContent(appRelatedFlagsElement);
}
}
if (simContext.isInsufficientIterations()) {
appComponentsElement.setAttribute(XMLTags.InsufficientIterationsTag, "true");
} else {
appComponentsElement.setAttribute(XMLTags.InsufficientIterationsTag, "false");
}
if (simContext.isInsufficientMaxMolecules()) {
appComponentsElement.setAttribute(XMLTags.InsufficientMaxMoleculesTag, "true");
} else {
appComponentsElement.setAttribute(XMLTags.InsufficientMaxMoleculesTag, "false");
}
if (simContext.isUsingMassConservationModelReduction()) {
appComponentsElement.setAttribute(XMLTags.MassConservationModelReductionTag, "true");
} else {
appComponentsElement.setAttribute(XMLTags.MassConservationModelReductionTag, "false");
}
Xmlproducer xmlProducer = new Xmlproducer(false);
NetworkConstraints constraints = simContext.getNetworkConstraints();
if (constraints != null) {
appComponentsElement.addContent(xmlProducer.getXML(constraints, simContext));
}
// first fill in bioevents from simContext
BioEvent[] bioEvents = simContext.getBioEvents();
if (bioEvents != null && bioEvents.length > 0) {
try {
Element bioEventsElement = xmlProducer.getXML(bioEvents);
appComponentsElement.addContent(bioEventsElement);
} catch (XmlParseException e) {
throw new RuntimeException("Error generating XML for bioevents : " + e.getMessage(), e);
}
}
SimulationContextParameter[] appParams = simContext.getSimulationContextParameters();
if (appParams != null && appParams.length > 0) {
try {
Element appParamsElement = xmlProducer.getXML(appParams);
appComponentsElement.addContent(appParamsElement);
} catch (Exception e) {
throw new RuntimeException("Error generating XML for application parameters : " + e.getMessage(), e);
}
}
SpatialObject[] spatialObjects = simContext.getSpatialObjects();
if (spatialObjects != null && spatialObjects.length > 0) {
try {
Element spatialObjectsElement = xmlProducer.getXML(spatialObjects);
appComponentsElement.addContent(spatialObjectsElement);
} catch (XmlParseException e) {
throw new RuntimeException("Error generating XML for spatialObjects : " + e.getMessage(), e);
}
}
SpatialProcess[] spatialProcesses = simContext.getSpatialProcesses();
if (spatialProcesses != null && spatialProcesses.length > 0) {
try {
Element spatialProcessesElement = xmlProducer.getXML(spatialProcesses);
appComponentsElement.addContent(spatialProcessesElement);
} catch (XmlParseException e) {
throw new RuntimeException("Error generating XML for spatialProcesses : " + e.getMessage(), e);
}
}
// microscope measurements
Element element = xmlProducer.getXML(simContext.getMicroscopeMeasurement());
appComponentsElement.addContent(element);
// rate rules
RateRule[] rateRules = simContext.getRateRules();
if (rateRules != null && rateRules.length > 0) {
try {
Element rateRulesElement = xmlProducer.getXML(rateRules);
appComponentsElement.addContent(rateRulesElement);
} catch (XmlParseException e) {
throw new RuntimeException("Error generating XML for bioevents : " + e.getMessage(), e);
}
}
AssignmentRule[] assignmentRules = simContext.getAssignmentRules();
if (assignmentRules != null && assignmentRules.length > 0) {
try {
Element assignmentRulesElement = xmlProducer.getXML(assignmentRules);
appComponentsElement.addContent(assignmentRulesElement);
} catch (XmlParseException e) {
throw new RuntimeException("Error generating XML for bioevents : " + e.getMessage(), e);
}
}
// ReactionRuleSpecs
ReactionRuleSpec[] reactionRuleSpecs = simContext.getReactionContext().getReactionRuleSpecs();
if (reactionRuleSpecs != null && reactionRuleSpecs.length > 0) {
Element reactionRuleSpecsElement = xmlProducer.getXML(reactionRuleSpecs);
appComponentsElement.addContent(reactionRuleSpecsElement);
}
String appComponentsXMLStr = null;
if (appComponentsElement.getContent() != null) {
appComponentsXMLStr = XmlUtil.xmlToString(appComponentsElement);
}
return appComponentsXMLStr;
}
Aggregations