Search in sources :

Example 1 with SymbolTable

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

the class MovingBoundaryFileWriter method flattenExpression.

private Expression flattenExpression(Expression ex, VariableDomain varDomain) throws ExpressionException, MathException {
    SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
    Variable normalX = new Variable("normalX", null) {

        public boolean compareEqual(Matchable object, boolean bIgnoreMissingDomains) {
            return false;
        }

        public String getVCML() throws MathException {
            return null;
        }
    };
    Variable normalY = new Variable("normalY", null) {

        public boolean compareEqual(Matchable object, boolean bIgnoreMissingDomains) {
            return false;
        }

        public String getVCML() throws MathException {
            return null;
        }
    };
    SymbolTable augmentedSymbolTable = new SymbolTable() {

        @Override
        public SymbolTableEntry getEntry(String identifierString) {
            if (identifierString.equals(normalX.getName())) {
                return normalX;
            }
            if (identifierString.equals(normalY.getName())) {
                return normalY;
            }
            return simSymbolTable.getEntry(identifierString);
        }

        @Override
        public void getEntries(Map<String, SymbolTableEntry> entryMap) {
            simSymbolTable.getEntries(entryMap);
            entryMap.put(normalX.getName(), normalX);
            entryMap.put(normalY.getName(), normalY);
        }
    };
    ex = new Expression(ex);
    ex.bindExpression(augmentedSymbolTable);
    Expression flattended = MathUtilities.substituteFunctions(ex, augmentedSymbolTable).flatten();
    Expression substituted = SolverUtilities.substituteSizeAndNormalFunctions(flattended, varDomain).flatten();
    return substituted;
// return simSymbolTable.substituteFunctions(ex).flatten().infix();
}
Also used : PointVariable(cbit.vcell.math.PointVariable) Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) Expression(cbit.vcell.parser.Expression) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) SymbolTable(cbit.vcell.parser.SymbolTable) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) Map(java.util.Map) Matchable(org.vcell.util.Matchable)

Example 2 with SymbolTable

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

the class ODESolverPlotSpecificationPanel method setSymbolTable.

/**
 * Sets the symbolTable property (cbit.vcell.parser.SymbolTable) value.
 * @param symbolTable The new value for the property.
 * @see #getSymbolTable
 */
public void setSymbolTable(SymbolTable symbolTable) {
    SymbolTable oldValue = fieldSymbolTable;
    fieldSymbolTable = symbolTable;
    firePropertyChange("symbolTable", oldValue, symbolTable);
}
Also used : SymbolTable(cbit.vcell.parser.SymbolTable)

Example 3 with SymbolTable

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

the class ModelUnitConverter method createBioModelWithNewUnitSystem.

