Search in sources :

Example 1 with MolecularComponentEntry

use of org.vcell.model.rbm.RuleAnalysis.MolecularComponentEntry in project vcell by virtualcell.

the class ModelRuleFactory method createRuleEntry.

public ModelRuleEntry createRuleEntry(ReactionRule reactionRule, int reactionRuleIndex, ReactionRuleDirection direction) {
    ModelRuleEntry rule = new ModelRuleEntry(reactionRule, reactionRuleIndex);
    // 
    // for each molecular type in reactant, find all possible matches in products (without regard for consistency).
    // 
    int participantIndex = 0;
    for (ReactantPattern rp : reactionRule.getReactantPatterns()) {
        ModelParticipantEntry reactantEntry = new ModelParticipantEntry(rule, participantIndex, rp);
        rule.reactantEntries.add(reactantEntry);
        int moleculeIndex = 0;
        for (MolecularTypePattern mtp : rp.getSpeciesPattern().getMolecularTypePatterns()) {
            ModelMolecularTypeEntry molecularTypeEntry = new ModelMolecularTypeEntry(reactantEntry, moleculeIndex, mtp);
            rule.reactantMolecularTypeEntries.add(molecularTypeEntry);
            int componentIndex = 0;
            for (MolecularComponentPattern mcp : mtp.getComponentPatternList()) {
                // TODO: divergence point vs. MathRuleFactory
                // we need to look at all components when we compare reactants to products looking for changes
                // if(mcp.getBondType() == BondType.Possible && (mcp.getComponentStatePattern() == null || mcp.getComponentStatePattern().isAny())) {
                // continue;
                // }
                ModelMolecularComponentEntry mce = new ModelMolecularComponentEntry(molecularTypeEntry, componentIndex, mcp);
                rule.reactantMolecularComponentEntries.add(mce);
                // 
                // if this reactant component has a bond, find partner already in list (will always find second binding site where first one is in the list already).
                // 
                Bond bond = mcp.getBond();
                if (bond != null) {
                    ReactantBondEntry bondEntry = null;
                    for (MolecularComponentEntry otherMCE : rule.reactantMolecularComponentEntries) {
                        if (((ModelMolecularComponentEntry) otherMCE).molecularComponentPattern == bond.molecularComponentPattern) {
                            bondEntry = new ReactantBondEntry(otherMCE, mce);
                            break;
                        }
                    }
                    if (bondEntry != null) {
                        rule.reactantBondEntries.add(bondEntry);
                    }
                }
                componentIndex++;
            }
            moleculeIndex++;
        }
        participantIndex++;
    }
    participantIndex = 0;
    for (ProductPattern pp : reactionRule.getProductPatterns()) {
        ModelParticipantEntry productEntry = new ModelParticipantEntry(rule, participantIndex, pp);
        rule.productEntries.add(productEntry);
        int moleculeIndex = 0;
        for (MolecularTypePattern mtp : pp.getSpeciesPattern().getMolecularTypePatterns()) {
            ModelMolecularTypeEntry molecularTypeEntry = new ModelMolecularTypeEntry(productEntry, moleculeIndex, mtp);
            rule.productMolecularTypeEntries.add(molecularTypeEntry);
            int componentIndex = 0;
            for (MolecularComponentPattern mcp : mtp.getComponentPatternList()) {
                // TODO: divergence point vs. MathRuleFactory
                // we need to look at all components when we compare reactants to products looking for changes
                // if(mcp.getBondType() == BondType.Possible && (mcp.getComponentStatePattern() == null || mcp.getComponentStatePattern().isAny())) {
                // continue;
                // }
                ModelMolecularComponentEntry mce = new ModelMolecularComponentEntry(molecularTypeEntry, componentIndex, mcp);
                rule.productMolecularComponentEntries.add(mce);
                // 
                // if this product component has a bond, find partner already in list (will always find second binding site where first one is in the list already).
                // 
                Bond bond = mcp.getBond();
                if (bond != null) {
                    ProductBondEntry bondEntry = null;
                    for (MolecularComponentEntry otherMCE : rule.productMolecularComponentEntries) {
                        if (((ModelMolecularComponentEntry) otherMCE).molecularComponentPattern == bond.molecularComponentPattern) {
                            bondEntry = new ProductBondEntry(otherMCE, mce);
                            break;
                        }
                    }
                    if (bondEntry != null) {
                        rule.productBondEntries.add(bondEntry);
                    }
                }
                componentIndex++;
            }
            moleculeIndex++;
        }
        participantIndex++;
    }
    return rule;
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ProductBondEntry(org.vcell.model.rbm.RuleAnalysis.ProductBondEntry) ReactantBondEntry(org.vcell.model.rbm.RuleAnalysis.ReactantBondEntry) MolecularComponentEntry(org.vcell.model.rbm.RuleAnalysis.MolecularComponentEntry) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) Bond(org.vcell.model.rbm.SpeciesPattern.Bond)

