use of org.vcell.sbmlsim.api.common.SimulationInfo in project vcell by virtualcell.
the class VCellSbmlSimCLI method process_timepoints.
private void process_timepoints() throws Exception {
Gson gson = new Gson();
SimulationInfo simInfo = null;
if (simhandle != null) {
simInfo = new SimulationInfo(simhandle);
} else {
throw new CliException("simhandle (simulation handle) not specified");
}
if (outputfile == null) {
throw new CliException("output file not specified");
}
TimePoints timePoints = simService.getTimePoints(simInfo);
String timepointsJSON = gson.toJson(timePoints);
FileUtils.write(outputfile, timepointsJSON);
}
use of org.vcell.sbmlsim.api.common.SimulationInfo in project vcell by virtualcell.
the class VCellSbmlSimCLI method process_status.
private void process_status() throws Exception {
Gson gson = new Gson();
SimulationInfo simInfo = null;
if (simhandle != null) {
simInfo = new SimulationInfo(simhandle);
} else {
throw new CliException("simhandle (simulation handle) not specified");
}
if (outputfile == null) {
throw new CliException("output file not specified");
}
SimulationStatus simstatus = simService.getStatus(simInfo);
String simstatusJSON = gson.toJson(simstatus);
FileUtils.write(outputfile, simstatusJSON);
}
use of org.vcell.sbmlsim.api.common.SimulationInfo in project vcell by virtualcell.
the class VCellSbmlSimCLI method process_submit.
private void process_submit() throws Exception {
Gson gson = new Gson();
SimulationSpec simspec = null;
if (simspecJSON != null) {
try {
simspec = gson.fromJson(simspecJSON, SimulationSpec.class);
} catch (Exception e) {
throw new CliException("failed to parse JSON text for simspec (Simulation Specification): " + e.getMessage(), e);
}
} else {
throw new CliException("simhandle (simulation handle option) not specified");
}
SBMLModel model = null;
if (sbmlfile != null) {
model = new SBMLModel(sbmlfile);
} else {
throw new CliException("sbmlfile (SBML file option) not specified");
}
if (outputfile == null) {
throw new CliException("output file not specified");
}
SimulationInfo siminfo = simService.computeModel(model, simspec);
String siminfoJSON = gson.toJson(siminfo);
FileUtils.write(outputfile, siminfoJSON);
}
use of org.vcell.sbmlsim.api.common.SimulationInfo in project vcell by virtualcell.
the class SimulationServiceImpl method computeModel.
private SimulationInfo computeModel(VCDocument vcDoc, SimulationSpec simSpec, ClientTaskStatusSupport statusCallback) throws Exception {
// try {
Simulation newsim = null;
if (vcDoc instanceof BioModel) {
SimulationContext simContext = ((BioModel) vcDoc).getSimulationContext(0);
MathMappingCallback callback = new MathMappingCallbackTaskAdapter(statusCallback);
newsim = simContext.addNewSimulation(SimulationOwner.DEFAULT_SIM_NAME_PREFIX, callback, NetworkGenerationRequirements.AllowTruncatedStandardTimeout);
} else if (vcDoc instanceof MathModel) {
newsim = ((MathModel) vcDoc).addNewSimulation(SimulationOwner.DEFAULT_SIM_NAME_PREFIX);
} else {
throw new IllegalArgumentException("computeModel expecting BioModel or MathModel but got " + vcDoc.getClass().getName());
}
GeometrySpec geometrySpec = newsim.getMathDescription().getGeometry().getGeometrySpec();
VCImage image = geometrySpec.getImage();
if (image != null) {
newsim.getMeshSpecification().setSamplingSize(new ISize(image.getNumX(), image.getNumY(), image.getNumZ()));
}
// newsim.getMeshSpecification().setSamplingSize(new ISize(simContext.getGeometry().getGeometrySpec().getImage().getNumX(), simContext.getGeometry().getGeometrySpec().getImage().getNumY(), simContext.getGeometry().getGeometrySpec().getImage().getNumZ()));
newsim.getSolverTaskDescription().setTimeBounds(new TimeBounds(0, simSpec.getTotalTime()));
newsim.getSolverTaskDescription().setOutputTimeSpec(new UniformOutputTimeSpec(simSpec.getOutputTimeStep()));
SimulationInfo simulationInfo = new SimulationInfo(Math.abs(new Random().nextInt(1000000)));
// ----------- run simulation(s)
final File localSimDataDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
Simulation simulation = new TempSimulation(newsim, false);
final SimulationServiceContext simServiceContext = new SimulationServiceContext();
simServiceContext.simInfo = simulationInfo;
simServiceContext.simState = SimulationState.running;
simServiceContext.simTask = new SimulationTask(new SimulationJob(simulation, 0, null), 0);
simServiceContext.vcDataIdentifier = simServiceContext.simTask.getSimulationJob().getVCDataIdentifier();
simServiceContext.solver = createQuickRunSolver(localSimDataDir, simServiceContext.simTask);
simServiceContext.localSimDataDir = localSimDataDir;
if (simServiceContext.solver == null) {
throw new RuntimeException("null solver");
}
sims.put(simulationInfo.getLocalId(), simServiceContext);
simServiceContext.solver.addSolverListener(new SolverListener() {
public void solverStopped(SolverEvent event) {
simServiceContext.simState = SimulationState.failed;
System.err.println("Simulation stopped");
}
public void solverStarting(SolverEvent event) {
simServiceContext.simState = SimulationState.running;
updateStatus(event);
}
public void solverProgress(SolverEvent event) {
simServiceContext.simState = SimulationState.running;
updateStatus(event);
}
public void solverPrinted(SolverEvent event) {
simServiceContext.simState = SimulationState.running;
}
public void solverFinished(SolverEvent event) {
try {
getDataSetController(simServiceContext).getDataSetTimes(simServiceContext.vcDataIdentifier);
simServiceContext.simState = SimulationState.done;
} catch (DataAccessException e) {
simServiceContext.simState = SimulationState.failed;
e.printStackTrace();
}
updateStatus(event);
}
public void solverAborted(SolverEvent event) {
simServiceContext.simState = SimulationState.failed;
System.err.println(event.getSimulationMessage().getDisplayMessage());
}
private void updateStatus(SolverEvent event) {
if (statusCallback == null)
return;
statusCallback.setMessage(event.getSimulationMessage().getDisplayMessage());
statusCallback.setProgress((int) (event.getProgress() * 100));
}
});
if (true) {
// debug
if (vcDoc instanceof BioModel) {
XmlUtil.writeXMLStringToFile(XmlHelper.bioModelToXML(((BioModel) vcDoc)), "C:\\Users\\frm\\vcGititImageJWorkspace\\vcell\\imagej_BM_true.xml", true);
} else if (vcDoc instanceof MathModel) {
XmlUtil.writeXMLStringToFile(XmlHelper.mathModelToXML(((MathModel) vcDoc)), "C:\\Users\\frm\\vcGititImageJWorkspace\\vcell\\imagej_MM_true.xml", true);
}
}
simServiceContext.solver.startSolver();
return simServiceContext.simInfo;
// } catch (Exception e){
// e.printStackTrace(System.out);
// // remember the exceptiopn ... fail the status ... save the error message
// return new SimulationInfo();
// }
}
use of org.vcell.sbmlsim.api.common.SimulationInfo in project vcell by virtualcell.
the class SimulationServiceImplTest method test.
@Test
public void test() throws URISyntaxException, Exception {
SimulationServiceImpl simService = new SimulationServiceImpl();
// TODO - Eliminate code duplication.
URL sbmlFileUrl = SimulationServiceImplTest.class.getResource("../optoPlexin_PRG_rule_based.xml");
File file = new File(sbmlFileUrl.toURI());
VCMongoMessage.enabled = false;
// TODO - Encapsulate this common setup stuff into VCellService initialization.
// Then all VCell-based scripts can focus on the customization below.
System.setProperty(PropertyLoader.installationRoot, new File("..").getAbsolutePath());
ResourceUtil.setNativeLibraryDirectory();
NativeLib.HDF5.load();
file = new File("src/test/resources/org/vcell/sbmlsim/optoPlexin_PRG_rule_based.xml");
Assert.assertTrue(file.exists());
SBMLModel sbmlModel = new SBMLModel(file);
SimulationSpec simSpec = new SimulationSpec();
SimulationInfo simInfo = simService.computeModel(sbmlModel, simSpec);
long timeMS = System.currentTimeMillis();
while (simService.getStatus(simInfo).getSimState() != SimulationState.done && simService.getStatus(simInfo).getSimState() != SimulationState.failed) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
long time2MS = System.currentTimeMillis();
if (time2MS - timeMS > 10000) {
fail("timed out after 10 seconds");
}
}
List<VariableInfo> vars = simService.getVariableList(simInfo);
Assert.assertNotNull(vars);
// TODO - Assert more things.
final TimePoints timePoints = simService.getTimePoints(simInfo);
vars.stream().forEach(var -> {
try {
System.out.println(//
var.getVariableDisplayName() + "[0] = " + simService.getData(simInfo, var, 0));
} catch (Exception exc) {
exc.printStackTrace();
}
});
}
Aggregations