Search in sources :

Example 16 with FluxReaction

use of cbit.vcell.model.FluxReaction 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 17 with FluxReaction

use of cbit.vcell.model.FluxReaction 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 18 with FluxReaction

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

the class ReactionCartoonTool method mouseClicked.

@Override
public void mouseClicked(MouseEvent event) {
    Point screenPoint = new Point(event.getX(), event.getY());
    Point worldPoint = screenToWorld(screenPoint);
    try {
        if (event.getButton() != MouseEvent.BUTTON1) {
            return;
        }
        switch(mode) {
            case SELECT:
                {
                    if (event.getClickCount() == 2) {
                        final Shape selectedShape = getReactionCartoon().getSelectedShape();
                        if (selectedShape instanceof ReactionContainerShape || selectedShape instanceof SpeciesContextShape || selectedShape instanceof SimpleReactionShape || selectedShape instanceof FluxReactionShape || selectedShape instanceof ReactionRuleDiagramShape || selectedShape instanceof RuleParticipantSignatureDiagramShape) {
                            editInPlace(selectedShape, worldPoint);
                        }
                        if (selectedShape != null) {
                            menuAction(selectedShape, CartoonToolMiscActions.Properties.MENU_ACTION);
                        }
                    }
                    break;
                }
            case STEP:
                {
                    Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
                    if (pickedShape instanceof ReactionContainerShape) {
                        Structure structure = ((ReactionContainerShape) pickedShape).getStructure();
                        if (getReactionCartoon().getStructureSuite().areReactionsShownFor(structure)) {
                            ReactionStep reactionStep = getReactionCartoon().getModel().createSimpleReaction(structure);
                            positionShapeForObject(structure, reactionStep, worldPoint);
                            saveDiagram();
                        }
                    }
                    break;
                }
            case FLUX:
                {
                    Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
                    if (pickedShape instanceof ReactionContainerShape) {
                        Structure structure = ((ReactionContainerShape) pickedShape).getStructure();
                        if (structure instanceof Membrane) {
                            Membrane membrane = (Membrane) structure;
                            FluxReaction fluxReaction = getReactionCartoon().getModel().createFluxReaction(membrane);
                            ReactionStepShape frShape = (ReactionStepShape) getReactionCartoon().getShapeFromModelObject(fluxReaction);
                            Point parentLocation = frShape.getParent().getSpaceManager().getAbsLoc();
                            frShape.getSpaceManager().setRelPos(worldPoint.x - parentLocation.x, worldPoint.y - parentLocation.y);
                            saveDiagram();
                        // setMode(SELECT_MODE);
                        } else {
                        // setMode(SELECT_MODE);
                        // throw new Exception("fluxes only applicable to membranes");
                        }
                    }
                    break;
                }
            case SPECIES:
                {
                    Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
                    if (pickedShape instanceof ReactionContainerShape) {
                        SpeciesContext speciesContext = getReactionCartoon().getModel().createSpeciesContext(((ReactionContainerShape) pickedShape).getStructure());
                        reactionCartoon.clearSelection();
                        getGraphModel().select(speciesContext);
                        positionShapeForObject(speciesContext.getStructure(), speciesContext, worldPoint);
                        // showCreateSpeciesContextDialog(getGraphPane(), getReactionCartoon().getModel(), ((ReactionContainerShape) pickedShape).getStructure(), scShapeLocation);
                        saveDiagram();
                    }
                }
            default:
                break;
        }
    } catch (Exception e) {
        System.out.println("CartoonTool.mouseClicked: uncaught exception");
        e.printStackTrace(System.out);
        Point canvasLoc = getGraphPane().getLocationOnScreen();
        canvasLoc.x += screenPoint.x;
        canvasLoc.y += screenPoint.y;
        DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
    }
}
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) ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) FluxReaction(cbit.vcell.model.FluxReaction) Point(java.awt.Point) SpeciesContext(cbit.vcell.model.SpeciesContext) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) PropertyVetoException(java.beans.PropertyVetoException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) FluxReactionShape(cbit.vcell.graph.FluxReactionShape) ReactionStep(cbit.vcell.model.ReactionStep) Membrane(cbit.vcell.model.Membrane) RuleParticipantSignatureDiagramShape(cbit.vcell.graph.RuleParticipantSignatureDiagramShape) Structure(cbit.vcell.model.Structure)

Example 19 with FluxReaction

use of cbit.vcell.model.FluxReaction 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 20 with FluxReaction

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

the class TransformMassActions method transformOne.

