Search in sources :

Example 1 with SpeciesPattern

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

the class ViewGeneratedReactionsPanel method updateShape.

public void updateShape(int selectedRow) {
    GeneratedReactionTableRow reactionTableRow = tableModel.getValueAt(selectedRow);
    String inputString = reactionTableRow.getExpression();
    System.out.println(selectedRow + ": " + inputString);
    // ReactionRule newReactionRule = (ReactionRule)RbmUtils.parseReactionRule(inputString, bioModel);
    Model tempModel = null;
    try {
        tempModel = new Model("MyTempModel");
        tempModel.addFeature("c0");
    } catch (ModelException | PropertyVetoException e1) {
        e1.printStackTrace();
    }
    if (owner != null && owner.getSimulationContext() != null) {
        List<MolecularType> mtList = owner.getSimulationContext().getModel().getRbmModelContainer().getMolecularTypeList();
        try {
            tempModel.getRbmModelContainer().setMolecularTypeList(mtList);
        } catch (PropertyVetoException e1) {
            e1.printStackTrace();
            throw new RuntimeException("Unexpected exception setting " + MolecularType.typeName + " list: " + e1.getMessage(), e1);
        }
    } else {
        // This should not be possible
        throw new RuntimeException("Owner or SimulationContext are null.");
    }
    int arrowIndex = inputString.indexOf("<->");
    boolean bReversible = true;
    if (arrowIndex < 0) {
        arrowIndex = inputString.indexOf("->");
        bReversible = false;
    }
    String left = inputString.substring(0, arrowIndex).trim();
    String right = inputString.substring(arrowIndex + (bReversible ? 3 : 2)).trim();
    if (left.length() == 0 && right.length() == 0) {
        return;
    }
    // we recover the original rule that generated the flattened reaction we now try to transform back into a fake rule
    BNGReaction reactionObject = reactionTableRow.getReactionObject();
    String name = reactionObject.getRuleName();
    if (name.contains(GeneratedReactionTableModel.reverse)) {
        name = name.substring(GeneratedReactionTableModel.reverse.length());
    }
    if (name.endsWith(ReactionRule.DirectHalf)) {
        name = name.substring(0, name.indexOf(ReactionRule.DirectHalf));
    }
    if (name.endsWith(ReactionRule.InverseHalf)) {
        name = name.substring(0, name.indexOf(ReactionRule.InverseHalf));
    }
    // get the name of the original structure from the original rule and make here another structure with the same name
    String strStructure = null;
    Structure ruleStructure;
    SimulationContext sc = owner.getSimulationContext();
    ReactionRule rr = sc.getModel().getRbmModelContainer().getReactionRule(name);
    if (rr != null && rr.getStructure() != null) {
        strStructure = rr.getStructure().getName();
    }
    if (strStructure != null) {
        if (tempModel.getStructure(strStructure) == null) {
            try {
                if (rr.getStructure().getTypeName().equals(Structure.TYPE_NAME_MEMBRANE)) {
                    tempModel.addMembrane(strStructure);
                } else {
                    tempModel.addFeature(strStructure);
                }
            } catch (ModelException | PropertyVetoException e) {
                e.printStackTrace();
            }
        }
        ruleStructure = tempModel.getStructure(strStructure);
    } else {
        throw new RuntimeException("Failed to recover a Structure name from the Reaction Rule: " + name);
    }
    // making the fake rules just for display purpose, actually they are the flattened reactions resulted from bngl
    // the name is probably not unique, it's likely that many flattened reactions are derived from the same rule
    ReactionRule reactionRule = tempModel.getRbmModelContainer().createReactionRule(name, ruleStructure, bReversible);
    String regex = "[^!]\\+";
    String[] patterns = left.split(regex);
    for (String spString : patterns) {
        try {
            spString = spString.trim();
            // if compartments are present, we're cheating big time making some fake compartments just for compartment name display purposes
            SpeciesPattern speciesPattern = (SpeciesPattern) RbmUtils.parseSpeciesPattern(spString, tempModel);
            strStructure = RbmUtils.parseCompartment(spString, tempModel);
            speciesPattern.resolveBonds();
            Structure structure;
            if (strStructure != null) {
                if (tempModel.getStructure(strStructure) == null) {
                    if (sc.getModel().getStructure(strStructure).getTypeName().equals(Structure.TYPE_NAME_MEMBRANE)) {
                        tempModel.addMembrane(strStructure);
                    } else {
                        tempModel.addFeature(strStructure);
                    }
                }
                structure = tempModel.getStructure(strStructure);
            } else {
                // if nothing explicit for a participant, we use by default the structure of the rule
                structure = ruleStructure;
            }
            reactionRule.addReactant(new ReactantPattern(speciesPattern, structure));
        } catch (Throwable ex) {
            ex.printStackTrace();
            // error (red circle)
            SpeciesPatternLargeShape spls = new SpeciesPatternLargeShape(20, 20, -1, shapePanel, true, issueManager);
            reactantPatternShapeList.clear();
            productPatternShapeList.clear();
            reactantPatternShapeList.add(spls);
            shapePanel.repaint();
            return;
        }
    }
    patterns = right.split(regex);
    for (String spString : patterns) {
        try {
            spString = spString.trim();
            SpeciesPattern speciesPattern = (SpeciesPattern) RbmUtils.parseSpeciesPattern(spString, tempModel);
            strStructure = RbmUtils.parseCompartment(spString, tempModel);
            speciesPattern.resolveBonds();
            Structure structure;
            if (strStructure != null) {
                if (tempModel.getStructure(strStructure) == null) {
                    if (sc.getModel().getStructure(strStructure).getTypeName().equals(Structure.TYPE_NAME_MEMBRANE)) {
                        tempModel.addMembrane(strStructure);
                    } else {
                        tempModel.addFeature(strStructure);
                    }
                }
                structure = tempModel.getStructure(strStructure);
            } else {
                structure = ruleStructure;
            }
            // BNGLParser parser = new BNGLParser(new StringReader(sp));
            // ASTSpeciesPattern astSpeciesPattern = parser.SpeciesPattern();
            // BnglObjectConstructionVisitor constructionVisitor = new BnglObjectConstructionVisitor(tempModel, null, false);
            // SpeciesPattern speciesPattern = (SpeciesPattern) astSpeciesPattern.jjtAccept(constructionVisitor, null);
            // for(MolecularTypePattern mtp : speciesPattern.getMolecularTypePatterns()) {
            // mtp.setParticipantMatchLabel("*");
            // }
            // System.out.println(speciesPattern.toString());
            reactionRule.addProduct(new ProductPattern(speciesPattern, structure));
        } catch (Throwable ex) {
            ex.printStackTrace();
            // error (red circle)
            SpeciesPatternLargeShape spls = new SpeciesPatternLargeShape(20, 20, -1, shapePanel, true, issueManager);
            reactantPatternShapeList.clear();
            productPatternShapeList.clear();
            reactantPatternShapeList.add(spls);
            shapePanel.repaint();
            return;
        }
    }
    // ----------------------------------------------------------------------------------------------------
    List<ReactantPattern> rpList = reactionRule.getReactantPatterns();
    reactantPatternShapeList.clear();
    int xOffset = 20;
    int xOffsetRound = 20;
    if (rpList != null && rpList.size() > 0) {
        for (int i = 0; i < rpList.size(); i++) {
            SpeciesPattern sp = rpList.get(i).getSpeciesPattern();
            for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
                mtp.setParticipantMatchLabel("*");
            }
            SpeciesPatternLargeShape sps = new SpeciesPatternLargeShape(xOffset, 20, -1, sp, shapePanel, reactionRule, issueManager);
            // SpeciesPatternRoundShape sps = new SpeciesPatternRoundShape(xOffsetRound, 20, -1, sp, shapePanel, reactionRule);
            if (i < rpList.size() - 1) {
                sps.addEndText("+");
            } else {
                if (reactionRule.isReversible()) {
                    sps.addEndText("<->");
                } else {
                    sps.addEndText("->");
                }
            }
            xOffset = sps.getRightEnd() + 45;
            xOffsetRound = sps.getRightEnd() + 45;
            reactantPatternShapeList.add(sps);
        }
    }
    // space for the <-> sign
    xOffset += 15;
    List<ProductPattern> ppList = reactionRule.getProductPatterns();
    productPatternShapeList.clear();
    if (ppList != null && ppList.size() > 0) {
        for (int i = 0; i < ppList.size(); i++) {
            SpeciesPattern sp = ppList.get(i).getSpeciesPattern();
            for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
                mtp.setParticipantMatchLabel("*");
            }
            SpeciesPatternLargeShape sps = new SpeciesPatternLargeShape(xOffset, 20, -1, sp, shapePanel, reactionRule, issueManager);
            // SpeciesPatternRoundShape sps = new SpeciesPatternRoundShape(xOffset, 20, -1, sp, shapePanel, reactionRule);
            if (i < ppList.size() - 1) {
                sps.addEndText("+");
            }
            xOffset = sps.getRightEnd() + 45;
            productPatternShapeList.add(sps);
        }
    }
    Dimension preferredSize = new Dimension(xOffset + 90, 50);
    shapePanel.setPreferredSize(preferredSize);
    shapePanel.repaint();
}
Also used : SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) Structure(cbit.vcell.model.Structure) ReactantPattern(cbit.vcell.model.ReactantPattern) ModelException(cbit.vcell.model.ModelException) ReactionRule(cbit.vcell.model.ReactionRule) ProductPattern(cbit.vcell.model.ProductPattern) Dimension(java.awt.Dimension) SimulationContext(cbit.vcell.mapping.SimulationContext) Point(java.awt.Point) PropertyVetoException(java.beans.PropertyVetoException) MolecularType(org.vcell.model.rbm.MolecularType) BNGReaction(cbit.vcell.bionetgen.BNGReaction) Model(cbit.vcell.model.Model) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) BioModel(cbit.vcell.biomodel.BioModel) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern)

