Search in sources :

Example 26 with ReactionParticipant

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

the class ReactStepDbDriver method getReactionParticipant.

/**
 * This method was created in VisualAge.
 * @return cbit.vcell.model.ReactionParticipant
 * @param rset java.sql.ResultSet
 * @exception java.sql.SQLException The exception description.
 */
private ReactionParticipant getReactionParticipant(QueryHashtable dbc, Connection con, ResultSet rset, ReactionStep rs) throws SQLException, DataAccessException {
    // 
    // try to get ReactionParticipant from object cache
    // 
    KeyValue rpKey = new KeyValue(rset.getBigDecimal(ReactPartTable.table.id.toString()));
    ReactionParticipant rp = (ReactionParticipant) dbc.get(rpKey);
    if (rp != null) {
        return rp;
    }
    // 
    // get foreign keys
    // 
    KeyValue speciesContextKey = new KeyValue(rset.getBigDecimal(ReactPartTable.table.scRef.toString()));
    // 
    // get ReactionParticipant
    // 
    rp = reactPartTable.getReactionParticipant(rpKey, rset);
    // 
    // get referenced Objects (Species and Structure)
    // 
    SpeciesContext speciesContext = modelDB.getSpeciesContext(dbc, con, speciesContextKey);
    try {
        rp.setSpeciesContext(speciesContext);
    } catch (PropertyVetoException e) {
        e.printStackTrace(System.out);
        throw new DataAccessException("PropertyVetoException: " + e.getMessage());
    }
    rp.setReactionStep(rs);
    // ========== Since there is no flux carrier in fluxReaction, this is not required?? ===========
    // if (rp instanceof Flux && rs instanceof FluxReaction) {
    // try {
    // ((FluxReaction) rs).setFluxCarrier(speciesContext.getSpecies(), null);
    // }catch (ModelException e){
    // e.printStackTrace(System.out);
    // throw new DataAccessException("ModelException: "+e.getMessage());
    // }catch (PropertyVetoException e){
    // e.printStackTrace(System.out);
    // throw new DataAccessException("PropertyVetoException: "+e.getMessage());
    // }
    // }
    // 
    // stick ReactionParticipant in object cache
    // 
    dbc.put(rpKey, rp);
    return rp;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) KeyValue(org.vcell.util.document.KeyValue) SpeciesContext(cbit.vcell.model.SpeciesContext) ReactionParticipant(cbit.vcell.model.ReactionParticipant) DataAccessException(org.vcell.util.DataAccessException)

Example 27 with ReactionParticipant

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

the class ReactStepDbDriver method getReactionParticipants.

/**
 * getModel method comment.
 */
private ReactionParticipant[] getReactionParticipants(QueryHashtable dbc, Connection con, KeyValue reactStepID, ReactionStep rs) throws SQLException, DataAccessException, ObjectNotFoundException {
    if (reactStepID == null) {
        throw new IllegalArgumentException("Improper parameters for getReactionParticipants");
    }
    // log.print("ModelDbDriver.getReactionParticipants(reactStepID=" + reactStepID + ")");
    String sql;
    sql = " SELECT * " + " FROM " + reactPartTable.getTableName() + " WHERE " + reactPartTable.reactStepRef + " = " + reactStepID;
    // System.out.println(sql);
    java.util.Vector rpList = new java.util.Vector();
    Statement stmt = con.createStatement();
    try {
        ResultSet rset = stmt.executeQuery(sql);
        // 
        while (rset.next()) {
            ReactionParticipant rp = getReactionParticipant(dbc, con, rset, rs);
            rpList.addElement(rp);
        }
        // 
        if (rpList.size() == 0) {
            System.out.println("WARNING:::::ReactionParticipants for reactionStep(id=" + reactStepID + ") not found");
        }
    } finally {
        // Release resources include resultset
        stmt.close();
    }
    ReactionParticipant[] reactionParticipants = new ReactionParticipant[rpList.size()];
    rpList.copyInto(reactionParticipants);
    return reactionParticipants;
}
Also used : Vector(java.util.Vector) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) Vector(java.util.Vector) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Example 28 with ReactionParticipant

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

the class ReactionCartoonTool method getLineTypeFromDirection.

