Search in sources :

Example 41 with VCSimulationDataIdentifier

use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.

the class SimulationData method getChomboFiles.

@Override
public ChomboFiles getChomboFiles() throws IOException, XmlParseException, ExpressionException {
    if (chomboFileIterationIndices == null) {
        throw new RuntimeException("SimulationData.chomboFileIterationIndices is null, can't process Chombo HDF5 files");
    }
    if (!(getVcDataId() instanceof VCSimulationDataIdentifier)) {
        throw new RuntimeException("SimulationData.getVcDataId() is not a VCSimulationDataIdentifier (type is " + getVcDataId().getClass().getName() + "), can't process chombo HDF5 files");
    }
    VCSimulationDataIdentifier vcDataID = (VCSimulationDataIdentifier) getVcDataId();
    String expectedMeshfile = vcDataID.getID() + ".mesh.hdf5";
    File meshFile = amplistorHelper.getFile(expectedMeshfile);
    ChomboFiles chomboFiles = new ChomboFiles(vcDataID.getSimulationKey(), vcDataID.getJobIndex(), meshFile);
    String simtaskFilePath = vcDataID.getID() + "_0.simtask.xml";
    File simtaskFile = amplistorHelper.getFile(simtaskFilePath);
    if (!simtaskFile.exists()) {
        throw new RuntimeException("Chombo dataset mission .simtask.xml file, please rerun");
    }
    String xmlString = FileUtils.readFileToString(simtaskFile);
    SimulationTask simTask = XmlHelper.XMLToSimTask(xmlString);
    if (!simTask.getSimulation().getSolverTaskDescription().getChomboSolverSpec().isSaveChomboOutput() && !simTask.getSimulation().getSolverTaskDescription().isParallel()) {
        throw new RuntimeException("Export of Chombo simulations to VTK requires chombo data, select 'Chombo' data format in simulation solver options and rerun simulation.");
    }
    CartesianMeshChombo chomboMesh = (CartesianMeshChombo) mesh;
    FeaturePhaseVol[] featurePhaseVols = chomboMesh.getFeaturePhaseVols();
    for (int timeIndex : chomboFileIterationIndices) {
        if (featurePhaseVols == null) {
            // for old format which doesn't have featurephasevols, we need to try ivol up to 20 for each feature
            Enumeration<SubDomain> subdomainEnum = simTask.getSimulation().getMathDescription().getSubDomains();
            while (subdomainEnum.hasMoreElements()) {
                SubDomain subDomain = subdomainEnum.nextElement();
                if (subDomain instanceof CompartmentSubDomain) {
                    for (int ivol = 0; ivol < 20; ++ivol) {
                        // can be many vol, let us try 20
                        findChomboFeatureVolFile(chomboFiles, vcDataID, subDomain.getName(), ivol, timeIndex);
                    }
                }
            }
        } else {
            // note: some feature + ivol doesn't have a file if there are no variables defined in that feature
            for (FeaturePhaseVol pfv : featurePhaseVols) {
                findChomboFeatureVolFile(chomboFiles, vcDataID, pfv.feature, pfv.ivol, timeIndex);
            }
        }
    }
    return chomboFiles;
}
Also used : SimulationTask(cbit.vcell.messaging.server.SimulationTask) FeaturePhaseVol(cbit.vcell.solvers.CartesianMeshChombo.FeaturePhaseVol) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) CartesianMeshChombo(cbit.vcell.solvers.CartesianMeshChombo) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) FilamentSubDomain(cbit.vcell.math.FilamentSubDomain) SubDomain(cbit.vcell.math.SubDomain) PointSubDomain(cbit.vcell.math.PointSubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) ChomboFiles(org.vcell.vis.io.ChomboFiles) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File)

Example 42 with VCSimulationDataIdentifier

use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.

the class VtkMeshGenerator method generateVtkMeshes.

private void generateVtkMeshes(User owner, KeyValue simKey, int jobIndex) throws DataAccessException, IOException {
    VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, owner);
    VCSimulationDataIdentifier vcdataID = new VCSimulationDataIdentifier(vcSimID, jobIndex);
    Cachetable cacheTable = new Cachetable(MessageConstants.MINUTE_IN_MS * 20);
    DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(cacheTable, new File(PropertyLoader.getRequiredProperty(PropertyLoader.primarySimDataDirInternalProperty)), new File(PropertyLoader.getRequiredProperty(PropertyLoader.secondarySimDataDirInternalProperty)));
    ExportServiceImpl exportServiceImpl = new ExportServiceImpl();
    DataServerImpl dataServerImpl = new DataServerImpl(dataSetControllerImpl, exportServiceImpl);
    // @SuppressWarnings("unused")
    if (!dataSetControllerImpl.getIsMovingBoundary(vcdataID)) {
        // 
        // precompute single static vtk mesh
        // 
        VtuFileContainer vtuFileContainer = dataServerImpl.getEmptyVtuMeshFiles(owner, vcdataID, 0);
    } else {
        // 
        // precompute static vtk mesh for each saved time point
        // 
        double[] times = dataServerImpl.getDataSetTimes(owner, vcdataID);
        for (int i = 0; i < times.length; i++) {
            VtuFileContainer vtuFileContainer = dataServerImpl.getEmptyVtuMeshFiles(owner, vcdataID, i);
        }
    }
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) VtuFileContainer(org.vcell.vis.io.VtuFileContainer) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) File(java.io.File)

