Search in sources :

Example 91 with SymbolTableEntry

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

the class PDEDataViewer method plotSpaceStats.

void plotSpaceStats(TSJobResultsSpaceStats tsjrss) {
    // Determine if Volume or Membrane
    DataIdentifier[] diArr = getPdeDataContext().getDataIdentifiers();
    boolean bVolume = true;
    for (int i = 0; i < diArr.length; i += 1) {
        if (diArr[i].getName().equals(tsjrss.getVariableNames()[0])) {
            if (diArr[i].getVariableType().equals(VariableType.MEMBRANE) || diArr[i].getVariableType().equals(VariableType.MEMBRANE_REGION)) {
                bVolume = false;
                break;
            }
        }
    }
    SymbolTableEntry[] symbolTableEntries = null;
    if (tsjrss.getVariableNames().length == 1) {
        // max.mean.min,sum
        symbolTableEntries = new SymbolTableEntry[3];
        if (getSimulation() != null && getSimulation().getMathDescription() != null) {
            symbolTableEntries[0] = getSimulation().getMathDescription().getEntry(tsjrss.getVariableNames()[0]);
        } else {
            symbolTableEntries[0] = new SimpleSymbolTable(tsjrss.getVariableNames()).getEntry(tsjrss.getVariableNames()[0]);
        }
        symbolTableEntries[1] = symbolTableEntries[0];
        symbolTableEntries[2] = symbolTableEntries[0];
    }
    SymbolTableEntry[] finalSymbolTableEntries = symbolTableEntries;
    boolean finalBVolume = bVolume;
    PlotPane plotPane = new cbit.plot.gui.PlotPane();
    plotPane.setPlot2D(new SingleXPlot2D(finalSymbolTableEntries, getSimulationModelInfo().getDataSymbolMetadataResolver(), "Time", new String[] { "Max", (tsjrss.getWeightedMean() != null ? "WeightedMean" : "UnweightedMean"), "Min" /*,
				(tsjrss.getWeightedSum() != null?"WeightedSum":"UnweightedSum")*/
    }, new double[][] { tsjrss.getTimes(), tsjrss.getMaximums()[0], (tsjrss.getWeightedMean() != null ? tsjrss.getWeightedMean()[0] : tsjrss.getUnweightedMean()[0]), tsjrss.getMinimums()[0] /*,
				(tsjrss.getWeightedSum() != null?tsjrss.getWeightedSum()[0]:tsjrss.getUnweightedSum()[0])*/
    }, new String[] { "Statistics Plot for " + tsjrss.getVariableNames()[0] + (tsjrss.getTotalSpace() != null ? " (ROI " + (finalBVolume ? "volume" : "area") + "=" + tsjrss.getTotalSpace()[0] + ")" : ""), ReservedVariable.TIME.getName(), "[" + tsjrss.getVariableNames()[0] + "]" }));
    String title = "Statistics: (" + tsjrss.getVariableNames()[0] + ") ";
    if (getSimulationModelInfo() != null) {
        title += getSimulationModelInfo().getContextName() + " " + getSimulationModelInfo().getSimulationName();
    }
    ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(PDEDataViewer.this);
    ChildWindow childWindow = childWindowManager.addChildWindow(plotPane, plotPane, title);
    childWindow.setIsCenteredOnParent();
    childWindow.pack();
    childWindow.show();
}
Also used : VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) LocalVCSimulationDataIdentifier(cbit.vcell.client.ClientSimManager.LocalVCSimulationDataIdentifier) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) ChildWindowManager(cbit.vcell.client.ChildWindowManager) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) Point(java.awt.Point) SinglePoint(cbit.vcell.geometry.SinglePoint) SingleXPlot2D(cbit.plot.SingleXPlot2D) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) PlotPane(cbit.plot.gui.PlotPane)

Example 92 with SymbolTableEntry

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

the class PDEDataViewer method showSpatialPlot.

/**
 * Comment
 */