Example 2 with SpeciesPattern

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

the class ViewObservablesMapPanel method initialize.

private void initialize() {
    try {
        // --------------------------------------- the split panels
        setName("ViewGeneratedSpeciesPanel");
        setLayout(new BorderLayout());
        JPanel topPanel = new JPanel();
        topPanel.setLayout(new GridBagLayout());
        JPanel bottomPanel = new JPanel();
        bottomPanel.setLayout(new GridBagLayout());
        JSplitPane splitPaneHorizontal = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        splitPaneHorizontal.setDividerSize(10);
        splitPaneHorizontal.setOneTouchExpandable(true);
        splitPaneHorizontal.setDividerLocation(260);
        splitPaneHorizontal.setResizeWeight(0.5);
        splitPaneHorizontal.setTopComponent(topPanel);
        splitPaneHorizontal.setBottomComponent(bottomPanel);
        add(splitPaneHorizontal, BorderLayout.CENTER);
        // ---------------------------------------- species shape panel
        shapePanelSpecies = new LargeShapePanel() {

            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                if (spls != null) {
                    spls.paintSelf(g);
                }
            }

            @Override
            public DisplayMode getDisplayMode() {
                return DisplayMode.other;
            }

            @Override
            public RuleAnalysisChanged hasStateChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasStateChanged(MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasBondChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasBondChanged(MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasNoMatch(String reactionRuleName, MolecularTypePattern mtp) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasNoMatch(MolecularTypePattern molecularTypePattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleParticipantSignature getSignature() {
                return null;
            }

            @Override
            public GroupingCriteria getCriteria() {
                return null;
            }

            @Override
            public boolean isViewSingleRow() {
                return true;
            }
        };
        shapePanelSpecies.setLayout(new GridBagLayout());
        shapePanelSpecies.setBackground(Color.white);
        // not really editable but we don't want the brown contours here
        shapePanelSpecies.setEditable(true);
        shapePanelSpecies.setShowMoleculeColor(true);
        shapePanelSpecies.setShowNonTrivialOnly(true);
        Border loweredBevelBorder = BorderFactory.createLoweredBevelBorder();
        JScrollPane scrollPaneSpecies = new JScrollPane(shapePanelSpecies);
        scrollPaneSpecies.setBorder(loweredBevelBorder);
        scrollPaneSpecies.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPaneSpecies.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
        JPanel optionsPanelSpecies = new JPanel();
        optionsPanelSpecies.setLayout(new GridBagLayout());
        getZoomSmallerButtonSpecies().setEnabled(true);
        getZoomLargerButtonSpecies().setEnabled(true);
        shapePanelSpecies.zoomSmaller();
        shapePanelSpecies.zoomSmaller();
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(0, 0, 0, 10);
        gbc.anchor = GridBagConstraints.WEST;
        optionsPanelSpecies.add(getZoomLargerButtonSpecies(), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(2, 0, 4, 10);
        gbc.anchor = GridBagConstraints.WEST;
        optionsPanelSpecies.add(getZoomSmallerButtonSpecies(), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.weightx = 1;
        // fake cell used for filling all the vertical empty space
        gbc.weighty = 1;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.insets = new Insets(4, 4, 4, 10);
        optionsPanelSpecies.add(new JLabel(""), gbc);
        JPanel containerOfScrollPanelSpecies = new JPanel();
        containerOfScrollPanelSpecies.setLayout(new BorderLayout());
        containerOfScrollPanelSpecies.add(optionsPanelSpecies, BorderLayout.WEST);
        containerOfScrollPanelSpecies.add(scrollPaneSpecies, BorderLayout.CENTER);
        Dimension dimS = new Dimension(500, 125);
        // dimension of shape panel
        containerOfScrollPanelSpecies.setPreferredSize(dimS);
        containerOfScrollPanelSpecies.setMinimumSize(dimS);
        containerOfScrollPanelSpecies.setMaximumSize(dimS);
        shapePanelObservable = new LargeShapePanel() {

            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                for (SpeciesPatternLargeShape sps : spsList) {
                    if (sps == null) {
                        continue;
                    }
                    sps.paintSelf(g);
                }
            }

            @Override
            public DisplayMode getDisplayMode() {
                return DisplayMode.other;
            }

            @Override
            public RuleAnalysisChanged hasStateChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasStateChanged(MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasBondChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasBondChanged(MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasNoMatch(String reactionRuleName, MolecularTypePattern mtp) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasNoMatch(MolecularTypePattern molecularTypePattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleParticipantSignature getSignature() {
                return null;
            }

            @Override
            public GroupingCriteria getCriteria() {
                return null;
            }

            @Override
            public boolean isViewSingleRow() {
                return true;
            }
        };
        // 
        DefaultScrollTableCellRenderer rbmSpeciesPatternCellRenderer = new DefaultScrollTableCellRenderer() {

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                if (table.getModel() instanceof GeneratedSpeciesTableModel2) {
                    Object selectedObject = null;
                    if (table.getModel() == speciesTableModel) {
                        selectedObject = speciesTableModel.getValueAt(row);
                    }
                    if (selectedObject != null) {
                        if (selectedObject instanceof GeneratedSpeciesTableRow && value instanceof String) {
                            SpeciesPattern sp = ((GeneratedSpeciesTableRow) selectedObject).getSpecies().getSpeciesPattern();
                            String text = "<html>";
                            text += RbmTableRenderer.toHtml(sp, isSelected);
                            text += "</html>";
                            setText(text);
                        }
                    }
                }
                return this;
            }
        };
        // shapePanelObservable.setLayout(null);
        shapePanelObservable.setLayout(new GridBagLayout());
        shapePanelObservable.setBackground(Color.white);
        shapePanelObservable.setEditable(true);
        shapePanelObservable.setShowMoleculeColor(true);
        shapePanelObservable.setShowNonTrivialOnly(true);
        JScrollPane scrollPaneObservable = new JScrollPane(shapePanelObservable);
        scrollPaneObservable.setBorder(loweredBevelBorder);
        scrollPaneObservable.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPaneObservable.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
        JPanel optionsPanelObservable = new JPanel();
        optionsPanelObservable.setLayout(new GridBagLayout());
        getZoomSmallerButtonObservable().setEnabled(true);
        getZoomLargerButtonObservable().setEnabled(true);
        shapePanelObservable.zoomSmaller();
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(0, 0, 0, 10);
        gbc.anchor = GridBagConstraints.WEST;
        optionsPanelObservable.add(getZoomLargerButtonObservable(), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(2, 0, 4, 10);
        gbc.anchor = GridBagConstraints.WEST;
        optionsPanelObservable.add(getZoomSmallerButtonObservable(), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.weightx = 1;
        // fake cell used for filling all the vertical empty space
        gbc.weighty = 1;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.insets = new Insets(4, 4, 4, 10);
        optionsPanelObservable.add(new JLabel(""), gbc);
        JPanel containerOfScrollPanelObservable = new JPanel();
        containerOfScrollPanelObservable.setLayout(new BorderLayout());
        containerOfScrollPanelObservable.add(optionsPanelObservable, BorderLayout.WEST);
        containerOfScrollPanelObservable.add(scrollPaneObservable, BorderLayout.CENTER);
        Dimension dimO = new Dimension(500, 100);
        // dimension of shape panel
        containerOfScrollPanelObservable.setPreferredSize(dimO);
        containerOfScrollPanelObservable.setMinimumSize(dimO);
        containerOfScrollPanelObservable.setMaximumSize(dimO);
        // -------------- connection between tables, table models, selection models, renderers, event handlers
        speciesTable = new EditorScrollTable();
        speciesTableModel = new GeneratedSpeciesTableModel2(speciesTable, owner);
        speciesTable.setModel(speciesTableModel);
        speciesTable.getSelectionModel().addListSelectionListener(eventHandlerS);
        speciesTable.getModel().addTableModelListener(eventHandlerS);
        observablesTable = new EditorScrollTable();
        observablesTableModel = new ObservablesGroupTableModel(observablesTable, owner, speciesTableModel);
        observablesTable.setModel(observablesTableModel);
        observablesTable.getSelectionModel().addListSelectionListener(eventHandlerO);
        observablesTable.getModel().addTableModelListener(eventHandlerO);
        speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDefinition).setCellRenderer(rbmSpeciesPatternCellRenderer);
        DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
        rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
        // speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColMultiplier).setCellRenderer(rightRenderer);	// right align
        // left column wide enough for title
        speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColMultiplier).setMaxWidth(70);
        speciesTable.addMouseMotionListener(new // add toolTipText for each table cell
        MouseMotionAdapter() {

            public void mouseMoved(MouseEvent e) {
                Point p = e.getPoint();
                int row = speciesTable.rowAtPoint(p);
                int column = speciesTable.columnAtPoint(p);
                speciesTable.setToolTipText(String.valueOf(speciesTable.getValueAt(row, column)));
            }
        });
        // ---------------------------------------------- top panel
        int gridy = 0;
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.gridwidth = 8;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.insets = new Insets(4, 4, 4, 4);
        observablesTable.setPreferredScrollableViewportSize(new Dimension(400, 200));
        topPanel.add(observablesTable.getEnclosingScrollPane(), gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.anchor = GridBagConstraints.LINE_END;
        gbc.insets = new Insets(4, 4, 4, 4);
        topPanel.add(new JLabel("Search "), gbc);
        textFieldSearchObservables = new JTextField(70);
        textFieldSearchObservables.addActionListener(eventHandlerO);
        textFieldSearchObservables.getDocument().addDocumentListener(eventHandlerO);
        textFieldSearchObservables.putClientProperty("JTextField.variant", "search");
        gbc = new java.awt.GridBagConstraints();
        gbc.weightx = 1.0;
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.gridwidth = 3;
        gbc.anchor = GridBagConstraints.LINE_START;
        gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(4, 0, 4, 4);
        topPanel.add(textFieldSearchObservables, gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 4;
        gbc.gridy = gridy;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(4, 4, 4, 10);
        topPanel.add(totalObservablesLabel, gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        // gbc.weightx = 1.0;
        gbc.gridwidth = 8;
        gbc.anchor = GridBagConstraints.LINE_END;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(4, 4, 4, 4);
        topPanel.add(containerOfScrollPanelObservable, gbc);
        // -------------------------------------------- bottom panel
        gridy = 0;
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.gridwidth = 8;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.insets = new Insets(4, 4, 4, 4);
        speciesTable.setPreferredScrollableViewportSize(new Dimension(400, 200));
        bottomPanel.add(speciesTable.getEnclosingScrollPane(), gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.anchor = GridBagConstraints.LINE_END;
        gbc.insets = new Insets(4, 4, 4, 4);
        bottomPanel.add(new JLabel("Search "), gbc);
        textFieldSearchSpecies = new JTextField(70);
        textFieldSearchSpecies.addActionListener(eventHandlerS);
        textFieldSearchSpecies.getDocument().addDocumentListener(eventHandlerS);
        textFieldSearchSpecies.putClientProperty("JTextField.variant", "search");
        gbc = new java.awt.GridBagConstraints();
        gbc.weightx = 1.0;
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.gridwidth = 3;
        gbc.anchor = GridBagConstraints.LINE_START;
        gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(4, 0, 4, 4);
        bottomPanel.add(textFieldSearchSpecies, gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 4;
        gbc.gridy = gridy;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(4, 4, 4, 10);
        bottomPanel.add(totalSpeciesLabel, gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        // gbc.weightx = 1.0;
        gbc.gridwidth = 8;
        gbc.anchor = GridBagConstraints.LINE_END;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(4, 4, 4, 4);
        bottomPanel.add(containerOfScrollPanelSpecies, gbc);
        // rendering the small shapes of the flattened species in the Depiction column of this viewer table)
        // TODO: this renderer is almost identical with the one in BioModelEditorModelPanel (which paints the small shapes
        // of a species context in the Depiction column of the species table)
        DefaultScrollTableCellRenderer rbmSpeciesShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {

            SpeciesPatternSmallShape spss = null;

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                if (table.getModel() instanceof VCellSortTableModel<?>) {
                    Object selectedObject = null;
                    if (table.getModel() == speciesTableModel) {
                        selectedObject = speciesTableModel.getValueAt(row);
                    }
                    if (selectedObject != null) {
                        if (selectedObject instanceof GeneratedSpeciesTableRow) {
                            SpeciesContext sc = ((GeneratedSpeciesTableRow) selectedObject).getSpecies();
                            // sp cannot be null
                            SpeciesPattern sp = sc.getSpeciesPattern();
                            Graphics panelContext = table.getGraphics();
                            spss = new SpeciesPatternSmallShape(4, 2, sp, panelContext, sc, isSelected, issueManager);
                        }
                    } else {
                        spss = null;
                    }
                }
                setText("");
                return this;
            }

            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                if (spss != null) {
                    spss.paintSelf(g);
                }
            }
        };
        speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDepiction).setCellRenderer(rbmSpeciesShapeDepictionCellRenderer);
        speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDepiction).setPreferredWidth(400);
        speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDepiction).setMinWidth(400);
        speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDefinition).setPreferredWidth(30);
        speciesTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
        DefaultScrollTableCellRenderer rbmObservableShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {

            List<SpeciesPatternSmallShape> spssList = new ArrayList<SpeciesPatternSmallShape>();

            SpeciesPatternSmallShape spss = null;

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                if (table.getModel() instanceof VCellSortTableModel<?>) {
                    Object selectedObject = null;
                    if (table.getModel() == observablesTableModel) {
                        selectedObject = observablesTableModel.getValueAt(row);
                    }
                    if (selectedObject != null && selectedObject instanceof ObservablesGroupTableRow) {
                        ObservablesGroupTableRow ogtr = ((ObservablesGroupTableRow) selectedObject);
                        String obsName = ogtr.getObservableGroupObject().getObservableGroupName();
                        RbmObservable observable = ogtr.getObservable(obsName);
                        Graphics panelContext = table.getGraphics();
                        int xPos = 4;
                        spssList.clear();
                        for (int i = 0; i < observable.getSpeciesPatternList().size(); i++) {
                            SpeciesPattern sp = observable.getSpeciesPatternList().get(i);
                            spss = new SpeciesPatternSmallShape(xPos, 2, sp, panelContext, observable, isSelected, issueManager);
                            xPos += spss.getWidth() + 6;
                            spssList.add(spss);
                        }
                    } else {
                        spssList.clear();
                    }
                }
                setText("");
                return this;
            }

            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                for (SpeciesPatternSmallShape spss : spssList) {
                    if (spss == null) {
                        continue;
                    }
                    spss.paintSelf(g);
                }
            }
        };
        observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColDepiction).setCellRenderer(rbmObservableShapeDepictionCellRenderer);
        observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColDepiction).setPreferredWidth(150);
        observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColDepiction).setMinWidth(150);
        observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColDefinition).setPreferredWidth(80);
        observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColExpression).setPreferredWidth(100);
        observablesTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    } catch (java.lang.Throwable ivjExc) {
        handleException(ivjExc);
    }
}
Also used : JPanel(javax.swing.JPanel) RuleParticipantSignature(cbit.vcell.model.RuleParticipantSignature) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) SpeciesPatternSmallShape(cbit.vcell.graph.SpeciesPatternSmallShape) SpeciesContext(cbit.vcell.model.SpeciesContext) JTextField(javax.swing.JTextField) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) LargeShapePanel(cbit.vcell.graph.gui.LargeShapePanel) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) BorderLayout(java.awt.BorderLayout) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) List(java.util.List) ArrayList(java.util.ArrayList) RuleAnalysisChanged(cbit.vcell.graph.ReactionCartoon.RuleAnalysisChanged) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) GroupingCriteria(cbit.vcell.model.GroupingCriteria) RbmObservable(cbit.vcell.model.RbmObservable) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Point(java.awt.Point) GridBagConstraints(java.awt.GridBagConstraints) Point(java.awt.Point) Graphics(java.awt.Graphics) JTable(javax.swing.JTable) DefaultScrollTableCellRenderer(org.vcell.util.gui.DefaultScrollTableCellRenderer) EditorScrollTable(org.vcell.util.gui.EditorScrollTable) JSplitPane(javax.swing.JSplitPane) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) Border(javax.swing.border.Border)

