Search in sources :

Example 91 with VCUnitDefinition

use of cbit.vcell.units.VCUnitDefinition in project vcell by virtualcell.

the class XmlReader method getGeometrySurfaceDescription.

private GeometrySurfaceDescription getGeometrySurfaceDescription(Element param, Geometry geom) throws XmlParseException {
    GeometrySurfaceDescription gsd = geom.getGeometrySurfaceDescription();
    String cutoffStr = param.getAttributeValue(XMLTags.CutoffFrequencyAttrTag);
    String xDim = param.getAttributeValue(XMLTags.NumSamplesXAttrTag);
    String yDim = param.getAttributeValue(XMLTags.NumSamplesYAttrTag);
    String zDim = param.getAttributeValue(XMLTags.NumSamplesZAttrTag);
    if (cutoffStr == null || xDim == null || yDim == null || zDim == null) {
        throw new XmlParseException("Attributes for element Surface Description not properly set, under geometry: " + ((Element) param.getParent()).getAttributeValue(XMLTags.NameAttrTag));
    }
    try {
        ISize isize = new ISize(Integer.parseInt(xDim), Integer.parseInt(yDim), Integer.parseInt(zDim));
        gsd.setVolumeSampleSize(isize);
        gsd.setFilterCutoffFrequency(new Double(cutoffStr));
        // these lists are allowed to be empty.
        ArrayList<Element> memRegions = new ArrayList<Element>(param.getChildren(XMLTags.MembraneRegionTag, vcNamespace));
        ArrayList<Element> volRegions = new ArrayList<Element>(param.getChildren(XMLTags.VolumeRegionTag, vcNamespace));
        ArrayList<GeometricRegion> regions = new ArrayList<GeometricRegion>();
        GeometryUnitSystem geometryUnitSystem = geom.getUnitSystem();
        for (Element temp : volRegions) {
            String regionID = temp.getAttributeValue(XMLTags.RegionIDAttrTag);
            String name = temp.getAttributeValue(XMLTags.NameAttrTag);
            String subvolumeRef = temp.getAttributeValue(XMLTags.SubVolumeAttrTag);
            if (regionID == null || name == null || subvolumeRef == null) {
                throw new XmlParseException("Attributes for element Volume Region not properly set, under geometry: " + ((Element) param.getParent()).getAttributeValue(XMLTags.NameAttrTag));
            }
            SubVolume subvolume = geom.getGeometrySpec().getSubVolume(subvolumeRef);
            if (subvolume == null) {
                throw new XmlParseException("The subvolume " + subvolumeRef + " could not be resolved.");
            }
            double size = -1;
            VCUnitDefinition unit = null;
            String sizeStr = temp.getAttributeValue(XMLTags.SizeAttrTag);
            if (sizeStr != null) {
                size = Double.parseDouble(sizeStr);
                String unitSymbol = temp.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
                if (unitSymbol != null) {
                    unit = geometryUnitSystem.getInstance(unitSymbol);
                }
            }
            VolumeGeometricRegion vgr = new VolumeGeometricRegion(name, size, unit, subvolume, Integer.parseInt(regionID));
            regions.add(vgr);
        }
        for (Element temp : memRegions) {
            String volRegion_1 = temp.getAttributeValue(XMLTags.VolumeRegion_1AttrTag);
            String volRegion_2 = temp.getAttributeValue(XMLTags.VolumeRegion_2AttrTag);
            String name = temp.getAttributeValue(XMLTags.NameAttrTag);
            if (volRegion_1 == null || volRegion_2 == null || name == null) {
                throw new XmlParseException("Attributes for element Membrane Region not properly set, under geometry: " + ((Element) param.getParent()).getAttributeValue(XMLTags.NameAttrTag));
            }
            VolumeGeometricRegion region1 = getAdjacentVolumeRegion(regions, volRegion_1);
            VolumeGeometricRegion region2 = getAdjacentVolumeRegion(regions, volRegion_2);
            if (region1 == null || region2 == null) {
                throw new XmlParseException("Element Membrane Region refernces invalid volume regions, under geometry: " + ((Element) param.getParent()).getAttributeValue(XMLTags.NameAttrTag));
            }
            double size = -1;
            VCUnitDefinition unit = null;
            String sizeStr = temp.getAttributeValue(XMLTags.SizeAttrTag);
            if (sizeStr != null) {
                size = Double.parseDouble(sizeStr);
                String unitSymbol = temp.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
                if (unitSymbol != null) {
                    unit = geometryUnitSystem.getInstance(unitSymbol);
                }
            }
            SurfaceGeometricRegion rsl = new SurfaceGeometricRegion(name, size, unit);
            rsl.addAdjacentGeometricRegion(region1);
            region1.addAdjacentGeometricRegion(rsl);
            rsl.addAdjacentGeometricRegion(region2);
            region2.addAdjacentGeometricRegion(rsl);
            regions.add(rsl);
        }
        if (regions.size() > 0) {
            gsd.setGeometricRegions((GeometricRegion[]) regions.toArray(new GeometricRegion[regions.size()]));
        }
    } catch (Exception e) {
        System.err.println("Unable to read geometry surface description from XML, for geometry: " + ((Element) param.getParent()).getAttributeValue(XMLTags.NameAttrTag));
        e.printStackTrace();
    }
    return gsd;
}
Also used : GeometrySurfaceDescription(cbit.vcell.geometry.surface.GeometrySurfaceDescription) ISize(org.vcell.util.ISize) Element(org.jdom.Element) ArrayList(java.util.ArrayList) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) GeometryException(cbit.vcell.geometry.GeometryException) MathFormatException(cbit.vcell.math.MathFormatException) MappingException(cbit.vcell.mapping.MappingException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ModelException(cbit.vcell.model.ModelException) DataConversionException(org.jdom.DataConversionException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) GeometricRegion(cbit.vcell.geometry.surface.GeometricRegion) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) GeometryUnitSystem(cbit.vcell.geometry.GeometryUnitSystem) SubVolume(cbit.vcell.geometry.SubVolume) CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion)