private LineType getLineTypeFromDirection(Shape startingShape, Point worldPoint) throws Exception {
    Shape mouseOverShape = getReactionCartoon().pickWorld(worldPoint);
    if (mouseOverShape instanceof ReactionStepShape) {
        if (startingShape instanceof SpeciesContextShape) {
            SpeciesContext speciesContext = (SpeciesContext) startingShape.getModelObject();
            // check if the ReactionStep already has a Product for this SpeciesContext
            ReactionStep reactionStep = (ReactionStep) mouseOverShape.getModelObject();
            ReactionParticipant[] rps = reactionStep.getReactionParticipants();
            if ((mouseOverShape instanceof SimpleReactionShape) || (mouseOverShape instanceof FluxReactionShape)) {
                for (int i = 0; i < rps.length; i++) {
                    if (rps[i] instanceof Reactant && rps[i].getSpeciesContext() == speciesContext) {
                        return LineType.NULL;
                    }
                }
                return LineType.REACTANT;
            }
        // else if (mouseOverShape instanceof FluxReactionShape){
        // for (int i = 0; i < rps.length; i++){
        // if ((rps[i] instanceof Reactant || rps[i] instanceof Product) && rps[i].getSpeciesContext() == speciesContext) {
        // return LineType.NULL;
        // }
        // }
        // return LineType.FLUX;
        // }
        }
    } else if (mouseOverShape instanceof SpeciesContextShape) {
        SpeciesContext speciesContext = (SpeciesContext) mouseOverShape.getModelObject();
        if (startingShape instanceof SpeciesContextShape) {
            // straight from one species to another ... will create a reaction upon release
            return LineType.PRODUCT;
        } else if (startingShape instanceof ReactionStepShape) {
            ReactionStep reactionStep = (ReactionStep) startingShape.getModelObject();
            ReactionParticipant[] rps = reactionStep.getReactionParticipants();
            // } else
            if (reactionStep instanceof SimpleReaction || reactionStep instanceof FluxReaction) {
                for (int i = 0; i < rps.length; i++) {
                    if (rps[i] instanceof Reactant && rps[i].getSpeciesContext() == speciesContext) {
                        return LineType.NULL;
                    }
                }
                return LineType.REACTANT;
            }
        }
    }
    return LineType.NULL;
}
Also used : SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) RubberBandRectShape(cbit.gui.graph.RubberBandRectShape) ProductShape(cbit.vcell.graph.ProductShape) ContainerShape(cbit.gui.graph.ContainerShape) CatalystShape(cbit.vcell.graph.CatalystShape) FluxReactionShape(cbit.vcell.graph.FluxReactionShape) ContainerContainerShape(cbit.vcell.graph.ContainerContainerShape) ReactantShape(cbit.vcell.graph.ReactantShape) ElipseShape(cbit.gui.graph.ElipseShape) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) Shape(cbit.gui.graph.Shape) RuleParticipantSignatureDiagramShape(cbit.vcell.graph.RuleParticipantSignatureDiagramShape) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) RubberBandEdgeShape(cbit.gui.graph.RubberBandEdgeShape) ReactionParticipantShape(cbit.vcell.graph.ReactionParticipantShape) SimpleReaction(cbit.vcell.model.SimpleReaction) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) FluxReaction(cbit.vcell.model.FluxReaction) SpeciesContext(cbit.vcell.model.SpeciesContext) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) Reactant(cbit.vcell.model.Reactant) Point(java.awt.Point) FluxReactionShape(cbit.vcell.graph.FluxReactionShape) ReactionStep(cbit.vcell.model.ReactionStep) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Example 29 with ReactionParticipant

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

the class ReactionCartoonTool method lineAction.

