Search in sources :

Example 11 with ODESimData

use of cbit.vcell.solver.ode.ODESimData in project vcell by virtualcell.

the class SimulationData method getDataTimes.

/**
 * This method was created in VisualAge.
 * @return double[]
 */
public synchronized double[] getDataTimes() throws DataAccessException {
    if (getIsODEData()) {
        // for ODE's we need to rebuild
        try {
            ODESimData odeSimData = null;
            if (odeIdentifier.equals(ODE_DATA_IDENTIFIER)) {
                odeSimData = ODESimData.readODEDataFile(getODEDataFile());
            } else if (odeIdentifier.equals(IDA_DATA_IDENTIFIER)) {
                odeSimData = ODESimData.readIDADataFile(vcDataId, getODEDataFile(), odeKeepMost, getJobFunctionsFile());
            } else if (odeIdentifier.equals(NETCDF_DATA_IDENTIFIER)) {
                odeSimData = ODESimData.readNCDataFile(vcDataId, getODEDataFile(), getJobFunctionsFile());
            } else {
                throw new DataAccessException("Unexpected data format:" + odeIdentifier);
            }
            if (odeSimData == null) {
                return null;
            }
            int timeIndex = odeSimData.findColumn("t");
            if (timeIndex < 0) {
                // ok, time probably doesn't exist like for a histogram dataset ... just use first index.
                timeIndex = 0;
                LG.warn("cannot find time ('t') column in ODESimData, assuming first column holds the independent variable (maybe not time)");
            }
            dataTimes = odeSimData.extractColumn(timeIndex);
        } catch (ExpressionException e) {
            e.printStackTrace(System.out);
            throw new DataAccessException("error getting dataset times: " + e.getMessage());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            throw new DataAccessException("error getting dataset times: " + e.getMessage());
        }
    }
    return dataTimes;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) ODESimData(cbit.vcell.solver.ode.ODESimData) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 12 with ODESimData

use of cbit.vcell.solver.ode.ODESimData in project vcell by virtualcell.

the class NagiosVCellCheck method checkVCell.

