use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class XmlReader method getVarIniCount.
/**
* This method return a VarIniCondition object from a XML element.
* Creation date: (7/24/2006 5:26:05 PM)
* @return cbit.vcell.math.VarIniCondition
* @param param org.jdom.Element
* @exception cbit.vcell.xml.XmlParseException The exception description.
*/
private VarIniCondition getVarIniCount(Element param, MathDescription md) throws XmlParseException, MathException, ExpressionException {
// retrieve values
Expression exp = unMangleExpression(param.getText());
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
Variable var = md.getVariable(name);
if (var == null) {
throw new MathFormatException("variable " + name + " not defined");
}
if (!(var instanceof StochVolVariable)) {
throw new MathFormatException("variable " + name + " not a Stochastic Volume Variable");
}
try {
VarIniCondition varIni = new VarIniCount(var, exp);
return varIni;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of cbit.vcell.parser.ExpressionException 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.ExpressionException 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.ExpressionException in project vcell by virtualcell.
the class RefinementRoi method readVCML.
private void readVCML(CommentStringTokenizer tokens) throws DataAccessException {
try {
String token = tokens.nextToken();
if (token.equalsIgnoreCase(VCML.RefinementRoi)) {
token = tokens.nextToken();
if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
throw new DataAccessException("unexpected token " + token + " expecting " + VCML.BeginBlock);
}
}
while (tokens.hasMoreTokens()) {
token = tokens.nextToken();
if (token.equalsIgnoreCase(VCML.EndBlock)) {
break;
} else if (token.equalsIgnoreCase(VCML.RefinementRoiType)) {
token = tokens.nextToken();
type = RoiType.valueOf(token);
} else if (token.equalsIgnoreCase(VCML.Level)) {
token = tokens.nextToken();
level = Integer.parseInt(token);
} else if (token.equalsIgnoreCase(VCML.TagsGrow)) {
// backward compatible
} else if (token.equalsIgnoreCase(VCML.ROIExpression)) {
token = tokens.readToSemicolon();
try {
setRoiExpression(token);
} catch (ExpressionException e) {
System.err.println("Invalid " + VCML.ROIExpression + ": " + token);
}
} else {
throw new DataAccessException("unexpected identifier " + token);
}
}
} catch (Throwable e) {
e.printStackTrace(System.out);
throw new DataAccessException("line #" + (tokens.lineIndex() + 1) + " Exception: " + e.getMessage());
}
}
use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class SpeciesContextSpec method convertParticlesToConcentration.
public Expression convertParticlesToConcentration(Expression iniParticles) throws ExpressionException, MappingException {
Expression iniConcentrationExpr = null;
Structure structure = getSpeciesContext().getStructure();
double structSize = computeStructureSize();
if (structure instanceof Membrane) {
// iniConcentration(molecules/um2) = particles/size(um2)
try {
iniConcentrationExpr = new Expression((iniParticles.evaluateConstant() * 1.0) / structSize);
} catch (ExpressionException e) {
iniConcentrationExpr = Expression.div(iniParticles, new Expression(structSize)).flatten();
}
} else {
// convert concentration(particles/volume) to number of particles
// particles = [iniParticles(uM)/size(um3)]*KMOLE
// @Note : 'kMole' variable here is used only as a var name, it does not represent the previously known ReservedSymbol KMOLE.
ModelUnitSystem modelUnitSystem = getSimulationContext().getModel().getUnitSystem();
VCUnitDefinition stochasticToVolSubstance = modelUnitSystem.getVolumeSubstanceUnit().divideBy(modelUnitSystem.getStochasticSubstanceUnit());
double stochasticToVolSubstanceScale = stochasticToVolSubstance.getDimensionlessScale().doubleValue();
try {
iniConcentrationExpr = new Expression((iniParticles.evaluateConstant() * stochasticToVolSubstanceScale / structSize));
} catch (ExpressionException e) {
Expression numeratorExpr = Expression.mult(iniParticles, new Expression(stochasticToVolSubstanceScale));
Expression denominatorExpr = new Expression(structSize);
iniConcentrationExpr = Expression.div(numeratorExpr, denominatorExpr).flatten();
}
}
return iniConcentrationExpr;
}
Aggregations