private void showSpatialPlot() {
    // check selections
    final SpatialSelection[] sl = getPDEDataContextPanel1().fetchSpatialSelections(false, true);
    if (sl == null) {
        PopupGenerator.showErrorDialog(this, "Nothing selected!");
        return;
    }
    for (int i = 0; i < sl.length; i++) {
        if (sl[i].isPoint()) {
            PopupGenerator.showErrorDialog(this, "One or more selections are single points - no spatial plot will be produced for those selections");
            break;
        }
    }
    final String varName = getPdeDataContext().getVariableName();
    final double timePoint = getPdeDataContext().getTimePoint();
    final SymbolTableEntry[] symbolTableEntries = new SymbolTableEntry[1];
    if (getSimulation() != null && getSimulation().getMathDescription() != null) {
        symbolTableEntries[0] = getSimulation().getMathDescription().getEntry(varName);
    }
    if (symbolTableEntries[0] == null) {
        // TODO domain
        Domain domain = null;
        symbolTableEntries[0] = new VolVariable(varName, domain);
    }
    AsynchClientTask task1 = new AsynchClientTask("Retrieving spatial series for variable '" + varName, AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // get plots, ignoring points
            PlotData[] plotDatas = new PlotData[sl.length];
            for (int i = 0; i < sl.length; i++) {
                PlotData plotData = null;
                if (getPdeDataContext() instanceof PDEDataViewerPostProcess.PostProcessDataPDEDataContext) {
                    SpatialSelectionVolume ssVolume = (SpatialSelectionVolume) sl[i];
                    SpatialSelection.SSHelper ssvHelper = ssVolume.getIndexSamples(0.0, 1.0);
                    ssvHelper.initializeValues_VOLUME(getPdeDataContext().getDataValues());
                    double[] values = ssvHelper.getSampledValues();
                    plotData = new PlotData(ssvHelper.getWorldCoordinateLengths(), values);
                } else {
                    plotData = getPdeDataContext().getLineScan(varName, timePoint, sl[i]);
                }
                plotDatas[i] = plotData;
            }
            hashTable.put("plotDatas", plotDatas);
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("Showing spatial plot for variable" + varName, AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            PlotData[] plotDatas = (PlotData[]) hashTable.get("plotDatas");
            for (PlotData plotData : plotDatas) {
                if (plotData != null) {
                    PlotPane plotPane = new PlotPane();
                    Plot2D plot2D = new Plot2D(symbolTableEntries, getSimulationModelInfo().getDataSymbolMetadataResolver(), new String[] { varName }, new PlotData[] { plotData }, new String[] { "Values along curve", "Distance (\u00b5m)", "[" + varName + "]" });
                    plotPane.setPlot2D(plot2D);
                    String title = createContextTitle(PDEDataViewer.this.isPostProcess(), "Spatial Plot:'" + varName + "' ", getPdeDataContext(), getSimulationModelInfo(), getSimulation());
                    ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(PDEDataViewer.this);
                    ChildWindow childWindow = childWindowManager.addChildWindow(plotPane, plotPane, title);
                    childWindow.setIsCenteredOnParent();
                    childWindow.pack();
                    childWindow.show();
                // System.out.println("Spatial plot requesting focus.  Result is: "+childWindow.requestFocusInWindow());
                }
            }
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, false);
}
Also used : PlotData(cbit.plot.PlotData) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VolVariable(cbit.vcell.math.VolVariable) Hashtable(java.util.Hashtable) PostProcessDataPDEDataContext(cbit.vcell.client.data.PDEDataViewerPostProcess.PostProcessDataPDEDataContext) ChildWindowManager(cbit.vcell.client.ChildWindowManager) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) Point(java.awt.Point) SinglePoint(cbit.vcell.geometry.SinglePoint) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) SpatialSelection(cbit.vcell.simdata.SpatialSelection) SSHelper(cbit.vcell.simdata.SpatialSelection.SSHelper) SpatialSelectionVolume(cbit.vcell.simdata.SpatialSelectionVolume) PlotPane(cbit.plot.gui.PlotPane) SingleXPlot2D(cbit.plot.SingleXPlot2D) Plot2D(cbit.plot.Plot2D) VariableDomain(cbit.vcell.math.VariableType.VariableDomain) Domain(cbit.vcell.math.Variable.Domain)

Example 93 with SymbolTableEntry

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

the class XmlReader method getRateRules.

