use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class XmlReader method getSpeciesContextSpecs.
/**
* This method returns a SpeciesContextSpec object from a XML representation.
* Creation date: (4/26/2001 4:14:01 PM)
* @return cbit.vcell.mapping.SpeciesContextSpec
* @param param org.jdom.Element
*/
private void getSpeciesContextSpecs(List<Element> scsChildren, ReactionContext rxnContext, Model model) throws XmlParseException {
for (int i = 0; i < scsChildren.size(); i++) {
Element scsElement = scsChildren.get(i);
SpeciesContextSpec specspec = null;
// Get Atributes
String speccontname = unMangle(scsElement.getAttributeValue(XMLTags.SpeciesContextRefAttrTag));
boolean constant = Boolean.valueOf(scsElement.getAttributeValue(XMLTags.ForceConstantAttrTag)).booleanValue();
// boolean enabledif = Boolean.valueOf(scsElement.getAttributeValue(XMLTags.EnableDiffusionAttrTag)).booleanValue();
String spatialStr = scsElement.getAttributeValue(XMLTags.SpatialAttrTag);
Boolean spatial = null;
if (spatialStr != null) {
spatial = Boolean.valueOf(spatialStr);
}
String bWellMixedStr = scsElement.getAttributeValue(XMLTags.WellMixedAttrTag);
Boolean bWellMixed = null;
if (bWellMixedStr != null) {
bWellMixed = Boolean.valueOf(bWellMixedStr);
}
String bForceContinuousStr = scsElement.getAttributeValue(XMLTags.ForceContinuousAttrTag);
Boolean bForceContinuous = null;
if (bForceContinuousStr != null) {
bForceContinuous = Boolean.valueOf(bForceContinuousStr);
}
// Retrieve reference
SpeciesContext specref = model.getSpeciesContext(speccontname);
if (specref == null) {
throw new XmlParseException("The SpeciesContext " + speccontname + " refrence could not be resolved!");
}
// get SpeciesContextSpec from reactionContext & specRef
specspec = rxnContext.getSpeciesContextSpec(specref);
// set attributes
specspec.setConstant(constant);
// }
if (spatial != null) {
specspec.setWellMixed(!spatial);
}
if (bWellMixed != null) {
specspec.setWellMixed(bWellMixed);
}
if (bForceContinuous != null) {
specspec.setForceContinuous(bForceContinuous);
}
// set expressions
// Initial
String tempCon = scsElement.getChildText(XMLTags.InitialConcentrationTag, vcNamespace);
String tempAmt = scsElement.getChildText(XMLTags.InitialAmountTag, vcNamespace);
String temp = scsElement.getChildText(XMLTags.InitialTag, vcNamespace);
try {
if (// old model
temp != null) {
Expression expression = unMangleExpression(temp);
specspec.getInitialConcentrationParameter().setExpression(expression);
specspec.getInitialCountParameter().setExpression(null);
} else // new model
{
if (// use concentration as initial condition
tempCon != null) {
Expression expression = unMangleExpression(tempCon);
specspec.getInitialConcentrationParameter().setExpression(expression);
specspec.getInitialCountParameter().setExpression(null);
} else if (// use number of particles as initial condition
tempAmt != null) {
Expression expression = unMangleExpression(tempAmt);
specspec.getInitialCountParameter().setExpression(expression);
specspec.getInitialConcentrationParameter().setExpression(null);
} else {
throw new XmlParseException("Unrecognizable initial condition when parsing VCML file.");
}
}
// Expression expression = unMangleExpression(temp);
// specspec.getInitialConditionParameter().setExpression(expression);
} catch (ExpressionException e) {
e.printStackTrace();
throw new XmlParseException("An expressionException was fired when setting the InitilaconditionExpression " + temp + ", for a SpeciesContextSpec!", e);
}
// diffusion (if there is no diffusion information skip it)
Element xmlDiffusionElement = scsElement.getChild(XMLTags.DiffusionTag, vcNamespace);
if (xmlDiffusionElement != null) {
temp = xmlDiffusionElement.getText();
try {
Expression expression = unMangleExpression(temp);
specspec.getDiffusionParameter().setExpression(expression);
} catch (ExpressionException e) {
e.printStackTrace();
throw new XmlParseException("An ExpressionException was fired when setting the diffusionExpression " + temp + " to a SpeciesContextSpec!", e);
}
}
// Get Boundaries if any
Element tempElement = scsElement.getChild(XMLTags.BoundariesTag, vcNamespace);
if (tempElement != null) {
try {
// Xm
temp = tempElement.getAttributeValue(XMLTags.BoundaryAttrValueXm);
if (temp != null) {
specspec.getBoundaryXmParameter().setExpression(unMangleExpression(temp));
}
// Xp
temp = tempElement.getAttributeValue(XMLTags.BoundaryAttrValueXp);
if (temp != null) {
specspec.getBoundaryXpParameter().setExpression(unMangleExpression(temp));
}
// Ym
temp = tempElement.getAttributeValue(XMLTags.BoundaryAttrValueYm);
if (temp != null) {
specspec.getBoundaryYmParameter().setExpression(unMangleExpression(temp));
}
// Yp
temp = tempElement.getAttributeValue(XMLTags.BoundaryAttrValueYp);
if (temp != null) {
specspec.getBoundaryYpParameter().setExpression(unMangleExpression(temp));
}
// Zm
temp = tempElement.getAttributeValue(XMLTags.BoundaryAttrValueZm);
if (temp != null) {
specspec.getBoundaryZmParameter().setExpression(unMangleExpression(temp));
}
// Zp
temp = tempElement.getAttributeValue(XMLTags.BoundaryAttrValueZp);
if (temp != null) {
specspec.getBoundaryZpParameter().setExpression(unMangleExpression(temp));
}
} catch (ExpressionException e) {
e.printStackTrace();
throw new XmlParseException("An ExpressionException was fired when Setting the boundary Expression: " + unMangle(temp), e);
}
}
// Get Velocities if any
Element velocityE = scsElement.getChild(XMLTags.VelocityTag, vcNamespace);
if (velocityE != null) {
String tempStr = null;
boolean dummyVel = true;
try {
tempStr = velocityE.getAttributeValue(XMLTags.XAttrTag);
if (tempStr != null) {
// all velocity dimensions are optional.
specspec.getVelocityXParameter().setExpression(unMangleExpression(tempStr));
if (dummyVel) {
dummyVel = false;
}
}
tempStr = velocityE.getAttributeValue(XMLTags.YAttrTag);
if (tempStr != null) {
specspec.getVelocityYParameter().setExpression(unMangleExpression(tempStr));
if (dummyVel) {
dummyVel = false;
}
}
tempStr = velocityE.getAttributeValue(XMLTags.ZAttrTag);
if (tempStr != null) {
specspec.getVelocityZParameter().setExpression(unMangleExpression(tempStr));
if (dummyVel) {
dummyVel = false;
}
}
} catch (ExpressionException e) {
e.printStackTrace();
throw new XmlParseException("Error setting Velocity parameter for '" + specspec.getSpeciesContext().getName(), e);
}
if (dummyVel) {
throw new XmlParseException("Void Velocity element found under PDE for: " + specspec.getSpeciesContext().getName());
}
}
}
}
use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class XmlReader method getBioEvents.
public BioEvent[] getBioEvents(SimulationContext simContext, Element bioEventsElement) throws XmlParseException {
Iterator<Element> bioEventsIterator = bioEventsElement.getChildren(XMLTags.BioEventTag, vcNamespace).iterator();
Vector<BioEvent> bioEventsVector = new Vector<BioEvent>();
while (bioEventsIterator.hasNext()) {
Element bEventElement = (Element) bioEventsIterator.next();
BioEvent newBioEvent = null;
String name = unMangle(bEventElement.getAttributeValue(XMLTags.NameAttrTag));
Element triggerElement = bEventElement.getChild(XMLTags.TriggerTag, vcNamespace);
if (triggerElement != null && triggerElement.getText().length() > 0) {
//
// read legacy VCell 5.3 style trigger and delay elements
//
// <Trigger>(t>3.0)</Trigger>
// <Delay UseValuesFromTriggerTime="true">3.0</Delay> [optional]
//
Expression triggerExpression = unMangleExpression(triggerElement.getText());
// read <Delay>
Expression delayDurationExpression = null;
boolean useValuesFromTriggerTime = true;
Element delayElement = bEventElement.getChild(XMLTags.DelayTag, vcNamespace);
if (delayElement != null) {
useValuesFromTriggerTime = Boolean.valueOf(delayElement.getAttributeValue(XMLTags.UseValuesFromTriggerTimeAttrTag)).booleanValue();
delayDurationExpression = unMangleExpression((delayElement.getText()));
}
newBioEvent = new BioEvent(name, TriggerType.GeneralTrigger, useValuesFromTriggerTime, simContext);
try {
newBioEvent.setParameterValue(BioEventParameterType.GeneralTriggerFunction, triggerExpression);
if (delayDurationExpression != null) {
newBioEvent.setParameterValue(BioEventParameterType.TriggerDelay, delayDurationExpression);
}
} catch (ExpressionBindingException | PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("failed to read trigger or delay expressions in bioEvent " + name + ": " + e.getMessage(), e);
}
} else if (triggerElement != null && triggerElement.getText().length() == 0) {
//
// read legacy first-pass VCell 5.4 style trigger and delay elements
//
// <Trigger>
// <TriggerParameters triggerClass="TriggerGeneral">
// (t > 500.0)
// </TriggerParameters>
// </Trigger>
// <Delay UseValuesFromTriggerTime="true">3.0</Delay> [optional]
//
final String TriggerParametersTag = "TriggerParameters";
final String TriggerClassAttrTag = "triggerClass";
final String TriggerClassAttrValue_TriggerGeneral = "TriggerGeneral";
Element triggerParametersElement = triggerElement.getChild(TriggerParametersTag, vcNamespace);
Expression triggerExpression = null;
String triggerClass = triggerParametersElement.getAttributeValue(TriggerClassAttrTag);
if (triggerClass.equals(TriggerClassAttrValue_TriggerGeneral)) {
triggerExpression = unMangleExpression(triggerParametersElement.getText());
} else {
// not general trigger (just make it never happen, user will have to edit "t > -1")
triggerExpression = Expression.relational(">", new Expression(simContext.getModel().getTIME(), simContext.getModel().getNameScope()), new Expression(-1.0));
}
// read <Delay>
Expression delayDurationExpression = null;
boolean useValuesFromTriggerTime = true;
Element delayElement = bEventElement.getChild(XMLTags.DelayTag, vcNamespace);
if (delayElement != null) {
useValuesFromTriggerTime = Boolean.valueOf(delayElement.getAttributeValue(XMLTags.UseValuesFromTriggerTimeAttrTag)).booleanValue();
delayDurationExpression = unMangleExpression((delayElement.getText()));
}
newBioEvent = new BioEvent(name, TriggerType.GeneralTrigger, useValuesFromTriggerTime, simContext);
try {
newBioEvent.setParameterValue(BioEventParameterType.GeneralTriggerFunction, triggerExpression);
if (delayDurationExpression != null) {
newBioEvent.setParameterValue(BioEventParameterType.TriggerDelay, delayDurationExpression);
}
} catch (ExpressionBindingException | PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("failed to read trigger or delay expressions in bioEvent " + name + ": " + e.getMessage(), e);
}
} else {
//
// VCell 5.4 style bioevent parameters
//
//
TriggerType triggerType = TriggerType.fromXmlName(bEventElement.getAttributeValue(XMLTags.BioEventTriggerTypeAttrTag));
boolean bUseValuesFromTriggerTime = Boolean.parseBoolean(bEventElement.getAttributeValue(XMLTags.UseValuesFromTriggerTimeAttrTag));
newBioEvent = new BioEvent(name, triggerType, bUseValuesFromTriggerTime, simContext);
Iterator<Element> paramElementIter = bEventElement.getChildren(XMLTags.ParameterTag, vcNamespace).iterator();
ArrayList<LocalParameter> parameters = new ArrayList<LocalParameter>();
boolean bHasGeneralTriggerParam = false;
while (paramElementIter.hasNext()) {
Element paramElement = paramElementIter.next();
// Get parameter attributes
String paramName = paramElement.getAttributeValue(XMLTags.NameAttrTag);
Expression exp = unMangleExpression(paramElement.getText());
String roleStr = paramElement.getAttributeValue(XMLTags.ParamRoleAttrTag);
BioEventParameterType parameterType = BioEventParameterType.fromRoleXmlName(roleStr);
if (parameterType == BioEventParameterType.GeneralTriggerFunction) {
bHasGeneralTriggerParam = true;
}
VCUnitDefinition unit = simContext.getModel().getUnitSystem().getInstance_TBD();
String unitSymbol = paramElement.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
if (unitSymbol != null) {
unit = simContext.getModel().getUnitSystem().getInstance(unitSymbol);
}
parameters.add(newBioEvent.createNewParameter(paramName, parameterType, exp, unit));
}
if (!bHasGeneralTriggerParam) {
parameters.add(newBioEvent.createNewParameter(BioEventParameterType.GeneralTriggerFunction.getDefaultName(), BioEventParameterType.GeneralTriggerFunction, // computed as needed
null, simContext.getModel().getUnitSystem().getInstance_DIMENSIONLESS()));
}
try {
newBioEvent.setParameters(parameters.toArray(new LocalParameter[0]));
} catch (PropertyVetoException | ExpressionBindingException e) {
e.printStackTrace();
throw new XmlParseException("failed to read parameters in bioEvent " + name + ": " + e.getMessage(), e);
}
}
ArrayList<BioEvent.EventAssignment> eventAssignmentList = new ArrayList<BioEvent.EventAssignment>();
Iterator<Element> iter = bEventElement.getChildren(XMLTags.EventAssignmentTag, vcNamespace).iterator();
while (iter.hasNext()) {
Element eventAssignmentElement = iter.next();
try {
String varname = eventAssignmentElement.getAttributeValue(XMLTags.EventAssignmentVariableAttrTag);
Expression assignExp = unMangleExpression(eventAssignmentElement.getText());
SymbolTableEntry target = simContext.getEntry(varname);
BioEvent.EventAssignment eventAssignment = newBioEvent.new EventAssignment(target, assignExp);
eventAssignmentList.add(eventAssignment);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e);
}
}
try {
newBioEvent.setEventAssignmentsList(eventAssignmentList);
} catch (PropertyVetoException e1) {
e1.printStackTrace(System.out);
throw new XmlParseException(e1);
}
try {
newBioEvent.bind();
} catch (ExpressionBindingException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e);
}
bioEventsVector.add(newBioEvent);
}
return ((BioEvent[]) BeanUtils.getArray(bioEventsVector, BioEvent.class));
}
use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class XmlReader method readParameters.
private void readParameters(List<Element> parameterElements, ParameterContext parameterContext, HashMap<String, ParameterRoleEnum> roleHash, ParameterRoleEnum userDefinedRole, HashSet<String> xmlRolesTagsToIgnore, Model model) throws XmlParseException {
String contextName = parameterContext.getNameScope().getName();
try {
//
// prepopulate varHash with reserved symbols
//
VariableHash varHash = new VariableHash();
addResevedSymbols(varHash, model);
//
for (Element xmlParam : parameterElements) {
String parsedParamName = unMangle(xmlParam.getAttributeValue(XMLTags.NameAttrTag));
String parsedRoleString = xmlParam.getAttributeValue(XMLTags.ParamRoleAttrTag);
String parsedExpressionString = xmlParam.getText();
//
if (xmlRolesTagsToIgnore.contains(parsedRoleString)) {
varHash.removeVariable(parsedParamName);
continue;
}
Expression paramExp = null;
if (parsedExpressionString.trim().length() > 0) {
paramExp = unMangleExpression(parsedExpressionString);
}
if (varHash.getVariable(parsedParamName) == null) {
Domain domain = null;
varHash.addVariable(new Function(parsedParamName, paramExp, domain));
} else {
if (model.getReservedSymbolByName(parsedParamName) != null) {
varHash.removeVariable(parsedParamName);
Domain domain = null;
varHash.addVariable(new Function(parsedParamName, paramExp, domain));
}
}
//
// get the parameter for this xml role string
//
ParameterRoleEnum paramRole = roleHash.get(parsedRoleString);
if (paramRole == null) {
throw new XmlParseException("parameter '" + parsedParamName + "' has unexpected role '" + parsedRoleString + "' in '" + contextName + "'");
}
//
if (paramRole != userDefinedRole) {
LocalParameter paramWithSameRole = parameterContext.getLocalParameterFromRole(paramRole);
if (paramWithSameRole == null) {
throw new XmlParseException("can't find parameter with role '" + parsedRoleString + "' in '" + contextName + "'");
}
//
if (!paramWithSameRole.getName().equals(parsedParamName)) {
//
// first rename other parameters with same name
//
LocalParameter paramWithSameNameButDifferentRole = parameterContext.getLocalParameterFromName(parsedParamName);
if (paramWithSameNameButDifferentRole != null) {
//
// find available name
//
int n = 0;
String newName = parsedParamName + "_" + n++;
while (parameterContext.getEntry(newName) != null) {
newName = parsedParamName + "_" + n++;
}
parameterContext.renameLocalParameter(parsedParamName, newName);
}
//
// then rename parameter with correct role
//
parameterContext.renameLocalParameter(paramWithSameRole.getName(), parsedParamName);
}
}
}
//
// create unresolved parameters for all unresolved symbols
//
String unresolvedSymbol = varHash.getFirstUnresolvedSymbol();
while (unresolvedSymbol != null) {
try {
Domain domain = null;
// will turn into an UnresolvedParameter.
varHash.addVariable(new Function(unresolvedSymbol, new Expression(0.0), domain));
} catch (MathException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e.getMessage());
}
parameterContext.addUnresolvedParameter(unresolvedSymbol);
unresolvedSymbol = varHash.getFirstUnresolvedSymbol();
}
//
// in topological order, add parameters to model (getting units also).
// note that all pre-defined parameters already have the correct names
// here we set expressions on pre-defined parameters and add user-defined parameters
//
Variable[] sortedVariables = varHash.getTopologicallyReorderedVariables();
ModelUnitSystem modelUnitSystem = model.getUnitSystem();
for (int i = sortedVariables.length - 1; i >= 0; i--) {
if (sortedVariables[i] instanceof Function) {
Function paramFunction = (Function) sortedVariables[i];
Element xmlParam = null;
for (int j = 0; j < parameterElements.size(); j++) {
Element tempParam = (Element) parameterElements.get(j);
if (paramFunction.getName().equals(unMangle(tempParam.getAttributeValue(XMLTags.NameAttrTag)))) {
xmlParam = tempParam;
break;
}
}
if (xmlParam == null) {
// must have been an unresolved parameter
continue;
}
String symbol = xmlParam.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
VCUnitDefinition unit = null;
if (symbol != null) {
unit = modelUnitSystem.getInstance(symbol);
}
LocalParameter tempParam = parameterContext.getLocalParameterFromName(paramFunction.getName());
if (tempParam == null) {
tempParam = parameterContext.addLocalParameter(paramFunction.getName(), new Expression(0.0), userDefinedRole, unit, userDefinedRole.getDescription());
parameterContext.setParameterValue(tempParam, paramFunction.getExpression(), true);
} else {
if (tempParam.getExpression() != null) {
// if the expression is null, it should remain null.
parameterContext.setParameterValue(tempParam, paramFunction.getExpression(), true);
}
tempParam.setUnitDefinition(unit);
}
}
}
} catch (PropertyVetoException | ExpressionException | MathException e) {
e.printStackTrace(System.out);
throw new XmlParseException("Exception while setting parameters for '" + contextName + "': " + e.getMessage(), e);
}
}
use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class XmlReader method getParticleJumpProcess.
private ParticleJumpProcess getParticleJumpProcess(Element param, MathDescription md) throws XmlParseException {
// name
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
ProcessSymmetryFactor processSymmetryFactor = null;
Attribute symmetryFactorAttr = param.getAttribute(XMLTags.ProcessSymmetryFactorAttrTag);
if (symmetryFactorAttr != null) {
processSymmetryFactor = new ProcessSymmetryFactor(Double.parseDouble(symmetryFactorAttr.getValue()));
}
// selected particle
List<ParticleVariable> varList = new ArrayList<ParticleVariable>();
Iterator<Element> iterator = param.getChildren(XMLTags.SelectedParticleTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element tempelement = (Element) iterator.next();
String varname = unMangle(tempelement.getAttributeValue(XMLTags.NameAttrTag));
Variable var = md.getVariable(varname);
if (!(var instanceof ParticleVariable)) {
throw new XmlParseException("Not a ParticleVariable in ParticleJumpProcess.");
}
varList.add((ParticleVariable) var);
}
// probability rate
JumpProcessRateDefinition jprd = null;
// for old models
Element pb = param.getChild(XMLTags.ParticleProbabilityRateTag, vcNamespace);
if (pb != null) {
Expression exp = unMangleExpression(pb.getText());
jprd = new MacroscopicRateConstant(exp);
} else // for new models
{
pb = param.getChild(XMLTags.MacroscopicRateConstantTag, vcNamespace);
if (// jump process rate defined by macroscopic rate constant
pb != null) {
Expression exp = unMangleExpression(pb.getText());
jprd = new MacroscopicRateConstant(exp);
} else // jump process rate defined by binding radius
{
pb = param.getChild(XMLTags.InteractionRadiusTag, vcNamespace);
if (pb != null) {
Expression exp = unMangleExpression(pb.getText());
jprd = new InteractionRadius(exp);
}
}
}
// add actions
List<Action> actionList = new ArrayList<Action>();
iterator = param.getChildren(XMLTags.ActionTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element tempelement = (Element) iterator.next();
try {
actionList.add(getAction(tempelement, md));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException(e);
} catch (ExpressionException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
ParticleJumpProcess jump = new ParticleJumpProcess(name, varList, jprd, actionList, processSymmetryFactor);
return jump;
}
use of cbit.vcell.parser.ExpressionException 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);
}
}
Aggregations