Example 2 with MolecularComponentEntry

use of org.vcell.model.rbm.RuleAnalysis.MolecularComponentEntry in project vcell by virtualcell.

the class MathRuleFactory method createRuleEntry.

public MathRuleEntry createRuleEntry(ParticleJumpProcess particleJumpProcess, int particleJumpProcessIndex) {
    MathRuleEntry rule = new MathRuleEntry(particleJumpProcess, particleJumpProcessIndex);
    ArrayList<ParticleSpeciesPattern> selectedPatterns = new ArrayList<ParticleSpeciesPattern>();
    for (ParticleVariable particleVariable : particleJumpProcess.getParticleVariables()) {
        if (!(particleVariable instanceof ParticleSpeciesPattern)) {
            throw new RuntimeException("expecting only " + ParticleSpeciesPattern.class.getSimpleName() + "s for " + ParticleJumpProcess.class.getSimpleName() + " " + particleJumpProcess.getName());
        }
        selectedPatterns.add((ParticleSpeciesPattern) particleVariable);
    }
    ArrayList<ParticleSpeciesPattern> createdPatterns = new ArrayList<ParticleSpeciesPattern>();
    HashSet<ParticleSpeciesPattern> destroyedPatterns = new HashSet<ParticleSpeciesPattern>();
    for (Action action : particleJumpProcess.getActions()) {
        if (!(action.getVar() instanceof ParticleSpeciesPattern)) {
            throw new RuntimeException("expecting only " + ParticleSpeciesPattern.class.getSimpleName() + "s for " + ParticleJumpProcess.class.getSimpleName() + " " + particleJumpProcess.getName());
        }
        if (action.getOperation().equals(Action.ACTION_CREATE)) {
            createdPatterns.add((VolumeParticleSpeciesPattern) action.getVar());
        } else if (action.getOperation().equals(Action.ACTION_DESTROY)) {
            destroyedPatterns.add((VolumeParticleSpeciesPattern) action.getVar());
        } else {
            throw new RuntimeException("unexpected action operation " + action.getOperation() + " for jump process " + particleJumpProcess.getName());
        }
    }
    ArrayList<ParticleSpeciesPattern> productSpeciesPatterns = new ArrayList<ParticleSpeciesPattern>(selectedPatterns);
    productSpeciesPatterns.removeAll(destroyedPatterns);
    productSpeciesPatterns.addAll(createdPatterns);
    // 
    // for each molecular type in reactant, find all possible matches in products (without regard for consistency).
    // 
    int participantIndex = 0;
    for (ParticleSpeciesPattern particleSpeciesPattern : selectedPatterns) {
        MathParticipantEntry reactantEntry = new MathParticipantEntry(rule, participantIndex, particleSpeciesPattern, ParticipantType.Reactant);
        rule.reactantEntries.add(reactantEntry);
        int moleculeIndex = 0;
        for (ParticleMolecularTypePattern mtp : particleSpeciesPattern.getParticleMolecularTypePatterns()) {
            MathMolecularTypeEntry molecularTypeEntry = new MathMolecularTypeEntry(reactantEntry, moleculeIndex, mtp);
            rule.reactantMolecularTypeEntries.add(molecularTypeEntry);
            int componentIndex = 0;
            for (ParticleMolecularComponentPattern mcp : mtp.getMolecularComponentPatternList()) {
                // here we skip the trivial components
                if (mcp.getBondType() == ParticleBondType.Possible && (mcp.getComponentStatePattern() == null || mcp.getComponentStatePattern().isAny())) {
                    continue;
                }
                MathMolecularComponentEntry mce = new MathMolecularComponentEntry(molecularTypeEntry, componentIndex, mcp);
                rule.reactantMolecularComponentEntries.add(mce);
                // 
                if (mcp.getBondType() == ParticleBondType.Specified) {
                    ReactantBondEntry bondEntry = null;
                    for (MolecularComponentEntry otherMCE : rule.reactantMolecularComponentEntries) {
                        if (mce.isBoundTo(otherMCE)) {
                            bondEntry = new ReactantBondEntry(otherMCE, mce);
                            break;
                        }
                    }
                    if (bondEntry != null) {
                        rule.reactantBondEntries.add(bondEntry);
                    }
                }
                componentIndex++;
            }
            moleculeIndex++;
        }
        participantIndex++;
    }
    participantIndex = 0;
    for (ParticleSpeciesPattern particleSpeciesPattern : productSpeciesPatterns) {
        MathParticipantEntry productEntry = new MathParticipantEntry(rule, participantIndex, particleSpeciesPattern, ParticipantType.Product);
        rule.productEntries.add(productEntry);
        int moleculeIndex = 0;
        for (ParticleMolecularTypePattern mtp : particleSpeciesPattern.getParticleMolecularTypePatterns()) {
            MathMolecularTypeEntry molecularTypeEntry = new MathMolecularTypeEntry(productEntry, moleculeIndex, mtp);
            rule.productMolecularTypeEntries.add(molecularTypeEntry);
            int componentIndex = 0;
            for (ParticleMolecularComponentPattern mcp : mtp.getMolecularComponentPatternList()) {
                // here we skip the trivial components
                if (mcp.getBondType() == ParticleBondType.Possible && (mcp.getComponentStatePattern() == null || mcp.getComponentStatePattern().isAny())) {
                    continue;
                }
                MathMolecularComponentEntry mce = new MathMolecularComponentEntry(molecularTypeEntry, componentIndex, mcp);
                rule.productMolecularComponentEntries.add(mce);
                // 
                if (mcp.getBondType() == ParticleBondType.Specified) {
                    ProductBondEntry bondEntry = null;
                    for (MolecularComponentEntry otherMCE : rule.productMolecularComponentEntries) {
                        if (mce.isBoundTo(otherMCE)) {
                            bondEntry = new ProductBondEntry(otherMCE, mce);
                            break;
                        }
                    }
                    if (bondEntry != null) {
                        rule.productBondEntries.add(bondEntry);
                    }
                }
                componentIndex++;
            }
            moleculeIndex++;
        }
        participantIndex++;
    }
    return rule;
}
Also used : ProductBondEntry(org.vcell.model.rbm.RuleAnalysis.ProductBondEntry) ArrayList(java.util.ArrayList) ReactantBondEntry(org.vcell.model.rbm.RuleAnalysis.ReactantBondEntry) MolecularComponentEntry(org.vcell.model.rbm.RuleAnalysis.MolecularComponentEntry) HashSet(java.util.HashSet)

