Search in sources :

Example 11 with SimulationVersion

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);
}
Also used : SimulationVersion(org.vcell.util.document.SimulationVersion) KeyValue(org.vcell.util.document.KeyValue) Simulation(cbit.vcell.solver.Simulation) SimulationVersion(org.vcell.util.document.SimulationVersion) Version(org.vcell.util.document.Version)

Example 12 with SimulationVersion

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);
}
Also used : SimulationVersion(org.vcell.util.document.SimulationVersion) KeyValue(org.vcell.util.document.KeyValue) Simulation(cbit.vcell.solver.Simulation) SimulationVersion(org.vcell.util.document.SimulationVersion) Version(org.vcell.util.document.Version)

Example 13 with SimulationVersion

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;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) MathDescription(cbit.vcell.math.MathDescription) ISize(org.vcell.util.ISize) MeshSpecification(cbit.vcell.solver.MeshSpecification) BigDecimal(java.math.BigDecimal) SimulationVersion(org.vcell.util.document.SimulationVersion) Simulation(cbit.vcell.solver.Simulation) DataProcessingInstructions(cbit.vcell.solver.DataProcessingInstructions) CommentStringTokenizer(org.vcell.util.CommentStringTokenizer) DataAccessException(org.vcell.util.DataAccessException)

Example 14 with SimulationVersion

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));
}
Also used : BigDecimal(java.math.BigDecimal) KeyValue(org.vcell.util.document.KeyValue) SimulationVersion(org.vcell.util.document.SimulationVersion) Version(org.vcell.util.document.Version) SimulationVersion(org.vcell.util.document.SimulationVersion) VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion) SimulationInfo(cbit.vcell.solver.SimulationInfo)

Example 15 with SimulationVersion

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;
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) ImageException(cbit.image.ImageException) KeyValue(org.vcell.util.document.KeyValue) SurfaceClass(cbit.vcell.geometry.SurfaceClass) MathDescription(cbit.vcell.math.MathDescription) VCImage(cbit.image.VCImage) SpeciesContext(cbit.vcell.model.SpeciesContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) Feature(cbit.vcell.model.Feature) Function(cbit.vcell.math.Function) GroupAccessNone(org.vcell.util.document.GroupAccessNone) TimeStep(cbit.vcell.solver.TimeStep) SimulationVersion(org.vcell.util.document.SimulationVersion) FeatureMapping(cbit.vcell.mapping.FeatureMapping) SubVolume(cbit.vcell.geometry.SubVolume) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) Membrane(cbit.vcell.model.Membrane) Species(cbit.vcell.model.Species) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) VCImageUncompressed(cbit.image.VCImageUncompressed) SimulationContext(cbit.vcell.mapping.SimulationContext) ImageException(cbit.image.ImageException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) IOException(java.io.IOException) UserCancelException(org.vcell.util.UserCancelException) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) BioModel(cbit.vcell.biomodel.BioModel) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel)

Aggregations

SimulationVersion (org.vcell.util.document.SimulationVersion)19 KeyValue (org.vcell.util.document.KeyValue)15 Simulation (cbit.vcell.solver.Simulation)13 SimulationContext (cbit.vcell.mapping.SimulationContext)9 BioModel (cbit.vcell.biomodel.BioModel)8 MathDescription (cbit.vcell.math.MathDescription)8 Model (cbit.vcell.model.Model)8 UniformOutputTimeSpec (cbit.vcell.solver.UniformOutputTimeSpec)8 BigDecimal (java.math.BigDecimal)8 SpeciesContext (cbit.vcell.model.SpeciesContext)7 Expression (cbit.vcell.parser.Expression)7 TimeBounds (cbit.vcell.solver.TimeBounds)7 Geometry (cbit.vcell.geometry.Geometry)6 SubVolume (cbit.vcell.geometry.SubVolume)6 FeatureMapping (cbit.vcell.mapping.FeatureMapping)6 MathMapping (cbit.vcell.mapping.MathMapping)6 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)6 Feature (cbit.vcell.model.Feature)6 Date (java.util.Date)6 GroupAccessNone (org.vcell.util.document.GroupAccessNone)6