Search in sources :

Example 56 with Model

use of cbit.vcell.model.Model in project vcell by virtualcell.

the class ModelDbDriver method getModel.

/**
 * getModel method comment.
 */
private cbit.vcell.model.Model getModel(QueryHashtable dbc, Connection con, User user, KeyValue modelKey) throws SQLException, DataAccessException, ObjectNotFoundException {
    if (user == null || modelKey == null) {
        throw new IllegalArgumentException("Improper parameters for getModel");
    }
    // log.print("ModelDbDriver.getModel(user=" + user + ", id=" + modelKey + ")");
    String sql;
    Field[] f = { new cbit.sql.StarField(modelTable), userTable.userid };
    Table[] t = { modelTable, userTable };
    String condition = modelTable.id.getQualifiedColName() + " = " + modelKey + " AND " + userTable.id.getQualifiedColName() + " = " + modelTable.ownerRef.getQualifiedColName();
    sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, (OuterJoin) null, condition, null, dbSyntax);
    Statement stmt = con.createStatement();
    Model model = null;
    try {
        ResultSet rset = stmt.executeQuery(sql);
        if (rset.next()) {
            model = getModel(dbc, rset, con, user);
        } else {
            throw new org.vcell.util.ObjectNotFoundException("Model id=" + modelKey + " not found for user '" + user + "'");
        }
    } finally {
        // Release resources include resultset
        stmt.close();
    }
    // GlobalModelParameterTable.table.setModelParameters(con, model);
    return model;
}
Also used : Table(cbit.sql.Table) Statement(java.sql.Statement) Field(cbit.sql.Field) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) OuterJoin(cbit.vcell.modeldb.DatabasePolicySQL.OuterJoin) Model(cbit.vcell.model.Model) ResultSet(java.sql.ResultSet)

Example 57 with Model

use of cbit.vcell.model.Model in project vcell by virtualcell.

the class ModelTable method getModel.

/**
 * This method was created in VisualAge.
 * @return Model
 * @param rset ResultSet
 * @param log SessionLog
 */
public Model getModel(ResultSet rset, Connection con) throws SQLException, DataAccessException {
    java.math.BigDecimal groupid = rset.getBigDecimal(VersionTable.privacy_ColumnName);
    Version version = getVersion(rset, DbDriver.getGroupAccessFromGroupID(con, groupid));
    ModelUnitSystem modelUnitSystem = ModelUnitSystem.createDefaultVCModelUnitSystem();
    String unitSystemXML = rset.getString(ModelTable.table.unitSystemXML.toString());
    if (!rset.wasNull()) {
        unitSystemXML = org.vcell.util.TokenMangler.getSQLRestoredString(unitSystemXML);
        XmlReader xmlReader = new XmlReader(false);
        modelUnitSystem = xmlReader.getUnitSystem(XmlUtil.stringToXML(unitSystemXML, null).getRootElement());
    }
    return new Model(version, modelUnitSystem);
}
Also used : Version(org.vcell.util.document.Version) VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion) Model(cbit.vcell.model.Model) XmlReader(cbit.vcell.xml.XmlReader) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 58 with Model

use of cbit.vcell.model.Model in project vcell by virtualcell.

the class ServerDocumentManager method getBioModelUnresolved.

/**
 * Insert the method's description here.
 * Creation date: (11/14/00 4:02:44 PM)
 * @return cbit.vcell.biomodel.BioModel
 * @param bioModelInfo cbit.vcell.biomodel.BioModelInfo
 */