public RateRule[] getRateRules(SimulationContext simContext, Element rateRulesElement) throws XmlParseException {
    Iterator<Element> rateRulesIterator = rateRulesElement.getChildren(XMLTags.RateRuleTag, vcNamespace).iterator();
    Vector<RateRule> rateRulesVector = new Vector<RateRule>();
    while (rateRulesIterator.hasNext()) {
        Element rrElement = (Element) rateRulesIterator.next();
        RateRule newRateRule = null;
        try {
            String rrName = unMangle(rrElement.getAttributeValue(XMLTags.NameAttrTag));
            String varname = rrElement.getAttributeValue(XMLTags.RateRuleVariableAttrTag);
            SymbolTableEntry rrVar = simContext.getEntry(varname);
            Expression rrExp = unMangleExpression(rrElement.getText());
            newRateRule = new RateRule(rrName, rrVar, rrExp, simContext);
            newRateRule.bind();
        } catch (ExpressionBindingException e) {
            e.printStackTrace(System.out);
            throw new XmlParseException(e.getMessage());
        }
        if (newRateRule != null) {
            rateRulesVector.add(newRateRule);
        }
    }
    return ((RateRule[]) BeanUtils.getArray(rateRulesVector, RateRule.class));
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Expression(cbit.vcell.parser.Expression) Element(org.jdom.Element) RateRule(cbit.vcell.mapping.RateRule) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) Vector(java.util.Vector)

Example 94 with SymbolTableEntry

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

the class TriggerTemplatePanel method init.

