Search in sources :

Example 6 with ElectricalTopology

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

the class GHKKinetics method updateGeneratedExpressions.

/**
 * Insert the method's description here.
 * Creation date: (10/19/2003 12:05:14 AM)
 * @exception cbit.vcell.parser.ExpressionException The exception description.
 */
protected void updateGeneratedExpressions() throws ExpressionException, PropertyVetoException {
    KineticsParameter currentParm = getKineticsParameterFromRole(ROLE_CurrentDensity);
    KineticsParameter rateParm = getKineticsParameterFromRole(ROLE_ReactionRate);
    if (currentParm == null && rateParm == null) {
        return;
    }
    Membrane membrane = (Membrane) getReactionStep().getStructure();
    if (!(getReactionStep().getStructure() instanceof Membrane)) {
        return;
    }
    ElectricalTopology electricalTopology = getReactionStep().getModel().getElectricalTopology();
    Membrane.MembraneVoltage V = membrane.getMembraneVoltage();
    Feature negativeFeature = electricalTopology.getNegativeFeature(membrane);
    Feature positiveFeature = electricalTopology.getPositiveFeature(membrane);
    if (negativeFeature == null || positiveFeature == null) {
        return;
    }
    KineticsParameter P = getKineticsParameterFromRole(ROLE_Permeability);
    Model model = getReactionStep().getModel();
    Expression F = getSymbolExpression(model.getFARADAY_CONSTANT());
    Expression K_GHK = getSymbolExpression(model.getK_GHK());
    Expression R = getSymbolExpression(model.getGAS_CONSTANT());
    Expression T = getSymbolExpression(model.getTEMPERATURE());
    ReactionParticipant[] reactionParticipants = getReactionStep().getReactionParticipants();
    ReactionParticipant Neg0 = null;
    ReactionParticipant Pos0 = null;
    for (int i = 0; i < reactionParticipants.length; i++) {
        ReactionParticipant rp = reactionParticipants[i];
        if ((rp instanceof Reactant || rp instanceof Product)) {
            if (rp.getStructure() == negativeFeature) {
                Neg0 = rp;
            } else if (rp.getStructure() == positiveFeature) {
                Pos0 = rp;
            }
        }
    }
    // "-A0*pow("+VALENCE_SYMBOL+",2)*"+VOLTAGE_SYMBOL+"*pow("+F+",2)/("+R+"*"+T+")*(R0-(P0*exp(-"+VALENCE_SYMBOL+"*"+F+"*"+VOLTAGE_SYMBOL+"/("+R+"*"+T+"))))/(1 - exp(-"+VALENCE_SYMBOL+"*"+F+"*"+VOLTAGE_SYMBOL+"/("+R+"*"+T+")))"
    if (Neg0 != null && Pos0 != null && P != null) {
        // PRIMARY CURRENT DENSITY
        // 
        Expression V_exp = getSymbolExpression(V);
        Expression carrier_z = getSymbolExpression(getKineticsParameterFromRole(Kinetics.ROLE_CarrierChargeValence));
        Expression net_z = carrier_z;
        Expression Neg0_exp = getSymbolExpression(Neg0.getSpeciesContext());
        Expression Pos0_exp = getSymbolExpression(Pos0.getSpeciesContext());
        Expression P_exp = getSymbolExpression(P);
        Expression exponentTerm = Expression.div(Expression.mult(Expression.negate(carrier_z), F, V_exp), Expression.mult(R, T));
        Expression expTerm = Expression.exp(exponentTerm);
        Expression term1 = Expression.add(Pos0_exp, Expression.negate(Expression.mult(Neg0_exp, expTerm)));
        Expression numerator = Expression.negate(Expression.mult(P_exp, K_GHK, Expression.power(carrier_z, 2.0), V_exp, Expression.power(F, 2.0), term1));
        Expression denominator = Expression.mult(R, T, Expression.add(new Expression(1.0), Expression.negate(expTerm)));
        Expression newCurrExp = Expression.div(numerator, denominator);
        // Expression newCurrExp = new Expression("-"+P.getName()+"*"+K_GHK.getName()+"*pow("+z+",2)*"+V.getName()+"*pow("+F.getName()+",2)/("+R.getName()+"*"+T.getName()+")*("+R0.getName()+"-("+P0.getName()+"*exp(-"+z+"*"+F.getName()+"*"+V.getName()+"/("+R.getName()+"*"+T.getName()+"))))/(1 - exp(-"+z+"*"+F.getName()+"*"+V.getName()+"/("+R.getName()+"*"+T.getName()+")))");
        currentParm.setExpression(newCurrExp);
        // SECONDARY REACTION RATE
        // update from current density
        updateReactionRatesFromInwardCurrentDensity();
    }
}
Also used : Expression(cbit.vcell.parser.Expression) ElectricalTopology(cbit.vcell.model.Model.ElectricalTopology)

