Search in sources :

Example 21 with SimpleReaction

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

the class ReactionCartoonTool method lineActon.

private void lineActon(Structure startStructure, ReactionStep reactionEnd) throws Exception {
    Structure endStructure = reactionEnd.getStructure();
    if (StructureUtil.reactionHereCanHaveParticipantThere(endStructure, startStructure)) {
        // if reactionStart is a SimpleRxn OR FluxRxn without a product, add speciesContext as reactant
        if ((reactionEnd instanceof SimpleReaction) || ((reactionEnd instanceof FluxReaction) && !reactionEnd.hasReactant())) {
            SpeciesContext speciesContext = getReactionCartoon().getModel().createSpeciesContext(startStructure);
            reactionEnd.addReactant(speciesContext, 1);
            positionShapeForObject(startStructure, speciesContext, edgeShape.getStart());
        }
        if (((startStructure instanceof Feature && endStructure instanceof Feature) || (startStructure instanceof Membrane && endStructure instanceof Membrane)) && startStructure != endStructure) {
        // ============ change kinetics to lumped or warn user ?????????
        // simpleReaction.setKinetics(new GeneralLumpedKinetics(simpleReaction));
        }
        getReactionCartoon().notifyChangeEvent();
    }
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) Membrane(cbit.vcell.model.Membrane) FluxReaction(cbit.vcell.model.FluxReaction) SpeciesContext(cbit.vcell.model.SpeciesContext) Structure(cbit.vcell.model.Structure) Feature(cbit.vcell.model.Feature)

Example 22 with SimpleReaction

use of cbit.vcell.model.SimpleReaction 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 23 with SimpleReaction

use of cbit.vcell.model.SimpleReaction 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 24 with SimpleReaction

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

the class ReactionCartoonTool method lineAction.