Example 43 with VCSimulationDataIdentifier

use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.

the class DataSetControllerImplTest method setUp.

@Before
public void setUp() throws Exception {
    System.setProperty(PropertyLoader.installationRoot, new File("../").getAbsolutePath());
    String message = "installation directory is " + PropertyLoader.getRequiredProperty(PropertyLoader.installationRoot);
    ResourceUtil.setNativeLibraryDirectory();
    NativeLib.HDF5.load();
    Cachetable cachetable = new Cachetable(2000);
    File resourcesDirectory = new File("src/test/resources/simdata");
    File primarydir = resourcesDirectory;
    File secondarydir = resourcesDirectory;
    KeyValue simKey = new KeyValue("1771409053");
    VCSimulationIdentifier vcSimId = new VCSimulationIdentifier(new KeyValue("1771409053"), User.tempUser);
    vcDataIdentifier = new VCSimulationDataIdentifier(vcSimId, 0);
    dsc = new DataSetControllerImpl(cachetable, primarydir, secondarydir);
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) File(java.io.File) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) Before(org.junit.Before)

Example 44 with VCSimulationDataIdentifier

use of cbit.vcell.solver.VCSimulationDataIdentifier 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)

Example 45 with VCSimulationDataIdentifier

use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.

the class ImportImageROIsFrom2DVCellOp method importROIs.

public ImageROIs importROIs(File vcellSimLogFile, String bleachedMaskVarName, String cellSubvolumeName, String ecSubvolumeName) throws Exception {
    VCSimulationIdentifier vcSimulationIdentifier = VCellSimReader.getVCSimulationIdentifierFromVCellSimulationData(vcellSimLogFile);
    VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(vcSimulationIdentifier, 0);
    DataSetControllerImpl dataSetControllerImpl = VCellSimReader.getDataSetControllerImplFromVCellSimulationData(vcellSimLogFile);
    CartesianMesh cartesianMesh = dataSetControllerImpl.getMesh(vcSimulationDataIdentifier);
    // get rois from log file
    if (bleachedMaskVarName == null) {
        throw new RuntimeException("bleachedMathVarName not set");
    }
    double[] rawROIBleached = dataSetControllerImpl.getSimDataBlock(null, vcSimulationDataIdentifier, bleachedMaskVarName, 0).getData();
    short[] scaledCellDataShort = new short[rawROIBleached.length];
    short[] scaledBleachedDataShort = new short[rawROIBleached.length];
    short[] scaledBackgoundDataShort = new short[rawROIBleached.length];
    for (int j = 0; j < scaledCellDataShort.length; j++) {
        boolean isCell = cartesianMesh.getCompartmentSubdomainNamefromVolIndex(j).equals(cellSubvolumeName);
        boolean isBackground = cartesianMesh.getCompartmentSubdomainNamefromVolIndex(j).equals(ecSubvolumeName);
        if (isCell) {
            scaledCellDataShort[j] = 1;
        }
        if (isBackground) {
            scaledBackgoundDataShort[j] = 1;
        }
        if (rawROIBleached[j] > 0.2) {
            scaledBleachedDataShort[j] = 1;
        }
    }
    UShortImage cellImage = new UShortImage(scaledCellDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
    UShortImage bleachedImage = new UShortImage(scaledBleachedDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
    UShortImage backgroundImage = new UShortImage(scaledBackgoundDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
    ROI cellROI = new ROI(cellImage, "cellROI");
    ROI bleachedROI = new ROI(bleachedImage, "bleachedROI");
    ROI backgroundROI = new ROI(backgroundImage, "backgroundROI");
    ImageROIs imageRois = new ImageROIs();
    imageRois.cellROI_2D = cellROI;
    imageRois.bleachedROI_2D = bleachedROI;
    imageRois.backgroundROI_2D = backgroundROI;
    return imageRois;
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) CartesianMesh(cbit.vcell.solvers.CartesianMesh) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Aggregations

VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)47 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)27 File (java.io.File)25 KeyValue (org.vcell.util.document.KeyValue)24 User (org.vcell.util.document.User)15 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)15 Simulation (cbit.vcell.solver.Simulation)11 BioModel (cbit.vcell.biomodel.BioModel)8 DataSetControllerImpl (cbit.vcell.simdata.DataSetControllerImpl)8 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)7 PDEDataManager (cbit.vcell.simdata.PDEDataManager)7 BigString (org.vcell.util.BigString)7 DataIdentifier (cbit.vcell.simdata.DataIdentifier)6 ODEDataManager (cbit.vcell.simdata.ODEDataManager)6 CartesianMesh (cbit.vcell.solvers.CartesianMesh)6 OutputContext (cbit.vcell.simdata.OutputContext)5 VCDataManager (cbit.vcell.simdata.VCDataManager)5 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)5 IOException (java.io.IOException)5 Hashtable (java.util.Hashtable)5