Example 7 with ElectricalTopology

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

the class ModelDbDriver method insertModel.

/**
 * This method was created in VisualAge.
 * @param model cbit.vcell.model.Model
 */
private void insertModel(InsertHashtable hash, Connection con, User user, Model model, Version newVersion) throws SQLException, DataAccessException, RecordChangedException {
    // 
    // insert model record
    // 
    insertModelSQL(con, user, model, newVersion);
    hash.put(model, newVersion.getVersionKey());
    // 
    // make sure all species are in the database and the hashtable
    // 
    StructureTopology structureTopology = model.getStructureTopology();
    ElectricalTopology electricalTopology = model.getElectricalTopology();
    Species[] speciesArray = model.getSpecies();
    for (int i = 0; i < speciesArray.length; i++) {
        // speciesArray[i].getKey();
        KeyValue speciesKey = null;
        // if (speciesKey == null) {
        speciesKey = reactStepDB.insertSpecies(hash, con, speciesArray[i], user);
        // throw new DataAccessException("Database error: species "+species.getName()+" has null key");
        // }else if (speciesArray[i].getOwnerKey()!=null && speciesArray[i].getOwnerKey()==user.getID()){
        // reactStepDB.updateSpecies(con,speciesArray[i],user);
        // }
        // if (hash.getDatabaseKey(speciesArray[i])==null){
        hash.put(speciesArray[i], speciesKey);
    // }
    }
    // 
    // make sure all structures are in the database and the hashtable (add entry to link table)
    // this does not populate the parent, negativeFeature, and positiveFeature columns ... done later with updateStructureKeys()
    // 
    Structure[] structures = model.getStructures();
    for (int i = 0; i < structures.length; i++) {
        Structure structure = (Structure) structures[i];
        KeyValue structureKey = null;
        if (hash.getDatabaseKey(structure) == null) {
            structureKey = reactStepDB.insertStructure(hash, con, structure);
        }
        KeyValue linkKey = keyFactory.getNewKey(con);
        insertModelStructLinkSQL(con, linkKey, newVersion.getVersionKey(), /*modelKey*/
        hash.getDatabaseKey(structure));
    }
    // 
    for (Structure structure : structures) {
        KeyValue structKey = hash.getDatabaseKey(structure);
        KeyValue parentKey = null;
        Structure parentStruct = structureTopology.getParentStructure(structure);
        if (parentStruct != null) {
            parentKey = hash.getDatabaseKey(parentStruct);
        }
        KeyValue negKey = null;
        KeyValue posKey = null;
        if (structure instanceof Membrane) {
            Membrane membrane = (Membrane) structure;
            Feature negFeature = electricalTopology.getNegativeFeature(membrane);
            if (negFeature != null) {
                negKey = hash.getDatabaseKey(negFeature);
            }
            Feature posFeature = electricalTopology.getPositiveFeature(membrane);
            if (posFeature != null) {
                posKey = hash.getDatabaseKey(posFeature);
            }
        }
        StructureKeys structureKeys = new StructureKeys(structKey, parentKey, posKey, negKey);
        reactStepDB.updateStructureKeys(con, structureKeys);
    }
    // 
    // make sure all speciesContexts are in database and the hashtable
    // 
    SpeciesContext[] speciesContexts = model.getSpeciesContexts();
    for (int i = 0; i < speciesContexts.length; i++) {
        SpeciesContext sc = speciesContexts[i];
        if (hash.getDatabaseKey(sc) == null) {
            insertSpeciesContextSQL(hash, con, keyFactory.getNewKey(con), sc, newVersion.getVersionKey());
        }
    }
    // 
    // insert all reactionSteps
    // 
    ReactionStep[] reactionSteps = model.getReactionSteps();
    for (int i = 0; i < reactionSteps.length; i++) {
        ReactionStep rs = reactionSteps[i];
        if (hash.getDatabaseKey(rs) == null) {
            reactStepDB.insertReactionStep(hash, con, user, rs, newVersion.getVersionKey());
        }
    }
    // 
    // insert diagrams
    // 
    Diagram[] diagrams = model.getDiagrams();
    for (int i = 0; i < diagrams.length; i++) {
        Diagram diagram = diagrams[i];
        KeyValue key = keyFactory.getNewKey(con);
        KeyValue structKey = hash.getDatabaseKey(diagram.getStructure());
        if (structKey != null) {
            insertDiagramSQL(con, key, diagram, newVersion.getVersionKey(), /*modelKey*/
            hash.getDatabaseKey(diagram.getStructure()));
        } else {
            if (lg.isWarnEnabled())
                lg.warn("ModelDbDriver.insertModel(),  diagram " + diagram.toString() + " is orphaned, check Model logic");
        }
    }
    // 
    // insert GlobalModelParameters
    // 
    // //-----------------testing remove
    // try{
    // Model.ModelParameter testParam = model.new ModelParameter("test",new Expression("1.0"),Model.ROLE_UserDefined,VCUnitDefinition.UNIT_molecules);
    // model.setModelParameters(new Model.ModelParameter[] {testParam});
    // }catch(Exception e){
    // e.printStackTrace();
    // }
    // //-----------------
    GlobalModelParameterTable.table.insertModelParameters(con, keyFactory, model.getModelParameters(), newVersion.getVersionKey());
}
Also used : KeyValue(org.vcell.util.document.KeyValue) StructureTopology(cbit.vcell.model.Model.StructureTopology) ElectricalTopology(cbit.vcell.model.Model.ElectricalTopology) SpeciesContext(cbit.vcell.model.SpeciesContext) Feature(cbit.vcell.model.Feature) Diagram(cbit.vcell.model.Diagram) StructureKeys(cbit.vcell.modeldb.ReactStepDbDriver.StructureKeys) ReactionStep(cbit.vcell.model.ReactionStep) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) Species(cbit.vcell.model.Species)