// 
// this returns a BioModel that contains multiple instances of objects.
// 
public String getBioModelUnresolved(QueryHashtable dbc, User user, KeyValue bioModelKey) throws DataAccessException, XmlParseException, java.sql.SQLException {
    // 
    // get meta data associated with BioModel
    // 
    BioModelMetaData bioModelMetaData = dbServer.getDBTopLevel().getBioModelMetaData(dbc, user, bioModelKey);
    // 
    // get list of appropriate child components
    // 
    KeyValue modelKey = bioModelMetaData.getModelKey();
    KeyValue[] simKeys = getKeyArrayFromEnumeration(bioModelMetaData.getSimulationKeys());
    KeyValue[] scKeys = getKeyArrayFromEnumeration(bioModelMetaData.getSimulationContextKeys());
    Model model = dbServer.getDBTopLevel().getModel(dbc, user, modelKey);
    Simulation[] simArray = new Simulation[simKeys.length];
    for (int i = 0; i < simKeys.length; i++) {
        Simulation sim = dbServer.getDBTopLevel().getSimulation(dbc, user, simKeys[i]);
        // 
        try {
            simArray[i] = (Simulation) BeanUtils.cloneSerializable(sim);
        } catch (Throwable e) {
            e.printStackTrace(System.out);
            throw new RuntimeException("exception cloning Simulation: " + e.getMessage());
        }
    }
    SimulationContext[] scArray = new SimulationContext[scKeys.length];
    for (int i = 0; i < scKeys.length; i++) {
        SimulationContext sc = dbServer.getDBTopLevel().getSimulationContext(dbc, user, scKeys[i]);
        // 
        try {
            scArray[i] = (SimulationContext) BeanUtils.cloneSerializable(sc);
            scArray[i].getModel().refreshDependencies();
            scArray[i].refreshDependencies();
            scArray[i].setModel(model);
        } catch (Throwable e) {
            e.printStackTrace(System.out);
            throw new RuntimeException("exception cloning Application: " + e.getMessage());
        }
        if (!scArray[i].getModel().getKey().compareEqual(modelKey)) {
            // throw new DataAccessException("simulationContext("+scKeys[i]+").model = "+scArray[i].getModel().getKey()+", BioModel.model = "+modelKey);
            System.out.println("simulationContext(" + scKeys[i] + ").model = " + scArray[i].getModel().getKey() + ", BioModel.model = " + modelKey);
        }
    }
    // 
    // create new BioModel according to loaded BioModelMetaData
    // 
    BioModel newBioModel = new BioModel(bioModelMetaData.getVersion());
    try {
        // newBioModel.setMIRIAMAnnotation(bioModelMetaData.getMIRIAMAnnotation());
        System.err.println("< < < < NEED TO GET VCMETADATA FROM METADATA TABLE ... METADATA IS EMPTY. > > > >");
        newBioModel.setModel(model);
        newBioModel.setSimulationContexts(scArray);
        // 
        for (int i = 0; i < simArray.length; i++) {
            boolean bMathFound = false;
            for (int j = 0; j < scArray.length; j++) {
                if (simArray[i].getMathDescription().getVersion().getVersionKey().compareEqual(scArray[j].getMathDescription().getVersion().getVersionKey())) {
                    simArray[i].setMathDescription(scArray[j].getMathDescription());
                    bMathFound = true;
                    break;
                }
            }
            if (!bMathFound) {
                System.out.println("<<<<WARNING>>>>> ClientDocumentManager.getBioModel(), Simulation " + simArray[i].getName() + " is orphaned, Math(" + simArray[i].getMathDescription().getName() + ") not found in Applications");
                simArray = (Simulation[]) BeanUtils.removeElement(simArray, simArray[i]);
                i--;
            }
        }
        newBioModel.setSimulations(simArray);
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace(System.out);
        throw new DataAccessException("PropertyVetoException caught " + e.getMessage());
    }
    // 
    // The BioModel is no longer cloned because the reference to this BioModel is no longer returned to the calling method.
    // the only possible side effect is the "BioModel:refreshDependencies()" method call.
    // this will reconnect internal listeners and other transient fields, and is not going to harm the cache integrity.
    // 
    // //
    // // clone BioModel (so that children can't be corrupted in the cache)
    // //
    // try {
    // newBioModel = (BioModel)BeanUtils.cloneSerializable(newBioModel);
    // }catch (Exception e){
    // e.printStackTrace(System.out);
    // throw new DataAccessException("BioModel clone failed: "+e.getMessage());
    // }
    newBioModel.refreshDependencies();
    // 
    return cbit.vcell.xml.XmlHelper.bioModelToXML(newBioModel);
}
Also used : KeyValue(org.vcell.util.document.KeyValue) BioModelMetaData(cbit.vcell.biomodel.BioModelMetaData) SimulationContext(cbit.vcell.mapping.SimulationContext) PropertyVetoException(java.beans.PropertyVetoException) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) MathModel(cbit.vcell.mathmodel.MathModel) BioModel(cbit.vcell.biomodel.BioModel) Model(cbit.vcell.model.Model) DataAccessException(org.vcell.util.DataAccessException)

