Search in sources :

Example 71 with SymbolTableEntry

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;
}
Also used : VCUnitException(cbit.vcell.units.VCUnitException) VCUnitEvaluator(cbit.vcell.parser.VCUnitEvaluator) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Issue(org.vcell.util.Issue) Expression(cbit.vcell.parser.Expression) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ExpressionException(cbit.vcell.parser.ExpressionException) VCUnitException(cbit.vcell.units.VCUnitException) PropertyVetoException(java.beans.PropertyVetoException) MatrixException(cbit.vcell.matrix.MatrixException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ModelException(cbit.vcell.model.ModelException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) MathException(cbit.vcell.math.MathException)

Example 72 with SymbolTableEntry

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;
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry)

Example 73 with SymbolTableEntry

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);
    }
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry)

Example 74 with SymbolTableEntry

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;
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry)

Example 75 with SymbolTableEntry

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;
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ProxyParameter(cbit.vcell.model.ProxyParameter) Expression(cbit.vcell.parser.Expression) ProxyParameter(cbit.vcell.model.ProxyParameter) Parameter(cbit.vcell.model.Parameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) SpeciesContext(cbit.vcell.model.SpeciesContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec)

Aggregations

SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)115 Expression (cbit.vcell.parser.Expression)50 ExpressionException (cbit.vcell.parser.ExpressionException)20 Vector (java.util.Vector)20 ArrayList (java.util.ArrayList)19 SpeciesContext (cbit.vcell.model.SpeciesContext)18 ModelParameter (cbit.vcell.model.Model.ModelParameter)14 PropertyVetoException (java.beans.PropertyVetoException)14 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)13 Model (cbit.vcell.model.Model)12 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)11 HashMap (java.util.HashMap)11 SimulationContext (cbit.vcell.mapping.SimulationContext)10 Variable (cbit.vcell.math.Variable)10 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)9 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)9 Parameter (cbit.vcell.model.Parameter)9 SingleXPlot2D (cbit.plot.SingleXPlot2D)8 MathException (cbit.vcell.math.MathException)8 ReservedVariable (cbit.vcell.math.ReservedVariable)8