Search in sources :

Example 16 with MolecularComponent

use of org.vcell.model.rbm.MolecularComponent 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 17 with MolecularComponent

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

the class SpeciesContext method checkComponentStateConsistency.

public void checkComponentStateConsistency(IssueContext issueContext, List<Issue> issueList, MolecularTypePattern mtpThis) {
    issueContext = issueContext.newChildContext(ContextType.SpeciesContext, this);
    MolecularType mtThat = mtpThis.getMolecularType();
    for (MolecularComponentPattern mcpThis : mtpThis.getComponentPatternList()) {
        ComponentStatePattern cspThis = mcpThis.getComponentStatePattern();
        String mcNameThis = mcpThis.getMolecularComponent().getName();
        MolecularComponent[] mcThatList = mtThat.getMolecularComponents(mcNameThis);
        if (mcThatList.length == 0) {
            System.out.println("we already fired an issue about component missing");
            // nothing to do here, we already fired an issue about component missing
            continue;
        } else if (mcThatList.length > 1) {
            String msg = "Multiple " + MolecularComponent.typeName + "s with the same name are not yet supported.";
            issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, Issue.SEVERITY_ERROR));
        } else {
            // found exactly 1 component
            MolecularComponent mcThat = mcThatList[0];
            List<ComponentStateDefinition> csdListThat = mcThat.getComponentStateDefinitions();
            if (csdListThat.size() == 0) {
                // component has no states, we check if mcpThis has any states... it shouldn't
                if (cspThis == null) {
                    // all is well
                    continue;
                }
                if (!cspThis.isAny() || (cspThis.getComponentStateDefinition() != null)) {
                    String msg = MolecularComponentPattern.typeName + " " + mcNameThis + " is in an invalid State.";
                    issueList.add(new Issue(this, mcpThis, issueContext, IssueCategory.Identifiers, msg, null, Issue.SEVERITY_WARNING));
                }
            } else {
                // we check if mcpThis has any of these states... it should!
                if ((cspThis == null) || cspThis.isAny() || (cspThis.getComponentStateDefinition() == null)) {
                    String msg = MolecularComponentPattern.typeName + " " + mcNameThis + " must be in an explicit State.";
                    issueList.add(new Issue(this, mcpThis, issueContext, IssueCategory.Identifiers, msg, null, Issue.Severity.ERROR));
                } else {
                    String csdNameThis = cspThis.getComponentStateDefinition().getName();
                    if (csdNameThis.isEmpty() || (mcThat.getComponentStateDefinition(csdNameThis) == null)) {
                        String msg = "Invalid State " + csdNameThis + " for " + MolecularComponentPattern.typeName + " " + mcNameThis;
                        issueList.add(new Issue(this, mcpThis, issueContext, IssueCategory.Identifiers, msg, null, Issue.SEVERITY_WARNING));
                    }
                }
            }
        }
    }
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) Issue(org.vcell.util.Issue) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) MolecularComponent(org.vcell.model.rbm.MolecularComponent) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) List(java.util.List)

Example 18 with MolecularComponent

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

the class RbmMolecularTypeTreeCellEditor method getTreeCellEditorComponent.

@Override
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {
    Component component = null;
    realEditor = defaultCellEditor;
    if (value instanceof BioModelNode) {
        BioModelNode node = (BioModelNode) value;
        Object userObject = node.getUserObject();
        String text = null;
        Icon icon = null;
        if (userObject instanceof MolecularType) {
            text = ((MolecularType) userObject).getName();
            icon = VCellIcons.rbmMolecularTypeIcon;
        } else if (userObject instanceof MolecularComponent) {
            BioModelNode parentNode = (BioModelNode) node.getParent();
            Object parentObject = parentNode == null ? null : parentNode.getUserObject();
            icon = VCellIcons.rbmComponentErrorIcon;
            text = ((MolecularComponent) userObject).getName();
        } else if (userObject instanceof ComponentStateDefinition) {
            text = ((ComponentStateDefinition) userObject).getName();
            icon = VCellIcons.rbmComponentStateIcon;
        } else {
            System.out.println("unexpected thing here " + userObject);
        }
        renderer.setOpenIcon(icon);
        renderer.setClosedIcon(icon);
        renderer.setLeafIcon(icon);
        component = super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row);
        if (editingComponent instanceof JTextField) {
            JTextField textField = (JTextField) editingComponent;
            textField.setText(text);
        }
    }
    return component;
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) MolecularComponent(org.vcell.model.rbm.MolecularComponent) BioModelNode(cbit.vcell.desktop.BioModelNode) Icon(javax.swing.Icon) MolecularComponent(org.vcell.model.rbm.MolecularComponent) Component(java.awt.Component) JTextField(javax.swing.JTextField) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 19 with MolecularComponent

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

