Search in sources :

Example 96 with SimulationContext

use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.

the class ParameterEstimationRunTaskPanel method saveSolutionAsNewSimulation.

private void saveSolutionAsNewSimulation() {
    try {
        OptimizationSpec optSpec = parameterEstimationTask.getModelOptimizationMapping().getOptimizationSpec();
        if (optSpec == null) {
            throw new RuntimeException("optimization not yet performed");
        }
        // 
        // add new simulation to the Application (other bookkeeping required?)
        // 
        String newSimName = DialogUtils.showInputDialog0(this, "Enter name for new simulation", "Fitted");
        newSimName = (newSimName == null ? null : newSimName.trim());
        if (newSimName == null || newSimName.length() == 0) {
            throw new Exception("New Simulation name cannot be 0 characters");
        }
        SimulationContext simContext = parameterEstimationTask.getModelOptimizationSpec().getSimulationContext();
        MathMappingCallback dummyCallback = new MathMappingCallback() {

            @Override
            public void setProgressFraction(float fractionDone) {
            }

            @Override
            public void setMessage(String message) {
            }

            @Override
            public boolean isInterrupted() {
                return false;
            }
        };
        Simulation newSim = simContext.addNewSimulation(newSimName, dummyCallback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
        parameterEstimationTask.getModelOptimizationMapping().applySolutionToMathOverrides(newSim, parameterEstimationTask.getOptimizationResultSet());
        DialogUtils.showInfoDialog(this, "created simulation \"" + newSim.getName() + "\"");
    } catch (UtilCancelException e) {
    // ignore, user cancelled operation
    } catch (Exception e) {
        e.printStackTrace(System.out);
        DialogUtils.showErrorDialog(this, e.getMessage(), e);
    }
}
Also used : UtilCancelException(org.vcell.util.UtilCancelException) MathMappingCallback(cbit.vcell.mapping.SimulationContext.MathMappingCallback) Simulation(cbit.vcell.solver.Simulation) ModelOptimizationSpec(cbit.vcell.modelopt.ModelOptimizationSpec) OptimizationSpec(cbit.vcell.opt.OptimizationSpec) SimulationContext(cbit.vcell.mapping.SimulationContext) OptimizationException(cbit.vcell.opt.OptimizationException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 97 with SimulationContext

use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.

the class ParameterMappingPanel method jMenuItemCopy_ActionPerformed.

/**
 * Comment
 */
private void jMenuItemCopy_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
    if (actionEvent.getSource() == getJMenuItemCopy() || actionEvent.getSource() == getJMenuItemCopyAll()) {
        try {
            // 
            // Copy Optimization Parameters (Initial Guess or Solution)
            // 
            int[] rows = null;
            if (actionEvent.getSource() == getJMenuItemCopyAll()) {
                rows = new int[getScrollPaneTable().getRowCount()];
                for (int i = 0; i < rows.length; i += 1) {
                    rows[i] = i;
                }
            } else {
                rows = getScrollPaneTable().getSelectedRows();
            }
            SimulationContext sc = getParameterEstimationTask().getModelOptimizationSpec().getSimulationContext();
            MathSymbolMapping msm = null;
            try {
                MathMapping mm = sc.createNewMathMapping();
                msm = mm.getMathSymbolMapping();
            } catch (Exception e) {
                e.printStackTrace(System.out);
                DialogUtils.showWarningDialog(this, "current math not valid, some paste operations will be limited\n\nreason: " + e.getMessage());
            }
            boolean bInitialGuess = (getScrollPaneTable().getSelectedColumn() == ParameterMappingTableModel.COLUMN_CURRENTVALUE);
            ParameterMappingSpec[] parameterMappingSpecs = new ParameterMappingSpec[rows.length];
            java.util.Vector<SymbolTableEntry> primarySymbolTableEntriesV = new java.util.Vector<SymbolTableEntry>();
            java.util.Vector<SymbolTableEntry> alternateSymbolTableEntriesV = new java.util.Vector<SymbolTableEntry>();
            java.util.Vector<Expression> resolvedValuesV = new java.util.Vector<Expression>();
            // 
            // Create formatted string for text/spreadsheet pasting.
            // 
            StringBuffer sb = new StringBuffer();
            sb.append("\"Parameters for (Optimization Task)" + getParameterEstimationTask().getName() + " -> " + "(BioModel)" + getParameterEstimationTask().getModelOptimizationSpec().getSimulationContext().getBioModel().getName() + " -> " + "(App)" + getParameterEstimationTask().getModelOptimizationSpec().getSimulationContext().getName() + "\"\n");
            sb.append("\"Parameter Name\"\t\"" + (bInitialGuess ? "Initial Guess" : "Solution") + "\"\n");
            for (int i = 0; i < rows.length; i += 1) {
                ParameterMappingSpec pms = parameterMappingTableModel.getValueAt(rows[i]);
                parameterMappingSpecs[i] = pms;
                primarySymbolTableEntriesV.add(pms.getModelParameter());
                if (msm != null) {
                    alternateSymbolTableEntriesV.add(msm.getVariable(pms.getModelParameter()));
                } else {
                    alternateSymbolTableEntriesV.add(null);
                }
                Double resolvedValue = null;
                if (!bInitialGuess) {
                    resolvedValue = getParameterEstimationTask().getCurrentSolution(pms);
                }
                if (resolvedValue == null) {
                    resolvedValue = new Double(pms.getCurrent());
                }
                resolvedValuesV.add(new Expression(resolvedValue.doubleValue()));
                sb.append("\"" + parameterMappingSpecs[i].getModelParameter().getName() + "\"\t" + resolvedValue + "\n");
            }
            // 
            // Send to clipboard
            // 
            VCellTransferable.ResolvedValuesSelection rvs = new VCellTransferable.ResolvedValuesSelection((SymbolTableEntry[]) BeanUtils.getArray(primarySymbolTableEntriesV, SymbolTableEntry.class), (SymbolTableEntry[]) BeanUtils.getArray(alternateSymbolTableEntriesV, SymbolTableEntry.class), (Expression[]) BeanUtils.getArray(resolvedValuesV, Expression.class), sb.toString());
            VCellTransferable.sendToClipboard(rvs);
        } catch (Throwable e) {
            PopupGenerator.showErrorDialog(this, "ParameterMappingPanel copy failed.  " + e.getMessage(), e);
        }
    }
}
Also used : VCellTransferable(cbit.vcell.desktop.VCellTransferable) SimulationContext(cbit.vcell.mapping.SimulationContext) MathSymbolMapping(cbit.vcell.mapping.MathSymbolMapping) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Expression(cbit.vcell.parser.Expression) ParameterMappingSpec(cbit.vcell.modelopt.ParameterMappingSpec) MathMapping(cbit.vcell.mapping.MathMapping)

Example 98 with SimulationContext

use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.

the class BioModel method addNewSimulationContext.

/**
 * Insert the method's description here.
 * Creation date: (1/19/01 3:31:00 PM)
 * @param simulationContext cbit.vcell.mapping.SimulationContext
 * @exception java.beans.PropertyVetoException The exception description.
 */
public SimulationContext addNewSimulationContext(String newSimulationContextName, SimulationContext.Application app) throws java.beans.PropertyVetoException {
    SimulationContext simContext = new SimulationContext(getModel(), new Geometry("non-spatial", 0), null, null, app);
    simContext.setName(newSimulationContextName);
    addSimulationContext(simContext);
    return simContext;
}
Also used : Geometry(cbit.vcell.geometry.Geometry) SimulationContext(cbit.vcell.mapping.SimulationContext)

Example 99 with SimulationContext

use of cbit.vcell.mapping.SimulationContext 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 100 with SimulationContext

use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.

the class ClientDocumentManager method saveAsNew.

/**
 * Insert the method's description here.
 * Creation date: (1/19/01 11:27:52 AM)
 */
public BioModel saveAsNew(BioModel bioModel, java.lang.String newName, String[] independentSims) throws DataAccessException {
    try {
        String bioModelXML = null;
        try {
            bioModel.getVCMetaData().cleanupMetadata();
            bioModelXML = XmlHelper.bioModelToXML(bioModel);
        } catch (XmlParseException e) {
            e.printStackTrace(System.out);
            throw new DataAccessException(e.getMessage());
        }
        String savedBioModelXML = sessionManager.getUserMetaDbServer().saveBioModelAs(new BigString(bioModelXML), newName, independentSims).toString();
        BioModel savedBioModel = getBioModelFromDatabaseXML(new XMLHolder<BioModel>(savedBioModelXML));
        KeyValue savedKey = savedBioModel.getVersion().getVersionKey();
        if (xmlHash.get(savedKey) == null) {
            xmlHash.put(savedKey, savedBioModelXML);
        }
        BioModelInfo savedBioModelInfo = new BioModelInfo(savedBioModel.getVersion(), savedBioModel.getModel().getKey(), savedBioModel.createBioModelChildSummary(), VCellSoftwareVersion.fromSystemProperty());
        bioModelInfoHash.put(savedKey, savedBioModelInfo);
        SimulationContext[] scArr = savedBioModel.getSimulationContexts();
        for (int i = 0; i < scArr.length; i++) {
            updateGeometryRelatedHashes(scArr[i].getGeometry());
        }
        fireDatabaseInsert(new DatabaseEvent(this, DatabaseEvent.INSERT, null, savedBioModelInfo));
        return savedBioModel;
    } catch (RemoteProxyException e) {
        e.printStackTrace(System.out);
        throw new DataAccessException(VCellErrorMessages.FAIL_SAVE_MESSAGE + "\n\n" + e.getMessage());
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) BioModelInfo(org.vcell.util.document.BioModelInfo) BigString(org.vcell.util.BigString) XmlParseException(cbit.vcell.xml.XmlParseException) SimulationContext(cbit.vcell.mapping.SimulationContext) BigString(org.vcell.util.BigString) BioModel(cbit.vcell.biomodel.BioModel) DataAccessException(org.vcell.util.DataAccessException) RemoteProxyException(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException)

Aggregations

SimulationContext (cbit.vcell.mapping.SimulationContext)181 BioModel (cbit.vcell.biomodel.BioModel)73 Simulation (cbit.vcell.solver.Simulation)57 MathDescription (cbit.vcell.math.MathDescription)32 Geometry (cbit.vcell.geometry.Geometry)29 PropertyVetoException (java.beans.PropertyVetoException)28 MathModel (cbit.vcell.mathmodel.MathModel)25 Model (cbit.vcell.model.Model)25 KeyValue (org.vcell.util.document.KeyValue)25 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)23 ArrayList (java.util.ArrayList)23 DataAccessException (org.vcell.util.DataAccessException)23 XMLSource (cbit.vcell.xml.XMLSource)22 XmlParseException (cbit.vcell.xml.XmlParseException)22 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)20 Expression (cbit.vcell.parser.Expression)20 ExpressionException (cbit.vcell.parser.ExpressionException)19 SpeciesContext (cbit.vcell.model.SpeciesContext)17 Structure (cbit.vcell.model.Structure)17 IOException (java.io.IOException)17