Search in sources :

Example 1 with ODESolverResultSet

use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.

the class ParameterEstimationRunTaskPanel method plot.

private void plot() {
    try {
        java.util.Vector<DataSource> dataSourceList = new java.util.Vector<DataSource>();
        java.util.Vector<String> nameVector = new java.util.Vector<String>();
        ModelOptimizationSpec modelOptimizationSpec = parameterEstimationTask.getModelOptimizationSpec();
        final ReferenceDataMappingSpec[] mappingSpecs = modelOptimizationSpec.getReferenceDataMappingSpecs();
        int timeIndex = modelOptimizationSpec.getReferenceDataTimeColumnIndex();
        ReferenceData referenceData = modelOptimizationSpec.getReferenceData();
        if (referenceData != null) {
            dataSourceList.add(new DataSource.DataSourceReferenceData("EXPT", timeIndex, referenceData));
            String[] refColumnNames = referenceData.getColumnNames();
            for (int i = 0; i < refColumnNames.length; i++) {
                if (i == timeIndex) {
                    continue;
                }
                nameVector.add(refColumnNames[i]);
                break;
            }
        }
        ParameterEstimationTaskSimulatorIDA parestSimulator = new ParameterEstimationTaskSimulatorIDA();
        ODESolverResultSet odeSolverResultSet = parestSimulator.getOdeSolverResultSet(parameterEstimationTask);
        if (odeSolverResultSet != null) {
            dataSourceList.add(new DataSource.DataSourceRowColumnResultSet("EST", odeSolverResultSet));
            if (mappingSpecs != null) {
                for (int i = 0; i < mappingSpecs.length; i++) {
                    if (i == timeIndex) {
                        continue;
                    }
                    Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(mappingSpecs[i].getModelObject());
                    nameVector.add(var.getName());
                    break;
                }
            }
        }
        DataSource[] dataSources = (DataSource[]) BeanUtils.getArray(dataSourceList, DataSource.class);
        MultisourcePlotPane multisourcePlotPane = new MultisourcePlotPane();
        multisourcePlotPane.setGroupingListSorter(new Comparator<SortDataReferenceHelper>() {

            @Override
            public int compare(SortDataReferenceHelper o1, SortDataReferenceHelper o2) {
                DataSource ds01 = o1.dataReference.getDataSource();
                DataSource ds02 = o2.dataReference.getDataSource();
                // System.out.println(ds01.getClass().getSimpleName()+" "+o1.dataReference.getIdentifier()+" "+ds02.getClass().getSimpleName()+" "+o2.dataReference.getIdentifier());
                if (ds01 instanceof DataSource.DataSourceReferenceData) {
                    if (ds02 instanceof DataSource.DataSourceReferenceData) {
                        // both reference data, sort names
                        ReferenceDataMappingSpec mspec01 = null;
                        ReferenceDataMappingSpec mspec02 = null;
                        for (ReferenceDataMappingSpec rdMappingSpec : mappingSpecs) {
                            // Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(rdMappingSpec.getModelObject());
                            if (rdMappingSpec.getModelObject() instanceof ReservedSymbol) {
                                continue;
                            }
                            if (o1.dataReference.getIdentifier().equals(rdMappingSpec.getReferenceDataColumnName())) {
                                mspec01 = rdMappingSpec;
                                o1.setReferenceDataMappingSpec(rdMappingSpec);
                            } else if (o2.dataReference.getIdentifier().equals(rdMappingSpec.getReferenceDataColumnName())) {
                                mspec02 = rdMappingSpec;
                                o2.setReferenceDataMappingSpec(rdMappingSpec);
                            }
                        }
                        if (mspec01 == null && mspec02 == null) {
                            return o1.dataReference.getIdentifier().compareToIgnoreCase(o2.dataReference.getIdentifier());
                        } else if (mspec01 != null && mspec02 != null) {
                            return mspec01.getReferenceDataColumnName().compareToIgnoreCase(mspec02.getReferenceDataColumnName());
                        } else if (mspec01 != null && mspec02 == null) {
                            return -1;
                        } else {
                            return 1;
                        }
                    } else {
                        // compare ref to ode
                        ReferenceDataMappingSpec mspec01 = null;
                        ReferenceDataMappingSpec mspec02 = null;
                        for (ReferenceDataMappingSpec rdMappingSpec : mappingSpecs) {
                            Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(rdMappingSpec.getModelObject());
                            if (rdMappingSpec.getModelObject() instanceof ReservedSymbol) {
                                continue;
                            }
                            if (o1.dataReference.getIdentifier().equals(rdMappingSpec.getReferenceDataColumnName())) {
                                mspec01 = rdMappingSpec;
                                o1.setReferenceDataMappingSpec(rdMappingSpec);
                            } else if (o2.dataReference.getIdentifier().equals(var.getName())) {
                                mspec02 = rdMappingSpec;
                                o2.setReferenceDataMappingSpec(rdMappingSpec);
                            }
                        }
                        if (mspec01 == null && mspec02 == null) {
                            return -1;
                        } else if (mspec01 != null && mspec02 == null) {
                            return -1;
                        } else if (mspec02 != null && mspec01 == null) {
                            return 1;
                        } else {
                            // BeanUtils.forceStringSize(mspec02.getReferenceDataColumnName(), 25, " ", true));
                            return mspec01.getReferenceDataColumnName().compareToIgnoreCase(mspec02.getReferenceDataColumnName());
                        }
                    }
                } else {
                    if (ds02 instanceof DataSource.DataSourceRowColumnResultSet) {
                        // both OdeSolverResultSet data, sort names
                        ReferenceDataMappingSpec mspec01 = null;
                        ReferenceDataMappingSpec mspec02 = null;
                        for (ReferenceDataMappingSpec rdMappingSpec : mappingSpecs) {
                            Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(rdMappingSpec.getModelObject());
                            if (rdMappingSpec.getModelObject() instanceof ReservedSymbol) {
                                continue;
                            }
                            if (o1.dataReference.getIdentifier().equals(var.getName())) {
                                mspec01 = rdMappingSpec;
                                o1.setReferenceDataMappingSpec(rdMappingSpec);
                            } else if (o2.dataReference.getIdentifier().equals(var.getName())) {
                                mspec02 = rdMappingSpec;
                                o2.setReferenceDataMappingSpec(rdMappingSpec);
                            }
                        }
                        if (mspec01 == null && mspec02 == null) {
                            return o1.dataReference.getIdentifier().compareToIgnoreCase(o2.dataReference.getIdentifier());
                        } else if (mspec01 != null && mspec02 != null) {
                            return mspec01.getReferenceDataColumnName().compareToIgnoreCase(mspec02.getReferenceDataColumnName());
                        } else if (mspec01 != null && mspec02 == null) {
                            return -1;
                        } else {
                            return 1;
                        }
                    } else {
                        // compare ode to ref
                        ReferenceDataMappingSpec mspec01 = null;
                        ReferenceDataMappingSpec mspec02 = null;
                        for (ReferenceDataMappingSpec rdMappingSpec : mappingSpecs) {
                            Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(rdMappingSpec.getModelObject());
                            if (rdMappingSpec.getModelObject() instanceof ReservedSymbol) {
                                continue;
                            }
                            if (o2.dataReference.getIdentifier().equals(rdMappingSpec.getReferenceDataColumnName())) {
                                mspec02 = rdMappingSpec;
                                o2.setReferenceDataMappingSpec(rdMappingSpec);
                            } else if (o1.dataReference.getIdentifier().equals(var.getName())) {
                                mspec01 = rdMappingSpec;
                                o1.setReferenceDataMappingSpec(rdMappingSpec);
                            }
                        }
                        if (mspec01 == null && mspec02 == null) {
                            return 1;
                        } else if (mspec01 != null && mspec02 == null) {
                            return -1;
                        } else if (mspec02 != null && mspec01 == null) {
                            return 1;
                        } else {
                            // BeanUtils.forceStringSize(mspec02.getReferenceDataColumnName(), 25, " ", true));
                            return mspec01.getReferenceDataColumnName().compareToIgnoreCase(mspec02.getReferenceDataColumnName());
                        }
                    }
                }
            }
        });
        multisourcePlotPane.setDataSources(dataSources);
        String[] nameArray = new String[nameVector.size()];
        nameArray = (String[]) BeanUtils.getArray(nameVector, String.class);
        multisourcePlotPane.select(nameArray);
        DialogUtils.showComponentCloseDialog(JOptionPane.getFrameForComponent(this), multisourcePlotPane, "Data Plot");
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : Variable(cbit.vcell.math.Variable) MultisourcePlotPane(cbit.vcell.modelopt.gui.MultisourcePlotPane) ReferenceDataMappingSpec(cbit.vcell.modelopt.ReferenceDataMappingSpec) ReservedSymbol(cbit.vcell.model.Model.ReservedSymbol) ModelOptimizationSpec(cbit.vcell.modelopt.ModelOptimizationSpec) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ParameterEstimationTaskSimulatorIDA(org.vcell.optimization.ParameterEstimationTaskSimulatorIDA) OptimizationException(cbit.vcell.opt.OptimizationException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException) DataSource(cbit.vcell.modelopt.DataSource) SortDataReferenceHelper(cbit.vcell.modelopt.gui.MultisourcePlotListModel.SortDataReferenceHelper) ReferenceData(cbit.vcell.opt.ReferenceData)

Example 2 with ODESolverResultSet

use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.

the class VCellSedMLSolver method doWork.

// everything is done here
public void doWork(ExternalDocInfo externalDocInfo, AbstractTask sedmlTask, SedML sedml) throws Exception {
    // create the VCDocument (bioModel + application + simulation), do sanity checks
    cbit.util.xml.VCLogger sedmlImportLogger = new LocalLogger();
    List<AbstractTask> tasks = new ArrayList<AbstractTask>();
    tasks.add(sedmlTask);
    List<VCDocument> docs = XmlHelper.sedmlToBioModel(sedmlImportLogger, externalDocInfo, sedml, tasks, null, false);
    VCDocument doc = docs.get(0);
    sanityCheck(doc);
    // create the work directory for this task, invoke the solver
    String docName = doc.getName();
    String outString = VCellSedMLSolver.OUT_ROOT_STRING + "/" + docName + "/" + sedmlTask.getId();
    File outDir = new File(outString);
    if (!outDir.exists()) {
        outDir.mkdirs();
    }
    BioModel bioModel = (BioModel) doc;
    SimulationContext simContext = bioModel.getSimulationContext(0);
    MathDescription mathDesc = simContext.getMathDescription();
    String vcml = mathDesc.getVCML();
    try (PrintWriter pw = new PrintWriter(outString + "/vcmlTrace.xml")) {
        pw.println(vcml);
    }
    Simulation sim = bioModel.getSimulation(0);
    SolverTaskDescription std = sim.getSolverTaskDescription();
    SolverDescription sd = std.getSolverDescription();
    String kisao = sd.getKisao();
    if (SolverDescription.CVODE.getKisao().contentEquals(kisao)) {
        ODESolverResultSet odeSolverResultSet = solveCvode(outDir, bioModel);
        System.out.println("Finished: " + docName + ": - task '" + sedmlTask.getId() + "'.");
    } else if (SolverDescription.StochGibson.getKisao().contentEquals(kisao)) {
        ODESolverResultSet odeSolverResultSet = solveGibson(outDir, bioModel);
        System.out.println("Finished: " + docName + ": - task '" + sedmlTask.getId() + "'.");
    } else if (SolverDescription.IDA.getKisao().contentEquals(kisao)) {
        ODESolverResultSet odeSolverResultSet = solveIDA(outDir, bioModel);
        System.out.println("Finished: " + docName + ": - task '" + sedmlTask.getId() + "'.");
    } else {
        System.out.println("Unsupported solver: " + kisao);
    }
    System.out.println("-------------------------------------------------------------------------");
}
Also used : AbstractTask(org.jlibsedml.AbstractTask) SolverDescription(cbit.vcell.solver.SolverDescription) VCDocument(org.vcell.util.document.VCDocument) MathDescription(cbit.vcell.math.MathDescription) VCLogger(cbit.util.xml.VCLogger) SimulationContext(cbit.vcell.mapping.SimulationContext) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription)

Example 3 with ODESolverResultSet

use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.

the class VCellSedMLSolver method solveGibson.

private static ODESolverResultSet solveGibson(File outDir, BioModel bioModel) throws Exception {
    String docName = bioModel.getName();
    Simulation sim = bioModel.getSimulation(0);
    File gibsonInputFile = new File(outDir, docName + SimDataConstants.STOCHINPUT_DATA_EXTENSION);
    PrintWriter gibsonPW = new java.io.PrintWriter(gibsonInputFile);
    SimulationJob simJob = new SimulationJob(sim, 0, null);
    SimulationTask simTask = new SimulationTask(simJob, 0);
    StochFileWriter stFileWriter = new StochFileWriter(gibsonPW, simTask, false);
    stFileWriter.write();
    gibsonPW.close();
    File gibsonOutputFile = new File(outDir, docName + SimDataConstants.IDA_DATA_EXTENSION);
    writeFunctionFile(outDir, docName, SimDataConstants.FUNCTIONFILE_EXTENSION, simTask);
    String executableName = null;
    try {
        executableName = SolverUtilities.getExes(SolverDescription.StochGibson)[0].getAbsolutePath();
    } catch (IOException e) {
        throw new RuntimeException("failed to get executable for solver " + SolverDescription.StochGibson.getDisplayLabel() + ": " + e.getMessage(), e);
    }
    Executable executable = new Executable(new String[] { executableName, "gibson", gibsonInputFile.getAbsolutePath(), gibsonOutputFile.getAbsolutePath() });
    executable.start();
    ODESolverResultSet odeSolverResultSet = VCellSBMLSolver.getODESolverResultSet(simJob, gibsonOutputFile.getPath());
    return odeSolverResultSet;
}
Also used : SimulationTask(cbit.vcell.messaging.server.SimulationTask) Simulation(cbit.vcell.solver.Simulation) StochFileWriter(cbit.vcell.solver.stoch.StochFileWriter) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) Executable(org.vcell.util.exe.Executable) SimulationJob(cbit.vcell.solver.SimulationJob)