Example 59 with Model

use of cbit.vcell.model.Model in project vcell by virtualcell.

the class SimContextTable method getSimContext.

/**
 * This method was created in VisualAge.
 * @return cbit.vcell.mapping.SimulationContext
 * @param rset java.sql.ResultSet
 * @param log cbit.vcell.server.SessionLog
 * @deprecated shouldn't do recursive query
 */
public SimulationContext getSimContext(QueryHashtable dbc, Connection con, User user, ResultSet rset, GeomDbDriver geomDB, ModelDbDriver modelDB, MathDescriptionDbDriver mathDB) throws SQLException, DataAccessException, java.beans.PropertyVetoException {
    java.math.BigDecimal groupid = rset.getBigDecimal(VersionTable.privacy_ColumnName);
    Version version = getVersion(rset, DbDriver.getGroupAccessFromGroupID(con, groupid));
    KeyValue geomKey = new KeyValue(rset.getBigDecimal(SimContextTable.table.geometryRef.toString()));
    Geometry geom = (Geometry) geomDB.getVersionable(dbc, con, user, VersionableType.Geometry, geomKey, false);
    KeyValue modelKey = new KeyValue(rset.getBigDecimal(SimContextTable.table.modelRef.toString()));
    Model model = (Model) modelDB.getVersionable(dbc, con, user, VersionableType.Model, modelKey);
    // 
    // read characteristic size (may be null)
    // 
    Double characteristicSize = null;
    BigDecimal size = rset.getBigDecimal(charSize.toString());
    if (!rset.wasNull() && size != null) {
        characteristicSize = new Double(size.doubleValue());
    }
    // 
    // get mathKey (may be null)
    // 
    MathDescription mathDesc = null;
    BigDecimal mathKeyValue = rset.getBigDecimal(SimContextTable.table.mathRef.toString());
    if (!rset.wasNull()) {
        KeyValue mathKey = new KeyValue(mathKeyValue);
        mathDesc = (MathDescription) mathDB.getVersionable(dbc, con, user, VersionableType.MathDescription, mathKey);
    }
    boolean bStochastic = mathDesc.isNonSpatialStoch() || mathDesc.isSpatialStoch() || mathDesc.isSpatialHybrid();
    boolean bRuleBased = mathDesc.isRuleBased();
    SimulationContext simContext = new SimulationContext(model, geom, mathDesc, version, bStochastic, bRuleBased);
    if (characteristicSize != null) {
        simContext.setCharacteristicSize(characteristicSize);
    }
    return simContext;
}
Also used : Geometry(cbit.vcell.geometry.Geometry) BigDecimal(java.math.BigDecimal) KeyValue(org.vcell.util.document.KeyValue) Version(org.vcell.util.document.Version) VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion) MathDescription(cbit.vcell.math.MathDescription) Model(cbit.vcell.model.Model) SimulationContext(cbit.vcell.mapping.SimulationContext) BigDecimal(java.math.BigDecimal)

Example 60 with Model

use of cbit.vcell.model.Model in project vcell by virtualcell.

the class ReactionCartoonTool method lineAction.

