SmartsFragmentExtractor { public String generate(int[] atomIdxs) { if (atomIdxs == null) throw new NullPointerException("No atom indexes provided"); if (atomIdxs.length == 0) return null; if (atomIdxs.length == 1 && mode == MODE_EXACT) return aexpr[atomIdxs[0]]; Arrays.fill(rbnds, 0); Arrays.fill(avisit, 0); for (int atmIdx : atomIdxs) avisit[atmIdx] = -1; numVisit = 1; for (int atomIdx : atomIdxs) { if (avisit[atomIdx] < 0) markRings(atomIdx, -1); } numVisit = 1; for (int atmIdx : atomIdxs) avisit[atmIdx] = -1; StringBuilder sb = new StringBuilder(); for (int i = 0; i < atomIdxs.length; i++) { if (avisit[atomIdxs[i]] < 0) { if (i > 0) sb.append('.'); encodeExpr(atomIdxs[i], -1, sb); } } return sb.toString(); } SmartsFragmentExtractor(IAtomContainer mol); void setMode(int mode); String generate(int[] atomIdxs); static final int MODE_JCOMPOUNDMAPPER; static final int MODE_EXACT; }
@Test public void methylExact() throws Exception { String smarts = generate("CC(C)CCC", SmartsFragmentExtractor.MODE_EXACT, makeSeq(0,1)); assertThat(smarts, is("[CH3v4X4+0]")); }
@Test public void methylForJCompoundMap() throws Exception { String smarts = generate("CC(C)CCC", SmartsFragmentExtractor.MODE_JCOMPOUNDMAPPER, makeSeq(0,1)); assertThat(smarts, is("C*")); }
@Test public void indole() throws Exception { String smarts = generate("[nH]1ccc2c1cccc2", SmartsFragmentExtractor.MODE_EXACT, makeSeq(0,4)); assertThat(smarts, is("[nH1v3X3+0][cH1v4X3+0][cH1v4X3+0][cH0v4X3+0]")); }
@Test public void indoleForJCompoundMap() throws Exception { String smarts = generate("[nH]1ccc2c1cccc2", SmartsFragmentExtractor.MODE_JCOMPOUNDMAPPER, makeSeq(0,4)); assertThat(smarts, is("n(ccc(a)a)a")); }
@Test public void biphenylIncludesSingleBond() throws Exception { String smarts = generate("c1ccccc1-c1ccccc1", SmartsFragmentExtractor.MODE_EXACT, makeSeq(0,12)); assertThat(smarts, containsString("-")); }
@Test public void fullereneC60() throws Exception { String smarts = generate("c12c3c4c5c1c1c6c7c2c2c8c3c3c9c4c4c%10c5c5c1c1c6c6c%11c7c2c2c7c8c3c3c8c9c4c4c9c%10c5c5c1c1c6c6c%11c2c2c7c3c3c8c4c4c9c5c1c1c6c2c3c41", SmartsFragmentExtractor.MODE_EXACT, makeSeq(0,60)); assertThat(smarts, is("[cH0v4X3+0]12[cH0v4X3+0]3[cH0v4X3+0]4[cH0v4X3+0]5[cH0v4X3+0]1[cH0v4X3+0]1[cH0v4X3+0]6[cH0v4X3+0]7[cH0v4X3+0]2[cH0v4X3+0]2[cH0v4X3+0]8[cH0v4X3+0]3[cH0v4X3+0]3[cH0v4X3+0]9[cH0v4X3+0]4[cH0v4X3+0]4[cH0v4X3+0]%10[cH0v4X3+0]5[cH0v4X3+0]5[cH0v4X3+0]1[cH0v4X3+0]1[cH0v4X3+0]6[cH0v4X3+0]6[cH0v4X3+0]%11[cH0v4X3+0]7[cH0v4X3+0]2[cH0v4X3+0]2[cH0v4X3+0]7[cH0v4X3+0]8[cH0v4X3+0]3[cH0v4X3+0]3[cH0v4X3+0]8[cH0v4X3+0]9[cH0v4X3+0]4[cH0v4X3+0]4[cH0v4X3+0]9[cH0v4X3+0]%10[cH0v4X3+0]5[cH0v4X3+0]5[cH0v4X3+0]1[cH0v4X3+0]1[cH0v4X3+0]6[cH0v4X3+0]6[cH0v4X3+0]%11[cH0v4X3+0]2[cH0v4X3+0]2[cH0v4X3+0]7[cH0v4X3+0]3[cH0v4X3+0]3[cH0v4X3+0]8[cH0v4X3+0]4[cH0v4X3+0]4[cH0v4X3+0]9[cH0v4X3+0]5[cH0v4X3+0]1[cH0v4X3+0]1[cH0v4X3+0]6[cH0v4X3+0]2[cH0v4X3+0]3[cH0v4X3+0]41")); }