Aggregations

ElectricalTopology (cbit.vcell.model.Model.ElectricalTopology)7 Feature (cbit.vcell.model.Feature)5 Membrane (cbit.vcell.model.Membrane)4 Expression (cbit.vcell.parser.Expression)3 Edge (cbit.util.graph.Edge)2 StructureTopology (cbit.vcell.model.Model.StructureTopology)2 Structure (cbit.vcell.model.Structure)2 Graph (cbit.util.graph.Graph)1 Node (cbit.util.graph.Node)1 CurrentDensityClampStimulus (cbit.vcell.mapping.CurrentDensityClampStimulus)1 ElectricalStimulus (cbit.vcell.mapping.ElectricalStimulus)1 Electrode (cbit.vcell.mapping.Electrode)1 MembraneMapping (cbit.vcell.mapping.MembraneMapping)1 TotalCurrentClampStimulus (cbit.vcell.mapping.TotalCurrentClampStimulus)1 VoltageClampStimulus (cbit.vcell.mapping.VoltageClampStimulus)1 Diagram (cbit.vcell.model.Diagram)1 MembraneVoltage (cbit.vcell.model.Membrane.MembraneVoltage)1 Model (cbit.vcell.model.Model)1 ReactionStep (cbit.vcell.model.ReactionStep)1 Species (cbit.vcell.model.Species)1