Example 3 with MolecularComponentEntry

use of org.vcell.model.rbm.RuleAnalysis.MolecularComponentEntry in project vcell by virtualcell.

the class ParticipantSignatureShapePanel method hasBondChanged.

public RuleAnalysisChanged hasBondChanged(String key, MolecularComponentPattern molecularComponentPattern) {
    ReactionRule reactionRule = reactionRuleMap.get(key);
    if (reactionRule == null) {
        return RuleAnalysisChanged.ANALYSISFAILED;
    }
    ModelRuleEntry modelRuleEntry = modelRuleEntryMap.get(key);
    RuleAnalysisReport report = reportMap.get(key);
    if (modelRuleEntry == null || report == null) {
        System.out.println("modelRuleEntry == null || report == null,  NOT GOOD!");
    // refreshRuleAnalysis();
    }
    if (!bRuleAnalysisFailed && report != null) {
        MolecularComponentEntry molecularComponentEntry = modelRuleEntry.findMolecularComponentEntry(molecularComponentPattern);
        if (report.hasBondChanged(molecularComponentEntry)) {
            return RuleAnalysisChanged.CHANGED;
        } else {
            return RuleAnalysisChanged.UNCHANGED;
        }
    } else {
        return RuleAnalysisChanged.ANALYSISFAILED;
    }
}
Also used : RuleAnalysisReport(org.vcell.model.rbm.RuleAnalysisReport) ModelRuleEntry(cbit.vcell.model.ModelRuleFactory.ModelRuleEntry) ReactionRule(cbit.vcell.model.ReactionRule) MolecularComponentEntry(org.vcell.model.rbm.RuleAnalysis.MolecularComponentEntry)