Example 4 with ODESolverResultSet

use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.

the class VCellSedMLSolver method solveCvode.

private static ODESolverResultSet solveCvode(File outDir, BioModel bioModel) throws Exception {
    String docName = bioModel.getName();
    Simulation sim = bioModel.getSimulation(0);
    File cvodeInputFile = new File(outDir, docName + SimDataConstants.CVODEINPUT_DATA_EXTENSION);
    PrintWriter cvodePW = new java.io.PrintWriter(cvodeInputFile);
    SimulationJob simJob = new SimulationJob(sim, 0, null);
    SimulationTask simTask = new SimulationTask(simJob, 0);
    CVodeFileWriter cvodeFileWriter = new CVodeFileWriter(cvodePW, simTask);
    cvodeFileWriter.write();
    cvodePW.close();
    // use the cvodeStandalone solver
    String outDirPath = outDir.getAbsolutePath();
    int indexOfLastSlash = outDirPath.lastIndexOf("/");
    String task_name = outDirPath.substring(indexOfLastSlash + 1);
    String idaFilePath = outDirPath.substring(0, indexOfLastSlash);
    File cvodeOutputFile = new File(idaFilePath, task_name + SimDataConstants.IDA_DATA_EXTENSION);
    String executableName = null;
    try {
        // we need to specify the vCell install dir in the Eclipse Debug configuration, as VM argument
        // so that the code next knows where to look for the solver
        // -Dvcell.installDir=G:\dan\jprojects\git\vcell
        // OR
        // just type the string with the full path explicitly
        // OR
        // provide a .properties file in the working directory
        executableName = SolverUtilities.getExes(SolverDescription.CVODE)[0].getAbsolutePath();
    } catch (IOException e) {
        throw new RuntimeException("failed to get executable for solver " + SolverDescription.CVODE.getDisplayLabel() + ": " + e.getMessage(), e);
    }
    Executable executable = new Executable(new String[] { executableName, cvodeInputFile.getAbsolutePath(), cvodeOutputFile.getAbsolutePath() });
    executable.start();
    ODESolverResultSet odeSolverResultSet = VCellSBMLSolver.getODESolverResultSet(simJob, cvodeOutputFile.getPath());
    return odeSolverResultSet;
}
Also used : SimulationTask(cbit.vcell.messaging.server.SimulationTask) CVodeFileWriter(cbit.vcell.solver.ode.CVodeFileWriter) Simulation(cbit.vcell.solver.Simulation) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) Executable(org.vcell.util.exe.Executable) SimulationJob(cbit.vcell.solver.SimulationJob)

