use of cbit.vcell.solver.SimulationOwner in project vcell by virtualcell.
the class DocumentValidUtil method checkIssuesForErrors.
public static void checkIssuesForErrors(Vector<Issue> issueList) {
final int MaxCounter = 5;
String errMsg = "Unable to perform operation. Errors found: \n\n";
boolean bErrorFound = false;
int counter = 0;
for (int i = 0; i < issueList.size(); i++) {
Issue issue = issueList.elementAt(i);
if (issue.getSeverity() == Issue.Severity.ERROR) {
bErrorFound = true;
Object issueSource = issue.getSource();
if (!(issueSource instanceof OutputFunctionIssueSource)) {
if (counter >= MaxCounter) {
// We display MaxCounter error issues
errMsg += "\n...and more.\n";
break;
}
errMsg += issue.getMessage() + "\n";
counter++;
}
}
}
for (int i = 0; i < issueList.size(); i++) {
Issue issue = issueList.elementAt(i);
if (issue.getSeverity() == Issue.Severity.ERROR) {
bErrorFound = true;
Object issueSource = issue.getSource();
if (issueSource instanceof OutputFunctionIssueSource) {
SimulationOwner simulationOwner = ((OutputFunctionIssueSource) issueSource).getOutputFunctionContext().getSimulationOwner();
String funcName = ((OutputFunctionIssueSource) issueSource).getAnnotatedFunction().getDisplayName();
if (simulationOwner instanceof SimulationContext) {
String opErrMsg = "Output Function '" + funcName + "' in application '" + simulationOwner.getName() + "' ";
if (issue.getCategory().equals(IssueCategory.OUTPUTFUNCTIONCONTEXT_FUNCTION_EXPBINDING)) {
opErrMsg += "refers to an unknown variable. Either the model changed or this version of VCell generates variable names differently.\n";
}
errMsg += opErrMsg;
}
errMsg += issue.getMessage() + "\n";
// we display no more than 1 issue of this type because it may get very verbose
break;
}
}
}
if (bErrorFound) {
errMsg += "\n See the Problems panel for a full list of errors and detailed error information.";
throw new RuntimeException(errMsg);
}
}
use of cbit.vcell.solver.SimulationOwner in project vcell by virtualcell.
the class ClientSimManager method runSmoldynParticleView.
public void runSmoldynParticleView(final Simulation originalSimulation) {
SimulationOwner simulationOwner = simWorkspace.getSimulationOwner();
Collection<AsynchClientTask> tasks;
if (simulationOwner instanceof SimulationContext) {
tasks = ClientRequestManager.updateMath(documentWindowManager.getComponent(), (SimulationContext) simulationOwner, false, NetworkGenerationRequirements.ComputeFullStandardTimeout);
} else {
tasks = new ArrayList<>();
}
AsynchClientTask pv = new AsynchClientTask("starting particle view", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
File[] exes = SolverUtilities.getExes(SolverDescription.Smoldyn);
assert exes.length == 1 : "one and only one smoldyn solver expected";
File smoldynExe = exes[0];
Simulation simulation = new TempSimulation(originalSimulation, false);
SimulationTask simTask = new SimulationTask(new SimulationJob(simulation, 0, null), 0);
File inputFile = new File(ResourceUtil.getLocalSimDir(User.tempUser.getName()), simTask.getSimulationJobID() + SimDataConstants.SMOLDYN_INPUT_FILE_EXTENSION);
inputFile.deleteOnExit();
PrintWriter pw = new PrintWriter(inputFile);
SmoldynFileWriter smf = new SmoldynFileWriter(pw, true, null, simTask, false);
smf.write();
pw.close();
String[] cmd = new String[] { smoldynExe.getAbsolutePath(), inputFile.getAbsolutePath() };
StringBuilder commandLine = new StringBuilder();
for (int i = 0; i < cmd.length; i++) {
if (i > 0) {
commandLine.append(" ");
}
commandLine.append(TokenMangler.getEscapedPathName(cmd[i]));
}
System.out.println(commandLine);
char[] charArrayOut = new char[10000];
char[] charArrayErr = new char[10000];
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
final Process process = processBuilder.start();
getClientTaskStatusSupport().addProgressDialogListener(new ProgressDialogListener() {
public void cancelButton_actionPerformed(EventObject newEvent) {
process.destroy();
}
});
InputStream errorStream = process.getErrorStream();
InputStreamReader errisr = new InputStreamReader(errorStream);
InputStream outputStream = process.getInputStream();
InputStreamReader outisr = new InputStreamReader(outputStream);
StringBuilder sb = new StringBuilder();
boolean running = true;
while (running) {
try {
process.exitValue();
running = false;
} catch (IllegalThreadStateException e) {
// process didn't exit yet, do nothing
}
if (outputStream.available() > 0) {
outisr.read(charArrayOut, 0, charArrayOut.length);
}
if (errorStream.available() > 0) {
errisr.read(charArrayErr, 0, charArrayErr.length);
sb.append(new String(charArrayErr));
}
}
if (sb.length() > 0) {
throw new RuntimeException(sb.toString());
}
}
};
tasks.add(pv);
ClientTaskDispatcher.dispatchColl(documentWindowManager.getComponent(), new Hashtable<String, Object>(), tasks, false, true, null);
}
use of cbit.vcell.solver.SimulationOwner in project vcell by virtualcell.
the class OutputFunctionsPanel method getPossibleGeometryClassesAndVariableTypes.
private ArrayList<Object> getPossibleGeometryClassesAndVariableTypes(Expression expr) throws ExpressionException, InconsistentDomainException {
SimulationOwner simulationOwner = getSimulationWorkspace().getSimulationOwner();
MathDescription mathDescription = simulationOwner.getMathDescription();
boolean bSpatial = simulationOwner.getGeometry().getDimension() > 0;
if (!bSpatial) {
return null;
}
// making sure that output function is not direct function of constant.
expr.bindExpression(outputFunctionContext);
// here use math description as symbol table because we allow
// new expression itself to be function of constant.
expr = MathUtilities.substituteFunctions(expr, outputFunctionContext).flatten();
String[] symbols = expr.getSymbols();
// using bit operation to determine whether geometry classes for symbols in expression are vol, membrane or both. 01 => vol; 10 => membrane; 11 => both
int gatherFlag = 0;
Set<GeometryClass> geomClassSet = new HashSet<GeometryClass>();
ArrayList<Object> objectsList = new ArrayList<Object>();
boolean bHasVariable = false;
VariableType[] varTypes = null;
if (symbols != null && symbols.length > 0) {
// making sure that new expression is defined in the same domain
varTypes = new VariableType[symbols.length];
for (int i = 0; i < symbols.length; i++) {
if (ReservedMathSymbolEntries.getReservedVariableEntry(symbols[i]) != null) {
varTypes[i] = VariableType.VOLUME;
} else {
Variable var = mathDescription.getVariable(symbols[i]);
if (var == null) {
var = mathDescription.getPostProcessingBlock().getDataGenerator(symbols[i]);
}
varTypes[i] = VariableType.getVariableType(var);
bHasVariable = true;
if (var.getDomain() != null) {
GeometryClass varGeoClass = simulationOwner.getGeometry().getGeometryClass(var.getDomain().getName());
geomClassSet.add(varGeoClass);
if (varGeoClass instanceof SubVolume) {
gatherFlag |= 1;
} else if (varGeoClass instanceof SurfaceClass) {
gatherFlag |= 2;
}
}
if (varTypes[i].equals(VariableType.POSTPROCESSING)) {
gatherFlag |= 4;
}
}
}
}
if (gatherFlag > 4) {
throw new RuntimeException("cannot mix post processing variables with membrane or volume variables");
}
int numGeomClasses = geomClassSet.size();
if (numGeomClasses == 0) {
if (bHasVariable) {
// if there are no variables (like built in function, vcRegionArea), check with flattened expression to find out the variable type of the new expression
Function flattenedFunction = new Function(getFunctionNameTextField().getText(), expr, null);
flattenedFunction.bind(outputFunctionContext);
VariableType newVarType = SimulationSymbolTable.getFunctionVariableType(flattenedFunction, simulationOwner.getMathDescription(), symbols, varTypes, bSpatial);
objectsList.add(newVarType);
} else {
objectsList.add(VariableType.VOLUME);
objectsList.add(VariableType.MEMBRANE);
}
} else if (numGeomClasses == 1) {
objectsList.add(geomClassSet.iterator().next());
if (gatherFlag == 1) {
objectsList.add(VariableType.MEMBRANE);
}
} else if (gatherFlag == 1) {
// all volumes
if (numGeomClasses == 2) {
// all subvolumes, if there are only 2, check for adjacency.
GeometryClass[] geomClassesArray = geomClassSet.toArray(new GeometryClass[0]);
SurfaceClass sc = simulationOwner.getGeometry().getGeometrySurfaceDescription().getSurfaceClass((SubVolume) geomClassesArray[0], (SubVolume) geomClassesArray[1]);
if (sc != null) {
objectsList.add(sc);
}
}
objectsList.add(VariableType.VOLUME);
} else if (gatherFlag == 2) {
// all membranes
objectsList.add(VariableType.MEMBRANE);
} else if (gatherFlag == 3) {
// mixed - both vols and membranes
// add only membranes?
objectsList.add(VariableType.MEMBRANE);
}
return objectsList;
}
use of cbit.vcell.solver.SimulationOwner in project vcell by virtualcell.
the class ClientSimManager method runQuickSimulation.
public void runQuickSimulation(final Simulation originalSimulation, ViewerType viewerType) {
Collection<AsynchClientTask> taskList = new ArrayList<AsynchClientTask>();
final SimulationOwner simulationOwner = simWorkspace.getSimulationOwner();
// ----------- update math if it is from biomodel (simulationContext)
if (simulationOwner instanceof SimulationContext) {
Collection<AsynchClientTask> ut = ClientRequestManager.updateMath(documentWindowManager.getComponent(), ((SimulationContext) simulationOwner), false, NetworkGenerationRequirements.ComputeFullStandardTimeout);
taskList.addAll(ut);
}
// ----------- run simulation(s)
final File localSimDataDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
AsynchClientTask runSimTask = new AsynchClientTask("running simulation", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Simulation simulation = new TempSimulation(originalSimulation, false);
SimulationTask simTask = new SimulationTask(new SimulationJob(simulation, 0, null), 0);
Solver solver = createQuickRunSolver(localSimDataDir, simTask);
if (solver == null) {
throw new RuntimeException("null solver");
}
// check if spatial stochastic simulation (smoldyn solver) has data processing instructions with field data - need to access server for field data, so cannot do local simulation run.
if (solver instanceof SmoldynSolver) {
DataProcessingInstructions dpi = simulation.getDataProcessingInstructions();
if (dpi != null) {
FieldDataIdentifierSpec fdis = dpi.getSampleImageFieldData(simulation.getVersion().getOwner());
if (fdis != null) {
throw new RuntimeException("Spatial Stochastic simulation '" + simulation.getName() + "' (Smoldyn solver) with field data (in data processing instructions) cannot be run locally at this time since field data needs to be retrieved from the VCell server.");
}
}
}
solver.addSolverListener(new SolverListener() {
public void solverStopped(SolverEvent event) {
getClientTaskStatusSupport().setMessage(event.getSimulationMessage().getDisplayMessage());
}
public void solverStarting(SolverEvent event) {
String displayMessage = event.getSimulationMessage().getDisplayMessage();
System.out.println(displayMessage);
getClientTaskStatusSupport().setMessage(displayMessage);
if (displayMessage.equals(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INIT.getDisplayMessage())) {
getClientTaskStatusSupport().setProgress(75);
} else if (displayMessage.equals(SimulationMessage.MESSAGE_SOLVER_RUNNING_INPUT_FILE.getDisplayMessage())) {
getClientTaskStatusSupport().setProgress(90);
}
}
public void solverProgress(SolverEvent event) {
getClientTaskStatusSupport().setMessage("Running...");
int progress = (int) (event.getProgress() * 100);
getClientTaskStatusSupport().setProgress(progress);
}
public void solverPrinted(SolverEvent event) {
getClientTaskStatusSupport().setMessage("Running...");
}
public void solverFinished(SolverEvent event) {
getClientTaskStatusSupport().setMessage(event.getSimulationMessage().getDisplayMessage());
}
public void solverAborted(SolverEvent event) {
getClientTaskStatusSupport().setMessage(event.getSimulationMessage().getDisplayMessage());
}
});
solver.startSolver();
while (true) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
if (getClientTaskStatusSupport().isInterrupted()) {
solver.stopSolver();
throw UserCancelException.CANCEL_GENERIC;
}
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;
}
}
}
ArrayList<AnnotatedFunction> outputFunctionsList = getSimWorkspace().getSimulationOwner().getOutputFunctionContext().getOutputFunctionsList();
OutputContext outputContext = new OutputContext(outputFunctionsList.toArray(new AnnotatedFunction[outputFunctionsList.size()]));
Simulation[] simsArray = new Simulation[] { simulation };
hashTable.put("outputContext", outputContext);
hashTable.put("simsArray", simsArray);
}
};
taskList.add(runSimTask);
// --------- add tasks from showSimResults : retrieve data, display results
AsynchClientTask[] showResultsTask = showSimulationResults0(true, viewerType);
for (AsynchClientTask task : showResultsTask) {
taskList.add(task);
}
// ------- dispatch
AsynchClientTask[] taskArray = new AsynchClientTask[taskList.size()];
taskList.toArray(taskArray);
ClientTaskDispatcher.dispatch(documentWindowManager.getComponent(), new Hashtable<String, Object>(), taskArray, true, true, null);
}
use of cbit.vcell.solver.SimulationOwner in project vcell by virtualcell.
the class VCellClientDataServiceImpl method displayPostProcessingDataInVCell.
@Override
public void displayPostProcessingDataInVCell(SimulationDataSetRef simulationDataSetRef) throws NumberFormatException, DataAccessException {
User vcUser = vcellClient.getRequestManager().getDocumentManager().getUser();
VCSimulationIdentifier vcSimId = new VCSimulationIdentifier(new KeyValue(simulationDataSetRef.getSimId()), vcUser);
ClientDocumentManager clientDocumentManager = (ClientDocumentManager) vcellClient.getClientServerManager().getDocumentManager();
SimulationOwner simulationOwner = null;
if (simulationDataSetRef.isMathModel) {
simulationOwner = clientDocumentManager.getMathModel(new KeyValue(simulationDataSetRef.getModelId()));
} else {
BioModel bioModel = clientDocumentManager.getBioModel(new KeyValue(simulationDataSetRef.getModelId()));
simulationOwner = bioModel.getSimulationContext(simulationDataSetRef.getSimulationContextName());
}
ArrayList<AnnotatedFunction> outputFunctionsList = simulationOwner.getOutputFunctionContext().getOutputFunctionsList();
OutputContext outputContext = new OutputContext(outputFunctionsList.toArray(new AnnotatedFunction[outputFunctionsList.size()]));
VCSimulationDataIdentifier vcSimDataId = new VCSimulationDataIdentifier(vcSimId, simulationDataSetRef.getJobIndex());
PDEDataManager pdeDataManager = (PDEDataManager) vcellClient.getRequestManager().getDataManager(outputContext, vcSimDataId, true);
final ClientPDEDataContext newClientPDEDataContext = pdeDataManager.getPDEDataContext();
// this was the code before the windows refactoring; appears to just always get the first window???
// Enumeration<TopLevelWindowManager> windowManagers = vcellClient.getMdiManager().getWindowManagers();
// final Window window = FindWindow.getWindow(windowManagers.nextElement().getComponent());
Optional<TopLevelWindowManager> first = vcellClient.getMdiManager().getWindowManagers().stream().findFirst();
VCAssert.assertTrue(first.isPresent(), "window manager not present?");
final Window window = getWindow(first.get().getComponent());
AsynchClientTask task = new AsynchClientTask("Display Post Processing Statistics", AsynchClientTask.TASKTYPE_SWING_NONBLOCKING, false, false) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
DataProcessingResultsPanel dataProcessingResultsPanel = new DataProcessingResultsPanel();
dataProcessingResultsPanel.update(newClientPDEDataContext);
DialogUtils.showComponentOKCancelDialog(window, dataProcessingResultsPanel, "Post Processing Statistics");
}
};
Hashtable<String, Object> hash = new Hashtable<String, Object>();
Vector<AsynchClientTask> tasksV = new Vector<AsynchClientTask>();
tasksV.add(task);
AsynchClientTask[] tasks = new AsynchClientTask[tasksV.size()];
tasksV.copyInto(tasks);
ClientTaskDispatcher.dispatch(window, hash, tasks, true);
}
Aggregations