Example 3 with SpeciesPattern

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

the class ViewObservablesMapPanel method updateShapeObservable.

private void updateShapeObservable(int selectedRow) {
    spsList.clear();
    if (selectedRow == -1) {
        shapePanelObservable.repaint();
        return;
    }
    ObservablesGroupTableRow observablesTableRow = observablesTableModel.getValueAt(selectedRow);
    String obsName = observablesTableRow.getObservableGroupObject().getObservableGroupName();
    RbmObservable observable = observablesTableRow.getObservable(obsName);
    int maxXOffset = xOffsetInitial;
    int maxYOffset = 8;
    if (observable != null && observable.getSpeciesPatternList() != null && observable.getSpeciesPatternList().size() > 0) {
        // if more than one sp per observable, since non-editable we show them all on a single row
        for (int i = 0; i < observable.getSpeciesPatternList().size(); i++) {
            SpeciesPattern sp = observable.getSpeciesPatternList().get(i);
            SpeciesPatternLargeShape sps = new SpeciesPatternLargeShape(maxXOffset, maxYOffset, 80, sp, shapePanelObservable, observable, issueManager);
            spsList.add(sps);
            int xOffset = sps.getRightEnd();
            maxXOffset = xOffset + 40;
        }
    }
    Dimension preferredSize = new Dimension(maxXOffset + 200, maxYOffset);
    shapePanelObservable.setPreferredSize(preferredSize);
    shapePanelObservable.repaint();
}
Also used : RbmObservable(cbit.vcell.model.RbmObservable) Dimension(java.awt.Dimension) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) Point(java.awt.Point) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 4 with SpeciesPattern

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

