Search in sources :

Example 16 with ReactionRule

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

the class BioModel method propertyChange.

/**
 * This method gets called when a bound property is changed.
 * @param evt A PropertyChangeEvent object describing the event source
 *   	and the property that has changed.
 */
public void propertyChange(java.beans.PropertyChangeEvent evt) {
    // 
    if (evt.getSource() instanceof SimulationContext && evt.getPropertyName().equals("mathDescription") && evt.getNewValue() != null) {
        if (fieldSimulations != null) {
            for (int i = 0; i < fieldSimulations.length; i++) {
                if (fieldSimulations[i].getMathDescription() == evt.getOldValue()) {
                    try {
                        fieldSimulations[i].setMathDescription((MathDescription) evt.getNewValue());
                    } catch (PropertyVetoException e) {
                        System.out.println("error propagating math from SimulationContext '" + ((SimulationContext) evt.getSource()).getName() + "' to Simulation '" + fieldSimulations[i].getName());
                        e.printStackTrace(System.out);
                    }
                }
            }
        }
    }
    // 
    if (evt.getSource() == this && evt.getPropertyName().equals(PropertyConstants.PROPERTY_NAME_SIMULATIONS) && evt.getNewValue() != null) {
        // 
        if (evt.getOldValue() != null) {
            Simulation[] simulations = (Simulation[]) evt.getOldValue();
            for (int i = 0; i < simulations.length; i++) {
                simulations[i].removeVetoableChangeListener(this);
                simulations[i].removePropertyChangeListener(this);
            }
        }
        // 
        if (evt.getOldValue() != null) {
            Simulation[] simulations = (Simulation[]) evt.getNewValue();
            for (int i = 0; i < simulations.length; i++) {
                simulations[i].addVetoableChangeListener(this);
                simulations[i].addPropertyChangeListener(this);
            }
        }
    }
    if (evt.getSource() == this && evt.getPropertyName().equals(PROPERTY_NAME_SIMULATION_CONTEXTS) && evt.getNewValue() != null) {
        // 
        if (evt.getOldValue() != null) {
            SimulationContext[] simulationContexts = (SimulationContext[]) evt.getOldValue();
            for (int i = 0; i < simulationContexts.length; i++) {
                simulationContexts[i].removeVetoableChangeListener(this);
                simulationContexts[i].removePropertyChangeListener(this);
            }
        }
        // 
        if (evt.getOldValue() != null) {
            SimulationContext[] simulationContexts = (SimulationContext[]) evt.getNewValue();
            for (int i = 0; i < simulationContexts.length; i++) {
                simulationContexts[i].addVetoableChangeListener(this);
                simulationContexts[i].addPropertyChangeListener(this);
            }
        }
    }
    if (evt.getSource() == fieldModel && (evt.getPropertyName().equals(Model.PROPERTY_NAME_SPECIES_CONTEXTS) || evt.getPropertyName().equals(Model.PROPERTY_NAME_REACTION_STEPS))) {
        // remove the relationship objects if the biomodelEntity objects were removed
        Set<BioModelEntityObject> removedObjects = relationshipModel.getBioModelEntityObjects();
        for (SpeciesContext sc : fieldModel.getSpeciesContexts()) {
            removedObjects.remove(sc);
        }
        for (ReactionStep rs : fieldModel.getReactionSteps()) {
            removedObjects.remove(rs);
        }
        for (MolecularType mt : fieldModel.getRbmModelContainer().getMolecularTypeList()) {
            removedObjects.remove(mt);
        }
        for (ReactionRule rr : fieldModel.getRbmModelContainer().getReactionRuleList()) {
            removedObjects.remove(rr);
        }
        relationshipModel.removeRelationshipObjects(removedObjects);
    }
    // adjust the relationship model when a molecule gets deleted
    if (evt.getSource() == fieldModel && (evt.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_MOLECULAR_TYPE_LIST))) {
        @SuppressWarnings("unchecked") List<MolecularType> oldListCopy = new ArrayList<MolecularType>((List<MolecularType>) evt.getOldValue());
        @SuppressWarnings("unchecked") List<MolecularType> newList = (List<MolecularType>) evt.getNewValue();
        if (newList != null && oldListCopy != null && oldListCopy.size() > newList.size()) {
            // something got deleted
            oldListCopy.removeAll(newList);
            for (MolecularType removedMt : oldListCopy) {
                relationshipModel.removeRelationshipObject(removedMt);
            }
        }
    }
    if (evt.getSource() == fieldModel && (evt.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_REACTION_RULE_LIST))) {
        @SuppressWarnings("unchecked") List<ReactionRule> oldListCopy = new ArrayList<ReactionRule>((List<ReactionRule>) evt.getOldValue());
        @SuppressWarnings("unchecked") List<ReactionRule> newList = (List<ReactionRule>) evt.getNewValue();
        if (newList != null && oldListCopy != null && oldListCopy.size() > newList.size()) {
            // something got deleted
            oldListCopy.removeAll(newList);
            for (ReactionRule removedRr : oldListCopy) {
                relationshipModel.removeRelationshipObject(removedRr);
            }
        }
    }
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) ArrayList(java.util.ArrayList) SpeciesContext(cbit.vcell.model.SpeciesContext) SimulationContext(cbit.vcell.mapping.SimulationContext) BioModelEntityObject(cbit.vcell.model.BioModelEntityObject) PropertyVetoException(java.beans.PropertyVetoException) MolecularType(org.vcell.model.rbm.MolecularType) Simulation(cbit.vcell.solver.Simulation) ReactionStep(cbit.vcell.model.ReactionStep) List(java.util.List) ArrayList(java.util.ArrayList)

