Search in sources :

Example 6 with SimulationTask

use of cbit.vcell.messaging.server.SimulationTask in project vcell by virtualcell.

the class NfsimExtensionFilter method writeBioModel.

@Override
public void writeBioModel(DocumentManager documentManager, BioModel bioModel, File exportFile, SimulationContext simulationContext) throws Exception {
    // TODO: get the first thing we find for now, in the future we'll need to modify ChooseFile
    // to only offer the applications / simulations with bngl content
    // This should be done by creating one or more additional Selector values and add the filtering logic to ChooseFile
    SimulationContext[] simContexts = bioModel.getSimulationContexts();
    Simulation selectedSim = simulationContext.getSimulations(0);
    // Simulation selectedSim = (Simulation)hashTable.get("selectedSimulation");
    SimulationTask simTask = new SimulationTask(new SimulationJob(selectedSim, 0, null), 0);
    // a fixed seed will allow us to run reproducible simulations
    long randomSeed = 0;
    // long randomSeed = System.currentTimeMillis();
    NFsimSimulationOptions nfsimSimulationOptions = new NFsimSimulationOptions();
    // we get the data we need from the math description
    boolean bUseLocationMarks = true;
    Element root = NFsimXMLWriter.writeNFsimXML(simTask, randomSeed, nfsimSimulationOptions, bUseLocationMarks);
    Document doc = new Document();
    doc.setRootElement(root);
    XMLOutputter xmlOut = new XMLOutputter();
    String resultString = xmlOut.outputString(doc);
    FileUtils.writeStringToFile(exportFile, resultString);
}
Also used : NFsimSimulationOptions(cbit.vcell.solver.NFsimSimulationOptions) XMLOutputter(org.jdom.output.XMLOutputter) SimulationTask(cbit.vcell.messaging.server.SimulationTask) Simulation(cbit.vcell.solver.Simulation) Element(org.jdom.Element) SimulationContext(cbit.vcell.mapping.SimulationContext) Document(org.jdom.Document) SimulationJob(cbit.vcell.solver.SimulationJob)

Example 7 with SimulationTask

use of cbit.vcell.messaging.server.SimulationTask in project vcell by virtualcell.

the class SmoldynExtensionFilter method writeBioModel.

@Override
public void writeBioModel(DocumentManager documentManager, BioModel bioModel, File exportFile, SimulationContext ignored) throws Exception {
    Objects.requireNonNull(selectedSim);
    int scanCount = selectedSim.getScanCount();
    if (// has parameter scan
    scanCount > 1) {
        String baseExportFileName = exportFile.getPath().substring(0, exportFile.getPath().indexOf("."));
        for (int i = 0; i < scanCount; i++) {
            SimulationTask simTask = new SimulationTask(new SimulationJob(selectedSim, i, null), 0);
            // Need to export each parameter scan into a separate file
            String newExportFileName = baseExportFileName + "_" + i + SMOLDYN_INPUT_FILE_EXTENSION;
            exportFile = new File(newExportFileName);
            PrintWriter pw = new PrintWriter(exportFile);
            SmoldynFileWriter smf = new SmoldynFileWriter(pw, true, null, simTask, false);
            smf.write();
            pw.close();
        }
    } else if (// regular simulation, no parameter scan
    scanCount == 1) {
        SimulationTask simTask = new SimulationTask(new SimulationJob(selectedSim, 0, null), 0);
        // export the simulation to the selected file
        PrintWriter pw = new PrintWriter(exportFile);
        SmoldynFileWriter smf = new SmoldynFileWriter(pw, true, null, simTask, false);
        smf.write();
        pw.close();
    } else {
        throw new Exception("Simulation scan count is smaller than 1.");
    }
}
Also used : SimulationTask(cbit.vcell.messaging.server.SimulationTask) SmoldynFileWriter(org.vcell.solver.smoldyn.SmoldynFileWriter) File(java.io.File) SimulationJob(cbit.vcell.solver.SimulationJob) UserCancelException(org.vcell.util.UserCancelException) PrintWriter(java.io.PrintWriter)

Example 8 with SimulationTask

use of cbit.vcell.messaging.server.SimulationTask in project vcell by virtualcell.

the class LocalSolverController method solverStarting.

/**
 * Invoked when the solver begins a calculation.
 * @param event indicates the solver and the event type
 */
public void solverStarting(SolverEvent event) {
    try {
        if (lg.isTraceEnabled())
            lg.trace("LocalSolverController Caught solverStarting(" + event.getSource().toString() + ")");
        if (serialParameterScanJobIndex >= 0) {
            SimulationTask newSimTask = new SimulationTask(new SimulationJob(getSimulationTask().getSimulation(), serialParameterScanJobIndex, getSimulationTask().getSimulationJob().getFieldDataIdentifierSpecs()), getSimulationTask().getTaskID());
            fireWorkerEvent(new WorkerEvent(WorkerEvent.JOB_STARTING, this, newSimTask, hostname, event.getSimulationMessage()));
        } else {
            fireWorkerEvent(new WorkerEvent(WorkerEvent.JOB_STARTING, this, getSimulationTask(), hostname, event.getSimulationMessage()));
        }
    } catch (Throwable e) {
        lg.error(e.getMessage(), e);
    }
}
Also used : SimulationTask(cbit.vcell.messaging.server.SimulationTask) WorkerEvent(cbit.rmi.event.WorkerEvent) SimulationJob(cbit.vcell.solver.SimulationJob)

