Search in sources :

Example 1 with ParameterContext

use of cbit.vcell.mapping.ParameterContext in project vcell by virtualcell.

the class XmlReader method getRbmReactionRule.

private ReactionRule getRbmReactionRule(Element reactionRuleElement, Model newModel) throws XmlParseException {
    String n = reactionRuleElement.getAttributeValue(XMLTags.NameAttrTag);
    if (n == null || n.isEmpty()) {
        System.out.println("XMLReader: getRbmReactionRule: name is missing.");
        return null;
    }
    try {
        boolean reversible = Boolean.valueOf(reactionRuleElement.getAttributeValue(XMLTags.RbmReactionRuleReversibleTag));
        // get 1st structure if attribute missing
        String structureName = reactionRuleElement.getAttributeValue(XMLTags.StructureAttrTag, newModel.getStructures()[0].getName());
        Structure structure = newModel.getStructure(structureName);
        ReactionRule reactionRule = new ReactionRule(newModel, n, structure, reversible);
        // we ignore this, name and label are the same thing for now
        String reactionRuleLabel = reactionRuleElement.getAttributeValue(XMLTags.RbmReactionRuleLabelTag);
        // 
        // old style kinetics placed parameter values as attributes
        // look for attributes named ("MassActionKf","MassActionKr","MichaelisMentenKcat","MichaelisMentenKm","SaturableKs","SaturableVmax")
        String[] oldKineticsAttributes = new String[] { XMLTags.RbmMassActionKfAttrTag_DEPRECATED, XMLTags.RbmMassActionKrAttrTag_DEPRECATED, XMLTags.RbmMichaelisMentenKcatAttrTag_DEPRECATED, XMLTags.RbmMichaelisMentenKmAttrTag_DEPRECATED, XMLTags.RbmSaturableKsAttrTag_DEPRECATED, XMLTags.RbmSaturableVmaxAttrTag_DEPRECATED };
        boolean bOldKineticsFound = false;
        for (String oldKineticsAttribute : oldKineticsAttributes) {
            if (reactionRuleElement.getAttribute(oldKineticsAttribute) != null) {
                bOldKineticsFound = true;
            }
        }
        if (bOldKineticsFound) {
            readOldRbmKineticsAttributes(reactionRuleElement, reactionRule);
        } else {
            Element kineticsElement = reactionRuleElement.getChild(XMLTags.KineticsTag, vcNamespace);
            if (kineticsElement != null) {
                String kineticLawTypeString = kineticsElement.getAttributeValue(XMLTags.KineticsTypeAttrTag);
                RbmKineticLaw.RateLawType rateLawType = null;
                if (XMLTags.RbmKineticTypeMassAction.equals(kineticLawTypeString)) {
                    rateLawType = RateLawType.MassAction;
                } else if (XMLTags.RbmKineticTypeMichaelisMenten.equals(kineticLawTypeString)) {
                    rateLawType = RateLawType.MichaelisMenten;
                } else if (XMLTags.RbmKineticTypeSaturable.equals(kineticLawTypeString)) {
                    rateLawType = RateLawType.Saturable;
                } else {
                    throw new RuntimeException("unexpected rate law type " + kineticLawTypeString);
                }
                reactionRule.setKineticLaw(new RbmKineticLaw(reactionRule, rateLawType));
                List<Element> parameterElements = kineticsElement.getChildren(XMLTags.ParameterTag, vcNamespace);
                HashMap<String, ParameterRoleEnum> roleHash = new HashMap<String, ParameterContext.ParameterRoleEnum>();
                roleHash.put(XMLTags.RbmMassActionKfRole, RbmKineticLawParameterType.MassActionForwardRate);
                roleHash.put(XMLTags.RbmMassActionKrRole, RbmKineticLawParameterType.MassActionReverseRate);
                roleHash.put(XMLTags.RbmMichaelisMentenKcatRole, RbmKineticLawParameterType.MichaelisMentenKcat);
                roleHash.put(XMLTags.RbmMichaelisMentenKmRole, RbmKineticLawParameterType.MichaelisMentenKm);
                roleHash.put(XMLTags.RbmSaturableVmaxRole, RbmKineticLawParameterType.SaturableVmax);
                roleHash.put(XMLTags.RbmSaturableKsRole, RbmKineticLawParameterType.SaturableKs);
                roleHash.put(XMLTags.RbmUserDefinedRole, RbmKineticLawParameterType.UserDefined);
                HashSet<String> xmlRolesToIgnore = new HashSet<String>();
                xmlRolesToIgnore.add(XMLTags.RbmRuleRateRole);
                ParameterContext parameterContext = reactionRule.getKineticLaw().getParameterContext();
                readParameters(parameterElements, parameterContext, roleHash, RbmKineticLawParameterType.UserDefined, xmlRolesToIgnore, newModel);
            }
        }
        Element e1 = reactionRuleElement.getChild(XMLTags.RbmReactantPatternsListTag, vcNamespace);
        getRbmReactantPatternsList(e1, reactionRule, newModel);
        Element e2 = reactionRuleElement.getChild(XMLTags.RbmProductPatternsListTag, vcNamespace);
        getRbmProductPatternsList(e2, reactionRule, newModel);
        reactionRule.checkMatchConsistency();
        return reactionRule;
    } catch (PropertyVetoException | ExpressionException ex) {
        ex.printStackTrace(System.out);
        throw new RuntimeException("failed to parse kinetics for reaction rule '" + n + "': " + ex.getMessage(), ex);
    }
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) HashMap(java.util.HashMap) Element(org.jdom.Element) RbmKineticLaw(cbit.vcell.model.RbmKineticLaw) ExpressionException(cbit.vcell.parser.ExpressionException) PropertyVetoException(java.beans.PropertyVetoException) ParameterContext(cbit.vcell.mapping.ParameterContext) RateLawType(cbit.vcell.model.RbmKineticLaw.RateLawType) Structure(cbit.vcell.model.Structure) ParameterRoleEnum(cbit.vcell.mapping.ParameterContext.ParameterRoleEnum) HashSet(java.util.HashSet)

Aggregations

ParameterContext (cbit.vcell.mapping.ParameterContext)1 ParameterRoleEnum (cbit.vcell.mapping.ParameterContext.ParameterRoleEnum)1 RbmKineticLaw (cbit.vcell.model.RbmKineticLaw)1 RateLawType (cbit.vcell.model.RbmKineticLaw.RateLawType)1 ReactionRule (cbit.vcell.model.ReactionRule)1 Structure (cbit.vcell.model.Structure)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 PropertyVetoException (java.beans.PropertyVetoException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Element (org.jdom.Element)1