public static BioModel createBioModelWithNewUnitSystem(BioModel oldBioModel, ModelUnitSystem newUnitSystem) throws ExpressionException, XmlParseException {
    // new BioModel has new unit system applied to all built-in units ... but expressions still need to be corrected (see below).
    BioModel newBioModel = XmlHelper.cloneBioModelWithNewUnitSystem(oldBioModel, newUnitSystem);
    Model newModel = newBioModel.getModel();
    Model oldModel = oldBioModel.getModel();
    for (Parameter p : newBioModel.getModel().getModelParameters()) {
        convertVarsWithUnitFactors(oldBioModel.getModel(), newBioModel.getModel(), p);
    }
    for (ReactionStep reactionStep : newBioModel.getModel().getReactionSteps()) {
        SymbolTable oldSymbolTable = oldBioModel.getModel().getReactionStep(reactionStep.getName());
        SymbolTable newSymbolTable = reactionStep;
        for (Parameter p : reactionStep.getKinetics().getUnresolvedParameters()) {
            convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
        }
        for (Parameter p : reactionStep.getKinetics().getKineticsParameters()) {
            convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
        }
    }
    for (ReactionRule reactionRule : newBioModel.getModel().getRbmModelContainer().getReactionRuleList()) {
        SymbolTable oldSymbolTable = oldBioModel.getModel().getRbmModelContainer().getReactionRule(reactionRule.getName()).getKineticLaw().getScopedSymbolTable();
        SymbolTable newSymbolTable = reactionRule.getKineticLaw().getScopedSymbolTable();
        for (Parameter p : reactionRule.getKineticLaw().getUnresolvedParameters()) {
            convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
        }
        for (Parameter p : reactionRule.getKineticLaw().getLocalParameters()) {
            convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
        }
    }
    for (SimulationContext simContext : newBioModel.getSimulationContexts()) {
        SimulationContext oldSimContext = oldBioModel.getSimulationContext(simContext.getName());
        // ArrayList<Parameter> parameterList = new ArrayList<Parameter>();
        for (StructureMapping mapping : simContext.getGeometryContext().getStructureMappings()) {
            Structure oldStructure = oldModel.getStructure(mapping.getStructure().getName());
            StructureMapping oldMapping = oldSimContext.getGeometryContext().getStructureMapping(oldStructure);
            for (Parameter p : mapping.computeApplicableParameterList()) {
                convertVarsWithUnitFactors(oldMapping, mapping, p);
            }
        }
        for (SpeciesContextSpec spec : simContext.getReactionContext().getSpeciesContextSpecs()) {
            SpeciesContext oldSpeciesContext = oldModel.getSpeciesContext(spec.getSpeciesContext().getName());
            SpeciesContextSpec oldSpec = oldSimContext.getReactionContext().getSpeciesContextSpec(oldSpeciesContext);
            for (Parameter p : spec.computeApplicableParameterList()) {
                convertVarsWithUnitFactors(oldSpec, spec, p);
            }
        }
        for (int i = 0; i < simContext.getElectricalStimuli().length; i++) {
            ElectricalStimulus newElectricalStimulus = simContext.getElectricalStimuli()[i];
            ElectricalStimulus oldElectricalStimulus = oldSimContext.getElectricalStimuli()[i];
            for (Parameter p : newElectricalStimulus.getParameters()) {
                convertVarsWithUnitFactors(oldElectricalStimulus.getNameScope().getScopedSymbolTable(), newElectricalStimulus.getNameScope().getScopedSymbolTable(), p);
            }
        }
        // convert events : trigger and delay parameters and event assignments
        for (int i = 0; simContext.getBioEvents() != null && oldSimContext.getBioEvents() != null && i < simContext.getBioEvents().length; i++) {
            BioEvent newBioEvent = simContext.getBioEvents()[i];
            BioEvent oldBioEvent = oldSimContext.getBioEvent(newBioEvent.getName());
            for (Parameter p : newBioEvent.getEventParameters()) {
                convertVarsWithUnitFactors(oldBioEvent.getNameScope().getScopedSymbolTable(), newBioEvent.getNameScope().getScopedSymbolTable(), p);
            }
            // for each event assignment expression
            for (int e = 0; e < newBioEvent.getEventAssignments().size(); e++) {
                ScopedSymbolTable newSymbolTable = newBioEvent.getNameScope().getScopedSymbolTable();
                ScopedSymbolTable oldSymbolTable = oldBioEvent.getNameScope().getScopedSymbolTable();
                EventAssignment newEventAssignment = newBioEvent.getEventAssignments().get(e);
                EventAssignment oldEventAssignment = oldBioEvent.getEventAssignments().get(e);
                VCUnitDefinition oldTargetUnit = oldEventAssignment.getTarget().getUnitDefinition();
                VCUnitDefinition newTargetUnit = newEventAssignment.getTarget().getUnitDefinition();
                Expression eventAssgnExpr = newEventAssignment.getAssignmentExpression();
                convertExprWithUnitFactors(oldSymbolTable, newSymbolTable, oldTargetUnit, newTargetUnit, eventAssgnExpr);
            }
        }
        /**
         * @TODO: If rate rule variable unit is TBD, we still need to handle the rate expression unit.
         */
        // convert rate rules
        RateRule[] rateRules = simContext.getRateRules();
        if (rateRules != null && rateRules.length > 0) {
            for (RateRule rateRule : rateRules) {
                RateRule oldRateRule = oldSimContext.getRateRule(rateRule.getName());
                ScopedSymbolTable oldSymbolTable = oldRateRule.getSimulationContext();
                ScopedSymbolTable newSymbolTable = rateRule.getSimulationContext();
                VCUnitDefinition oldTargetUnit = oldRateRule.getRateRuleVar().getUnitDefinition();
                VCUnitDefinition newTargetUnit = rateRule.getRateRuleVar().getUnitDefinition();
                Expression rateRuleExpr = rateRule.getRateRuleExpression();
                convertExprWithUnitFactors(oldSymbolTable, newSymbolTable, oldTargetUnit, newTargetUnit, rateRuleExpr);
            }
        }
    }
    // end  for - simulationContext
    return newBioModel;
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) EventAssignment(cbit.vcell.mapping.BioEvent.EventAssignment) ScopedSymbolTable(cbit.vcell.parser.ScopedSymbolTable) SymbolTable(cbit.vcell.parser.SymbolTable) SpeciesContext(cbit.vcell.model.SpeciesContext) SimulationContext(cbit.vcell.mapping.SimulationContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) StructureMapping(cbit.vcell.mapping.StructureMapping) ElectricalStimulus(cbit.vcell.mapping.ElectricalStimulus) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) ReactionStep(cbit.vcell.model.ReactionStep) Model(cbit.vcell.model.Model) Parameter(cbit.vcell.model.Parameter) RateRule(cbit.vcell.mapping.RateRule) ScopedSymbolTable(cbit.vcell.parser.ScopedSymbolTable) BioEvent(cbit.vcell.mapping.BioEvent) Structure(cbit.vcell.model.Structure)

