Search in sources :

Example 56 with MolecularComponentPattern

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

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

the class ReactionRule method getReactantComponentBondType.

public BondType getReactantComponentBondType(MolecularComponentPattern mcpProduct) {
    MolecularTypePattern mtpProduct = getProductMoleculeOfComponent(mcpProduct);
    MolecularTypePattern mtpReactant = getMatchingReactantMolecule(mtpProduct);
    if (mtpReactant == null) {
        // possible if this product has no matching explicit or implicit reactant
        return null;
    }
    for (MolecularComponentPattern mcpReactant : mtpReactant.getComponentPatternList()) {
        if (mcpReactant.getMolecularComponent() != mcpProduct.getMolecularComponent()) {
            continue;
        }
        return mcpReactant.getBondType();
    }
    return null;
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern)

Example 58 with MolecularComponentPattern

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

the class SpeciesContext method findComponentUsage.

public void findComponentUsage(MolecularType mt, MolecularComponent mc, 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 all components are always in use
                    if (mcp.getBond() != null) {
                        // we only care about the components with 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) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 59 with MolecularComponentPattern

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

the class SpeciesContext method checkMolecularTypeConsistency.

// I think this should never fire issues, that's why I keep issue severity to error to force further investigation
// TODO: oct 30, 2015: hasn't fired in 9 months, we replace the issues with exception just to protect ourselves against regressions
private void checkMolecularTypeConsistency(IssueContext issueContext, List<Issue> issueList, MolecularType mtThat, MolecularTypePattern mtpThis) {
    issueContext = issueContext.newChildContext(ContextType.SpeciesContext, this);
    Map<String, MolecularComponent> hashThat = new HashMap<String, MolecularComponent>();
    Map<String, MolecularComponent> hashThis = new HashMap<String, MolecularComponent>();
    for (MolecularComponent mcThat : mtThat.getComponentList()) {
        hashThat.put(mcThat.getName(), mcThat);
    }
    for (MolecularComponentPattern mcpThis : mtpThis.getComponentPatternList()) {
        hashThis.put(mcpThis.getMolecularComponent().getName(), mcpThis.getMolecularComponent());
    }
    Iterator<Entry<String, MolecularComponent>> it = hashThat.entrySet().iterator();
    while (it.hasNext()) {
        String key = ((Map.Entry<String, MolecularComponent>) it.next()).getKey();
        if (hashThis.containsKey(key)) {
            it.remove();
            hashThis.remove(key);
        }
    }
    // any component still present in hashThis it means that it has been deleted in the molecular types definition and is now invalid
    for (String key : hashThat.keySet()) {
        String msg = "All components in the " + mtThat.getDisplayType() + " definition must be present. Missing: " + key + ".";
        throw new RuntimeException(msg);
    // issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, Issue.SEVERITY_ERROR));
    }
    for (String key : hashThis.keySet()) {
        String msg = "Component " + key + " is no longer defined for the " + mtThat.getDisplayType() + " and must be removed.";
        throw new RuntimeException(msg);
    // issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, Issue.SEVERITY_ERROR));
    }
}
Also used : Entry(java.util.Map.Entry) MolecularComponent(org.vcell.model.rbm.MolecularComponent) HashMap(java.util.HashMap) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern)

Example 60 with MolecularComponentPattern

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

the class SpeciesContext method checkBondsSufficiency.

private void checkBondsSufficiency(IssueContext issueContext, List<Issue> issueList, SpeciesPattern sp) {
    if (sp.getMolecularTypePatterns().size() < 2) {
        return;
    }
    int numberOfMolecularTypeCandidates = 0;
    for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
        if (mtp.getComponentPatternList().size() > 0) {
            numberOfMolecularTypeCandidates++;
        }
    }
    if (numberOfMolecularTypeCandidates < 2) {
        // we need at least 2 molecular types with at least 1 component each
        return;
    }
    boolean atLeastOneBad = false;
    for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
        boolean bondSpecifiedExists = false;
        for (MolecularComponentPattern mcp : mtp.getComponentPatternList()) {
            if (mcp.getBondType() == BondType.Specified) {
                Bond b = mcp.getBond();
                if (b != null) {
                    bondSpecifiedExists = true;
                    break;
                }
            }
        }
        if (!bondSpecifiedExists) {
            atLeastOneBad = true;
        }
    }
    if (atLeastOneBad) {
        String msg = "Each Molecular Pattern of the Species Pattern " + sp.toString() + " needs at least one explicit Bond.\n";
        IssueSource parent = issueContext.getContextObject();
        issueList.add(new Issue(parent, issueContext, IssueCategory.Identifiers, msg, Issue.Severity.ERROR));
    }
}
Also used : IssueSource(org.vcell.util.Issue.IssueSource) Issue(org.vcell.util.Issue) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) Bond(org.vcell.model.rbm.SpeciesPattern.Bond)

Aggregations

MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)62 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)49 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)30 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)25 Graphics (java.awt.Graphics)16 MolecularComponent (org.vcell.model.rbm.MolecularComponent)14 Point (java.awt.Point)13 MolecularType (org.vcell.model.rbm.MolecularType)12 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)10 Icon (javax.swing.Icon)9 BondType (org.vcell.model.rbm.MolecularComponentPattern.BondType)9 Bond (org.vcell.model.rbm.SpeciesPattern.Bond)8 List (java.util.List)7 BioModelNode (cbit.vcell.desktop.BioModelNode)6 MolecularTypeLargeShape (cbit.vcell.graph.MolecularTypeLargeShape)6 MolecularTypeSmallShape (cbit.vcell.graph.MolecularTypeSmallShape)6 RuleAnalysisChanged (cbit.vcell.graph.ReactionCartoon.RuleAnalysisChanged)6 SpeciesPatternLargeShape (cbit.vcell.graph.SpeciesPatternLargeShape)6 SpeciesPatternSmallShape (cbit.vcell.graph.SpeciesPatternSmallShape)6 ZoomShapeIcon (cbit.vcell.graph.gui.ZoomShapeIcon)6