use of cbit.vcell.parser.ExpressionBindingException in project vcell by virtualcell.
the class GeometryContext method setDefaultUnitSizes.
private void setDefaultUnitSizes() throws PropertyVetoException {
if (getGeometry().getDimension() > 0) {
for (StructureMapping sm : fieldStructureMappings) {
StructureMapping[] sms = getStructureMappings(sm.getGeometryClass());
StructureMappingParameter unitSizeParameter = sm.getUnitSizeParameter();
if (unitSizeParameter == null) {
continue;
}
Expression exp = unitSizeParameter.getExpression();
if (sm instanceof MembraneMapping) {
// Membrane mapped to surface or subdomain, default to 1.0
if (exp == null) {
try {
unitSizeParameter.setExpression(new Expression(1.0));
} catch (ExpressionBindingException e) {
e.printStackTrace();
}
}
} else if (sm instanceof FeatureMapping) {
// Feature mapped to subdomain
if (sm.getGeometryClass() instanceof SubVolume) {
if (sms != null && sms.length == 1) {
try {
unitSizeParameter.setExpression(new Expression(1.0));
} catch (ExpressionBindingException e) {
e.printStackTrace();
}
}
} else {
if (exp == null) {
try {
unitSizeParameter.setExpression(new Expression(1.0));
} catch (ExpressionBindingException e) {
e.printStackTrace();
}
}
}
}
}
}
}
use of cbit.vcell.parser.ExpressionBindingException in project vcell by virtualcell.
the class ParameterContext method resolveUndefinedUnits.
public void resolveUndefinedUnits() {
//
if (!bResolvingUnits) {
VCUnitSystem unitSystem = unitSystemProvider.getUnitSystem();
try {
bResolvingUnits = true;
boolean bAnyTBDUnits = false;
for (int i = 0; i < fieldParameters.length; i++) {
if (fieldParameters[i].getUnitDefinition() == null) {
// not ready to resolve units yet
return;
} else if (fieldParameters[i].getUnitDefinition().isTBD()) {
bAnyTBDUnits = true;
}
}
//
if (bAnyTBDUnits) {
VCUnitEvaluator unitEvaluator = new VCUnitEvaluator(unitSystem);
VCUnitDefinition[] vcUnitDefinitions = unitEvaluator.suggestUnitDefinitions(fieldParameters);
for (int i = 0; i < fieldParameters.length; i++) {
if (!fieldParameters[i].getUnitDefinition().isEquivalent(vcUnitDefinitions[i])) {
fieldParameters[i].setUnitDefinition(vcUnitDefinitions[i]);
}
}
// System.out.println("successfully completed Kinetics.resolveUndefinedUnits() for ReactionStep '"+getReactionStep()+"'");
}
} catch (ExpressionBindingException e) {
System.out.println("ParameterContext.resolveUndefinedUnits(): EXCEPTION: " + e.getMessage());
} catch (Exception e) {
System.out.println("ParameterContext.resolveUndefinedUnits(): EXCEPTION: " + e.getMessage());
} finally {
bResolvingUnits = false;
}
}
}
use of cbit.vcell.parser.ExpressionBindingException in project vcell by virtualcell.
the class ParameterContext method cleanupParameters.
/**
* This method was created in VisualAge.
*/
final void cleanupParameters() throws ExpressionException, PropertyVetoException {
if (bReading) {
return;
}
//
if (fieldParameters != null) {
for (int i = 0; i < fieldParameters.length; i++) {
if (parameterPolicy.isUserDefined(fieldParameters[i]) && !isReferenced(fieldParameters[i], 0)) {
removeParameter(fieldParameters[i]);
i--;
}
}
}
if (fieldProxyParameters != null) {
for (int i = 0; i < fieldProxyParameters.length; i++) {
if (!isReferenced(fieldProxyParameters[i], 0)) {
removeProxyParameter(fieldProxyParameters[i]);
i--;
}
}
}
for (int i = 0; fieldParameters != null && i < fieldParameters.length; i++) {
Expression exp = fieldParameters[i].getExpression();
if (exp != null) {
try {
exp.bindExpression(this);
} catch (ExpressionBindingException e) {
System.out.println("error binding expression '" + exp.infix() + "': " + e.getMessage());
}
}
}
resolveUndefinedUnits();
}
use of cbit.vcell.parser.ExpressionBindingException in project vcell by virtualcell.
the class AbstractMathMapping method getIdentifierSubstitutions.
/**
* Substitutes appropriate variables for speciesContext bindings
*
* @return cbit.vcell.parser.Expression
* @param origExp cbit.vcell.parser.Expression
* @param structureMapping cbit.vcell.mapping.StructureMapping
*/
protected Expression getIdentifierSubstitutions(Expression origExp, VCUnitDefinition desiredExpUnitDef, GeometryClass geometryClass) throws ExpressionException, MappingException {
String[] symbols = origExp.getSymbols();
if (symbols == null) {
return origExp;
}
VCUnitDefinition expUnitDef = null;
try {
VCUnitEvaluator unitEvaluator = new VCUnitEvaluator(simContext.getModel().getUnitSystem());
expUnitDef = unitEvaluator.getUnitDefinition(origExp);
if (desiredExpUnitDef == null) {
String expStr = origExp.renameBoundSymbols(getNameScope()).infix();
System.out.println("...........exp='" + expStr + "', desiredUnits are null");
localIssueList.add(new Issue(origExp, issueContext, IssueCategory.Units, "expected=[null], observed=[" + expUnitDef.getSymbol() + "]", Issue.SEVERITY_WARNING));
} else if (expUnitDef == null) {
String expStr = origExp.renameBoundSymbols(getNameScope()).infix();
System.out.println("...........exp='" + expStr + "', evaluated Units are null");
localIssueList.add(new Issue(origExp, issueContext, IssueCategory.Units, "expected=[" + desiredExpUnitDef.getSymbol() + "], observed=[null]", Issue.SEVERITY_WARNING));
} else if (desiredExpUnitDef.isTBD()) {
String expStr = origExp.renameBoundSymbols(getNameScope()).infix();
// System.out.println("...........exp='"+expStr+"', desiredUnits are ["+desiredExpUnitDef.getSymbol()+"] and expression units are ["+expUnitDef.getSymbol()+"]");
localIssueList.add(new Issue(origExp, issueContext, IssueCategory.Units, "expected=[" + desiredExpUnitDef.getSymbol() + "], observed=[" + expUnitDef.getSymbol() + "] for exp = " + expStr, Issue.SEVERITY_WARNING));
} else if (!desiredExpUnitDef.isEquivalent(expUnitDef) && !expUnitDef.isTBD()) {
String expStr = origExp.renameBoundSymbols(getNameScope()).infix();
// System.out.println("...........exp='"+expStr+"', desiredUnits are ["+desiredExpUnitDef.getSymbol()+"] and expression units are ["+expUnitDef.getSymbol()+"]");
localIssueList.add(new Issue(origExp, issueContext, IssueCategory.Units, "expected=[" + desiredExpUnitDef.getSymbol() + "], observed=[" + expUnitDef.getSymbol() + "] for exp = " + expStr, Issue.SEVERITY_WARNING));
}
} catch (VCUnitException e) {
String expStr = origExp.renameBoundSymbols(getNameScope()).infix();
System.out.println(".........exp='" + expStr + "' exception='" + e.getMessage() + "'");
localIssueList.add(new Issue(origExp, issueContext, IssueCategory.Units, "expected=[" + ((desiredExpUnitDef != null) ? (desiredExpUnitDef.getSymbol()) : ("null")) + "], exception=" + e.getMessage(), Issue.SEVERITY_WARNING));
} catch (ExpressionException e) {
String expStr = origExp.renameBoundSymbols(getNameScope()).infix();
System.out.println(".........exp='" + expStr + "' exception='" + e.getMessage() + "'");
localIssueList.add(new Issue(origExp, issueContext, IssueCategory.Units, "expected=[" + ((desiredExpUnitDef != null) ? (desiredExpUnitDef.getSymbol()) : ("null")) + "], exception=" + e.getMessage(), Issue.SEVERITY_WARNING));
} catch (Exception e) {
e.printStackTrace(System.out);
localIssueList.add(new Issue(origExp, issueContext, IssueCategory.Units, "expected=[" + ((desiredExpUnitDef != null) ? (desiredExpUnitDef.getSymbol()) : ("null")) + "], exception=" + e.getMessage(), Issue.SEVERITY_WARNING));
}
Expression newExp = new Expression(origExp);
//
// flatten user-defined functions
//
FunctionInvocation[] functionInvocations = newExp.getFunctionInvocations(new FunctionFilter() {
@Override
public boolean accept(String functionName, FunctionType functionType) {
return functionType == FunctionType.USERDEFINED;
}
});
for (FunctionInvocation functionInvocation : functionInvocations) {
if (functionInvocation.getSymbolTableFunctionEntry() instanceof Model.ModelFunction) {
ModelFunction modelFunction = (ModelFunction) functionInvocation.getSymbolTableFunctionEntry();
newExp.substituteInPlace(functionInvocation.getFunctionExpression(), modelFunction.getFlattenedExpression(functionInvocation));
}
}
//
// then substitute Math symbols for Biological symbols.
//
newExp.bindExpression(null);
for (int i = 0; i < symbols.length; i++) {
SymbolTableEntry ste = origExp.getSymbolBinding(symbols[i]);
if (ste == null) {
throw new ExpressionBindingException("symbol '" + symbols[i] + "' not bound");
// ste = simContext.getGeometryContext().getModel().getSpeciesContext(symbols[i]);
}
if (ste != null) {
String newName = getMathSymbol(ste, geometryClass);
if (!newName.equals(symbols[i])) {
newExp.substituteInPlace(new Expression(symbols[i]), new Expression(newName));
}
}
}
return newExp;
}
use of cbit.vcell.parser.ExpressionBindingException in project vcell by virtualcell.
the class MathUtilities method substituteFunctions.
/**
* This method was created in VisualAge.
* @return cbit.vcell.parser.Expression
* @param exp cbit.vcell.parser.Expression
* @exception java.lang.Exception The exception description.
*/
public static Expression substituteFunctions(Expression exp, SymbolTable symbolTable) throws ExpressionException {
Expression exp2 = new Expression(exp);
//
// do until no more functions to substitute
//
int count = 0;
while (true) {
if (count++ > 30) {
throw new ExpressionBindingException("infinite loop in eliminating function nesting");
}
//
if (lg.isDebugEnabled()) {
lg.debug("substituteFunctions() exp2 = '" + exp2 + "'");
}
Enumeration<Variable> enum1 = getRequiredVariablesExplicit(exp2, symbolTable);
Vector<Variable> functionList = new Vector<Variable>();
while (enum1.hasMoreElements()) {
Variable var = enum1.nextElement();
if (var instanceof Function) {
functionList.addElement(var);
if (lg.isDebugEnabled()) {
lg.debug("added " + var + " to function list");
}
}
}
//
if (functionList.size() == 0) {
break;
}
//
for (int i = 0; i < functionList.size(); i++) {
Function funct = (Function) functionList.elementAt(i);
Expression functExp = new Expression(funct.getName() + ";");
if (lg.isDebugEnabled()) {
lg.debug("flattenFunctions(pass=" + count + "), substituting '" + funct.getExpression() + "' for function '" + functExp + "'");
}
exp2.substituteInPlace(functExp, new Expression(funct.getExpression()));
if (lg.isDebugEnabled()) {
lg.debug(".......substituted exp2 = '" + exp2 + "'");
}
}
}
// exp2 = exp2.flatten();
exp2.bindExpression(symbolTable);
return exp2;
}
Aggregations