Example 4 with SymbolTable

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

the class PDEDataViewer method showKymograph.

private void showKymograph() {
    String title = createContextTitle(PDEDataViewer.this.isPostProcess(), "Kymograph: ", getPdeDataContext(), getSimulationModelInfo(), getSimulation());
    final String INDICES_KEY = "INDICES_KEY";
    final String CROSSING_KEY = "CROSSING_KEY";
    final String ACCUM_KEY = "ACCUM_KEY";
    AsynchClientTask multiTimePlotHelperTask = new AsynchClientTask("multiTimePlotHelperTask...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // Collect all sample curves created by user
            SpatialSelection[] spatialSelectionArr = getPDEDataContextPanel1().fetchSpatialSelections(false, true);
            final Vector<SpatialSelection> lineSSOnly = new Vector<SpatialSelection>();
            if (spatialSelectionArr != null && spatialSelectionArr.length > 0) {
                // 
                for (int i = 0; i < spatialSelectionArr.length; i++) {
                    if (spatialSelectionArr[i].isPoint() || (spatialSelectionArr[i] instanceof SpatialSelectionMembrane && ((SpatialSelectionMembrane) spatialSelectionArr[i]).getSelectionSource() instanceof cbit.vcell.geometry.SinglePoint)) {
                    } else {
                        lineSSOnly.add(spatialSelectionArr[i]);
                    }
                }
            }
            // 
            if (lineSSOnly.size() == 0) {
                throw new Exception("No line samples match DataType=" + getPdeDataContext().getDataIdentifier().getVariableType());
            }
            VariableType varType = getPdeDataContext().getDataIdentifier().getVariableType();
            int[] indices = null;
            int[] crossingMembraneIndices = null;
            double[] accumDistances = null;
            for (int i = 0; i < lineSSOnly.size(); i++) {
                if (varType.equals(VariableType.VOLUME) || varType.equals(VariableType.VOLUME_REGION) || varType.equals(VariableType.POSTPROCESSING)) {
                    SpatialSelectionVolume ssv = (SpatialSelectionVolume) lineSSOnly.get(i);
                    SpatialSelection.SSHelper ssh = ssv.getIndexSamples(0.0, 1.0);
                    indices = ssh.getSampledIndexes();
                    crossingMembraneIndices = ssh.getMembraneIndexesInOut();
                    accumDistances = ssh.getWorldCoordinateLengths();
                } else if (varType.equals(VariableType.MEMBRANE) || varType.equals(VariableType.MEMBRANE_REGION)) {
                    SpatialSelectionMembrane ssm = (SpatialSelectionMembrane) lineSSOnly.get(i);
                    SpatialSelection.SSHelper ssh = ssm.getIndexSamples();
                    indices = ssh.getSampledIndexes();
                    accumDistances = ssh.getWorldCoordinateLengths();
                }
            }
            if (indices != null) {
                hashTable.put(INDICES_KEY, indices);
            }
            if (crossingMembraneIndices != null) {
                hashTable.put(CROSSING_KEY, crossingMembraneIndices);
            }
            if (accumDistances != null) {
                hashTable.put(ACCUM_KEY, accumDistances);
            }
            MultiTimePlotHelper multiTimePlotHelper = createMultiTimePlotHelper((ClientPDEDataContext) getPdeDataContext(), getDataViewerManager().getUser(), getSimulationModelInfo().getDataSymbolMetadataResolver());
            hashTable.put(MULTITPHELPER_TASK_KEY, multiTimePlotHelper);
        }
    };
    AsynchClientTask kymographTask = new AsynchClientTask("Kymograph showing...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            KymographPanel kymographPanel = new KymographPanel(PDEDataViewer.this, title, (MultiTimePlotHelper) hashTable.get(MULTITPHELPER_TASK_KEY));
            SymbolTable symbolTable;
            if (getSimulation() != null && getSimulation().getMathDescription() != null) {
                symbolTable = getSimulation().getMathDescription();
            } else {
                symbolTable = new SimpleSymbolTable(new String[] { getPdeDataContext().getDataIdentifier().getName() });
            }
            ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(PDEDataViewer.this);
            ChildWindow childWindow = childWindowManager.addChildWindow(kymographPanel, kymographPanel, title);
            childWindow.setSize(new Dimension(700, 500));
            childWindow.show();
            kymographPanel.initDataManager(getPdeDataContext().getDataIdentifier(), getPdeDataContext().getTimePoints()[0], 1, getPdeDataContext().getTimePoints()[getPdeDataContext().getTimePoints().length - 1], (int[]) hashTable.get(INDICES_KEY), (int[]) hashTable.get(CROSSING_KEY), (double[]) hashTable.get(ACCUM_KEY), true, getPdeDataContext().getTimePoint(), symbolTable);
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { multiTimePlotHelperTask, kymographTask }, null, false, false, true, null, false);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) SpatialSelectionMembrane(cbit.vcell.simdata.SpatialSelectionMembrane) SpatialSelection(cbit.vcell.simdata.SpatialSelection) SinglePoint(cbit.vcell.geometry.SinglePoint) Vector(java.util.Vector) MultiTimePlotHelper(cbit.vcell.simdata.gui.PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper) VariableType(cbit.vcell.math.VariableType) Hashtable(java.util.Hashtable) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) SymbolTable(cbit.vcell.parser.SymbolTable) SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) SSHelper(cbit.vcell.simdata.SpatialSelection.SSHelper) ChildWindowManager(cbit.vcell.client.ChildWindowManager) Dimension(java.awt.Dimension) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) Point(java.awt.Point) SinglePoint(cbit.vcell.geometry.SinglePoint) DataAccessException(org.vcell.util.DataAccessException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) UserCancelException(org.vcell.util.UserCancelException) SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) SSHelper(cbit.vcell.simdata.SpatialSelection.SSHelper) SpatialSelectionVolume(cbit.vcell.simdata.SpatialSelectionVolume)

Aggregations

SymbolTable (cbit.vcell.parser.SymbolTable)4 Expression (cbit.vcell.parser.Expression)2 SimulationSymbolTable (cbit.vcell.solver.SimulationSymbolTable)2 ImageException (cbit.image.ImageException)1 ChildWindowManager (cbit.vcell.client.ChildWindowManager)1 ChildWindow (cbit.vcell.client.ChildWindowManager.ChildWindow)1 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1 SinglePoint (cbit.vcell.geometry.SinglePoint)1 BioEvent (cbit.vcell.mapping.BioEvent)1 EventAssignment (cbit.vcell.mapping.BioEvent.EventAssignment)1 ElectricalStimulus (cbit.vcell.mapping.ElectricalStimulus)1 RateRule (cbit.vcell.mapping.RateRule)1 SimulationContext (cbit.vcell.mapping.SimulationContext)1 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)1 StructureMapping (cbit.vcell.mapping.StructureMapping)1 PointVariable (cbit.vcell.math.PointVariable)1 Variable (cbit.vcell.math.Variable)1 VariableType (cbit.vcell.math.VariableType)1 VolVariable (cbit.vcell.math.VolVariable)1 Model (cbit.vcell.model.Model)1