Search in sources :

Example 1 with ODEDataManager

use of cbit.vcell.simdata.ODEDataManager in project vcell by virtualcell.

the class ClientSimManager method showSimulationResults0.

private AsynchClientTask[] showSimulationResults0(final boolean isLocal, final ViewerType viewerType) {
    // Create the AsynchClientTasks
    ArrayList<AsynchClientTask> taskList = new ArrayList<AsynchClientTask>();
    taskList.add(new AsynchClientTaskFunction(h -> {
        h.put(H_LOCAL_SIM, isLocal);
        h.put(H_VIEWER_TYPE, viewerType);
    }, "setLocal", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING));
    final DocumentWindowManager documentWindowManager = getDocumentWindowManager();
    AsynchClientTask retrieveResultsTask = new AsynchClientTask("Retrieving results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @SuppressWarnings("unchecked")
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Simulation[] simsToShow = (Simulation[]) hashTable.get("simsArray");
            for (int i = 0; i < simsToShow.length; i++) {
                final Simulation sim = simsToShow[i];
                final VCSimulationIdentifier vcSimulationIdentifier = sim.getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
                final SimulationWindow simWindow = documentWindowManager.haveSimulationWindow(vcSimulationIdentifier);
                OutputContext outputContext = (OutputContext) hashTable.get("outputContext");
                if (simWindow == null && (viewerType == ViewerType.NativeViewer_only)) {
                    try {
                        // make the manager and wire it up
                        DataViewerController dataViewerController = null;
                        if (!isLocal) {
                            dataViewerController = documentWindowManager.getRequestManager().getDataViewerController(outputContext, sim, 0);
                            // For changes in time or variable
                            documentWindowManager.addDataListener(dataViewerController);
                        } else {
                            // ---- preliminary : construct the localDatasetControllerProvider
                            File primaryDir = ResourceUtil.getLocalRootDir();
                            User usr = sim.getVersion().getOwner();
                            DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
                            ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
                            LocalDataSetControllerProvider localDSCProvider = new LocalDataSetControllerProvider(usr, dataSetControllerImpl, localExportServiceImpl);
                            VCDataManager vcDataManager = new VCDataManager(localDSCProvider);
                            File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
                            LocalVCDataIdentifier vcDataId = new LocalVCSimulationDataIdentifier(vcSimulationIdentifier, 0, localSimDir);
                            DataManager dataManager = null;
                            if (sim.isSpatial()) {
                                dataManager = new PDEDataManager(outputContext, vcDataManager, vcDataId);
                            } else {
                                dataManager = new ODEDataManager(outputContext, vcDataManager, vcDataId);
                            }
                            dataViewerController = new SimResultsViewerController(dataManager, sim);
                            dataSetControllerImpl.addDataJobListener(documentWindowManager);
                        }
                        // make the viewer
                        Hashtable<VCSimulationIdentifier, DataViewerController> dataViewerControllers = (Hashtable<VCSimulationIdentifier, DataViewerController>) hashTable.get(H_DATA_VIEWER_CONTROLLERS);
                        if (dataViewerControllers == null) {
                            dataViewerControllers = new Hashtable<VCSimulationIdentifier, DataViewerController>();
                            hashTable.put(H_DATA_VIEWER_CONTROLLERS, dataViewerControllers);
                        }
                        dataViewerControllers.put(vcSimulationIdentifier, dataViewerController);
                    } catch (Throwable exc) {
                        exc.printStackTrace(System.out);
                        saveFailure(hashTable, sim, exc);
                    }
                }
            }
        }
    };
    taskList.add(retrieveResultsTask);
    AsynchClientTask displayResultsTask = new AsynchClientTask("Showing results", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @SuppressWarnings("unchecked")
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            boolean isLocal = fetch(hashTable, H_LOCAL_SIM, Boolean.class, true);
            SimulationWindow.LocalState localState = isLocal ? LocalState.LOCAL : LocalState.SERVER;
            Hashtable<Simulation, Throwable> failures = (Hashtable<Simulation, Throwable>) hashTable.get(H_FAILURES);
            Simulation[] simsToShow = (Simulation[]) hashTable.get("simsArray");
            for (int i = 0; i < simsToShow.length; i++) {
                final Simulation sim = simsToShow[i];
                if (failures != null && failures.containsKey(sim)) {
                    continue;
                }
                final VCSimulationIdentifier vcSimulationIdentifier = simsToShow[i].getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
                final SimulationWindow simWindow = documentWindowManager.haveSimulationWindow(vcSimulationIdentifier);
                if (simWindow != null) {
                    ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(documentWindowManager.getComponent());
                    ChildWindow childWindow = childWindowManager.getChildWindowFromContext(simWindow);
                    if (childWindow == null) {
                        childWindow = childWindowManager.addChildWindow(simWindow.getDataViewer(), simWindow);
                        childWindow.pack();
                        childWindow.setIsCenteredOnParent();
                        childWindow.show();
                    }
                    setFinalWindow(hashTable, childWindow);
                    simWindow.setLocalState(localState);
                } else {
                    // wire it up the viewer
                    Hashtable<VCSimulationIdentifier, DataViewerController> dataViewerControllers = (Hashtable<VCSimulationIdentifier, DataViewerController>) hashTable.get(H_DATA_VIEWER_CONTROLLERS);
                    DataViewerController viewerController = dataViewerControllers.get(vcSimulationIdentifier);
                    Throwable ex = (failures == null ? null : failures.get(sim));
                    if (viewerController != null && ex == null) {
                        // no failure
                        DataViewer viewer = viewerController.createViewer();
                        getSimWorkspace().getSimulationOwner().getOutputFunctionContext().addPropertyChangeListener(viewerController);
                        documentWindowManager.addExportListener(viewer);
                        // For data related activities such as calculating statistics
                        documentWindowManager.addDataJobListener(viewer);
                        viewer.setSimulationModelInfo(new SimulationWorkspaceModelInfo(getSimWorkspace().getSimulationOwner(), sim.getName()));
                        viewer.setDataViewerManager(documentWindowManager);
                        SimulationWindow newWindow = new SimulationWindow(vcSimulationIdentifier, sim, getSimWorkspace().getSimulationOwner(), viewer);
                        BeanUtils.addCloseWindowKeyboardAction(newWindow.getDataViewer());
                        documentWindowManager.addResultsFrame(newWindow);
                        setFinalWindow(hashTable, viewer);
                        newWindow.setLocalState(localState);
                    }
                }
            }
            StringBuffer failMessage = new StringBuffer();
            if (failures != null) {
                if (!failures.isEmpty()) {
                    failMessage.append("Error, " + failures.size() + " of " + simsToShow.length + " sim results failed to display:\n");
                    Enumeration<Simulation> en = failures.keys();
                    while (en.hasMoreElements()) {
                        Simulation sim = en.nextElement();
                        Throwable exc = (Throwable) failures.get(sim);
                        failMessage.append("'" + sim.getName() + "' - " + exc.getMessage());
                    }
                }
            }
            if (failMessage.length() > 0) {
                PopupGenerator.showErrorDialog(ClientSimManager.this.getDocumentWindowManager(), failMessage.toString());
            }
        }
    };
    if (viewerType == ViewerType.NativeViewer_only) {
        taskList.add(displayResultsTask);
    }
    // Dispatch the tasks using the ClientTaskDispatcher.
    AsynchClientTask[] taskArray = new AsynchClientTask[taskList.size()];
    taskList.toArray(taskArray);
    return taskArray;
}
Also used : User(org.vcell.util.document.User) SimulationMessage(cbit.vcell.solver.server.SimulationMessage) Enumeration(java.util.Enumeration) Version(org.vcell.util.document.Version) Vector(java.util.Vector) Map(java.util.Map) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) SimulationContext(cbit.vcell.mapping.SimulationContext) PrintWriter(java.io.PrintWriter) NetworkGenerationRequirements(cbit.vcell.mapping.SimulationContext.NetworkGenerationRequirements) VCDataManager(cbit.vcell.simdata.VCDataManager) BeanUtils(org.vcell.util.BeanUtils) ODESimData(cbit.vcell.solver.ode.ODESimData) WindowAdapter(java.awt.event.WindowAdapter) SimulationWorkspace(cbit.vcell.client.desktop.simulation.SimulationWorkspace) SolverListener(cbit.vcell.solver.server.SolverListener) VtkManager(cbit.vcell.simdata.VtkManager) SimulationJob(cbit.vcell.solver.SimulationJob) VCellClientTest(cbit.vcell.client.test.VCellClientTest) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) DataProcessingInstructions(cbit.vcell.solver.DataProcessingInstructions) VCellClientDataServiceImpl(cbit.vcell.client.data.VCellClientDataServiceImpl) OutputContext(cbit.vcell.simdata.OutputContext) SimulationTask(cbit.vcell.messaging.server.SimulationTask) VCDocument(org.vcell.util.document.VCDocument) TempSimulation(cbit.vcell.solver.TempSimulation) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SolverFactory(cbit.vcell.solver.server.SolverFactory) SolverStatus(cbit.vcell.solver.server.SolverStatus) SimulationInfo(cbit.vcell.solver.SimulationInfo) Container(java.awt.Container) PDEDataManager(cbit.vcell.simdata.PDEDataManager) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) UserPreferences(cbit.vcell.client.server.UserPreferences) BioModel(cbit.vcell.biomodel.BioModel) BufferedWriter(java.io.BufferedWriter) RemoteProxyException(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException) Window(java.awt.Window) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) PropertyLoader(cbit.vcell.resource.PropertyLoader) InputStreamReader(java.io.InputStreamReader) File(java.io.File) SolverUtilities(cbit.vcell.solver.SolverUtilities) DialogUtils(org.vcell.util.gui.DialogUtils) DataViewerController(cbit.vcell.client.data.DataViewerController) SimResultsViewer(cbit.vcell.client.data.SimResultsViewer) LocalVCDataIdentifier(org.vcell.util.document.LocalVCDataIdentifier) SimulationWindow(cbit.vcell.client.desktop.simulation.SimulationWindow) EventObject(java.util.EventObject) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) DataViewer(cbit.vcell.client.data.DataViewer) ColumnDescription(cbit.vcell.util.ColumnDescription) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) SmoldynSolver(org.vcell.solver.smoldyn.SmoldynSolver) Simulation(cbit.vcell.solver.Simulation) Solver(cbit.vcell.solver.server.Solver) Collection(java.util.Collection) UtilCancelException(org.vcell.util.UtilCancelException) WindowEvent(java.awt.event.WindowEvent) FileNotFoundException(java.io.FileNotFoundException) SolverEvent(cbit.vcell.solver.server.SolverEvent) AsynchClientTaskFunction(cbit.vcell.client.task.AsynchClientTaskFunction) Dimension(java.awt.Dimension) List(java.util.List) ClientTaskDispatcher(cbit.vcell.client.task.ClientTaskDispatcher) VCellConfiguration(cbit.vcell.resource.VCellConfiguration) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) SimulationOwner(cbit.vcell.solver.SimulationOwner) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) SimulationWorkspaceModelInfo(cbit.vcell.client.data.SimulationWorkspaceModelInfo) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) DataSetController(cbit.vcell.server.DataSetController) VtuVarInfo(org.vcell.vis.io.VtuVarInfo) LocalState(cbit.vcell.client.desktop.simulation.SimulationWindow.LocalState) SwingUtilities(javax.swing.SwingUtilities) SimDataConstants(cbit.vcell.simdata.SimDataConstants) SolverException(cbit.vcell.solver.SolverException) Hashtable(java.util.Hashtable) SimulationStatusDetailsPanel(cbit.vcell.client.desktop.simulation.SimulationStatusDetailsPanel) SimulationStatus(cbit.vcell.server.SimulationStatus) SimulationDataSetRef(cbit.vcell.client.pyvcellproxy.SimulationDataSetRef) ClientServerManager(cbit.vcell.client.server.ClientServerManager) ResourceUtil(cbit.vcell.resource.ResourceUtil) ODEDataManager(cbit.vcell.simdata.ODEDataManager) FileWriter(java.io.FileWriter) SmoldynFileWriter(org.vcell.solver.smoldyn.SmoldynFileWriter) ExpressionException(cbit.vcell.parser.ExpressionException) TokenMangler(org.vcell.util.TokenMangler) SolverDescription(cbit.vcell.solver.SolverDescription) SimulationStatusDetails(cbit.vcell.client.desktop.simulation.SimulationStatusDetails) ProgressDialogListener(org.vcell.util.ProgressDialogListener) DataManager(cbit.vcell.simdata.DataManager) InputStream(java.io.InputStream) UserCancelException(org.vcell.util.UserCancelException) LocalState(cbit.vcell.client.desktop.simulation.SimulationWindow.LocalState) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) User(org.vcell.util.document.User) ArrayList(java.util.ArrayList) AsynchClientTaskFunction(cbit.vcell.client.task.AsynchClientTaskFunction) DataViewerController(cbit.vcell.client.data.DataViewerController) DataViewer(cbit.vcell.client.data.DataViewer) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) VCDataManager(cbit.vcell.simdata.VCDataManager) SimulationWorkspaceModelInfo(cbit.vcell.client.data.SimulationWorkspaceModelInfo) Hashtable(java.util.Hashtable) VCDataManager(cbit.vcell.simdata.VCDataManager) PDEDataManager(cbit.vcell.simdata.PDEDataManager) ODEDataManager(cbit.vcell.simdata.ODEDataManager) DataManager(cbit.vcell.simdata.DataManager) LocalVCDataIdentifier(org.vcell.util.document.LocalVCDataIdentifier) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) OutputContext(cbit.vcell.simdata.OutputContext) TempSimulation(cbit.vcell.solver.TempSimulation) Simulation(cbit.vcell.solver.Simulation) PDEDataManager(cbit.vcell.simdata.PDEDataManager) SimulationWindow(cbit.vcell.client.desktop.simulation.SimulationWindow) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) ODEDataManager(cbit.vcell.simdata.ODEDataManager) File(java.io.File)

