Search in sources :

Example 16 with RbmModelContainer

use of cbit.vcell.model.Model.RbmModelContainer in project vcell by virtualcell.

the class MolecularTypeLargeShape method paintSpecies.

// --------------------------------------------------------------------------------------
private void paintSpecies(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Font fontOld = g2.getFont();
    Color colorOld = g2.getColor();
    Stroke strokeOld = g2.getStroke();
    Color primaryColor = null;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    if (mt == null && mtp == null) {
        // plain species context
        Color exterior;
        if (owner == null) {
            // for plain species, we just draw a circle based on height!!! we ignore width!!!
            // error
            exterior = Color.red.darker();
        } else {
            if (!shapePanel.isShowMoleculeColor()) {
                exterior = Color.GRAY;
            } else {
                // plain species
                exterior = Color.green.darker().darker();
            }
        }
        Point2D center = new Point2D.Float(xPos + baseHeight / 3, yPos + baseHeight / 3);
        float radius = baseHeight * 0.5f;
        Point2D focus = new Point2D.Float(xPos + baseHeight / 3 - 1, yPos + baseHeight / 3 - 1);
        float[] dist = { 0.1f, 1.0f };
        Color[] colors = { Color.white, exterior };
        RadialGradientPaint p = new RadialGradientPaint(center, radius, focus, dist, colors, CycleMethod.NO_CYCLE);
        g2.setPaint(p);
        Ellipse2D circle = new Ellipse2D.Double(xPos, yPos, baseHeight, baseHeight);
        g2.fill(circle);
        Ellipse2D circle2 = new Ellipse2D.Double(xPos - 1, yPos - 1, baseHeight + 0.7, baseHeight + 0.7);
        g2.setPaint(getDefaultColor(Color.DARK_GRAY));
        int z = shapePanel.getZoomFactor();
        g2.setStroke(new BasicStroke(2.0f + 0.14f * z));
        g2.draw(circle2);
        if (owner == null) {
            Font font = fontOld.deriveFont(Font.BOLD);
            g.setFont(font);
            g.setColor(Color.red.darker().darker());
            g2.drawString("Error parsing generated species!", xPos + baseHeight + 10, yPos + baseHeight - 9);
        }
        g2.setFont(fontOld);
        g2.setColor(colorOld);
        g2.setStroke(strokeOld);
        return;
    } else {
        // molecular type, species pattern, observable
        if (mt == null || mt.getModel() == null) {
            primaryColor = Color.blue.darker().darker();
        } else {
            if (shapePanel.getDisplayMode() == DisplayMode.participantSignatures) {
                if (!shapePanel.isShowMoleculeColor()) {
                    primaryColor = AbstractComponentShape.componentVeryLightGray;
                } else {
                    RbmModelContainer rbmmc = mt.getModel().getRbmModelContainer();
                    List<MolecularType> mtList = rbmmc.getMolecularTypeList();
                    int index = mtList.indexOf(mt);
                    index = index % 7;
                    primaryColor = colorTable[index].darker().darker();
                }
                if (shapePanel.isShowDifferencesOnly()) {
                    ReactionRule reactionRule = (ReactionRule) owner;
                    switch(shapePanel.hasNoMatch(reactionRule.getName(), mtp)) {
                        case CHANGED:
                            primaryColor = AbstractComponentShape.deepOrange;
                            break;
                        case // keep whatever color we set above
                        UNCHANGED:
                            break;
                        case ANALYSISFAILED:
                            ArrayList<Issue> issueList = new ArrayList<Issue>();
                            reactionRule.gatherIssues(new IssueContext(), issueList);
                            boolean bRuleHasErrorIssues = false;
                            for (Issue issue : issueList) {
                                if (issue.getSeverity() == Severity.ERROR) {
                                    bRuleHasErrorIssues = true;
                                    break;
                                }
                            }
                            if (bRuleHasErrorIssues) {
                                primaryColor = AbstractComponentShape.componentHidden;
                            } else {
                                System.err.println("ReactionRule Analysis failed, but there are not Error Issues with ReactionRule " + reactionRule.getName());
                                primaryColor = Color.red.darker();
                            }
                            break;
                        default:
                            break;
                    }
                }
            } else if (shapePanel.getDisplayMode() == DisplayMode.rules) {
                if (!shapePanel.isShowMoleculeColor()) {
                    primaryColor = AbstractComponentShape.componentVeryLightGray;
                } else {
                    RbmModelContainer rbmmc = mt.getModel().getRbmModelContainer();
                    List<MolecularType> mtList = rbmmc.getMolecularTypeList();
                    int index = mtList.indexOf(mt);
                    index = index % 7;
                    primaryColor = colorTable[index].darker().darker();
                }
                // if we show difference, we apply that now and override the color
                if (shapePanel.isShowDifferencesOnly()) {
                    ReactionRule reactionRule = (ReactionRule) owner;
                    switch(shapePanel.hasNoMatch(mtp)) {
                        case CHANGED:
                            primaryColor = AbstractComponentShape.deepOrange;
                            break;
                        case // keep whatever color we set above
                        UNCHANGED:
                            break;
                        case ANALYSISFAILED:
                            ArrayList<Issue> issueList = new ArrayList<Issue>();
                            reactionRule.gatherIssues(new IssueContext(), issueList);
                            boolean bRuleHasErrorIssues = false;
                            for (Issue issue : issueList) {
                                if (issue.getSeverity() == Severity.ERROR) {
                                    bRuleHasErrorIssues = true;
                                    break;
                                }
                            }
                            if (bRuleHasErrorIssues) {
                                primaryColor = AbstractComponentShape.componentHidden;
                            } else {
                                System.err.println("ReactionRule Analysis failed, but there are not Error Issues with ReactionRule " + reactionRule.getName());
                                primaryColor = Color.red.darker();
                            }
                            break;
                        default:
                            break;
                    }
                }
            } else {
                // TODO: do we ever get here legitimately? if not throw an exception!
                RbmModelContainer rbmmc = mt.getModel().getRbmModelContainer();
                List<MolecularType> mtList = rbmmc.getMolecularTypeList();
                int index = mtList.indexOf(mt);
                index = index % 7;
                if (!shapePanel.isShowMoleculeColor()) {
                    primaryColor = AbstractComponentShape.componentVeryLightGray;
                } else {
                    primaryColor = isHighlighted() == true ? Color.white : colorTable[index].darker().darker();
                }
                if (hasErrorIssues(owner, mt)) {
                    primaryColor = isHighlighted() ? Color.white : Color.red;
                }
            }
        }
    }
    // paint the structure contour if applicable (only for anchored molecules!)
    if (structure != null && mt != null && !mt.isAnchorAll() && mt.getAnchors().size() > 0) {
        paintNarrowCompartmentRight(g);
    } else if (owner instanceof MolecularType && !mt.isAnchorAll()) {
        paintNarrowCompartmentRight(g);
    }
    // paint the shape of the molecule and fill it with color
    GradientPaint p = new GradientPaint(xPos, yPos, primaryColor, xPos, yPos + baseHeight / 2, Color.WHITE, true);
    g2.setPaint(p);
    RoundRectangle2D rect = new RoundRectangle2D.Float(xPos, yPos, width, baseHeight, cornerArc, cornerArc);
    g2.fill(rect);
    RoundRectangle2D inner = new RoundRectangle2D.Float(xPos + 1, yPos + 1, width - 2, baseHeight - 2, cornerArc - 3, cornerArc - 3);
    if (isHighlighted()) {
        if (hasErrorIssues(owner, mt)) {
            g2.setPaint(Color.red);
        } else {
            g2.setPaint(getDefaultColor(Color.BLACK));
        }
        g2.draw(inner);
        if (hasErrorIssues(owner, mt)) {
            g2.setPaint(Color.red);
        } else {
            g2.setPaint(getDefaultColor(Color.BLACK));
        }
        g2.draw(rect);
    } else {
        if (hasErrorIssues(owner, mt)) {
            g2.setPaint(Color.red.darker());
        } else {
            g2.setPaint(getDefaultColor(Color.GRAY));
        }
        g2.draw(inner);
        if (hasErrorIssues(owner, mt)) {
            g2.setPaint(Color.red.darker());
        } else {
            g2.setPaint(getDefaultColor(Color.DARK_GRAY));
        }
        g2.draw(rect);
    }
    // paint the anchor glyph
    Rectangle r = getAnchorHotspot();
    if (r != null) {
        // g2.drawRect(r.x, r.y, r.width, r.height);	// anchor tooltip hotspot area
        int z = shapePanel.getZoomFactor();
        int w = r.width;
        int x = r.x + w / 2;
        int y = r.y;
        int h = 12 + z / 2;
        h = z < -2 ? h - 1 : h;
        h = z < -4 ? h - 1 : h;
        Line2D line = new Line2D.Float(x, y, x, y + h);
        g2.setPaint(getDefaultColor(Color.RED.darker().darker()));
        g2.setStroke(new BasicStroke(2.6f + 0.13f * z));
        g2.draw(line);
        // TODO: adjust the arc at deep zoom!
        double a1 = z < -3 ? 245 : 240;
        // 60
        double a2 = z < -3 ? 52 : 59;
        Arc2D arc = new Arc2D.Double(x - h, y - h, 2 * h, 2 * h, a1, a2, Arc2D.OPEN);
        g2.setStroke(new BasicStroke(2.6f + 0.20f * z));
        g2.draw(arc);
        g2.setPaint(colorOld);
        g2.setStroke(strokeOld);
    }
    // the text inside the molecule shape
    if (mt == null && mtp == null) {
    // plain species context
    // don't write any text inside
    } else {
        // molecular type, species pattern
        Graphics gc = shapePanel.getGraphics();
        Font font = deriveMoleculeFontBold(g, shapePanel);
        g.setFont(font);
        // font color
        g.setColor(getDefaultColor(Color.BLACK));
        int fontSize = font.getSize();
        int textX = xPos + 11;
        int textY = yPos + baseHeight - (baseHeight - fontSize) / 2;
        g2.drawString(name, textX, textY);
        if (owner instanceof ReactionRule && mtp != null && mtp.hasExplicitParticipantMatch()) {
            int z = shapePanel.getZoomFactor();
            if (z >= LargeShapeCanvas.SmallestZoomFactorWithText) {
                // hide the matching too when we don't display the name
                FontMetrics fm = gc.getFontMetrics(font);
                int stringWidth = fm.stringWidth(name);
                Font smallerFont = font.deriveFont(font.getSize() * 0.8F);
                g.setFont(smallerFont);
                g2.drawString(mtp.getParticipantMatchLabel(), textX + stringWidth + 2, textY + 2);
            }
        }
    }
    g.setFont(fontOld);
    g.setColor(colorOld);
    g2.setStroke(strokeOld);
    for (MolecularComponentLargeShape mcls : componentShapes) {
        // paint the components
        mcls.paintSelf(g);
    }
    g2.setFont(fontOld);
    g2.setColor(colorOld);
    g2.setStroke(strokeOld);
}
Also used : BasicStroke(java.awt.BasicStroke) Issue(org.vcell.util.Issue) RoundRectangle2D(java.awt.geom.RoundRectangle2D) ArrayList(java.util.ArrayList) Rectangle(java.awt.Rectangle) RadialGradientPaint(java.awt.RadialGradientPaint) GradientPaint(java.awt.GradientPaint) Line2D(java.awt.geom.Line2D) Arc2D(java.awt.geom.Arc2D) Font(java.awt.Font) Ellipse2D(java.awt.geom.Ellipse2D) Point2D(java.awt.geom.Point2D) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) FontMetrics(java.awt.FontMetrics) IssueContext(org.vcell.util.IssueContext) ArrayList(java.util.ArrayList) List(java.util.List) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) ReactionRule(cbit.vcell.model.ReactionRule) Color(java.awt.Color) RadialGradientPaint(java.awt.RadialGradientPaint) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D) MolecularType(org.vcell.model.rbm.MolecularType) Graphics(java.awt.Graphics)

