Search in sources :

Example 86 with SpeciesPattern

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

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

the class ReactionRule method duplicate.

public static ReactionRule duplicate(ReactionRule oldRule, Structure s) throws ExpressionBindingException {
    Model m = oldRule.getModel();
    boolean bR = oldRule.isReversible();
    String newName = ReactionRule.deriveReactionName(oldRule);
    ReactionRule newRule = new ReactionRule(m, newName, s, bR);
    RateLawType rateLawType = oldRule.getKineticLaw().getRateLawType();
    if (rateLawType != RateLawType.MassAction) {
        throw new RuntimeException("Only Mass Action Kinetics supported at this time, " + ReactionRule.typeName + " \"" + oldRule.getName() + "\" uses kinetic law type \"" + rateLawType.toString() + "\"");
    }
    RbmKineticLaw kineticLaw = new RbmKineticLaw(newRule, rateLawType);
    RbmKineticLaw.duplicate(kineticLaw, oldRule);
    for (ReactantPattern oldrp : oldRule.getReactantPatterns()) {
        SpeciesPattern newsp = new SpeciesPattern(m, oldrp.getSpeciesPattern());
        ReactantPattern newrp = new ReactantPattern(newsp, oldrp.getStructure());
        // don't try to resolve matches or bonds, we want to mirror whatever is in the old rule
        newRule.addReactant(newrp, false, false);
    }
    for (ProductPattern oldpp : oldRule.getProductPatterns()) {
        SpeciesPattern newsp = new SpeciesPattern(m, oldpp.getSpeciesPattern());
        ProductPattern newpp = new ProductPattern(newsp, oldpp.getStructure());
        newRule.addProduct(newpp, false, false);
    }
    newRule.setKineticLaw(kineticLaw);
    kineticLaw.bind(newRule);
    return newRule;
}
Also used : RateLawType(cbit.vcell.model.RbmKineticLaw.RateLawType) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 88 with SpeciesPattern

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

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

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

the class SpeciesContext method parseSpeciesPatternString.

public void parseSpeciesPatternString(Model model) {
    if (speciesPatternString.equalsIgnoreCase("null")) {
        System.out.println("Species Pattern String is 'NULL'.");
        return;
    }
    if (speciesPatternString != null) {
        try {
            if (speciesPattern != null) {
                System.out.println("Species pattern already exists: " + speciesPattern.toString());
                return;
            }
            SpeciesPattern sp = RbmUtils.parseSpeciesPattern(speciesPatternString, model);
            setSpeciesPattern(sp);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new RuntimeException("Bad format for repository species pattern string: " + e.getMessage());
        }
    }
}
Also used : ParseException(org.vcell.model.bngl.ParseException) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Aggregations

SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)93 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)39 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)30 MolecularType (org.vcell.model.rbm.MolecularType)25 RbmObservable (cbit.vcell.model.RbmObservable)22 SpeciesContext (cbit.vcell.model.SpeciesContext)22 Structure (cbit.vcell.model.Structure)22 Point (java.awt.Point)18 ReactionRule (cbit.vcell.model.ReactionRule)16 ArrayList (java.util.ArrayList)16 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)16 Graphics (java.awt.Graphics)13 PropertyVetoException (java.beans.PropertyVetoException)13 SpeciesPatternLargeShape (cbit.vcell.graph.SpeciesPatternLargeShape)12 ProductPattern (cbit.vcell.model.ProductPattern)12 ReactantPattern (cbit.vcell.model.ReactantPattern)12 Dimension (java.awt.Dimension)12 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)12 Model (cbit.vcell.model.Model)11 ModelException (cbit.vcell.model.ModelException)11