use of cbit.vcell.solver.SimulationJob 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);
}
use of cbit.vcell.solver.SimulationJob 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.");
}
}
use of cbit.vcell.solver.SimulationJob 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);
}
}
use of cbit.vcell.solver.SimulationJob 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);
}
}
use of cbit.vcell.solver.SimulationJob 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);
}
}
Aggregations