use of org.vcell.util.document.SimulationVersion in project vcell by virtualcell.
the class SimulationDbDriver method insertVersionableInit.
/**
* This method was created in VisualAge.
* @return cbit.image.VCImage
* @param user cbit.vcell.server.User
* @param image cbit.image.VCImage
*/
protected SimulationVersion insertVersionableInit(InsertHashtable hash, Connection con, User user, Versionable versionable, String name, String annot, boolean bVersion, boolean bMathematicallyEquivalent) throws DataAccessException, SQLException, RecordChangedException {
SimulationVersion dbSimulationVersion = ((Simulation) versionable).getSimulationVersion();
Version newVersion = insertVersionableInit(hash, con, user, versionable, name, annot, bVersion);
//
// point to oldest mathematically equivalent ancestor, this will be used for all identification (status/data).
//
KeyValue parentSimRef = null;
if (bMathematicallyEquivalent) {
if (dbSimulationVersion == null) {
throw new RuntimeException("Simulation must have been saved for bMathematicallyEquivalent to be true");
}
if (dbSimulationVersion.getParentSimulationReference() != null) {
// //
// // mathematically equivalent, prior link is transitive (B->C and A==B, then A->C)
// //
parentSimRef = dbSimulationVersion.getParentSimulationReference();
} else {
// //
// // mathematically equivalent, no prior link (A==B, then A->B)
// //
parentSimRef = dbSimulationVersion.getVersionKey();
}
}
return new SimulationVersion(newVersion.getVersionKey(), newVersion.getName(), newVersion.getOwner(), newVersion.getGroupAccess(), newVersion.getBranchPointRefKey(), newVersion.getBranchID(), newVersion.getDate(), newVersion.getFlag(), newVersion.getAnnot(), parentSimRef);
}
use of org.vcell.util.document.SimulationVersion in project vcell by virtualcell.
the class SimulationDbDriver method updateVersionableInit.
/**
* This method was created in VisualAge.
* @return cbit.image.VCImage
* @param user cbit.vcell.server.User
* @param image cbit.image.VCImage
*/
protected SimulationVersion updateVersionableInit(InsertHashtable hash, Connection con, User user, Versionable versionable, boolean bVersion, boolean bMathematicallyEquivalent) throws DataAccessException, SQLException, RecordChangedException {
SimulationVersion dbSimulationVersion = ((Simulation) versionable).getSimulationVersion();
Version newVersion = updateVersionableInit(hash, con, user, versionable, bVersion);
//
// point to oldest mathematically equivalent ancestor, this will be used for all identification (status/data).
//
KeyValue parentSimRef = null;
if (bMathematicallyEquivalent) {
if (dbSimulationVersion == null) {
throw new RuntimeException("Simulation must have been saved for bMathematicallyEquivalent to be true");
}
if (dbSimulationVersion.getParentSimulationReference() != null) {
// //
// // mathematically equivalent, prior link is transitive (B->C and A==B, then A->C)
// //
parentSimRef = dbSimulationVersion.getParentSimulationReference();
} else {
// //
// // mathematically equivalent, no prior link (A==B, then A->B)
// //
parentSimRef = dbSimulationVersion.getVersionKey();
}
}
return new SimulationVersion(newVersion.getVersionKey(), newVersion.getName(), newVersion.getOwner(), newVersion.getGroupAccess(), newVersion.getBranchPointRefKey(), newVersion.getBranchID(), newVersion.getDate(), newVersion.getFlag(), newVersion.getAnnot(), parentSimRef);
}
use of org.vcell.util.document.SimulationVersion in project vcell by virtualcell.
the class SimulationTable method getSimulation.
/**
* This method was created in VisualAge.
* @return cbit.vcell.math.MathDescription
* @param user cbit.vcell.server.User
* @param rset java.sql.ResultSet
*/
public Simulation getSimulation(QueryHashtable dbc, ResultSet rset, Connection con, User user, MathDescriptionDbDriver mathDB, DatabaseSyntax dbSyntax) throws SQLException, DataAccessException, PropertyVetoException {
//
// get TaskDescription Data into parsable form
//
//
// String taskDescriptionString = new String(solverTaskDescData);
//
// System.out.println("taskDescriptionString '"+taskDescriptionString+"'");
String taskDescriptionString = rset.getString(SimulationTable.table.taskDescription.getUnqualifiedColName());
taskDescriptionString = TokenMangler.getSQLRestoredString(taskDescriptionString);
CommentStringTokenizer solverTaskDescTokens = new CommentStringTokenizer(taskDescriptionString);
//
// get MathOverride Data (language) (MUST BE READ FIRST)
//
/*
byte[] mathOverridesData = null;
mathOverridesData = rset.getBytes(SimulationTable.table.mathOverrides.toString());
if (rset.wasNull() || mathOverridesData==null || mathOverridesData.length==0){
throw new DataAccessException("no data stored for MathOverrides");
}
String mathOverridesString = new String(mathOverridesData);
*/
//
CommentStringTokenizer mathOverrideTokens = getMathOverridesTokenizer(rset, dbSyntax);
String dataProcessingInstructionString = rset.getString(dataProcInstr.getUnqualifiedColName());
DataProcessingInstructions dpi = null;
if (!rset.wasNull() && dataProcessingInstructionString != null && dataProcessingInstructionString.length() > 0) {
dataProcessingInstructionString = TokenMangler.getSQLRestoredString(dataProcessingInstructionString);
dpi = DataProcessingInstructions.fromDbXml(dataProcessingInstructionString);
}
//
// Get Version
//
java.math.BigDecimal groupid = rset.getBigDecimal(VersionTable.privacy_ColumnName);
SimulationVersion simulationVersion = (SimulationVersion) getVersion(rset, DbDriver.getGroupAccessFromGroupID(con, groupid));
java.math.BigDecimal bigD = rset.getBigDecimal(SimulationTable.table.mathRef.toString());
KeyValue mathKey = null;
if (!rset.wasNull()) {
mathKey = new KeyValue(bigD);
} else {
throw new DataAccessException("Error: MathDescription Reference Cannot be Null for Simulation");
}
MathDescription mathDesc = (MathDescription) mathDB.getVersionable(dbc, con, user, VersionableType.MathDescription, mathKey);
Simulation simulation = new Simulation(simulationVersion, mathDesc, mathOverrideTokens, solverTaskDescTokens);
simulation.setDataProcessingInstructions(dpi);
// MeshSpec (Is This Correct?????)
if (mathDesc != null && mathDesc.getGeometry() != null && mathDesc.getGeometry().getDimension() > 0) {
int msX = rset.getInt(SimulationTable.table.meshSpecX.getUnqualifiedColName());
int msY = rset.getInt(SimulationTable.table.meshSpecY.getUnqualifiedColName());
int msZ = rset.getInt(SimulationTable.table.meshSpecZ.getUnqualifiedColName());
MeshSpecification meshSpec = new MeshSpecification(simulation.getMathDescription().getGeometry());
meshSpec.setSamplingSize(new ISize(msX, msY, msZ));
simulation.getMeshSpecification().copyFrom(meshSpec);
}
return simulation;
}
use of org.vcell.util.document.SimulationVersion in project vcell by virtualcell.
the class SimulationTable method getInfo.
/**
* This method was created in VisualAge.
* @return cbit.vcell.geometry.GeometryInfo
* @param rset java.sql.ResultSet
* @param log cbit.vcell.server.SessionLog
*/
public VersionInfo getInfo(ResultSet rset, Connection con) throws SQLException, DataAccessException {
KeyValue mathRef = new KeyValue(rset.getBigDecimal(SimulationTable.table.mathRef.toString()));
java.math.BigDecimal groupid = rset.getBigDecimal(VersionTable.privacy_ColumnName);
Version version = getVersion(rset, DbDriver.getGroupAccessFromGroupID(con, groupid));
SimulationVersion simulationVersion = (SimulationVersion) version;
String softwareVersion = rset.getString(SoftwareVersionTable.table.softwareVersion.toString());
return new SimulationInfo(mathRef, simulationVersion, VCellSoftwareVersion.fromString(softwareVersion));
}
use of org.vcell.util.document.SimulationVersion in project vcell by virtualcell.
the class RunRefSimulationFastOp method createRefSimBioModel.
private BioModel createRefSimBioModel(KeyValue simKey, User owner, Origin origin, Extent extent, ROI cellROI_2D, double timeStepVal, TimeBounds timeBounds, String varName, Expression initialConcentration, FieldFunctionArguments psfFFA, Expression chirpedDiffusionRate) throws Exception {
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);
geometry.getGeometrySpec().setOrigin(origin);
if (geometry.getGeometrySpec().getNumSubVolumes() != 2) {
throw new Exception("Cell ROI has no ExtraCellular.");
}
String EXTRACELLULAR_NAME = "ec";
String CYTOSOL_NAME = "cyt";
String PLASMAMEMBRANE_NAME = "pm";
ImageSubVolume subVolume0 = (ImageSubVolume) geometry.getGeometrySpec().getSubVolume(0);
ImageSubVolume subVolume1 = (ImageSubVolume) geometry.getGeometrySpec().getSubVolume(1);
if (subVolume0.getPixelValue() == EXTRACELLULAR_PIXVAL) {
subVolume0.setName(EXTRACELLULAR_NAME);
subVolume1.setName(CYTOSOL_NAME);
} else {
subVolume0.setName(CYTOSOL_NAME);
subVolume1.setName(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);
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));
// Mobile Species
Species diffusingSpecies = model.addSpecies(new Species("species", "Mobile bleachable species"));
SpeciesContext diffusingSpeciesContext = model.addSpeciesContext(diffusingSpecies, cytosol);
diffusingSpeciesContext.setName(varName);
SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(diffusingSpeciesContext);
scs.getInitialConditionParameter().setExpression(initialConcentration);
chirpedDiffusionRate.bindExpression(scs);
scs.getDiffusionParameter().setExpression(chirpedDiffusionRate);
// simContext.getMicroscopeMeasurement().addFluorescentSpecies(speciesContexts[0]);
// simContext.getMicroscopeMeasurement().setConvolutionKernel(new MicroscopeMeasurement.ProjectionZKernel());
MathDescription mathDescription = simContext.createNewMathMapping().getMathDescription();
// maybe there is a way that works for simContext.getMicroscopeMeasurement().... but this is needed now.
mathDescription.addVariable(new Function(Simulation.PSF_FUNCTION_NAME, new Expression(psfFFA.infix()), null));
simContext.setMathDescription(mathDescription);
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