Search in sources :

Example 21 with SymbolTableEntry

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

the class Model method gatherIssues.

/**
 * Insert the method's description here.
 * Creation date: (5/12/2004 10:38:12 PM)
 * @param issueList java.util.Vector
 */
public void gatherIssues(IssueContext issueContext, List<Issue> issueList) {
    issueContext = issueContext.newChildContext(ContextType.Model, this);
    // 
    try {
        for (ModelParameter modelParameter : fieldModelParameters) {
            Expression exp = modelParameter.getExpression();
            String[] symbols = exp.getSymbols();
            if (symbols != null) {
                String issueMsgPrefix = "Global parameter '" + modelParameter.getName() + "' ";
                for (int j = 0; j < symbols.length; j++) {
                    SymbolTableEntry ste = exp.getSymbolBinding(symbols[j]);
                    if (ste == null) {
                        issueList.add(new Issue(modelParameter, issueContext, IssueCategory.ModelParameterExpressionError, issueMsgPrefix + "references undefined symbol '" + symbols[j] + "'", Issue.SEVERITY_ERROR));
                    } else if (ste instanceof SpeciesContext) {
                        if (!contains((SpeciesContext) ste)) {
                            issueList.add(new Issue(modelParameter, issueContext, IssueCategory.ModelParameterExpressionError, issueMsgPrefix + "references undefined species '" + symbols[j] + "'", Issue.SEVERITY_ERROR));
                        }
                    } else if (ste instanceof ModelParameter) {
                        if (!contains((ModelParameter) ste)) {
                            issueList.add(new Issue(modelParameter, issueContext, IssueCategory.ModelParameterExpressionError, issueMsgPrefix + "references undefined global parameter '" + symbols[j] + "'", Issue.SEVERITY_ERROR));
                        }
                    }
                }
            }
        }
        // 
        for (int i = 0; i < fieldModelParameters.length; i++) {
            try {
                VCUnitEvaluator unitEvaluator = new VCUnitEvaluator(getUnitSystem());
                VCUnitDefinition paramUnitDef = fieldModelParameters[i].getUnitDefinition();
                VCUnitDefinition expUnitDef = unitEvaluator.getUnitDefinition(fieldModelParameters[i].getExpression());
                if (paramUnitDef == null) {
                    issueList.add(new Issue(fieldModelParameters[i], issueContext, IssueCategory.Units, "defined unit is null", Issue.SEVERITY_WARNING));
                } else if (expUnitDef == null) {
                    issueList.add(new Issue(fieldModelParameters[i], issueContext, IssueCategory.Units, "computed unit is null", Issue.SEVERITY_WARNING));
                } else if (paramUnitDef.isTBD()) {
                    issueList.add(new Issue(fieldModelParameters[i], issueContext, IssueCategory.Units, "unit is undefined (" + unitSystem.getInstance_TBD().getSymbol() + ")", Issue.SEVERITY_WARNING));
                } else if (!paramUnitDef.isEquivalent(expUnitDef) && !expUnitDef.isTBD()) {
                    issueList.add(new Issue(fieldModelParameters[i], issueContext, IssueCategory.Units, "unit mismatch, computed = [" + expUnitDef.getSymbol() + "]", Issue.SEVERITY_WARNING));
                }
            } catch (VCUnitException e) {
                issueList.add(new Issue(fieldModelParameters[i], issueContext, IssueCategory.Units, "units inconsistent: " + e.getMessage(), Issue.SEVERITY_WARNING));
            } catch (ExpressionException e) {
                issueList.add(new Issue(fieldModelParameters[i], issueContext, IssueCategory.Units, "units inconsistent: " + e.getMessage(), Issue.SEVERITY_WARNING));
            }
        }
    } catch (Throwable e) {
        e.printStackTrace(System.out);
        issueList.add(new Issue(this, issueContext, IssueCategory.Units, "unexpected exception: " + e.getMessage(), Issue.SEVERITY_WARNING));
    }
    // 
    for (Structure struct : fieldStructures) {
        struct.gatherIssues(issueContext, issueList);
    }
    // 
    for (int i = 0; i < fieldReactionSteps.length; i++) {
        fieldReactionSteps[i].gatherIssues(issueContext, issueList);
    }
    // 
    // get issues from species contexts (species patterns)
    // 
    int seedSpeciesCount = 0;
    for (int i = 0; i < fieldSpeciesContexts.length; i++) {
        if (fieldSpeciesContexts[i].hasSpeciesPattern()) {
            seedSpeciesCount++;
        }
        fieldSpeciesContexts[i].gatherIssues(issueContext, issueList);
    }
    if (seedSpeciesCount == 0 && !rbmModelContainer.getReactionRuleList().isEmpty()) {
        String msg = "At least one seed species is required.";
        issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, Issue.Severity.WARNING));
    }
    // 
    // get issues for symbol name clashes (specifically structures with same voltage names or structure names)
    // 
    HashSet<SymbolTableEntry> steHashSet = new HashSet<SymbolTableEntry>();
    gatherLocalEntries(steHashSet);
    Iterator<SymbolTableEntry> iter = steHashSet.iterator();
    Hashtable<String, SymbolTableEntry> symbolHashtable = new Hashtable<String, SymbolTableEntry>();
    while (iter.hasNext()) {
        SymbolTableEntry ste = iter.next();
        SymbolTableEntry existingSTE = symbolHashtable.get(ste.getName());
        if (existingSTE != null) {
            issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "model symbol \"" + ste.getName() + "\" is used within \"" + ste.getNameScope().getName() + "\" and \"" + existingSTE.getNameScope().getName() + "\"", Issue.SEVERITY_ERROR));
        } else {
            symbolHashtable.put(ste.getName(), ste);
        }
    }
    // 
    // gather issues for electrical topology (unspecified +ve or -ve features, or +ve feature == -ve feature
    // 
    getElectricalTopology().gatherIssues(issueContext, issueList);
    // 
    if (rbmModelContainer == null) {
        issueList.add(new Issue(this, issueContext, IssueCategory.InternalError, "Rbm Model Container is null", Issue.SEVERITY_WARNING));
    } else {
        rbmModelContainer.gatherIssues(issueContext, issueList);
    }
}
Also used : Issue(org.vcell.util.Issue) Hashtable(java.util.Hashtable) ExpressionException(cbit.vcell.parser.ExpressionException) VCUnitException(cbit.vcell.units.VCUnitException) VCUnitEvaluator(cbit.vcell.parser.VCUnitEvaluator) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) HashSet(java.util.HashSet)

