use of cbit.vcell.parser.LambdaFunction in project vcell by virtualcell.
the class SBMLImporter method addFunctionDefinitions.
protected void addFunctionDefinitions() {
if (sbmlModel == null) {
throw new SBMLImportException("SBML model is NULL");
}
ListOf listofFunctionDefinitions = sbmlModel.getListOfFunctionDefinitions();
if (listofFunctionDefinitions == null) {
System.out.println("No Function Definitions");
return;
}
// The function definitions contain lambda function definition.
// Each lambda function has a name, (list of) argument(s), function body
// which is represented as a math element.
lambdaFunctions = new LambdaFunction[(int) sbmlModel.getNumFunctionDefinitions()];
try {
for (int i = 0; i < sbmlModel.getNumFunctionDefinitions(); i++) {
FunctionDefinition fnDefn = (FunctionDefinition) listofFunctionDefinitions.get(i);
String functionName = new String(fnDefn.getId());
ASTNode math = null;
Vector<String> argsVector = new Vector<String>();
String[] functionArgs = null;
if (fnDefn.isSetMath()) {
math = fnDefn.getMath();
// Function body.
if (math.getNumChildren() == 0) {
System.out.println("(no function body defined)");
continue;
}
// children
for (int j = 0; j < math.getNumChildren() - 1; ++j) {
argsVector.addElement(new String(math.getChild(j).getName()));
}
functionArgs = argsVector.toArray(new String[0]);
math = math.getChild(math.getNumChildren() - 1);
// formula = libsbml.formulaToString(math);
Expression fnExpr = getExpressionFromFormula(math);
lambdaFunctions[i] = new LambdaFunction(functionName, fnExpr, functionArgs);
}
}
} catch (Exception e) {
e.printStackTrace(System.out);
throw new SBMLImportException("Error adding Lambda function" + e.getMessage(), e);
}
}
Aggregations