Search in sources :

Example 6 with MolecularType

use of org.vcell.model.rbm.MolecularType in project vcell by virtualcell.

the class Xmlproducer method getXML.

// public because it's being called in simcontexttable to populate the app components element
public Element getXML(NetworkConstraints param) {
    Element e = new Element(XMLTags.RbmNetworkConstraintsTag);
    e.setAttribute(XMLTags.RbmMaxIterationTag, Integer.toString(param.getMaxIteration()));
    e.setAttribute(XMLTags.RbmMaxMoleculesPerSpeciesTag, Integer.toString(param.getMaxMoleculesPerSpecies()));
    Map<MolecularType, Integer> sm = param.getMaxStoichiometry();
    for (Map.Entry<MolecularType, Integer> m : sm.entrySet()) {
        MolecularType mt = m.getKey();
        Integer value = m.getValue();
        Element e1 = new Element(XMLTags.RbmMaxStoichiometryTag);
        e1.setAttribute(XMLTags.RbmMolecularTypeTag, mangle(mt.getName()));
        e1.setAttribute(XMLTags.RbmIntegerAttrTag, Integer.toString(value));
        e.addContent(e1);
    }
    return e;
}
Also used : ParticleMolecularType(cbit.vcell.math.ParticleMolecularType) MolecularType(org.vcell.model.rbm.MolecularType) Element(org.jdom.Element) Map(java.util.Map) HashMap(java.util.HashMap)

Example 7 with MolecularType

use of org.vcell.model.rbm.MolecularType in project vcell by virtualcell.

the class BioModelEditorSpeciesTableModel method isCellEditable.

public boolean isCellEditable(int row, int column) {
    switch(column) {
        case COLUMN_NAME:
            return true;
        case COLUMN_DEFINITION:
            SpeciesContext sc = getValueAt(row);
            if (sc == null) {
                return false;
            }
            SpeciesPattern sp = sc.getSpeciesPattern();
            if (sp == null) {
                // we can edit a species pattern if none is present
                return true;
            }
            final List<MolecularTypePattern> mtpList = sp.getMolecularTypePatterns();
            for (MolecularTypePattern mtp : mtpList) {
                MolecularType mt = mtp.getMolecularType();
                if (mt.getComponentList().size() != 0) {
                    return false;
                }
            }
            return true;
        default:
            return false;
    }
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) SpeciesContext(cbit.vcell.model.SpeciesContext) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 8 with MolecularType

use of org.vcell.model.rbm.MolecularType in project vcell by virtualcell.

the class BioModelEditorSpeciesTableModel method checkInputValue.

