Search in sources :

Example 1 with SimulationOwner

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);
    }
}
Also used : SimulationOwner(cbit.vcell.solver.SimulationOwner) Issue(org.vcell.util.Issue) OutputFunctionIssueSource(cbit.vcell.solver.OutputFunctionContext.OutputFunctionIssueSource) SimulationContext(cbit.vcell.mapping.SimulationContext)

Example 2 with SimulationOwner

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);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) SimulationTask(cbit.vcell.messaging.server.SimulationTask) SmoldynFileWriter(org.vcell.solver.smoldyn.SmoldynFileWriter) SimulationOwner(cbit.vcell.solver.SimulationOwner) ProgressDialogListener(org.vcell.util.ProgressDialogListener) SimulationJob(cbit.vcell.solver.SimulationJob) PrintWriter(java.io.PrintWriter) InputStreamReader(java.io.InputStreamReader) Hashtable(java.util.Hashtable) InputStream(java.io.InputStream) TempSimulation(cbit.vcell.solver.TempSimulation) SimulationContext(cbit.vcell.mapping.SimulationContext) EventObject(java.util.EventObject) Simulation(cbit.vcell.solver.Simulation) TempSimulation(cbit.vcell.solver.TempSimulation) EventObject(java.util.EventObject) File(java.io.File)

Example 3 with SimulationOwner

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;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) Variable(cbit.vcell.math.Variable) VariableType(cbit.vcell.math.VariableType) MathDescription(cbit.vcell.math.MathDescription) SurfaceClass(cbit.vcell.geometry.SurfaceClass) ArrayList(java.util.ArrayList) SimulationOwner(cbit.vcell.solver.SimulationOwner) Function(cbit.vcell.math.Function) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) SubVolume(cbit.vcell.geometry.SubVolume) HashSet(java.util.HashSet)

Example 4 with SimulationOwner

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);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) SmoldynSolver(org.vcell.solver.smoldyn.SmoldynSolver) Solver(cbit.vcell.solver.server.Solver) SimulationTask(cbit.vcell.messaging.server.SimulationTask) ArrayList(java.util.ArrayList) SimulationOwner(cbit.vcell.solver.SimulationOwner) DataProcessingInstructions(cbit.vcell.solver.DataProcessingInstructions) SolverListener(cbit.vcell.solver.server.SolverListener) SolverStatus(cbit.vcell.solver.server.SolverStatus) SimulationJob(cbit.vcell.solver.SimulationJob) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) Hashtable(java.util.Hashtable) TempSimulation(cbit.vcell.solver.TempSimulation) SimulationContext(cbit.vcell.mapping.SimulationContext) OutputContext(cbit.vcell.simdata.OutputContext) SolverEvent(cbit.vcell.solver.server.SolverEvent) Simulation(cbit.vcell.solver.Simulation) TempSimulation(cbit.vcell.solver.TempSimulation) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) SmoldynSolver(org.vcell.solver.smoldyn.SmoldynSolver) EventObject(java.util.EventObject) File(java.io.File)

Example 5 with SimulationOwner

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);
}
Also used : Window(java.awt.Window) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) TopLevelWindowManager(cbit.vcell.client.TopLevelWindowManager) Hashtable(java.util.Hashtable) ClientDocumentManager(cbit.vcell.clientdb.ClientDocumentManager) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) LocalVCSimulationDataIdentifier(cbit.vcell.client.ClientSimManager.LocalVCSimulationDataIdentifier) OutputContext(cbit.vcell.simdata.OutputContext) SimulationOwner(cbit.vcell.solver.SimulationOwner) PDEDataManager(cbit.vcell.simdata.PDEDataManager) BioModel(cbit.vcell.biomodel.BioModel) ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) Vector(java.util.Vector) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Aggregations

SimulationOwner (cbit.vcell.solver.SimulationOwner)9 SimulationContext (cbit.vcell.mapping.SimulationContext)4 Simulation (cbit.vcell.solver.Simulation)4 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)3 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)3 Hashtable (java.util.Hashtable)3 MathDescription (cbit.vcell.math.MathDescription)2 SimulationTask (cbit.vcell.messaging.server.SimulationTask)2 OutputContext (cbit.vcell.simdata.OutputContext)2 UnitInfo (cbit.vcell.solver.SimulationOwner.UnitInfo)2 BioModel (cbit.vcell.biomodel.BioModel)1 LocalVCSimulationDataIdentifier (cbit.vcell.client.ClientSimManager.LocalVCSimulationDataIdentifier)1 TopLevelWindowManager (cbit.vcell.client.TopLevelWindowManager)1 DecoratedIssueSource (cbit.vcell.client.desktop.DecoratedIssueSource)1 ActiveView (cbit.vcell.client.desktop.biomodel.SelectionManager.ActiveView)1 ClientDocumentManager (cbit.vcell.clientdb.ClientDocumentManager)1 FieldDataIdentifierSpec (cbit.vcell.field.FieldDataIdentifierSpec)1 ChomboInvalidGeometryException (cbit.vcell.geometry.ChomboInvalidGeometryException)1 Geometry (cbit.vcell.geometry.Geometry)1 GeometryClass (cbit.vcell.geometry.GeometryClass)1