private static String checkVCell(VCELL_CHECK_LEVEL checkLevel, String rmiHostName, int rmiPort, String rmiBootstrapStubName, String vcellNagiosPassword, int warningTimeout, int criticalTimeout) throws Exception {
    long startTime = System.currentTimeMillis();
    SimulationStatusPersistent lastSimStatus = null;
    if (rmiHostName == null || rmiPort == -1) {
        throw new UnexpectedTestStateException("Host name/ip and rmiPort required for testing, rmihostname=" + rmiHostName + " rmiport=" + rmiPort);
    }
    String rmiUrl = "//" + rmiHostName + ":" + rmiPort + "/" + rmiBootstrapStubName;
    VCellBootstrap vcellBootstrap = null;
    try {
        vcellBootstrap = (VCellBootstrap) Naming.lookup(rmiUrl);
    } catch (Exception e) {
        throw new UnexpectedTestStateException("Error during bootstrap lookup, " + e.getClass().getSimpleName() + " " + e.getMessage());
    }
    if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.CONNECT_1.ordinal()) {
        if (vcellNagiosPassword == null) {
            throw new UnexpectedTestStateException("vcellNagios Password required for " + VCELL_CHECK_LEVEL.CONNECT_1.toString() + " and above");
        }
        VCellConnection vcellConnection = vcellBootstrap.getVCellConnection(new UserLoginInfo("vcellNagios", new DigestedPassword(vcellNagiosPassword)));
        if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.INFOS_2.ordinal()) {
            VCInfoContainer vcInfoContainer = vcellConnection.getUserMetaDbServer().getVCInfoContainer();
            if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.LOAD_3.ordinal()) {
                KeyValue bioModelKey = null;
                final String testModelName = "Solver Suite 5.1 (BETA only ode)";
                for (BioModelInfo bioModelInfo : vcInfoContainer.getBioModelInfos()) {
                    if (bioModelInfo.getVersion().getName().equals(testModelName)) {
                        bioModelKey = bioModelInfo.getVersion().getVersionKey();
                        break;
                    }
                }
                BigString bioModelXML = vcellConnection.getUserMetaDbServer().getBioModelXML(bioModelKey);
                BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
                bioModel.refreshDependencies();
                if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.DATA_4.ordinal()) {
                    final String testSimContextName = "non-spatial ODE";
                    SimulationContext simulationContext = bioModel.getSimulationContext(testSimContextName);
                    final String testSimName = "Copy of combined ida/cvode";
                    Simulation simulation = simulationContext.getSimulation(testSimName);
                    if (simulation == null) {
                        throw new UnexpectedTestStateException("Couldn't find sim '" + testSimName + "' for " + checkLevel.toString());
                    }
                    VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(simulation.getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), 0);
                    ArrayList<AnnotatedFunction> outputFunctionsList = simulationContext.getOutputFunctionContext().getOutputFunctionsList();
                    OutputContext outputContext = new OutputContext(outputFunctionsList.toArray(new AnnotatedFunction[outputFunctionsList.size()]));
                    double[] times = vcellConnection.getDataSetController().getDataSetTimes(vcSimulationDataIdentifier);
                    ODESimData odeSimData = vcellConnection.getDataSetController().getODEData(vcSimulationDataIdentifier);
                    // SimDataBlock simDataBlock = vcellConnection.getDataSetController().getSimDataBlock(outputContext, vcSimulationDataIdentifier, "RanC_cyt",times[times.length-1]);
                    if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.RUN_5.ordinal()) {
                        KeyValue copy1Key = null;
                        KeyValue copy2Key = null;
                        try {
                            if (simulationContext.getSimulations().length != 1) {
                                throw new UnexpectedTestStateException("Expecting only 1 sim to be copied for " + checkLevel.toString());
                            }
                            SimulationStatusPersistent simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(simulation.getVersion().getVersionKey());
                            if (!simulationStatus.isCompleted()) {
                                throw new UnexpectedTestStateException("Expecting completed sim to copy for " + checkLevel.toString());
                            }
                            String copyModelName = testModelName + "_" + rmiHostName + "_" + rmiPort;
                            for (BioModelInfo bioModelInfo : vcInfoContainer.getBioModelInfos()) {
                                if (bioModelInfo.getVersion().getName().equals(copyModelName)) {
                                    throw new UnexpectedTestStateException("Messy test environment, not expecting " + copyModelName + " to exist at this point");
                                }
                            }
                            BigString copyBioModelXMLStr = vcellConnection.getUserMetaDbServer().saveBioModelAs(bioModelXML, copyModelName, null);
                            BioModel copyBioModel = XmlHelper.XMLToBioModel(new XMLSource(copyBioModelXMLStr.toString()));
                            copy1Key = copyBioModel.getVersion().getVersionKey();
                            copyBioModel.refreshDependencies();
                            Simulation copySim = copyBioModel.getSimulationContext(testSimContextName).copySimulation(copyBioModel.getSimulationContext(testSimContextName).getSimulation(testSimName));
                            final String copyTestSimName = "test";
                            copySim.setName(copyTestSimName);
                            copyBioModel.refreshDependencies();
                            copyBioModelXMLStr = new BigString(XmlHelper.bioModelToXML(copyBioModel));
                            copyBioModelXMLStr = vcellConnection.getUserMetaDbServer().saveBioModel(copyBioModelXMLStr, null);
                            copyBioModel = XmlHelper.XMLToBioModel(new XMLSource(copyBioModelXMLStr.toString()));
                            copy2Key = copyBioModel.getVersion().getVersionKey();
                            copyBioModel.refreshDependencies();
                            Simulation newSimulation = copyBioModel.getSimulationContext(testSimContextName).getSimulation(copyTestSimName);
                            simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(newSimulation.getVersion().getVersionKey());
                            if (simulationStatus != null && !simulationStatus.isNeverRan()) {
                                throw new UnexpectedTestStateException("Expecting new sim to have 'never ran' status for " + checkLevel.toString());
                            }
                            VCSimulationIdentifier newSimID = new VCSimulationIdentifier(newSimulation.getVersion().getVersionKey(), copyBioModel.getVersion().getOwner());
                            vcellConnection.getSimulationController().startSimulation(newSimID, 1);
                            lastSimStatus = simulationStatus;
                            MessageEvent[] messageEvents = null;
                            while (simulationStatus == null || (!simulationStatus.isStopped() && !simulationStatus.isCompleted() && !simulationStatus.isFailed())) {
                                Thread.sleep(200);
                                if (((System.currentTimeMillis() - startTime) / 1000) > criticalTimeout) {
                                    vcellConnection.getSimulationController().stopSimulation(newSimID);
                                    vcellConnection.getMessageEvents();
                                    break;
                                }
                                simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(newSimulation.getVersion().getVersionKey());
                                if (simulationStatus != null && !simulationStatus.toString().equals((lastSimStatus == null ? null : lastSimStatus.toString()))) {
                                    lastSimStatus = simulationStatus;
                                }
                                messageEvents = vcellConnection.getMessageEvents();
                            }
                        } finally {
                            try {
                                if (copy1Key != null) {
                                    vcellConnection.getUserMetaDbServer().deleteBioModel(copy1Key);
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            try {
                                if (copy2Key != null) {
                                    vcellConnection.getUserMetaDbServer().deleteBioModel(copy2Key);
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
        }
    }
    long endTime = System.currentTimeMillis();
    if (criticalTimeout != -1 && ((endTime - startTime) / 1000) > criticalTimeout) {
        throw new Exception(checkLevel.toString() + " test exceeded criticalTimeout=" + criticalTimeout + " seconds lastSimStatus=" + lastSimStatus);
    }
    if (warningTimeout != -1 && ((endTime - startTime) / 1000) > warningTimeout) {
        throw new WarningTestConditionException(checkLevel.toString() + " test exceeded warningTimeout=" + warningTimeout + " seconds lastSimStatus=" + lastSimStatus);
    }
    return vcellBootstrap.getVCellSoftwareVersion();
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) MessageEvent(cbit.rmi.event.MessageEvent) VCellBootstrap(cbit.vcell.server.VCellBootstrap) BigString(org.vcell.util.BigString) ODESimData(cbit.vcell.solver.ode.ODESimData) DigestedPassword(org.vcell.util.document.UserLoginInfo.DigestedPassword) BigString(org.vcell.util.BigString) VCInfoContainer(org.vcell.util.document.VCInfoContainer) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) VCellConnection(cbit.vcell.server.VCellConnection) BioModelInfo(org.vcell.util.document.BioModelInfo) SimulationStatusPersistent(cbit.vcell.server.SimulationStatusPersistent) SimulationContext(cbit.vcell.mapping.SimulationContext) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) OutputContext(cbit.vcell.simdata.OutputContext) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) UserLoginInfo(org.vcell.util.document.UserLoginInfo) XMLSource(cbit.vcell.xml.XMLSource)

Aggregations

ODESimData (cbit.vcell.solver.ode.ODESimData)12 ExpressionException (cbit.vcell.parser.ExpressionException)5 Simulation (cbit.vcell.solver.Simulation)5 File (java.io.File)5 DataAccessException (org.vcell.util.DataAccessException)5 SimulationTask (cbit.vcell.messaging.server.SimulationTask)4 ODEDataBlock (cbit.vcell.simdata.ODEDataBlock)3 SimulationData (cbit.vcell.simdata.SimulationData)3 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)3 SimulationJob (cbit.vcell.solver.SimulationJob)3 TempSimulation (cbit.vcell.solver.TempSimulation)3 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)3 MessageEvent (cbit.rmi.event.MessageEvent)2 BioModel (cbit.vcell.biomodel.BioModel)2 SimulationContext (cbit.vcell.mapping.SimulationContext)2 SimulationStatusPersistent (cbit.vcell.server.SimulationStatusPersistent)2 VCellBootstrap (cbit.vcell.server.VCellBootstrap)2 VCellConnection (cbit.vcell.server.VCellConnection)2 OutputContext (cbit.vcell.simdata.OutputContext)2 Solver (cbit.vcell.solver.server.Solver)2