Example 2 with ODEDataManager

use of cbit.vcell.simdata.ODEDataManager in project vcell by virtualcell.

the class ODETimePlotMultipleScansPanel method updateScanParamChoices.

/**
 * Insert the method's description here.
 * Creation date: (10/18/2005 12:44:06 AM)
 */
private void updateScanParamChoices() {
    AsynchClientTask task1 = new AsynchClientTask("get ode results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            int[] jobIndexes = scanChoiceTable.getSelectedRows();
            VCSimulationIdentifier vcSimulationIdentifier = simulation.getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
            int plotCount = jobIndexes.length * variableNames.length;
            SymbolTableEntry[] symbolTableEntries = new SymbolTableEntry[plotCount];
            double[][] dataValues = new double[plotCount + 1][];
            PlotData[] plotDatas = new PlotData[plotCount];
            String[] plotNames = new String[plotCount];
            int plotIndex = 0;
            dataValues[0] = null;
            for (int ji = 0; ji < jobIndexes.length; ji++) {
                int jobIndex = jobIndexes[ji];
                final VCDataIdentifier vcdid = new VCSimulationDataIdentifier(vcSimulationIdentifier, jobIndex);
                ODEDataManager odeDatamanager = ((ODEDataManager) dataManager).createNewODEDataManager(vcdid);
                ODESolverResultSet odeSolverResultSet = odeDatamanager.getODESolverResultSet();
                if (ji == 0) {
                    plotPane.setStepViewVisible(simulation.getSolverTaskDescription().getSolverDescription().isNonSpatialStochasticSolver(), odeSolverResultSet.isMultiTrialData());
                    hashTable.put("bMultiTrial", new Boolean(odeSolverResultSet.isMultiTrialData()));
                }
                double[] tdata = null;
                if (!odeSolverResultSet.isMultiTrialData()) {
                    int tcol = odeSolverResultSet.findColumn(xVarColumnName);
                    tdata = odeSolverResultSet.extractColumn(tcol);
                    if (dataValues[0] == null) {
                        dataValues[0] = tdata;
                    }
                }
                for (int v = 0; v < variableNames.length; v++) {
                    String varname = variableNames[v];
                    int varcol = odeSolverResultSet.findColumn(varname);
                    double[] vdata = odeSolverResultSet.extractColumn(varcol);
                    if (!odeSolverResultSet.isMultiTrialData()) {
                        dataValues[plotIndex + 1] = vdata;
                        // plotNames[plotIndex] = varname + " -- " + JOB_PLOT_NAME + " " + jobIndex;
                        plotDatas[plotIndex] = new PlotData(tdata, vdata);
                    // symbolTableEntries[plotIndex] = simulation.getMathDescription().getVariable(varname);
                    } else {
                        Point2D[] histogram = ODESolverPlotSpecificationPanel.generateHistogram(vdata);
                        double[] x = new double[histogram.length];
                        double[] y = new double[histogram.length];
                        for (int j = 0; j < histogram.length; j++) {
                            x[j] = histogram[j].getX();
                            y[j] = histogram[j].getY();
                        }
                        plotDatas[plotIndex] = new PlotData(x, y);
                    }
                    plotNames[plotIndex] = varname + " -- " + JOB_PLOT_NAME + " " + jobIndex;
                    symbolTableEntries[plotIndex] = simulation.getMathDescription().getVariable(varname);
                    plotIndex++;
                }
            }
            hashTable.put("dataValues", dataValues);
            hashTable.put("plotDatas", plotDatas);
            hashTable.put("plotNames", plotNames);
            hashTable.put("symbolTableEntries", symbolTableEntries);
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("show results", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            double[][] dataValues = (double[][]) hashTable.get("dataValues");
            PlotData[] plotDatas = (PlotData[]) hashTable.get("plotDatas");
            String[] plotNames = (String[]) hashTable.get("plotNames");
            SymbolTableEntry[] symbolTableEntries = (SymbolTableEntry[]) hashTable.get("symbolTableEntries");
            if (plotDatas == null || plotDatas.length == 0 || (plotDatas.length == 1 && plotDatas[0] == null) || plotNames == null) {
                plotPane.setPlot2D(null);
                return;
            }
            Plot2D plot2D = null;
            if (hashTable.get("bMultiTrial") instanceof Boolean && (Boolean) hashTable.get("bMultiTrial")) {
                plot2D = new Plot2D(symbolTableEntries, null, plotNames, plotDatas, new String[] { "Probability Distribution of Species", "Number of Particles", "" });
            }
            // else if(simulation.getSolverTaskDescription().getOutputTimeSpec() instanceof DefaultOutputTimeSpec)
            // {
            plot2D = new Plot2D(symbolTableEntries, null, plotNames, plotDatas, new String[] { "Plot", xVarColumnName, /*ReservedVariable.TIME.getName()*/
            "" });
            // }
            // else
            // {
            // plot2D = new SingleXPlot2D(symbolTableEntries, null, ReservedVariable.TIME.getName(), plotNames, dataValues);
            // }
            plotPane.setPlot2D(plot2D);
            plotPane.setHDF5ParamScanParamNames(scanParams);
            plotPane.setHDF5ParamScanParamValues(values);
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
}
Also used : PlotData(cbit.plot.PlotData) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) Hashtable(java.util.Hashtable) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Point2D(java.awt.geom.Point2D) ODEDataManager(cbit.vcell.simdata.ODEDataManager) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) SingleXPlot2D(cbit.plot.SingleXPlot2D) Plot2D(cbit.plot.Plot2D) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier)