Example 17 with ReactionRule

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

the class BioModel method getVCID.

public VCID getVCID(Identifiable identifiable) {
    String localName;
    String className;
    if (identifiable instanceof SpeciesContext) {
        localName = ((SpeciesContext) identifiable).getName();
        className = "SpeciesContext";
    } else if (identifiable instanceof Species) {
        localName = ((Species) identifiable).getCommonName();
        className = VCID.CLASS_SPECIES;
    } else if (identifiable instanceof Structure) {
        localName = ((Structure) identifiable).getName();
        className = "Structure";
    } else if (identifiable instanceof ReactionStep) {
        localName = ((ReactionStep) identifiable).getName();
        className = VCID.CLASS_REACTION_STEP;
    } else if (identifiable instanceof BioModel) {
        localName = ((BioModel) identifiable).getName();
        className = VCID.CLASS_BIOMODEL;
    // }else if (identifiable instanceof SimulationContext){
    // localName = ((SimulationContext)identifiable).getName();
    // className = "Application";
    } else if (identifiable instanceof BioPaxObject) {
        localName = ((BioPaxObject) identifiable).getID();
        className = "BioPaxObject";
    } else if (identifiable instanceof MolecularType) {
        localName = ((MolecularType) identifiable).getName();
        className = "MolecularType";
    } else if (identifiable instanceof ReactionRule) {
        localName = ((ReactionRule) identifiable).getName();
        className = "ReactionRule";
    } else if (identifiable instanceof RbmObservable) {
        localName = ((RbmObservable) identifiable).getName();
        className = "RbmObservable";
    } else {
        throw new RuntimeException("unsupported Identifiable class");
    }
    localName = TokenMangler.mangleVCId(localName);
    VCID vcid;
    try {
        vcid = VCID.fromString(className + "(" + localName + ")");
    } catch (VCID.InvalidVCIDException e) {
        e.printStackTrace();
        throw new RuntimeException(e.getMessage());
    }
    return vcid;
}
Also used : VCID(cbit.vcell.biomodel.meta.VCID) ReactionRule(cbit.vcell.model.ReactionRule) BioPaxObject(org.vcell.pathway.BioPaxObject) RbmObservable(cbit.vcell.model.RbmObservable) SpeciesContext(cbit.vcell.model.SpeciesContext) MolecularType(org.vcell.model.rbm.MolecularType) ReactionStep(cbit.vcell.model.ReactionStep) Structure(cbit.vcell.model.Structure) Species(cbit.vcell.model.Species)

Example 18 with ReactionRule

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

the class MolecularTypeLargeShape method flash.