private void lineAction(SpeciesContext speciesContextStart, ReactionStep reactionEnd) throws Exception {
    Structure endStructure = reactionEnd.getStructure();
    Structure startStructure = speciesContextStart.getStructure();
    if (StructureUtil.reactionHereCanHaveParticipantThere(endStructure, startStructure)) {
        int stoichiometry = 1;
        Reactant reactant = null;
        for (ReactionParticipant participant : reactionEnd.getReactionParticipants()) {
            if (participant instanceof Reactant && participant.getSpeciesContext().equals(speciesContextStart)) {
                reactant = (Reactant) participant;
            }
        }
        if (reactant != null) {
            // only increase stoichiometry if reaction is SimpleReaction
            if (reactionEnd instanceof SimpleReaction) {
                reactant.setStoichiometry(reactant.getStoichiometry() + 1);
            }
            Shape shape = getReactionCartoon().getShapeFromModelObject(reactant);
            if (shape != null) {
                shape.refreshLabel();
            }
        } else {
            // add speciesContextEnd as pdt to reactionStart only if reactionStart is a SimpleRxn or if it is a FluxRxn and doesn't have a pdt.
            if (reactionEnd instanceof SimpleReaction || ((reactionEnd instanceof FluxReaction) && !(reactionEnd.hasReactant()))) {
                reactionEnd.addReactant(speciesContextStart, stoichiometry);
            }
        }
        if (((startStructure instanceof Feature && endStructure instanceof Feature) || (startStructure instanceof Membrane && endStructure instanceof Membrane)) && startStructure != endStructure) {
        // ============ change kinetics to lumped or warn user ?????????
        // simpleReactionEnd.setKinetics(new GeneralLumpedKinetics(simpleReactionEnd));
        }
        getReactionCartoon().notifyChangeEvent();
    }
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) RubberBandRectShape(cbit.gui.graph.RubberBandRectShape) ProductShape(cbit.vcell.graph.ProductShape) ContainerShape(cbit.gui.graph.ContainerShape) CatalystShape(cbit.vcell.graph.CatalystShape) FluxReactionShape(cbit.vcell.graph.FluxReactionShape) ContainerContainerShape(cbit.vcell.graph.ContainerContainerShape) ReactantShape(cbit.vcell.graph.ReactantShape) ElipseShape(cbit.gui.graph.ElipseShape) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) Shape(cbit.gui.graph.Shape) RuleParticipantSignatureDiagramShape(cbit.vcell.graph.RuleParticipantSignatureDiagramShape) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) RubberBandEdgeShape(cbit.gui.graph.RubberBandEdgeShape) ReactionParticipantShape(cbit.vcell.graph.ReactionParticipantShape) Membrane(cbit.vcell.model.Membrane) FluxReaction(cbit.vcell.model.FluxReaction) Structure(cbit.vcell.model.Structure) Reactant(cbit.vcell.model.Reactant) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Feature(cbit.vcell.model.Feature) Point(java.awt.Point)

Example 30 with ReactionParticipant

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

the class ReactionCartoonTool method deleteReactionsAndSpecies.

