Search in sources :

Example 11 with ComponentStateDefinition

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

the class MolecularTypeTreeModel method valueForPathChanged.

@Override
public void valueForPathChanged(TreePath path, Object newValue) {
    Object obj = path.getLastPathComponent();
    if (obj == null || !(obj instanceof BioModelNode)) {
        return;
    }
    BioModelNode selectedNode = (BioModelNode) obj;
    Object userObject = selectedNode.getUserObject();
    try {
        if (newValue instanceof String) {
            String inputString = (String) newValue;
            if (inputString == null || inputString.length() == 0) {
                return;
            }
            if (userObject instanceof MolecularType) {
                String mangled = TokenMangler.fixTokenStrict(inputString);
                if (!mangled.equals(inputString)) {
                    String errMsg = ((Displayable) userObject).getDisplayType() + " '" + inputString + "' not legal identifier, try '" + mangled + "'";
                    throw new RuntimeException(errMsg);
                }
                ((MolecularType) userObject).setName(inputString);
            } else if (userObject instanceof MolecularComponent) {
                String mangled = TokenMangler.fixTokenStrict(inputString);
                if (!mangled.equals(inputString)) {
                    String errMsg = ((Displayable) userObject).getDisplayType() + " '" + inputString + "' not legal identifier, try '" + mangled + "'";
                    throw new RuntimeException(errMsg);
                }
                ((MolecularComponent) userObject).setName(inputString);
            } else if (userObject instanceof ComponentStateDefinition) {
                if (inputString.matches("[A-Z_a-z0-9]+")) {
                    ((ComponentStateDefinition) userObject).setName(inputString);
                }
            }
        }
    } catch (Exception ex) {
        DialogUtils.showErrorDialog(ownerTree, ex.getMessage());
    }
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) Displayable(org.vcell.util.Displayable) MolecularComponent(org.vcell.model.rbm.MolecularComponent) BioModelNode(cbit.vcell.desktop.BioModelNode) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 12 with ComponentStateDefinition

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

the class IssueTableModel method getSourceObjectDescription.