Example 92 with VCUnitDefinition

use of cbit.vcell.units.VCUnitDefinition in project vcell by virtualcell.

the class Xmlproducer method getXML.

// For events in SimulationContext - XML is very similar to math events
public Element getXML(BioEvent[] bioEvents) throws XmlParseException {
    Element bioEventsElement = new Element(XMLTags.BioEventsTag);
    for (int i = 0; i < bioEvents.length; i++) {
        Element eventElement = new Element(XMLTags.BioEventTag);
        eventElement.setAttribute(XMLTags.NameAttrTag, mangle(bioEvents[i].getName()));
        String triggerType = bioEvents[i].getTriggerType().getXmlName();
        // Add atributes
        eventElement.setAttribute(XMLTags.BioEventTriggerTypeAttrTag, triggerType);
        eventElement.setAttribute(XMLTags.UseValuesFromTriggerTimeAttrTag, Boolean.toString(bioEvents[i].getUseValuesFromTriggerTime()));
        // Add BioEvent Parameters
        LocalParameter[] parameters = bioEvents[i].getEventParameters();
        for (LocalParameter parm : parameters) {
            if (parm.getExpression() != null) {
                Element tempparameter = new Element(XMLTags.ParameterTag);
                // Get parameter attributes
                tempparameter.setAttribute(XMLTags.NameAttrTag, mangle(parm.getName()));
                tempparameter.setAttribute(XMLTags.ParamRoleAttrTag, bioEvents[i].getParameterType(parm).getRoleXmlName());
                VCUnitDefinition unit = parm.getUnitDefinition();
                if (unit != null) {
                    tempparameter.setAttribute(XMLTags.VCUnitDefinitionAttrTag, unit.getSymbol());
                }
                tempparameter.addContent(mangleExpression(parm.getExpression()));
                // Add the parameter to the general kinetics object
                eventElement.addContent(tempparameter);
            }
        }
        ArrayList<BioEvent.EventAssignment> eventAssignmentsList = bioEvents[i].getEventAssignments();
        if (eventAssignmentsList != null) {
            for (BioEvent.EventAssignment eventAssignment : eventAssignmentsList) {
                Element eventAssignmentElement = new Element(XMLTags.EventAssignmentTag);
                eventAssignmentElement.setAttribute(XMLTags.EventAssignmentVariableAttrTag, eventAssignment.getTarget().getName());
                eventAssignmentElement.addContent(mangleExpression(eventAssignment.getAssignmentExpression()));
                eventElement.addContent(eventAssignmentElement);
            }
        }
        bioEventsElement.addContent(eventElement);
    }
    System.out.println(XmlUtil.xmlToString(bioEventsElement));
    return bioEventsElement;
}
Also used : LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) EventAssignment(cbit.vcell.math.Event.EventAssignment) Element(org.jdom.Element) BioEvent(cbit.vcell.mapping.BioEvent)

