Search in sources :

Example 36 with VCSimulationDataIdentifier

use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.

the class HybridSolverTester method runHybridTest.

public void runHybridTest(String site) {
    try {
        double[] timePoints = null;
        File mathModelFile = new File(mathModelVCMLFileName);
        XMLSource vcmlSource = new XMLSource(mathModelFile);
        MathModel mathModel = XmlHelper.XMLToMathModel(vcmlSource);
        File simDataDir = mathModelFile.getParentFile();
        Simulation sim = mathModel.getSimulations()[0];
        // run multiple trials and each run will have a simID = origSimID + i
        for (int i = 0; i < numRuns; i++) {
            System.out.println("--------------Trial No: " + (startTrialNo + i) + "----------------");
            // replace random seed
            sim.getSolverTaskDescription().getSmoldynSimulationOptions().setRandomSeed(new Integer(startTrialNo + i));
            // create sim job
            int jobIndex = startTrialNo + i;
            SimulationTask simTask = new SimulationTask(new SimulationJob(sim, jobIndex, null), 0);
            /*
				 * When you want to run the multiple trials on local uncomment the line below.
				 */
            // ResourceUtil.prepareSolverExecutable(sim.getSolverTaskDescription().getSolverDescription());
            /*
				 * When you want to run the multiple trials on server (without VCell user interface), use the next line of code 
				 * Corresponding changes should be made in the shell script runhybridtest for the location of executable on server
				 */
            FVSolverStandalone fvSolver = new FVSolverStandalone(simTask, simDataDir, false);
            fvSolver.startSolver();
            SolverStatus status = fvSolver.getSolverStatus();
            while (status.getStatus() != SolverStatus.SOLVER_FINISHED && status.getStatus() != SolverStatus.SOLVER_ABORTED) {
                System.out.println("progress: " + (int) (fvSolver.getProgress() * 100) + "%");
                // ask status every 2 seconds
                Thread.sleep(2000);
                status = fvSolver.getSolverStatus();
            }
            if (status.getStatus() == SolverStatus.SOLVER_FINISHED) {
                // get data
                VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(sim.getVersion().getVersionKey(), sim.getVersion().getOwner());
                VCSimulationDataIdentifier vcSimDataID = new VCSimulationDataIdentifier(vcSimID, jobIndex);
                File hdf5File = new File(simDataDir, vcSimDataID.getID() + SimDataConstants.DATA_PROCESSING_OUTPUT_EXTENSION_HDF5);
                DataOperationResults.DataProcessingOutputInfo dataProcessingOutputInfo = (DataOperationResults.DataProcessingOutputInfo) DataSetControllerImpl.getDataProcessingOutput(new DataOperation.DataProcessingOutputInfoOP(vcSimDataID, false, null), hdf5File);
                if (i == 0) {
                    // do only one time
                    timePoints = dataProcessingOutputInfo.getVariableTimePoints();
                    for (int j = 0; j < varNames.length; j++) {
                        // row: numTimePoints, col:first col time + numRuns
                        double[][] data = new double[numRuns + 1][timePoints.length];
                        data[0] = timePoints;
                        results.add(data);
                    }
                }
                // write into results after each run
                for (int j = 0; j < varNames.length; j++) {
                    results.get(j)[i + 1] = dataProcessingOutputInfo.getVariableStatValues().get(varNames[j]);
                }
                // delete the file generated for this run
                deleteSimFiles(simDataDir, vcSimDataID);
            } else {
                throw new Exception("Sover did not finish normally." + status);
            }
        }
        // write to output file, tab delimited
        if (results != null && results.size() > 0) {
            for (int j = 0; j < varNames.length; j++) {
                File file = new File(simDataDir, "SimID_" + sim.getVersion().getVersionKey().toString() + "_" + varNames[j] + "_" + startTrialNo + ".txt");
                PrintWriter pw = new PrintWriter(file);
                double[][] data = results.get(j);
                if (data != null) {
                    for (int k = 0; k < data.length; k++) {
                        if (!bPrintTime && k == 0) {
                            continue;
                        }
                        String rowStr = (k == 0) ? "Time\t" : ("trialNo_" + (startTrialNo + k - 1) + "\t");
                        double[] rowData = data[k];
                        for (int q = 0; q < rowData.length; q++) {
                            rowStr += rowData[q] + "\t";
                        }
                        pw.println(rowStr);
                    }
                }
                pw.close();
            }
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) SimulationTask(cbit.vcell.messaging.server.SimulationTask) BigString(org.vcell.util.BigString) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) FVSolverStandalone(cbit.vcell.solvers.FVSolverStandalone) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Simulation(cbit.vcell.solver.Simulation) DataOperationResults(cbit.vcell.simdata.DataOperationResults) File(java.io.File) XMLSource(cbit.vcell.xml.XMLSource) SolverStatus(cbit.vcell.solver.server.SolverStatus) SimulationJob(cbit.vcell.solver.SimulationJob) PrintWriter(java.io.PrintWriter)

Example 37 with VCSimulationDataIdentifier

use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.

the class RestDatabaseService method getDataSetTimeSeries.

public DataSetTimeSeries getDataSetTimeSeries(SimDataValuesServerResource resource, User vcellUser) throws DataAccessException, ObjectNotFoundException, SQLException {
    if (vcellUser == null) {
        vcellUser = VCellApiApplication.DUMMY_USER;
    }
    UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName(), null);
    // resource.getRequestAttributes().get(VCellApiApplication.SIMDATAID);
    String simId = resource.getAttribute(VCellApiApplication.SIMDATAID);
    // resource.getRequestAttributes().get(VCellApiApplication.SIMDATAID);
    String jobIndexString = resource.getAttribute(VCellApiApplication.JOBINDEX);
    KeyValue simKey = new KeyValue(simId);
    SimulationRep simRep = getSimulationRep(simKey);
    if (simRep == null) {
        throw new ObjectNotFoundException("Simulation with key " + simKey + " not found");
    }
    int jobIndex = Integer.parseInt(jobIndexString);
    // TODO: pass in variables names from the query parameters.
    String[] variableNames = null;
    User owner = simRep.getOwner();
    VCMessageSession rpcSession = vcMessagingService.createProducerSession();
    try {
        RpcDataServerProxy rpcDataServerProxy = new RpcDataServerProxy(userLoginInfo, rpcSession);
        VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, owner);
        VCDataIdentifier vcdID = new VCSimulationDataIdentifier(vcSimID, jobIndex);
        DataSetTimeSeries dataSetTimeSeries = rpcDataServerProxy.getDataSetTimeSeries(vcdID, variableNames);
        return dataSetTimeSeries;
    } finally {
        rpcSession.close();
    }
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) VCMessageSession(cbit.vcell.message.VCMessageSession) BigString(org.vcell.util.BigString) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) RpcDataServerProxy(org.vcell.rest.rpc.RpcDataServerProxy) DataSetTimeSeries(cbit.vcell.simdata.DataSetTimeSeries) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) UserLoginInfo(org.vcell.util.document.UserLoginInfo) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) SimulationRep(cbit.vcell.modeldb.SimulationRep)