public String checkInputValue(String inputValue, int row, int column) {
    SpeciesContext speciesContext = getValueAt(row);
    String errMsg = null;
    switch(column) {
        case COLUMN_NAME:
            if (speciesContext == null || !speciesContext.getName().equals(inputValue)) {
                if (getModel().getSpeciesContext(inputValue) != null) {
                    errMsg = "Species '" + inputValue + "' already exists!";
                    errMsg += VCellErrorMessages.PressEscToUndo;
                    errMsg = "<html>" + errMsg + "</html>";
                    return errMsg;
                }
            }
            break;
        case COLUMN_STRUCTURE:
            if (getModel().getStructure(inputValue) == null) {
                errMsg = "Structure '" + inputValue + "' does not exist!";
                errMsg += VCellErrorMessages.PressEscToUndo;
                errMsg = "<html>" + errMsg + "</html>";
                return errMsg;
            }
            break;
        case COLUMN_DEFINITION:
            try {
                inputValue = inputValue.trim();
                if (inputValue.length() > 0) {
                    // parsing will throw appropriate exception if molecular type or component don't exist
                    // our change
                    SpeciesPattern spThis = RbmUtils.parseSpeciesPattern(inputValue, bioModel.getModel());
                    // here we can restrict what the user can do
                    for (MolecularTypePattern mtpThis : spThis.getMolecularTypePatterns()) {
                        MolecularType mtThis = mtpThis.getMolecularType();
                        for (MolecularComponent mcThis : mtThis.getComponentList()) {
                            // we check that each component is present in the molecular type pattern (as component pattern)
                            if (mtpThis.getMolecularComponentPattern(mcThis) == null) {
                                // not found
                                errMsg = "All " + MolecularComponent.typeName + "s in the " + mtThis.getDisplayType() + " definition must be present. Missing: " + mcThis.getName();
                                errMsg += VCellErrorMessages.PressEscToUndo;
                                errMsg = "<html>" + errMsg + "</html>";
                                return errMsg;
                            } else if (mtpThis.getMolecularComponentPattern(mcThis).isImplied()) {
                                errMsg = "All " + MolecularComponent.typeName + "s in the " + mtThis.getDisplayType() + " definition must be present. Missing: " + mcThis.getName();
                                errMsg += VCellErrorMessages.PressEscToUndo;
                                errMsg = "<html>" + errMsg + "</html>";
                                return errMsg;
                            } else {
                                // now need to also check the states
                                if (mcThis.getComponentStateDefinitions().size() == 0) {
                                    // nothing to do if the molecular component has no component state definition
                                    continue;
                                // note that we raise exception in parseSpeciesPattern() if we attempt to use an undefined state
                                // so no need to check that here
                                }
                                boolean found = false;
                                for (ComponentStateDefinition csThis : mcThis.getComponentStateDefinitions()) {
                                    MolecularComponentPattern mcpThis = mtpThis.getMolecularComponentPattern(mcThis);
                                    if ((mcpThis.getComponentStatePattern() == null) || mcpThis.getComponentStatePattern().isAny()) {
                                        // no component state pattern means no state, there's no point to check for this component again
                                        break;
                                    // we get out of the for and complain that we found no matching state
                                    }
                                    if (csThis.getName().equals(mcpThis.getComponentStatePattern().getComponentStateDefinition().getName())) {
                                        found = true;
                                    }
                                }
                                if (found == false) {
                                    // we should have found a matching state for the molecular component pattern
                                    errMsg = MolecularComponent.typeName + " " + mcThis.getDisplayName() + " of " + mtThis.getDisplayType() + " " + mtThis.getDisplayName() + " must be in one of the following states: ";
                                    for (int i = 0; i < mcThis.getComponentStateDefinitions().size(); i++) {
                                        ComponentStateDefinition csThis = mcThis.getComponentStateDefinitions().get(i);
                                        errMsg += csThis.getName();
                                        if (i < mcThis.getComponentStateDefinitions().size() - 1) {
                                            errMsg += ", ";
                                        }
                                    }
                                    errMsg += VCellErrorMessages.PressEscToUndo;
                                    errMsg = "<html>" + errMsg + "</html>";
                                    return errMsg;
                                }
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                errMsg = ex.getMessage();
                errMsg += VCellErrorMessages.PressEscToUndo;
                errMsg = "<html>" + errMsg + "</html>";
                return errMsg;
            }
            break;
    }
    return null;
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) MolecularComponent(org.vcell.model.rbm.MolecularComponent) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) SpeciesContext(cbit.vcell.model.SpeciesContext) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 9 with MolecularType

use of org.vcell.model.rbm.MolecularType in project vcell by virtualcell.

the class RuleParticipantSignatureDiagramShape method paintSelf.

// TODO: Override ElipseShape::isInside()
// our shape here is rounded rectangle while IsInside thinks it's an ellipse, which means
// that clicking near the corners of a long shape (with many molecules) fails to select the shape
// TODO: the RoundRectangle2D contour below needs to be recalculated with updated width, using the
// species pattern in the RuleParticipantSignature
@Override
public void paintSelf(Graphics2D g, int absPosX, int absPosY) {
    if (!bVisible) {
        return;
    }
    // we reserve space for at least 1 molecule
    int numMolecules = Math.max(1, ruleParticipantSignature.getSpeciesPattern().getMolecularTypePatterns().size());
    width = leftmargin + circleDiameter + displacement * (numMolecules - 1) + 1;
    getSpaceManager().setSize(width, height);
    int shapeHeight = getSpaceManager().getSize().height;
    int shapeWidth = getSpaceManager().getSize().width;
    Graphics2D g2D = g;
    Paint oldPaint = g2D.getPaint();
    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Color exterior;
    // draw the contour around the whole rule participant
    // no need to really draw it if the shapes of the molecules fill it perfectly, because it won't be visible anyway
    // however, the "isInside" function will need exactly this RoundRectangle2D to compute whether the point is inside the shape
    RoundRectangle2D contour = new RoundRectangle2D.Double(absPosX, absPosY, shapeWidth, shapeHeight, shapeHeight, shapeHeight);
    g2D.setPaint(isSelected() ? AbstractComponentShape.componentMediumPalePink : AbstractComponentShape.componentPaleGreen);
    g2D.fill(contour);
    exterior = isSelected() ? Color.red.darker().darker() : Color.darkGray;
    g.setColor(exterior);
    g2D.draw(contour);
    Model model = ((ReactionCartoon) graphModel).getModel();
    RbmModelContainer rbmmc = model.getRbmModelContainer();
    List<MolecularType> mtList = rbmmc.getMolecularTypeList();
    List<MolecularType> ruleSignatureMolecularTypes = ruleParticipantSignature.getMolecularTypes();
    // draw the molecules (they are properly drawn because we use the sp as it is in the associated RuleParticipantSignature object)
    for (int i = 0; i < ruleSignatureMolecularTypes.size(); i++) {
        double offsetx = leftmargin + i * displacement - 1.4;
        int offsety = getSpaceManager().getSize().height - circleDiameter - 2;
        Ellipse2D icon = new Ellipse2D.Double(absPosX + offsetx, absPosY + offsety, circleDiameter, circleDiameter);
        // int offsetx = leftmargin + i*displacement;
        // int offsety = 0;
        // Rectangle2D icon = new Rectangle2D.Double(absPosX + offsetx, absPosY + offsety, displacement, shapeHeight-1);
        MolecularType mt = ruleSignatureMolecularTypes.get(i);
        int index = mtList.indexOf(mt);
        index = index % 7;
        defaultBG = Color.lightGray;
        Color interior = Color.white;
        if (graphModel instanceof ReactionCartoonFull) {
            // take color from molecular type color selection
            defaultBG = MolecularTypeLargeShape.colorTable[index];
        }
        backgroundColor = defaultBG;
        // darkerBackground = backgroundColor.darker().darker();
        exterior = !isSelected() ? backgroundColor.darker().darker() : backgroundColor.darker();
        Color[] colors = { interior, exterior };
        g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        Point2D center = new Point2D.Double(absPosX + offsetx + circleDiameter / 2, absPosY + offsety + circleDiameter / 2);
        float radius = circleDiameter * 0.5f;
        Point2D focus = new Point2D.Double(absPosX + offsetx + circleDiameter / 2 - 2, absPosY + offsety + circleDiameter / 2 - 2);
        float[] dist = { 0.1f, 1.0f };
        RadialGradientPaint p = new RadialGradientPaint(center, radius, focus, dist, colors, CycleMethod.NO_CYCLE);
        // Paint p = defaultBG.darker().darker();
        g2D.setPaint(p);
        g2D.fill(icon);
        g.setColor(forgroundColor);
        g2D.draw(icon);
    }
    // TODO: see if RefreshLabel below works properly, if it does make a similar call to refresh the width!!!
    if (getLabel() != null && getLabel().length() > 0) {
        if (isSelected()) {
            // clear background and outline to make selected label stand out
            Rectangle outlineRectangle = getLabelOutline(absPosX, absPosY);
            drawRaisedOutline(outlineRectangle.x, outlineRectangle.y, outlineRectangle.width, outlineRectangle.height, g, Color.white, forgroundColor, Color.gray);
        }
        if (bDisplayLabel || isSelected()) {
            g.setColor(forgroundColor);
            g.drawString((isSelected() || smallLabel == null ? getLabel() : smallLabel), (isSelected() || smallLabel == null ? getLabelPos().x : smallLabelPos.x) + absPosX, getLabelPos().y - 2 + absPosY);
        }
    }
    if (linkText != null && linkText != "") {
        ShapePaintUtil.paintLinkMark(g2D, this, Color.BLACK);
    }
    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    g2D.setPaint(oldPaint);
}
Also used : Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Rectangle(java.awt.Rectangle) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) RadialGradientPaint(java.awt.RadialGradientPaint) Point(java.awt.Point) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) Ellipse2D(java.awt.geom.Ellipse2D) Graphics2D(java.awt.Graphics2D) MolecularType(org.vcell.model.rbm.MolecularType) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) Point2D(java.awt.geom.Point2D) Model(cbit.vcell.model.Model)