the class PathwayMapping method createSpeciesContextFromBioPaxObject.

private SpeciesContext createSpeciesContextFromBioPaxObject(BioModel bioModel, PhysicalEntity bioPaxObject, boolean addSubunits) throws Exception {
    String name;
    if (bioPaxObject.getName().size() == 0) {
        name = getSafetyName(bioPaxObject.getID());
    } else {
        name = getSafetyName(bioPaxObject.getName().get(0));
    }
    Model model = bioModel.getModel();
    SpeciesContext freeSpeciesContext = model.getSpeciesContext(name);
    if (freeSpeciesContext == null) {
        // create the new speciesContex Object, and link it to the corresponding pathway object
        if (model.getSpecies(name) == null) {
            freeSpeciesContext = model.createSpeciesContext(model.getStructures()[0]);
        } else {
            freeSpeciesContext = new SpeciesContext(model.getSpecies(name), model.getStructures()[0]);
        }
        freeSpeciesContext.setName(name);
        RelationshipObject newRelationship = new RelationshipObject(freeSpeciesContext, bioPaxObject);
        bioModel.getRelationshipModel().addRelationshipObject(newRelationship);
    } else {
        // if it is in the bioModel, then check whether it links to pathway object or not
        HashSet<RelationshipObject> linkedReObjects = bioModel.getRelationshipModel().getRelationshipObjects(freeSpeciesContext);
        if (linkedReObjects != null) {
            boolean flag = true;
            for (RelationshipObject reObject : linkedReObjects) {
                if (reObject.getBioPaxObject() == bioPaxObject) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                RelationshipObject newSpeciesContext = new RelationshipObject(freeSpeciesContext, bioPaxObject);
                bioModel.getRelationshipModel().addRelationshipObject(newSpeciesContext);
            }
        } else {
            RelationshipObject newSpeciesContext = new RelationshipObject(freeSpeciesContext, bioPaxObject);
            bioModel.getRelationshipModel().addRelationshipObject(newSpeciesContext);
        }
    }
    if (!freeSpeciesContext.hasSpeciesPattern()) {
        SpeciesPattern sp = generateSpeciesPattern(bioModel, bioPaxObject, addSubunits);
        if (sp != null && !sp.getMolecularTypePatterns().isEmpty()) {
            freeSpeciesContext.setSpeciesPattern(sp);
        }
    }
    return freeSpeciesContext;
}
Also used : BioModel(cbit.vcell.biomodel.BioModel) Model(cbit.vcell.model.Model) SpeciesContext(cbit.vcell.model.SpeciesContext) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 5 with SpeciesPattern

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