Example 38 with VCSimulationDataIdentifier

use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.

the class BioModelWindowManager method simStatusChanged.

/**
 * Insert the method's description here.
 * Creation date: (6/9/2004 3:58:21 PM)
 * @param newJobStatus cbit.vcell.messaging.db.SimulationJobStatus
 * @param progress java.lang.Double
 * @param timePoint java.lang.Double
 */
public void simStatusChanged(SimStatusEvent simStatusEvent) {
    // ** events are only generated from server side job statuses **
    KeyValue simKey = simStatusEvent.getVCSimulationIdentifier().getSimulationKey();
    // do we have the sim?
    Simulation[] sims = getBioModel().getSimulations();
    if (sims == null) {
        // we don't have it
        return;
    }
    Simulation simulation = null;
    for (int i = 0; i < sims.length; i++) {
        if (sims[i].getSimulationInfo() != null && simKey.equals(sims[i].getSimulationInfo().getAuthoritativeVCSimulationIdentifier().getSimulationKey())) {
            simulation = sims[i];
            break;
        }
    }
    if (simulation == null) {
        // we don't have it
        return;
    }
    // we have it; get current server side status
    SimulationStatus simStatus = getRequestManager().getServerSimulationStatus(simulation.getSimulationInfo());
    // if failed, notify
    if (simStatusEvent.isNewFailureEvent()) {
        String qualifier = "";
        if (simulation.getScanCount() > 1) {
            qualifier += "One job from ";
        }
        PopupGenerator.showErrorDialog(this, qualifier + "Simulation '" + simulation.getName() + "' failed\n" + simStatus.getDetails());
    }
    // was the gui on it ever opened?
    SimulationContext simContext = null;
    simulation = null;
    Enumeration<SimulationContext> en = getApplicationsHash().keys();
    while (en.hasMoreElements()) {
        SimulationContext sc = (SimulationContext) en.nextElement();
        sims = sc.getSimulations();
        if (sims != null) {
        }
        for (int i = 0; i < sims.length; i++) {
            if (sims[i].getSimulationInfo() != null && simKey.equals(sims[i].getSimulationInfo().getAuthoritativeVCSimulationIdentifier().getSimulationKey())) {
                simulation = sims[i];
                break;
            }
        }
        if (simulation != null) {
            simContext = sc;
            break;
        }
    }
    if (simulation == null || simContext == null) {
        return;
    }
    // the gui was opened, update status display
    ApplicationComponents appComponents = (ApplicationComponents) getApplicationsHash().get(simContext);
    ClientSimManager simManager = appComponents.getSimulationWorkspace().getClientSimManager();
    simManager.updateStatusFromServer(simulation);
    // is there new data?
    if (simStatusEvent.isNewDataEvent()) {
        fireNewData(new DataEvent(this, new VCSimulationDataIdentifier(simulation.getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), simStatusEvent.getJobIndex())));
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) Simulation(cbit.vcell.solver.Simulation) SimulationStatus(cbit.vcell.server.SimulationStatus) ApplicationComponents(cbit.vcell.client.desktop.biomodel.ApplicationComponents) DataEvent(cbit.vcell.simdata.DataEvent) SimulationContext(cbit.vcell.mapping.SimulationContext) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier)