Example 17 with RbmModelContainer

use of cbit.vcell.model.Model.RbmModelContainer in project vcell by virtualcell.

the class BioModelEditorTreeCellRenderer method getTreeCellRendererComponent.

public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    if (regularFont == null) {
        regularFont = getFont();
        boldFont = regularFont.deriveFont(Font.BOLD);
    }
    Font font = regularFont;
    Icon icon = null;
    String labelText = null;
    String toolTipPrefix = "";
    String toolTipSuffix = "";
    if (value instanceof LinkNode) {
        LinkNode ln = (LinkNode) value;
        String link = ln.getLink();
        String text = ln.getText();
        String qualifier = ln.getMiriamQualifier().getDescription();
        if (link != null) {
            String colorString = (sel) ? "white" : "blue";
            toolTipPrefix = "double-click to open link " + link;
            labelText = "<html>" + qualifier + "&nbsp;<font color=\"" + colorString + "\"><a href=" + link + ">" + text + "</a></font></html>";
        } else {
            String colorString = (sel) ? "white" : "black";
            labelText = "<html>" + qualifier + "&nbsp;<font color=\"" + colorString + "\">" + text + "</font></html>";
        }
    } else if (value instanceof BioModelNode) {
        BioModelNode node = (BioModelNode) value;
        Object userObj = node.getUserObject();
        if (userObj instanceof BioModel) {
            font = boldFont;
            icon = VCellIcons.documentIcon;
            labelText = ((BioModel) userObj).getName();
            toolTipPrefix = "BioModel: ";
        } else if (userObj instanceof SimulationContext) {
            // --- root: application name
            font = boldFont;
            // icon = VCellIcons.applicationIcon;
            SimulationContext simContext = (SimulationContext) userObj;
            if (simContext.isRuleBased()) {
                if (simContext.getGeometry().getDimension() == 0) {
                    icon = VCellIcons.appRbmNonspIcon;
                    toolTipSuffix = "Rule Based / Non spatial";
                }
            } else if (simContext.isStoch()) {
                if (simContext.getGeometry().getDimension() == 0) {
                    icon = VCellIcons.appStoNonspIcon;
                    toolTipSuffix = "Stochastic / Non spatial";
                } else {
                    icon = VCellIcons.appStoSpatialIcon;
                    toolTipSuffix = "Stochastic / Spatial";
                }
            } else {
                // deterministic
                if (simContext.getGeometry().getDimension() == 0) {
                    icon = VCellIcons.appDetNonspIcon;
                    toolTipSuffix = "Deterministic / Non spatial";
                } else {
                    icon = VCellIcons.appDetSpatialIcon;
                    toolTipSuffix = "Deterministic / Spatial";
                }
            }
            labelText = /*"Application: " + */
            ((SimulationContext) userObj).getName();
            toolTipPrefix = "Application: ";
        } else if (userObj instanceof DocumentEditorTreeFolderNode) {
            // --- 1st level folders
            DocumentEditorTreeFolderNode folder = (DocumentEditorTreeFolderNode) userObj;
            labelText = folder.getName();
            if (folder.isBold()) {
                font = boldFont;
            }
            DocumentEditorTreeFolderClass folderClass = folder.getFolderClass();
            switch(folderClass) {
                // break;
                case REACTIONS_NODE:
                    icon = VCellIcons.tableIcon;
                    if (bioModel == null) {
                        labelText = folder.getName() + "(00000)";
                    } else {
                        int numReactions = bioModel.getModel().getNumReactions();
                        if (bioModel.getModel().getRbmModelContainer() != null) {
                            numReactions += bioModel.getModel().getRbmModelContainer().getReactionRuleList().size();
                        }
                        labelText = folder.getName() + " (" + numReactions + ")";
                    }
                    break;
                case STRUCTURES_NODE:
                    icon = VCellIcons.tableIcon;
                    if (bioModel == null) {
                        labelText = folder.getName() + "(00000)";
                    } else {
                        labelText = folder.getName() + " (" + bioModel.getModel().getNumStructures() + ")";
                    }
                    break;
                case SPECIES_NODE:
                    icon = VCellIcons.tableIcon;
                    if (bioModel == null) {
                        labelText = folder.getName() + "(00000)";
                    } else {
                        labelText = folder.getName() + " (" + bioModel.getModel().getNumSpeciesContexts() + ")";
                    }
                    break;
                case MOLECULAR_TYPES_NODE:
                    icon = VCellIcons.tableIcon;
                    if (bioModel == null) {
                        labelText = folder.getName() + "(00000)";
                    } else {
                        RbmModelContainer rbmModelContainer = bioModel.getModel().getRbmModelContainer();
                        if (rbmModelContainer == null) {
                            labelText = folder.getName() + "(00000)";
                        } else {
                            labelText = folder.getName() + " (" + rbmModelContainer.getMolecularTypeList().size() + ")";
                        }
                    }
                    break;
                case OBSERVABLES_NODE:
                    icon = VCellIcons.tableIcon;
                    if (bioModel == null) {
                        labelText = folder.getName() + "(00000)";
                    } else {
                        RbmModelContainer rbmModelContainer = bioModel.getModel().getRbmModelContainer();
                        if (rbmModelContainer == null) {
                            labelText = folder.getName() + "(00000)";
                        } else {
                            labelText = folder.getName() + " (" + rbmModelContainer.getObservableList().size() + ")";
                        }
                    }
                    break;
                case APPLICATIONS_NODE:
                    if (bioModel == null) {
                        labelText = folder.getName() + "(00000)";
                    } else {
                        labelText = folder.getName() + " (" + bioModel.getNumSimulationContexts() + ")";
                    }
                    break;
                case REACTION_DIAGRAM_NODE:
                    icon = VCellIcons.diagramIcon;
                    break;
                // break;
                case GEOMETRY_NODE:
                    icon = VCellIcons.geometryIcon;
                    break;
                case SPECIFICATIONS_NODE:
                    icon = VCellIcons.settingsIcon;
                    break;
                case PROTOCOLS_NODE:
                    icon = VCellIcons.protocolsIcon;
                    break;
                case SIMULATIONS_NODE:
                    icon = VCellIcons.simulationIcon;
                    break;
                case PARAMETER_ESTIMATION_NODE:
                    icon = VCellIcons.fittingIcon;
                    break;
                case PATHWAY_DIAGRAM_NODE:
                    icon = VCellIcons.diagramIcon;
                    break;
                case PATHWAY_OBJECTS_NODE:
                    icon = VCellIcons.tableIcon;
                    if (bioModel == null) {
                        labelText = folder.getName() + "(00000)";
                    } else {
                        labelText = folder.getName() + " (" + bioModel.getPathwayModel().getBiopaxObjects().size() + ")";
                    }
                    break;
                case BIOPAX_SUMMARY_NODE:
                    icon = VCellIcons.textNotesIcon;
                    break;
                case BIOPAX_TREE_NODE:
                    icon = VCellIcons.tableIcon;
                    break;
            }
        }
    }
    setIcon(icon);
    setFont(font);
    setText(labelText);
    if (toolTipSuffix.length() == 0) {
        toolTipSuffix = labelText;
    }
    setToolTipText(toolTipPrefix + toolTipSuffix);
    return this;
}
Also used : RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) BioModel(cbit.vcell.biomodel.BioModel) LinkNode(cbit.vcell.xml.gui.MiriamTreeModel.LinkNode) DocumentEditorTreeFolderNode(cbit.vcell.client.desktop.biomodel.DocumentEditorTreeModel.DocumentEditorTreeFolderNode) BioModelNode(cbit.vcell.desktop.BioModelNode) Icon(javax.swing.Icon) SimulationContext(cbit.vcell.mapping.SimulationContext) DocumentEditorTreeFolderClass(cbit.vcell.client.desktop.biomodel.DocumentEditorTreeModel.DocumentEditorTreeFolderClass) Font(java.awt.Font)

