use of cbit.vcell.mapping.MembraneMapping in project vcell by virtualcell.
the class ModelOptimizationSpec method getModelParameters.
/**
* Insert the method's description here.
* Creation date: (8/22/2005 10:38:04 AM)
* @return cbit.vcell.model.Parameter[]
*/
private Parameter[] getModelParameters() {
java.util.Vector<Parameter> modelParameterList = new java.util.Vector<Parameter>();
Model model = getSimulationContext().getModel();
//
// get Model (global) parameters
//
ModelParameter[] globalParams = model.getModelParameters();
for (int i = 0; i < globalParams.length; i++) {
if (globalParams[i] != null && globalParams[i].getExpression() != null && globalParams[i].getExpression().isNumeric()) {
modelParameterList.add(globalParams[i]);
}
}
//
// get kinetic parameters that are numbers
//
ReactionStep[] reactionSteps = model.getReactionSteps();
for (int i = 0; i < reactionSteps.length; i++) {
//
// make sure ReactionSteps are "enabled"
//
ReactionSpec reactionSpec = getSimulationContext().getReactionContext().getReactionSpec(reactionSteps[i]);
if (reactionSpec == null || reactionSpec.isExcluded()) {
continue;
}
Kinetics.KineticsParameter[] kineticsParameters = reactionSteps[i].getKinetics().getKineticsParameters();
for (int j = 0; j < kineticsParameters.length; j++) {
if (kineticsParameters[j].getExpression() != null && kineticsParameters[j].getExpression().isNumeric()) {
if (((kineticsParameters[j].getRole() == Kinetics.ROLE_CurrentDensity) || (kineticsParameters[j].getRole() == Kinetics.ROLE_LumpedCurrent)) && reactionSteps[i].getPhysicsOptions() == ReactionStep.PHYSICS_MOLECULAR_ONLY) {
continue;
}
if (((kineticsParameters[j].getRole() == Kinetics.ROLE_ReactionRate) || (kineticsParameters[j].getRole() == Kinetics.ROLE_LumpedReactionRate)) && reactionSteps[i].getPhysicsOptions() == ReactionStep.PHYSICS_ELECTRICAL_ONLY) {
continue;
}
modelParameterList.add(kineticsParameters[j]);
}
}
}
//
// get initial conditions that are numbers
//
SpeciesContextSpec[] speciesContextSpecs = getSimulationContext().getReactionContext().getSpeciesContextSpecs();
for (int i = 0; i < speciesContextSpecs.length; i++) {
SpeciesContextSpec.SpeciesContextSpecParameter initParam = speciesContextSpecs[i].getInitialConditionParameter();
if (initParam != null && initParam.getExpression() != null && initParam.getExpression().isNumeric()) {
modelParameterList.add(initParam);
}
}
//
// get structure parameters
//
StructureMapping[] structureMappings = getSimulationContext().getGeometryContext().getStructureMappings();
for (int i = 0; i < structureMappings.length; i++) {
StructureMapping.StructureMappingParameter[] parameters = structureMappings[i].getParameters();
for (int j = 0; j < parameters.length; j++) {
if (parameters[j].getRole() == StructureMapping.ROLE_SpecificCapacitance && structureMappings[i] instanceof MembraneMapping && !((MembraneMapping) structureMappings[i]).getCalculateVoltage()) {
continue;
}
if (parameters[j].getExpression() != null && parameters[j].getExpression().isNumeric()) {
modelParameterList.add(parameters[j]);
}
}
}
Parameter[] modelParameters = (Parameter[]) BeanUtils.getArray(modelParameterList, Parameter.class);
return modelParameters;
}
use of cbit.vcell.mapping.MembraneMapping in project vcell by virtualcell.
the class ITextWriter method writeStructureMapping.
// boundary types ignored.
protected void writeStructureMapping(Section simContextSection, SimulationContext sc) throws DocumentException {
GeometryContext gc = sc.getGeometryContext();
if (gc == null) {
return;
}
Section structMappSection = null;
/*try {
ByteArrayOutputStream bos = generateStructureMappingImage(sc);
com.lowagie.text.Image structMapImage = com.lowagie.text.Image.getInstance(Toolkit.getDefaultToolkit().createImage(bos.toByteArray()), null);
structMappSection = simContextSection.addSection("Structure Mapping For " + sc.getName(), simContextSection.numberDepth() + 1);
structMappSection.add(structMapImage);
} catch (Exception e) {
System.err.println("Unable to add structure mapping image to report.");
e.printStackTrace();
}*/
StructureMapping[] structMap = gc.getStructureMappings();
Table structMapTable = null;
ModelUnitSystem modelUnitSystem = sc.getModel().getUnitSystem();
for (int i = 0; i < structMap.length; i++) {
if (!(structMap[i] instanceof FeatureMapping)) {
continue;
}
if (i == 0) {
structMapTable = getTable(5, 100, 1, 3, 3);
structMapTable.addCell(createCell("Structure Mapping", getBold(DEF_HEADER_FONT_SIZE), 5, 1, Element.ALIGN_CENTER, true));
structMapTable.addCell(createHeaderCell("Structure", getBold(), 1));
structMapTable.addCell(createHeaderCell("Subdomain", getBold(), 1));
structMapTable.addCell(createHeaderCell("Resolved (T/F)", getBold(), 1));
structMapTable.addCell(createHeaderCell("Surf/Vol", getBold(), 1));
structMapTable.addCell(createHeaderCell("VolFract", getBold(), 1));
structMapTable.endHeaders();
}
String structName = structMap[i].getStructure().getName();
SubVolume subVol = (SubVolume) ((FeatureMapping) structMap[i]).getGeometryClass();
String subDomain = "";
if (subVol != null) {
subDomain = subVol.getName();
}
// ((FeatureMapping)structMap[i]).getResolved();
boolean isResolved = false;
String surfVolStr = "", volFractStr = "";
MembraneMapping mm = (MembraneMapping) gc.getStructureMapping(sc.getModel().getStructureTopology().getParentStructure(structMap[i].getStructure()));
if (mm != null) {
StructureMapping.StructureMappingParameter smp = mm.getSurfaceToVolumeParameter();
if (smp != null) {
Expression tempExp = smp.getExpression();
VCUnitDefinition tempUnit = smp.getUnitDefinition();
if (tempExp != null) {
surfVolStr = tempExp.infix();
if (tempUnit != null && !modelUnitSystem.getInstance_DIMENSIONLESS().compareEqual(tempUnit)) {
// no need to add '1' for dimensionless unit
surfVolStr += " " + tempUnit.getSymbolUnicode();
}
}
}
smp = mm.getVolumeFractionParameter();
if (smp != null) {
Expression tempExp = smp.getExpression();
VCUnitDefinition tempUnit = smp.getUnitDefinition();
if (tempExp != null) {
volFractStr = tempExp.infix();
if (tempUnit != null && !modelUnitSystem.getInstance_DIMENSIONLESS().compareEqual(tempUnit)) {
volFractStr += " " + tempUnit.getSymbolUnicode();
}
}
}
}
structMapTable.addCell(createCell(structName, getFont()));
structMapTable.addCell(createCell(subDomain, getFont()));
structMapTable.addCell(createCell((isResolved ? " T " : " F "), getFont()));
structMapTable.addCell(createCell(surfVolStr, getFont()));
structMapTable.addCell(createCell(volFractStr, getFont()));
}
if (structMapTable != null) {
if (structMappSection == null) {
structMappSection = simContextSection.addSection("Structure Mapping For " + sc.getName(), simContextSection.numberDepth() + 1);
}
structMappSection.add(structMapTable);
}
}
use of cbit.vcell.mapping.MembraneMapping in project vcell by virtualcell.
the class StructureSizeSolver method updateUnitStructureSizes.
/**
* Insert the method's description here.
* Creation date: (5/17/2006 10:33:38 AM)
* @return double[]
* @param structName java.lang.String
* @param structSize double
*/
public static void updateUnitStructureSizes(SimulationContext simContext, GeometryClass geometryClass) {
if (simContext.getGeometryContext().getGeometry().getDimension() == 0) {
return;
}
StructureMapping[] myStructMappings = simContext.getGeometryContext().getStructureMappings(geometryClass);
if (myStructMappings != null && myStructMappings.length == 1) {
// if the unitSizeParameter is dimensionless, then features are mapped to SubVolumes or Membranes are mapped to surfaces (should sum to 1)
boolean bDimensionless = myStructMappings[0].getUnitSizeParameter().getUnitDefinition().isEquivalent(simContext.getModel().getUnitSystem().getInstance_DIMENSIONLESS());
if (bDimensionless) {
try {
myStructMappings[0].getUnitSizeParameter().setExpression(new Expression(1.0));
return;
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
}
}
if (myStructMappings != null && myStructMappings.length == 0) {
// nothing to solve, there are no mappings for this geometryClass
return;
}
StructureMapping[] structMappings = simContext.getGeometryContext().getStructureMappings();
try {
ConstraintContainerImpl ccImpl = new ConstraintContainerImpl();
Structure struct = null;
Expression totalVolExpr = new Expression(0.0);
StructureTopology structureTopology = simContext.getModel().getStructureTopology();
for (int i = 0; i < structMappings.length; i++) {
if (structMappings[i].getGeometryClass() != geometryClass) {
continue;
}
// new model with unit sizes already
if (structMappings[i].getUnitSizeParameter() != null && structMappings[i].getUnitSizeParameter().getExpression() != null) {
return;
}
if (struct == null) {
struct = structMappings[i].getStructure();
}
if (structMappings[i] instanceof MembraneMapping) {
MembraneMapping membraneMapping = (MembraneMapping) structMappings[i];
Membrane membrane = membraneMapping.getMembrane();
String membraneSizeName = TokenMangler.mangleToSName(membrane.getName() + "_size");
ccImpl.addSimpleBound(new SimpleBounds(membraneSizeName, new RealInterval(0, 100000), AbstractConstraint.PHYSICAL_LIMIT, "definition"));
Feature insideFeature = structureTopology.getInsideFeature(membrane);
String volFractName = TokenMangler.mangleToSName(insideFeature.getName() + "_volFract");
String svRatioName = TokenMangler.mangleToSName(insideFeature.getName() + "_svRatio");
StructureMapping.StructureMappingParameter volFractParameter = membraneMapping.getVolumeFractionParameter();
double volFractValue = volFractParameter.getExpression().evaluateConstant();
ccImpl.addSimpleBound(new SimpleBounds(volFractName, new RealInterval(volFractValue, volFractValue), AbstractConstraint.MODELING_ASSUMPTION, "from model"));
StructureMapping.StructureMappingParameter surfToVolParameter = membraneMapping.getSurfaceToVolumeParameter();
double svRatioValue = surfToVolParameter.getExpression().evaluateConstant();
ccImpl.addSimpleBound(new SimpleBounds(svRatioName, new RealInterval(svRatioValue, svRatioValue), AbstractConstraint.MODELING_ASSUMPTION, "from model"));
// membrane mapped to volume
if (geometryClass instanceof SubVolume) {
//
// EC eclosing cyt, which contains er and golgi
// "(cyt_size+ er_size + golgi_size) * cyt_svRatio - PM_size == 0"
//
Expression sumOfInsideVolumeExp = new Expression(0.0);
for (int j = 0; j < structMappings.length; j++) {
if (structMappings[j] instanceof FeatureMapping && structureTopology.enclosedBy(structMappings[j].getStructure(), insideFeature)) {
Feature childFeatureOfInside = ((FeatureMapping) structMappings[j]).getFeature();
if (simContext.getGeometryContext().getStructureMapping(childFeatureOfInside).getGeometryClass() == geometryClass) {
sumOfInsideVolumeExp = Expression.add(sumOfInsideVolumeExp, new Expression(TokenMangler.mangleToSName(childFeatureOfInside.getName() + "_size")));
}
}
}
Expression tempExpr = Expression.mult(sumOfInsideVolumeExp, new Expression(svRatioName));
tempExpr = Expression.add(tempExpr, new Expression("-" + membraneSizeName));
ccImpl.addGeneralConstraint(new GeneralConstraint(new Expression(tempExpr.infix() + "==0"), AbstractConstraint.MODELING_ASSUMPTION, "svRatio definition"));
//
// EC eclosing cyt, which contains er and golgi
// (EC_size + cyt_size + er_size + golgi_size) * cyt_vfRatio - (cyt_size + er_size + golgi_size) == 0
//
Feature outsideFeature = structureTopology.getOutsideFeature(membrane);
Expression sumOfParentVolumeExp = new Expression(0.0);
for (int j = 0; j < structMappings.length; j++) {
if (structMappings[j] instanceof FeatureMapping && structureTopology.enclosedBy(structMappings[j].getStructure(), outsideFeature)) {
Feature childFeatureOfParent = ((FeatureMapping) structMappings[j]).getFeature();
if (simContext.getGeometryContext().getStructureMapping(childFeatureOfParent).getGeometryClass() == geometryClass) {
sumOfParentVolumeExp = Expression.add(sumOfParentVolumeExp, new Expression(TokenMangler.mangleToSName(childFeatureOfParent.getName() + "_size")));
}
}
}
Expression exp = Expression.mult(sumOfParentVolumeExp, new Expression(volFractName));
exp = Expression.add(exp, Expression.negate(sumOfInsideVolumeExp));
ccImpl.addGeneralConstraint(new GeneralConstraint(new Expression(exp.infix() + "==0.0"), AbstractConstraint.MODELING_ASSUMPTION, "volFract definition"));
}
} else if (structMappings[i] instanceof FeatureMapping) {
FeatureMapping featureMapping = (FeatureMapping) structMappings[i];
String featureSizeName = TokenMangler.mangleToSName(featureMapping.getFeature().getName() + "_size");
totalVolExpr = Expression.add(totalVolExpr, new Expression(featureSizeName));
ccImpl.addSimpleBound(new SimpleBounds(featureSizeName, new RealInterval(0, 1), AbstractConstraint.PHYSICAL_LIMIT, "definition"));
}
}
if (geometryClass instanceof SubVolume) {
ccImpl.addGeneralConstraint(new GeneralConstraint(new Expression(totalVolExpr.infix() + "==1.0"), AbstractConstraint.MODELING_ASSUMPTION, "total volume"));
}
// ccImpl.show();
ConstraintSolver constraintSolver = new ConstraintSolver(ccImpl);
constraintSolver.resetIntervals();
int numTimesNarrowed = 0;
RealInterval[] lastSolution = null;
boolean bChanged = true;
while (constraintSolver.narrow() && bChanged && numTimesNarrowed < 125) {
numTimesNarrowed++;
bChanged = false;
RealInterval[] thisSolution = constraintSolver.getIntervals();
if (lastSolution != null) {
for (int i = 0; i < thisSolution.length; i++) {
if (!thisSolution[i].equals(lastSolution[i])) {
bChanged = true;
}
}
} else {
bChanged = true;
}
lastSolution = thisSolution;
}
System.out.println("num of times narrowed = " + numTimesNarrowed);
if (numTimesNarrowed > 0) {
String[] symbols = constraintSolver.getSymbols();
net.sourceforge.interval.ia_math.RealInterval[] solution = constraintSolver.getIntervals();
double totalArea = 0;
double totalVolume = 0;
for (int i = 0; i < symbols.length; i++) {
System.out.println("solution[" + i + "] \"" + symbols[i] + "\" = " + solution[i]);
for (int j = 0; j < structMappings.length; j++) {
if (symbols[i].equals(TokenMangler.mangleToSName(structMappings[j].getStructure().getName() + "_size"))) {
if (!Double.isInfinite(solution[i].lo()) && !Double.isInfinite(solution[i].hi())) {
double value = (solution[i].lo() + solution[i].hi()) / 2;
Expression exp = new Expression(value);
if (structMappings[j] instanceof FeatureMapping) {
FeatureMapping fm = (FeatureMapping) structMappings[j];
totalVolume += value;
if (geometryClass instanceof SubVolume) {
fm.getVolumePerUnitVolumeParameter().setExpression(exp);
} else if (geometryClass instanceof SurfaceClass) {
fm.getVolumePerUnitAreaParameter().setExpression(exp);
}
} else if (structMappings[j] instanceof MembraneMapping) {
MembraneMapping mm = (MembraneMapping) structMappings[j];
totalArea += value;
if (geometryClass instanceof SubVolume) {
mm.getAreaPerUnitVolumeParameter().setExpression(exp);
} else if (geometryClass instanceof SurfaceClass) {
mm.getAreaPerUnitAreaParameter().setExpression(exp);
}
}
}
}
}
}
//
// normalize all so that total volume is 1.0 for subVolumes or
// total area is 1.0 for surfaceClasses
//
double scaleFactor = 1;
if (geometryClass instanceof SubVolume) {
scaleFactor = totalVolume;
} else if (geometryClass instanceof SurfaceClass) {
scaleFactor = totalArea;
} else {
throw new RuntimeException("unexpected GeometryClass");
}
for (int j = 0; j < structMappings.length; j++) {
if (structMappings[j].getGeometryClass() == geometryClass) {
if (structMappings[j] instanceof FeatureMapping) {
FeatureMapping fm = (FeatureMapping) structMappings[j];
if (geometryClass instanceof SubVolume) {
fm.getVolumePerUnitVolumeParameter().setExpression(new Expression(fm.getVolumePerUnitVolumeParameter().getExpression().evaluateConstant() / scaleFactor));
} else if (geometryClass instanceof SurfaceClass) {
fm.getVolumePerUnitAreaParameter().setExpression(new Expression(fm.getVolumePerUnitAreaParameter().getExpression().evaluateConstant() / scaleFactor));
}
} else if (structMappings[j] instanceof MembraneMapping) {
MembraneMapping mm = (MembraneMapping) structMappings[j];
if (geometryClass instanceof SubVolume) {
mm.getAreaPerUnitVolumeParameter().setExpression(new Expression(mm.getAreaPerUnitVolumeParameter().getExpression().evaluateConstant() / scaleFactor));
} else if (geometryClass instanceof SurfaceClass) {
mm.getAreaPerUnitAreaParameter().setExpression(new Expression(mm.getAreaPerUnitAreaParameter().getExpression().evaluateConstant() / scaleFactor));
}
}
}
}
} else {
throw new RuntimeException("cannot solve for size");
}
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
}
use of cbit.vcell.mapping.MembraneMapping in project vcell by virtualcell.
the class SimulationContextDbDriver method assignStructureMappingsSQL.
/**
* This method was created in VisualAge.
* @param simContext cbit.vcell.mapping.SimulationContext
*/
private void assignStructureMappingsSQL(QueryHashtable dbc, Connection con, KeyValue simContextKey, SimulationContext simContext) throws SQLException, DataAccessException {
String sql;
sql = " SELECT " + "*" + " FROM " + structureMappingTable.getTableName() + " WHERE " + structureMappingTable.simContextRef + " = " + simContextKey;
Statement stmt = con.createStatement();
try {
// log.print(sql);
ResultSet rset = stmt.executeQuery(sql);
while (rset.next()) {
BigDecimal subvolumeRefBigDecimal = rset.getBigDecimal(structureMappingTable.subVolumeRef.toString());
KeyValue subVolumeRef = (subvolumeRefBigDecimal == null ? null : new KeyValue(subvolumeRefBigDecimal));
BigDecimal surfaceClassRefBigDecimal = rset.getBigDecimal(structureMappingTable.surfaceClassRef.toString());
KeyValue surfaceClassRef = (surfaceClassRefBigDecimal == null ? null : new KeyValue(surfaceClassRefBigDecimal));
KeyValue structureRef = new KeyValue(rset.getBigDecimal(structureMappingTable.structRef.toString()));
//
// lookup structure and subVolume from SimulationContext by their keys
//
// DBCache will not always give same instance consistently (usually this is
// fixed up later in the ReferenceResolver at the Client).
//
Structure theStructure = null;
Structure[] structureArray = simContext.getModel().getStructures();
for (int i = 0; i < structureArray.length; i++) {
Structure structure = structureArray[i];
if (structure.getKey().compareEqual(structureRef)) {
theStructure = structure;
break;
}
}
if (theStructure == null) {
throw new DataAccessException("Can't match structure and subvolume");
}
GeometryClass theGeometryClass = null;
KeyValue geometryClassKey = (subVolumeRef == null ? surfaceClassRef : subVolumeRef);
if (geometryClassKey != null) {
GeometryClass[] geometryClasses = simContext.getGeometry().getGeometryClasses();
for (int i = 0; i < geometryClasses.length; i++) {
if (geometryClasses[i].getKey().compareEqual(geometryClassKey)) {
theGeometryClass = geometryClasses[i];
break;
}
}
if (theGeometryClass == null) {
throw new DataAccessException("Can't find Geometryclass");
}
}
Expression sizeExpression = null;
String sizeExpressionS = rset.getString(StructureMappingTable.table.sizeExp.getUnqualifiedColName());
if (!rset.wasNull() && sizeExpressionS != null && sizeExpressionS.length() > 0) {
try {
sizeExpressionS = TokenMangler.getSQLRestoredString(sizeExpressionS);
sizeExpression = new Expression(sizeExpressionS);
} catch (ExpressionException e) {
e.printStackTrace();
throw new DataAccessException("SimulationContextDbDriver.assignStructureMappingSQL : Couldn't parse non-null size expression for Structure " + theStructure.getName());
}
}
StructureMapping sm = simContext.getGeometryContext().getStructureMapping(theStructure);
try {
sm.getSizeParameter().setExpression(sizeExpression);
} catch (Exception e1) {
throw new DataAccessException("SimulationContextDbDriver.assignStructureMappingSQL : Couldn't set size expression '" + sizeExpressionS + "'for Structure " + theStructure.getName());
}
try {
sm.setGeometryClass(theGeometryClass);
} catch (PropertyVetoException e) {
lg.error(e.getMessage(), e);
throw new DataAccessException(e.getMessage());
}
if (sm instanceof FeatureMapping) {
FeatureMapping fm = (FeatureMapping) sm;
String boundaryTypeXmString = rset.getString(structureMappingTable.boundaryTypeXm.toString());
if (!rset.wasNull()) {
fm.setBoundaryConditionTypeXm(new BoundaryConditionType(boundaryTypeXmString));
}
String boundaryTypeXpString = rset.getString(structureMappingTable.boundaryTypeXp.toString());
if (!rset.wasNull()) {
fm.setBoundaryConditionTypeXp(new BoundaryConditionType(boundaryTypeXpString));
}
String boundaryTypeYmString = rset.getString(structureMappingTable.boundaryTypeYm.toString());
if (!rset.wasNull()) {
fm.setBoundaryConditionTypeYm(new BoundaryConditionType(boundaryTypeYmString));
}
String boundaryTypeYpString = rset.getString(structureMappingTable.boundaryTypeYp.toString());
if (!rset.wasNull()) {
fm.setBoundaryConditionTypeYp(new BoundaryConditionType(boundaryTypeYpString));
}
String boundaryTypeZmString = rset.getString(structureMappingTable.boundaryTypeZm.toString());
if (!rset.wasNull()) {
fm.setBoundaryConditionTypeZm(new BoundaryConditionType(boundaryTypeZmString));
}
String boundaryTypeZpString = rset.getString(structureMappingTable.boundaryTypeZp.toString());
if (!rset.wasNull()) {
fm.setBoundaryConditionTypeZp(new BoundaryConditionType(boundaryTypeZpString));
}
String volPerUnitArea = rset.getString(structureMappingTable.volPerUnitAreaExp.toString());
if (!rset.wasNull()) {
try {
fm.getVolumePerUnitAreaParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(volPerUnitArea)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
}
}
String volPerUnitVol = rset.getString(structureMappingTable.volPerUnitVolExp.toString());
if (!rset.wasNull()) {
try {
fm.getVolumePerUnitVolumeParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(volPerUnitVol)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
}
}
} else if (sm instanceof MembraneMapping) {
MembraneMapping mm = (MembraneMapping) sm;
String surfToVolString = rset.getString(structureMappingTable.surfToVolExp.toString());
if (!rset.wasNull()) {
try {
mm.getSurfaceToVolumeParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(surfToVolString)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
}
}
String volFractString = rset.getString(structureMappingTable.volFractExp.toString());
if (!rset.wasNull()) {
try {
mm.getVolumeFractionParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(volFractString)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("parse error in volFract expression: " + e.getMessage());
}
}
boolean bCalculateVoltage = rset.getBoolean(structureMappingTable.bCalculateVoltage.toString());
if (!rset.wasNull()) {
mm.setCalculateVoltage(bCalculateVoltage);
}
java.math.BigDecimal specificCapacitance = rset.getBigDecimal(structureMappingTable.specificCap.toString());
if (!rset.wasNull()) {
try {
mm.getSpecificCapacitanceParameter().setExpression(new Expression(specificCapacitance.doubleValue()));
} catch (ExpressionBindingException e) {
e.printStackTrace(System.out);
throw new DataAccessException("error setting membrane specific capacitance: " + e.getMessage());
}
}
String initialVoltageString = rset.getString(structureMappingTable.initialVoltage.toString());
if (!rset.wasNull()) {
try {
mm.getInitialVoltageParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(initialVoltageString)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("database parse error in initial membrane voltage: " + e.getMessage());
}
}
String areaPerUnitArea = rset.getString(structureMappingTable.areaPerUnitAreaExp.toString());
if (!rset.wasNull()) {
try {
mm.getAreaPerUnitAreaParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(areaPerUnitArea)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
}
}
String areaPerUnitVol = rset.getString(structureMappingTable.areaPerUnitVolExp.toString());
if (!rset.wasNull()) {
try {
mm.getAreaPerUnitVolumeParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(areaPerUnitVol)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
}
}
} else {
throw new DataAccessException("unknown structureMapping type");
}
// System.out.println("Structure Key = " + theStructure + " - " + "SubVolume Key " + theSubVolume.getKey());
}
} finally {
stmt.close();
}
}
use of cbit.vcell.mapping.MembraneMapping in project vcell by virtualcell.
the class StructureMappingTable method getSQLValueList.
/**
* This method was created in VisualAge.
* @return java.lang.String
* @param key KeyValue
* @param modelName java.lang.String
*/
public String getSQLValueList(InsertHashtable hash, KeyValue Key, KeyValue simContextKey, StructureMapping structureMapping) throws DataAccessException {
GeometryClass geometryClass = structureMapping.getGeometryClass();
KeyValue geometryClassKey = (geometryClass == null ? null : hash.getDatabaseKey(geometryClass));
if (geometryClass != null && geometryClassKey == null) {
geometryClassKey = geometryClass.getKey();
if (geometryClassKey == null) {
throw new DataAccessException("no key for GeometryClass '" + geometryClass.getName() + "' " + geometryClass.getClass().getName());
}
}
KeyValue structureKey = hash.getDatabaseKey(structureMapping.getStructure());
if (structureKey == null) {
structureKey = structureMapping.getStructure().getKey();
if (structureKey == null) {
throw new DataAccessException("no key for structure " + structureMapping.getStructure());
}
}
StringBuffer buffer = new StringBuffer();
buffer.append("(");
buffer.append(Key + ",");
buffer.append((geometryClass instanceof SubVolume ? geometryClassKey : null) + ",");
buffer.append(structureKey + ",");
buffer.append(simContextKey + ",");
buffer.append((/*isResolved*/
false ? 1 : 0) + ",");
if (structureMapping instanceof FeatureMapping) {
FeatureMapping fm = (FeatureMapping) structureMapping;
buffer.append("null" + ",");
buffer.append("null" + ",");
buffer.append("'" + fm.getBoundaryConditionTypeXm().boundaryTypeStringValue() + "',");
buffer.append("'" + fm.getBoundaryConditionTypeXp().boundaryTypeStringValue() + "',");
buffer.append("'" + fm.getBoundaryConditionTypeYm().boundaryTypeStringValue() + "',");
buffer.append("'" + fm.getBoundaryConditionTypeYp().boundaryTypeStringValue() + "',");
buffer.append("'" + fm.getBoundaryConditionTypeZm().boundaryTypeStringValue() + "',");
buffer.append("'" + fm.getBoundaryConditionTypeZp().boundaryTypeStringValue() + "',");
buffer.append("null" + ",");
buffer.append("null" + ",");
buffer.append("null" + ",");
} else if (structureMapping instanceof MembraneMapping) {
MembraneMapping mm = (MembraneMapping) structureMapping;
// amended Sept. 17th, 2007
if (mm.getSurfaceToVolumeParameter().getExpression() != null) {
buffer.append("'" + TokenMangler.getSQLEscapedString(mm.getSurfaceToVolumeParameter().getExpression().infix()) + "',");
} else {
buffer.append("null" + ",");
}
if (mm.getVolumeFractionParameter().getExpression() != null) {
buffer.append("'" + TokenMangler.getSQLEscapedString(mm.getVolumeFractionParameter().getExpression().infix()) + "',");
} else {
buffer.append("null" + ",");
}
buffer.append("null" + ",");
buffer.append("null" + ",");
buffer.append("null" + ",");
buffer.append("null" + ",");
buffer.append("null" + ",");
buffer.append("null" + ",");
buffer.append((mm.getCalculateVoltage() ? 1 : 0) + ",");
try {
buffer.append(mm.getSpecificCapacitanceParameter().getExpression().evaluateConstant() + ",");
} catch (cbit.vcell.parser.ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("specific capacitance for " + mm.getMembrane().getName() + " not constant: (" + e.getMessage() + ")");
}
buffer.append("'" + TokenMangler.getSQLEscapedString(mm.getInitialVoltageParameter().getExpression().infix()) + "',");
}
if (structureMapping.getSizeParameter().getExpression() != null)
buffer.append("'" + TokenMangler.getSQLEscapedString(structureMapping.getSizeParameter().getExpression().infix()) + "',");
else
buffer.append("'',");
if (structureMapping instanceof FeatureMapping) {
FeatureMapping fm = (FeatureMapping) structureMapping;
if (fm.getVolumePerUnitAreaParameter().getExpression() != null) {
buffer.append("'" + TokenMangler.getSQLEscapedString(fm.getVolumePerUnitAreaParameter().getExpression().infix()) + "',");
} else {
buffer.append("null" + ",");
}
if (fm.getVolumePerUnitVolumeParameter().getExpression() != null) {
buffer.append("'" + TokenMangler.getSQLEscapedString(fm.getVolumePerUnitVolumeParameter().getExpression().infix()) + "',");
} else {
buffer.append("null" + ",");
}
// if structureMapping is a featureMapping, 'areaPerUnitArea' and 'areaPerUnitVol' params are null, so fill those in here
buffer.append("null,null");
} else if (structureMapping instanceof MembraneMapping) {
// if structureMapping is a featureMapping, 'volPerUnitArea' and 'volPerUnitVol' params are null, so fill those in here; then memMapping params
buffer.append("null,null,");
MembraneMapping mm = (MembraneMapping) structureMapping;
if (mm.getAreaPerUnitAreaParameter().getExpression() != null) {
buffer.append("'" + TokenMangler.getSQLEscapedString(mm.getAreaPerUnitAreaParameter().getExpression().infix()) + "',");
} else {
buffer.append("null" + ",");
}
if (mm.getAreaPerUnitVolumeParameter().getExpression() != null) {
buffer.append("'" + TokenMangler.getSQLEscapedString(mm.getAreaPerUnitVolumeParameter().getExpression().infix()) + "'");
} else {
buffer.append("null");
}
}
buffer.append("," + (geometryClass instanceof SurfaceClass ? geometryClassKey : null));
buffer.append(")");
return buffer.toString();
}
Aggregations