Example 3 with ODEDataManager

use of cbit.vcell.simdata.ODEDataManager in project vcell by virtualcell.

the class SimResultsViewer method updateScanParamChoices.

private void updateScanParamChoices(final String message, ListReset listReset) {
    if ((paramScanChoiceTimer = ClientTaskDispatcher.getBlockingTimer(this, null, null, paramScanChoiceTimer, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e2) {
            updateScanParamChoices(message, listReset);
        }
    }, message)) != null) {
        return;
    }
    int selectedJobIndex = getSelectedParamScanJobIndex();
    // update viewer
    if (selectedJobIndex == -1) {
        if (isODEData) {
            if (listReset != null && odeDataViewer != null && odeDataViewer.getVcDataIdentifier() != null) {
                listReset.reset(odeDataViewer.getVcDataIdentifier());
            } else {
                odeDataViewer.setOdeSolverResultSet(null);
            }
        } else {
            if (listReset != null && pdeDataViewer != null && pdeDataViewer.getPdeDataContext() != null && pdeDataViewer.getPdeDataContext().getVCDataIdentifier() != null) {
                listReset.reset(pdeDataViewer.getPdeDataContext().getVCDataIdentifier());
            } else {
                pdeDataViewer.setPdeDataContext(null);
            }
        }
        return;
    }
    final VCSimulationDataIdentifier vcdid = new VCSimulationDataIdentifier(getSimulation().getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), selectedJobIndex);
    if (isODEData) {
        AsynchClientTask task1 = new AsynchClientTask("get ode results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                try {
                    ODEDataManager odeDatamanager = ((ODEDataManager) dataManager).createNewODEDataManager(vcdid);
                    hashTable.put("odeDatamanager", odeDatamanager);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    if (e.getMessage() != null && e.getMessage().contains("no results are available yet")) {
                        throw UserCancelException.CANCEL_GENERIC;
                    }
                    throw e;
                }
            }
        };
        AsynchClientTask task2 = new AsynchClientTask("show results", AsynchClientTask.TASKTYPE_SWING_BLOCKING, false, false) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                if (hashTable.get(ClientTaskDispatcher.TASK_ABORTED_BY_ERROR) == null && hashTable.get(ClientTaskDispatcher.TASK_ABORTED_BY_USER) == null) {
                    ODEDataManager odeDatamanager = (ODEDataManager) hashTable.get("odeDatamanager");
                    odeDataViewer.setOdeSolverResultSet(odeDatamanager.getODESolverResultSet());
                    odeDataViewer.setVcDataIdentifier(vcdid);
                } else {
                    odeDataViewer.setOdeSolverResultSet(null);
                }
            }
        };
        ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
    } else {
        AsynchClientTask task1 = new AsynchClientTask("get pde results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                PDEDataManager pdeDatamanager = ((PDEDataManager) dataManager).createNewPDEDataManager(vcdid, null);
                PDEDataContext newPDEDC = pdeDatamanager.getPDEDataContext();
                PDEDataContext oldPDEDC = pdeDataViewer.getPdeDataContext();
                hashTable.put("newPDEDC", newPDEDC);
                if (oldPDEDC != null && oldPDEDC.getTimePoints().length <= newPDEDC.getTimePoints().length) {
                    DataIdentifier setDid = (newPDEDC.getDataIdentifier() == null ? newPDEDC.getDataIdentifiers()[0] : newPDEDC.getDataIdentifier());
                    if (Arrays.asList(newPDEDC.getDataIdentifiers()).contains(oldPDEDC.getDataIdentifier())) {
                        setDid = oldPDEDC.getDataIdentifier();
                        newPDEDC.setVariableAndTime(setDid, newPDEDC.getTimePoints()[BeanUtils.firstIndexOf(oldPDEDC.getTimePoints(), oldPDEDC.getTimePoint())]);
                    }
                }
            }
        };
        AsynchClientTask task2 = new AsynchClientTask("show results", AsynchClientTask.TASKTYPE_SWING_BLOCKING, false, false) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                if (hashTable.get(ClientTaskDispatcher.TASK_ABORTED_BY_ERROR) == null) {
                    ClientPDEDataContext newPDEDC = (ClientPDEDataContext) hashTable.get("newPDEDC");
                    pdeDataViewer.setPdeDataContext(newPDEDC);
                    pdeDataViewer.setSimNameSimDataID(new ExportSpecs.SimNameSimDataID(getSimulation().getName(), getSimulation().getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), SimResultsViewer.getParamScanInfo(getSimulation(), vcdid.getJobIndex())));
                } else {
                    if (listReset != null && pdeDataViewer != null && pdeDataViewer.getPdeDataContext() != null && pdeDataViewer.getPdeDataContext().getVCDataIdentifier() != null) {
                        listReset.reset(pdeDataViewer.getPdeDataContext().getVCDataIdentifier());
                    } else {
                        pdeDataViewer.setPdeDataContext(null);
                        pdeDataViewer.setSimNameSimDataID(null);
                    }
                }
            }
        };
        // AsynchClientTask refreshTask = new AsynchClientTask("",AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
        // @Override
        // public void run(Hashtable<String, Object> hashTable) throws Exception {
        // ((ArrayList<AsynchClientTask>)hashTable.get(ClientTaskDispatcher.INTERMEDIATE_TASKS)).addAll(Arrays.asList(pdeDataViewer.getRefreshTasks()));
        // }
        // };
        ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 /*,refreshTask*/
        });
    }
}
Also used : ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) PDEDataContext(cbit.vcell.simdata.PDEDataContext) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) ActionEvent(java.awt.event.ActionEvent) Hashtable(java.util.Hashtable) ExportSpecs(cbit.vcell.export.server.ExportSpecs) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) DataAccessException(org.vcell.util.DataAccessException) UserCancelException(org.vcell.util.UserCancelException) ActionListener(java.awt.event.ActionListener) PDEDataManager(cbit.vcell.simdata.PDEDataManager) ODEDataManager(cbit.vcell.simdata.ODEDataManager) HObject(ncsa.hdf.object.HObject) ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext)