Example 9 with SimulationTask

use of cbit.vcell.messaging.server.SimulationTask in project vcell by virtualcell.

the class LocalSolverController method solverProgress.

/**
 * Invoked when the solver stores values in the result set.
 * @param event indicates the solver and the event type
 */
public void solverProgress(SolverEvent event) {
    try {
        // don't log progress and data events
        if (System.currentTimeMillis() - timeOfLastProgressMessage > 1000 * getMessagingInterval()) {
            if (serialParameterScanJobIndex >= 0) {
                SimulationTask newSimTask = new SimulationTask(new SimulationJob(getSimulationTask().getSimulation(), serialParameterScanJobIndex, getSimulationTask().getSimulationJob().getFieldDataIdentifierSpecs()), getSimulationTask().getTaskID());
                fireWorkerEvent(new WorkerEvent(WorkerEvent.JOB_PROGRESS, this, newSimTask, hostname, new Double(event.getProgress()), new Double(event.getTimePoint()), event.getSimulationMessage()));
                if (event.getProgress() >= 1) {
                    fireWorkerEvent(new WorkerEvent(WorkerEvent.JOB_COMPLETED, this, newSimTask, hostname, new Double(event.getProgress()), new Double(event.getTimePoint()), SimulationMessage.MESSAGE_JOB_COMPLETED));
                    serialParameterScanJobIndex++;
                }
            } else {
                fireWorkerEvent(new WorkerEvent(WorkerEvent.JOB_PROGRESS, this, getSimulationTask(), hostname, new Double(event.getProgress()), new Double(event.getTimePoint()), event.getSimulationMessage()));
            }
        }
    } catch (Throwable e) {
        lg.error(e.getMessage(), e);
    }
}
Also used : SimulationTask(cbit.vcell.messaging.server.SimulationTask) WorkerEvent(cbit.rmi.event.WorkerEvent) SimulationJob(cbit.vcell.solver.SimulationJob)

Example 10 with SimulationTask

use of cbit.vcell.messaging.server.SimulationTask in project vcell by virtualcell.

the class LocalSolverController method solverFinished.

/**
 * Invoked when the solver finishes a calculation (normal termination).
 * @param event indicates the solver and the event type
 */
public void solverFinished(SolverEvent event) {
    try {
        if (lg.isTraceEnabled())
            lg.trace("LocalSolverController Caught solverFinished(" + event.getSource().toString() + ")");
        SimulationJob simJob = getSimulationTask().getSimulationJob();
        if (serialParameterScanJobIndex >= 0) {
            SimulationTask newSimTask = new SimulationTask(new SimulationJob(simJob.getSimulation(), serialParameterScanJobIndex, simJob.getFieldDataIdentifierSpecs()), getSimulationTask().getTaskID());
            fireWorkerEvent(new WorkerEvent(WorkerEvent.JOB_COMPLETED, this, newSimTask, hostname, new Double(event.getProgress()), new Double(event.getTimePoint()), event.getSimulationMessage()));
        } else {
            fireWorkerEvent(new WorkerEvent(WorkerEvent.JOB_COMPLETED, this, getSimulationTask(), hostname, new Double(event.getProgress()), new Double(event.getTimePoint()), event.getSimulationMessage()));
        }
    } catch (Throwable e) {
        lg.error(e.getMessage(), e);
    }
}
Also used : SimulationTask(cbit.vcell.messaging.server.SimulationTask) WorkerEvent(cbit.rmi.event.WorkerEvent) SimulationJob(cbit.vcell.solver.SimulationJob)

Aggregations

SimulationTask (cbit.vcell.messaging.server.SimulationTask)34 SimulationJob (cbit.vcell.solver.SimulationJob)26 File (java.io.File)17 Simulation (cbit.vcell.solver.Simulation)15 IOException (java.io.IOException)13 SolverStatus (cbit.vcell.solver.server.SolverStatus)11 XmlParseException (cbit.vcell.xml.XmlParseException)8 FieldDataIdentifierSpec (cbit.vcell.field.FieldDataIdentifierSpec)7 SimulationContext (cbit.vcell.mapping.SimulationContext)7 ExpressionException (cbit.vcell.parser.ExpressionException)7 SolverException (cbit.vcell.solver.SolverException)7 FVSolverStandalone (cbit.vcell.solvers.FVSolverStandalone)7 PrintWriter (java.io.PrintWriter)7 UserCancelException (org.vcell.util.UserCancelException)7 TempSimulation (cbit.vcell.solver.TempSimulation)6 MathDescription (cbit.vcell.math.MathDescription)5 Variable (cbit.vcell.math.Variable)5 DataAccessException (org.vcell.util.DataAccessException)5 ImageException (cbit.image.ImageException)4 ODESimData (cbit.vcell.solver.ode.ODESimData)4