Search in sources :

Example 26 with ComponentStatePattern

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

the class ReactionRule method findStateUsage.

public void findStateUsage(MolecularType mt, MolecularComponent mc, ComponentStateDefinition csd, Map<String, Pair<Displayable, SpeciesPattern>> usedHere) {
    for (ProductPattern pp : getProductPatterns()) {
        SpeciesPattern sp = pp.getSpeciesPattern();
        for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
            if (mtp.getMolecularType() == mt) {
                List<MolecularComponentPattern> componentPatterns = mtp.getComponentPatternList();
                for (MolecularComponentPattern mcp : componentPatterns) {
                    if (mcp.isImplied()) {
                        // we don't care about these
                        continue;
                    }
                    if (mcp.getMolecularComponent() == mc) {
                        // found mc in use
                        // now let's look at component state definition
                        ComponentStatePattern csp = mcp.getComponentStatePattern();
                        if (csp == null) {
                            continue;
                        }
                        if (csp.getComponentStateDefinition() == csd) {
                            String key = getDisplayType() + getDisplayName() + sp.getDisplayName();
                            usedHere.put(key, new Pair<Displayable, SpeciesPattern>(this, sp));
                        }
                    }
                }
            }
        }
    }
    for (ReactantPattern rp : getReactantPatterns()) {
        SpeciesPattern sp = rp.getSpeciesPattern();
        for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
            if (mtp.getMolecularType() == mt) {
                List<MolecularComponentPattern> componentPatterns = mtp.getComponentPatternList();
                for (MolecularComponentPattern mcp : componentPatterns) {
                    if (mcp.isImplied()) {
                        continue;
                    }
                    if (mcp.getMolecularComponent() == mc) {
                        ComponentStatePattern csp = mcp.getComponentStatePattern();
                        if (csp == null) {
                            continue;
                        }
                        if (csp.getComponentStateDefinition() == csd) {
                            String key = getDisplayType() + getDisplayName() + sp.getDisplayName();
                            usedHere.put(key, new Pair<Displayable, SpeciesPattern>(this, sp));
                        }
                    }
                }
            }
        }
    }
}
Also used : Displayable(org.vcell.util.Displayable) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 27 with ComponentStatePattern

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

the class ReactionRule method checkComponentStateConsistency.

