Search in sources :

Example 31 with Kinetics

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

the class ReactStepTable method getReactionStep.

/**
 * This method was created in VisualAge.
 * @return cbit.vcell.model.ReactionParticipant
 * @param rset java.sql.ResultSet
 */
public ReactionStep getReactionStep(Structure structure, Model model, KeyValue rsKey, java.sql.ResultSet rset, DatabaseSyntax dbSyntax) throws java.sql.SQLException, DataAccessException {
    KeyValue key = rsKey;
    if (rset.wasNull()) {
        key = null;
    }
    String reactType = rset.getString(ReactStepTable.table.reactType.toString());
    String reactionStepName = null;
    String nameString = rset.getString(ReactStepTable.table.name.toString());
    if (rset.wasNull()) {
        nameString = null;
    }
    if (nameString != null) {
        reactionStepName = TokenMangler.getSQLRestoredString(nameString);
    }
    ReactionStep rs = null;
    try {
        if (reactType.equals(ReactStepTable.REACTTYPE_FLUX_REVERSIBLE)) {
            rs = new FluxReaction(model, (Membrane) structure, key, reactionStepName, true);
        } else if (reactType.equals(ReactStepTable.REACTTYPE_FLUX_IRREVERSIBLE)) {
            rs = new FluxReaction(model, (Membrane) structure, key, reactionStepName, false);
        } else if (reactType.equals(ReactStepTable.REACTTYPE_SIMPLE_REVERSIBLE)) {
            rs = new SimpleReaction(model, structure, key, reactionStepName, true);
        } else if (reactType.equals(ReactStepTable.REACTTYPE_SIMPLE_IRREVERSIBLE)) {
            rs = new SimpleReaction(model, structure, key, reactionStepName, false);
        }
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace(System.out);
        throw new DataAccessException(e.getMessage());
    }
    // 
    // if valence is stored as a 'null', it was an error (previous models were updated administratively).
    // 
    int valenceValue = rset.getInt(ReactStepTable.table.chargeValence.toString());
    if (rset.wasNull()) {
        throw new DataAccessException("unexpected null for chargeValence");
    }
    // 
    // New procedure for getting kinetics
    // 
    String kinetics_vcml = DbDriver.varchar2_CLOB_get(rset, ReactStepTable.table.kineticsSmall, ReactStepTable.table.kineticsLarge, dbSyntax);
    if (kinetics_vcml == null || kinetics_vcml.length() == 0) {
        throw new DataAccessException("no data stored for kinetics");
    }
    // This isn't needed?
    // if (kinetics_vcml.endsWith(";}\n")){
    // StringBuffer buffer = new StringBuffer(kinetics_vcml.substring(0,kinetics_vcml.length()-2));
    // buffer.append("\n}\n");
    // kinetics_vcml = buffer.toString();
    // }
    org.vcell.util.CommentStringTokenizer tokens = new org.vcell.util.CommentStringTokenizer(kinetics_vcml);
    Kinetics kinetics = null;
    try {
        String token = tokens.nextToken();
        if (!token.equalsIgnoreCase(VCMODL.Kinetics)) {
            throw new DataAccessException("expected " + VCMODL.Kinetics);
        }
        token = tokens.nextToken();
        KineticsDescription kineticsDescription = KineticsDescription.fromVCMLKineticsName(token);
        if (kineticsDescription != null) {
            kinetics = kineticsDescription.createKinetics(rs);
        } else {
            throw new DataAccessException("expected valid kinetics type, read '" + token + "'");
        }
        kinetics.fromTokens(kinetics_vcml);
        // 
        // for debug purposes only, remove when unresolvedParameters are ok ... when globals exist
        // 
        // if (kinetics.getUnresolvedParameters().length!=0){
        // System.out.println("<<<WARNING>>> ReactStepTable.getReactionStep(key="+rsKey+") has "+kinetics.getUnresolvedParameters().length+" UnresolvedParameters");
        // for (int i = 0; i < kinetics.getUnresolvedParameters().length; i++){
        // System.out.println(">>>>>>>>>>>>> UnresolvedParameter["+i+"] = "+kinetics.getUnresolvedParameters()[i].toString());
        // }
        // }
        KineticsParameter chargeValenceParameter = kinetics.getChargeValenceParameter();
        if (chargeValenceParameter != null) {
            chargeValenceParameter.setExpression(new cbit.vcell.parser.Expression(valenceValue));
        }
    } catch (Exception e) {
        lg.error(e.getMessage(), e);
        throw new DataAccessException(e.getMessage());
    }
    rs.setKinetics(kinetics);
    // 
    // if physicsOptions is stored as a 'null', it was an error (previous models were updated administratively).
    // 
    int physicsOptionsValue = rset.getInt(ReactStepTable.table.physicsOptions.toString());
    if (rset.wasNull()) {
        throw new DataAccessException("unexpected null for physicsOptions");
    }
    try {
        rs.setPhysicsOptions(physicsOptionsValue);
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace(System.out);
    }
    String annot = rset.getString(ReactStepTable.table.annotation.getUnqualifiedColName());
    if (!rset.wasNull()) {
    // annot = TokenMangler.getSQLRestoredString(annot);
    // rs.setAnnotation(annot);
    }
    return rs;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) SimpleReaction(cbit.vcell.model.SimpleReaction) KineticsDescription(cbit.vcell.model.KineticsDescription) FluxReaction(cbit.vcell.model.FluxReaction) DataAccessException(org.vcell.util.DataAccessException) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ReactionStep(cbit.vcell.model.ReactionStep) Membrane(cbit.vcell.model.Membrane) Kinetics(cbit.vcell.model.Kinetics) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

Kinetics (cbit.vcell.model.Kinetics)31 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)21 ReactionStep (cbit.vcell.model.ReactionStep)17 Expression (cbit.vcell.parser.Expression)16 ModelParameter (cbit.vcell.model.Model.ModelParameter)11 ExpressionException (cbit.vcell.parser.ExpressionException)11 ReactionParticipant (cbit.vcell.model.ReactionParticipant)10 SpeciesContext (cbit.vcell.model.SpeciesContext)10 MassActionKinetics (cbit.vcell.model.MassActionKinetics)9 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)9 SimpleReaction (cbit.vcell.model.SimpleReaction)9 PropertyVetoException (java.beans.PropertyVetoException)9 LumpedKinetics (cbit.vcell.model.LumpedKinetics)8 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)8 Model (cbit.vcell.model.Model)7 Parameter (cbit.vcell.model.Parameter)7 Product (cbit.vcell.model.Product)7 Reactant (cbit.vcell.model.Reactant)7 FluxReaction (cbit.vcell.model.FluxReaction)6 StructureMapping (cbit.vcell.mapping.StructureMapping)5