Search in sources :

Example 66 with Structure

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

the class StructureMappingTableModel method setValueAt.

public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    if (rowIndex < 0 || rowIndex >= getRowCount()) {
        throw new RuntimeException("StructureMappingTableModel.setValueAt(), row = " + rowIndex + " out of range [" + 0 + "," + (getRowCount() - 1) + "]");
    }
    if (columnIndex < 0 || columnIndex >= getColumnCount()) {
        throw new RuntimeException("StructureMappingTableModel.setValueAt(), column = " + columnIndex + " out of range [" + 0 + "," + (getColumnCount() - 1) + "]");
    }
    StructureMapping structureMapping = getValueAt(rowIndex);
    Structure structure = structureMapping.getStructure();
    if (bNonSpatial) {
        switch(columnIndex) {
            case NONSPATIAL_COLUMN_SIZE:
                {
                    try {
                        Expression exp = null;
                        if (aValue instanceof String) {
                            exp = new Expression((String) aValue);
                        } else if (aValue instanceof Double) {
                            exp = new Expression(((Double) aValue).doubleValue());
                        }
                        // if the input volumn is null, leave it as it was.
                        if (exp != null) {
                            // for old ode model, once one size is input, solve the rest.                                                                                                          if it is unnamed compartment(the only one), we don't need to solve anything
                            if (!getGeometryContext().getSimulationContext().isStoch() && getGeometryContext().isAllSizeSpecifiedNull() && getGeometryContext().isAllVolFracAndSurfVolSpecified() && getGeometryContext().getStructureMappings().length > 1) {
                                structureMapping.getSizeParameter().setExpression(exp);
                                double size;
                                try {
                                    size = exp.evaluateConstant();
                                    VCUnitDefinition volumeUnit = getGeometryContext().getSimulationContext().getModel().getUnitSystem().getVolumeUnit();
                                    StructureSizeSolver.updateAbsoluteStructureSizes(getGeometryContext().getSimulationContext(), structure, size, volumeUnit);
                                    fireTableRowsUpdated(0, getRowCount());
                                } catch (ExpressionException ex) {
                                    ex.printStackTrace(System.out);
                                    PopupGenerator.showErrorDialog(ownerTable, "Size of Feature " + structure.getName() + " can not be solved as constant!");
                                } catch (Exception ex) {
                                    ex.printStackTrace(System.out);
                                    PopupGenerator.showErrorDialog(ownerTable, ex.getMessage());
                                }
                            } else {
                                structureMapping.getSizeParameter().setExpression(exp);
                                // set fraction in stoch math description, because these might be used when copy from stoch app to ode app.
                                if (getGeometryContext().isAllSizeSpecifiedPositive()) /*&& !getGeometryContext().getSimulationContext().isStoch()*/
                                {
                                    try {
                                        StructureSizeSolver.updateRelativeStructureSizes(getGeometryContext().getSimulationContext());
                                    } catch (Exception ex) {
                                        ex.printStackTrace(System.out);
                                        PopupGenerator.showErrorDialog(ownerTable, ex.getMessage());
                                    }
                                }
                            }
                        }
                    } catch (ExpressionException e) {
                        e.printStackTrace(System.out);
                        PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
                    }
                    break;
                }
        }
    } else {
        switch(columnIndex) {
            case SPATIAL_COLUMN_SUBDOMAIN:
                {
                    GeometryClass geometryClass = null;
                    if (aValue instanceof String) {
                        String svname = (String) aValue;
                        geometryClass = getGeometryContext().getGeometry().getGeometryClass(svname);
                    } else if (aValue instanceof GeometryClass) {
                        geometryClass = (GeometryClass) aValue;
                    }
                    if (geometryClass != null) {
                        try {
                            getGeometryContext().assignStructure(structure, geometryClass);
                        } catch (PropertyVetoException e) {
                            e.printStackTrace(System.out);
                            PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
                        } catch (IllegalMappingException e) {
                            e.printStackTrace(System.out);
                            PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
                        } catch (MappingException e) {
                            e.printStackTrace(System.out);
                            PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
                        }
                    }
                    break;
                }
            case SPATIAL_COLUMN_SIZERATIO:
                try {
                    Expression exp = null;
                    if (aValue instanceof String) {
                        exp = new Expression((String) aValue);
                    } else if (aValue instanceof Double) {
                        exp = new Expression(((Double) aValue).doubleValue());
                    }
                    if (exp != null) {
                        structureMapping.getUnitSizeParameter().setExpression(exp);
                        StructureSizeSolver.updateUnitStructureSizes(getGeometryContext().getSimulationContext(), structureMapping.getGeometryClass());
                    }
                } catch (ExpressionException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
                }
                break;
            case SPATIAL_COLUMN_X_MINUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeXm(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_X_PLUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeXp(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_Y_MINUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeYm(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_Y_PLUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeYp(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_Z_MINUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeZm(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_Z_PLUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeZp(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
        }
    }
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) BoundaryConditionType(cbit.vcell.math.BoundaryConditionType) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) StructureMapping(cbit.vcell.mapping.StructureMapping) ExpressionException(cbit.vcell.parser.ExpressionException) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) PropertyVetoException(java.beans.PropertyVetoException) DivideByZeroException(cbit.vcell.parser.DivideByZeroException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) MappingException(cbit.vcell.mapping.MappingException) PropertyVetoException(java.beans.PropertyVetoException) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) Structure(cbit.vcell.model.Structure)

Example 67 with Structure

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

the class StructureMappingTableRenderer method getTableCellRendererComponent.

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    setIcon(null);
    if (table.getModel() instanceof StructureMappingTableModel) {
        StructureMappingTableModel structureMappingTableModel = (StructureMappingTableModel) table.getModel();
        String toolTip = structureMappingTableModel.getToolTip(row, column);
        if (value instanceof Structure) {
            Structure structure = (Structure) value;
            setText(structure.getName());
        } else if (value instanceof Double && structureMappingTableModel.isNewSizeColumn(column)) {
            StructureMapping structureMapping = structureMappingTableModel.getStructureMapping(row);
            if (structureMappingTableModel.isNonSpatial()) {
                VCUnitDefinition unitDefinition = structureMapping.getStructure().getStructureSize().getUnitDefinition();
                TextIcon sizeIcon = unitIconHash.get(unitDefinition.getSymbol());
                if (sizeIcon == null) {
                    sizeIcon = new TextIcon("[ " + unitDefinition.getSymbolUnicode() + " ]");
                    unitIconHash.put(unitDefinition.getSymbol(), sizeIcon);
                }
                setIcon(sizeIcon);
            } else {
                // spatial
                if (structureMapping.getUnitSizeParameter() != null) {
                    VCUnitDefinition unitDefinition = structureMapping.getUnitSizeParameter().getUnitDefinition();
                    TextIcon sizeIcon = unitIconHash.get(unitDefinition.getSymbol());
                    if (sizeIcon == null) {
                        sizeIcon = new TextIcon("[ " + unitDefinition.getSymbolUnicode() + " ]");
                        unitIconHash.put(unitDefinition.getSymbol(), sizeIcon);
                    }
                    setIcon(sizeIcon);
                }
            }
        }
        if (structureMappingTableModel.isSubdomainColumn(column)) {
            // can be null
            if (value == null) {
                setText("Unmapped");
                setForeground(Color.red);
                setIcon(null);
            } else {
                if (value instanceof GeometryClass) {
                    setText(((GeometryClass) value).getName());
                    if (value instanceof SubVolume) {
                        SubVolume subVolume = (SubVolume) value;
                        java.awt.Color handleColor = new java.awt.Color(colormap[subVolume.getHandle()]);
                        // small square icon with subdomain color
                        Icon icon = new ColorIcon(10, 10, handleColor, true);
                        setHorizontalTextPosition(SwingConstants.RIGHT);
                        setIcon(icon);
                    } else if (value instanceof SurfaceClass) {
                        SurfaceClass sc = (SurfaceClass) value;
                        Set<SubVolume> sv = sc.getAdjacentSubvolumes();
                        Iterator<SubVolume> iterator = sv.iterator();
                        SubVolume sv1 = iterator.next();
                        SubVolume sv2 = iterator.next();
                        java.awt.Color c1 = new java.awt.Color(colormap[sv2.getHandle()]);
                        java.awt.Color c2 = new java.awt.Color(colormap[sv1.getHandle()]);
                        Icon icon = new ColorIconEx(10, 10, c1, c2);
                        setIcon(icon);
                        setHorizontalTextPosition(SwingConstants.RIGHT);
                    }
                } else {
                    setText(value.toString());
                    setIcon(null);
                }
            }
        }
        if (value instanceof BoundaryConditionType) {
            // we get here only for spatial
            Object candidate = structureMappingTableModel.getValueAt(row, StructureMappingTableModel.SPATIAL_COLUMN_SUBDOMAIN);
            if (candidate instanceof SurfaceClass) {
                SurfaceClass surfaceClass = (SurfaceClass) candidate;
                cbit.vcell.model.Model model = structureMappingTableModel.getGeometryContext().getModel();
                SimulationContext simContext = structureMappingTableModel.getGeometryContext().getSimulationContext();
                Pair<SubVolume, SubVolume> ret = DiffEquMathMapping.computeBoundaryConditionSource(model, simContext, surfaceClass);
                SubVolume innerSubVolume = ret.one;
                java.awt.Color handleColor = new java.awt.Color(colormap[innerSubVolume.getHandle()]);
                // small square icon with subdomain color
                Icon icon = new ColorIcon(8, 8, handleColor, true);
                setHorizontalTextPosition(SwingConstants.LEFT);
                setIcon(icon);
                setText("from");
                // override default tooltip
                toolTip = "Boundary condition inherited from Subdomain '" + innerSubVolume.getName() + "'";
                setToolTipText(toolTip);
            } else {
                setText(((BoundaryConditionType) value).boundaryTypeStringValue());
            }
        }
        List<Issue> issueList = structureMappingTableModel.getIssues(row, column, Issue.SEVERITY_ERROR);
        if (issueList.size() > 0) {
            // override default tooltip
            setToolTipText(Issue.getHtmlIssueMessage(issueList));
            if (column == 0) {
                setBorder(new MatteBorder(1, 1, 1, 0, Color.red));
            } else if (column == table.getColumnCount() - 1) {
                setBorder(new MatteBorder(1, 0, 1, 1, Color.red));
            } else {
                setBorder(new MatteBorder(1, 0, 1, 0, Color.red));
            }
        } else {
            setToolTipText(toolTip);
            setBorder(DEFAULT_GAP);
        }
    }
    return this;
}
Also used : Color(java.awt.Color) GeometryClass(cbit.vcell.geometry.GeometryClass) Set(java.util.Set) Issue(org.vcell.util.Issue) SurfaceClass(cbit.vcell.geometry.SurfaceClass) BoundaryConditionType(cbit.vcell.math.BoundaryConditionType) AttributedString(java.text.AttributedString) StructureMapping(cbit.vcell.mapping.StructureMapping) MatteBorder(javax.swing.border.MatteBorder) SubVolume(cbit.vcell.geometry.SubVolume) Iterator(java.util.Iterator) Structure(cbit.vcell.model.Structure) ColorIconEx(org.vcell.util.gui.ColorIconEx) ColorIcon(org.vcell.util.gui.ColorIcon) Color(java.awt.Color) SimulationContext(cbit.vcell.mapping.SimulationContext) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) ColorIcon(org.vcell.util.gui.ColorIcon) Icon(javax.swing.Icon)

