Search in sources :

Example 6 with SymbolTableEntry

use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.

the class RbmUtils method toBnglString.

public static String toBnglString(Parameter parameter, boolean bFunction) {
    if (!bFunction) {
        // parameter
        String str = parameter.getName() + " ";
        if (parameter.getExpression() != null) {
            str += parameter.getExpression().infixBng();
        } else {
            str = "# " + str + "(expression undefined)";
        }
        return str;
    } else {
        // function
        String str = parameter.getName() + "()\t=\t";
        if (parameter.getExpression() != null) {
            String[] symbols = parameter.getExpression().getSymbols();
            for (String s : symbols) {
                SymbolTableEntry ste = parameter.getExpression().getSymbolBinding(s);
                if (ste instanceof SpeciesContext) {
                    System.out.println("SpeciesContext '" + s + "' found in expression of function, not exporting");
                    str = "# " + str;
                    break;
                }
            }
            str += parameter.getExpression().infixBng();
        } else {
            str = "# " + str + "(expression undefined)";
        }
        return str;
    }
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) SpeciesContext(cbit.vcell.model.SpeciesContext)

Example 7 with SymbolTableEntry

use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.

the class RbmUtils method getBoundExpression.

public static Expression getBoundExpression(String expressionString, final SymbolTable symbolTable) throws ExpressionException {
    Expression exp = null;
    if (expressionString == null || expressionString.equals("")) {
        exp = new Expression(0);
    } else {
        exp = new Expression(expressionString);
    }
    // 
    // look for function invocations of unsupported but known functions
    // 
    FunctionInvocation[] invocations = exp.getFunctionInvocations(new FunctionFilter() {

        @Override
        public boolean accept(String functionName, FunctionType functionType) {
            if (functionName.equalsIgnoreCase("if")) {
                return true;
            }
            return false;
        }
    });
    if (invocations != null && invocations.length > 0) {
        for (FunctionInvocation invocation : invocations) {
            if (invocation.getFunctionName().equalsIgnoreCase("if")) {
                // build new expression
                // if (testExp, trueExp, falseExp)
                // 
                Expression testExp = invocation.getArguments()[0];
                Expression trueExp = invocation.getArguments()[1];
                Expression falseExp = invocation.getArguments()[2];
                Expression testPassed = Expression.relational("!=", testExp, new Expression(0.0));
                Expression testFailed = Expression.relational("==", testExp, new Expression(0.0));
                Expression newExp = Expression.add(Expression.mult(testPassed, trueExp), Expression.mult(testFailed, falseExp));
                // substitute new expression replacing if()
                exp.substituteInPlace(invocation.getFunctionExpression(), newExp);
            }
        }
        System.out.println(invocations.toString());
    }
    // 
    // "if()" functions are goine ... but lets look for BNGL function invocations
    // 1) if they have no arguments, drop the "()".
    // 2) if they have arguments, have to substitute the arguments in the expression ... flatten it.
    // 
    invocations = exp.getFunctionInvocations(new FunctionFilter() {

        @Override
        public boolean accept(String functionName, FunctionType functionType) {
            return true;
        }
    });
    if (invocations != null && invocations.length > 0) {
        for (FunctionInvocation invocation : invocations) {
            if (invocation.getArguments().length == 0) {
                // 
                // no arguments, look for existing parameter by name (parameter name is function name).
                // 
                // look up "identifier()" as "identifier" to find a model parameter generated earlier when processing functions (or prior functions)
                // 
                SymbolTableEntry parameter = symbolTable.getEntry(invocation.getFunctionName());
                if (parameter != null) {
                    exp.substituteInPlace(invocation.getFunctionExpression(), new Expression(parameter, parameter.getNameScope()));
                } else {
                    // 
                    // didn't find a parameter, may be a built-in function with zero arguments built into VCell. (none exists right now).
                    // 
                    SymbolTableFunctionEntry vcellFunction = (SymbolTableFunctionEntry) symbolTable.getEntry(invocation.getFormalDefinition());
                    if (vcellFunction != null) {
                    // 
                    // nothing to do, vcell will parse and interpret this correctly
                    // 
                    } else {
                        throw new RuntimeException("function \"" + invocation.getFunctionExpression().infix() + "\" not found as a bngl function or as a vcell built-in function");
                    }
                }
            } else {
                // 
                // should be a build-in vcell function with arguments ... user defined functions with arguments not supported yet in bngl import.
                // 
                FunctionType builtinFunctionType = cbit.vcell.parser.ASTFuncNode.FunctionType.fromFunctionName(invocation.getFunctionName());
                if (builtinFunctionType == null) {
                    throw new RuntimeException("function \"" + invocation.getFunctionExpression().infix() + "\" not found as a built-in VCell function (and bngl functions with arguments are not yet supported");
                } else {
                    if (invocation.getArguments().length != builtinFunctionType.getArgTypes().length) {
                        throw new RuntimeException("built-in function \"" + invocation.getFunctionExpression().infix() + "\" expects " + builtinFunctionType.getArgTypes().length + " arguments");
                    }
                }
            }
            System.out.println(invocations.toString());
        }
    }
    exp.bindExpression(symbolTable);
    return exp;
}
Also used : FunctionInvocation(cbit.vcell.parser.FunctionInvocation) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) FunctionFilter(cbit.vcell.parser.Expression.FunctionFilter) Expression(cbit.vcell.parser.Expression) ASTExpression(org.vcell.model.bngl.ASTExpression) FunctionType(cbit.vcell.parser.ASTFuncNode.FunctionType) SymbolTableFunctionEntry(cbit.vcell.parser.SymbolTableFunctionEntry)

Example 8 with SymbolTableEntry