Example 93 with VCUnitDefinition

use of cbit.vcell.units.VCUnitDefinition in project vcell by virtualcell.

the class Xmlproducer method getXML.

public Element getXML(SpatialProcess[] spatialProcesses) throws XmlParseException {
    Element spatialProcessesElement = new Element(XMLTags.SpatialProcessesTag);
    for (SpatialProcess spatialProcess : spatialProcesses) {
        Element spatialProcessElement = new Element(XMLTags.SpatialProcessTag);
        spatialProcessElement.setAttribute(XMLTags.NameAttrTag, mangle(spatialProcess.getName()));
        if (spatialProcess instanceof PointKinematics) {
            spatialProcessElement.setAttribute(XMLTags.SpatialProcessTypeAttrTag, XMLTags.SpatialProcessTypeAttrValue_PointKinematics);
            spatialProcessElement.setAttribute(XMLTags.SpatialProcessPointObjectAttrTag, ((PointKinematics) spatialProcess).getPointObject().getName());
        } else if (spatialProcess instanceof PointLocation) {
            spatialProcessElement.setAttribute(XMLTags.SpatialProcessTypeAttrTag, XMLTags.SpatialProcessTypeAttrValue_PointLocation);
            spatialProcessElement.setAttribute(XMLTags.SpatialProcessPointObjectAttrTag, ((PointLocation) spatialProcess).getPointObject().getName());
        } else if (spatialProcess instanceof SurfaceKinematics) {
            spatialProcessElement.setAttribute(XMLTags.SpatialProcessTypeAttrTag, XMLTags.SpatialProcessTypeAttrValue_SurfaceKinematics);
            spatialProcessElement.setAttribute(XMLTags.SpatialProcessSurfaceObjectAttrTag, ((SurfaceKinematics) spatialProcess).getSurfaceRegionObject().getName());
        } else if (spatialProcess instanceof VolumeKinematics) {
            spatialProcessElement.setAttribute(XMLTags.SpatialProcessTypeAttrTag, XMLTags.SpatialProcessTypeAttrValue_VolumeKinematics);
            spatialProcessElement.setAttribute(XMLTags.SpatialProcessVolumeObjectAttrTag, ((VolumeKinematics) spatialProcess).getVolumeRegionObject().getName());
        } else {
            throw new RuntimeException("spatialProcess type " + spatialProcess.getClass().getSimpleName() + " not yet supported for persistence.");
        }
        LocalParameter[] parameters = spatialProcess.getParameters();
        for (LocalParameter parm : parameters) {
            if (parm.getExpression() != null) {
                Element tempparameter = new Element(XMLTags.ParameterTag);
                // Get parameter attributes
                tempparameter.setAttribute(XMLTags.NameAttrTag, mangle(parm.getName()));
                tempparameter.setAttribute(XMLTags.ParamRoleAttrTag, spatialProcess.getParameterType(parm).getRoleXmlName());
                VCUnitDefinition unit = parm.getUnitDefinition();
                if (unit != null) {
                    tempparameter.setAttribute(XMLTags.VCUnitDefinitionAttrTag, unit.getSymbol());
                }
                tempparameter.addContent(mangleExpression(parm.getExpression()));
                spatialProcessElement.addContent(tempparameter);
            }
        }
        spatialProcessesElement.addContent(spatialProcessElement);
    }
    System.out.println(XmlUtil.xmlToString(spatialProcessesElement));
    return spatialProcessesElement;
}
Also used : LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) PointLocation(cbit.vcell.mapping.spatial.processes.PointLocation) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) SurfaceKinematics(cbit.vcell.mapping.spatial.processes.SurfaceKinematics) VolumeKinematics(cbit.vcell.mapping.spatial.processes.VolumeKinematics) Element(org.jdom.Element) PointKinematics(cbit.vcell.mapping.spatial.processes.PointKinematics)

Example 94 with VCUnitDefinition

use of cbit.vcell.units.VCUnitDefinition in project vcell by virtualcell.

