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;
}
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;
}
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;
}
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]);
}
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;
}
Aggregations