Search in sources :

Example 11 with AsynchClientTask

use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.

the class ParameterEstimationRunTaskPanel method solve.

private void solve() throws NumberFormatException {
    CopasiOptimizationMethod com = optimizationMethodParameterTableModel.copasiOptimizationMethod;
    OptimizationSolverSpec optSolverSpec = new OptimizationSolverSpec(com);
    // get num runs for stochstic opt mehtods before starting solving...
    if (com.getType().isStochasticMethod()) {
        int numRuns = Integer.parseInt(((String) numberOfRunComboBox.getSelectedItem()));
        optSolverSpec.setNumOfRuns(numRuns);
    }
    parameterEstimationTask.setOptimizationSolverSpec(optSolverSpec);
    parameterEstimationTask.getModelOptimizationSpec().setComputeProfileDistributions(computeProfileDistributionsCheckBox.isSelected());
    optSolverCallbacks.reset();
    Double endValue = com.getEndValue();
    optSolverCallbacks.setEvaluation(0, Double.POSITIVE_INFINITY, 0, endValue, 0);
    // (endValue != null);
    getRunStatusDialog().showProgressBar(com);
    Collection<AsynchClientTask> taskList = ClientRequestManager.updateMath(this, parameterEstimationTask.getSimulationContext(), false, NetworkGenerationRequirements.ComputeFullStandardTimeout);
    AsynchClientTask task1 = new AsynchClientTask("checking issues", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            StringBuffer issueText = new StringBuffer();
            java.util.Vector<Issue> issueList = new java.util.Vector<Issue>();
            IssueContext issueContext = new IssueContext();
            parameterEstimationTask.gatherIssues(issueContext, issueList);
            boolean bFailed = false;
            for (int i = 0; i < issueList.size(); i++) {
                Issue issue = (Issue) issueList.elementAt(i);
                issueText.append(issue.getMessage() + "\n");
                if (issue.getSeverity() == Issue.SEVERITY_ERROR) {
                    bFailed = true;
                    break;
                }
            }
            if (bFailed) {
                throw new OptimizationException(issueText.toString());
            }
            parameterEstimationTask.refreshMappings();
        }
    };
    taskList.add(task1);
    AsynchClientTask task2 = new AsynchClientTask("solving", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            MathMappingCallback mathMappingCallback = new MathMappingCallbackTaskAdapter(getClientTaskStatusSupport());
            // OptimizationResultSet optResultSet = CopasiOptimizationSolver.solveLocalPython(new ParameterEstimationTaskSimulatorIDA(),parameterEstimationTask,optSolverCallbacks,mathMappingCallback);
            OptimizationResultSet optResultSet = CopasiOptimizationSolver.solveRemoteApi(new ParameterEstimationTaskSimulatorIDA(), parameterEstimationTask, optSolverCallbacks, mathMappingCallback);
            hashTable.put(ORS_KEY, optResultSet);
        }
    };
    taskList.add(task2);
    AsynchClientTask setResultTask = new AsynchClientTask("set results", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            OptimizationResultSet optResultSet = (OptimizationResultSet) hashTable.get(ORS_KEY);
            parameterEstimationTask.setOptimizationResultSet(optResultSet);
        }
    };
    taskList.add(setResultTask);
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), taskList.toArray(new AsynchClientTask[taskList.size()]), getRunStatusDialog(), true, true, true, null, false);
}
Also used : OptimizationException(cbit.vcell.opt.OptimizationException) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Issue(org.vcell.util.Issue) MathMappingCallbackTaskAdapter(cbit.vcell.mapping.MathMappingCallbackTaskAdapter) MathMappingCallback(cbit.vcell.mapping.SimulationContext.MathMappingCallback) Hashtable(java.util.Hashtable) OptimizationResultSet(cbit.vcell.opt.OptimizationResultSet) CopasiOptimizationMethod(cbit.vcell.opt.CopasiOptimizationMethod) IssueContext(org.vcell.util.IssueContext) OptimizationSolverSpec(cbit.vcell.opt.OptimizationSolverSpec) EventObject(java.util.EventObject) ParameterEstimationTaskSimulatorIDA(org.vcell.optimization.ParameterEstimationTaskSimulatorIDA)

