Hi all,
I encountered some problems searching for the shortest path between two
atoms in a molecule using the method
getShortestPath(IAtomContainer atomContainer, IAtom start, IAtom end)
in the class PathTools. I am using CDK 20060714, but I compared this
method to that in a more recent version (CDK 20070422), and as they are
nearly the same that shouldn't be the problem.
I tested this method with a very simple molecule, decane, built in
ChemDraw and stored in an MDL Mol File as follows:
-------------------------------
shortest_path_test.mol
ChemDraw08220712522D
10 9 0 0 0 0 0 0 0 0999 V2000
-3.2151 -0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-2.5006 0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.7862 -0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.0717 0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.3572 -0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.3572 0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.0717 -0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.7862 0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.5006 -0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
3.2151 0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1 2 1 0
2 3 1 0
3 4 1 0
4 5 1 0
5 6 1 0
6 7 1 0
7 8 1 0
8 9 1 0
9 10 1 0
M END
-------------------------------
All I do is the following:
-------------------------------
try {
MDLReader reader = new MDLReader(new
FileInputStream("data/molecules/shortest_path_test.mol"));
IMolecule testMolecule = new Molecule();
reader.read(testMolecule);
PathTools pTools = new PathTools();
ArrayList<IAtom> path = (ArrayList)
pTools.getShortestPath(testMolecule, testMolecule.getAtomAt(0),
testMolecule.getAtomAt(9));
System.out.println("length" + path.size());
} catch (Exception ex) {
ex.printStackTrace();
}
-------------------------------
This snipped of code does exactly what it should do - the length of the
path found is 10. But if I change the start node and start the search of
the shortest path with
ArrayList<IAtom> path = (ArrayList)
pTools.getShortestPath(testMolecule, testMolecule.getAtomAt(1),
testMolecule.getAtomAt(9));
an exception is thrown:
java.lang.ArrayIndexOutOfBoundsException: 999999
at
org.openscience.cdk.AtomContainer.getAtomAt(AtomContainer.java:241)
at
org.openscience.cdk.graph.PathTools.getShortestPath(PathTools.java:467)
An Exception with another invalid index is thrown when I start the only
working configuration (start with atom index 0, end with atom index 9)
in the inverted order:
ArrayList<IAtom> path = (ArrayList)
pTools.getShortestPath(testMolecule, testMolecule.getAtomAt(9),
testMolecule.getAtomAt(0));
java.lang.ArrayIndexOutOfBoundsException: -1
at
org.openscience.cdk.AtomContainer.getAtomAt(AtomContainer.java:241)
at
org.openscience.cdk.graph.PathTools.getShortestPath(PathTools.java:484)
Is there a flaw in my code? As there were minor changes in the current
CDK version in this method, I assume people used and tested it and it
works. So I must have done something wrong, but at the moment I don't
see where. Had anybody ever similar problems? Any suggestions?
Kind regards
Volker
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Cdk-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cdk-user