the class RbmMolecularTypeTreeCellRenderer method getTreeCellRendererComponent.

@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    setBorder(null);
    if (value instanceof BioModelNode) {
        BioModelNode node = (BioModelNode) value;
        Object userObject = node.getUserObject();
        String text = null;
        String toolTip = null;
        Icon icon = null;
        if (userObject instanceof MolecularType) {
            MolecularType mt = (MolecularType) userObject;
            text = toHtml(mt, true);
            toolTip = toHtmlWithTip(mt, true);
            if (owner == null) {
                icon = VCellIcons.rbmMolecularTypeSimpleIcon;
                ;
            } else {
                Graphics gc = owner.getGraphics();
                icon = new MolecularTypeSmallShape(1, 4, mt, null, gc, mt, null, issueManager);
            }
        } else if (userObject instanceof MolecularComponent) {
            BioModelNode parentNode = (BioModelNode) node.getParent();
            MolecularComponent mc = (MolecularComponent) userObject;
            text = toHtml(mc, true);
            toolTip = toHtmlWithTip(mc, true);
            icon = VCellIcons.rbmComponentGreenIcon;
            if (mc.getComponentStateDefinitions().size() > 0) {
                icon = VCellIcons.rbmComponentGreenStateIcon;
            }
            // here is how to set the cell minimum size !!!
            FontMetrics fm = getFontMetrics(getFont());
            int width = fm.stringWidth(text);
            setMinimumSize(new Dimension(width + 50, fm.getHeight() + 5));
        } else if (userObject instanceof ComponentStateDefinition) {
            ComponentStateDefinition cs = (ComponentStateDefinition) userObject;
            text = toHtml(cs);
            toolTip = toHtmlWithTip(cs);
            icon = VCellIcons.rbmComponentStateIcon;
        } else {
            System.out.println("unknown thingie " + userObject);
        }
        setText(text);
        setIcon(icon);
        setToolTipText(toolTip == null ? text : toolTip);
    }
    return this;
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) Graphics(java.awt.Graphics) MolecularTypeSmallShape(cbit.vcell.graph.MolecularTypeSmallShape) MolecularComponent(org.vcell.model.rbm.MolecularComponent) FontMetrics(java.awt.FontMetrics) BioModelNode(cbit.vcell.desktop.BioModelNode) Icon(javax.swing.Icon) Dimension(java.awt.Dimension) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 20 with MolecularComponent

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

the class RbmTreeCellRenderer method toHtml.

public static final String toHtml(MolecularComponentPattern mcp, boolean bShowWords) {
    String text = (bShowWords ? MolecularComponent.typeName : "") + " <b>" + mcp.getMolecularComponent().getName() + "</b>";
    MolecularComponent mc = mcp.getMolecularComponent();
    return "<html> " + text + "</html>";
}
Also used : MolecularComponent(org.vcell.model.rbm.MolecularComponent)

Aggregations

MolecularComponent (org.vcell.model.rbm.MolecularComponent)42 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)23 MolecularType (org.vcell.model.rbm.MolecularType)23 BioModelNode (cbit.vcell.desktop.BioModelNode)17 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)14 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)11 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)10 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)10 LinkedHashMap (java.util.LinkedHashMap)7 Icon (javax.swing.Icon)7 BondType (org.vcell.model.rbm.MolecularComponentPattern.BondType)7 Point (java.awt.Point)6 List (java.util.List)6 ParticleMolecularComponent (cbit.vcell.math.ParticleMolecularComponent)5 ArrayList (java.util.ArrayList)5 RbmObservable (cbit.vcell.model.RbmObservable)4 ReactionRule (cbit.vcell.model.ReactionRule)4 Structure (cbit.vcell.model.Structure)4 Graphics (java.awt.Graphics)4 ActionEvent (java.awt.event.ActionEvent)4