Yes, you're right. I added more debugging output to compareAtoms:
public boolean compareAtoms(int queryAtomNum, int targetAtomNum) {
debugPrint("Entering ExplicitHMatcher.compareAtoms: "
+ "query = " + query.toFormat("smiles")
+ ", target = " + target.toFormat("smiles")
+ "; internal qAtomNum = " + (queryAtomNum + 1)
+ ", internal tAtomNum = " + (targetAtomNum + 1)
);
int qAtomNum = getOrigQueryAtom(queryAtomNum);
int tAtomNum = getOrigTargetAtom(targetAtomNum);
debugPrint("ExplicitHMatcher.compareAtoms: "
+ "getting query atom " + (qAtomNum + 1)
+ ", target atom " + (tAtomNum + 1)
);
MolAtom qAtom = query.getAtom(qAtomNum);
MolAtom tAtom = target.getAtom(tAtomNum);
debugPrint("ExplicitHMatcher.compareAtoms: "
+ "getting qAtom.getExplicitHcount() for "
+ qAtom.getSymbol() + (qAtomNum + 1));
int qHCount = qAtom.getExplicitHcount();
debugPrint("ExplicitHMatcher.compareAtoms: "
+ "getting tAtom.getExplicitHcount() for "
+ tAtom.getSymbol() + (tAtomNum + 1));
int tHCount = tAtom.getExplicitHcount();
boolean match = (qHCount == tHCount);
debugPrint("qAtom " + qAtom.getSymbol() + (qAtomNum + 1)
+ " has " + qHCount + " explicit H atoms"
+ "; tAtom " + tAtom.getSymbol() + (tAtomNum + 1)
+ " has " + tHCount + " explicit H atoms"
+ "; atoms " + (match ? "" : "do not ") + "match.");
return match;
} // compareAtoms(int, int)
And I get this output in the log:
Entering ExplicitHMatcher.compareAtoms: query = [H+], target = [H][OH+]C([H])[H]; internal qAtomNum = 1, internal tAtomNum = 1
ExplicitHMatcher.compareAtoms: getting query atom 1, target atom 1
ExplicitHMatcher.compareAtoms: getting qAtom.getExplicitHcount() for H1
ExplicitHMatcher.compareAtoms: getting tAtom.getExplicitHcount() for H1
qAtom H1 has 0 explicit H atoms; tAtom H1 has 0 explicit H atoms; atoms match.
Entering ExplicitHMatcher.compareAtoms: query = [H+], target = [H][OH+]C([H])[H]; internal qAtomNum = 1, internal tAtomNum = 4
ExplicitHMatcher.compareAtoms: getting query atom 1, target atom 4
ExplicitHMatcher.compareAtoms: getting qAtom.getExplicitHcount() for H1
ExplicitHMatcher.compareAtoms: getting tAtom.getExplicitHcount() for H4
qAtom H1 has 0 explicit H atoms; tAtom H4 has 0 explicit H atoms; atoms match.
Entering ExplicitHMatcher.compareAtoms: query = [H+], target = [H][OH+]C([H])[H]; internal qAtomNum = 1, internal tAtomNum = 5
ExplicitHMatcher.compareAtoms: getting query atom 1, target atom 5
ExplicitHMatcher.compareAtoms: getting qAtom.getExplicitHcount() for H1
ExplicitHMatcher.compareAtoms: getting tAtom.getExplicitHcount() for H5
qAtom H1 has 0 explicit H atoms; tAtom H5 has 0 explicit H atoms; atoms match.
Entering ExplicitHMatcher.compareAtoms: query = [H+], target = [H][OH+]C([H])[H]; internal qAtomNum = 1, internal tAtomNum = 6
ExplicitHMatcher.compareAtoms: getting query atom 1, target atom 0
Error in matchSigmaNetwork
Caught exception:
An error occured during search:java.lang.ArrayIndexOutOfBoundsException: -1
Query:[H+]
Target:[H][OH+]C([H])[H]
Caused by:
-1
So, now the question is why compareAtoms() is getting an index of -1 for an atom in the target.