Example 68 with Structure

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

the class StructurePasteMappingPanel method initialize.

private void initialize() {
    Structure structFrom = rsCopy.getFromStructure();
    List<String> membranesTo = new ArrayList<>();
    List<String> compartmentsTo = new ArrayList<>();
    membranesTo.add(CHOOSE_STRUCT);
    membranesTo.add(MAKE_NEW);
    compartmentsTo.add(CHOOSE_STRUCT);
    compartmentsTo.add(MAKE_NEW);
    for (Structure struct : modelTo.getStructures()) {
        if (struct == structTo) {
            continue;
        }
        if (struct instanceof Membrane) {
            membranesTo.add(struct.getName());
        } else {
            compartmentsTo.add(struct.getName());
        }
    }
    for (Structure from : rsCopy.getStructuresArr()) {
        if (from == structFrom) {
            // skip the structure from where we copy, it's already mapped
            continue;
        }
        JComboBox<String> comboTo = new JComboBox<>();
        if (from instanceof Membrane) {
            comboTo.setModel(new DefaultComboBoxModel(membranesTo.toArray()));
            int index = membranesTo.indexOf(from.getName());
            comboTo.setSelectedIndex(index >= 0 ? index : 0);
        } else {
            comboTo.setModel(new DefaultComboBoxModel(compartmentsTo.toArray()));
            int index = compartmentsTo.indexOf(from.getName());
            comboTo.setSelectedIndex(index >= 0 ? index : 0);
        }
        structureMap.put(from, comboTo);
        comboTo.addActionListener(eventHandler);
    }
    JPanel structPanel = new JPanel();
    // structPanel.setPreferredSize(new Dimension(220, 180));
    structPanel.setLayout(new GridBagLayout());
    // header
    int gridy = 0;
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    // top, left, bottom, right
    gbc.insets = new Insets(10, 10, 10, 10);
    gbc.weightx = 1;
    gbc.anchor = GridBagConstraints.WEST;
    structPanel.add(new JLabel("<html><b>Structures to Paste</b></html>"), gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = gridy;
    gbc.insets = new Insets(10, 10, 10, 10);
    gbc.weightx = 1;
    gbc.anchor = GridBagConstraints.WEST;
    // gbc.fill = GridBagConstraints.HORIZONTAL;
    structPanel.add(new JLabel("<html><b>Mapped to: </b></html>"), gbc);
    // the first row shows the source and destination structures (not customizable)
    gridy++;
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.insets = new Insets(1, 10, 1, 10);
    gbc.weightx = 1;
    gbc.anchor = GridBagConstraints.WEST;
    structPanel.add(new JLabel("<html>" + structFrom.getName() + "</html>"), gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = gridy;
    gbc.insets = new Insets(1, 12, 1, 10);
    gbc.weightx = 1;
    gbc.anchor = GridBagConstraints.WEST;
    structPanel.add(new JLabel("<html>" + structTo.getName() + "</html>"), gbc);
    for (Map.Entry<Structure, JComboBox<String>> entry : structureMap.entrySet()) {
        // the first row shows the source and destination structures (not customizable)
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.insets = new Insets(1, 10, 2, 10);
        gbc.weightx = 1;
        gbc.anchor = GridBagConstraints.WEST;
        structPanel.add(new JLabel("<html>" + entry.getKey().getName() + "</html>"), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.insets = new Insets(2, 10, 1, 10);
        gbc.weightx = 1;
        gbc.anchor = GridBagConstraints.WEST;
        structPanel.add(entry.getValue(), gbc);
    }
    gridy++;
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.gridwidth = 4;
    gbc.weightx = 1;
    // fake cell used for filling all the vertical empty space
    gbc.weighty = 1;
    gbc.anchor = GridBagConstraints.WEST;
    structPanel.add(new JLabel(""), gbc);
    // JPanel issuesPanel = new JPanel();
    // issuesPanel.setLayout(new BorderLayout());
    // issuesPanel.add(issuesPane, BorderLayout.CENTER);
    JScrollPane upper = new JScrollPane(structPanel);
    upper.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    upper.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    JScrollPane lower = new JScrollPane(issuesPane);
    lower.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    lower.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    setLayout(new BorderLayout());
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, upper, lower);
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerLocation(150);
    add(splitPane, BorderLayout.CENTER);
    recalculateIssues();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JComboBox(javax.swing.JComboBox) GridBagLayout(java.awt.GridBagLayout) ArrayList(java.util.ArrayList) JLabel(javax.swing.JLabel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) BorderLayout(java.awt.BorderLayout) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) JSplitPane(javax.swing.JSplitPane) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 69 with Structure

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

the class StructurePasteMappingPanel method recalculateIssues.

private void recalculateIssues() {
    String issues = "";
    issueVector.clear();
    Set<String> duplicateCheck = new HashSet<>();
    duplicateCheck.add(structTo.getName());
    for (Map.Entry<Structure, JComboBox<String>> entry : structureMap.entrySet()) {
        if (entry.getValue().getSelectedItem().equals(CHOOSE_STRUCT) || entry.getValue().getSelectedItem().equals(MAKE_NEW)) {
            continue;
        }
        if (duplicateCheck.contains(entry.getValue().getSelectedItem())) {
            String msg = "Multiple Structures to be Pasted are mapped to the same destination " + entry.getValue().getSelectedItem();
            Issue issue = new Issue(modelTo, issueContext, IssueCategory.CopyPaste, msg, Issue.Severity.WARNING);
            issueVector.add(issue);
            issues += msg + "\n";
        } else {
            duplicateCheck.add((String) (entry.getValue().getSelectedItem()));
        }
    }
    for (Map.Entry<Structure, JComboBox<String>> entry : structureMap.entrySet()) {
        if (entry.getValue().getSelectedItem().equals(CHOOSE_STRUCT)) {
            String msg = "Map each Structure to be Pasted to an existing Structure or create a new one";
            Issue issue = new Issue(modelTo, issueContext, IssueCategory.CopyPaste, msg, Issue.Severity.ERROR);
            issueVector.add(issue);
            issues += msg + "\n";
            break;
        }
    }
    issuesPane.setText(issues);
}
Also used : Issue(org.vcell.util.Issue) JComboBox(javax.swing.JComboBox) Structure(cbit.vcell.model.Structure) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 70 with Structure

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

the class ReactionCartoonTool method lineAction.

private void lineAction(ReactionStep reactionStart, Structure endStructure) throws Exception {
    Structure startStructure = reactionStart.getStructure();
    if (StructureUtil.reactionHereCanHaveParticipantThere(startStructure, endStructure)) {
        // if reactionStart is a SimpleRxn OR FluxRxn without a product, add speciesContext as pdt
        if ((reactionStart instanceof SimpleReaction) || ((reactionStart instanceof FluxReaction) && !reactionStart.hasProduct())) {
            SpeciesContext speciesContext = getModel().createSpeciesContext(endStructure);
            reactionStart.addProduct(speciesContext, 1);
            positionShapeForObject(endStructure, speciesContext, edgeShape.getEnd());
        }
        if (((startStructure instanceof Feature && endStructure instanceof Feature) || (startStructure instanceof Membrane && endStructure instanceof Membrane)) && startStructure != endStructure) {
        // ============ change kinetics to lumped or warn user ?????????
        // reactionStart.setKinetics(new GeneralLumpedKinetics(reactionStart));
        }
        getReactionCartoon().notifyChangeEvent();
    }
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) Membrane(cbit.vcell.model.Membrane) FluxReaction(cbit.vcell.model.FluxReaction) SpeciesContext(cbit.vcell.model.SpeciesContext) Structure(cbit.vcell.model.Structure) Feature(cbit.vcell.model.Feature)

Aggregations

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