Example 22 with SymbolTableEntry

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

the class MathUtilities method substituteModelParameters.

/**
 * 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 substituteModelParameters(Expression exp, SymbolTable symbolTable) throws ExpressionException {
    Expression exp2 = new Expression(exp);
    // 
    // do until no more functions to substitute
    // 
    int count = 0;
    boolean bSubstituted = true;
    while (bSubstituted) {
        bSubstituted = false;
        if (count++ > 30) {
            throw new ExpressionBindingException("infinite loop in eliminating function nesting");
        }
        String[] symbols = exp2.getSymbols();
        if (symbols != null) {
            for (int i = 0; i < symbols.length; i++) {
                SymbolTableEntry ste = exp2.getSymbolBinding(symbols[i]);
                if (ste != null && !(ste instanceof SymbolTableFunctionEntry)) {
                    Expression steExp = ste.getExpression();
                    if (steExp != null) {
                        exp2.substituteInPlace(new Expression(ste.getName()), steExp);
                        bSubstituted = true;
                    }
                }
            }
        }
    }
    exp2.bindExpression(symbolTable);
    return exp2;
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Expression(cbit.vcell.parser.Expression) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) SymbolTableFunctionEntry(cbit.vcell.parser.SymbolTableFunctionEntry)

Example 23 with SymbolTableEntry

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

the class MathUtilities method getRequiredVariablesExplicit.

/**
 * This method was created by a SmartGuide.
 * @return java.util.Enumeration
 * @param exp cbit.vcell.parser.Expression
 */
