Search in sources :

Example 1 with LambdaFunction

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);
    }
}
Also used : Expression(cbit.vcell.parser.Expression) ListOf(org.sbml.jsbml.ListOf) ASTNode(org.sbml.jsbml.ASTNode) FunctionDefinition(org.sbml.jsbml.FunctionDefinition) LambdaFunction(cbit.vcell.parser.LambdaFunction) Vector(java.util.Vector) InteriorPoint(org.sbml.jsbml.ext.spatial.InteriorPoint) XMLStreamException(javax.xml.stream.XMLStreamException) SbmlException(org.vcell.sbml.SbmlException) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) SBMLException(org.sbml.jsbml.SBMLException) ModelPropertyVetoException(cbit.vcell.model.ModelPropertyVetoException) ExpressionException(cbit.vcell.parser.ExpressionException)

Aggregations

ModelPropertyVetoException (cbit.vcell.model.ModelPropertyVetoException)1 Expression (cbit.vcell.parser.Expression)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 LambdaFunction (cbit.vcell.parser.LambdaFunction)1 PropertyVetoException (java.beans.PropertyVetoException)1 IOException (java.io.IOException)1 Vector (java.util.Vector)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 ASTNode (org.sbml.jsbml.ASTNode)1 FunctionDefinition (org.sbml.jsbml.FunctionDefinition)1 ListOf (org.sbml.jsbml.ListOf)1 SBMLException (org.sbml.jsbml.SBMLException)1 InteriorPoint (org.sbml.jsbml.ext.spatial.InteriorPoint)1 SbmlException (org.vcell.sbml.SbmlException)1