Example 39 with VCSimulationDataIdentifier

use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.

the class NonGUIFRAPTest method runSolver.

/**
 * @param args
 */
public static void runSolver(String[] args) throws Exception {
    String startingIndexForRecovery = args[0];
    String freeDiffusionRateStr = args[1];
    String freeMobileFractionStr = args[2];
    String complexDiffusionRateStr = args[3];
    String complexMobileFractionStr = args[4];
    String bleachWhileMonitoringRateString = args[5];
    String immobileFractionStr = args[6];
    String bindingSiteConcentrationStr = args[7];
    String reacOnRateStr = args[8];
    String reacOffRateStr = args[9];
    String workingDirectoryPath = args[10];
    String inputFRAPDataFileName = args[11];
    String inputCellROIFileName = args[12];
    String inputBleachROIFileName = args[13];
    String inputBackgroundROIFileName = args[14];
    String outputXMLFileName = args[15];
    String commaSepTimeStamps = args[16];
    String commaSepExtentXYZ = args[17];
    LocalWorkspace localWorkspace = new LocalWorkspace(new File(workingDirectoryPath));
    ExternalDataFileContents extDataFileContents = readExternalDataContents(inputFRAPDataFileName, inputCellROIFileName, inputBleachROIFileName, inputBackgroundROIFileName);
    ROI cellROI = new ROI(extDataFileContents.cellROIData.getImage(0, 0, 0), FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name());
    ROI bleachROI = new ROI(extDataFileContents.bleachROIData.getImage(0, 0, 0), FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name());
    ROI backgroundROI = new ROI(extDataFileContents.backgroundROIData.getImage(0, 0, 0), FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name());
    // Insert Time information
    double[] timeStamps = new double[extDataFileContents.imageData.getAllImages().length];
    StringTokenizer commaStringTokenizer = new StringTokenizer(commaSepTimeStamps, ",");
    int timeCount = 0;
    while (commaStringTokenizer.hasMoreTokens()) {
        timeStamps[timeCount] = Double.parseDouble(commaStringTokenizer.nextToken());
        timeCount++;
    }
    ImageDataset frapDataImageDataSet = new ImageDataset(extDataFileContents.imageData.getAllImages(), timeStamps, 1);
    // Insert Extent information
    commaStringTokenizer = new StringTokenizer(commaSepExtentXYZ, ",");
    Extent extent = new Extent(Double.parseDouble(commaStringTokenizer.nextToken()), Double.parseDouble(commaStringTokenizer.nextToken()), Double.parseDouble(commaStringTokenizer.nextToken()));
    frapDataImageDataSet.setExtent(extent);
    bleachROI.getRoiImages()[0].setExtent(extent);
    cellROI.getRoiImages()[0].setExtent(extent);
    backgroundROI.getRoiImages()[0].setExtent(extent);
    FRAPData frapData = FrapDataUtils.importFRAPDataFromImageDataSet(frapDataImageDataSet);
    frapData.addReplaceRoi(bleachROI);
    frapData.addReplaceRoi(cellROI);
    frapData.addReplaceRoi(backgroundROI);
    FRAPStudy frapStudy = new FRAPStudy();
    frapStudy.setFrapData(frapData);
    // old model parameters, need to rewrite
    // FRAPStudy.FRAPModelParameters frapModelParameters = new FRAPStudy.FRAPModelParameters(
    // new FRAPStudy.InitialModelParameters(freeDiffusionRateStr, freeMobileFractionStr, bleachWhileMonitoringRateString, startingIndexForRecovery),
    // null,
    // null);
    // frapStudy.setFrapModelParameters(frapModelParameters);
    frapStudy.refreshDependentROIs();
    ExternalDataInfo imageDatasetExternalDataInfo = FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.IMAGE_EXTDATA_NAME);
    ExternalDataInfo roiExternalDataInfo = FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.ROI_EXTDATA_NAME);
    frapStudy.setFrapDataExternalDataInfo(imageDatasetExternalDataInfo);
    frapStudy.setRoiExternalDataInfo(roiExternalDataInfo);
    frapStudy.saveImageDatasetAsExternalData(localWorkspace, frapStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), frapStudy.getStartingIndexForRecovery());
    frapStudy.saveROIsAsExternalData(localWorkspace, frapStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), frapStudy.getStartingIndexForRecovery());
    // Double bleachWhileMonitoringRate =
    // (!bleachWhileMonitoringRateString.equals("-")
    // ?Double.parseDouble(bleachWhileMonitoringRateString)
    // :null);
    double fd, ff, bwmr, cd, cf, imf, bs, on, off;
    try {
        fd = Double.parseDouble(freeDiffusionRateStr);
        ff = Double.parseDouble(freeMobileFractionStr);
        bwmr = Double.parseDouble(bleachWhileMonitoringRateString);
        cd = Double.parseDouble(complexDiffusionRateStr);
        cf = Double.parseDouble(complexMobileFractionStr);
        imf = Double.parseDouble(immobileFractionStr);
        bs = Double.parseDouble(bindingSiteConcentrationStr);
        on = Double.parseDouble(reacOnRateStr);
        off = Double.parseDouble(reacOffRateStr);
    } catch (NumberFormatException e) {
        throw new Exception("Input parameters are not all valid. Check if they are empty or in illegal forms.");
    }
    BioModel bioModel = FRAPStudy.createNewSimBioModel(frapStudy, createParameterArray(fd, ff, bwmr, cd, cf, imf, bs, on, off), null, LocalWorkspace.createNewKeyValue(), LocalWorkspace.getDefaultOwner(), new Integer(frapStudy.getStartingIndexForRecovery()));
    frapStudy.setBioModel(bioModel);
    // no progress listener, need to change
    MicroscopyXmlproducer.writeXMLFile(frapStudy, new File(outputXMLFileName), true, null, false);
    FRAPStudy.runFVSolverStandalone(new File(localWorkspace.getDefaultSimDataDirectory()), bioModel.getSimulation(0), imageDatasetExternalDataInfo.getExternalDataIdentifier(), roiExternalDataInfo.getExternalDataIdentifier(), null);
    VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(bioModel.getSimulations()[0].getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), FieldDataFileOperationSpec.JOBINDEX_DEFAULT);
    PDEDataManager simulationDataManager = new PDEDataManager(null, localWorkspace.getVCDataManager(), vcSimulationDataIdentifier);
    double[] frapDataTimeStamps = frapData.getImageDataset().getImageTimeStamps();
    VCDataManager testVCDataManager = localWorkspace.getVCDataManager();
    double[] prebleachAverage = testVCDataManager.getSimDataBlock(null, frapStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), "prebleach_avg", 0).getData();
    // TODO: need to create parameters here.
    Parameter[] parameters = null;
    SpatialAnalysisResults spatialAnalysisResults = FRAPStudy.spatialAnalysis(simulationDataManager, new Integer(frapStudy.getStartingIndexForRecovery()), frapDataTimeStamps[new Integer(frapStudy.getStartingIndexForRecovery())], parameters, frapData, prebleachAverage);
    dumpSummaryReport(spatialAnalysisResults, frapDataTimeStamps, new Integer(startingIndexForRecovery).intValue(), new File(workingDirectoryPath, "nonguiSpatialResults.txt"));
    dumpSpatialResults(spatialAnalysisResults, frapDataTimeStamps, new File(workingDirectoryPath, "nonguiSpatialResults.txt"));
}
Also used : ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) Extent(org.vcell.util.Extent) ROI(cbit.vcell.VirtualMicroscopy.ROI) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) StringTokenizer(java.util.StringTokenizer) PDEDataManager(cbit.vcell.simdata.PDEDataManager) BioModel(cbit.vcell.biomodel.BioModel) Parameter(cbit.vcell.opt.Parameter) File(java.io.File) VCDataManager(cbit.vcell.simdata.VCDataManager)