Example 5 with ODESolverResultSet

use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.

the class BNGDataPlotListModel method setOdeSolverResultSet.

/**
 * Sets the dataSource property (cbit.vcell.modelopt.gui.DataSource) value.
 * @param dataSource The new value for the property.
 * @see #getDataSource
 */
public void setOdeSolverResultSet(ODESolverResultSet odeSolverResultSet) {
    ODESolverResultSet oldValue = fieldOdeSolverResultSet;
    fieldOdeSolverResultSet = odeSolverResultSet;
    firePropertyChange("odeSolverResultSet", oldValue, odeSolverResultSet);
}
Also used : ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet)

Aggregations

ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)51 ODESolverResultSetColumnDescription (cbit.vcell.math.ODESolverResultSetColumnDescription)18 FunctionColumnDescription (cbit.vcell.math.FunctionColumnDescription)11 Expression (cbit.vcell.parser.Expression)11 Simulation (cbit.vcell.solver.Simulation)11 IOException (java.io.IOException)11 File (java.io.File)10 SimulationTask (cbit.vcell.messaging.server.SimulationTask)9 DataSource (cbit.vcell.modelopt.DataSource)9 ExpressionException (cbit.vcell.parser.ExpressionException)9 ReferenceData (cbit.vcell.opt.ReferenceData)8 BioModel (cbit.vcell.biomodel.BioModel)7 SolverException (cbit.vcell.solver.SolverException)7 SBMLImportException (org.vcell.sbml.vcell.SBMLImportException)7 SimulationJob (cbit.vcell.solver.SimulationJob)6 SimulationSymbolTable (cbit.vcell.solver.SimulationSymbolTable)6 Executable (org.vcell.util.exe.Executable)6 SbmlException (org.vcell.sbml.SbmlException)5 VCLogger (cbit.util.xml.VCLogger)4 MathDescription (cbit.vcell.math.MathDescription)4