the class XmlReader method getSpatialProcesses.

public SpatialProcess[] getSpatialProcesses(SimulationContext simContext, Element spatialProcessesElement) throws XmlParseException {
    Iterator<Element> spatialProcessElementIterator = spatialProcessesElement.getChildren(XMLTags.SpatialProcessTag, vcNamespace).iterator();
    ArrayList<SpatialProcess> spatialProcessList = new ArrayList<SpatialProcess>();
    while (spatialProcessElementIterator.hasNext()) {
        Element spatialProcessElement = (Element) spatialProcessElementIterator.next();
        SpatialProcess spatialProcess = null;
        String name = unMangle(spatialProcessElement.getAttributeValue(XMLTags.NameAttrTag));
        String type = unMangle(spatialProcessElement.getAttributeValue(XMLTags.SpatialProcessTypeAttrTag));
        if (type.equals(XMLTags.SpatialProcessTypeAttrValue_PointKinematics)) {
            PointKinematics pointKinematics = new PointKinematics(name, simContext);
            String pointObjectName = spatialProcessElement.getAttributeValue(XMLTags.SpatialProcessPointObjectAttrTag);
            PointObject pointObject = (PointObject) simContext.getSpatialObject(pointObjectName);
            pointKinematics.setPointObject(pointObject);
            spatialProcess = pointKinematics;
        } else if (type.equals(XMLTags.SpatialProcessTypeAttrValue_PointLocation)) {
            PointLocation pointLocation = new PointLocation(name, simContext);
            String pointObjectName = spatialProcessElement.getAttributeValue(XMLTags.SpatialProcessPointObjectAttrTag);
            PointObject pointObject = (PointObject) simContext.getSpatialObject(pointObjectName);
            pointLocation.setPointObject(pointObject);
            spatialProcess = pointLocation;
        } else if (type.equals(XMLTags.SpatialProcessTypeAttrValue_SurfaceKinematics)) {
            SurfaceKinematics surfaceKinematics = new SurfaceKinematics(name, simContext);
            String surfaceRegionObjectName = spatialProcessElement.getAttributeValue(XMLTags.SpatialProcessSurfaceObjectAttrTag);
            SurfaceRegionObject surfaceRegionObject = (SurfaceRegionObject) simContext.getSpatialObject(surfaceRegionObjectName);
            surfaceKinematics.setSurfaceRegionObject(surfaceRegionObject);
            spatialProcess = surfaceKinematics;
        } else if (type.equals(XMLTags.SpatialProcessTypeAttrValue_VolumeKinematics)) {
            VolumeKinematics volumeKinematics = new VolumeKinematics(name, simContext);
            String volumeRegionObjectName = spatialProcessElement.getAttributeValue(XMLTags.SpatialProcessVolumeObjectAttrTag);
            VolumeRegionObject volumeRegionObject = (VolumeRegionObject) simContext.getSpatialObject(volumeRegionObjectName);
            volumeKinematics.setVolumeRegionObject(volumeRegionObject);
            spatialProcess = volumeKinematics;
        }
        // set parameters
        Iterator<Element> paramElementIter = spatialProcessElement.getChildren(XMLTags.ParameterTag, vcNamespace).iterator();
        ArrayList<LocalParameter> parameters = new ArrayList<LocalParameter>();
        while (paramElementIter.hasNext()) {
            Element paramElement = paramElementIter.next();
            // Get parameter attributes
            String paramName = paramElement.getAttributeValue(XMLTags.NameAttrTag);
            Expression exp = unMangleExpression(paramElement.getText());
            String roleStr = paramElement.getAttributeValue(XMLTags.ParamRoleAttrTag);
            SpatialProcessParameterType parameterType = SpatialProcessParameterType.fromRoleXmlName(roleStr);
            VCUnitDefinition unit = simContext.getModel().getUnitSystem().getInstance_TBD();
            String unitSymbol = paramElement.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
            if (unitSymbol != null) {
                unit = simContext.getModel().getUnitSystem().getInstance(unitSymbol);
            }
            parameters.add(spatialProcess.createNewParameter(paramName, parameterType, exp, unit));
        }
        try {
            spatialProcess.setParameters(parameters.toArray(new LocalParameter[0]));
        } catch (PropertyVetoException | ExpressionBindingException e) {
            e.printStackTrace();
            throw new XmlParseException("failed to read parameters in bioEvent " + name + ": " + e.getMessage(), e);
        }
        spatialProcessList.add(spatialProcess);
    }
    return spatialProcessList.toArray(new SpatialProcess[0]);
}
Also used : VolumeRegionObject(cbit.vcell.mapping.spatial.VolumeRegionObject) PointLocation(cbit.vcell.mapping.spatial.processes.PointLocation) SurfaceKinematics(cbit.vcell.mapping.spatial.processes.SurfaceKinematics) VolumeKinematics(cbit.vcell.mapping.spatial.processes.VolumeKinematics) Element(org.jdom.Element) ArrayList(java.util.ArrayList) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) PropertyVetoException(java.beans.PropertyVetoException) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) PointObject(cbit.vcell.mapping.spatial.PointObject) Expression(cbit.vcell.parser.Expression) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) PointKinematics(cbit.vcell.mapping.spatial.processes.PointKinematics) SpatialProcessParameterType(cbit.vcell.mapping.spatial.processes.SpatialProcess.SpatialProcessParameterType) SurfaceRegionObject(cbit.vcell.mapping.spatial.SurfaceRegionObject)