public void init(SimulationContext simulationContext, AutoCompleteSymbolFilter autoCompleteSymbolFilter, BioEvent existingBioEvent) {
    if (simulationContext != null) {
        // mathOpComboBox.removeAllItems();
        // mathOpComboBox.addItem(BioEvent.TriggerComparison.greaterThan);
        // mathOpComboBox.addItem(BioEvent.TriggerComparison.lessThan);
        // mathOpComboBox.addItem(BioEvent.TriggerComparison.greaterThanOrEqual);
        // mathOpComboBox.addItem(BioEvent.TriggerComparison.lessThanOrEqual);
        varAboveComboBox.removeAllItems();
        varBelowComboBox.removeAllItems();
        SymbolTableEntry[] triggerExprSymbols = ModelOptimizationSpec.calculateTimeDependentModelObjects(simulationContext);
        Arrays.sort(triggerExprSymbols, new Comparator<SymbolTableEntry>() {

            @Override
            public int compare(SymbolTableEntry o1, SymbolTableEntry o2) {
                return o1.getName().compareToIgnoreCase(o2.getName());
            }
        });
        for (SymbolTableEntry ste : triggerExprSymbols) {
            if (!(ste instanceof ReservedSymbol)) {
                varAboveComboBox.addItem(ste);
                varBelowComboBox.addItem(ste);
            }
        }
        // setVerifier(simulationContext);
        Map<String, SymbolTableEntry> entryMap = new HashMap<String, SymbolTableEntry>();
        simulationContext.getEntries(entryMap);
        textFieldAboveVarVal.setAutoCompleteSymbolFilter(autoCompleteSymbolFilter);
        textFieldAboveVarVal.setAutoCompletionWords(entryMap.keySet());
        textFieldBelowVarVal.setAutoCompleteSymbolFilter(autoCompleteSymbolFilter);
        textFieldBelowVarVal.setAutoCompletionWords(entryMap.keySet());
        textFieldSingleTime.setAutoCompleteSymbolFilter(autoCompleteSymbolFilter);
        textFieldSingleTime.setAutoCompletionWords(entryMap.keySet());
        textFieldGeneral.setAutoCompleteSymbolFilter(autoCompleteSymbolFilter);
        textFieldGeneral.setAutoCompletionWords(entryMap.keySet());
        if (existingBioEvent != null) {
            // Edit Trigger mode
            switch(existingBioEvent.getTriggerType()) {
                case GeneralTrigger:
                    {
                        textFieldGeneral.setText(existingBioEvent.getParameter(BioEventParameterType.GeneralTriggerFunction).getExpression().infix());
                        rdbtnGeneral.setSelected(true);
                        break;
                    }
                case LogRangeTimes:
                    {
                        LocalParameter rangeMinParam = existingBioEvent.getParameter(BioEventParameterType.RangeMinTime);
                        if (rangeMinParam != null && rangeMinParam.getExpression() != null) {
                            textFieldLogMin.setText(rangeMinParam.getExpression().infix());
                        } else {
                            textFieldLogMin.setText("");
                        }
                        LocalParameter rangeMaxParam = existingBioEvent.getParameter(BioEventParameterType.RangeMaxTime);
                        if (rangeMaxParam != null && rangeMaxParam.getExpression() != null) {
                            textFieldLogMax.setText(rangeMaxParam.getExpression().infix());
                        } else {
                            textFieldLogMax.setText("");
                        }
                        LocalParameter rangeNumParam = existingBioEvent.getParameter(BioEventParameterType.RangeNumTimes);
                        if (rangeNumParam != null && rangeNumParam.getExpression() != null) {
                            textFieldLogNum.setText(rangeNumParam.getExpression().infix());
                        } else {
                            textFieldLogNum.setText("");
                        }
                        rdbtnLogTimeRange.setSelected(true);
                        break;
                    }
                case LinearRangeTimes:
                    {
                        LocalParameter rangeMinParam = existingBioEvent.getParameter(BioEventParameterType.RangeMinTime);
                        if (rangeMinParam != null && rangeMinParam.getExpression() != null) {
                            textFieldLinearMin.setText(rangeMinParam.getExpression().infix());
                        } else {
                            textFieldLinearMin.setText("");
                        }
                        LocalParameter rangeMaxParam = existingBioEvent.getParameter(BioEventParameterType.RangeMaxTime);
                        if (rangeMaxParam != null && rangeMaxParam.getExpression() != null) {
                            textFieldLinearMax.setText(rangeMaxParam.getExpression().infix());
                        } else {
                            textFieldLinearMax.setText("");
                        }
                        LocalParameter rangeNumParam = existingBioEvent.getParameter(BioEventParameterType.RangeNumTimes);
                        if (rangeNumParam != null && rangeNumParam.getExpression() != null) {
                            textFieldLinearNum.setText(rangeNumParam.getExpression().infix());
                        } else {
                            textFieldLinearNum.setText("");
                        }
                        rdbtnLinearTimeRange.setSelected(true);
                        break;
                    }
                case ListOfTimes:
                    {
                        StringBuffer sb = new StringBuffer();
                        for (LocalParameter p : existingBioEvent.getEventParameters()) {
                            if (p.getRole() == BioEventParameterType.TimeListItem) {
                                if (sb.length() > 0) {
                                    sb.append(",");
                                }
                                sb.append(p.getExpression().infix());
                            }
                        }
                        textFieldListTimes.setText(sb.toString());
                        rdbtnListTimes.setSelected(true);
                        break;
                    }
                case ObservableAboveThreshold:
                    {
                        LocalParameter observableParameter = existingBioEvent.getParameter(BioEventParameterType.Observable);
                        SymbolTableEntry ste = null;
                        if (observableParameter != null && observableParameter.getExpression() != null && observableParameter.getExpression().isIdentifier()) {
                            ste = observableParameter.getExpression().getSymbolBinding(observableParameter.getExpression().getSymbols()[0]);
                            varAboveComboBox.setSelectedItem(ste);
                        }
                        textFieldAboveVarVal.setText(existingBioEvent.getParameter(BioEventParameterType.Threshold).getExpression().infix());
                        rdbtnVarAboveThreshold.setSelected(true);
                        break;
                    }
                case ObservableBelowThreshold:
                    {
                        LocalParameter observableParameter = existingBioEvent.getParameter(BioEventParameterType.Observable);
                        SymbolTableEntry ste = null;
                        if (observableParameter != null && observableParameter.getExpression() != null && observableParameter.getExpression().isIdentifier()) {
                            ste = observableParameter.getExpression().getSymbolBinding(observableParameter.getExpression().getSymbols()[0]);
                            varBelowComboBox.setSelectedItem(ste);
                        }
                        textFieldBelowVarVal.setText(existingBioEvent.getParameter(BioEventParameterType.Threshold).getExpression().infix());
                        rdbtnVarBelowThreshold.setSelected(true);
                        break;
                    }
                case SingleTriggerTime:
                    {
                        LocalParameter parameter = existingBioEvent.getParameter(BioEventParameterType.SingleTriggerTime);
                        textFieldSingleTime.setText(parameter.getExpression().infix());
                        rdbtnSingleTime.setSelected(true);
                        break;
                    }
            }
        }
    }
}
Also used : LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) HashMap(java.util.HashMap) ReservedSymbol(cbit.vcell.model.Model.ReservedSymbol)

Example 95 with SymbolTableEntry

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

the class TriggerTemplatePanel method setTrigger.