public void flash(String matchKey) {
    if (!(owner instanceof ReactionRule)) {
        return;
    }
    if (mtp != null && mtp.hasExplicitParticipantMatch() && mtp.getParticipantMatchLabel().equals(matchKey)) {
        Graphics g = shapePanel.getGraphics();
        Graphics2D g2 = (Graphics2D) g;
        Font fontOld = g2.getFont();
        Color colorOld = g2.getColor();
        Color color = (Color.red).darker();
        Font font = deriveMoleculeFontBold(g, shapePanel);
        Font smallerFont = font.deriveFont(font.getSize() * 0.8F);
        g.setFont(smallerFont);
        FontMetrics fm = g.getFontMetrics(font);
        int stringWidth = fm.stringWidth(name);
        int textX = xPos + 11;
        int textY = yPos + baseHeight - (baseHeight - smallerFont.getSize()) / 2;
        g.setColor(color);
        g2.drawString(mtp.getParticipantMatchLabel(), textX + stringWidth + 2, textY + 2);
        g.setFont(fontOld);
        g.setColor(colorOld);
    }
}
Also used : Graphics(java.awt.Graphics) ReactionRule(cbit.vcell.model.ReactionRule) FontMetrics(java.awt.FontMetrics) Color(java.awt.Color) Font(java.awt.Font) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 19 with ReactionRule

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

the class ReactionCartoonFull method setPositionsFromReactionCartoon.