Example 4 with MolecularComponentEntry

use of org.vcell.model.rbm.RuleAnalysis.MolecularComponentEntry in project vcell by virtualcell.

the class ParticipantSignatureShapePanel method hasStateChanged.

public RuleAnalysisChanged hasStateChanged(String key, MolecularComponentPattern molecularComponentPattern) {
    ReactionRule reactionRule = reactionRuleMap.get(key);
    if (reactionRule == null) {
        return RuleAnalysisChanged.ANALYSISFAILED;
    }
    ModelRuleEntry modelRuleEntry = modelRuleEntryMap.get(key);
    RuleAnalysisReport report = reportMap.get(key);
    if (modelRuleEntry == null || report == null) {
        System.out.println("modelRuleEntry == null || report == null,  NOT GOOD!");
    // refreshRuleAnalysis();
    }
    if (!bRuleAnalysisFailed && report != null) {
        MolecularComponentEntry molecularComponentEntry = modelRuleEntry.findMolecularComponentEntry(molecularComponentPattern);
        if (report.hasStateChanged(molecularComponentEntry)) {
            return RuleAnalysisChanged.CHANGED;
        } else {
            return RuleAnalysisChanged.UNCHANGED;
        }
    } else {
        return RuleAnalysisChanged.ANALYSISFAILED;
    }
}
Also used : RuleAnalysisReport(org.vcell.model.rbm.RuleAnalysisReport) ModelRuleEntry(cbit.vcell.model.ModelRuleFactory.ModelRuleEntry) ReactionRule(cbit.vcell.model.ReactionRule) MolecularComponentEntry(org.vcell.model.rbm.RuleAnalysis.MolecularComponentEntry)

Aggregations

MolecularComponentEntry (org.vcell.model.rbm.RuleAnalysis.MolecularComponentEntry)4 ModelRuleEntry (cbit.vcell.model.ModelRuleFactory.ModelRuleEntry)2 ReactionRule (cbit.vcell.model.ReactionRule)2 ProductBondEntry (org.vcell.model.rbm.RuleAnalysis.ProductBondEntry)2 ReactantBondEntry (org.vcell.model.rbm.RuleAnalysis.ReactantBondEntry)2 RuleAnalysisReport (org.vcell.model.rbm.RuleAnalysisReport)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)1 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)1 Bond (org.vcell.model.rbm.SpeciesPattern.Bond)1