Search in sources :

Example 46 with Membrane

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

the class ReactionCartoonTool method lineAction.

private void lineAction(Structure startStructure, SpeciesContext speciesContextEnd) throws PropertyVetoException, Exception {
    Structure endStructure = speciesContextEnd.getStructure();
    Model model = getModel();
    ReactionStep reaction = null;
    Point startPos = edgeShape.getStart();
    Point endPos = edgeShape.getEnd();
    Structure reactionStructure = null;
    if (startStructure != endStructure) {
        if (startStructure instanceof Feature && endStructure instanceof Feature) {
            // Feature ==> Feature-speciesContext
            Feature startFeature = (Feature) startStructure;
            Feature endFeature = (Feature) endStructure;
            // Feature ==> feature-speciesContext with no membrane between : create a 0th-order simpleReaction in startFeature with GeneralLumpedKinetics
            reactionStructure = startStructure;
            reaction = model.createSimpleReaction(reactionStructure);
            reaction.setKinetics(new GeneralLumpedKinetics(reaction));
        } else if (startStructure instanceof Feature && endStructure instanceof Membrane) {
            // Feature ==> membrane-species : Create volume species ; create membrane reaction ; add volume species as reactant and membrane species(End) as product.
            reactionStructure = endStructure;
            reaction = model.createSimpleReaction(reactionStructure);
            SpeciesContext startingSpeciesContext = model.createSpeciesContext(startStructure);
            reaction.addReactant(startingSpeciesContext, 1);
            positionShapeForObject(startStructure, startingSpeciesContext, startPos);
        } else if (startStructure instanceof Membrane && endStructure instanceof Feature) {
            // Membrane ==> Feature-species : 0th-order reaction in membrane
            reactionStructure = startStructure;
            reaction = model.createSimpleReaction(reactionStructure);
        } else if (startStructure instanceof Membrane && endStructure instanceof Membrane) {
            // Membrane ==> membrane-species : the 2 membranes are different : create a 0th-order lumped simpleReaction in startMembrane
            reactionStructure = startStructure;
            reaction = model.createSimpleReaction(reactionStructure);
            reaction.setKinetics(new GeneralLumpedKinetics(reaction));
        }
    } else {
        // startStructure == endStructure : 0th-order simplereaction in structure
        reactionStructure = startStructure;
        reaction = model.createSimpleReaction(reactionStructure);
    }
    // speciesContextEnd should be added as a product to reaction (if not flux).
    if (!(reaction instanceof FluxReaction)) {
        reaction.addProduct(speciesContextEnd, 1);
    }
    positionShapeForObject(reactionStructure, reaction, new Point((2 * startPos.x + 8 * endPos.x) / 10, (2 * startPos.y + 8 * endPos.y) / 10));
    getReactionCartoon().notifyChangeEvent();
    getGraphModel().clearSelection();
    getGraphModel().select(reaction);
}
Also used : ReactionStep(cbit.vcell.model.ReactionStep) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) GraphModel(cbit.gui.graph.GraphModel) Membrane(cbit.vcell.model.Membrane) FluxReaction(cbit.vcell.model.FluxReaction) Point(java.awt.Point) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) SpeciesContext(cbit.vcell.model.SpeciesContext) Structure(cbit.vcell.model.Structure) Feature(cbit.vcell.model.Feature)

Example 47 with Membrane

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

the class ReactStepDbDriver method populateStructureAndElectricalTopology.

public static void populateStructureAndElectricalTopology(Model model, HashMap<KeyValue, StructureKeys> structureKeysMap) throws DataAccessException {
    // 
    for (Structure structure : model.getStructures()) {
        // get parent struct
        KeyValue parentKey = structureKeysMap.get(structure.getKey()).parentKey;
        Structure parentStructure = null;
        if (parentKey != null) {
            for (Structure struct1 : model.getStructures()) {
                if (struct1.getKey().equals(parentKey)) {
                    parentStructure = struct1;
                    break;
                }
            }
        }
        if (parentStructure != null) {
            StructureTopology structureTopology = model.getStructureTopology();
            if (structure instanceof Feature) {
                Feature feature = (Feature) structure;
                if (parentStructure instanceof Feature) {
                    // feature.setParentFeature((Feature)parent);
                    throw new DataAccessException("Feature is not permitted to be the parent of another feature");
                } else if (parentStructure instanceof Membrane) {
                    structureTopology.setInsideFeature((Membrane) parentStructure, feature);
                }
            } else if (structure instanceof Membrane) {
                Membrane membrane = (Membrane) structure;
                if (parentStructure instanceof Feature) {
                    structureTopology.setOutsideFeature(membrane, (Feature) parentStructure);
                } else {
                    throw new DataAccessException("Membrane '" + membrane.getName() + "' is not permitted to be the parent of another membrane '" + parentStructure.getName());
                }
            }
        }
        if (structure instanceof Membrane) {
            Membrane membrane = (Membrane) structure;
            KeyValue negKey = structureKeysMap.get(structure.getKey()).negKey;
            if (negKey != null) {
                for (Structure struct : model.getStructures()) {
                    if (struct instanceof Feature && struct.getKey().equals(negKey)) {
                        Feature feature = (Feature) struct;
                        model.getElectricalTopology().setNegativeFeature(membrane, feature);
                        break;
                    }
                }
            }
            KeyValue posKey = structureKeysMap.get(structure.getKey()).posKey;
            if (posKey != null) {
                for (Structure struct : model.getStructures()) {
                    if (struct instanceof Feature && struct.getKey().equals(posKey)) {
                        Feature feature = (Feature) struct;
                        model.getElectricalTopology().setPositiveFeature(membrane, feature);
                        break;
                    }
                }
            }
        }
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) StructureTopology(cbit.vcell.model.Model.StructureTopology) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) Feature(cbit.vcell.model.Feature) DataAccessException(org.vcell.util.DataAccessException)

