use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class CellQuanVCTranslator method processVariables.
protected void processVariables() {
@SuppressWarnings("unchecked") List<Element> compElementList = sRoot.getChildren(CELLMLTags.COMPONENT, sNamespace);
Iterator<Element> compElementIterator = compElementList.iterator();
Element comp, var, varRef, temp;
String compName, varName, publicIn, privateIn, mangledName;
while (compElementIterator.hasNext()) {
comp = compElementIterator.next();
compName = comp.getAttributeValue(CELLMLTags.name, sAttNamespace);
@SuppressWarnings("unchecked") List<Element> varElementList = comp.getChildren(CELLMLTags.VARIABLE, sNamespace);
Iterator<Element> varElementIterator = varElementList.iterator();
// clear const and volVars vectors for each component
while (varElementIterator.hasNext()) {
var = varElementIterator.next();
publicIn = var.getAttributeValue(CELLMLTags.public_interface, sAttNamespace);
privateIn = var.getAttributeValue(CELLMLTags.private_interface, sAttNamespace);
if ((publicIn != null && publicIn.equals(CELLMLTags.inInterface)) || (privateIn != null && privateIn.equals(CELLMLTags.inInterface)))
continue;
varName = var.getAttributeValue(CELLMLTags.name, sAttNamespace);
mangledName = nm.getMangledName(compName, varName);
String uniqueVarName = getUniqueParamName(mangledName);
System.out.println("Vars: " + compName + "." + varName + " " + mangledName + " " + uniqueVarName);
// declare any differential free variables as VolumeVariable's
temp = getMathElementIdentifier(comp, varName, MathMLTags.DIFFERENTIAL);
try {
if (temp != null) {
// formula ignored at this point
Domain domain = null;
VolVariable volVar = new VolVariable(mangledName, domain);
varsHash.addVariable(volVar);
continue;
}
// any LHS variables of an eq operator are functions
temp = getMathElementIdentifier(comp, varName, MathMLTags.IDENTIFIER);
if (temp != null) {
Function fn = addFunction(temp, comp, mangledName);
varsHash.addVariable(fn);
continue;
}
// Handle delta variables as a special case function
varRef = getMatchingVarRef(comp, varName);
if (varRef != null) {
// 2 functions with same name?
Function rateFn = addRateFunction(varRef, compName, uniqueVarName);
varsHash.addVariable(rateFn);
continue;
}
// check if it is the time variable, if not add as a constant. No handling for a specific value for the time var.
if (!isTimeVar(varName)) {
Constant constant = new Constant(uniqueVarName, new Expression(getInitial(comp, varName)));
varsHash.addVariable(constant);
}
} catch (Exception e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error adding variable to variablesHash : " + e.getMessage());
}
}
// end iteration for VARIABLES
}
// add the variables from varsHash to mathDescription
try {
mathDescription.setAllVariables(varsHash.getAlphabeticallyOrderedVariables());
} catch (Exception e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error adding variables to mathDescription : " + e.getMessage());
}
}
use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class CellQuanVCTranslator method addFunction.
private Function addFunction(Element temp, Element comp, String mangledName) {
String expStr = null;
Expression exp = null;
Element parent = (Element) temp.getParent();
Element sibling = parent.getChild(MathMLTags.APPLY, mathns);
if (sibling == null) {
// check if its value is assigned to another variable (i.e. A = B)
@SuppressWarnings("unchecked") ArrayList<Element> list = new ArrayList<Element>(parent.getChildren(MathMLTags.IDENTIFIER, mathns));
if (list.size() == 2) {
expStr = (list.get(1)).getTextTrim();
}
if (expStr == null || expStr.length() == 0) {
expStr = parent.getChildText(MathMLTags.CONSTANT, mathns);
}
if (expStr == null || expStr.length() == 0) {
// check if 'piecewise'
sibling = parent.getChild(MathMLTags.PIECEWISE, mathns);
}
if (expStr != null) {
try {
exp = new Expression(expStr);
exp = processMathExp(comp, exp);
nl.mangleString(expStr);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
}
}
if (sibling != null) {
Element trimmedMath = new Element(CELLMLTags.MATH, mathns).addContent(sibling.detach());
fixMathMLBug(trimmedMath);
try {
exp = (new ExpressionMathMLParser(null)).fromMathML(trimmedMath);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
exp = processMathExp(comp, exp);
expStr = exp.infix();
nl.mangleString(expStr);
}
Domain domain = null;
return new Function(mangledName, exp, domain);
}
use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class SBPAXHMMIrrevLawBuilder method addKinetics.
public void addKinetics(KineticContext context) {
try {
ReactionStep reaction = context.getReaction();
HMM_IRRKinetics kinetics = new HMM_IRRKinetics((SimpleReaction) reaction);
NameScope modelScope = reaction.getModel().getNameScope();
ModelParameter kMichaelis = context.getParameter(SBOList.MICHAELIS_CONST_FORW);
if (kMichaelis != null) {
KineticsParameter kmParameter = kinetics.getKmParameter();
kmParameter.setExpression(new Expression(kMichaelis, modelScope));
kmParameter.setUnitDefinition(kMichaelis.getUnitDefinition());
}
ModelParameter kcat = context.getParameter(SBOList.CATALYTIC_RATE_CONST_FORW);
if (kcat != null && context.getCatalysts().size() == 1) {
KineticsParameter vmaxParameter = kinetics.getVmaxParameter();
Catalyst catalyst = context.getCatalysts().iterator().next();
vmaxParameter.setExpression(Expression.mult(new Expression(kcat, modelScope), new Expression(catalyst.getSpeciesContext(), modelScope)));
// vmaxParameter.setUnitDefinition(vMax.getUnitDefinition());
} else {
ModelParameter vMax = context.getParameter(SBOList.MAXIMAL_VELOCITY_FORW);
if (vMax != null) {
KineticsParameter vmaxParameter = kinetics.getVmaxParameter();
vmaxParameter.setExpression(new Expression(vMax, modelScope));
vmaxParameter.setUnitDefinition(vMax.getUnitDefinition());
}
}
} catch (ExpressionException e) {
e.printStackTrace();
}
}
use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class SBPAXKineticsExtractor method setKForwardParam.
private static void setKForwardParam(ReactionStep reaction, SBOParam kForward, Kinetics kinetics) throws ExpressionException, PropertyVetoException {
if (kForward != null) {
KineticsParameter fwdParam = ((MassActionKinetics) kinetics).getForwardRateParameter();
kinetics.setParameterValue(fwdParam, new Expression(kForward.getNumber()));
String unitF = SBOParam.formatUnit(kForward.getUnit());
VCUnitDefinition fwdUnit = reaction.getModel().getUnitSystem().getInstance(unitF);
fwdParam.setUnitDefinition(fwdUnit);
}
}
use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class SBPAXKineticsExtractor method setKReverseParam.
private static void setKReverseParam(ReactionStep reaction, SBOParam kReverse, Kinetics kinetics) throws ExpressionException, PropertyVetoException {
if (kReverse != null) {
KineticsParameter revParam = ((MassActionKinetics) kinetics).getReverseRateParameter();
kinetics.setParameterValue(revParam, new Expression(kReverse.getNumber()));
String unitR = SBOParam.formatUnit(kReverse.getUnit());
VCUnitDefinition revUnit = reaction.getModel().getUnitSystem().getInstance(unitR);
revParam.setUnitDefinition(revUnit);
}
}
Aggregations