public void checkComponentStateConsistency(IssueContext issueContext, List<Issue> issueList, MolecularTypePattern mtpThis) {
    if (issueList == null) {
        // this may be called during parsing before the model is consistent
        return;
    }
    issueContext = issueContext.newChildContext(ContextType.ReactionRule, this);
    MolecularType mtThat = mtpThis.getMolecularType();
    for (MolecularComponentPattern mcpThis : mtpThis.getComponentPatternList()) {
        if (mcpThis.isImplied()) {
            continue;
        }
        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, mcpThis, issueContext, IssueCategory.Identifiers, msg, 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, msg, 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 = "Component pattern " + mcNameThis + " must be in an explicit State.";
                // issueList.add(new Issue(this, IssueCategory.Identifiers, msg, Issue.SEVERITY_WARNING));
                } else {
                    String csdNameThis = cspThis.getComponentStateDefinition().getName();
                    if (csdNameThis.isEmpty() || (mcThat.getComponentStateDefinition(csdNameThis) == null)) {
                        String msg = "Invalid State " + csdNameThis + " for component pattern " + mcNameThis;
                        issueList.add(new Issue(this, mcpThis, issueContext, IssueCategory.Identifiers, msg, msg, 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) ArrayList(java.util.ArrayList) List(java.util.List)

Example 28 with ComponentStatePattern

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

the class ReactionRule method deleteStateFromPatterns.

public boolean deleteStateFromPatterns(MolecularType mt, MolecularComponent mc, ComponentStateDefinition csd) {
    for (ProductPattern pp : getProductPatterns()) {
        SpeciesPattern sp = pp.getSpeciesPattern();
        for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
            if (mtp.getMolecularType() == mt) {
                List<MolecularComponentPattern> componentPatterns = mtp.getComponentPatternList();
                for (MolecularComponentPattern mcp : componentPatterns) {
                    if (!(mcp.getMolecularComponent() == mc)) {
                        // not our mc
                        continue;
                    }
                    ComponentStatePattern csp = mcp.getComponentStatePattern();
                    if (csp == null) {
                        continue;
                    }
                    if (csp.isAny()) {
                        if (mc.getComponentStateDefinitions().size() == 1) {
                            // we are about to delete the last possible state, so we set the ComponentStatePattern to null
                            mcp.setComponentStatePattern(null);
                        }
                        continue;
                    }
                    if (csp.getComponentStateDefinition() == csd) {
                        if (mc.getComponentStateDefinitions().size() == 1) {
                            // we are about to delete the last possible state, so we set the ComponentStatePattern to null
                            mcp.setComponentStatePattern(null);
                        } else {
                            // some other state is still available, we set the ComponentStatePattern to Any and let the user deal with it
                            csp = new ComponentStatePattern();
                            mcp.setComponentStatePattern(csp);
                        }
                    }
                }
            }
        }
    }
    for (ReactantPattern rp : getReactantPatterns()) {
        SpeciesPattern sp = rp.getSpeciesPattern();
        for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
            if (mtp.getMolecularType() == mt) {
                List<MolecularComponentPattern> componentPatterns = mtp.getComponentPatternList();
                for (MolecularComponentPattern mcp : componentPatterns) {
                    if (!(mcp.getMolecularComponent() == mc)) {
                        continue;
                    }
                    ComponentStatePattern csp = mcp.getComponentStatePattern();
                    if (csp == null) {
                        continue;
                    }
                    if (csp.isAny()) {
                        if (mc.getComponentStateDefinitions().size() == 1) {
                            mcp.setComponentStatePattern(null);
                        }
                        continue;
                    }
                    if (csp.getComponentStateDefinition() == csd) {
                        if (mc.getComponentStateDefinitions().size() == 1) {
                            mcp.setComponentStatePattern(null);
                        } else {
                            csp = new ComponentStatePattern();
                            mcp.setComponentStatePattern(csp);
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 29 with ComponentStatePattern

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

the class SpeciesContext method findStateUsage.

public void findStateUsage(MolecularType mt, MolecularComponent mc, ComponentStateDefinition csd, Map<String, Pair<Displayable, SpeciesPattern>> usedHere) {
    if (!hasSpeciesPattern()) {
        return;
    }
    SpeciesPattern sp = getSpeciesPattern();
    for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
        if (mtp.getMolecularType() == mt) {
            List<MolecularComponentPattern> componentPatterns = mtp.getComponentPatternList();
            for (MolecularComponentPattern mcp : componentPatterns) {
                if (mcp.getMolecularComponent() == mc) {
                    // here some state is always in use if available
                    ComponentStatePattern csp = mcp.getComponentStatePattern();
                    if (csp == null) {
                        System.out.println("This component " + mc.getName() + " should have had some State specified.");
                        continue;
                    }
                    if ((csp.getComponentStateDefinition() == csd) && (mcp.getBond() != null)) {
                        // we only care if there's a bond
                        String key = sp.getDisplayName();
                        key = getDisplayType() + getDisplayName() + key;
                        usedHere.put(key, new Pair<Displayable, SpeciesPattern>(this, sp));
                    }
                }
            }
        }
    }
}
Also used : Displayable(org.vcell.util.Displayable) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 30 with ComponentStatePattern

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

the class SpeciesContext method deleteStateFromPatterns.

public boolean deleteStateFromPatterns(MolecularType mt, MolecularComponent mc, ComponentStateDefinition csd) {
    if (!hasSpeciesPattern()) {
        return true;
    }
    SpeciesPattern sp = getSpeciesPattern();
    for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
        if (mtp.getMolecularType() == mt) {
            List<MolecularComponentPattern> componentPatterns = mtp.getComponentPatternList();
            for (MolecularComponentPattern mcp : componentPatterns) {
                if (!(mcp.getMolecularComponent() == mc)) {
                    continue;
                }
                ComponentStatePattern csp = mcp.getComponentStatePattern();
                if (csp == null) {
                    continue;
                }
                if (csp.isAny()) {
                    if (mc.getComponentStateDefinitions().size() == 1) {
                        mcp.setComponentStatePattern(null);
                    }
                    continue;
                }
                if (csp.getComponentStateDefinition() == csd) {
                    if (mc.getComponentStateDefinitions().size() == 1) {
                        // we are about to delete the last possible state, so we set the ComponentStatePattern to null
                        mcp.setComponentStatePattern(null);
                    } else {
                        // set to Any (may result in an Issue being raised)
                        csp = new ComponentStatePattern();
                        mcp.setComponentStatePattern(csp);
                    }
                }
            }
        }
    }
    return true;
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Aggregations

ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)30 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)25 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)19 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)16 MolecularComponent (org.vcell.model.rbm.MolecularComponent)10 MolecularType (org.vcell.model.rbm.MolecularType)9 Graphics (java.awt.Graphics)8 Icon (javax.swing.Icon)8 ZoomShapeIcon (cbit.vcell.graph.gui.ZoomShapeIcon)6 Point (java.awt.Point)6 ActionEvent (java.awt.event.ActionEvent)6 ActionListener (java.awt.event.ActionListener)6 JMenu (javax.swing.JMenu)6 JMenuItem (javax.swing.JMenuItem)6 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)6 MolecularTypeSmallShape (cbit.vcell.graph.MolecularTypeSmallShape)5 BondType (org.vcell.model.rbm.MolecularComponentPattern.BondType)5 Bond (org.vcell.model.rbm.SpeciesPattern.Bond)5 BioModelNode (cbit.vcell.desktop.BioModelNode)4 LinkedHashMap (java.util.LinkedHashMap)4