Example 18 with RbmModelContainer

use of cbit.vcell.model.Model.RbmModelContainer in project vcell by virtualcell.

the class XmlReader method getRbmNetworkConstraints.

private void getRbmNetworkConstraints(Element e, Model newModel) {
    RbmModelContainer mc = newModel.getRbmModelContainer();
    NetworkConstraints nc = new NetworkConstraints();
    this.legacyNetworkConstraints = nc;
    String s = e.getAttributeValue(XMLTags.RbmMaxIterationTag);
    if (s != null && !s.isEmpty()) {
        int maxIteration = Integer.parseInt(s);
        nc.setMaxIteration(maxIteration);
    }
    s = e.getAttributeValue(XMLTags.RbmMaxMoleculesPerSpeciesTag);
    if (s != null && !s.isEmpty()) {
        int maxMoleculesPerSpecies = Integer.parseInt(s);
        nc.setMaxMoleculesPerSpecies(maxMoleculesPerSpecies);
    }
    List<Element> children = e.getChildren(XMLTags.RbmMaxStoichiometryTag, vcNamespace);
    for (Element element : children) {
        Integer i = 1;
        MolecularType mt = null;
        s = element.getAttributeValue(XMLTags.RbmIntegerAttrTag);
        if (s != null && !s.isEmpty()) {
            i = Integer.getInteger(s);
        }
        s = element.getAttributeValue(XMLTags.RbmMolecularTypeTag);
        if (s != null && !s.isEmpty()) {
            mt = mc.getMolecularType(s);
        }
        if (mt != null) {
            nc.setMaxStoichiometry(mt, i);
        }
    }
}
Also used : ParticleMolecularType(cbit.vcell.math.ParticleMolecularType) MolecularType(org.vcell.model.rbm.MolecularType) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) Element(org.jdom.Element) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 19 with RbmModelContainer