private String getSourceObjectDescription(VCDocument vcDocument, Issue issue) {
    if (vcDocument instanceof BioModel) {
        Object object = issue.getSource();
        {
            DecoratedIssueSource dis = BeanUtils.downcast(DecoratedIssueSource.class, object);
            if (dis != null) {
                return dis.getSourcePath();
            }
        }
        String description = "";
        if (object instanceof SymbolTableEntry) {
            description = ((SymbolTableEntry) object).getName();
        } else if (object instanceof ReactionStep) {
            description = ((ReactionStep) object).getName();
        } else if (object instanceof ReactionRule) {
            description = ((ReactionRule) object).getName();
        } else if (object instanceof SpeciesPattern) {
            // Object parent = issue.getIssueContext().getContextObject();
            // if (parent instanceof SpeciesContext){
            // description = ((SpeciesContext)parent).getName();
            // }
            // if (issue.getIssueContext().hasContextType(ContextType.SpeciesContext)){
            // SpeciesContext thing = (SpeciesContext)issue.getIssueContext().getContextObject(ContextType.SpeciesContext);
            // description = thing.getName();
            // }else if(issue.getIssueContext().hasContextType(ContextType.ReactionRule)) {
            // ReactionRule thing = (ReactionRule)issue.getIssueContext().getContextObject(ContextType.ReactionRule);
            // description = thing.getName();
            // }else if(issue.getIssueContext().hasContextType(ContextType.RbmObservable)) {
            // RbmObservable thing = (RbmObservable)issue.getIssueContext().getContextObject(ContextType.RbmObservable);
            // description = thing.getName();
            // } else {
            System.err.println("Bad issue context for " + ((SpeciesPattern) object).toString());
            description = ((SpeciesPattern) object).toString();
        // }
        } else if (object instanceof MolecularType) {
            description = ((MolecularType) object).getName();
        } else if (object instanceof MolecularComponent) {
            description = ((MolecularComponent) object).getName();
        } else if (object instanceof ComponentStateDefinition) {
            description = ((ComponentStateDefinition) object).getName();
        } else if (object instanceof Structure) {
            description = ((Structure) object).getName();
        } else if (object instanceof SubDomain) {
            description = ((SubDomain) object).getName();
        } else if (object instanceof Geometry) {
            description = ((Geometry) object).getName();
        } else if (object instanceof StructureMapping) {
            description = ((StructureMapping) object).getStructure().getName();
        } else if (object instanceof OutputFunctionIssueSource) {
            description = ((OutputFunctionIssueSource) object).getAnnotatedFunction().getName();
        } else if (object instanceof UnmappedGeometryClass) {
            description = ((UnmappedGeometryClass) object).getGeometryClass().getName();
        } else if (object instanceof MicroscopeMeasurement) {
            description = ((MicroscopeMeasurement) object).getName();
        } else if (object instanceof SpatialObject) {
            description = ((SpatialObject) object).getName();
        } else if (object instanceof SpatialProcess) {
            description = ((SpatialProcess) object).getName();
        } else if (object instanceof GeometryContext) {
            description = "Geometry";
        } else if (object instanceof ModelOptimizationSpec) {
            description = ((ModelOptimizationSpec) object).getParameterEstimationTask().getName();
        } else if (object instanceof Simulation) {
            description = ((Simulation) object).getName();
        } else if (object instanceof SpeciesContextSpec) {
            SpeciesContextSpec scs = (SpeciesContextSpec) object;
            description = scs.getSpeciesContext().getName();
        } else if (object instanceof ReactionCombo) {
            ReactionSpec rs = ((ReactionCombo) object).getReactionSpec();
            description = rs.getReactionStep().getName();
        } else if (object instanceof RbmModelContainer) {
            // RbmModelContainer mc = (RbmModelContainer)object;
            description = "Rules validator";
        } else if (object instanceof SimulationContext) {
            SimulationContext sc = (SimulationContext) object;
            description = sc.getName();
        } else if (object instanceof Model) {
            Model m = (Model) object;
            description = m.getName();
        } else if (object instanceof BioEvent) {
            return ((BioEvent) object).getName() + "";
        } else if (object instanceof MathDescription) {
            return ((MathDescription) object).getName() + "";
        } else if (object instanceof AssignmentRule) {
            return ((AssignmentRule) object).getDisplayName() + "";
        } else if (object instanceof RateRule) {
            return ((RateRule) object).getDisplayName() + "";
        } else {
            System.err.println("unknown object type in IssueTableModel.getSourceObjectDescription(): " + object.getClass());
        }
        return description;
    } else if (vcDocument instanceof MathModel) {
        Object object = issue.getSource();
        String description = "";
        if (object instanceof Variable) {
            description = ((Variable) object).getName();
        } else if (object instanceof SubDomain) {
            description = ((SubDomain) object).getName();
        } else if (object instanceof Geometry) {
            description = "Geometry";
        } else if (object instanceof OutputFunctionIssueSource) {
            description = ((OutputFunctionIssueSource) object).getAnnotatedFunction().getName();
        } else if (object instanceof MathDescription) {
            return "math";
        } else if (object instanceof Simulation) {
            return "Simulation " + ((Simulation) object).getName() + "";
        }
        return description;
    } else {
        System.err.println("unknown document type in IssueTableModel.getSourceObjectDescription()");
        return "";
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) Variable(cbit.vcell.math.Variable) MathDescription(cbit.vcell.math.MathDescription) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) StructureMapping(cbit.vcell.mapping.StructureMapping) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) SubDomain(cbit.vcell.math.SubDomain) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) OutputFunctionIssueSource(cbit.vcell.solver.OutputFunctionContext.OutputFunctionIssueSource) MolecularComponent(org.vcell.model.rbm.MolecularComponent) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) ModelOptimizationSpec(cbit.vcell.modelopt.ModelOptimizationSpec) UnmappedGeometryClass(cbit.vcell.mapping.GeometryContext.UnmappedGeometryClass) MicroscopeMeasurement(cbit.vcell.mapping.MicroscopeMeasurement) RateRule(cbit.vcell.mapping.RateRule) GeometryContext(cbit.vcell.mapping.GeometryContext) Structure(cbit.vcell.model.Structure) ReactionCombo(cbit.vcell.mapping.ReactionSpec.ReactionCombo) ReactionRule(cbit.vcell.model.ReactionRule) DecoratedIssueSource(cbit.vcell.client.desktop.DecoratedIssueSource) ReactionSpec(cbit.vcell.mapping.ReactionSpec) AssignmentRule(cbit.vcell.mapping.AssignmentRule) SimulationContext(cbit.vcell.mapping.SimulationContext) MolecularType(org.vcell.model.rbm.MolecularType) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) ReactionStep(cbit.vcell.model.ReactionStep) MathModel(cbit.vcell.mathmodel.MathModel) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) BioEvent(cbit.vcell.mapping.BioEvent)