Example 40 with VCSimulationDataIdentifier

use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.

the class SimulationData method getVCellSimFiles.

@Override
public VCellSimFiles getVCellSimFiles() throws FileNotFoundException, DataAccessException {
    File cartesianMeshFile = getMeshFile();
    File meshMetricsFile = getMembraneMeshMetricsFile();
    File subdomainFile = getSubdomainFile();
    File logFile = getLogFile();
    File postprocessingFile = getDataProcessingOutputSourceFileHDF5();
    if (!(vcDataId instanceof VCSimulationDataIdentifier)) {
        throw new RuntimeException("cannot process vtk, vcDataId not " + VCSimulationDataIdentifier.class.getSimpleName());
    }
    VCSimulationDataIdentifier vcSimDataID = (VCSimulationDataIdentifier) vcDataId;
    VCellSimFiles vcellSimFiles = new VCellSimFiles(vcSimDataID.getSimulationKey(), vcSimDataID.getJobIndex(), cartesianMeshFile, meshMetricsFile, subdomainFile, logFile, postprocessingFile);
    refreshLogFile();
    double[] times = getDataTimes();
    for (int i = 0; i < times.length; i++) {
        File pdeDataFile = getPDEDataFile(times[i]);
        File zipFile = getPDEDataZipFile(times[i]);
        vcellSimFiles.addDataFileEntry(zipFile, pdeDataFile, times[i]);
    }
    return vcellSimFiles;
}
Also used : VCellSimFiles(org.vcell.vis.io.VCellSimFiles) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier)

Aggregations

VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)47 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)27 File (java.io.File)25 KeyValue (org.vcell.util.document.KeyValue)24 User (org.vcell.util.document.User)15 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)15 Simulation (cbit.vcell.solver.Simulation)11 BioModel (cbit.vcell.biomodel.BioModel)8 DataSetControllerImpl (cbit.vcell.simdata.DataSetControllerImpl)8 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)7 PDEDataManager (cbit.vcell.simdata.PDEDataManager)7 BigString (org.vcell.util.BigString)7 DataIdentifier (cbit.vcell.simdata.DataIdentifier)6 ODEDataManager (cbit.vcell.simdata.ODEDataManager)6 CartesianMesh (cbit.vcell.solvers.CartesianMesh)6 OutputContext (cbit.vcell.simdata.OutputContext)5 VCDataManager (cbit.vcell.simdata.VCDataManager)5 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)5 IOException (java.io.IOException)5 Hashtable (java.util.Hashtable)5