MACCSFingerprinter extends AbstractFingerprinter implements IFingerprinter { @Override public IBitFingerprint getBitFingerprint(IAtomContainer container) throws CDKException { MaccsKey[] keys = keys(container.getBuilder()); BitSet fp = new BitSet(keys.length); SmartsPattern.prepare(container); final int numAtoms = container.getAtomCount(); final GraphUtil.EdgeToBondMap bmap = GraphUtil.EdgeToBondMap.withSpaceFor(container); final int[][] adjlist = GraphUtil.toAdjList(container, bmap); for (int i = 0; i < keys.length; i++) { final MaccsKey key = keys[i]; final Pattern pattern = key.pattern; switch (key.smarts) { case "[!*]": break; case "[!0]": for (IAtom atom : container.atoms()) { if (atom.getMassNumber() != null) { fp.set(i); break; } } break; case "[R]1@*@*@1": case "[R]1@*@*@*@1": case "[R]1@*@*@*@*@1": case "[R]1@*@*@*@*@*@1": case "[R]1@*@*@*@*@*@*@1": case "[R]1@*@*@*@*@*@*@*@1": break; case "(*).(*)": boolean[] visit = new boolean[numAtoms]; if (numAtoms > 1 && visitPart(visit, adjlist, 0, -1) < numAtoms) fp.set(165); break; default: if (key.count == 0) { if (pattern.matches(container)) fp.set(i); } else { if (pattern.matchAll(container).uniqueAtoms().atLeast(key.count + 1)) fp.set(i); } break; } } if (numAtoms > 2) { AllCycles allcycles = new AllCycles(adjlist, Math.min(8, numAtoms), 126); int numArom = 0; for (int[] path : allcycles.paths()) { switch (path.length) { case 4: fp.set(21); break; case 5: fp.set(10); break; case 6: fp.set(95); break; case 7: if (numArom < 2) { if (isAromPath(path, bmap)) { numArom++; if (numArom == 2) fp.set(124); } } if (fp.get(162)) { fp.set(144); } else { fp.set(162); } break; case 8: fp.set(18); break; case 9: fp.set(100); break; } } } return new BitSetFingerprint(fp); } MACCSFingerprinter();  MACCSFingerprinter(IChemObjectBuilder builder); @Override IBitFingerprint getBitFingerprint(IAtomContainer container); @Override Map<String, Integer> getRawFingerprint(IAtomContainer iAtomContainer); @Override int getSize(); @Override ICountFingerprint getCountFingerprint(IAtomContainer container);  }
@Test public void testfp2() throws Exception { SmilesParser parser = new SmilesParser(SilentChemObjectBuilder.getInstance()); IFingerprinter printer = new MACCSFingerprinter(); IAtomContainer mol1 = parser.parseSmiles("CC(N)CCCN"); IAtomContainer mol2 = parser.parseSmiles("CC(N)CCC"); IAtomContainer mol3 = parser.parseSmiles("CCCC"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol1); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol2); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol3); Aromaticity.cdkLegacy().apply(mol1); Aromaticity.cdkLegacy().apply(mol2); Aromaticity.cdkLegacy().apply(mol3); BitSet bs1 = printer.getBitFingerprint(mol1).asBitSet(); BitSet bs2 = printer.getBitFingerprint(mol2).asBitSet(); BitSet bs3 = printer.getBitFingerprint(mol3).asBitSet(); Assert.assertFalse(bs1.get(124)); Assert.assertFalse(bs2.get(124)); Assert.assertFalse(bs3.get(124)); Assert.assertFalse(FingerprinterTool.isSubset(bs1, bs2)); Assert.assertTrue(FingerprinterTool.isSubset(bs2, bs3)); }
@Test @Override public void testBug706786() throws Exception { IAtomContainer superStructure = bug706786_1(); IAtomContainer subStructure = bug706786_2(); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(superStructure); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(subStructure); addImplicitHydrogens(superStructure); addImplicitHydrogens(subStructure); IFingerprinter fpr = new MACCSFingerprinter(); IBitFingerprint superBits = fpr.getBitFingerprint(superStructure); IBitFingerprint subBits = fpr.getBitFingerprint(subStructure); assertThat( superBits.asBitSet(), is(asBitSet(53, 56, 65, 71, 73, 88, 97, 104, 111, 112, 126, 130, 136, 138, 139, 140, 142, 143, 144, 145, 148, 149, 151, 153, 156, 158, 159, 161, 162, 163, 164))); assertThat( subBits.asBitSet(), is(asBitSet(56, 97, 104, 108, 112, 117, 131, 136, 143, 144, 146, 151, 152, 156, 161, 162, 163, 164))); }