Example 13 with ComponentStateDefinition

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

the class MolecularTypePropertiesPanel method showPopupMenu.

private void showPopupMenu(MouseEvent e, PointLocationInShapeContext locationContext) {
    if (popupFromShapeMenu == null) {
        popupFromShapeMenu = new JPopupMenu();
    }
    if (popupFromShapeMenu.isShowing()) {
        return;
    }
    final Object deepestShape = locationContext.getDeepestShape();
    final Object selectedObject;
    if (deepestShape == null) {
        selectedObject = null;
        // when cursor is outside there's nothing to do  ???
        System.out.println("outside");
        return;
    } else if (deepestShape instanceof ComponentStateLargeShape) {
        System.out.println("inside state");
        if (((ComponentStateLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((ComponentStateLargeShape) deepestShape).getComponentStateDefinition();
        } else {
            // right click only works on highlighted entity, if it's not highlighted we simply return
            return;
        }
    } else if (deepestShape instanceof MolecularComponentLargeShape) {
        System.out.println("inside component");
        if (((MolecularComponentLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((MolecularComponentLargeShape) deepestShape).getMolecularComponent();
        } else {
            return;
        }
    } else if (deepestShape instanceof MolecularTypeLargeShape) {
        System.out.println("inside molecule");
        if (((MolecularTypeLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((MolecularTypeLargeShape) deepestShape).getMolecularType();
        } else {
            return;
        }
    } else if (deepestShape instanceof SpeciesPatternLargeShape) {
        // this cannot happen, here just for symmetry
        System.out.println("inside species pattern");
        if (((SpeciesPatternLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((SpeciesPatternLargeShape) deepestShape).getSpeciesPattern();
        } else {
            return;
        }
    } else {
        selectedObject = null;
        System.out.println("inside something else?");
        return;
    }
    System.out.println(selectedObject);
    boolean bDelete = false;
    boolean bAdd = false;
    popupFromShapeMenu.removeAll();
    Point mousePoint = e.getPoint();
    if (selectedObject instanceof MolecularType) {
        // rename, add
        if (selectedObject != molecularType) {
            throw new RuntimeException("The selected object from shape different from the current object");
        }
        JMenuItem renamMenuItem = new JMenuItem("Rename");
        popupFromShapeMenu.add(renamMenuItem);
        JMenuItem addMenuItem = new JMenuItem("Add " + MolecularComponent.typeName);
        // Icon icon = new MolecularTypeSmallShape(1, 4, mt, gc, mt);
        // menuItem.setIcon(icon);
        popupFromShapeMenu.add(new JSeparator());
        popupFromShapeMenu.add(addMenuItem);
        addMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                MolecularComponent molecularComponent = molecularType.createMolecularComponent();
                molecularType.addMolecularComponent(molecularComponent);
                bioModel.getModel().getRbmModelContainer().adjustSpeciesContextPatterns(molecularType, molecularComponent);
                bioModel.getModel().getRbmModelContainer().adjustObservablesPatterns(molecularType, molecularComponent);
                bioModel.getModel().getRbmModelContainer().adjustRulesPatterns(molecularType, molecularComponent);
            // editInPlace((LargeShape)deepestShape);
            }
        });
        renamMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                editInPlace((LargeShape) deepestShape);
            }
        });
    } else if (selectedObject instanceof MolecularComponent) {
        // move left / right / separator / rename, delete, separator, add
        String moveRightMenuText = "Move <b>" + "right" + "</b>";
        moveRightMenuText = "<html>" + moveRightMenuText + "</html>";
        JMenuItem moveRightMenuItem = new JMenuItem(moveRightMenuText);
        Icon icon = VCellIcons.moveRightIcon;
        moveRightMenuItem.setIcon(icon);
        moveRightMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                MolecularComponent from = (MolecularComponent) selectedObject;
                List<MolecularComponent> mcList = molecularType.getComponentList();
                int fromIndex = mcList.indexOf(from);
                if (mcList.size() == fromIndex + 1) {
                    // already the last element
                    return;
                }
                int toIndex = fromIndex + 1;
                MolecularComponent to = mcList.remove(toIndex);
                mcList.add(fromIndex, to);
                molecularTypeTreeModel.populateTree();
                molecularType.firePropertyChange("entityChange", null, "bbb");
            }
        });
        popupFromShapeMenu.add(moveRightMenuItem);
        String moveLeftMenuText = "Move <b>" + "left" + "</b>";
        moveLeftMenuText = "<html>" + moveLeftMenuText + "</html>";
        JMenuItem moveLeftMenuItem = new JMenuItem(moveLeftMenuText);
        icon = VCellIcons.moveLeftIcon;
        moveLeftMenuItem.setIcon(icon);
        moveLeftMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                MolecularComponent from = (MolecularComponent) selectedObject;
                List<MolecularComponent> mcList = molecularType.getComponentList();
                int fromIndex = mcList.indexOf(from);
                if (fromIndex == 0) {
                    // already the first element
                    return;
                }
                int toIndex = fromIndex - 1;
                MolecularComponent to = mcList.remove(toIndex);
                mcList.add(fromIndex, to);
                molecularTypeTreeModel.populateTree();
                molecularType.firePropertyChange("entityChange", null, "bbb");
            }
        });
        popupFromShapeMenu.add(moveLeftMenuItem);
        popupFromShapeMenu.add(new JSeparator());
        JMenuItem renamMenuItem = new JMenuItem("Rename");
        popupFromShapeMenu.add(renamMenuItem);
        JMenuItem addMenuItem = new JMenuItem("Add " + ComponentStateDefinition.typeName);
        JMenuItem deleteMenuItem = new JMenuItem("Delete ");
        popupFromShapeMenu.add(deleteMenuItem);
        popupFromShapeMenu.add(new JSeparator());
        popupFromShapeMenu.add(addMenuItem);
        deleteMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                MolecularComponent mc = (MolecularComponent) selectedObject;
                // detailed verifications will be done there, to see if they are being used in reactions, species, observables
                if (!mc.getComponentStateDefinitions().isEmpty()) {
                    String[] options = { "OK" };
                    String errMsg = mc.getDisplayType() + " '<b>" + mc.getDisplayName() + "</b>' cannot be deleted because it contains explicit States.";
                    errMsg += "<br>Please delete each individual State first.";
                    errMsg += "<br><br>Detailed usage information will be provided at that time to help you decide.";
                    errMsg = "<html>" + errMsg + "</html>";
                    JOptionPane.showOptionDialog(shapePanel, errMsg, "Delete " + mc.getDisplayType(), JOptionPane.NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
                    return;
                }
                // we find and display component usage information to help the user decide
                Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
                bioModel.getModel().getRbmModelContainer().findComponentUsage(molecularType, mc, usedHere);
                if (!usedHere.isEmpty()) {
                    String errMsg = mc.dependenciesToHtml(usedHere);
                    errMsg += "<br><br>Delete anyway?";
                    errMsg = "<html>" + errMsg + "</html>";
                    int dialogButton = JOptionPane.YES_NO_OPTION;
                    int returnCode = JOptionPane.showConfirmDialog(shapePanel, errMsg, "Delete " + mc.getDisplayType(), dialogButton);
                    if (returnCode == JOptionPane.YES_OPTION) {
                        // keep this code in sync with MolecularTypeTableModel.setValueAt
                        if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc) == true) {
                            molecularType.removeMolecularComponent(mc);
                        }
                    }
                } else {
                    if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc) == true) {
                        molecularType.removeMolecularComponent(mc);
                    }
                }
            }
        });
        addMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                MolecularComponent mc = (MolecularComponent) selectedObject;
                ComponentStateDefinition componentStateDefinition = mc.createComponentStateDefinition();
                mc.addComponentStateDefinition(componentStateDefinition);
                bioModel.getModel().getRbmModelContainer().adjustObservablesPatterns(molecularType, mc, componentStateDefinition);
                bioModel.getModel().getRbmModelContainer().adjustRulesPatterns(molecularType, mc, componentStateDefinition);
                bioModel.getModel().getRbmModelContainer().adjustSpeciesPatterns(molecularType, mc, componentStateDefinition);
            // editInPlace((LargeShape)deepestShape);
            }
        });
        renamMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                editInPlace((LargeShape) deepestShape);
            }
        });
    } else if (selectedObject instanceof ComponentStateDefinition) {
        // rename, delete
        JMenuItem renamMenuItem = new JMenuItem("Rename");
        popupFromShapeMenu.add(renamMenuItem);
        JMenuItem deleteMenuItem = new JMenuItem("Delete");
        popupFromShapeMenu.add(deleteMenuItem);
        deleteMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                ComponentStateDefinition csd = (ComponentStateDefinition) selectedObject;
                // must exist, we're deleting one of its states
                MolecularComponent mc = locationContext.mcs.getMolecularComponent();
                Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
                bioModel.getModel().getRbmModelContainer().findStateUsage(molecularType, mc, csd, usedHere);
                if (!usedHere.isEmpty()) {
                    String errMsg = csd.dependenciesToHtml(usedHere);
                    errMsg += "<br><br>Delete anyway?";
                    errMsg = "<html>" + errMsg + "</html>";
                    int dialogButton = JOptionPane.YES_NO_OPTION;
                    int returnCode = JOptionPane.showConfirmDialog(shapePanel, errMsg, "Delete " + ComponentStateDefinition.typeName, dialogButton);
                    if (returnCode == JOptionPane.YES_OPTION) {
                        // keep this code in sync with MolecularTypeTableModel.setValueAt
                        if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc, csd) == true) {
                            mc.deleteComponentStateDefinition(csd);
                        }
                    }
                } else {
                    if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc, csd) == true) {
                        mc.deleteComponentStateDefinition(csd);
                    }
                }
            }
        });
        renamMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                editInPlace((LargeShape) deepestShape);
            }
        });
    }
    popupFromShapeMenu.show(e.getComponent(), mousePoint.x, mousePoint.y);
}
Also used : ActionEvent(java.awt.event.ActionEvent) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) JSeparator(javax.swing.JSeparator) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) LinkedHashMap(java.util.LinkedHashMap) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition) MolecularTypeLargeShape(cbit.vcell.graph.MolecularTypeLargeShape) MolecularComponent(org.vcell.model.rbm.MolecularComponent) JMenuItem(javax.swing.JMenuItem) MolecularComponentLargeShape(cbit.vcell.graph.MolecularComponentLargeShape) Pair(org.vcell.util.Pair) Displayable(org.vcell.util.Displayable) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) Point(java.awt.Point) MolecularType(org.vcell.model.rbm.MolecularType) ActionListener(java.awt.event.ActionListener) ComponentStateLargeShape(cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape) MolecularTypeLargeShape(cbit.vcell.graph.MolecularTypeLargeShape) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) ComponentStateLargeShape(cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape) LargeShape(cbit.vcell.graph.LargeShape) MolecularComponentLargeShape(cbit.vcell.graph.MolecularComponentLargeShape) RelationshipObject(org.vcell.relationship.RelationshipObject) BioPaxObject(org.vcell.pathway.BioPaxObject) Icon(javax.swing.Icon) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ActionMap(javax.swing.ActionMap) InputMap(javax.swing.InputMap)

