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);
}
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);
}
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;
}
}
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);
}
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;
}
Aggregations