private void lineAction(Structure startStructure, Structure endStructure, Shape endShape) throws Exception, PropertyVetoException, ExpressionException {
    Point startPos = edgeShape.getStart();
    Point endPos = edgeShape.getEnd();
    if (endStructure.equals(startStructure)) {
        SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
        SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
        SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(endStructure);
        reaction.addReactant(speciesContext1, 1);
        reaction.addProduct(speciesContext2, 1);
        getReactionCartoon().notifyChangeEvent();
        positionShapeForObject(endStructure, speciesContext1, startPos);
        positionShapeForObject(endStructure, speciesContext2, endPos);
        positionShapeForObject(endStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
        getGraphModel().clearSelection();
        getGraphModel().select(reaction);
    } else {
        if (endStructure instanceof Membrane && startStructure instanceof Feature) {
            Membrane endMembrane = (Membrane) endStructure;
            Feature startFeature = (Feature) startStructure;
            // if(structTopology.getOutsideFeature(endMembrane).equals(startFeature) || structTopology.getInsideFeature(endMembrane).equals(startFeature))
            // {
            SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startFeature);
            SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endMembrane);
            SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(endMembrane);
            reaction.addReactant(speciesContext1, 1);
            reaction.addProduct(speciesContext2, 1);
            getReactionCartoon().notifyChangeEvent();
            positionShapeForObject(startFeature, speciesContext1, startPos);
            positionShapeForObject(endMembrane, speciesContext2, endPos);
            // finding correct insertion point for reaction, statements below should be put into a utility if used often
            int memAbsXmin = endShape.getSpaceManager().getAbsLoc().x;
            int memAbsXmax = memAbsXmin + endShape.getSpaceManager().getSize().width;
            int reactionWidth = new SimpleReactionShape(reaction, getReactionCartoon()).getSpaceManager().getSize().width;
            int reactionAbsX = (startPos.x + endPos.x) / 2;
            if ((memAbsXmax - memAbsXmin) <= reactionWidth) {
                reactionAbsX = memAbsXmin;
            } else {
                reactionAbsX = Math.max(reactionAbsX, memAbsXmin);
                reactionAbsX = Math.min(reactionAbsX, (memAbsXmax - reactionWidth));
            }
            positionShapeForObject(endMembrane, reaction, new Point(reactionAbsX, (startPos.y + endPos.y) / 2));
            getGraphModel().clearSelection();
            getGraphModel().select(reaction);
        // }
        } else if (endStructure instanceof Feature && startStructure instanceof Membrane) {
            Membrane startMembrane = (Membrane) startStructure;
            Feature endFeature = (Feature) endStructure;
            // if(structTopology.getOutsideFeature(startMembrane).equals(endFeature) || structTopology.getInsideFeature(startMembrane).equals(endFeature))
            // {
            SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startMembrane);
            SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endFeature);
            SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(startMembrane);
            reaction.addReactant(speciesContext1, 1);
            reaction.addProduct(speciesContext2, 1);
            getReactionCartoon().notifyChangeEvent();
            positionShapeForObject(startMembrane, speciesContext1, startPos);
            positionShapeForObject(endFeature, speciesContext2, endPos);
            // finding correct insertion point for reaction, statements below should be put into a utility if used often
            int memAbsXmin = startShape.getSpaceManager().getAbsLoc().x;
            int memAbsXmax = memAbsXmin + startShape.getSpaceManager().getSize().width;
            int reactionWidth = new SimpleReactionShape(reaction, getReactionCartoon()).getSpaceManager().getSize().width;
            int reactionAbsX = (startPos.x + endPos.x) / 2;
            if ((memAbsXmax - memAbsXmin) <= reactionWidth) {
                reactionAbsX = memAbsXmin;
            } else {
                reactionAbsX = Math.max(reactionAbsX, memAbsXmin);
                reactionAbsX = Math.min(reactionAbsX, (memAbsXmax - reactionWidth));
            }
            positionShapeForObject(startMembrane, reaction, new Point(reactionAbsX, (startPos.y + endPos.y) / 2));
            getGraphModel().clearSelection();
            getGraphModel().select(reaction);
        // }
        } else if (endStructure instanceof Feature && startStructure instanceof Feature) {
            Feature startFeature = (Feature) startStructure;
            Feature endFeature = (Feature) endStructure;
            SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startStructure);
            SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
            SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(startStructure);
            reaction.addReactant(speciesContext1, 1);
            reaction.addProduct(speciesContext2, 1);
            reaction.setKinetics(new GeneralLumpedKinetics(reaction));
            getReactionCartoon().notifyChangeEvent();
            positionShapeForObject(startStructure, speciesContext1, startPos);
            positionShapeForObject(endStructure, speciesContext2, endPos);
            positionShapeForObject(startStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
            getGraphModel().clearSelection();
            getGraphModel().select(reaction);
        } else if (endStructure instanceof Membrane && startStructure instanceof Membrane) {
            SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startStructure);
            SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
            SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(startStructure);
            reaction.addReactant(speciesContext1, 1);
            reaction.addProduct(speciesContext2, 1);
            reaction.setKinetics(new GeneralLumpedKinetics(reaction));
            getReactionCartoon().notifyChangeEvent();
            positionShapeForObject(startStructure, speciesContext1, startPos);
            positionShapeForObject(endStructure, speciesContext2, endPos);
            positionShapeForObject(startStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
            getGraphModel().clearSelection();
            getGraphModel().select(reaction);
        }
    }
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) Membrane(cbit.vcell.model.Membrane) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) Point(java.awt.Point) SpeciesContext(cbit.vcell.model.SpeciesContext) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) Feature(cbit.vcell.model.Feature) Point(java.awt.Point)

Example 25 with SimpleReaction

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

the class SimpleReactionPanel method setSimpleReaction.

/**
 * Sets the simpleReaction property (cbit.vcell.model.SimpleReaction) value.
 * @param simpleReaction The new value for the property.
 * @see #getSimpleReaction
 */
public void setSimpleReaction(SimpleReaction simpleReaction) {
    SimpleReaction oldValue = fieldSimpleReaction;
    fieldSimpleReaction = simpleReaction;
    firePropertyChange("simpleReaction", oldValue, simpleReaction);
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction)

Aggregations

SimpleReaction (cbit.vcell.model.SimpleReaction)49 FluxReaction (cbit.vcell.model.FluxReaction)26 SpeciesContext (cbit.vcell.model.SpeciesContext)22 ReactionParticipant (cbit.vcell.model.ReactionParticipant)20 ReactionStep (cbit.vcell.model.ReactionStep)19 Structure (cbit.vcell.model.Structure)19 Expression (cbit.vcell.parser.Expression)19 Membrane (cbit.vcell.model.Membrane)16 Feature (cbit.vcell.model.Feature)15 Reactant (cbit.vcell.model.Reactant)15 ArrayList (java.util.ArrayList)14 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)13 Product (cbit.vcell.model.Product)12 PropertyVetoException (java.beans.PropertyVetoException)12 Model (cbit.vcell.model.Model)10 Kinetics (cbit.vcell.model.Kinetics)9 MassActionKinetics (cbit.vcell.model.MassActionKinetics)9 Point (java.awt.Point)9 Shape (cbit.gui.graph.Shape)8 BioModel (cbit.vcell.biomodel.BioModel)7