use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class MathMapping_4_8 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, StructureMapping structureMapping) 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);
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, structureMapping);
if (!newName.equals(symbols[i])) {
newExp.substituteInPlace(new Expression(symbols[i]), new Expression(newName));
}
}
}
return newExp;
}
use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class MathMapping_4_8 method getLocalEntry.
/**
* Insert the method's description here.
* Creation date: (4/4/2004 1:01:22 AM)
* @return cbit.vcell.parser.SymbolTableEntry
* @param identifier java.lang.String
*/
public SymbolTableEntry getLocalEntry(java.lang.String identifier) {
//
// the MathMapping "nameScope" is the union of the Model and SimContext namescopes (with the addition of any locally defined parameters)
//
//
// try "truely" local first
//
SymbolTableEntry localSTE = getMathMappingParameter(identifier);
//
// try "model" next
//
SymbolTableEntry modelSTE = simContext.getModel().getLocalEntry(identifier);
//
// try "simContext" next
//
SymbolTableEntry simContextSTE = simContext.getLocalEntry(identifier);
int resolutionCount = 0;
SymbolTableEntry ste = null;
if (localSTE != null) {
resolutionCount++;
ste = localSTE;
}
if (modelSTE != null) {
resolutionCount++;
ste = modelSTE;
}
if (simContextSTE != null) {
resolutionCount++;
ste = simContextSTE;
}
if (resolutionCount == 0 || resolutionCount == 1) {
return ste;
} else if (resolutionCount == 2) {
if (localSTE != null) {
if (modelSTE != null) {
// local and model
throw new RuntimeException("identifier '" + identifier + "' ambiguous, resolved by MathMapping (" + localSTE + ") and Model (" + modelSTE + ")");
} else {
// local and simContext
throw new RuntimeException("identifier '" + identifier + "' ambiguous, resolved by MathMapping (" + localSTE + ") and Application (" + simContextSTE + ")");
}
} else {
// model and simContext
if (!modelSTE.equals(simContextSTE)) {
throw new RuntimeException("identifier '" + identifier + "' ambiguous, resolved by Model (" + modelSTE + ") and Application (" + simContextSTE + ")");
} else {
return ste;
}
}
} else if (resolutionCount == 3) {
// local and model and simContext
throw new RuntimeException("identifier '" + identifier + "' ambiguous, resolved by MathMapping (" + localSTE + ") and Model (" + modelSTE + ") and Application (" + simContextSTE + ")");
}
return null;
}
use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class MathMapping_4_8 method getLocalEntries.
public void getLocalEntries(Map<String, SymbolTableEntry> entryMap) {
simContext.getModel().getLocalEntries(entryMap);
simContext.getLocalEntries(entryMap);
for (SymbolTableEntry ste : fieldMathMappingParameters) {
entryMap.put(ste.getName(), ste);
}
}
use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class MathMapping_4_8 method getEntry.
/**
* getEntry method comment.
*/
public SymbolTableEntry getEntry(java.lang.String identifierString) {
SymbolTableEntry ste = getLocalEntry(identifierString);
if (ste != null) {
return ste;
}
ste = getNameScope().getExternalEntry(identifierString, this);
if (ste == null) {
System.out.println("MathMapping is unable to bind identifier '" + identifierString + "'");
}
return ste;
}
use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class StochMathMapping_4_8 method getSubstitutedExpr.
/**
* @param expr
* @param bConcentration
* @return
* @throws ExpressionException
*/
private Expression getSubstitutedExpr(Expression expr, boolean bConcentration, boolean bIsInitialCondn) throws ExpressionException {
expr = new Expression(expr);
String[] symbols = expr.getSymbols();
// Check if 'expr' has other speciesContexts in its expression, need to replace it with 'spContext_init'
for (int j = 0; symbols != null && j < symbols.length; j++) {
// if symbol is a speciesContext, replacing it with a reference to initial condition for that speciesContext.
SpeciesContext spC = null;
SymbolTableEntry ste = expr.getSymbolBinding(symbols[j]);
if (ste instanceof ProxyParameter) {
// if expression is for speciesContextSpec or Kinetics, ste will be a ProxyParameter instance.
ProxyParameter spspp = (ProxyParameter) ste;
if (spspp.getTarget() instanceof SpeciesContext) {
spC = (SpeciesContext) spspp.getTarget();
}
} else if (ste instanceof SpeciesContext) {
// if expression is for a global parameter, ste will be a SpeciesContext instance.
spC = (SpeciesContext) ste;
}
if (spC != null) {
SpeciesContextSpec spcspec = getSimulationContext().getReactionContext().getSpeciesContextSpec(spC);
Parameter spCParm = null;
if (bConcentration && bIsInitialCondn) {
// speciesContext has initConcentration set, so need to replace 'spContext' in 'expr' 'spContext_init'
spCParm = spcspec.getParameterFromRole(SpeciesContextSpec.ROLE_InitialConcentration);
} else if (!bConcentration && bIsInitialCondn) {
// speciesContext has initCount set, so need to replace 'spContext' in 'expr' 'spContext_initCount'
spCParm = spcspec.getParameterFromRole(SpeciesContextSpec.ROLE_InitialCount);
} else if (bConcentration && !bIsInitialCondn) {
// need to replace 'spContext' in 'expr' 'spContext_Conc'
spCParm = getSpeciesConcentrationParameter(spC);
} else if (!bConcentration && !bIsInitialCondn) {
// need to replace 'spContext' in 'expr' 'spContext_Count'
spCParm = getSpeciesCountParameter(spC);
}
// need to get init condn expression, but can't get it from getMathSymbol() (mapping between bio and math), hence get it as below.
Expression scsInitExpr = new Expression(spCParm, getNameScope());
// scsInitExpr.bindExpression(this);
expr.substituteInPlace(new Expression(spC.getName()), scsInitExpr);
}
}
return expr;
}
Aggregations