// private void setVerifier(final SimulationContext simulationContext){
// textFieldGeneral.setInputVerifier(new InputVerifier() {
// @Override
// public boolean verify(JComponent input) {
// boolean bValid = true;
// if (textFieldGeneral.isEnabled()) {
// String text = textFieldGeneral.getText();
// String errorText = null;
// if (text == null || text.trim().length() == 0) {
// bValid = false;
// errorText = "Trigger expression cannot be empty";
// }else{
// Expression expr = null;
// try{
// expr = EventPanel.bindTriggerExpression(textFieldGeneral.getText(),simulationContext);
// }catch(Exception e){
// bValid = false;
// errorText = e.getMessage();
// }
// }
// if (bValid) {
// textFieldGeneral.setBorder(UIManager.getBorder("TextField.border"));
// //						getBtnPlotTrigger().setEnabled(true);
// textFieldGeneral.setToolTipText(null);
// } else {
// textFieldGeneral.setBorder(GuiConstants.ProblematicTextFieldBorder);
// //						getBtnPlotTrigger().setEnabled(false);
// textFieldGeneral.setToolTipText(errorText);
// //						SwingUtilities.invokeLater(new Runnable() {
// //						    public void run() {
// //						    	getTriggerTextField().requestFocus();
// //						    }
// //						});
// }
// }
// return bValid;
// }
// });
// 
// }
public void setTrigger(BioEvent bioEvent) throws Exception {
    LocalParameter delayParam = bioEvent.getParameter(BioEventParameterType.TriggerDelay);
    if (rdbtnGeneral.isSelected()) {
        bioEvent.setTriggerType(TriggerType.GeneralTrigger);
        bioEvent.setParameterValue(BioEventParameterType.GeneralTriggerFunction, new Expression(textFieldGeneral.getText()));
    } else if (rdbtnListTimes.isSelected()) {
        bioEvent.setTriggerType(TriggerType.ListOfTimes);
        Expression[] listExps = new Expression("myFunc(" + textFieldListTimes.getText() + ")").getFunctionInvocations(null)[0].getArguments();
        bioEvent.setTimeList(listExps);
    } else if (rdbtnLinearTimeRange.isSelected()) {
        bioEvent.setTriggerType(TriggerType.LinearRangeTimes);
        bioEvent.setParameterValue(BioEventParameterType.RangeMinTime, new Expression(textFieldLinearMin.getText()));
        bioEvent.setParameterValue(BioEventParameterType.RangeMaxTime, new Expression(textFieldLinearMax.getText()));
        bioEvent.setParameterValue(BioEventParameterType.RangeNumTimes, new Expression(textFieldLinearNum.getText()));
    } else if (rdbtnLogTimeRange.isSelected()) {
        bioEvent.setTriggerType(TriggerType.LogRangeTimes);
        bioEvent.setParameterValue(BioEventParameterType.RangeMinTime, new Expression(textFieldLogMin.getText()));
        bioEvent.setParameterValue(BioEventParameterType.RangeMaxTime, new Expression(textFieldLogMax.getText()));
        bioEvent.setParameterValue(BioEventParameterType.RangeNumTimes, new Expression(textFieldLogNum.getText()));
    } else if (rdbtnSingleTime.isSelected()) {
        bioEvent.setTriggerType(TriggerType.SingleTriggerTime);
        bioEvent.setParameterValue(BioEventParameterType.SingleTriggerTime, new Expression(textFieldSingleTime.getText()));
    } else if (rdbtnVarAboveThreshold.isSelected()) {
        bioEvent.setTriggerType(TriggerType.ObservableAboveThreshold);
        bioEvent.setParameterValue(BioEventParameterType.Observable, new Expression(((SymbolTableEntry) varAboveComboBox.getSelectedItem()).getName()));
        bioEvent.setParameterValue(BioEventParameterType.Threshold, new Expression(textFieldAboveVarVal.getText()));
    } else if (rdbtnVarBelowThreshold.isSelected()) {
        bioEvent.setTriggerType(TriggerType.ObservableBelowThreshold);
        bioEvent.setParameterValue(BioEventParameterType.Observable, new Expression(((SymbolTableEntry) varBelowComboBox.getSelectedItem()).getName()));
        bioEvent.setParameterValue(BioEventParameterType.Threshold, new Expression(textFieldBelowVarVal.getText()));
    }
    if (delayParam.getExpression() != null) {
        bioEvent.setParameterValue(BioEventParameterType.TriggerDelay, delayParam.getExpression());
    }
}
Also used : LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Expression(cbit.vcell.parser.Expression)

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