Search in sources :

Example 1 with VariableInfo

use of org.vcell.sbmlsim.api.common.VariableInfo in project vcell by virtualcell.

the class SimulationServiceImpl method getVariableList.

@Override
public List<VariableInfo> getVariableList(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);
        OutputContext outputContext = new OutputContext(new AnnotatedFunction[0]);
        final DataIdentifier[] dataIdentifiers;
        try {
            dataIdentifiers = datasetController.getDataIdentifiers(outputContext, simServiceContext.vcDataIdentifier);
        } catch (IOException | DataAccessException e) {
            e.printStackTrace();
            throw new RuntimeException("failed to retrieve variable information: " + e.getMessage(), e);
        }
        ArrayList<VariableInfo> varInfos = new ArrayList<VariableInfo>();
        for (DataIdentifier dataIdentifier : dataIdentifiers) {
            final DomainType domainType;
            if (dataIdentifier.getVariableType().equals(VariableType.VOLUME)) {
                domainType = DomainType.VOLUME;
            } else if (dataIdentifier.getVariableType().equals(VariableType.MEMBRANE)) {
                domainType = DomainType.MEMBRANE;
            } else {
                continue;
            }
            String domainName = "";
            if (dataIdentifier.getDomain() != null) {
                domainName = dataIdentifier.getDomain().getName();
            }
            VariableInfo varInfo = new VariableInfo(dataIdentifier.getName(), dataIdentifier.getDisplayName(), domainName, domainType);
            varInfos.add(varInfo);
        }
        return varInfos;
    } catch (Exception e) {
        e.printStackTrace();
        throw new Exception("failed to retrieve variable list: " + e.getMessage());
    }
}
Also used : VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) VariableInfo(org.vcell.sbmlsim.api.common.VariableInfo) ArrayList(java.util.ArrayList) IOException(java.io.IOException) XMLStreamException(javax.xml.stream.XMLStreamException) SbmlException(org.vcell.sbml.SbmlException) SBMLException(org.sbml.jsbml.SBMLException) XmlParseException(cbit.vcell.xml.XmlParseException) SolverException(cbit.vcell.solver.SolverException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) OutputContext(cbit.vcell.simdata.OutputContext) DomainType(org.vcell.sbmlsim.api.common.DomainType) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) DataAccessException(org.vcell.util.DataAccessException)

Example 2 with VariableInfo

use of org.vcell.sbmlsim.api.common.VariableInfo 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 VariableInfo

use of org.vcell.sbmlsim.api.common.VariableInfo in project vcell by virtualcell.

the class VCellSbmlSimCLI method process_simdata.

private void process_simdata() 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");
    }
    VariableInfo varInfo = null;
    if (varinfoJSON != null) {
        try {
            varInfo = gson.fromJson(varinfoJSON, VariableInfo.class);
        } catch (Exception e) {
            throw new CliException("failed to parse JSON text for varInfo: " + e.getMessage(), e);
        }
    } else {
        throw new CliException("varinfo (variableInfo) not specified");
    }
    if (timepointIndex == null) {
        throw new CliException("timepoint index not specified");
    }
    if (outputfile == null) {
        throw new CliException("outputfile not specified");
    }
    SimData simdata = simService.getData(simInfo, varInfo, timepointIndex);
    String simdataJSON = gson.toJson(simdata);
    FileUtils.write(outputfile, simdataJSON);
}
Also used : SimData(org.vcell.sbmlsim.api.common.SimData) VariableInfo(org.vcell.sbmlsim.api.common.VariableInfo) Gson(com.google.gson.Gson) SimulationInfo(org.vcell.sbmlsim.api.common.SimulationInfo)

Aggregations

VariableInfo (org.vcell.sbmlsim.api.common.VariableInfo)3 SimulationInfo (org.vcell.sbmlsim.api.common.SimulationInfo)2 DataIdentifier (cbit.vcell.simdata.DataIdentifier)1 DataSetControllerImpl (cbit.vcell.simdata.DataSetControllerImpl)1 OutputContext (cbit.vcell.simdata.OutputContext)1 SolverException (cbit.vcell.solver.SolverException)1 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)1 XmlParseException (cbit.vcell.xml.XmlParseException)1 Gson (com.google.gson.Gson)1 File (java.io.File)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 Test (org.junit.Test)1 SBMLException (org.sbml.jsbml.SBMLException)1 SbmlException (org.vcell.sbml.SbmlException)1 DomainType (org.vcell.sbmlsim.api.common.DomainType)1 SBMLModel (org.vcell.sbmlsim.api.common.SBMLModel)1