Example 48 with Membrane

use of cbit.vcell.model.Membrane 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 49 with Membrane

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

the class ReactionCartoonTool method lineAction.

private void lineAction(SpeciesContext speciesContextStart, SpeciesContext speciesContextEnd) throws Exception {
    Structure endStructure = speciesContextEnd.getStructure();
    Structure startStructure = speciesContextStart.getStructure();
    Model model = getModel();
    ReactionStep reaction = null;
    Point startPos = edgeShape.getStart();
    Point endPos = edgeShape.getEnd();
    Structure reactionStructure = null;
    boolean bLumpedKinetics = false;
    if (startStructure != endStructure) {
        if (startStructure instanceof Feature && endStructure instanceof Feature) {
            // Feature-speciesContext ==> Feature-speciesContext
            Membrane membraneBetween = model.getStructureTopology().getMembrane((Feature) startStructure, (Feature) endStructure);
            // Feature-speciesContext ==> Feature-speciesContext with membrane in between : add reaction in Membrane (scStart : reactant; scEnd : pdt)
            if (membraneBetween != null) {
                reactionStructure = membraneBetween;
            } else {
                // Feature-speciesContext ==> Feature-speciesContext with no membrane between : create a lumped reaction in startFeature
                reactionStructure = startStructure;
                bLumpedKinetics = true;
            }
        } else if (startStructure instanceof Feature && endStructure instanceof Membrane) {
            // Feature-speciesContext ==> Membrane-speciesContext : create membrane reaction ; add scStart : reactant and scEnd : pdt.
            reactionStructure = endStructure;
        } else if (startStructure instanceof Membrane && endStructure instanceof Feature) {
            // Membrane-speciesContext ==> Feature-speciesContext : create reaction in membrane; scStart : reactant, scEnd : pdt.
            reactionStructure = startStructure;
        } else if (startStructure instanceof Membrane && endStructure instanceof Membrane) {
            // Membrane-speciesContext ==> Membrane-speciesContext : the 2 membranes are different : create lumped reaction in endMembrane
            reactionStructure = endStructure;
            bLumpedKinetics = true;
        }
    } else {
        // startStructure == endStructure : create reaction in structure
        reactionStructure = startStructure;
    }
    reaction = model.createSimpleReaction(reactionStructure);
    if (bLumpedKinetics) {
        reaction.setKinetics(new GeneralLumpedKinetics(reaction));
    }
    reaction.addReactant(speciesContextStart, 1);
    reaction.addProduct(speciesContextEnd, 1);
    positionShapeForObject(reactionStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
    getReactionCartoon().notifyChangeEvent();
    getGraphModel().clearSelection();
    getGraphModel().select(reaction);
}
Also used : ReactionStep(cbit.vcell.model.ReactionStep) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) GraphModel(cbit.gui.graph.GraphModel) Membrane(cbit.vcell.model.Membrane) Point(java.awt.Point) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) Structure(cbit.vcell.model.Structure) Feature(cbit.vcell.model.Feature)

Example 50 with Membrane

use of cbit.vcell.model.Membrane 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)

Aggregations

Membrane (cbit.vcell.model.Membrane)77 Feature (cbit.vcell.model.Feature)50 Structure (cbit.vcell.model.Structure)47 Expression (cbit.vcell.parser.Expression)31 SpeciesContext (cbit.vcell.model.SpeciesContext)25 MembraneMapping (cbit.vcell.mapping.MembraneMapping)20 StructureTopology (cbit.vcell.model.Model.StructureTopology)19 ExpressionException (cbit.vcell.parser.ExpressionException)18 PropertyVetoException (java.beans.PropertyVetoException)17 FluxReaction (cbit.vcell.model.FluxReaction)16 Model (cbit.vcell.model.Model)16 ReactionStep (cbit.vcell.model.ReactionStep)16 SimpleReaction (cbit.vcell.model.SimpleReaction)16 ArrayList (java.util.ArrayList)14 StructureMapping (cbit.vcell.mapping.StructureMapping)12 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)12 ReactionParticipant (cbit.vcell.model.ReactionParticipant)12 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)12 SubVolume (cbit.vcell.geometry.SubVolume)11 SurfaceClass (cbit.vcell.geometry.SurfaceClass)11