BiVeS – CellML parser

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// parse CellML document
TreeDocument tree = new TreeDocument (builder.parse (new FileInputStream (FILE)), new XyWeighter (), FILE.toURI ());
CellMLDocument doc = new CellMLDocument (tree);

// get model
CellMLModel model = doc.getModel ();

// get all components and a map: `name` -> `component`
HashMap<String, CellMLComponent> components = model.getComponents ();

// get all variables of the component with the name COMPONENT
// also return a map: `name` -> `variable`
HashMap<String, CellMLVariable> variables = components.get ("COMPONENT").getVariables ();

// get the variable with name VAR in component COMPONENT
CellMLVariable var = variables.get ("VAR");

// trace the interface connections back to the root variable
CellMLVariable rootVar = var.getRootVariable ();

// get the encapsulation hierarchy network
CellMLHierarchyNetwork hierarchy = model.getHierarchy ().getHierarchyNetwork ("encapsulation", "");

// get the hierarchy node of component COMPONENT
CellMLHierarchyNode hNode = getNode (components.get ("COMPONENT"));

// get its parent component in terms of encapsulation
CellMLHierarchyNode hNodeParent = hNode.getParent ();
// and its children
Vector<CellMLHierarchyNode> hNodeKids = hNode.getChildren ();

See also CellML:Reading and CellML:Flattening from the BiVeS-CellML module.