Hi Everyone,
I found a solution for parsing the bond orders.
Basically I had to introduce another <templateList> with three <template>s each matching either a line with three, two or one column(s) and containing just a single record for just such a line. (commit [1])
Luckily it's only the last line that can have less than three columns.
But now I have a new problem:
I want to create a new transform in org.xmlcml.cml.converters.text.TransformElement to extract the lower triangle from a matrix that otherwise would contain redundant information (e.g. inter-atomic distances or force-constant matrix)
<transform process='createTriangularMatrix' xpath='.' from='cml:array' dictRef='x:y' />
should convert:
<array dataType='xsd:double' size='5'>0.0 0.1 0.2 0.3 0.4</array>
<array dataType='xsd:double' size='5'>1.0 1.1 1.2 1.3 1.4</array>
<array dataType='xsd:double' size='5'>2.0 2.1 2.2 2.3 2.4</array>
<array dataType='xsd:double' size='5'>3.0 3.1 3.2 3.3 3.4</array>
<array dataType='xsd:double' size='5'>4.0 4.1 4.2 4.3 4.4</array>
</list>
to:
<array dictRef='x:y' dataType='xsd:double' size='15'>0.0 1.0 1.1 2.0 2.1 2.2 3.0 3.1 3.2 3.3 4.0 4.1 4.2 4.3 4.4</array>
</list>
So far I have followed the implementation of createVector3() but when I iterate over the array-elements inside the lists and want to cast them to CMLArray I get:
ClassCastException: nu.xom.Element cannot be cast to org.xmlcml.cml.element.CMLArray
(Please see my code below.)
I would really appreciate if someone could give me a hint on how to do that.
Thanks,
Oliver
private void createTriangularMatrix() {
assertRequired(DICT_REF, dictRef);
assertRequired(FROM, from);
assertRequired(XPATH, xpath);
List<Node> nodeList = getXpathQueryResults();
for (Node node : nodeList) { // all cml:list nodes
Element element = (Element)node;
Nodes arrayNodes = TransformElement.queryUsingNamespaces(element, from);
CMLArray fullArray = new CMLArray("xsd:double");
Node node0 = null;
for (int j = 0; j < arrayNodes.size(); j++)
{
// this fails with: java.lang.ClassCastException: nu.xom.Element cannot be cast to org.xmlcml.cml.element.CMLArray
CMLArray lineArray = (CMLArray) arrayNodes.get(j);
if (lineArray.getArraySize() >= j){
fullArray = fullArray.plus(lineArray.createSubArray(0, j ));
} else {
CMLUtil.debug(element, "PAR");
throw new RuntimeException("Lower Triangle of matrix cannot be extracted.");
}
if (j == 0) {
node0 = lineArray;
} else {
lineArray.detach();
}
} // for all cml:arrays in current cml:list node
fullArray.setDictRef(dictRef);
node0.getParent().replaceChild(node0, fullArray);
}// for all cml:list nodes
}