Search in sources :

Example 21 with SpeciesPattern

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

the class RulebasedTransformer method parseBngOutput.

private void parseBngOutput(SimulationContext simContext, Set<ReactionRule> fromReactions, BNGOutput bngOutput) {
    Model model = simContext.getModel();
    Document bngNFSimXMLDocument = bngOutput.getNFSimXMLDocument();
    bngRootElement = bngNFSimXMLDocument.getRootElement();
    Element modelElement = bngRootElement.getChild("model", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
    Element listOfReactionRulesElement = modelElement.getChild("ListOfReactionRules", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
    List<Element> reactionRuleChildren = new ArrayList<Element>();
    reactionRuleChildren = listOfReactionRulesElement.getChildren("ReactionRule", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
    for (Element reactionRuleElement : reactionRuleChildren) {
        ReactionRuleAnalysisReport rar = new ReactionRuleAnalysisReport();
        boolean bForward = true;
        String rule_id_str = reactionRuleElement.getAttributeValue("id");
        ruleElementMap.put(rule_id_str, reactionRuleElement);
        String rule_name_str = reactionRuleElement.getAttributeValue("name");
        String symmetry_factor_str = reactionRuleElement.getAttributeValue("symmetry_factor");
        Double symmetry_factor_double = Double.parseDouble(symmetry_factor_str);
        ReactionRule rr = null;
        if (rule_name_str.startsWith("_reverse_")) {
            bForward = false;
            rule_name_str = rule_name_str.substring("_reverse_".length());
            rr = model.getRbmModelContainer().getReactionRule(rule_name_str);
            RbmKineticLaw rkl = rr.getKineticLaw();
            try {
                if (symmetry_factor_double != 1.0 && fromReactions.contains(rr)) {
                    Expression expression = rkl.getLocalParameterValue(RbmKineticLawParameterType.MassActionReverseRate);
                    expression = Expression.div(expression, new Expression(symmetry_factor_double));
                    rkl.setLocalParameterValue(RbmKineticLawParameterType.MassActionReverseRate, expression);
                }
            } catch (ExpressionException | PropertyVetoException exc) {
                exc.printStackTrace();
                throw new RuntimeException("Unexpected transform exception: " + exc.getMessage());
            }
            rulesReverseMap.put(rr, rar);
        } else {
            rr = model.getRbmModelContainer().getReactionRule(rule_name_str);
            RbmKineticLaw rkl = rr.getKineticLaw();
            try {
                if (symmetry_factor_double != 1.0 && fromReactions.contains(rr)) {
                    Expression expression = rkl.getLocalParameterValue(RbmKineticLawParameterType.MassActionForwardRate);
                    expression = Expression.div(expression, new Expression(symmetry_factor_double));
                    rkl.setLocalParameterValue(RbmKineticLawParameterType.MassActionForwardRate, expression);
                }
            } catch (ExpressionException | PropertyVetoException exc) {
                exc.printStackTrace();
                throw new RuntimeException("Unexpected transform exception: " + exc.getMessage());
            }
            rulesForwardMap.put(rr, rar);
        }
        rar.symmetryFactor = symmetry_factor_double;
        System.out.println("rule id=" + rule_id_str + ", name=" + rule_name_str + ", symmetry factor=" + symmetry_factor_str);
        keyMap.put(rule_id_str, rr);
        Element listOfReactantPatternsElement = reactionRuleElement.getChild("ListOfReactantPatterns", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
        List<Element> reactantPatternChildren = new ArrayList<Element>();
        reactantPatternChildren = listOfReactantPatternsElement.getChildren("ReactantPattern", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
        for (int i = 0; i < reactantPatternChildren.size(); i++) {
            Element reactantPatternElement = reactantPatternChildren.get(i);
            String pattern_id_str = reactantPatternElement.getAttributeValue("id");
            ReactionRuleParticipant p = bForward ? rr.getReactantPattern(i) : rr.getProductPattern(i);
            SpeciesPattern sp = p.getSpeciesPattern();
            System.out.println("  reactant id=" + pattern_id_str + ", name=" + sp.toString());
            keyMap.put(pattern_id_str, sp);
            // list of molecules
            extractMolecules(sp, model, reactantPatternElement);
            // list of bonds (not implemented)
            extractBonds(reactantPatternElement);
        }
        Element listOfProductPatternsElement = reactionRuleElement.getChild("ListOfProductPatterns", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
        List<Element> productPatternChildren = new ArrayList<Element>();
        productPatternChildren = listOfProductPatternsElement.getChildren("ProductPattern", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
        for (int i = 0; i < productPatternChildren.size(); i++) {
            Element productPatternElement = productPatternChildren.get(i);
            String pattern_id_str = productPatternElement.getAttributeValue("id");
            ReactionRuleParticipant p = bForward ? rr.getProductPattern(i) : rr.getReactantPattern(i);
            SpeciesPattern sp = p.getSpeciesPattern();
            System.out.println("  product  id=" + pattern_id_str + ", name=" + sp.toString());
            keyMap.put(pattern_id_str, sp);
            extractMolecules(sp, model, productPatternElement);
            extractBonds(productPatternElement);
        }
        // extract the Map for this rule
        Element listOfMapElement = reactionRuleElement.getChild("Map", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
        List<Element> mapChildren = new ArrayList<Element>();
        mapChildren = listOfMapElement.getChildren("MapItem", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
        for (Element mapElement : mapChildren) {
            String target_id_str = mapElement.getAttributeValue("targetID");
            String source_id_str = mapElement.getAttributeValue("sourceID");
            System.out.println("Map: target=" + target_id_str + " source=" + source_id_str);
            RbmObject target_object = keyMap.get(target_id_str);
            RbmObject source_object = keyMap.get(source_id_str);
            if (target_object == null)
                System.out.println("!!! Missing map target  " + target_id_str);
            if (source_object == null)
                System.out.println("!!! Missing map source " + source_id_str);
            if (source_object != null) {
                // target_object may be null
                System.out.println("      target=" + target_object + " source=" + source_object);
                Pair<RbmObject, RbmObject> mapEntry = new Pair<RbmObject, RbmObject>(target_object, source_object);
                rar.objmappingList.add(mapEntry);
            }
            Pair<String, String> idmapEntry = new Pair<String, String>(target_id_str, source_id_str);
            rar.idmappingList.add(idmapEntry);
        }
        // ListOfOperations
        Element listOfOperationsElement = reactionRuleElement.getChild("ListOfOperations", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
        List<Element> operationsChildren = new ArrayList<Element>();
        operationsChildren = listOfOperationsElement.getChildren("StateChange", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
        System.out.println("ListOfOperations");
        for (Element operationsElement : operationsChildren) {
            String finalState_str = operationsElement.getAttributeValue("finalState");
            String site_str = operationsElement.getAttributeValue("site");
            RbmObject site_object = keyMap.get(site_str);
            if (site_object == null)
                System.out.println("!!! Missing map object " + site_str);
            if (site_object != null) {
                System.out.println("   finalState=" + finalState_str + " site=" + site_object);
                StateChangeOperation sco = new StateChangeOperation(finalState_str, site_str, site_object);
                rar.operationsList.add(sco);
            }
        }
        operationsChildren = listOfOperationsElement.getChildren("AddBond", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
        for (Element operationsElement : operationsChildren) {
            String site1_str = operationsElement.getAttributeValue("site1");
            String site2_str = operationsElement.getAttributeValue("site2");
            RbmObject site1_object = keyMap.get(site1_str);
            RbmObject site2_object = keyMap.get(site2_str);
            if (site1_object == null)
                System.out.println("!!! Missing map object " + site1_str);
            if (site2_object == null)
                System.out.println("!!! Missing map object " + site2_str);
            if (site1_object != null && site2_object != null) {
                System.out.println("   site1=" + site1_object + " site2=" + site2_object);
                AddBondOperation abo = new AddBondOperation(site1_str, site2_str, site1_object, site2_object);
                rar.operationsList.add(abo);
            }
        }
        operationsChildren = listOfOperationsElement.getChildren("DeleteBond", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
        for (Element operationsElement : operationsChildren) {
            String site1_str = operationsElement.getAttributeValue("site1");
            String site2_str = operationsElement.getAttributeValue("site2");
            RbmObject site1_object = keyMap.get(site1_str);
            RbmObject site2_object = keyMap.get(site2_str);
            if (site1_object == null)
                System.out.println("!!! Missing map object " + site1_str);
            if (site2_object == null)
                System.out.println("!!! Missing map object " + site2_str);
            if (site1_object != null && site2_object != null) {
                System.out.println("   site1=" + site1_object + " site2=" + site2_object);
                DeleteBondOperation dbo = new DeleteBondOperation(site1_str, site2_str, site1_object, site2_object);
                rar.operationsList.add(dbo);
            }
        }
        operationsChildren = listOfOperationsElement.getChildren("Add", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
        for (Element operationsElement : operationsChildren) {
            String id_str = operationsElement.getAttributeValue("id");
            RbmObject id_object = keyMap.get(id_str);
            if (id_object == null)
                System.out.println("!!! Missing map object " + id_str);
            if (id_object != null) {
                System.out.println("   id=" + id_str);
                AddOperation ao = new AddOperation(id_str, id_object);
                rar.operationsList.add(ao);
            }
        }
        operationsChildren = listOfOperationsElement.getChildren("Delete", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
        for (Element operationsElement : operationsChildren) {
            String id_str = operationsElement.getAttributeValue("id");
            String delete_molecules_str = operationsElement.getAttributeValue("DeleteMolecules");
            RbmObject id_object = keyMap.get(id_str);
            if (id_object == null)
                System.out.println("!!! Missing map object " + id_str);
            int delete_molecules_int = 0;
            if (delete_molecules_str != null) {
                delete_molecules_int = Integer.parseInt(delete_molecules_str);
            }
            if (id_object != null) {
                System.out.println("   id=" + id_str + ", DeleteMolecules=" + delete_molecules_str);
                DeleteOperation dop = new DeleteOperation(id_str, id_object, delete_molecules_int);
                rar.operationsList.add(dop);
            }
        }
    }
    System.out.println("done parsing xml file");
}
Also used : Element(org.jdom.Element) ArrayList(java.util.ArrayList) Document(org.jdom.Document) ExpressionException(cbit.vcell.parser.ExpressionException) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) Pair(org.vcell.util.Pair) ReactionRule(cbit.vcell.model.ReactionRule) RbmKineticLaw(cbit.vcell.model.RbmKineticLaw) PropertyVetoException(java.beans.PropertyVetoException) Expression(cbit.vcell.parser.Expression) ReactionRuleParticipant(cbit.vcell.model.ReactionRuleParticipant) RbmObject(org.vcell.model.rbm.RbmObject) Model(cbit.vcell.model.Model)

Example 22 with SpeciesPattern

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

the class RbmObservable method setSpeciesPatternList.

public void setSpeciesPatternList(List<SpeciesPattern> newValue) {
    List<SpeciesPattern> oldValue = speciesPatternList;
    if (oldValue != null) {
        for (SpeciesPattern sp : oldValue) {
            sp.removePropertyChangeListener(this);
        }
    }
    speciesPatternList = newValue;
    if (newValue != null) {
        for (SpeciesPattern sp : newValue) {
            sp.addPropertyChangeListener(this);
        }
        resolveBonds();
    }
    firePropertyChange(RbmObservable.PROPERTY_NAME_SPECIES_PATTERN_LIST, oldValue, newValue);
}
Also used : SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 23 with SpeciesPattern

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

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

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

the class RbmObservable method resolveBonds.

private void resolveBonds() {
    for (SpeciesPattern sp : speciesPatternList) {
        List<MolecularTypePattern> molecularTypePatterns = sp.getMolecularTypePatterns();
        for (int i = 0; i < molecularTypePatterns.size(); ++i) {
            molecularTypePatterns.get(i).setIndex(i + 1);
        }
        sp.resolveBonds();
    }
}
Also used : MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) 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