Skip to content

Commit

Permalink
SMARTS matching for smallest ring size atom defaults to any ring atom.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed Jun 18, 2015
1 parent c097bb0 commit 65e3d8e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Expand Up @@ -57,6 +57,7 @@ public SmallestRingAtom(int ringSize, IChemObjectBuilder builder) {
/** @inheritDoc */
@Override
public boolean matches(IAtom atom) {
return invariants(atom).ringSize().contains(ringSize);
return ringSize < 0 ? invariants(atom).ringConnectivity() > 0
: invariants(atom).ringSize().contains(ringSize);
}
}
Expand Up @@ -728,7 +728,7 @@ void RingMembership() #RingMembership :
void SmallestRingSize() #SmallestRingSize :
{ StringBuffer digits = new StringBuffer(); }
{
<r> { jjtThis.setSize(1); }
<r> { jjtThis.setSize(-1); }
[ ( <DIGIT> { digits.append(token.image); } )+
{ jjtThis.setSize( Integer.parseInt(digits.toString()) ); } ]
}
Expand Down
Expand Up @@ -2004,4 +2004,18 @@ public void bug1358() throws Exception {
assertThat(match("[$([*@](~*)(~*)(*)*),$([*@H](*)(*)*),$([*@](~*)(*)*)]",
"N#CN/C(=N/CCSCC=1N=CNC1C)NC"), is(new int[]{0, 0}));
}

/**
* Ensure 'r' without a size is equivalent to !R0 and R.
* @cdk.bug 1364
*/
@Test
public void bug1364() throws Exception {
assertThat(match("[!R0!R1]", "C[C@]12CC3CC([NH2+]CC(=O)NCC4CC4)(C1)C[C@@](C)(C3)C2"),
is(new int[]{7, 7}));
assertThat(match("[R!R1]", "C[C@]12CC3CC([NH2+]CC(=O)NCC4CC4)(C1)C[C@@](C)(C3)C2"),
is(new int[]{7, 7}));
assertThat(match("[r!R1]", "C[C@]12CC3CC([NH2+]CC(=O)NCC4CC4)(C1)C[C@@](C)(C3)C2"),
is(new int[]{7, 7}));
}
}

0 comments on commit 65e3d8e

Please sign in to comment.