Search in sources :

Example 1 with SimulationSpec

use of org.vcell.sbmlsim.api.common.SimulationSpec 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);
}
Also used : SBMLModel(org.vcell.sbmlsim.api.common.SBMLModel) Gson(com.google.gson.Gson) SimulationSpec(org.vcell.sbmlsim.api.common.SimulationSpec) SimulationInfo(org.vcell.sbmlsim.api.common.SimulationInfo)

Example 2 with SimulationSpec

use of org.vcell.sbmlsim.api.common.SimulationSpec 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();
        }
    });
}
Also used : TimePoints(org.vcell.sbmlsim.api.common.TimePoints) SBMLModel(org.vcell.sbmlsim.api.common.SBMLModel) VariableInfo(org.vcell.sbmlsim.api.common.VariableInfo) File(java.io.File) SimulationSpec(org.vcell.sbmlsim.api.common.SimulationSpec) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) SimulationInfo(org.vcell.sbmlsim.api.common.SimulationInfo) Test(org.junit.Test)

Example 3 with SimulationSpec

use of org.vcell.sbmlsim.api.common.SimulationSpec 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();
        }
    });
}
Also used : TimePoints(org.vcell.sbmlsim.api.common.TimePoints) VariableList(org.vcell.sbmlsim.api.common.VariableList) SBMLModel(org.vcell.sbmlsim.api.common.SBMLModel) File(java.io.File) SimulationSpec(org.vcell.sbmlsim.api.common.SimulationSpec) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test)

Aggregations

SBMLModel (org.vcell.sbmlsim.api.common.SBMLModel)3 SimulationSpec (org.vcell.sbmlsim.api.common.SimulationSpec)3 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 Test (org.junit.Test)2 SimulationInfo (org.vcell.sbmlsim.api.common.SimulationInfo)2 TimePoints (org.vcell.sbmlsim.api.common.TimePoints)2 Gson (com.google.gson.Gson)1 VariableInfo (org.vcell.sbmlsim.api.common.VariableInfo)1 VariableList (org.vcell.sbmlsim.api.common.VariableList)1