private static Enumeration<Variable> getRequiredVariablesExplicit(Expression exp, SymbolTable symbolTable) throws ExpressionException {
    Vector<Variable> requiredVarList = new Vector<Variable>();
    if (exp != null) {
        String[] identifiers = exp.getSymbols();
        if (lg.isDebugEnabled()) {
            lg.debug("from expression " + exp + " parsing identifiers " + Arrays.toString(identifiers));
        }
        if (identifiers != null) {
            for (int i = 0; i < identifiers.length; i++) {
                String id = identifiers[i];
                // 
                // look for globally bound variables
                // 
                SymbolTableEntry entry = symbolTable.getEntry(id);
                // 
                if (entry == null) {
                    entry = ReservedMathSymbolEntries.getReservedVariableEntry(id);
                    if (lg.isDebugEnabled()) {
                        lg.debug("id " + id + "not in symbol table looked for reserved symbols,found = " + (entry != null));
                    }
                } else if (lg.isDebugEnabled()) {
                    lg.debug("symbolTable.getEntry( ) returned " + entry + " for " + id);
                }
                // 
                if (entry == null) {
                    SymbolTableEntry ste = exp.getSymbolBinding(id);
                    if (ste instanceof PseudoConstant) {
                        entry = ste;
                    }
                    if (entry == null) {
                        ExpressionBindingException ebe = new ExpressionBindingException("unresolved symbol " + id + " in expression " + exp);
                        lg.debug("found " + ste + "but it's not a PseudoConstant; throwing ", ebe);
                        throw ebe;
                    }
                }
                if (!(entry instanceof Variable)) {
                    throw new RuntimeException("MathUtilities.getRequiredVariablesExplicit() only gets required math variable. Use math side symbol table, e.g. MathDescription, SimulationSymbolTable, etc.");
                }
                requiredVarList.addElement((Variable) entry);
            }
        }
    }
    return requiredVarList.elements();
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) Vector(java.util.Vector)

Example 24 with SymbolTableEntry

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

the class ReservedMathSymbolEntries method getEntry.

public static SymbolTableEntry getEntry(String symbolName, boolean bIncludePostProcessing) {
    SymbolTableEntry ste = getSymbolTableEntries().get(symbolName);
    if (ste != null) {
        return ste;
    }
    SymbolTableFunctionEntry steFunction = getMathSymbolTableFunctionEntries().get(symbolName);
    if (steFunction != null) {
        return steFunction;
    }
    if (bIncludePostProcessing) {
        steFunction = getPostProcessingSymbolTableFunctionEntries().get(symbolName);
        if (steFunction != null) {
            return steFunction;
        }
    }
    return null;
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) SymbolTableFunctionEntry(cbit.vcell.parser.SymbolTableFunctionEntry)

Example 25 with SymbolTableEntry

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

the class PdeTimePlotMultipleVariablesPanel method initialize.