Example 95 with VCUnitDefinition

use of cbit.vcell.units.VCUnitDefinition in project vcell by virtualcell.

the class XmlReader method getModelParameter.

public ModelParameter getModelParameter(Element paramElement, Model model) {
    // get its attributes : name, role and unit definition
    String glParamName = unMangle(paramElement.getAttributeValue(XMLTags.NameAttrTag));
    String role = paramElement.getAttributeValue(XMLTags.ParamRoleAttrTag);
    ModelUnitSystem modelUnitSystem = model.getUnitSystem();
    int glParamRole = -1;
    if (role.equals(XMLTags.ParamRoleUserDefinedTag)) {
        glParamRole = Model.ROLE_UserDefined;
    } else {
        throw new RuntimeException("unknown type of model parameter (not user-defined)");
    }
    // 
    // int glParamRole = -1;
    // if (role.equals(XMLTags.ParamRoleUserDefinedTag)) {
    // glParamRole = Model.ROLE_UserDefined;
    // } else	if (role.equals(XMLTags.RoleVariableRateTag)) {
    // glParamRole = Model.ROLE_VariableRate;
    // } else {
    // throw new RuntimeException("unknown type of model parameter (not user-defined or variable rate)");
    // }
    String unitSymbol = paramElement.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
    VCUnitDefinition glParamUnit = null;
    if (unitSymbol != null) {
        glParamUnit = modelUnitSystem.getInstance(unitSymbol);
    }
    // get parameter contents : expression; annotation, if any.
    String glParamExpStr = paramElement.getText();
    Expression glParamExp = unMangleExpression(glParamExpStr);
    String glParamAnnotation = null;
    String annotationText = paramElement.getChildText(XMLTags.AnnotationTag, vcNamespace);
    if (annotationText != null && annotationText.length() > 0) {
        glParamAnnotation = unMangle(annotationText);
    }
    // create new global parameter
    ModelParameter newGlParam = model.new ModelParameter(glParamName, glParamExp, glParamRole, glParamUnit);
    newGlParam.setModelParameterAnnotation(glParamAnnotation);
    return newGlParam;
}
Also used : ModelParameter(cbit.vcell.model.Model.ModelParameter) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Aggregations

VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)113 Expression (cbit.vcell.parser.Expression)73 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)36 ExpressionException (cbit.vcell.parser.ExpressionException)26 PropertyVetoException (java.beans.PropertyVetoException)24 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)21 Element (org.jdom.Element)20 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)19 ArrayList (java.util.ArrayList)17 ModelParameter (cbit.vcell.model.Model.ModelParameter)16 Model (cbit.vcell.model.Model)14 Parameter (cbit.vcell.model.Parameter)14 SpeciesContext (cbit.vcell.model.SpeciesContext)13 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)13 Membrane (cbit.vcell.model.Membrane)12 Structure (cbit.vcell.model.Structure)12 StructureMapping (cbit.vcell.mapping.StructureMapping)11 MathException (cbit.vcell.math.MathException)10 ReactionStep (cbit.vcell.model.ReactionStep)10 Feature (cbit.vcell.model.Feature)9