use of org.sbml.jsbml.FunctionDefinition in project vcell by virtualcell.
the class SBMLImporter method addFunctionDefinitions.
private void addFunctionDefinitions() {
if (sbmlModel == null) {
throw new SBMLImportException("SBML model is NULL");
}
ListOf<FunctionDefinition> 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>();
Vector<String> secureArgsVector = new Vector<>();
String[] functionArgs = null;
if (fnDefn.isSetMath()) {
math = fnDefn.getMath();
// Function body.
if (math.getNumChildren() == 0) {
System.out.println("(no function body defined)");
continue;
}
// Note that lambda function always should have at least 2 children
for (int j = 0; j < math.getNumChildren() - 1; ++j) {
String baseName = new String(math.getChild(j).getName());
argsVector.addElement(baseName);
secureArgsVector.addElement(baseName + "_" + functionName + FormalArgumentSuffix);
}
functionArgs = secureArgsVector.toArray(new String[0]);
math = math.getChild(math.getNumChildren() - 1);
// formula = libsbml.formulaToString(math);
Expression fnExpr = getExpressionFromFormula(math);
for (int j = 0; j < argsVector.size(); j++) {
fnExpr.substituteInPlace(new Expression(argsVector.get(j)), new Expression(secureArgsVector.get(j)));
}
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