SubstructureFingerprinter extends AbstractFingerprinter implements IFingerprinter { @Override public IBitFingerprint getBitFingerprint(IAtomContainer atomContainer) throws CDKException { if (keys.isEmpty()) { throw new CDKException("No substructures were defined"); } SmartsPattern.prepare(atomContainer); BitSet fingerPrint = new BitSet(keys.size()); for (int i = 0; i < keys.size(); i++) { if (keys.get(i).pattern.matches(atomContainer)) fingerPrint.set(i, true); } return new BitSetFingerprint(fingerPrint); } SubstructureFingerprinter(String[] smarts);  SubstructureFingerprinter(); @Override IBitFingerprint getBitFingerprint(IAtomContainer atomContainer); @Override ICountFingerprint getCountFingerprint(IAtomContainer atomContainer); @Override Map<String, Integer> getRawFingerprint(IAtomContainer iAtomContainer); @Override int getSize(); String getSubstructure(int bitIndex);  }
@Test @Override public void testBug706786() throws Exception { IAtomContainer superStructure = bug706786_1(); IAtomContainer subStructure = bug706786_2(); addImplicitHydrogens(superStructure); addImplicitHydrogens(subStructure); AtomContainerManipulator.suppressHydrogens(superStructure); AtomContainerManipulator.suppressHydrogens(subStructure); IFingerprinter fpr = getBitFingerprinter(); IBitFingerprint superBits = fpr.getBitFingerprint(superStructure); IBitFingerprint subBits = fpr.getBitFingerprint(subStructure); assertThat(superBits.asBitSet(), is(asBitSet(0, 11, 13, 17, 40, 48, 136, 273, 274, 278, 286, 294, 299, 301, 304, 306))); assertThat(subBits.asBitSet(), is(asBitSet(1, 17, 273, 274, 278, 294, 306))); }
@Test public void testCountableMACCSBinary2() throws Exception { SmilesParser parser = new SmilesParser(SilentChemObjectBuilder.getInstance()); IFingerprinter printer = new SubstructureFingerprinter(StandardSubstructureSets.getCountableMACCSSMARTS()); IAtomContainer mol; BitSet bs; mol = parser.parseSmiles("C([S](O)(=O)=O)C1=C(C=CC=C1)CCCC[N+](=O)[O-]"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); bs = printer.getBitFingerprint(mol).asBitSet(); Assert.assertTrue(bs.get(46)); Assert.assertTrue(bs.get(27)); Assert.assertTrue(bs.get(59)); Assert.assertTrue(bs.get(49)); Assert.assertTrue(bs.get(111)); Assert.assertTrue(bs.get(129)); Assert.assertTrue(bs.get(115)); Assert.assertTrue(bs.get(120)); Assert.assertTrue(bs.get(41)); Assert.assertFalse(bs.get(93)); Assert.assertFalse(bs.get(91)); Assert.assertFalse(bs.get(24)); mol = parser.parseSmiles("CC(=O)NC1=C(C(=C(C(=C1I)C(=O)O)I)NC(=O)C)I"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); bs = printer.getBitFingerprint(mol).asBitSet(); Assert.assertTrue(bs.get(15)); Assert.assertTrue(bs.get(135)); Assert.assertTrue(bs.get(139)); Assert.assertTrue(bs.get(93)); Assert.assertTrue(bs.get(73)); Assert.assertFalse(bs.get(91)); }
@Test public void testCountableMACCSBinary_Rings() throws Exception { SmilesParser parser = new SmilesParser(SilentChemObjectBuilder.getInstance()); IFingerprinter printer = new SubstructureFingerprinter(StandardSubstructureSets.getCountableMACCSSMARTS()); IAtomContainer mol; BitSet bs; mol = parser.parseSmiles("C1=CC=CC(=C1)CCCC2=CC=CC=C2"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); bs = printer.getBitFingerprint(mol).asBitSet(); Assert.assertTrue(bs.get(128)); Assert.assertTrue(bs.get(111)); Assert.assertFalse(bs.get(7)); Assert.assertFalse(bs.get(82)); mol = parser.parseSmiles("C1CC(CCC1)CCCCC2CCCCC2"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); bs = printer.getBitFingerprint(mol).asBitSet(); Assert.assertTrue(bs.get(128)); Assert.assertFalse(bs.get(111)); Assert.assertFalse(bs.get(7)); Assert.assertFalse(bs.get(82)); mol = parser.parseSmiles("C1CC1C(CCC2CCC2)CC3=CC=CC=C3"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); bs = printer.getBitFingerprint(mol).asBitSet(); Assert.assertTrue(bs.get(128)); Assert.assertTrue(bs.get(111)); Assert.assertTrue(bs.get(10)); Assert.assertTrue(bs.get(1)); Assert.assertFalse(bs.get(7)); Assert.assertFalse(bs.get(82)); mol = parser.parseSmiles("C1(CC1C(CCC2CCC2)CC3=CC=CC=C3)C(C(C(C4CC4)C5CC5)C6CC6)C7CC7"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); bs = printer.getBitFingerprint(mol).asBitSet(); Assert.assertTrue(bs.get(128)); Assert.assertTrue(bs.get(111)); Assert.assertTrue(bs.get(10)); Assert.assertTrue(bs.get(1)); Assert.assertFalse(bs.get(7)); Assert.assertFalse(bs.get(82)); }