the class PathwayMapping method createSpeciesContextFromTableRow.

private SpeciesContext createSpeciesContextFromTableRow(BioModel bioModel, PhysicalEntity bioPaxObject, double stoich, String id, String location, boolean addSubunits) throws Exception {
    // use user defined id as the name of the speciesContext
    String safeId = getSafetyName(id);
    String name;
    if (bioPaxObject.getName().size() == 0) {
        name = getSafetyName(bioPaxObject.getID());
    } else {
        name = getSafetyName(bioPaxObject.getName().get(0));
    }
    Model model = bioModel.getModel();
    SpeciesContext freeSpeciesContext = model.getSpeciesContext(safeId);
    if (freeSpeciesContext == null) {
        // create the new speciesContex Object, and link it to the corresponding pathway object
        if (model.getSpecies(name) == null) {
            freeSpeciesContext = model.createSpeciesContext(model.getStructure(location));
        } else {
            freeSpeciesContext = new SpeciesContext(model.getSpecies(name), model.getStructure(location));
        }
        freeSpeciesContext.setName(safeId);
        RelationshipObject newRelationship = new RelationshipObject(freeSpeciesContext, bioPaxObject);
        bioModel.getRelationshipModel().addRelationshipObject(newRelationship);
    } else {
        // if it is in the bioModel, then check whether it links to pathway object or not
        HashSet<RelationshipObject> linkedReObjects = bioModel.getRelationshipModel().getRelationshipObjects(freeSpeciesContext);
        if (linkedReObjects != null) {
            boolean flag = true;
            for (RelationshipObject reObject : linkedReObjects) {
                if (reObject.getBioPaxObject() == bioPaxObject) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                RelationshipObject newSpeciesContext = new RelationshipObject(freeSpeciesContext, bioPaxObject);
                bioModel.getRelationshipModel().addRelationshipObject(newSpeciesContext);
            }
        } else {
            RelationshipObject newSpeciesContext = new RelationshipObject(freeSpeciesContext, bioPaxObject);
            bioModel.getRelationshipModel().addRelationshipObject(newSpeciesContext);
        }
    }
    // else if it's proteine, small molecule, dna, etc the sp will consist of one molecule
    if (!freeSpeciesContext.hasSpeciesPattern()) {
        SpeciesPattern sp = generateSpeciesPattern(bioModel, bioPaxObject, addSubunits);
        if (sp != null && !sp.getMolecularTypePatterns().isEmpty()) {
            freeSpeciesContext.setSpeciesPattern(sp);
            sp.initializeBonds(MolecularComponentPattern.BondType.None);
        }
    }
    return freeSpeciesContext;
}
Also used : BioModel(cbit.vcell.biomodel.BioModel) Model(cbit.vcell.model.Model) SpeciesContext(cbit.vcell.model.SpeciesContext) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Aggregations

SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)93 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)39 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)30 MolecularType (org.vcell.model.rbm.MolecularType)25 RbmObservable (cbit.vcell.model.RbmObservable)22 SpeciesContext (cbit.vcell.model.SpeciesContext)22 Structure (cbit.vcell.model.Structure)22 Point (java.awt.Point)18 ReactionRule (cbit.vcell.model.ReactionRule)16 ArrayList (java.util.ArrayList)16 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)16 Graphics (java.awt.Graphics)13 PropertyVetoException (java.beans.PropertyVetoException)13 SpeciesPatternLargeShape (cbit.vcell.graph.SpeciesPatternLargeShape)12 ProductPattern (cbit.vcell.model.ProductPattern)12 ReactantPattern (cbit.vcell.model.ReactantPattern)12 Dimension (java.awt.Dimension)12 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)12 Model (cbit.vcell.model.Model)11 ModelException (cbit.vcell.model.ModelException)11