Example 14 with ComponentStateDefinition

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

the class RulebasedMathMapping method addSpeciesPatterns.

private HashMap<SpeciesPattern, VolumeParticleSpeciesPattern> addSpeciesPatterns(Domain domain, List<ReactionRule> rrList) throws MathException {
    // Particle Molecular Types
    // 
    Model model = getSimulationContext().getModel();
    List<RbmObservable> observableList = model.getRbmModelContainer().getObservableList();
    List<MolecularType> molecularTypeList = model.getRbmModelContainer().getMolecularTypeList();
    for (MolecularType molecularType : molecularTypeList) {
        ParticleMolecularType particleMolecularType = new ParticleMolecularType(molecularType.getName());
        for (MolecularComponent molecularComponent : molecularType.getComponentList()) {
            String pmcName = molecularComponent.getName();
            String pmcId = particleMolecularType.getName() + "_" + molecularComponent.getName();
            ParticleMolecularComponent particleMolecularComponent = new ParticleMolecularComponent(pmcId, pmcName);
            for (ComponentStateDefinition componentState : molecularComponent.getComponentStateDefinitions()) {
                ParticleComponentStateDefinition pcsd = particleMolecularComponent.getComponentStateDefinition(componentState.getName());
                if (pcsd == null) {
                    particleMolecularComponent.addComponentStateDefinition(new ParticleComponentStateDefinition(componentState.getName()));
                }
            }
            particleMolecularType.addMolecularComponent(particleMolecularComponent);
        }
        if (!molecularType.isAnchorAll()) {
            List<String> anchorList = new ArrayList<>();
            for (Structure struct : molecularType.getAnchors()) {
                anchorList.add(struct.getName());
            }
            particleMolecularType.setAnchorList(anchorList);
        }
        mathDesc.addParticleMolecularType(particleMolecularType);
    }
    // 
    // Assemble list of all Species Patterns (from observables, reaction rules, and seed species).
    // 
    // linked hash set maintains insertion order
    LinkedHashMap<SpeciesPattern, Structure> speciesPatternStructureMap = new LinkedHashMap<SpeciesPattern, Structure>();
    for (RbmObservable observable : observableList) {
        for (SpeciesPattern speciesPattern : observable.getSpeciesPatternList()) {
            speciesPatternStructureMap.put(speciesPattern, observable.getStructure());
        }
    }
    for (ReactionRule reactionRule : rrList) {
        for (ReactantPattern rp : reactionRule.getReactantPatterns()) {
            speciesPatternStructureMap.put(rp.getSpeciesPattern(), rp.getStructure());
        }
        for (ProductPattern pp : reactionRule.getProductPatterns()) {
            speciesPatternStructureMap.put(pp.getSpeciesPattern(), pp.getStructure());
        }
    }
    for (SpeciesContext sc : model.getSpeciesContexts()) {
        if (!sc.hasSpeciesPattern()) {
            continue;
        }
        speciesPatternStructureMap.put(sc.getSpeciesPattern(), sc.getStructure());
    }
    // 
    // add list of unique speciesPatterns
    // 
    HashMap<String, VolumeParticleSpeciesPattern> speciesPatternVCMLMap = new HashMap<String, VolumeParticleSpeciesPattern>();
    HashMap<SpeciesPattern, VolumeParticleSpeciesPattern> speciesPatternMap = new HashMap<SpeciesPattern, VolumeParticleSpeciesPattern>();
    String speciesPatternName = "speciesPattern0";
    for (SpeciesPattern speciesPattern : speciesPatternStructureMap.keySet()) {
        VolumeParticleSpeciesPattern volumeParticleSpeciesPattern = new VolumeParticleSpeciesPattern(speciesPatternName, domain, speciesPatternStructureMap.get(speciesPattern).getName());
        for (MolecularTypePattern molecularTypePattern : speciesPattern.getMolecularTypePatterns()) {
            ParticleMolecularType particleMolecularType = mathDesc.getParticleMolecularType(molecularTypePattern.getMolecularType().getName());
            ParticleMolecularTypePattern particleMolecularTypePattern = new ParticleMolecularTypePattern(particleMolecularType);
            String participantMatchLabel = molecularTypePattern.getParticipantMatchLabel();
            if (molecularTypePattern.getParticipantMatchLabel() != null) {
                particleMolecularTypePattern.setMatchLabel(participantMatchLabel);
            }
            for (MolecularComponentPattern molecularComponentPattern : molecularTypePattern.getComponentPatternList()) {
                MolecularComponent molecularComponent = molecularComponentPattern.getMolecularComponent();
                ParticleMolecularComponent particleMolecularComponent = particleMolecularType.getMolecularComponent(molecularComponent.getName());
                ParticleMolecularComponentPattern particleMolecularComponentPattern = new ParticleMolecularComponentPattern(particleMolecularComponent);
                ComponentStatePattern componentState = molecularComponentPattern.getComponentStatePattern();
                if (componentState != null) {
                    if (componentState.isAny()) {
                        ParticleComponentStatePattern pcsp = new ParticleComponentStatePattern();
                        particleMolecularComponentPattern.setComponentStatePattern(pcsp);
                    } else {
                        String name = componentState.getComponentStateDefinition().getName();
                        ParticleComponentStateDefinition pcsd = particleMolecularComponent.getComponentStateDefinition(name);
                        // ParticleComponentStateDefinition pcsd = new ParticleComponentStateDefinition(componentState.getComponentStateDefinition().getName());
                        // particleMolecularComponent.addComponentStateDefinition(pcsd);
                        ParticleComponentStatePattern pcsp = new ParticleComponentStatePattern(pcsd);
                        particleMolecularComponentPattern.setComponentStatePattern(pcsp);
                    }
                } else {
                    ParticleComponentStatePattern pcsp = new ParticleComponentStatePattern();
                    particleMolecularComponentPattern.setComponentStatePattern(pcsp);
                }
                switch(molecularComponentPattern.getBondType()) {
                    case Specified:
                        {
                            particleMolecularComponentPattern.setBondType(ParticleBondType.Specified);
                            particleMolecularComponentPattern.setBondId(molecularComponentPattern.getBondId());
                            break;
                        }
                    case Exists:
                        {
                            particleMolecularComponentPattern.setBondType(ParticleBondType.Exists);
                            particleMolecularComponentPattern.setBondId(-1);
                            break;
                        }
                    case None:
                        {
                            particleMolecularComponentPattern.setBondType(ParticleBondType.None);
                            particleMolecularComponentPattern.setBondId(-1);
                            break;
                        }
                    case Possible:
                        {
                            particleMolecularComponentPattern.setBondType(ParticleBondType.Possible);
                            particleMolecularComponentPattern.setBondId(-1);
                            break;
                        }
                }
                particleMolecularTypePattern.addMolecularComponentPattern(particleMolecularComponentPattern);
            }
            volumeParticleSpeciesPattern.addMolecularTypePattern(particleMolecularTypePattern);
        }
        String speciesPatternVCML = volumeParticleSpeciesPattern.getVCML("tempName");
        VolumeParticleSpeciesPattern uniqueVolumeParticleSpeciesPattern = speciesPatternVCMLMap.get(speciesPatternVCML);
        if (uniqueVolumeParticleSpeciesPattern == null) {
            speciesPatternVCMLMap.put(speciesPatternVCML, volumeParticleSpeciesPattern);
            speciesPatternName = TokenMangler.getNextEnumeratedToken(speciesPatternName);
            speciesPatternMap.put(speciesPattern, volumeParticleSpeciesPattern);
        } else {
            speciesPatternMap.put(speciesPattern, uniqueVolumeParticleSpeciesPattern);
        }
    }
    return speciesPatternMap;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ParticleMolecularComponent(cbit.vcell.math.ParticleMolecularComponent) SpeciesContext(cbit.vcell.model.SpeciesContext) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition) ParticleComponentStateDefinition(cbit.vcell.math.ParticleComponentStateDefinition) LinkedHashMap(java.util.LinkedHashMap) ParticleMolecularComponent(cbit.vcell.math.ParticleMolecularComponent) MolecularComponent(org.vcell.model.rbm.MolecularComponent) ParticleComponentStateDefinition(cbit.vcell.math.ParticleComponentStateDefinition) ParticleMolecularComponentPattern(cbit.vcell.math.ParticleMolecularComponentPattern) Structure(cbit.vcell.model.Structure) ParticleMolecularType(cbit.vcell.math.ParticleMolecularType) ReactantPattern(cbit.vcell.model.ReactantPattern) ReactionRule(cbit.vcell.model.ReactionRule) ProductPattern(cbit.vcell.model.ProductPattern) ParticleMolecularComponentPattern(cbit.vcell.math.ParticleMolecularComponentPattern) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ParticleComponentStatePattern(cbit.vcell.math.ParticleComponentStatePattern) RbmObservable(cbit.vcell.model.RbmObservable) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) ParticleComponentStatePattern(cbit.vcell.math.ParticleComponentStatePattern) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) ParticleMolecularTypePattern(cbit.vcell.math.ParticleMolecularTypePattern) ParticleMolecularType(cbit.vcell.math.ParticleMolecularType) MolecularType(org.vcell.model.rbm.MolecularType) Model(cbit.vcell.model.Model) ParticleMolecularTypePattern(cbit.vcell.math.ParticleMolecularTypePattern) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern)