Example 12 with AsynchClientTask

use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.

the class ClientRequestManager method createRuleBasedBioModelFromApplication.

public void createRuleBasedBioModelFromApplication(final BioModelWindowManager requester, final String name, final SimulationContext simContext) {
    if (simContext == null) {
        PopupGenerator.showErrorDialog(requester, "Selected Application is null, cannot generate corresponding bio model");
        return;
    }
    AsynchClientTask task1 = new AsynchClientTask("Creating BioModel from BioModel Application", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            MathMappingCallback dummyCallback = new MathMappingCallback() {

                public void setProgressFraction(float percentDone) {
                }

                public void setMessage(String message) {
                }

                public boolean isInterrupted() {
                    return false;
                }
            };
            MathMapping transformedMathMapping = simContext.createNewMathMapping(dummyCallback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
            // simContext.setMathDescription(transformedMathMapping.getMathDescription());
            BioModel newBioModel = new BioModel(null);
            SimulationContext transformedSimContext = transformedMathMapping.getTransformation().transformedSimContext;
            Model model = transformedSimContext.getModel();
            // for(ReactionStep rs : model.getReactionSteps()) {
            // model.removeReactionStep(rs);
            // }
            newBioModel.setModel(model);
            hashTable.put("newBioModel", newBioModel);
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("Creating BioModel from BioModel Application", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            BioModel newBioModel = (BioModel) hashTable.get("newBioModel");
            DocumentWindowManager windowManager = createDocumentWindowManager(newBioModel);
            getMdiManager().createNewDocumentWindow(windowManager);
        }
    };
    ClientTaskDispatcher.dispatch(requester.getComponent(), new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, false);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) MathMappingCallback(cbit.vcell.mapping.SimulationContext.MathMappingCallback) Hashtable(java.util.Hashtable) BioModel(cbit.vcell.biomodel.BioModel) MathMapping(cbit.vcell.mapping.MathMapping) ASTModel(org.vcell.model.bngl.ASTModel) MathModel(cbit.vcell.mathmodel.MathModel) Model(cbit.vcell.model.Model) ListSelectionModel(javax.swing.ListSelectionModel) BioModel(cbit.vcell.biomodel.BioModel) CSGObject(cbit.vcell.geometry.CSGObject) SimulationContext(cbit.vcell.mapping.SimulationContext)

Example 13 with AsynchClientTask

use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.

the class ClientRequestManager method curateDocument.

/**
 * Insert the method's description here.
 * Creation date: (6/22/2004 10:50:34 PM)
 * @param documentInfo cbit.vcell.document.VCDocumentInfo
 */
public void curateDocument(final VCDocumentInfo documentInfo, final int curateType, final TopLevelWindowManager requester) {
    if (documentInfo != null) {
        // see if we have this open
        String documentID = documentInfo.getVersion().getVersionKey().toString();
        if (getMdiManager().haveWindow(documentID)) {
            // already open, refuse
            PopupGenerator.showErrorDialog(requester, "Selected edition is open, cannot " + CurateSpec.CURATE_TYPE_NAMES[curateType]);
            return;
        } else {
            // don't have it open, try to CURATE it
            int confirm = PopupGenerator.showComponentOKCancelDialog(requester.getComponent(), new JTextArea(CurateSpec.CURATE_TYPE_ACTIONS[curateType] + " cannot be undone without VCELL administrative assistance.\n" + CurateSpec.CURATE_TYPE_STATES[curateType] + " versions of documents cannot be deleted without VCELL administrative assistance.\n" + (curateType == CurateSpec.PUBLISH ? CurateSpec.CURATE_TYPE_STATES[curateType] + " versions of documents MUST remain publically accessible to other VCELL users.\n" : "") + "Do you want to " + CurateSpec.CURATE_TYPE_NAMES[curateType] + " document '" + documentInfo.getVersion().getName() + "'" + "\nwith version date '" + documentInfo.getVersion().getDate().toString() + "'?"), "WARNING -- " + CurateSpec.CURATE_TYPE_ACTIONS[curateType] + " operation cannot be undone");
            if (confirm == JOptionPane.OK_OPTION) {
                AsynchClientTask task1 = new AsynchClientTask(CurateSpec.CURATE_TYPE_ACTIONS[curateType] + " document...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

                    @Override
                    public void run(Hashtable<String, Object> hashTable) throws Exception {
                        if (documentInfo instanceof BioModelInfo) {
                            getDocumentManager().curate(new CurateSpec((BioModelInfo) documentInfo, curateType));
                        } else if (documentInfo instanceof MathModelInfo) {
                            getDocumentManager().curate(new CurateSpec((MathModelInfo) documentInfo, curateType));
                        } else {
                            throw new RuntimeException(CurateSpec.CURATE_TYPE_ACTIONS[curateType] + " not supported for VCDocumentInfo type " + documentInfo.getClass().getName());
                        }
                    }
                };
                ClientTaskDispatcher.dispatch(requester.getComponent(), new Hashtable<String, Object>(), new AsynchClientTask[] { task1 }, false);
            } else {
                // user canceled
                return;
            }
        }
    } else {
        // nothing selected
        return;
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) JTextArea(javax.swing.JTextArea) Hashtable(java.util.Hashtable) CurateSpec(org.vcell.util.document.CurateSpec) BioModelInfo(org.vcell.util.document.BioModelInfo) CSGObject(cbit.vcell.geometry.CSGObject) MathModelInfo(org.vcell.util.document.MathModelInfo)

Example 14 with AsynchClientTask

use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.

the class ClientRequestManager method exportDocument.

/**
 * Comment
 */
public void exportDocument(TopLevelWindowManager manager, FileFilter forceFilefilter) {
    /* block window */
    JFrame currentWindow = getMdiManager().blockWindow(manager.getManagerID());
    /* prepare hashtable for tasks */
    Hashtable<String, Object> hash = new Hashtable<String, Object>();
    hash.put("mdiManager", getMdiManager());
    hash.put(DocumentManager.IDENT, getDocumentManager());
    hash.put("topLevelWindowManager", manager);
    hash.put("currentWindow", currentWindow);
    hash.put("userPreferences", getUserPreferences());
    if (forceFilefilter != null) {
        hash.put(ChooseFile.FORCE_FILE_FILTER, forceFilefilter);
    }
    /* create tasks */
    // get document to be exported
    AsynchClientTask documentToExport = new DocumentToExport();
    // get file
    AsynchClientTask chooseFile = new ChooseFile();
    // export it
    AsynchClientTask exportDocument = new ExportDocument();
    // clean-up
    AsynchClientTask finishExport = new FinishExport();
    // assemble array
    AsynchClientTask[] tasks = null;
    tasks = new AsynchClientTask[] { documentToExport, chooseFile, exportDocument, finishExport };
    /* run tasks */
    ClientTaskDispatcher.dispatch(currentWindow, hash, tasks, false);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) JFrame(javax.swing.JFrame) Hashtable(java.util.Hashtable) DocumentToExport(cbit.vcell.client.task.DocumentToExport) CSGObject(cbit.vcell.geometry.CSGObject) ChooseFile(cbit.vcell.client.task.ChooseFile) FinishExport(cbit.vcell.client.task.FinishExport) ExportDocument(cbit.vcell.client.task.ExportDocument)

Example 15 with AsynchClientTask

use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.

the class ClientRequestManager method newDocument.

/**
 * Insert the method's description here.
 * Creation date: (5/21/2004 4:20:47 AM)
 * @param documentType int
 */
public AsynchClientTask[] newDocument(TopLevelWindowManager requester, final VCDocument.DocumentCreationInfo documentCreationInfo) {
    // gcwtodo
    AsynchClientTask createNewDocumentTask = new AsynchClientTask("Creating New Document", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            VCDocument doc = (VCDocument) hashTable.get("doc");
            DocumentWindowManager windowManager = createDocumentWindowManager(doc);
            DocumentWindow dw = getMdiManager().createNewDocumentWindow(windowManager);
            if (windowManager != null) {
                hashTable.put("windowManager", windowManager);
            }
            setFinalWindow(hashTable, dw);
        }
    };
    if (documentCreationInfo.getDocumentType() == VCDocumentType.MATHMODEL_DOC && documentCreationInfo.getOption() == VCDocument.MATH_OPTION_SPATIAL_NEW) {
        final AsynchClientTask createSpatialMathModelTask = new AsynchClientTask("creating mathmodel", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                Geometry geometry = null;
                geometry = (Geometry) hashTable.get("doc");
                MathModel mathModel = createMathModel("Untitled", geometry);
                mathModel.setName("MathModel" + (getMdiManager().getNumCreatedDocumentWindows() + 1));
                hashTable.put("doc", mathModel);
            }
        };
        requester.createGeometry(null, new AsynchClientTask[] { createSpatialMathModelTask, createNewDocumentTask }, "Choose geometry type to start MathModel creation", "Create MathModel", null);
        return null;
    }
    /* asynchronous and not blocking any window */
    AsynchClientTask[] taskArray = null;
    if (documentCreationInfo.getPreCreatedDocument() == null) {
        AsynchClientTask[] taskArray1 = createNewDocument(requester, documentCreationInfo);
        taskArray = new AsynchClientTask[taskArray1.length + 1];
        System.arraycopy(taskArray1, 0, taskArray, 0, taskArray1.length);
    } else {
        taskArray = new AsynchClientTask[2];
        taskArray[0] = new AsynchClientTask("Setting document...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                hashTable.put("doc", documentCreationInfo.getPreCreatedDocument());
            }
        };
    }
    taskArray[taskArray.length - 1] = createNewDocumentTask;
    return taskArray;
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) MathModel(cbit.vcell.mathmodel.MathModel) VCDocument(org.vcell.util.document.VCDocument) Hashtable(java.util.Hashtable) ProgrammingException(org.vcell.util.ProgrammingException) GeometryException(cbit.vcell.geometry.GeometryException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) UtilCancelException(org.vcell.util.UtilCancelException) DataFormatException(java.util.zip.DataFormatException) UserCancelException(org.vcell.util.UserCancelException) DocumentWindow(cbit.vcell.client.desktop.DocumentWindow) Geometry(cbit.vcell.geometry.Geometry) CSGObject(cbit.vcell.geometry.CSGObject)

Aggregations

AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)229 Hashtable (java.util.Hashtable)219 ArrayList (java.util.ArrayList)68 UserCancelException (org.vcell.util.UserCancelException)52 File (java.io.File)35 CSGObject (cbit.vcell.geometry.CSGObject)30 Point (java.awt.Point)23 DataAccessException (org.vcell.util.DataAccessException)22 SimulationContext (cbit.vcell.mapping.SimulationContext)21 FRAPStudy (cbit.vcell.microscopy.FRAPStudy)18 PropertyVetoException (java.beans.PropertyVetoException)18 ImageException (cbit.image.ImageException)17 IOException (java.io.IOException)17 GeometryThumbnailImageFactoryAWT (cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT)14 Vector (java.util.Vector)14 DataFormatException (java.util.zip.DataFormatException)14 UtilCancelException (org.vcell.util.UtilCancelException)14 Geometry (cbit.vcell.geometry.Geometry)12 ActionEvent (java.awt.event.ActionEvent)12 BioModel (cbit.vcell.biomodel.BioModel)11