use of org.vcell.sbmlsim.api.common.TimePoints 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.TimePoints in project vcell by virtualcell.
the class SimulationServiceImpl method getTimePoints.
@Override
public TimePoints getTimePoints(SimulationInfo simInfo) throws Exception {
SimulationServiceContext simServiceContext = sims.get(simInfo.getLocalId());
if (simServiceContext == null) {
throw new Exception("simulation results not found");
}
try {
DataSetControllerImpl datasetController = getDataSetController(simServiceContext);
double[] timeArray = datasetController.getDataSetTimes(simServiceContext.vcDataIdentifier);
TimePoints timePoints = new TimePoints();
timePoints.setTimePoints(timeArray);
return timePoints;
} catch (Exception e) {
e.printStackTrace();
throw new Exception("failed to retrieve times for simulation: " + e.getMessage());
}
}
use of org.vcell.sbmlsim.api.common.TimePoints 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();
}
});
}
use of org.vcell.sbmlsim.api.common.TimePoints in project vcell by virtualcell.
the class VCellSimServiceTest method test.
@Test
public void test() throws URISyntaxException, Exception {
VCellSimService simService = new VCellSimService();
URL sbmlFileUrl = VCellSimServiceTest.class.getResource("../optoPlexin_PRG_rule_based.xml");
File file = new File(sbmlFileUrl.toURI());
Assert.assertTrue(file.exists());
SBMLModel sbmlModel = new SBMLModel(file);
SimulationSpec simSpec = new SimulationSpec();
SimulationHandle simulationHandle = simService.submit(sbmlModel, simSpec);
long timeMS = System.currentTimeMillis();
while (simService.getStatus(simulationHandle).getSimState() != SimulationState.done && simService.getStatus(simulationHandle).getSimState() != SimulationState.failed) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
long time2MS = System.currentTimeMillis();
if (time2MS - timeMS > 10000) {
fail("timed out after 10 seconds");
}
}
VariableList vars = simService.getVariableList(simulationHandle);
Assert.assertNotNull(vars);
// TODO - Assert more things.
final TimePoints timePoints = simService.getTimePoints(simulationHandle);
Arrays.asList(vars.varInfos).stream().forEach(var -> {
try {
System.out.println(//
var.getVariableDisplayName() + "[0] = " + simService.getSimData(simulationHandle, var, 0));
} catch (Exception exc) {
exc.printStackTrace();
}
});
}
use of org.vcell.sbmlsim.api.common.TimePoints in project vcell by virtualcell.
the class VCellSimService method getTimePoints.
public TimePoints getTimePoints(SimulationHandle simHandle) throws ExecutableException {
Gson gson = new Gson();
Executable exe = new Executable(new String[] { command().getAbsolutePath(), scriptArgDashes + "simhandle", Long.toString(simHandle.remoteId), "timepoints" });
int[] expectedReturnCodes = new int[] { 0 };
exe.start(expectedReturnCodes);
TimePoints timePoints = gson.fromJson(exe.getStdoutString(), TimePoints.class);
return timePoints;
}
Aggregations