Search in sources :

Example 56 with MolecularTypePattern

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

the class RbmObservable method gatherIssues.

public void gatherIssues(IssueContext issueContext, List<Issue> issueList) {
    issueContext = issueContext.newChildContext(ContextType.RbmObservable, this);
    if (name == null) {
        issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "Name of Observable is null", Issue.SEVERITY_ERROR));
    } else if (name.equals("")) {
        issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "Name of Observable is empty", Issue.SEVERITY_WARNING));
    } else {
        if (speciesPatternList == null) {
            issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "Observable '" + name + "' Species Pattern List is null", Issue.SEVERITY_ERROR));
        } else if (speciesPatternList.isEmpty()) {
            issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "Observable '" + name + "' Species Pattern List is empty", Issue.SEVERITY_WARNING));
        } else {
            for (SpeciesPattern sp : speciesPatternList) {
                sp.checkSpeciesPattern(issueContext, issueList);
                sp.gatherIssues(issueContext, issueList);
                for (MolecularTypePattern mtpThis : sp.getMolecularTypePatterns()) {
                    checkComponentStateConsistency(issueContext, issueList, mtpThis);
                }
            }
        }
        if (type == null) {
            issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "Observable '" + name + "' Type is null", Issue.SEVERITY_ERROR));
        }
    }
    for (SpeciesPattern sp : speciesPatternList) {
        for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
            String name = mtp.getMolecularType().getDisplayName().toLowerCase();
            if (name.equals("trash")) {
                String message = "'Trash' is a reserved NFSim keyword and it cannot be used as an observable.";
                issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.WARNING));
            }
        }
    }
    // ---------------------------------------- polymer notation restrictions
    // polymer notation may only contain one species pattern and one type of molecule
    boolean polymerAllowedSingle = true;
    // ---------------,,---------------- molecules in trivial state (question marks for bonds and states)
    boolean polymerAllowedSimple = true;
    if (speciesPatternList.size() > 1) {
        polymerAllowedSingle = false;
    }
    if (speciesPatternList.size() > 0) {
        SpeciesPattern sp = speciesPatternList.get(0);
        if (sp != null && !sp.getMolecularTypePatterns().isEmpty()) {
            if (sp.getMolecularTypePatterns().size() > 1) {
                polymerAllowedSingle = false;
            } else {
                MolecularTypePattern mtp = sp.getMolecularTypePatterns().get(0);
                if (mtp != null) {
                    for (MolecularComponentPattern mcp : mtp.getComponentPatternList()) {
                        if (mcp.isbVisible()) {
                            polymerAllowedSimple = false;
                            break;
                        }
                    }
                }
            }
        }
    }
    if (!polymerAllowedSingle && sequence != Sequence.Multimolecular) {
        String message = "Polymer may only be specified for Observable containing a single Molecule.";
        issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.ERROR));
    } else if (!polymerAllowedSimple && sequence != Sequence.Multimolecular) {
        String message = "Polymer may only be specified for Observable with all bonds set to 'Possible' and all States set to 'Any'";
        issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.ERROR));
    }
    if (sequence != Sequence.Multimolecular && type == ObservableType.Molecules) {
        String message = "The Polymer Observable must be of type 'Species'.";
        issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.ERROR));
    }
    if (name.equalsIgnoreCase("Rg3")) {
        System.out.println(name);
    }
    for (SpeciesPattern sp : speciesPatternList) {
        // we look for species patterns where the polymer notation would be more suitable
        Set<String> moleculeNames = new HashSet<>();
        boolean isTrivial = true;
        for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
            moleculeNames.add(mtp.getMolecularType().getDisplayName());
            for (MolecularComponentPattern mcp : mtp.getComponentPatternList()) {
                if (mcp.isbVisible()) {
                    isTrivial = false;
                    // we may have more than 1 sp in the observable, check them all
                    continue;
                }
            }
        }
        if (isTrivial && sp.getMolecularTypePatterns().size() > 1 && moleculeNames.size() == 1) {
            String message = "Please use the Polymer notation (i.e. " + moleculeNames.toArray()[0] + "()>" + (sp.getMolecularTypePatterns().size() - 1) + " ) ";
            message += "instead of " + sp.toString();
            issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.WARNING));
            // if we find one sp that is suitable for polymer notation we stop here and don't check other sp
            break;
        }
    }
}
Also used : Issue(org.vcell.util.Issue) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) HashSet(java.util.HashSet)

Example 57 with MolecularTypePattern

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

the class RbmObservable method deleteStateFromPatterns.

public boolean deleteStateFromPatterns(MolecularType mt, MolecularComponent mc, ComponentStateDefinition csd) {
    for (SpeciesPattern sp : getSpeciesPatternList()) {
        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 {
                            // 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);
                        }
                    }
                }
            }
        }
    }
    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 58 with MolecularTypePattern

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

the class RbmObservable method findComponentUsage.

public void findComponentUsage(MolecularType mt, MolecularComponent mc, Map<String, Pair<Displayable, SpeciesPattern>> usedHere) {
    for (SpeciesPattern sp : getSpeciesPatternList()) {
        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
                        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 MolecularTypePattern

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

the class ReactionRule method findComponentUsage.

// TODO: almost identical to findStateUsage() below - pay attention to keep both in sync
public void findComponentUsage(MolecularType mt, MolecularComponent mc, 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
                        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) {
                        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) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 60 with MolecularTypePattern

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

the class ReactionRule method checkReactantPatterns.

public void checkReactantPatterns(IssueContext issueContext, List<Issue> issueList) {
    issueContext = issueContext.newChildContext(ContextType.ReactionRule, this);
    int cnt = 0;
    // StringBuilder warning = new StringBuilder();
    for (ReactantPattern rp : reactantPatterns) {
        ++cnt;
        if (rp.getSpeciesPattern().getMolecularTypePatterns().size() == 0) {
            String msg = "Reactant " + cnt + " does not have any molecules.\n";
            // warning.append(msg);
            if (issueList != null) {
                issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, Issue.Severity.ERROR));
            }
        } else {
            rp.getSpeciesPattern().checkSpeciesPattern(issueContext, issueList);
            for (MolecularTypePattern mtpThis : rp.getSpeciesPattern().getMolecularTypePatterns()) {
                checkComponentStateConsistency(issueContext, issueList, mtpThis);
            }
        }
    }
// setReactantWarning(warning.length() == 0 ? null : warning.toString());
}
Also used : Issue(org.vcell.util.Issue) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern)

Aggregations

MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)72 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)49 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)39 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)19 Graphics (java.awt.Graphics)16 MolecularType (org.vcell.model.rbm.MolecularType)16 Point (java.awt.Point)14 BioModelNode (cbit.vcell.desktop.BioModelNode)11 RbmObservable (cbit.vcell.model.RbmObservable)10 SpeciesContext (cbit.vcell.model.SpeciesContext)10 Icon (javax.swing.Icon)10 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)10 MolecularComponent (org.vcell.model.rbm.MolecularComponent)10 ArrayList (java.util.ArrayList)9 SpeciesPatternLargeShape (cbit.vcell.graph.SpeciesPatternLargeShape)7 ReactionRule (cbit.vcell.model.ReactionRule)7 LinkedHashMap (java.util.LinkedHashMap)7 MolecularTypeLargeShape (cbit.vcell.graph.MolecularTypeLargeShape)6 MolecularTypeSmallShape (cbit.vcell.graph.MolecularTypeSmallShape)6 RuleAnalysisChanged (cbit.vcell.graph.ReactionCartoon.RuleAnalysisChanged)6