Search in sources :

Example 6 with ComponentStatePattern

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

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

the class RbmObservable method resolveStates.

// TODO: this will have to go once we get rid of ComponentStatePattern
// use as a stopgap measure to eliminate a bug where the ComponentStatePattern is null
// instead of being Any (which happens when the MolecularComponent has states defined)
private void resolveStates() {
    for (SpeciesPattern sp : speciesPatternList) {
        for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
            for (MolecularComponentPattern mcp : mtp.getComponentPatternList()) {
                if (mcp.getComponentStatePattern() == null && mcp.getMolecularComponent().getComponentStateDefinitions().size() > 0) {
                    ComponentStatePattern csp = new ComponentStatePattern();
                    mcp.setComponentStatePattern(csp);
                }
            }
        }
    }
}
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 8 with ComponentStatePattern

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

the class RbmObservable method findStateUsage.

public void findStateUsage(MolecularType mt, MolecularComponent mc, ComponentStateDefinition csd, 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
                        // now let's look at component state definition
                        ComponentStatePattern csp = mcp.getComponentStatePattern();
                        if (csp == null) {
                            continue;
                        }
                        if (csp.getComponentStateDefinition() == csd) {
                            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 9 with ComponentStatePattern

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

the class ReactionRule method gatherIssues.

// -----------------------------------------------------------------------------------------------------
// 
public void gatherIssues(IssueContext issueContext, List<Issue> issueList) {
    issueContext = issueContext.newChildContext(ContextType.ReactionRule, this);
    if (name == null || name.isEmpty()) {
        issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "Label is missing", Issue.Severity.ERROR));
    }
    if (name != null && name.startsWith("_reverse_")) {
        String msg = "The prefix '_reverse_' is a BioNetGen reserved keyword. Please rename the " + typeName + ".";
        issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, Issue.Severity.ERROR));
    }
    for (MolecularType mt : model.getRbmModelContainer().getMolecularTypeList()) {
        if (mt.getName().equals(name)) {
            String msg = "Name '" + name + "' name already used for " + mt.getDisplayType() + " '" + mt.getName() + "'.";
            issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, Issue.Severity.WARNING));
            // no need to look further, we won't find another match since Molecule names are unique
            break;
        }
    }
    if (reactantPatterns == null) {
        issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "Reactant Pattern is null", Issue.Severity.ERROR));
    } else if (reactantPatterns.isEmpty()) {
        String msg = typeName + " " + name + " does not have any Reactants.\n";
        issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, Issue.Severity.ERROR));
    } else {
        checkReactantPatterns(issueContext, issueList);
        for (ReactantPattern rp : reactantPatterns) {
            issueContext = issueContext.newChildContext(ContextType.ReactionRule, this);
            rp.getSpeciesPattern().gatherIssues(issueContext, issueList);
        }
    }
    if (productPatterns == null) {
        issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "Product Pattern is null", Issue.Severity.ERROR));
    } else if (productPatterns.isEmpty()) {
        String msg = typeName + " " + name + " does not have any Products.\n";
        issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, Issue.Severity.ERROR));
    } else {
        checkProductPatterns(issueContext, issueList);
        for (ProductPattern pp : productPatterns) {
            issueContext = issueContext.newChildContext(ContextType.ReactionRule, this);
            pp.getSpeciesPattern().gatherIssues(issueContext, issueList);
        }
    }
    kineticLaw.gatherIssues(issueContext, issueList);
    if (molecularTypeMappings == null) {
        issueList.add(new Issue(this, issueContext, IssueCategory.KineticsExpressionMissing, MolecularType.typeName + " Mapping is null", Issue.Severity.WARNING));
    }
    // the structure must be in the list of anchors, if anchors are being used -------------------------------
    for (ReactantPattern rp : reactantPatterns) {
        SpeciesPattern sp = rp.getSpeciesPattern();
        for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
            MolecularType mt = mtp.getMolecularType();
            if (mt.isAnchorAll()) {
                // no restrictions for this molecular type
                continue;
            }
            if (!mt.getAnchors().contains(rp.getStructure())) {
                String message = "The Structure " + structure.getName() + " is not allowed for the Molecule " + mt.getDisplayName();
                issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.ERROR));
            }
        }
    }
    for (ProductPattern pp : productPatterns) {
        SpeciesPattern sp = pp.getSpeciesPattern();
        for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
            MolecularType mt = mtp.getMolecularType();
            if (mt.isAnchorAll()) {
                // no restrictions for this molecular type
                continue;
            }
            if (!mt.getAnchors().contains(pp.getStructure())) {
                String message = "The Structure " + structure.getName() + " is not allowed for the Molecule " + mt.getDisplayName();
                issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.ERROR));
            }
        }
    }
    for (ReactantPattern rp : reactantPatterns) {
        SpeciesPattern sp = rp.getSpeciesPattern();
        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 a reactant.";
                issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.WARNING));
            }
        }
    }
    if (bReversible) {
        for (ProductPattern pp : productPatterns) {
            SpeciesPattern sp = pp.getSpeciesPattern();
            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 a reactant.";
                    issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.WARNING));
                }
            }
        }
    }
    // match management
    issueContext = issueContext.newChildContext(ContextType.ReactionRule, this);
    Map<String, Integer> matchedReactants = new LinkedHashMap<String, Integer>();
    Map<String, Integer> unmatchedReactants = new LinkedHashMap<String, Integer>();
    Map<String, MolecularTypePattern> rMatches = new LinkedHashMap<String, MolecularTypePattern>();
    for (ReactantPattern rp : reactantPatterns) {
        SpeciesPattern sp = rp.getSpeciesPattern();
        for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
            String thisName = mtp.getMolecularType().getDisplayName();
            if (!mtp.hasExplicitParticipantMatch()) {
                if (unmatchedReactants.containsKey(thisName)) {
                    int newCounter = unmatchedReactants.get(thisName) + 1;
                    unmatchedReactants.put(thisName, newCounter);
                } else {
                    unmatchedReactants.put(thisName, 1);
                }
                continue;
            }
            // the value doesn't matter, it's important to be there
            matchedReactants.put(thisName, 99);
            String key = mtp.getParticipantMatchLabel();
            if (rMatches.containsKey(key)) {
                // no duplicates in reactants allowed
                String message = "Multiple Reactants with the same match id " + key + " are not allowed.";
                issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.WARNING));
            } else {
                rMatches.put(key, mtp);
            }
        }
    }
    Map<String, Integer> matchedProducts = new LinkedHashMap<String, Integer>();
    Map<String, Integer> unmatchedProducts = new LinkedHashMap<String, Integer>();
    Map<String, MolecularTypePattern> pMatches = new LinkedHashMap<String, MolecularTypePattern>();
    for (ProductPattern pp : productPatterns) {
        SpeciesPattern sp = pp.getSpeciesPattern();
        for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
            String thisName = mtp.getMolecularType().getDisplayName();
            if (!mtp.hasExplicitParticipantMatch()) {
                if (unmatchedProducts.containsKey(thisName)) {
                    int newCounter = unmatchedProducts.get(thisName) + 1;
                    unmatchedProducts.put(thisName, newCounter);
                } else {
                    unmatchedProducts.put(thisName, 1);
                }
                continue;
            }
            matchedProducts.put(thisName, 100);
            String key = mtp.getParticipantMatchLabel();
            if (pMatches.containsKey(key)) {
                // no duplicates in products allowed
                String message = "Multiple Products with the same match id " + key + " are not allowed.";
                issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.WARNING));
            } else {
                pMatches.put(key, mtp);
            }
        }
    }
    // 2+ unmatched reactants and 1+ unmatched products of same molecule mean error (or vice-versa: 1+ && 2+)
    for (String key : unmatchedReactants.keySet()) {
        if (unmatchedProducts.containsKey(key)) {
            // both maps have the same unmatched molecule, anything larger than 1 and 1 means matching error
            int rCounter = unmatchedReactants.get(key);
            int pCounter = unmatchedProducts.get(key);
            if ((rCounter > 1 && pCounter > 1) || (rCounter > 0 && pCounter > 1)) {
                String message = "Matching missing for Molecule " + key;
                issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.ERROR));
            }
        }
    }
    // must look also for combination with matches and unmatches for the same molecule like pA rA matched AND also pA and rA unmatched - one of each unmatched
    for (String key : unmatchedReactants.keySet()) {
        if (unmatchedProducts.containsKey(key) && matchedProducts.containsKey(key) && matchedReactants.containsKey(key)) {
            int rCounter = matchedReactants.get(key);
            int pCounter = matchedProducts.get(key);
            if (rCounter == 1 && pCounter == 1) {
                // the cases when either is >1 was addressed above, don't need duplicates
                String message = "Matching missing for Molecule " + key;
                issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.ERROR));
            }
        }
    }
    // unmatched products must be unambiguous (bond can't be 'possible' and state can't be 'any')
    for (ProductPattern pp : productPatterns) {
        SpeciesPattern sp = pp.getSpeciesPattern();
        for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
            MolecularTypePattern match = getMatchingReactantMolecule(mtp);
            if (match == null) {
                // this product has no reactant to match
                for (MolecularComponentPattern mcp : mtp.getComponentPatternList()) {
                    if (mcp.isAmbiguousBond()) {
                        String message = "Ambiguous bond '" + mcp.getBondType().name() + "' in site '" + mcp.getMolecularComponent().getDisplayName() + "' in unmatched product molecule '" + mtp.getMolecularType().getDisplayName() + "'";
                        issueList.add(new Issue(this, mcp, issueContext, IssueCategory.Identifiers, message, message, Issue.Severity.ERROR));
                    }
                    if (mcp.isAmbiguousState()) {
                        String message = "Ambiguous state 'any' in site '" + mcp.getMolecularComponent().getDisplayName() + "' in unmatched product molecule '" + mtp.getMolecularType().getDisplayName() + "'";
                        issueList.add(new Issue(this, mcp, issueContext, IssueCategory.Identifiers, message, message, Issue.Severity.ERROR));
                    }
                }
            }
        }
    }
    if (bReversible) {
        // same as above for reactants if the rule is reversible
        for (ReactantPattern rp : reactantPatterns) {
            SpeciesPattern sp = rp.getSpeciesPattern();
            for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
                MolecularTypePattern match = getMatchingProductMolecule(mtp);
                if (match == null) {
                    for (MolecularComponentPattern mcp : mtp.getComponentPatternList()) {
                        if (mcp.isAmbiguousBond()) {
                            String message = "Ambiguous bond '" + mcp.getBondType().name() + "' in site '" + mcp.getMolecularComponent().getDisplayName() + "' in unmatched reactant molecule '" + mtp.getMolecularType().getDisplayName() + "'";
                            issueList.add(new Issue(this, mcp, issueContext, IssueCategory.Identifiers, message, message, Issue.Severity.ERROR));
                        }
                        if (mcp.isAmbiguousState()) {
                            String message = "Ambiguous state 'any' in site '" + mcp.getMolecularComponent().getDisplayName() + "' in unmatched reactant molecule '" + mtp.getMolecularType().getDisplayName() + "'";
                            issueList.add(new Issue(this, mcp, issueContext, IssueCategory.Identifiers, message, message, Issue.Severity.ERROR));
                        }
                    }
                }
            }
        }
    }
    // invalid combinations of bonds / states for corresponding reactant/product component pairs
    for (ReactantPattern rp : reactantPatterns) {
        SpeciesPattern sp = rp.getSpeciesPattern();
        for (MolecularTypePattern mtpReactant : sp.getMolecularTypePatterns()) {
            MolecularTypePattern mtpProduct = getMatchingProductMolecule(mtpReactant);
            // mtpProduct may be null (perhaps we don't have yet any explicit or implicit match for this reactant)
            if (mtpProduct == null) {
                continue;
            }
            for (MolecularComponentPattern mcpReactant : mtpReactant.getComponentPatternList()) {
                // search for a match of the component in this product molecule
                MolecularComponentPattern mcpProduct = ReactionRule.getMatchingComponent(mtpProduct, mcpReactant);
                if (mcpProduct == null) {
                    throw new RuntimeException("Reactant Site " + mcpReactant.getDisplayName() + " is missing its matching Product Site.");
                }
                boolean incompatibleBonds = false;
                switch(mcpReactant.getBondType()) {
                    case Exists:
                        switch(mcpProduct.getBondType()) {
                            case Exists:
                                break;
                            case None:
                                incompatibleBonds = true;
                                break;
                            case Possible:
                                incompatibleBonds = true;
                                break;
                            case Specified:
                                incompatibleBonds = true;
                                break;
                        }
                        break;
                    case None:
                        switch(mcpProduct.getBondType()) {
                            case Exists:
                                incompatibleBonds = true;
                                break;
                            case None:
                                break;
                            case Possible:
                                incompatibleBonds = true;
                                break;
                            case Specified:
                                break;
                        }
                        break;
                    case Possible:
                        switch(mcpProduct.getBondType()) {
                            case Exists:
                                incompatibleBonds = true;
                                break;
                            case None:
                                incompatibleBonds = true;
                                break;
                            case Possible:
                                break;
                            case Specified:
                                incompatibleBonds = true;
                                break;
                        }
                        break;
                    case Specified:
                        switch(mcpProduct.getBondType()) {
                            case Exists:
                                incompatibleBonds = true;
                                break;
                            case None:
                                break;
                            case Possible:
                                incompatibleBonds = true;
                                break;
                            case Specified:
                                break;
                        }
                        break;
                }
                // ----- end of bonds switch
                if (incompatibleBonds) {
                    String message = "Reactant " + MolecularComponentPattern.typeName + " " + mcpReactant.getDisplayName();
                    message += " and its matching Product " + MolecularComponentPattern.typeName + " " + mcpProduct.getDisplayName() + " have incompatible Bond Types.";
                    issueList.add(new Issue(this, mcpProduct, issueContext, IssueCategory.Identifiers, message, message, Issue.Severity.ERROR));
                }
                boolean incompatibleStates = true;
                if (mcpReactant.getMolecularComponent().getComponentStateDefinitions().isEmpty()) {
                // nothing to do if there are no States defined
                } else {
                    ComponentStatePattern cspReactant = mcpReactant.getComponentStatePattern();
                    ComponentStatePattern cspProduct = mcpProduct.getComponentStatePattern();
                    if (cspReactant == null) {
                        String message = "Required " + ComponentStatePattern.typeName + " missing for " + MolecularComponentPattern.typeName + " " + mcpReactant.getDisplayName();
                        issueList.add(new Issue(this, mcpReactant, issueContext, IssueCategory.Identifiers, message, message, Issue.Severity.ERROR));
                    }
                    if (cspProduct == null) {
                        String message = "Required " + ComponentStatePattern.typeName + " missing for " + MolecularComponentPattern.typeName + " " + mcpProduct.getDisplayName();
                        issueList.add(new Issue(this, mcpProduct, issueContext, IssueCategory.Identifiers, message, message, Issue.Severity.ERROR));
                    }
                    if (cspReactant.isAny() && cspProduct.isAny()) {
                        incompatibleStates = false;
                    } else if (!cspReactant.isAny() && !cspProduct.isAny()) {
                        incompatibleStates = false;
                    }
                    if (incompatibleStates) {
                        String message = "Reactant " + MolecularComponentPattern.typeName + " " + mcpReactant.getDisplayName();
                        message += " and its matching Product " + MolecularComponentPattern.typeName + " " + mcpProduct.getDisplayName() + " have incompatible States";
                        issueList.add(new Issue(this, mcpProduct, issueContext, IssueCategory.Identifiers, message, message, Issue.Severity.ERROR));
                    }
                }
            }
        }
    }
}
Also used : Issue(org.vcell.util.Issue) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) LinkedHashMap(java.util.LinkedHashMap) MolecularType(org.vcell.model.rbm.MolecularType) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern)

Example 10 with ComponentStatePattern

use of org.vcell.model.rbm.ComponentStatePattern 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)

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