use of org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class XmlReader method getDBSpecies.
/**
* This method reads a DBSpecies from a XML representation.
* Creation date: (6/3/2003 8:20:54 PM)
* @return cbit.vcell.dictionary.DBSpecies
* @param dbSpeciesElement org.jdom.Element
*/
private DBSpecies getDBSpecies(Element dbSpeciesElement) throws XmlParseException {
// Read the key
String keystring = dbSpeciesElement.getAttributeValue(XMLTags.KeyValueAttrTag);
KeyValue key = new KeyValue(keystring);
DBSpecies dbSpecies = null;
// read the type
String type = dbSpeciesElement.getAttributeValue(XMLTags.TypeAttrTag);
// Read the DBFormalSpecies
org.jdom.Element formalSpeciesElement = dbSpeciesElement.getChild(XMLTags.DBFormalSpeciesTag, vcNamespace);
if (type.equalsIgnoreCase(XMLTags.CompoundTypeTag)) {
// Create a BoundCompound
dbSpecies = new BoundCompound(key, (FormalCompound) getDBFormalSpecies(formalSpeciesElement));
} else if (type.equalsIgnoreCase(XMLTags.EnzymeTypeTag)) {
// Create a BoundEnzyme
dbSpecies = new BoundEnzyme(key, (FormalEnzyme) getDBFormalSpecies(formalSpeciesElement));
} else if (type.equalsIgnoreCase(XMLTags.ProteinTypeTag)) {
// Create a BoundProtein
dbSpecies = new BoundProtein(key, (FormalProtein) getDBFormalSpecies(formalSpeciesElement));
} else {
throw new XmlParseException("DBSpecies type: " + type + ", not supported yet!");
}
return dbSpecies;
}
use of org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class XmlReader method getDBFormalSpecies.
/**
* This method returns a DBFormalSpecies from a XML representation.
* Creation date: (6/3/2003 8:46:44 PM)
* @return cbit.vcell.dictionary.DBFormalSpecies
* @param formalSpeciesElement org.jdom.Element
*/
private DBFormalSpecies getDBFormalSpecies(Element formalSpeciesElement) throws XmlParseException {
// read key
String keystring = formalSpeciesElement.getAttributeValue(XMLTags.KeyValueAttrTag);
KeyValue key = new KeyValue(keystring);
// read type
String typestring = formalSpeciesElement.getAttributeValue(XMLTags.TypeAttrTag);
// read the FormalSpeciesInfo
Element speciesInfoElement = formalSpeciesElement.getChild(XMLTags.FormalSpeciesInfoTag, vcNamespace);
// create the DBFormalSpecies upon the type
DBFormalSpecies formalSpecies = null;
if (typestring.equalsIgnoreCase(XMLTags.CompoundTypeTag)) {
formalSpecies = new FormalCompound(key, (CompoundInfo) getFormalSpeciesInfo(speciesInfoElement));
} else if (typestring.equalsIgnoreCase(XMLTags.EnzymeTypeTag)) {
formalSpecies = new FormalEnzyme(key, (EnzymeInfo) getFormalSpeciesInfo(speciesInfoElement));
} else if (typestring.equalsIgnoreCase(XMLTags.ProteinTypeTag)) {
formalSpecies = new FormalProtein(key, (ProteinInfo) getFormalSpeciesInfo(speciesInfoElement));
} else {
throw new XmlParseException("DBFormalSpecies type:" + typestring + ", not supported yet!");
}
return formalSpecies;
}
use of org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class FRAPOptData method refreshDimensionReducedRefData.
public void refreshDimensionReducedRefData(final ClientTaskStatusSupport progressListener) throws Exception {
System.out.println("run simulation...");
KeyValue referenceSimKeyValue = null;
referenceSimKeyValue = runRefSimulation(progressListener);
System.out.println("simulation done...");
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(referenceSimKeyValue, LocalWorkspace.getDefaultOwner());
VCSimulationDataIdentifier vcSimDataID = new VCSimulationDataIdentifier(vcSimID, FieldDataFileOperationSpec.JOBINDEX_DEFAULT);
// read results from netCDF file
File hdf5File = new File(getLocalWorkspace().getDefaultSimDataDirectory(), vcSimDataID.getID() + SimDataConstants.DATA_PROCESSING_OUTPUT_EXTENSION_HDF5);
// get dataprocessing output
DataOperationResults.DataProcessingOutputInfo dataProcessingOutputInfo = (DataOperationResults.DataProcessingOutputInfo) DataSetControllerImpl.getDataProcessingOutput(new DataOperation.DataProcessingOutputInfoOP(null, /*no vcDataIdentifier OK*/
false, null), hdf5File);
DataOperationResults.DataProcessingOutputDataValues dataProcessingOutputDataValues = (DataOperationResults.DataProcessingOutputDataValues) DataSetControllerImpl.getDataProcessingOutput(new DataOperation.DataProcessingOutputDataValuesOP(null, /*no vcDataIdentifier OK*/
FRAPStudy.ROI_EXTDATA_NAME, TimePointHelper.createAllTimeTimePointHelper(), DataIndexHelper.createSliceDataIndexHelper(0), null, null), hdf5File);
// DataProcessingOutput dataProcessingOutput = getRawReferenceDataFromHDF5(hdf5File);
// get ref sim time points
double[] rawRefDataTimePoints = dataProcessingOutputInfo.getVariableTimePoints();
// get shifted time points
refDataTimePoints = shiftTimeForBaseDiffRate(rawRefDataTimePoints);
// get summarized raw ref data
double[][] rawData = new double[dataProcessingOutputInfo.getVariableISize(FRAPStudy.ROI_EXTDATA_NAME).getXYZ()][rawRefDataTimePoints.length];
for (int i = 0; i < rawRefDataTimePoints.length; i++) {
double[] temp = dataProcessingOutputDataValues.getDataValues()[i];
for (int j = 0; j < temp.length; j++) {
rawData[j][i] = temp[j];
}
}
// contains only 8rois +1(the area that beyond 8 rois)
// extend to whole roi data
dimensionReducedRefData = FRAPOptimizationUtils.extendSimToFullROIData(expFrapStudy.getFrapData(), rawData, refDataTimePoints.length);
System.out.println("generating dimension reduced ref data, done ....");
// if reference simulation completes successfully, we save reference data info and remove old simulation files.
boolean[] selectedROIs = new boolean[FRAPData.VFRAP_ROI_ENUM.values().length];
Arrays.fill(selectedROIs, true);
getExpFrapStudy().setStoredRefData(FRAPOptimizationUtils.doubleArrayToSimpleRefData(dimensionReducedRefData, getRefDataTimePoints(), 0, selectedROIs));
// remove reference simulation files
FRAPStudy.removeSimulationFiles(referenceSimKeyValue, getLocalWorkspace());
// remove experimental and roi external files
FRAPStudy.removeExternalFiles(getExpFrapStudy().getFrapDataExternalDataInfo().getExternalDataIdentifier(), getExpFrapStudy().getRoiExternalDataInfo().getExternalDataIdentifier(), getLocalWorkspace());
}
use of org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class FRAPOptData method runRefSimulation.
public KeyValue runRefSimulation(final ClientTaskStatusSupport progressListener) throws Exception {
BioModel bioModel = null;
if (progressListener != null) {
progressListener.setMessage("Running Reference Simulation...");
}
try {
FieldDataIdentifierSpec psfFieldFunc = FRAPStudy.getPSFFieldData(getLocalWorkspace());
bioModel = FRAPStudy.createNewRefBioModel(expFrapStudy, REFERENCE_DIFF_RATE_STR, getRefTimeStep(), LocalWorkspace.createNewKeyValue(), LocalWorkspace.getDefaultOwner(), psfFieldFunc, expFrapStudy.getStartingIndexForRecovery());
// change time bound and time step
Simulation sim = bioModel.getSimulations()[0];
ROIDataGenerator roiDataGenerator = getExpFrapStudy().getROIDataGenerator(getLocalWorkspace());
sim.getMathDescription().getPostProcessingBlock().addDataGenerator(roiDataGenerator);
System.out.println("run FRAP Reference Simulation...");
// run simulation
FRAPStudy.runFVSolverStandalone_ref(new File(getLocalWorkspace().getDefaultSimDataDirectory()), bioModel.getSimulation(0), getExpFrapStudy().getFrapDataExternalDataInfo().getExternalDataIdentifier(), getExpFrapStudy().getRoiExternalDataInfo().getExternalDataIdentifier(), psfFieldFunc.getExternalDataIdentifier(), progressListener, true);
KeyValue referenceSimKeyValue = sim.getVersion().getVersionKey();
return referenceSimKeyValue;
} catch (Exception e) {
e.printStackTrace(System.out);
if (bioModel != null && bioModel.getSimulations() != null) {
FRAPStudy.removeExternalDataAndSimulationFiles(bioModel.getSimulations()[0].getVersion().getVersionKey(), null, null, getLocalWorkspace());
}
throw e;
}
}
use of org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class FRAPStudy method createNewRefBioModel.
public static BioModel createNewRefBioModel(FRAPStudy sourceFrapStudy, String baseDiffusionRate, TimeStep tStep, KeyValue simKey, User owner, FieldDataIdentifierSpec psfFDIS, int startingIndexForRecovery) throws Exception {
if (owner == null) {
throw new Exception("Owner is not defined");
}
ROI cellROI_2D = sourceFrapStudy.getFrapData().getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name());
Extent extent = sourceFrapStudy.getFrapData().getImageDataset().getExtent();
TimeBounds timeBounds = FRAPOptData.getEstimatedRefTimeBound(sourceFrapStudy);
double timeStepVal = FRAPOptData.REFERENCE_DIFF_DELTAT;
int numX = cellROI_2D.getRoiImages()[0].getNumX();
int numY = cellROI_2D.getRoiImages()[0].getNumY();
int numZ = cellROI_2D.getRoiImages().length;
short[] shortPixels = cellROI_2D.getRoiImages()[0].getPixels();
byte[] bytePixels = new byte[numX * numY * numZ];
final byte EXTRACELLULAR_PIXVAL = 0;
final byte CYTOSOL_PIXVAL = 1;
for (int i = 0; i < bytePixels.length; i++) {
if (shortPixels[i] != 0) {
bytePixels[i] = CYTOSOL_PIXVAL;
}
}
VCImage maskImage;
try {
maskImage = new VCImageUncompressed(null, bytePixels, extent, numX, numY, numZ);
} catch (ImageException e) {
e.printStackTrace();
throw new RuntimeException("failed to create mask image for geometry");
}
Geometry geometry = new Geometry("geometry", maskImage);
if (geometry.getGeometrySpec().getNumSubVolumes() != 2) {
throw new Exception("Cell ROI has no ExtraCellular.");
}
int subVolume0PixVal = ((ImageSubVolume) geometry.getGeometrySpec().getSubVolume(0)).getPixelValue();
geometry.getGeometrySpec().getSubVolume(0).setName((subVolume0PixVal == EXTRACELLULAR_PIXVAL ? EXTRACELLULAR_NAME : CYTOSOL_NAME));
int subVolume1PixVal = ((ImageSubVolume) geometry.getGeometrySpec().getSubVolume(1)).getPixelValue();
geometry.getGeometrySpec().getSubVolume(1).setName((subVolume1PixVal == CYTOSOL_PIXVAL ? CYTOSOL_NAME : EXTRACELLULAR_NAME));
geometry.getGeometrySurfaceDescription().updateAll();
BioModel bioModel = new BioModel(null);
bioModel.setName("unnamed");
Model model = new Model("model");
bioModel.setModel(model);
Feature extracellular = model.addFeature(EXTRACELLULAR_NAME);
Feature cytosol = model.addFeature(CYTOSOL_NAME);
Membrane plasmaMembrane = model.addMembrane(PLASMAMEMBRANE_NAME);
String roiDataName = FRAPStudy.ROI_EXTDATA_NAME;
final int ONE_DIFFUSION_SPECIES_COUNT = 1;
final int MOBILE_SPECIES_INDEX = 0;
Expression[] diffusionConstants = new Expression[ONE_DIFFUSION_SPECIES_COUNT];
Species[] species = new Species[ONE_DIFFUSION_SPECIES_COUNT];
SpeciesContext[] speciesContexts = new SpeciesContext[ONE_DIFFUSION_SPECIES_COUNT];
Expression[] initialConditions = new Expression[ONE_DIFFUSION_SPECIES_COUNT];
// Mobile Species
diffusionConstants[MOBILE_SPECIES_INDEX] = new Expression(baseDiffusionRate);
species[MOBILE_SPECIES_INDEX] = new Species(SPECIES_NAME_PREFIX_MOBILE, "Mobile bleachable species");
speciesContexts[MOBILE_SPECIES_INDEX] = new SpeciesContext(null, species[MOBILE_SPECIES_INDEX].getCommonName(), species[MOBILE_SPECIES_INDEX], cytosol);
FieldFunctionArguments postBleach_first = new FieldFunctionArguments(roiDataName, "postbleach_first", new Expression(0), VariableType.VOLUME);
FieldFunctionArguments prebleach_avg = new FieldFunctionArguments(roiDataName, "prebleach_avg", new Expression(0), VariableType.VOLUME);
Expression expPostBleach_first = new Expression(postBleach_first.infix());
Expression expPreBleach_avg = new Expression(prebleach_avg.infix());
initialConditions[MOBILE_SPECIES_INDEX] = Expression.div(expPostBleach_first, expPreBleach_avg);
SimulationContext simContext = new SimulationContext(bioModel.getModel(), geometry);
bioModel.addSimulationContext(simContext);
FeatureMapping cytosolFeatureMapping = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(cytosol);
FeatureMapping extracellularFeatureMapping = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(extracellular);
MembraneMapping plasmaMembraneMapping = (MembraneMapping) simContext.getGeometryContext().getStructureMapping(plasmaMembrane);
SubVolume cytSubVolume = geometry.getGeometrySpec().getSubVolume(CYTOSOL_NAME);
SubVolume exSubVolume = geometry.getGeometrySpec().getSubVolume(EXTRACELLULAR_NAME);
SurfaceClass pmSurfaceClass = geometry.getGeometrySurfaceDescription().getSurfaceClass(exSubVolume, cytSubVolume);
cytosolFeatureMapping.setGeometryClass(cytSubVolume);
extracellularFeatureMapping.setGeometryClass(exSubVolume);
plasmaMembraneMapping.setGeometryClass(pmSurfaceClass);
cytosolFeatureMapping.getUnitSizeParameter().setExpression(new Expression(1.0));
extracellularFeatureMapping.getUnitSizeParameter().setExpression(new Expression(1.0));
plasmaMembraneMapping.getUnitSizeParameter().setExpression(new Expression(1.0));
for (int i = 0; i < initialConditions.length; i++) {
model.addSpecies(species[i]);
model.addSpeciesContext(speciesContexts[i]);
}
for (int i = 0; i < speciesContexts.length; i++) {
SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(speciesContexts[i]);
scs.getInitialConditionParameter().setExpression(initialConditions[i]);
scs.getDiffusionParameter().setExpression(diffusionConstants[i]);
}
MathMapping mathMapping = simContext.createNewMathMapping();
MathDescription mathDesc = mathMapping.getMathDescription();
// Add PSF function
mathDesc.addVariable(new Function(Simulation.PSF_FUNCTION_NAME, new Expression(psfFDIS.getFieldFuncArgs().infix()), null));
simContext.setMathDescription(mathDesc);
SimulationVersion simVersion = new SimulationVersion(simKey, "sim1", owner, new GroupAccessNone(), new KeyValue("0"), new BigDecimal(0), new Date(), VersionFlag.Current, "", null);
Simulation newSimulation = new Simulation(simVersion, simContext.getMathDescription());
newSimulation.getSolverTaskDescription().setSolverDescription(SolverDescription.FiniteVolumeStandalone);
simContext.addSimulation(newSimulation);
newSimulation.getSolverTaskDescription().setTimeBounds(timeBounds);
newSimulation.getSolverTaskDescription().setOutputTimeSpec(new UniformOutputTimeSpec(timeStepVal));
newSimulation.getMeshSpecification().setSamplingSize(cellROI_2D.getISize());
newSimulation.getSolverTaskDescription().setTimeStep(new TimeStep(timeStepVal, timeStepVal, timeStepVal));
return bioModel;
}
Aggregations