public void setPositionsFromReactionCartoon(Diagram diagram) {
    List<NodeReference> nodeList = new ArrayList<NodeReference>();
    NodeReference.Mode mode = NodeReference.Mode.full;
    for (Shape shape : getShapes()) {
        if (shape instanceof FluxReactionShape) {
            nodeList.add(new NodeReference(mode, NodeReference.FLUX_REACTION_NODE, ((FluxReaction) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
        } else if (shape instanceof SimpleReactionShape) {
            nodeList.add(new NodeReference(mode, NodeReference.SIMPLE_REACTION_NODE, ((ReactionStep) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
        } else if (shape instanceof ReactionRuleDiagramShape) {
            nodeList.add(new NodeReference(mode, NodeReference.REACTION_RULE_NODE, ((ReactionRule) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
        } else if (shape instanceof SpeciesContextShape) {
            nodeList.add(new NodeReference(mode, NodeReference.SPECIES_CONTEXT_NODE, ((SpeciesContext) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
        } else if (shape instanceof RuleParticipantSignatureFullDiagramShape) {
            RuleParticipantSignature ruleParticipantSignature = (RuleParticipantSignature) shape.getModelObject();
            if (ruleParticipantSignature.getStructure() == diagram.getStructure()) {
                String spAsString = ruleParticipantSignature.getFirstSpeciesPatternAsString();
                NodeReference nr = new NodeReference(mode, NodeReference.RULE_PARTICIPANT_SIGNATURE_FULL_NODE, spAsString, shape.getSpaceManager().getRelPos());
                nr.speciesPattern = ruleParticipantSignature.getSpeciesPattern();
                nodeList.add(nr);
            }
        } else if (shape instanceof RuleParticipantSignatureShortDiagramShape) {
            System.out.println("ReactionCartoonFull, Invalid shape type 'RuleParticipantSignatureShortDiagramShape'");
            RuleParticipantSignature ruleParticipantSignature = (RuleParticipantSignature) shape.getModelObject();
            if (ruleParticipantSignature.getStructure() == diagram.getStructure()) {
                String spAsString = ruleParticipantSignature.getFirstSpeciesPatternAsString();
                NodeReference nr = new NodeReference(mode, NodeReference.RULE_PARTICIPANT_SIGNATURE_SHORT_NODE, spAsString, shape.getSpaceManager().getRelPos());
                nr.speciesPattern = ruleParticipantSignature.getSpeciesPattern();
                nodeList.add(nr);
            }
        }
    }
    diagram.setNodeReferences(mode, nodeList);
}
Also used : RuleParticipantSignature(cbit.vcell.model.RuleParticipantSignature) Shape(cbit.gui.graph.Shape) ReactionRule(cbit.vcell.model.ReactionRule) NodeReference(cbit.vcell.model.NodeReference) ArrayList(java.util.ArrayList) FluxReaction(cbit.vcell.model.FluxReaction)

Example 20 with ReactionRule

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

the class ReactionCartoonMolecule method setPositionsFromReactionCartoon.

public void setPositionsFromReactionCartoon(Diagram diagram) {
    List<NodeReference> nodeList = new ArrayList<NodeReference>();
    NodeReference.Mode mode = NodeReference.Mode.molecule;
    for (Shape shape : getShapes()) {
        if (shape instanceof FluxReactionShape) {
            nodeList.add(new NodeReference(mode, NodeReference.FLUX_REACTION_NODE, ((FluxReaction) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
        } else if (shape instanceof SimpleReactionShape) {
            nodeList.add(new NodeReference(mode, NodeReference.SIMPLE_REACTION_NODE, ((ReactionStep) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
        } else if (shape instanceof ReactionRuleDiagramShape) {
            nodeList.add(new NodeReference(mode, NodeReference.REACTION_RULE_NODE, ((ReactionRule) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
        } else if (shape instanceof SpeciesContextShape) {
            nodeList.add(new NodeReference(mode, NodeReference.SPECIES_CONTEXT_NODE, ((SpeciesContext) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
        } else if (shape instanceof RuleParticipantSignatureFullDiagramShape) {
            System.out.println("ReactionCartoonMolecule, Invalid shape type 'RuleParticipantSignatureFullDiagramShape'");
            RuleParticipantSignature ruleParticipantSignature = (RuleParticipantSignature) shape.getModelObject();
            if (ruleParticipantSignature.getStructure() == diagram.getStructure()) {
                String spAsString = ruleParticipantSignature.getFirstSpeciesPatternAsString();
                NodeReference nr = new NodeReference(mode, NodeReference.RULE_PARTICIPANT_SIGNATURE_FULL_NODE, spAsString, shape.getSpaceManager().getRelPos());
                nr.speciesPattern = ruleParticipantSignature.getSpeciesPattern();
                nodeList.add(nr);
            }
        } else if (shape instanceof RuleParticipantSignatureShortDiagramShape) {
            RuleParticipantSignature ruleParticipantSignature = (RuleParticipantSignature) shape.getModelObject();
            if (ruleParticipantSignature.getStructure() == diagram.getStructure()) {
                String spAsString = ruleParticipantSignature.getFirstSpeciesPatternAsString();
                NodeReference nr = new NodeReference(mode, NodeReference.RULE_PARTICIPANT_SIGNATURE_SHORT_NODE, spAsString, shape.getSpaceManager().getRelPos());
                nr.speciesPattern = ruleParticipantSignature.getSpeciesPattern();
                nodeList.add(nr);
            }
        }
    }
    diagram.setNodeReferences(mode, nodeList);
}
Also used : RuleParticipantSignature(cbit.vcell.model.RuleParticipantSignature) Shape(cbit.gui.graph.Shape) ReactionRule(cbit.vcell.model.ReactionRule) NodeReference(cbit.vcell.model.NodeReference) ArrayList(java.util.ArrayList) FluxReaction(cbit.vcell.model.FluxReaction)

Aggregations

ReactionRule (cbit.vcell.model.ReactionRule)77 ArrayList (java.util.ArrayList)29 ReactionStep (cbit.vcell.model.ReactionStep)26 SpeciesContext (cbit.vcell.model.SpeciesContext)26 Structure (cbit.vcell.model.Structure)26 RbmObservable (cbit.vcell.model.RbmObservable)19 MolecularType (org.vcell.model.rbm.MolecularType)19 ProductPattern (cbit.vcell.model.ProductPattern)17 ReactantPattern (cbit.vcell.model.ReactantPattern)17 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)16 Model (cbit.vcell.model.Model)15 PropertyVetoException (java.beans.PropertyVetoException)14 SimulationContext (cbit.vcell.mapping.SimulationContext)13 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)10 BioModel (cbit.vcell.biomodel.BioModel)9 Expression (cbit.vcell.parser.Expression)9 List (java.util.List)9 Parameter (cbit.vcell.model.Parameter)8 Product (cbit.vcell.model.Product)8 RbmKineticLaw (cbit.vcell.model.RbmKineticLaw)8