public static void deleteReactionsAndSpecies(Component requester, ReactionStep[] reactionStepArr, SpeciesContext[] speciesContextArr) throws Exception, UserCancelException {
    if ((speciesContextArr == null && reactionStepArr == null) || (reactionStepArr == null && speciesContextArr != null && speciesContextArr.length == 0) || (speciesContextArr == null && reactionStepArr != null && reactionStepArr.length == 0) || (speciesContextArr != null && speciesContextArr.length == 0 && reactionStepArr != null && reactionStepArr.length == 0)) {
        return;
    }
    int rxCount = (reactionStepArr != null ? reactionStepArr.length : 0);
    int speciesCount = (speciesContextArr != null ? speciesContextArr.length : 0);
    boolean bHasBoth = speciesCount > 0 && rxCount > 0;
    ReactionCartoon rxCartoon = null;
    if (requester instanceof GraphPane && ((GraphPane) requester).getGraphModel() instanceof ReactionCartoon) {
        rxCartoon = (ReactionCartoon) (((GraphPane) requester).getGraphModel());
    } else if (requester instanceof ReactionCartoonEditorPanel) {
        rxCartoon = ((ReactionCartoonEditorPanel) requester).getReactionCartoon();
    } else {
        throw new IllegalArgumentException("ReactionCartoonTool.deleteSpeciesContext not implemented for type '" + requester.getClass().getName() + "'");
    }
    DeleteSpeciesInfo deleteSpeciesInfo = null;
    final String DETAILS = "Details...";
    while (true) {
        String response = DialogUtils.showWarningDialog(requester, RXSPECIES_DELETE + " " + (bHasBoth ? "Reactions and Species." : (rxCount > 0 ? "Reactions." : (speciesCount > 0 ? "Species." : ""))), RXSPECIES_DELETE + " " + (bHasBoth ? rxCount + " Reactions and " + speciesCount + " Species." : (rxCount > 0 ? rxCount + " Reactions." : (speciesCount > 0 ? speciesCount + " Species." : ""))), new String[] { RXSPECIES_DELETE, DETAILS, RXSPECIES_CANCEL }, RXSPECIES_DELETE);
        if (response == null || response.equals(RXSPECIES_CANCEL)) {
            throw UserCancelException.CANCEL_GENERIC;
        }
        deleteSpeciesInfo = (deleteSpeciesInfo == null ? detailsDeleteSpecies(requester, speciesContextArr, reactionStepArr, rxCartoon) : deleteSpeciesInfo);
        if (response.equals(DETAILS)) {
            TableListResult tableListResult = showDeleteDetails(requester, deleteSpeciesInfo, reactionStepArr, false);
        // if(!tableListResult.selectedOption.equals(RXSPECIES_BACK)){
        // //if(!tableListResult.selectedOption.equals((bCut?RXSPECIES_CUT:RXSPECIES_DELETE))){
        // throw UserCancelException.CANCEL_GENERIC;
        // }
        } else {
            break;
        }
    }
    if (deleteSpeciesInfo != null) {
        for (Boolean errors : deleteSpeciesInfo.getbUnresolvableHashMap().values()) {
            if (errors) {
                while (true) {
                    String response = DialogUtils.showWarningDialog(requester, "Error warning.", "Warning: 1 or more SpeciesContexts have Model references that could cause Model corruption if " + RXSPECIES_DELETE + ".", new String[] { DETAILS, RXSPECIES_CANCEL }, DETAILS);
                    if (response == null || response.equals(RXSPECIES_CANCEL)) {
                        throw UserCancelException.CANCEL_GENERIC;
                    }
                    showDeleteDetails(requester, deleteSpeciesInfo, reactionStepArr, true);
                }
            }
        }
    }
    if (reactionStepArr != null) {
        for (int i = 0; i < reactionStepArr.length; i += 1) {
            rxCartoon.getModel().removeReactionStep(reactionStepArr[i]);
        }
    }
    if (deleteSpeciesInfo != null) {
        // remove all ReactionParticipants ("lines" between reaction and species in "Reaction Diagram") that have this speciesContext before deleting SpeciesContext
        for (SpeciesContext objSpeciesContext : deleteSpeciesInfo.getRxPartHashMap().keySet()) {
            if (deleteSpeciesInfo.getbUnresolvableHashMap().get(objSpeciesContext)) {
                continue;
            }
            Iterator<ReactionParticipant> iterRxPart = deleteSpeciesInfo.getRxPartHashMap().get(objSpeciesContext).iterator();
            while (iterRxPart.hasNext()) {
                ReactionParticipant objRxPart = iterRxPart.next();
                if (rxCartoon.getObjects().contains(objRxPart)) {
                    // Reaction delete may have already removed
                    objRxPart.getReactionStep().removeReactionParticipant(objRxPart);
                }
            }
        }
        // remove the SpeciesContext
        for (int i = 0; i < speciesContextArr.length; i++) {
            if (deleteSpeciesInfo.getbUnresolvableHashMap().get(speciesContextArr[i])) {
                continue;
            }
            if (rxCartoon.getObjects().contains(speciesContextArr[i])) {
                // Reaction delete may have already removed
                rxCartoon.getModel().removeSpeciesContext(speciesContextArr[i]);
            }
        }
    }
}
Also used : TableListResult(org.vcell.util.gui.DialogUtils.TableListResult) SpeciesContext(cbit.vcell.model.SpeciesContext) GraphPane(cbit.gui.graph.gui.GraphPane) Point(java.awt.Point) ReactionCartoon(cbit.vcell.graph.ReactionCartoon) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Aggregations

ReactionParticipant (cbit.vcell.model.ReactionParticipant)55 Reactant (cbit.vcell.model.Reactant)30 SpeciesContext (cbit.vcell.model.SpeciesContext)30 ReactionStep (cbit.vcell.model.ReactionStep)29 Product (cbit.vcell.model.Product)26 SimpleReaction (cbit.vcell.model.SimpleReaction)20 Structure (cbit.vcell.model.Structure)19 Expression (cbit.vcell.parser.Expression)18 FluxReaction (cbit.vcell.model.FluxReaction)16 Catalyst (cbit.vcell.model.Catalyst)14 ArrayList (java.util.ArrayList)14 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)13 Model (cbit.vcell.model.Model)13 ExpressionException (cbit.vcell.parser.ExpressionException)13 Membrane (cbit.vcell.model.Membrane)12 PropertyVetoException (java.beans.PropertyVetoException)12 Kinetics (cbit.vcell.model.Kinetics)11 Point (java.awt.Point)10 HashMap (java.util.HashMap)10 Shape (cbit.gui.graph.Shape)9