Example 4 with ODEDataManager

use of cbit.vcell.simdata.ODEDataManager in project vcell by virtualcell.

the class SimResultsViewer method createODEDataViewer.

/**
 * Insert the method's description here.
 * Creation date: (6/11/2004 2:33:44 PM)
 * @return javax.swing.JPanel
 * @throws DataAccessException
 */
private DataViewer createODEDataViewer() throws DataAccessException {
    odeDataViewer = new ODEDataViewer();
    odeDataViewer.setSimulation(getSimulation());
    ODESolverResultSet odesrs = ((ODEDataManager) dataManager).getODESolverResultSet();
    odeDataViewer.setOdeSolverResultSet(odesrs);
    odeDataViewer.setNFSimMolecularConfigurations(((ODEDataManager) dataManager).getNFSimMolecularConfigurations());
    odeDataViewer.setVcDataIdentifier(dataManager.getVCDataIdentifier());
    if (getSimulation() != null) {
        String ownerName = generateHDF5DescrOwner(getSimulation());
        odeDataViewer.setHDF5DescriptionText(ownerName + ":" + simulation.getName());
    }
    // odeDataViewer.setXVarName(odeDataViewer.getODESolverPlotSpecificationPanel1().getXAxisComboBox_frm().getSelectedItem().toString());
    // 
    // Example code for reading stats data from Stochastic multitrial non-histogram
    // 
    FileFormat hdf5FileFormat = null;
    File to = null;
    try {
        if (odeDataViewer.getOdeSolverResultSet() instanceof ODESimData) {
            byte[] hdf5FileBytes = ((ODESimData) odeDataViewer.getOdeSolverResultSet()).getHdf5FileBytes();
            if (hdf5FileBytes != null) {
                to = File.createTempFile("odeStats_" + getSimulation().getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), ".hdf5");
                Files.write(hdf5FileBytes, to);
                FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
                if (fileFormat == null) {
                    throw new Exception("Cannot find HDF5 FileFormat.");
                }
                // open the file with read-only access
                hdf5FileFormat = fileFormat.createInstance(to.getAbsolutePath(), FileFormat.READ);
                // open the file and retrieve the file structure
                hdf5FileFormat.open();
                Group root = (Group) ((javax.swing.tree.DefaultMutableTreeNode) hdf5FileFormat.getRootNode()).getUserObject();
                List<HObject> postProcessMembers = ((Group) root).getMemberList();
                for (HObject nextHObject : postProcessMembers) {
                    // System.out.println(nextHObject.getName()+"\n"+nextHObject.getClass().getName());
                    H5ScalarDS h5ScalarDS = (H5ScalarDS) nextHObject;
                    h5ScalarDS.init();
                    try {
                        long[] dims = h5ScalarDS.getDims();
                        System.out.println("---" + nextHObject.getName() + " " + nextHObject.getClass().getName() + " Dimensions=" + Arrays.toString(dims));
                        Object obj = h5ScalarDS.read();
                        if (dims.length == 2) {
                            // dims[0]=numTimes (will be the same as 'SimTimes' data length)
                            // dims[1]=numVars (will be the same as 'VarNames' data length)
                            // if name='StatMean' this is the same as the default data saved in the odeSolverresultSet
                            double[] columns = new double[(int) dims[1]];
                            for (int row = 0; row < dims[0]; row++) {
                                System.arraycopy(obj, row * columns.length, columns, 0, columns.length);
                                System.out.println(Arrays.toString(columns));
                            }
                        } else {
                            if (obj instanceof double[]) {
                                System.out.println(Arrays.toString((double[]) obj));
                            } else {
                                System.out.println(Arrays.toString((String[]) obj));
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (hdf5FileFormat != null) {
            try {
                hdf5FileFormat.close();
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        if (to != null) {
            try {
                to.delete();
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
    return odeDataViewer;
}
Also used : Group(ncsa.hdf.object.Group) HObject(ncsa.hdf.object.HObject) ODESimData(cbit.vcell.solver.ode.ODESimData) H5ScalarDS(ncsa.hdf.object.h5.H5ScalarDS) FileFormat(ncsa.hdf.object.FileFormat) DataAccessException(org.vcell.util.DataAccessException) UserCancelException(org.vcell.util.UserCancelException) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODEDataManager(cbit.vcell.simdata.ODEDataManager) HObject(ncsa.hdf.object.HObject) File(java.io.File)

Example 5 with ODEDataManager

use of cbit.vcell.simdata.ODEDataManager in project vcell by virtualcell.

the class MergedDatasetViewer method createDataViewer.

/**
 * Insert the method's description here.
 * Creation date: (6/11/2004 2:33:44 PM)
 * @return javax.swing.JPanel
 */
private DataViewer createDataViewer() {
    try {
        if (isODEData) {
            ODEDataManager odeDataManager = (ODEDataManager) dataManager;
            odeDataViewer = new ODEDataViewer();
            odeDataViewer.setOdeSolverResultSet(odeDataManager.getODESolverResultSet());
            odeDataViewer.setVcDataIdentifier(dataManager.getVCDataIdentifier());
            return odeDataViewer;
        } else {
            PDEDataManager pdeDataManager = (PDEDataManager) dataManager;
            pdeDataViewer = new PDEDataViewer();
            pdeDataViewer.setPdeDataContext(pdeDataManager.getPDEDataContext());
            return pdeDataViewer;
        }
    } catch (org.vcell.util.DataAccessException exc) {
        DialogUtils.showErrorDialog(this, "Could not fetch requested data.\nJCompare may have failed.\n" + exc.getMessage());
        exc.printStackTrace();
    }
    return null;
}
Also used : PDEDataManager(cbit.vcell.simdata.PDEDataManager) ODEDataManager(cbit.vcell.simdata.ODEDataManager) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

ODEDataManager (cbit.vcell.simdata.ODEDataManager)7 PDEDataManager (cbit.vcell.simdata.PDEDataManager)4 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)4 ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)4 DataAccessException (org.vcell.util.DataAccessException)4 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)3 UserCancelException (org.vcell.util.UserCancelException)3 BioModel (cbit.vcell.biomodel.BioModel)2 DataManager (cbit.vcell.simdata.DataManager)2 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)2 Hashtable (java.util.Hashtable)2 HObject (ncsa.hdf.object.HObject)2 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)2 Plot2D (cbit.plot.Plot2D)1 PlotData (cbit.plot.PlotData)1 SingleXPlot2D (cbit.plot.SingleXPlot2D)1 ChildWindow (cbit.vcell.client.ChildWindowManager.ChildWindow)1 DataViewer (cbit.vcell.client.data.DataViewer)1 DataViewerController (cbit.vcell.client.data.DataViewerController)1 SimResultsViewer (cbit.vcell.client.data.SimResultsViewer)1