SubstructureFingerprinter extends AbstractFingerprinter implements IFingerprinter { @Override public ICountFingerprint getCountFingerprint(IAtomContainer atomContainer) throws CDKException { if (keys.isEmpty()) { throw new CDKException("No substructures were defined"); } SmartsPattern.prepare(atomContainer); final Map<Integer, Integer> map = new TreeMap<Integer, Integer>(); for (int i = 0; i < keys.size(); i++) { Pattern ptrn = keys.get(i).pattern; map.put(i, ptrn.matchAll(atomContainer) .countUnique()); } final int length = keys.size(); final int size = map.size(); final int[] hash = new int[size], count = new int[size]; int n = 0; for (int h : map.keySet()) { hash[n] = h; count[n++] = map.get(h); } return new ICountFingerprint() { @Override public long size() { return length; } @Override public int numOfPopulatedbins() { return size; } @Override public int getCount(int index) { return count[index]; } @Override public int getHash(int index) { return hash[index]; } @Override public void merge(ICountFingerprint fp) {} @Override public void setBehaveAsBitFingerprint(boolean behaveAsBitFingerprint) {} @Override public boolean hasHash(int hash) { return map.containsKey(hash); } @Override public int getCountForHash(int hash) { return map.get(hash); } }; } 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 public void testGetCountFingerprint() throws Exception { }
@Test public void testCountableMACCSCount2() throws Exception { SmilesParser parser = new SmilesParser(SilentChemObjectBuilder.getInstance()); IFingerprinter printer = new SubstructureFingerprinter(StandardSubstructureSets.getCountableMACCSSMARTS()); IAtomContainer mol; ICountFingerprint cfp; mol = parser.parseSmiles("C([S](O)(=O)=O)C1=C(C=CC=C1)CCCC[N+](=O)[O-]"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); cfp = printer.getCountFingerprint(mol); Assert.assertEquals(cfp.getCountForHash(46), 2); Assert.assertEquals(cfp.getCountForHash(27), 1); Assert.assertEquals(cfp.getCountForHash(59), 2); Assert.assertEquals(cfp.getCountForHash(49), 1); Assert.assertEquals(cfp.getCountForHash(111), 1); Assert.assertEquals(cfp.getCountForHash(129), 3); Assert.assertEquals(cfp.getCountForHash(115), 2); Assert.assertEquals(cfp.getCountForHash(120), 3); Assert.assertEquals(cfp.getCountForHash(41), 3); Assert.assertEquals(cfp.getCountForHash(93), 0); Assert.assertEquals(cfp.getCountForHash(91), 0); Assert.assertEquals(cfp.getCountForHash(24), 0); 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); cfp = printer.getCountFingerprint(mol); Assert.assertEquals(cfp.getCountForHash(15), 3); Assert.assertEquals(cfp.getCountForHash(135), 3); Assert.assertEquals(cfp.getCountForHash(139), 4); Assert.assertEquals(cfp.getCountForHash(93), 3); Assert.assertEquals(cfp.getCountForHash(73), 6); Assert.assertEquals(cfp.getCountForHash(91), 0); }
@Test public void testCountableMACCSCount_Rings() throws Exception { SmilesParser parser = new SmilesParser(SilentChemObjectBuilder.getInstance()); IFingerprinter printer = new SubstructureFingerprinter(StandardSubstructureSets.getCountableMACCSSMARTS()); IAtomContainer mol; ICountFingerprint cfp; mol = parser.parseSmiles("C1=CC=CC(=C1)CCCC2=CC=CC=C2"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); cfp = printer.getCountFingerprint(mol); Assert.assertEquals(cfp.getCountForHash(128), 2); Assert.assertEquals(cfp.getCountForHash(111), 2); Assert.assertEquals(cfp.getCountForHash(7), 0); Assert.assertEquals(cfp.getCountForHash(82), 0); mol = parser.parseSmiles("C1CC(CCC1)CCCCC2CCCCC2"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); cfp = printer.getCountFingerprint(mol); Assert.assertEquals(cfp.getCountForHash(128), 2); Assert.assertEquals(cfp.getCountForHash(111), 0); Assert.assertEquals(cfp.getCountForHash(7), 0); Assert.assertEquals(cfp.getCountForHash(82), 0); mol = parser.parseSmiles("C1CC1C(CCC2CCC2)CC3=CC=CC=C3"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); cfp = printer.getCountFingerprint(mol); Assert.assertEquals(cfp.getCountForHash(128), 1); Assert.assertEquals(cfp.getCountForHash(111), 1); Assert.assertEquals(cfp.getCountForHash(10), 1); Assert.assertEquals(cfp.getCountForHash(1), 1); Assert.assertEquals(cfp.getCountForHash(7), 0); Assert.assertEquals(cfp.getCountForHash(82), 0); mol = parser.parseSmiles("C1(CC1C(CCC2CCC2)CC3=CC=CC=C3)C(C(C(C4CC4)C5CC5)C6CC6)C7CC7"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); cfp = printer.getCountFingerprint(mol); Assert.assertEquals(cfp.getCountForHash(128), 1); Assert.assertEquals(cfp.getCountForHash(111), 1); Assert.assertEquals(cfp.getCountForHash(10), 5); Assert.assertEquals(cfp.getCountForHash(1), 1); Assert.assertEquals(cfp.getCountForHash(7), 0); Assert.assertEquals(cfp.getCountForHash(82), 0); }