use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.

the class BioModelParametersTableModel method computeData.

/**
 * Insert the method's description here.
 * Creation date: (9/23/2003 1:24:52 PM)
 * @return cbit.vcell.model.EditableSymbolTableEntry
 * @param row int
 */
protected List<EditableSymbolTableEntry> computeData() {
    ArrayList<EditableSymbolTableEntry> allEditableSymbolTableEntryList = new ArrayList<EditableSymbolTableEntry>();
    if (bioModel == null) {
        return null;
    }
    if (bGlobal) {
        Map<String, SymbolTableEntry> entryMap = new HashMap<String, SymbolTableEntry>();
        bioModel.getModel().getEntries(entryMap);
        for (SymbolTableEntry ste : entryMap.values()) {
            if (ste instanceof EditableSymbolTableEntry && !(ste instanceof ReservedSymbol)) {
                allEditableSymbolTableEntryList.add((EditableSymbolTableEntry) ste);
            }
        }
    }
    if (bReactions) {
        for (ReactionStep reactionStep : bioModel.getModel().getReactionSteps()) {
            allEditableSymbolTableEntryList.addAll(Arrays.asList(reactionStep.getKinetics().getUnresolvedParameters()));
            allEditableSymbolTableEntryList.addAll(Arrays.asList(reactionStep.getKinetics().getKineticsParameters()));
        }
        if (!bioModel.getModel().getRbmModelContainer().isEmpty()) {
            for (ReactionRule reactionRule : bioModel.getModel().getRbmModelContainer().getReactionRuleList()) {
                allEditableSymbolTableEntryList.addAll(Arrays.asList(reactionRule.getKineticLaw().getLocalParameters()));
                allEditableSymbolTableEntryList.addAll(Arrays.asList(reactionRule.getKineticLaw().getProxyParameters()));
                allEditableSymbolTableEntryList.addAll(Arrays.asList(reactionRule.getKineticLaw().getUnresolvedParameters()));
            }
        }
    }
    if (bApplications) {
        for (SimulationContext simContext : bioModel.getSimulationContexts()) {
            if (applicationSelection != null && (applicationSelection.isAll() || applicationSelection.getSimulationContext() == simContext)) {
                allEditableSymbolTableEntryList.addAll(getApplicationEditableSymbolTableEntryList(simContext));
            }
        }
    }
    boolean bSearchInactive = searchText == null || searchText.length() == 0;
    String lowerCaseSearchText = bSearchInactive ? null : searchText.toLowerCase();
    ArrayList<EditableSymbolTableEntry> parameterList = new ArrayList<EditableSymbolTableEntry>();
    for (EditableSymbolTableEntry parameter : allEditableSymbolTableEntryList) {
        boolean bNumeric = parameter.getExpression() == null || parameter.getExpression().isNumeric();
        if (bConstants && bNumeric || bFunctions && !bNumeric) {
            if (bSearchInactive || parameter.getNameScope().getPathDescription().toLowerCase().contains(lowerCaseSearchText) || parameter.getName().toLowerCase().contains(lowerCaseSearchText) || parameter.getExpression() != null && parameter.getExpression().infix().toLowerCase().contains(lowerCaseSearchText) || parameter.getDescription().toLowerCase().contains(lowerCaseSearchText)) {
                parameterList.add(parameter);
            }
        }
    }
    return parameterList;
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) EditableSymbolTableEntry(cbit.vcell.model.EditableSymbolTableEntry) ReactionRule(cbit.vcell.model.ReactionRule) HashMap(java.util.HashMap) ReservedSymbol(cbit.vcell.model.Model.ReservedSymbol) ReactionStep(cbit.vcell.model.ReactionStep) ArrayList(java.util.ArrayList) SimulationContext(cbit.vcell.mapping.SimulationContext) EditableSymbolTableEntry(cbit.vcell.model.EditableSymbolTableEntry)

Example 9 with SymbolTableEntry

use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.

the class SimulationContext method getLocalEntries.

public void getLocalEntries(Map<String, SymbolTableEntry> entryMap) {
    getModel().getEntries(entryMap);
    for (SymbolTableEntry ste : fieldSimulationContextParameters) {
        entryMap.put(ste.getName(), ste);
    }
    for (SymbolTableEntry ste : dataContext.getDataSymbols()) {
        entryMap.put(ste.getName(), ste);
    }
    for (SpatialObject spatialObject : spatialObjects) {
        for (SpatialQuantity spatialQuantity : spatialObject.getSpatialQuantities()) {
            if (spatialQuantity.isEnabled()) {
                entryMap.put(spatialQuantity.getName(), spatialQuantity);
            }
        }
    }
    entryMap.put(MathFunctionDefinitions.fieldFunctionDefinition.getName(), MathFunctionDefinitions.fieldFunctionDefinition);
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) SpatialQuantity(cbit.vcell.mapping.spatial.SpatialObject.SpatialQuantity) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject)

Example 10 with SymbolTableEntry

use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.

the class SpeciesContextSpec method getEntry.

/**
 * getEntry method comment.
 */
public SymbolTableEntry getEntry(String identifierString) {
    SymbolTableEntry ste = getLocalEntry(identifierString);
    if (ste != null) {
        return ste;
    }
    ste = getNameScope().getExternalEntry(identifierString, this);
    if (ste instanceof SymbolTableFunctionEntry) {
        return ste;
    }
    if (ste != null) {
        if (ste instanceof SymbolTableFunctionEntry) {
            return ste;
        } else {
            return addProxyParameter(ste);
        }
    }
    return null;
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) SymbolTableFunctionEntry(cbit.vcell.parser.SymbolTableFunctionEntry)

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