Skip to content

Commit

Permalink
SMARTS stereo matching requires additional checks to ensure we don't …
Browse files Browse the repository at this point in the history
…accidentally attempt to compare a tetrahedral centre to a double-bond (was causing a class cast). The typical case is when this occurs is when bond orders are not matched.

Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Mar 30, 2015
1 parent 60d85be commit b12d2ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Expand Up @@ -132,6 +132,9 @@ public boolean apply(final int[] mapping) {
private boolean checkTetrahedral(int u, int[] mapping) {

int v = mapping[u];

if (targetTypes[v] != null && targetTypes[v] != Type.Tetrahedral)
return false;

ITetrahedralChirality queryElement = (ITetrahedralChirality) queryElements[u];
ITetrahedralChirality targetElement = (ITetrahedralChirality) targetElements[v];
Expand Down Expand Up @@ -188,6 +191,11 @@ private boolean checkGeometric(int u1, int u2, int[] mapping) {
int v1 = mapping[u1];
int v2 = mapping[u2];

if (targetTypes[v1] != null && targetTypes[v1] != Type.Geometric)
return false;
if (targetTypes[v2] != null && targetTypes[v2] != Type.Geometric)
return false;

IDoubleBondStereochemistry queryElement = (IDoubleBondStereochemistry) queryElements[u1];
IBond[] queryBonds = queryElement.getBonds();

Expand Down
Expand Up @@ -1994,4 +1994,14 @@ public void componentGrouping3() throws Exception {
assertThat(match("([#8]).([#8])", "OCCO"), is(new int[]{0, 0}));
assertThat(match("([#8]).([#8])", "O.CCO"), is(new int[]{2, 1}));
}

/**
* Ensure a class cast exception is not thrown when matching stereochemistry.
* @cdk.bug 1358
*/
@Test
public void bug1358() throws Exception {
assertThat(match("[$([*@](~*)(~*)(*)*),$([*@H](*)(*)*),$([*@](~*)(*)*)]",
"N#CN/C(=N/CCSCC=1N=CNC1C)NC"), is(new int[]{0, 0}));
}
}

0 comments on commit b12d2ca

Please sign in to comment.