private void initialize() {
    VariableType varType = multiTimePlotHelper.getPdeDatacontext().getDataIdentifier().getVariableType();
    String varName = multiTimePlotHelper.getPdeDatacontext().getVariableName();
    String[] plotNames = new String[pointVector.size()];
    final SymbolTableEntry[] symbolTableEntries = new SymbolTableEntry[plotNames.length];
    DefaultListModel<String> pointListModel = new DefaultListModel<String>();
    for (int i = 0; i < pointVector.size(); i++) {
        Coordinate tp = null;
        if (varType.equals(VariableType.VOLUME) || varType.equals(VariableType.VOLUME_REGION) || varType.equals(VariableType.POSTPROCESSING)) {
            SpatialSelectionVolume ssv = (SpatialSelectionVolume) pointVector.get(i);
            tp = ssv.getCurveSelectionInfo().getCurve().getBeginningCoordinate();
        } else if (varType.equals(VariableType.MEMBRANE) || varType.equals(VariableType.MEMBRANE_REGION)) {
            SpatialSelectionMembrane ssm = (SpatialSelectionMembrane) pointVector.get(i);
            double midU = ssm.getCurveSelectionInfo().getCurveUfromSelectionU(.5);
            tp = ((SampledCurve) ssm.getCurveSelectionInfo().getCurve()).coordinateFromNormalizedU(midU);
        }
        plotNames[i] = varName + " at P[" + i + "]";
        String point = "P[" + i + "]  (" + niceCoordinateString(tp) + ")";
        pointListModel.addElement(point);
        if (multiTimePlotHelper.getsimulation() != null) {
            symbolTableEntries[0] = multiTimePlotHelper.getsimulation().getMathDescription().getEntry(varName);
        } else {
            System.out.println("PdeTimePlotMultipleVariablesPanel.initialize() adding artificial symbol table entries for field data");
            SimpleSymbolTable simpleSymbolTable = new SimpleSymbolTable(new String[] { varName });
            symbolTableEntries[0] = simpleSymbolTable.getEntry(varName);
        }
    }
    pointJList.setModel(pointListModel);
    pointJList.setForeground(variableJList.getForeground());
    pointJList.setVisibleRowCount(3);
    pointJList.setBackground(getBackground());
    pointJList.setSelectionBackground(getBackground());
    pointJList.setSelectionForeground(Color.black);
    plotPane = new PlotPane();
    double[][] plotDatas = tsJobResultsNoStats.getTimesAndValuesForVariable(varName);
    Plot2D plot2D = new SingleXPlot2D(symbolTableEntries, multiTimePlotHelper.getDataSymbolMetadataResolver(), ReservedVariable.TIME.getName(), plotNames, plotDatas, new String[] { "Time Plot", ReservedVariable.TIME.getName(), "" });
    plotPane.setPlot2D(plot2D);
    DataIdentifier[] dis = (multiTimePlotHelper.getCopyOfDisplayedDataIdentifiers() != null ? multiTimePlotHelper.getCopyOfDisplayedDataIdentifiers() : DataIdentifier.collectSortedSimilarDataTypes(multiTimePlotHelper.getVariableType(), multiTimePlotHelper.getPdeDatacontext().getDataIdentifiers()));
    Arrays.sort(dis, new Comparator<DataIdentifier>() {

        public int compare(DataIdentifier o1, DataIdentifier o2) {
            int bEqualIgnoreCase = o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
            if (bEqualIgnoreCase == 0) {
                return o1.getDisplayName().compareTo(o2.getDisplayName());
            }
            return bEqualIgnoreCase;
        }
    });
    variableJList.setListData(dis);
    initVariableListSelected(variableJList, multiTimePlotHelper.getPdeDatacontext().getDataIdentifier());
    variableJList.setCellRenderer(multiTimePlotHelper.getListCellRenderer());
    setLayout(new GridBagLayout());
    JLabel label = new JLabel("Selected Points");
    label.setFont(label.getFont().deriveFont(Font.BOLD));
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new java.awt.Insets(15, 10, 4, 4);
    add(label, gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.fill = java.awt.GridBagConstraints.BOTH;
    gbc.gridheight = 4;
    gbc.weightx = 1;
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.insets = new java.awt.Insets(0, 4, 0, 0);
    add(plotPane, gbc);
    JScrollPane sp = new JScrollPane(pointJList);
    sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.weighty = 0.5;
    gbc.fill = java.awt.GridBagConstraints.BOTH;
    gbc.insets = new java.awt.Insets(4, 10, 4, 4);
    add(sp, gbc);
    label = new JLabel("Y Axis");
    label.setFont(label.getFont().deriveFont(Font.BOLD));
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new java.awt.Insets(4, 10, 4, 4);
    add(label, gbc);
    sp = new JScrollPane(variableJList);
    sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 3;
    gbc.weightx = 0.2;
    gbc.weighty = 1;
    gbc.insets = new java.awt.Insets(4, 10, 50, 4);
    gbc.fill = java.awt.GridBagConstraints.BOTH;
    add(sp, gbc);
    variableJList.addListSelectionListener(eventHandler);
    multiTimePlotHelper.addPropertyChangeListener(eventHandler);
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) DataIdentifier(cbit.vcell.simdata.DataIdentifier) GridBagLayout(java.awt.GridBagLayout) SpatialSelectionMembrane(cbit.vcell.simdata.SpatialSelectionMembrane) DefaultListModel(javax.swing.DefaultListModel) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) JScrollPane(javax.swing.JScrollPane) SampledCurve(cbit.vcell.geometry.SampledCurve) VariableType(cbit.vcell.math.VariableType) JLabel(javax.swing.JLabel) SingleXPlot2D(cbit.plot.SingleXPlot2D) SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) Coordinate(org.vcell.util.Coordinate) SpatialSelectionVolume(cbit.vcell.simdata.SpatialSelectionVolume) PlotPane(cbit.plot.gui.PlotPane) SingleXPlot2D(cbit.plot.SingleXPlot2D) Plot2D(cbit.plot.Plot2D)

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