use of cbit.vcell.model.Model.RbmModelContainer in project vcell by virtualcell.

the class XmlReader method getAppNetworkConstraints.

// public because it's being called in simcontexttable to read from the app components element
public NetworkConstraints getAppNetworkConstraints(Element e, Model newModel) {
    RbmModelContainer mc = newModel.getRbmModelContainer();
    NetworkConstraints nc = new NetworkConstraints();
    String s = e.getAttributeValue(XMLTags.RbmMaxIterationTag);
    if (s != null && !s.isEmpty()) {
        int maxIteration = Integer.parseInt(s);
        nc.setMaxIteration(maxIteration);
    }
    s = e.getAttributeValue(XMLTags.RbmMaxMoleculesPerSpeciesTag);
    if (s != null && !s.isEmpty()) {
        int maxMoleculesPerSpecies = Integer.parseInt(s);
        nc.setMaxMoleculesPerSpecies(maxMoleculesPerSpecies);
    }
    List<Element> children = e.getChildren(XMLTags.RbmMaxStoichiometryTag, vcNamespace);
    for (Element element : children) {
        Integer i = 1;
        MolecularType mt = null;
        s = element.getAttributeValue(XMLTags.RbmIntegerAttrTag);
        if (s != null && !s.isEmpty()) {
            i = Integer.getInteger(s);
        }
        s = element.getAttributeValue(XMLTags.RbmMolecularTypeTag);
        if (s != null && !s.isEmpty()) {
            mt = mc.getMolecularType(s);
        }
        if (mt != null) {
            nc.setMaxStoichiometry(mt, i);
        }
    }
    return nc;
}
Also used : ParticleMolecularType(cbit.vcell.math.ParticleMolecularType) MolecularType(org.vcell.model.rbm.MolecularType) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) Element(org.jdom.Element) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 20 with RbmModelContainer