private void lineAction(SpeciesContext speciesContextStart, SpeciesContext speciesContextEnd) throws Exception {
    Structure endStructure = speciesContextEnd.getStructure();
    Structure startStructure = speciesContextStart.getStructure();
    Model model = getModel();
    ReactionStep reaction = null;
    Point startPos = edgeShape.getStart();
    Point endPos = edgeShape.getEnd();
    Structure reactionStructure = null;
    boolean bLumpedKinetics = false;
    if (startStructure != endStructure) {
        if (startStructure instanceof Feature && endStructure instanceof Feature) {
            // Feature-speciesContext ==> Feature-speciesContext
            Membrane membraneBetween = model.getStructureTopology().getMembrane((Feature) startStructure, (Feature) endStructure);
            // Feature-speciesContext ==> Feature-speciesContext with membrane in between : add reaction in Membrane (scStart : reactant; scEnd : pdt)
            if (membraneBetween != null) {
                reactionStructure = membraneBetween;
            } else {
                // Feature-speciesContext ==> Feature-speciesContext with no membrane between : create a lumped reaction in startFeature
                reactionStructure = startStructure;
                bLumpedKinetics = true;
            }
        } else if (startStructure instanceof Feature && endStructure instanceof Membrane) {
            // Feature-speciesContext ==> Membrane-speciesContext : create membrane reaction ; add scStart : reactant and scEnd : pdt.
            reactionStructure = endStructure;
        } else if (startStructure instanceof Membrane && endStructure instanceof Feature) {
            // Membrane-speciesContext ==> Feature-speciesContext : create reaction in membrane; scStart : reactant, scEnd : pdt.
            reactionStructure = startStructure;
        } else if (startStructure instanceof Membrane && endStructure instanceof Membrane) {
            // Membrane-speciesContext ==> Membrane-speciesContext : the 2 membranes are different : create lumped reaction in endMembrane
            reactionStructure = endStructure;
            bLumpedKinetics = true;
        }
    } else {
        // startStructure == endStructure : create reaction in structure
        reactionStructure = startStructure;
    }
    reaction = model.createSimpleReaction(reactionStructure);
    if (bLumpedKinetics) {
        reaction.setKinetics(new GeneralLumpedKinetics(reaction));
    }
    reaction.addReactant(speciesContextStart, 1);
    reaction.addProduct(speciesContextEnd, 1);
    positionShapeForObject(reactionStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
    getReactionCartoon().notifyChangeEvent();
    getGraphModel().clearSelection();
    getGraphModel().select(reaction);
}
Also used : ReactionStep(cbit.vcell.model.ReactionStep) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) GraphModel(cbit.gui.graph.GraphModel) Membrane(cbit.vcell.model.Membrane) Point(java.awt.Point) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) Structure(cbit.vcell.model.Structure) Feature(cbit.vcell.model.Feature)

Aggregations

Model (cbit.vcell.model.Model)107 BioModel (cbit.vcell.biomodel.BioModel)53 SpeciesContext (cbit.vcell.model.SpeciesContext)44 Expression (cbit.vcell.parser.Expression)42 Structure (cbit.vcell.model.Structure)35 PropertyVetoException (java.beans.PropertyVetoException)34 SimulationContext (cbit.vcell.mapping.SimulationContext)27 ReactionStep (cbit.vcell.model.ReactionStep)27 ModelParameter (cbit.vcell.model.Model.ModelParameter)23 ExpressionException (cbit.vcell.parser.ExpressionException)22 ArrayList (java.util.ArrayList)22 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)21 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)19 MathDescription (cbit.vcell.math.MathDescription)17 Feature (cbit.vcell.model.Feature)16 ModelException (cbit.vcell.model.ModelException)16 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)16 SubVolume (cbit.vcell.geometry.SubVolume)15 Parameter (cbit.vcell.model.Parameter)15 StructureMapping (cbit.vcell.mapping.StructureMapping)14