public TransformedReaction transformOne(ReactionStep origRS) throws PropertyVetoException, IOException, ClassNotFoundException {
    TransformedReaction transformedRS = new TransformedReaction();
    if (origRS instanceof SimpleReaction) {
        // we separate mass action and general law, because if it passes, mass action uses label 'ok' and general uses label 'stochastic capable'
        if (origRS.getKinetics().getKineticsDescription().equals(KineticsDescription.MassAction)) {
            Expression rateExp = origRS.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate).getExpression();
            try {
                Parameter forwardRateParameter = origRS.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_KForward);
                Parameter reverseRateParameter = origRS.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_KReverse);
                MassActionSolver.MassActionFunction maFunc = MassActionSolver.solveMassAction(forwardRateParameter, reverseRateParameter, rateExp, origRS);
                // set transformed reaction step
                transformedRS.setTransformType(TransformedReaction.TRANSFORMABLE_WITH_NOCHANGE);
                transformedRS.setTransformRemark(TransformedReaction.Label_Ok);
                transformedRS.setMassActionFunction(maFunc);
            } catch (Exception e) {
                // Mass Action Solver failed to parse the rate expression
                transformedRS.setMassActionFunction(new MassActionSolver.MassActionFunction());
                transformedRS.setTransformType(TransformedReaction.NOTRANSFORMABLE);
                transformedRS.setTransformRemark(TransformedReaction.Label_Failed + " " + e.getMessage());
            }
        } else if (origRS.getKinetics().getKineticsDescription().equals(KineticsDescription.General)) {
            Expression rateExp = origRS.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate).getExpression();
            try {
                Parameter forwardRateParameter = null;
                Parameter reverseRateParameter = null;
                MassActionSolver.MassActionFunction maFunc = MassActionSolver.solveMassAction(forwardRateParameter, reverseRateParameter, rateExp, origRS);
                // set transformed reaction step
                transformedRS.setMassActionFunction(maFunc);
                // if number of reactant is 0, or number of product is 0, we can not transform it to mass action law
                if (((SimpleReaction) origRS).getNumReactants() == 0 || ((SimpleReaction) origRS).getNumProducts() == 0) {
                    transformedRS.setTransformType(TransformedReaction.NOTRANSFORMABLE_STOCHCAPABLE);
                    transformedRS.setTransformRemark(TransformedReaction.Label_StochForm_NotTransformable);
                } else {
                    transformedRS.setTransformType(TransformedReaction.TRANSFORMABLE);
                    transformedRS.setTransformRemark(TransformedReaction.Label_Transformable);
                }
            } catch (Exception e) {
                // Mass Action Solver failed to parse the rate expression
                transformedRS.setMassActionFunction(new MassActionSolver.MassActionFunction());
                transformedRS.setTransformType(TransformedReaction.NOTRANSFORMABLE);
                transformedRS.setTransformRemark(TransformedReaction.Label_Failed + " " + e.getMessage());
            }
        } else // other kinetic rate laws other than MassAction and General
        {
            transformedRS.setMassActionFunction(new MassActionSolver.MassActionFunction());
            transformedRS.setTransformType(TransformedReaction.NOTRANSFORMABLE);
            transformedRS.setTransformRemark(TransformedReaction.Label_Failed + TransformedReaction.Label_FailedOtherReacLaw);
        }
    } else // flux
    {
        if (origRS instanceof FluxReaction) {
            // fluxes which are described by general density function/permeability
            if (origRS.getKinetics().getKineticsDescription().equals(KineticsDescription.General) || origRS.getKinetics().getKineticsDescription().equals(KineticsDescription.GeneralPermeability)) {
                Expression rateExp = origRS.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate).getExpression();
                try {
                    // forward and reverse rate parameters may be null
                    Parameter forwardRateParameter = null;
                    Parameter reverseRateParameter = null;
                    if (origRS.getKinetics().getKineticsDescription().equals(KineticsDescription.GeneralPermeability)) {
                        forwardRateParameter = origRS.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_Permeability);
                        reverseRateParameter = origRS.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_Permeability);
                    }
                    MassActionSolver.MassActionFunction maFunc = MassActionSolver.solveMassAction(forwardRateParameter, reverseRateParameter, rateExp, origRS);
                    // set transformed reaction step
                    transformedRS.setMassActionFunction(maFunc);
                    transformedRS.setTransformType(TransformedReaction.NOTRANSFORMABLE_STOCHCAPABLE);
                    transformedRS.setTransformRemark(TransformedReaction.Label_StochForm_NotTransformable);
                } catch (Exception e) {
                    // Mass Action Solver failed to parse the rate expression
                    transformedRS.setMassActionFunction(new MassActionSolver.MassActionFunction());
                    transformedRS.setTransformType(TransformedReaction.NOTRANSFORMABLE);
                    transformedRS.setTransformRemark(TransformedReaction.Label_Failed + " " + e.getMessage());
                }
            } else // other fluxes which are not described by general density function or general permeability
            {
                transformedRS.setMassActionFunction(new MassActionSolver.MassActionFunction());
                transformedRS.setTransformType(TransformedReaction.NOTRANSFORMABLE);
                transformedRS.setTransformRemark(TransformedReaction.Label_Failed + TransformedReaction.Label_FailedOtherFluxLaw);
            }
        }
    }
    return transformedRS;
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) Expression(cbit.vcell.parser.Expression) MassActionFunction(cbit.vcell.model.MassActionSolver.MassActionFunction) Parameter(cbit.vcell.model.Parameter) FluxReaction(cbit.vcell.model.FluxReaction) MassActionSolver(cbit.vcell.model.MassActionSolver) MassActionFunction(cbit.vcell.model.MassActionSolver.MassActionFunction) PropertyVetoException(java.beans.PropertyVetoException) IOException(java.io.IOException)

Aggregations

FluxReaction (cbit.vcell.model.FluxReaction)35 SimpleReaction (cbit.vcell.model.SimpleReaction)26 SpeciesContext (cbit.vcell.model.SpeciesContext)17 Structure (cbit.vcell.model.Structure)17 Membrane (cbit.vcell.model.Membrane)16 ReactionParticipant (cbit.vcell.model.ReactionParticipant)16 ArrayList (java.util.ArrayList)14 ReactionStep (cbit.vcell.model.ReactionStep)13 Shape (cbit.gui.graph.Shape)12 Feature (cbit.vcell.model.Feature)12 Reactant (cbit.vcell.model.Reactant)12 Expression (cbit.vcell.parser.Expression)11 Product (cbit.vcell.model.Product)10 Point (java.awt.Point)10 PropertyVetoException (java.beans.PropertyVetoException)9 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)8 RuleParticipantSignature (cbit.vcell.model.RuleParticipantSignature)8 Catalyst (cbit.vcell.model.Catalyst)7 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)7 LumpedKinetics (cbit.vcell.model.LumpedKinetics)6