Search in sources :

Example 6 with ODESimData

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

the class RuleBasedTest method runsolver.

// private static void printout(String printThis){
// System.out.flush();
// disableSystemOut(false);
// System.out.print(printThis);
// System.out.flush();
// disableSystemOut(true);
// }
private static void runsolver(Simulation newSimulation, File baseDirectory, int numRuns, TimeSeriesMultitrialData timeSeriesMultitrialData) {
    Simulation versSimulation = null;
    File destDir = null;
    // int progress = 1;
    for (int trialIndex = 0; trialIndex < numRuns; trialIndex++) {
        // }
        try {
            versSimulation = new TempSimulation(newSimulation, false);
            // printout(ruleBasedTestDir.getAbsolutePath());
            destDir = new File(baseDirectory, timeSeriesMultitrialData.datasetName);
            SimulationTask simTask = new SimulationTask(new SimulationJob(versSimulation, 0, null), 0);
            Solver solver = ClientSimManager.createQuickRunSolver(destDir, simTask);
            solver.startSolver();
            while (true) {
                try {
                    Thread.sleep(250);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                SolverStatus solverStatus = solver.getSolverStatus();
                if (solverStatus != null) {
                    if (solverStatus.getStatus() == SolverStatus.SOLVER_ABORTED) {
                        throw new RuntimeException(solverStatus.getSimulationMessage().getDisplayMessage());
                    }
                    if (solverStatus.getStatus() != SolverStatus.SOLVER_STARTING && solverStatus.getStatus() != SolverStatus.SOLVER_READY && solverStatus.getStatus() != SolverStatus.SOLVER_RUNNING) {
                        break;
                    }
                }
            }
            SimulationData simData = new SimulationData(simTask.getSimulationJob().getVCDataIdentifier(), destDir, null, null);
            ODEDataBlock odeDataBlock = simData.getODEDataBlock();
            ODESimData odeSimData = odeDataBlock.getODESimData();
            timeSeriesMultitrialData.addDataSet(odeSimData, trialIndex);
        } catch (Exception e) {
            e.printStackTrace();
            File file = new File(baseDirectory, Simulation.createSimulationID(versSimulation.getKey()) + "_solverExc.txt");
            writeMessageTofile(file, e.getMessage());
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        clearDir(destDir);
    }
// printout("\n");
}
Also used : Solver(cbit.vcell.solver.server.Solver) SimulationTask(cbit.vcell.messaging.server.SimulationTask) TempSimulation(cbit.vcell.solver.TempSimulation) ODESimData(cbit.vcell.solver.ode.ODESimData) TempSimulation(cbit.vcell.solver.TempSimulation) Simulation(cbit.vcell.solver.Simulation) SimulationData(cbit.vcell.simdata.SimulationData) ODEDataBlock(cbit.vcell.simdata.ODEDataBlock) File(java.io.File) SolverStatus(cbit.vcell.solver.server.SolverStatus) SimulationJob(cbit.vcell.solver.SimulationJob)

Example 7 with ODESimData

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

the class StandaloneRuleBasedTest method runsolver.

// private static void printout(String printThis){
// System.out.flush();
// disableSystemOut(false);
// System.out.print(printThis);
// System.out.flush();
// disableSystemOut(true);
// }
private static void runsolver(Simulation newSimulation, File baseDirectory, int numRuns, TimeSeriesMultitrialData timeSeriesMultitrialData) {
    Simulation versSimulation = null;
    File destDir = null;
    // int progress = 1;
    for (int trialIndex = 0; trialIndex < numRuns; trialIndex++) {
        // }
        try {
            versSimulation = new TempSimulation(newSimulation, false);
            // printout(ruleBasedTestDir.getAbsolutePath());
            destDir = new File(baseDirectory, timeSeriesMultitrialData.datasetName);
            SimulationTask simTask = new SimulationTask(new SimulationJob(versSimulation, 0, null), 0);
            Solver solver = ClientSimManager.createQuickRunSolver(destDir, simTask);
            solver.startSolver();
            while (true) {
                try {
                    Thread.sleep(250);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                SolverStatus solverStatus = solver.getSolverStatus();
                if (solverStatus != null) {
                    if (solverStatus.getStatus() == SolverStatus.SOLVER_ABORTED) {
                        throw new RuntimeException(solverStatus.getSimulationMessage().getDisplayMessage());
                    }
                    if (solverStatus.getStatus() != SolverStatus.SOLVER_STARTING && solverStatus.getStatus() != SolverStatus.SOLVER_READY && solverStatus.getStatus() != SolverStatus.SOLVER_RUNNING) {
                        break;
                    }
                }
            }
            SimulationData simData = new SimulationData(simTask.getSimulationJob().getVCDataIdentifier(), destDir, null, null);
            ODEDataBlock odeDataBlock = simData.getODEDataBlock();
            ODESimData odeSimData = odeDataBlock.getODESimData();
            timeSeriesMultitrialData.addDataSet(odeSimData, trialIndex);
        } catch (Exception e) {
            e.printStackTrace();
            File file = new File(baseDirectory, Simulation.createSimulationID(versSimulation.getKey()) + "_solverExc.txt");
            StochtestFileUtils.writeMessageTofile(file, e.getMessage());
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        StochtestFileUtils.clearDir(destDir);
    }
// printout("\n");
}
Also used : Solver(cbit.vcell.solver.server.Solver) SimulationTask(cbit.vcell.messaging.server.SimulationTask) TempSimulation(cbit.vcell.solver.TempSimulation) ODESimData(cbit.vcell.solver.ode.ODESimData) TempSimulation(cbit.vcell.solver.TempSimulation) Simulation(cbit.vcell.solver.Simulation) SimulationData(cbit.vcell.simdata.SimulationData) ODEDataBlock(cbit.vcell.simdata.ODEDataBlock) File(java.io.File) SolverStatus(cbit.vcell.solver.server.SolverStatus) SimulationJob(cbit.vcell.solver.SimulationJob)

Example 8 with ODESimData

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

the class DataSetTimeSeries method getVarDatas.

private VarData[] getVarDatas(ODEDataBlock odeDataBlock) {
    ArrayList<VarData> valValuesArray = new ArrayList<VarData>();
    ODESimData odeSimData = odeDataBlock.getODESimData();
    int rowCount = odeSimData.getRowCount();
    for (ColumnDescription column : odeSimData.getColumnDescriptions()) {
        VarData values = new VarData(column.getName(), new double[rowCount]);
        valValuesArray.add(values);
    }
    for (int i = 0; i < rowCount; i++) {
        double[] rowData = odeSimData.getRow(i);
        for (int j = 0; j < rowData.length; j++) {
            valValuesArray.get(j).values[i] = rowData[j];
        }
    }
    return valValuesArray.toArray(new VarData[0]);
}
Also used : ColumnDescription(cbit.vcell.util.ColumnDescription) ArrayList(java.util.ArrayList) ODESimData(cbit.vcell.solver.ode.ODESimData)

Example 9 with ODESimData

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

the class MergedData method getODEDataBlock.

/**
 * Insert the method's description here.
 * Creation date: (1/14/00 2:28:47 PM)
 * @return cbit.vcell.simdata.ODEDataBlock
 */
public ODEDataBlock getODEDataBlock() throws DataAccessException {
    ODESolverResultSet combinedODESolverRSet = new ODESolverResultSet();
    ODEDataBlock refDataBlock = dataSetControllerImpl.getODEDataBlock(datasetsIDList[0]);
    ODESimData refSimData = refDataBlock.getODESimData();
    // Can use dataTimes field later (for genuine SimulationData), but for now, obtain it on the fly
    double[] times = null;
    try {
        int independentVarIndex = refSimData.findColumn("t");
        if (independentVarIndex < 0) {
            independentVarIndex = refSimData.findColumn(HISTOGRAM_INDEX_NAME);
        }
        times = refSimData.extractColumn(independentVarIndex);
    } catch (ExpressionException e) {
        e.printStackTrace(System.out);
    }
    // Adding data/function columns to new resultSet
    ODESolverResultSet[] resultSetList = new ODESolverResultSet[datasetsIDList.length];
    for (int i = 0; i < datasetsIDList.length; i++) {
        ODEDataBlock dataBlock = dataSetControllerImpl.getODEDataBlock(datasetsIDList[i]);
        ODESimData simData = dataBlock.getODESimData();
        ODESolverResultSet newODErset = new ODESolverResultSet();
        // First resultSet is reference resultSet. From the second onwards, resample the resultSet wrt the reference.
        if (i > 0) {
            try {
                newODErset = resampleODEData(refSimData, simData);
            } catch (ExpressionException e) {
                e.printStackTrace(System.out);
                throw new RuntimeException("\n >>>> Could not resample data! <<<<\n");
            }
        } else {
            newODErset = simData;
        }
        resultSetList[i] = newODErset;
        // Add data columns
        String[] newVarNames = new String[newODErset.getDataColumnCount()];
        for (int j = 0; j < newODErset.getDataColumnCount(); j++) {
            // If 'time' column is present in combinedResultSet, continue with next data column
            if ((combinedODESolverRSet.findColumn("t") > -1) && (newODErset.getDataColumnDescriptions()[j].getName().equals("t"))) {
                newVarNames[j] = newODErset.getDataColumnDescriptions()[j].getName();
                continue;
            }
            // Retain 'time' column as 't', without using datasetID as prefix to avoid multiple time columns in combinedODEResultSet.
            // Adding the time column from the first dataset to combinedResultSet, since it is treated as the reference dataset.
            String newColName = null;
            if (j == 0 && newODErset.getDataColumnDescriptions()[j].getName().equals("t")) {
                newColName = newODErset.getDataColumnDescriptions()[j].getName();
            } else {
                newColName = dataSetPrefix[i] + "." + newODErset.getDataColumnDescriptions()[j].getName();
            }
            newVarNames[j] = newColName;
            ColumnDescription cd = newODErset.getDataColumnDescriptions()[j];
            if (cd instanceof ODESolverResultSetColumnDescription) {
                ODESolverResultSetColumnDescription newCD = new ODESolverResultSetColumnDescription(newColName, cd.getParameterName(), newColName);
                combinedODESolverRSet.addDataColumn(newCD);
            }
        }
        // Add function columns
        for (int j = 0; j < newODErset.getFunctionColumnCount(); j++) {
            try {
                String newColName = dataSetPrefix[i] + "." + newODErset.getFunctionColumnDescriptions()[j].getName();
                FunctionColumnDescription fcd = newODErset.getFunctionColumnDescriptions()[j];
                Expression newExp = new Expression(fcd.getExpression());
                String[] symbols = newExp.getSymbols();
                if (symbols != null && (symbols.length > 0)) {
                    for (int jj = 0; jj < symbols.length; jj++) {
                        for (int kk = 0; kk < newVarNames.length; kk++) {
                            if (newVarNames[kk].equals(dataSetPrefix[i] + "." + symbols[jj])) {
                                newExp.substituteInPlace(new Expression(symbols[jj]), new Expression(newVarNames[kk]));
                                break;
                            }
                        }
                    }
                }
                FunctionColumnDescription newFcd = new FunctionColumnDescription(newExp, newColName, fcd.getParameterName(), newColName, fcd.getIsUserDefined());
                combinedODESolverRSet.addFunctionColumn(newFcd);
            } catch (ExpressionException e) {
                e.printStackTrace(System.out);
            }
        }
    }
    // Populating new dataset
    for (int i = 0; i < times.length; i++) {
        double[] newRow = new double[combinedODESolverRSet.getDataColumnCount()];
        int indx = 0;
        for (int j = 0; j < resultSetList.length; j++) {
            ODESolverResultSet resultSet = resultSetList[j];
            double[] tempRow = resultSet.getRow(i);
            int startIndx = 0;
            int arrayLen = tempRow.length;
            if (j > 0) {
                // From the second dataset onwards, we do not want to copy the time column, hence skip to
                // the next element/col in dataset, that reduces the # of elements in the row by 1.
                startIndx = 1;
                arrayLen = tempRow.length - 1;
            }
            System.arraycopy(tempRow, startIndx, newRow, indx, arrayLen);
            indx += tempRow.length;
        }
        combinedODESolverRSet.addRow(newRow);
    }
    ODEDataInfo odeDataInfo = new ODEDataInfo(getResultsInfoObject().getOwner(), getResultsInfoObject().getID(), 0);
    ODESimData odeSimData = new ODESimData(getResultsInfoObject(), combinedODESolverRSet);
    return new ODEDataBlock(odeDataInfo, odeSimData);
}
Also used : ColumnDescription(cbit.vcell.util.ColumnDescription) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription) ODESimData(cbit.vcell.solver.ode.ODESimData) ExpressionException(cbit.vcell.parser.ExpressionException) Expression(cbit.vcell.parser.Expression) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription)

Example 10 with ODESimData

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

the class SimulationData method getODEDataBlock.

/**
 * Insert the method's description here.
 * Creation date: (1/14/00 2:28:47 PM)
 * @return cbit.vcell.simdata.ODEDataBlock
 */
public synchronized ODEDataBlock getODEDataBlock() throws DataAccessException, IOException {
    File file = getODEDataFile();
    long lastModified = file.lastModified();
    ODESimData odeSimData = null;
    try {
        if (odeIdentifier.equals(ODE_DATA_IDENTIFIER)) {
            odeSimData = ODESimData.readODEDataFile(getODEDataFile());
        } else if (odeIdentifier.equals(IDA_DATA_IDENTIFIER)) {
            odeSimData = ODESimData.readIDADataFile(vcDataId, getODEDataFile(), odeKeepMost, getJobFunctionsFile());
        } else if (odeIdentifier.equals(NETCDF_DATA_IDENTIFIER)) {
            odeSimData = ODESimData.readNCDataFile(vcDataId, getODEDataFile(), getJobFunctionsFile());
        } else if (odeIdentifier.equals(NFSIM_DATA_IDENTIFIER)) {
            odeSimData = ODESimData.readNFSIMDataFile(vcDataId, getODEDataFile(), getJobFunctionsFile());
        } else {
            throw new DataAccessException("Unexpected data format:" + odeIdentifier);
        }
        if (odeSimData == null) {
            return null;
        }
        // look for 't' first
        int colIndex = odeSimData.findColumn(ReservedVariable.TIME.getName());
        // if not time serie data, it should be multiple trial data. get the trial no as fake time data. let it run since we will not need it when displaying histogram
        if (colIndex == -1)
            colIndex = odeSimData.findColumn(SimDataConstants.HISTOGRAM_INDEX_NAME);
        dataTimes = odeSimData.extractColumn(colIndex);
    } catch (ExpressionException e) {
        e.printStackTrace(System.out);
        throw new DataAccessException("error getting data times: " + e.getMessage());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        throw new DataAccessException("error getting dataset times: " + e.getMessage());
    }
    ODEDataInfo odeDataInfo = new ODEDataInfo(vcDataId.getOwner(), vcDataId.getID(), lastModified);
    VCAssert.assertFalse(odeSimData == null, "should have returned null already");
    return new ODEDataBlock(odeDataInfo, odeSimData);
}
Also used : FileNotFoundException(java.io.FileNotFoundException) ODESimData(cbit.vcell.solver.ode.ODESimData) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException)

Aggregations

ODESimData (cbit.vcell.solver.ode.ODESimData)12 ExpressionException (cbit.vcell.parser.ExpressionException)5 Simulation (cbit.vcell.solver.Simulation)5 File (java.io.File)5 DataAccessException (org.vcell.util.DataAccessException)5 SimulationTask (cbit.vcell.messaging.server.SimulationTask)4 ODEDataBlock (cbit.vcell.simdata.ODEDataBlock)3 SimulationData (cbit.vcell.simdata.SimulationData)3 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)3 SimulationJob (cbit.vcell.solver.SimulationJob)3 TempSimulation (cbit.vcell.solver.TempSimulation)3 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)3 MessageEvent (cbit.rmi.event.MessageEvent)2 BioModel (cbit.vcell.biomodel.BioModel)2 SimulationContext (cbit.vcell.mapping.SimulationContext)2 SimulationStatusPersistent (cbit.vcell.server.SimulationStatusPersistent)2 VCellBootstrap (cbit.vcell.server.VCellBootstrap)2 VCellConnection (cbit.vcell.server.VCellConnection)2 OutputContext (cbit.vcell.simdata.OutputContext)2 Solver (cbit.vcell.solver.server.Solver)2