use of cbit.vcell.model.Model.RbmModelContainer in project vcell by virtualcell.

the class RbmNetworkGenerator method writeBngl_internal.

public static void writeBngl_internal(SimulationContext simulationContext, PrintWriter writer, Map<FakeReactionRuleRateParameter, LocalParameter> kineticsParameterMap, Map<FakeSeedSpeciesInitialConditionsParameter, Pair<SpeciesContext, Expression>> speciesEquivalenceMap, NetworkGenerationRequirements networkGenerationRequirements, CompartmentMode compartmentMode) {
    String callerClassName = new Exception().getStackTrace()[1].getClassName();
    String networkTransformerClassName = NetworkTransformer.class.getName();
    String rulebasedTransformerClassName = RulebasedTransformer.class.getName();
    if (!callerClassName.equals(networkTransformerClassName) && !callerClassName.equals(rulebasedTransformerClassName)) {
        throw new UnsupportedOperationException("This method may only be called from within a " + networkTransformerClassName + " or " + rulebasedTransformerClassName + " instance.");
    }
    Model model = simulationContext.getModel();
    RbmModelContainer rbmModelContainer = model.getRbmModelContainer();
    checkConsistency(model);
    // first we prepare the fake parameters we need to maintain the relationship between the species context and the seed species
    List<FakeSeedSpeciesInitialConditionsParameter> fakeParameterList = new ArrayList<FakeSeedSpeciesInitialConditionsParameter>();
    List<String> seedSpeciesList = new ArrayList<String>();
    SpeciesContext[] speciesContexts = model.getSpeciesContexts();
    for (int i = 0; i < speciesContexts.length; i++) {
        SpeciesContext sc = speciesContexts[i];
        if (!sc.hasSpeciesPattern()) {
            continue;
        }
        SpeciesContextSpec scs = simulationContext.getReactionContext().getSpeciesContextSpec(sc);
        Expression initialConcentration = scs.getParameter(SpeciesContextSpec.ROLE_InitialConcentration).getExpression();
        // fake initial values for the seed species, we need to present them to bngl as parameters
        FakeSeedSpeciesInitialConditionsParameter fakeSeedSpeciesParam = new FakeSeedSpeciesInitialConditionsParameter(sc.getName());
        Pair<SpeciesContext, Expression> p = new Pair<SpeciesContext, Expression>(sc, initialConcentration);
        speciesEquivalenceMap.put(fakeSeedSpeciesParam, p);
        String modified;
        if (compartmentMode == CompartmentMode.show) {
            modified = RbmUtils.toBnglString(sc.getSpeciesPattern(), null, CompartmentMode.hide, 0);
            modified = "@" + sc.getStructure().getName() + ":" + modified;
        } else if (compartmentMode == CompartmentMode.asSite) {
            modified = RbmUtils.toBnglString(sc.getSpeciesPattern(), sc.getStructure(), CompartmentMode.asSite, 0);
        } else {
            // CompartmentMode.hide
            modified = RbmUtils.toBnglString(sc.getSpeciesPattern(), null, CompartmentMode.hide, 0);
        }
        modified += " " + fakeSeedSpeciesParam.fakeParameterName;
        // we label the seed species with the index
        modified = (i + 1) + " " + modified;
        // we build the seed species list now, we write it later (in the BEGIN SPECIES block)
        seedSpeciesList.add(modified);
        fakeParameterList.add(fakeSeedSpeciesParam);
    }
    // second we produce the bngl file
    writer.println(BEGIN_MODEL);
    writer.println();
    for (ReactionRuleSpec rrs : simulationContext.getReactionContext().getReactionRuleSpecs()) {
        if (!rrs.isExcluded()) {
            ReactionRule reactionRule = rrs.getReactionRule();
            RbmKineticLaw kineticLaw = reactionRule.getKineticLaw();
            switch(kineticLaw.getRateLawType()) {
                case MassAction:
                    {
                        FakeReactionRuleRateParameter fakeRateParameterForward = new FakeReactionRuleRateParameter(reactionRule, RbmKineticLawParameterType.MassActionForwardRate);
                        LocalParameter origForwardRateParameter = kineticLaw.getLocalParameter(RbmKineticLawParameterType.MassActionForwardRate);
                        kineticsParameterMap.put(fakeRateParameterForward, origForwardRateParameter);
                        if (reactionRule.isReversible()) {
                            FakeReactionRuleRateParameter fakeRateParameterReverse = new FakeReactionRuleRateParameter(reactionRule, RbmKineticLawParameterType.MassActionReverseRate);
                            LocalParameter origReverseRateParameter = kineticLaw.getLocalParameter(RbmKineticLawParameterType.MassActionReverseRate);
                            kineticsParameterMap.put(fakeRateParameterReverse, origReverseRateParameter);
                        }
                        break;
                    }
                default:
                    {
                        throw new RuntimeException("kinetic law type " + kineticLaw.getRateLawType().name() + " not yet implemented");
                    }
            }
        }
    }
    if (compartmentMode == CompartmentMode.show) {
        RbmNetworkGenerator.writeCompartments(writer, model, simulationContext);
    }
    writer.println(BEGIN_PARAMETERS);
    // the fake parameters used for reaction rule kinetics
    for (FakeReactionRuleRateParameter p : kineticsParameterMap.keySet()) {
        writer.println(p.fakeParameterName + "\t\t1");
    }
    // the fake parameters used at initial values for the seed species
    for (FakeSeedSpeciesInitialConditionsParameter s : fakeParameterList) {
        writer.println(s.fakeParameterName + "\t\t1");
    }
    writer.println(END_PARAMETERS);
    writer.println();
    RbmNetworkGenerator.writeMolecularTypes(writer, model, compartmentMode);
    // write modified version of seed species while maintaining the connection between the species context and the real seed species
    writer.println(BEGIN_SPECIES);
    for (String s : seedSpeciesList) {
        writer.println(s);
    }
    writer.println(END_SPECIES);
    writer.println();
    RbmNetworkGenerator.writeObservables(writer, rbmModelContainer, compartmentMode);
    RbmNetworkGenerator.writeReactions_internal(writer, simulationContext, compartmentMode);
    writer.println(END_MODEL);
    writer.println();
    if (callerClassName.equals(networkTransformerClassName)) {
        RbmNetworkGenerator.writeNetworkConstraints(writer, rbmModelContainer, simulationContext, networkGenerationRequirements);
    } else if (callerClassName.equals(rulebasedTransformerClassName)) {
        writer.println();
        writer.println("writeXML()");
    }
    writer.println();
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) ReactionRuleSpec(cbit.vcell.mapping.ReactionRuleSpec) ArrayList(java.util.ArrayList) SpeciesContext(cbit.vcell.model.SpeciesContext) RbmKineticLaw(cbit.vcell.model.RbmKineticLaw) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) Expression(cbit.vcell.parser.Expression) BioModel(cbit.vcell.biomodel.BioModel) Model(cbit.vcell.model.Model) Pair(org.vcell.util.Pair)

Aggregations

RbmModelContainer (cbit.vcell.model.Model.RbmModelContainer)26 MolecularType (org.vcell.model.rbm.MolecularType)12 Element (org.jdom.Element)10 BioModel (cbit.vcell.biomodel.BioModel)9 ArrayList (java.util.ArrayList)9 Model (cbit.vcell.model.Model)8 ReactionRule (cbit.vcell.model.ReactionRule)7 SimulationContext (cbit.vcell.mapping.SimulationContext)5 RbmObservable (cbit.vcell.model.RbmObservable)5 ReactionStep (cbit.vcell.model.ReactionStep)5 Structure (cbit.vcell.model.Structure)5 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)4 ParticleMolecularType (cbit.vcell.math.ParticleMolecularType)4 SpeciesContext (cbit.vcell.model.SpeciesContext)4 MathModel (cbit.vcell.mathmodel.MathModel)3 Expression (cbit.vcell.parser.Expression)3 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)3 Geometry (cbit.vcell.geometry.Geometry)2 BioEvent (cbit.vcell.mapping.BioEvent)2 GeometryContext (cbit.vcell.mapping.GeometryContext)2