Example 15 with ComponentStateDefinition

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

the class MolecularComponentLargeShape method getLongestStateName.

private String getLongestStateName(MolecularComponent mc) {
    String longestStateName = "";
    if (shapePanel.getZoomFactor() < LargeShapeCanvas.SmallestZoomFactorWithText) {
        return "";
    }
    for (int i = 0; i < mc.getComponentStateDefinitions().size(); i++) {
        ComponentStateDefinition csd = mc.getComponentStateDefinitions().get(i);
        String stateName = csd.getDisplayName();
        stateName = adjustForStateSize(stateName);
        longestStateName = stateName.length() > longestStateName.length() ? stateName : longestStateName;
    }
    return longestStateName;
}
Also used : Paint(java.awt.Paint) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Aggregations

ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)31 MolecularComponent (org.vcell.model.rbm.MolecularComponent)23 MolecularType (org.vcell.model.rbm.MolecularType)15 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)12 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)10 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)10 BioModelNode (cbit.vcell.desktop.BioModelNode)8 LinkedHashMap (java.util.LinkedHashMap)7 Icon (javax.swing.Icon)7 Point (java.awt.Point)6 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)6 ParticleComponentStateDefinition (cbit.vcell.math.ParticleComponentStateDefinition)5 List (java.util.List)5 Graphics (java.awt.Graphics)4 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 JMenuItem (javax.swing.JMenuItem)4 BondType (org.vcell.model.rbm.MolecularComponentPattern.BondType)4 Bond (org.vcell.model.rbm.SpeciesPattern.Bond)4 BioPaxObject (org.vcell.pathway.BioPaxObject)4