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;
}
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);
}
}
}
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);
}
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();
}
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;
}
Aggregations