Search in sources :

Example 26 with SpatialObject

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;
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) GeneratedSpeciesSymbolTableEntry(cbit.vcell.mapping.NetworkTransformer.GeneratedSpeciesSymbolTableEntry) SpatialQuantity(cbit.vcell.mapping.spatial.SpatialObject.SpatialQuantity) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject)

Example 27 with SpatialObject

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();
        }
    }
}
Also used : VolumeRegionObject(cbit.vcell.mapping.spatial.VolumeRegionObject) SurfaceClass(cbit.vcell.geometry.SurfaceClass) ArrayList(java.util.ArrayList) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) GeometricRegion(cbit.vcell.geometry.surface.GeometricRegion) Geometry(cbit.vcell.geometry.Geometry) PropertyVetoException(java.beans.PropertyVetoException) PointObject(cbit.vcell.mapping.spatial.PointObject) SubVolume(cbit.vcell.geometry.SubVolume) SurfaceRegionObject(cbit.vcell.mapping.spatial.SurfaceRegionObject) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion)

Example 28 with SpatialObject

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]);
}
Also used : VolumeRegionObject(cbit.vcell.mapping.spatial.VolumeRegionObject) Element(org.jdom.Element) QuantityCategory(cbit.vcell.mapping.spatial.SpatialObject.QuantityCategory) ArrayList(java.util.ArrayList) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) PointObject(cbit.vcell.mapping.spatial.PointObject) SubVolume(cbit.vcell.geometry.SubVolume) CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) SurfaceRegionObject(cbit.vcell.mapping.spatial.SurfaceRegionObject)

Example 29 with SpatialObject

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;
}
Also used : Xmlproducer(cbit.vcell.xml.Xmlproducer) AssignmentRule(cbit.vcell.mapping.AssignmentRule) ReactionRuleSpec(cbit.vcell.mapping.ReactionRuleSpec) Element(org.jdom.Element) XmlParseException(cbit.vcell.xml.XmlParseException) SimulationContextParameter(cbit.vcell.mapping.SimulationContext.SimulationContextParameter) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) RateRule(cbit.vcell.mapping.RateRule) BioEvent(cbit.vcell.mapping.BioEvent) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Aggregations

SpatialObject (cbit.vcell.mapping.spatial.SpatialObject)29 SpatialProcess (cbit.vcell.mapping.spatial.processes.SpatialProcess)18 SurfaceRegionObject (cbit.vcell.mapping.spatial.SurfaceRegionObject)9 VolumeRegionObject (cbit.vcell.mapping.spatial.VolumeRegionObject)9 BioEvent (cbit.vcell.mapping.BioEvent)8 SimulationContext (cbit.vcell.mapping.SimulationContext)8 PointObject (cbit.vcell.mapping.spatial.PointObject)8 AssignmentRule (cbit.vcell.mapping.AssignmentRule)7 RateRule (cbit.vcell.mapping.RateRule)7 ReactionStep (cbit.vcell.model.ReactionStep)7 Geometry (cbit.vcell.geometry.Geometry)6 SimulationContextParameter (cbit.vcell.mapping.SimulationContext.SimulationContextParameter)6 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)6 StructureMapping (cbit.vcell.mapping.StructureMapping)6 ArrayList (java.util.ArrayList)6 Element (org.jdom.Element)6 ReactionRule (cbit.vcell.model.ReactionRule)5 SpeciesContext (cbit.vcell.model.SpeciesContext)5 NetworkConstraints (org.vcell.model.rbm.NetworkConstraints)5 BioModel (cbit.vcell.biomodel.BioModel)4