Example 10 with MolecularType

use of org.vcell.model.rbm.MolecularType in project vcell by virtualcell.

the class Model method refreshDependencies.

/**
 * Insert the method's description here.
 * Creation date: (5/22/00 10:50:08 PM)
 */
public void refreshDependencies() {
    removePropertyChangeListener(this);
    removeVetoableChangeListener(this);
    addVetoableChangeListener(this);
    addPropertyChangeListener(this);
    for (int i = 0; i < fieldStructures.length; i++) {
        fieldStructures[i].removePropertyChangeListener(this);
        fieldStructures[i].removeVetoableChangeListener(this);
        fieldStructures[i].addPropertyChangeListener(this);
        fieldStructures[i].addVetoableChangeListener(this);
        fieldStructures[i].getStructureSize().removePropertyChangeListener(this);
        fieldStructures[i].getStructureSize().removeVetoableChangeListener(this);
        fieldStructures[i].getStructureSize().addPropertyChangeListener(this);
        fieldStructures[i].getStructureSize().addVetoableChangeListener(this);
        if (fieldStructures[i] instanceof Membrane) {
            ((Membrane) fieldStructures[i]).getMembraneVoltage().removePropertyChangeListener(this);
            ((Membrane) fieldStructures[i]).getMembraneVoltage().removeVetoableChangeListener(this);
            ((Membrane) fieldStructures[i]).getMembraneVoltage().addPropertyChangeListener(this);
            ((Membrane) fieldStructures[i]).getMembraneVoltage().addVetoableChangeListener(this);
        }
        fieldStructures[i].setModel(this);
    }
    for (int i = 0; i < fieldSpecies.length; i++) {
        fieldSpecies[i].removeVetoableChangeListener(this);
        fieldSpecies[i].addVetoableChangeListener(this);
        fieldSpecies[i].refreshDependencies();
    }
    for (int i = 0; i < fieldSpeciesContexts.length; i++) {
        fieldSpeciesContexts[i].removePropertyChangeListener(this);
        fieldSpeciesContexts[i].removeVetoableChangeListener(this);
        fieldSpeciesContexts[i].addPropertyChangeListener(this);
        fieldSpeciesContexts[i].addVetoableChangeListener(this);
        fieldSpeciesContexts[i].setModel(this);
        fieldSpeciesContexts[i].refreshDependencies();
    }
    for (int i = 0; i < fieldReactionSteps.length; i++) {
        fieldReactionSteps[i].removePropertyChangeListener(this);
        fieldReactionSteps[i].removeVetoableChangeListener(this);
        fieldReactionSteps[i].getKinetics().removePropertyChangeListener(this);
        fieldReactionSteps[i].getKinetics().removeVetoableChangeListener(this);
        fieldReactionSteps[i].getKinetics().addPropertyChangeListener(this);
        fieldReactionSteps[i].getKinetics().addVetoableChangeListener(this);
        fieldReactionSteps[i].addPropertyChangeListener(this);
        fieldReactionSteps[i].addVetoableChangeListener(this);
        fieldReactionSteps[i].setModel(this);
        try {
            fieldReactionSteps[i].rebindAllToModel(this);
        } catch (Exception e) {
            e.printStackTrace(System.out);
        }
        fieldReactionSteps[i].refreshDependencies();
    }
    for (int i = 0; i < fieldModelParameters.length; i++) {
        fieldModelParameters[i].removeVetoableChangeListener(this);
        fieldModelParameters[i].removePropertyChangeListener(this);
        fieldModelParameters[i].addVetoableChangeListener(Parameter.PROPERTYNAME_NAME, this);
        fieldModelParameters[i].addPropertyChangeListener(this);
        try {
            fieldModelParameters[i].getExpression().bindExpression(this);
        } catch (ExpressionBindingException e) {
            e.printStackTrace(System.out);
            throw new RuntimeException("Error binding global parameter '" + fieldModelParameters[i].getName() + "' to model." + e.getMessage());
        }
    }
    for (int i = 0; i < getRbmModelContainer().getReactionRuleList().size(); i++) {
        ReactionRule reactionRule = getRbmModelContainer().getReactionRule(i);
        reactionRule.removePropertyChangeListener(this);
        reactionRule.removeVetoableChangeListener(this);
        reactionRule.getKineticLaw().removePropertyChangeListener(this);
        // reactionRule.getKineticLaw().removeVetoableChangeListener(this);
        reactionRule.getKineticLaw().addPropertyChangeListener(this);
        // reactionRule.getKineticLaw().addVetoableChangeListener(this);
        reactionRule.addPropertyChangeListener(this);
        reactionRule.addVetoableChangeListener(this);
        reactionRule.setModel(this);
        try {
            reactionRule.rebindAllToModel(this);
        } catch (Exception e) {
            e.printStackTrace(System.out);
        }
        reactionRule.refreshDependencies();
    }
    for (RbmObservable observable : getRbmModelContainer().getObservableList()) {
        observable.removePropertyChangeListener(this);
        observable.removeVetoableChangeListener(this);
        observable.addPropertyChangeListener(this);
        observable.addVetoableChangeListener(this);
        observable.setModel(this);
    }
    for (MolecularType molType : getRbmModelContainer().getMolecularTypeList()) {
        molType.removePropertyChangeListener(this);
        molType.removeVetoableChangeListener(this);
        molType.addPropertyChangeListener(this);
        molType.addVetoableChangeListener(this);
        molType.setModel(this);
    }
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) VCUnitException(cbit.vcell.units.VCUnitException) PropertyVetoException(java.beans.PropertyVetoException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ExpressionException(cbit.vcell.parser.ExpressionException)

Aggregations

MolecularType (org.vcell.model.rbm.MolecularType)78 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)25 MolecularComponent (org.vcell.model.rbm.MolecularComponent)23 Structure (cbit.vcell.model.Structure)20 ArrayList (java.util.ArrayList)20 ReactionRule (cbit.vcell.model.ReactionRule)19 SpeciesContext (cbit.vcell.model.SpeciesContext)19 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)16 PropertyVetoException (java.beans.PropertyVetoException)15 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)15 RbmObservable (cbit.vcell.model.RbmObservable)14 List (java.util.List)13 RbmModelContainer (cbit.vcell.model.Model.RbmModelContainer)12 Point (java.awt.Point)12 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)12 BioPaxObject (org.vcell.pathway.BioPaxObject)11 RelationshipObject (org.vcell.relationship.RelationshipObject)11 BioModelNode (cbit.vcell.desktop.BioModelNode)10 ModelException (cbit.vcell.model.ModelException)10 ParticleMolecularType (cbit.vcell.math.ParticleMolecularType)9