Search in sources :

Example 86 with Structure

use of cbit.vcell.model.Structure 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 87 with Structure

use of cbit.vcell.model.Structure 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 88 with Structure

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

the class ReactionCartoonTool method updateRXContainerDropTargetInfoMap.

private HashMap<RXContainerDropTargetInfo, Boolean> updateRXContainerDropTargetInfoMap(Point pointWorld) {
    HashMap<RXContainerDropTargetInfo, Boolean> rxContainerDropTargetInfoMap = null;
    if (rxContainerDropTargetInfoMap == null) {
        // System.out.println("-----redoing map...");
        AllStructureSuite allStructureSuite = (getReactionCartoon().getStructureSuite() instanceof AllStructureSuite ? (AllStructureSuite) getReactionCartoon().getStructureSuite() : null);
        if (allStructureSuite == null) {
            throw new RuntimeException("Expecting " + AllStructureSuite.class.getName());
        }
        rxContainerDropTargetInfoMap = new HashMap<ReactionCartoonTool.RXContainerDropTargetInfo, Boolean>();
        Structure[] originalOrderedStructArr = allStructureSuite.getStructures().toArray(new Structure[0]);
        for (int i = 0; i < originalOrderedStructArr.length; i++) {
            Shape currentRXContainerShape = getReactionCartoon().getShapeFromModelObject(originalOrderedStructArr[i]);
            if (i == 0) {
                rxContainerDropTargetInfoMap.put(new RXContainerDropTargetInfo((ReactionContainerShape) currentRXContainerShape, null, RXContainerDropTargetInfo.INSERT_BEGINNING), false);
            } else {
                rxContainerDropTargetInfoMap.put(new RXContainerDropTargetInfo((ReactionContainerShape) currentRXContainerShape, (ReactionContainerShape) getReactionCartoon().getShapeFromModelObject(originalOrderedStructArr[i - 1]), null), false);
            }
            if (i == (originalOrderedStructArr.length - 1)) {
                rxContainerDropTargetInfoMap.put(new RXContainerDropTargetInfo((ReactionContainerShape) currentRXContainerShape, null, RXContainerDropTargetInfo.INSERT_END), false);
            }
        }
    }
    // System.out.println("-----Starting to update selection..."+pointWorld);
    for (RXContainerDropTargetInfo rxcContainerDropTargetInfo : rxContainerDropTargetInfoMap.keySet()) {
        if (rxcContainerDropTargetInfo.absoluteRectangle.contains(pointWorld)) {
            // System.out.println(rxcContainerDropTargetInfo.dropShape.getLabel()+" "+rxcContainerDropTargetInfo.closestNeighborShape);
            rxContainerDropTargetInfoMap.put(rxcContainerDropTargetInfo, true);
        } else {
            rxContainerDropTargetInfoMap.put(rxcContainerDropTargetInfo, false);
        }
    }
    return rxContainerDropTargetInfoMap;
}
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) AllStructureSuite(cbit.vcell.graph.structures.AllStructureSuite) Structure(cbit.vcell.model.Structure) Point(java.awt.Point)

Example 89 with Structure

use of cbit.vcell.model.Structure 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 90 with Structure

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

the class ReactionCartoonTool method addStructure.

private void addStructure(boolean bMembrane, RXContainerDropTargetInfo selectedContainerDropTargetInfo) {
    Integer insertFlag = selectedContainerDropTargetInfo.insertFlag;
    try {
        Structure myStructure = null;
        if (bMembrane) {
            myStructure = ReactionCartoonTool.this.getModel().createMembrane();
        } else {
            myStructure = ReactionCartoonTool.this.getModel().createFeature();
        }
        ArrayList<Structure> diagramStructures = new ArrayList<Structure>(ReactionCartoonTool.this.getReactionCartoon().getStructureSuite().getStructures());
        diagramStructures.remove(myStructure);
        if (new Integer(RXContainerDropTargetInfo.INSERT_BEGINNING).equals(insertFlag)) {
            diagramStructures.add(0, myStructure);
        } else if (new Integer(RXContainerDropTargetInfo.INSERT_END).equals(insertFlag)) {
            diagramStructures.add(myStructure);
        } else {
            diagramStructures.add(diagramStructures.indexOf(selectedContainerDropTargetInfo.dropShape.getStructure()), myStructure);
        }
        ((AllStructureSuite) getReactionCartoon().getStructureSuite()).setModelStructureOrder(true);
        // ReactionCartoonTool.this.getModel().setStructures(structures.toArray(new Structure[0]));
        ArrayList<Diagram> newDiagramOrderList = new ArrayList<Diagram>();
        for (Structure structure : diagramStructures) {
            newDiagramOrderList.add(getModel().getDiagram(structure));
        }
        getModel().setDiagrams(newDiagramOrderList.toArray(new Diagram[0]));
        lastRXContainerDropTargetInfoMap = updateRXContainerDropTargetInfoMap(new Point(-1, -1));
        resetDropTargets(false, mode == Mode.STRUCTURE);
        getGraphPane().repaint();
    } catch (Exception e2) {
        e2.printStackTrace();
        DialogUtils.showErrorDialog(getGraphPane(), "Error adding structure: " + e2.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) AllStructureSuite(cbit.vcell.graph.structures.AllStructureSuite) Point(java.awt.Point) Structure(cbit.vcell.model.Structure) PropertyVetoException(java.beans.PropertyVetoException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) Diagram(cbit.vcell.model.Diagram)

Aggregations

Structure (cbit.vcell.model.Structure)159 SpeciesContext (cbit.vcell.model.SpeciesContext)57 Membrane (cbit.vcell.model.Membrane)47 PropertyVetoException (java.beans.PropertyVetoException)42 Feature (cbit.vcell.model.Feature)36 Model (cbit.vcell.model.Model)35 ArrayList (java.util.ArrayList)35 ReactionStep (cbit.vcell.model.ReactionStep)33 Expression (cbit.vcell.parser.Expression)33 ReactionRule (cbit.vcell.model.ReactionRule)27 ExpressionException (cbit.vcell.parser.ExpressionException)27 BioModel (cbit.vcell.biomodel.BioModel)23 StructureMapping (cbit.vcell.mapping.StructureMapping)22 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)22 Species (cbit.vcell.model.Species)21 MolecularType (org.vcell.model.rbm.MolecularType)20 ReactionParticipant (cbit.vcell.model.ReactionParticipant)19 SimpleReaction (cbit.vcell.model.SimpleReaction)19 SimulationContext (cbit.vcell.mapping.SimulationContext)18 ModelException (cbit.vcell.model.ModelException)18