PubchemFingerprinter extends AbstractFingerprinter implements IFingerprinter { @Override public IBitFingerprint getBitFingerprint(IAtomContainer atomContainer) throws CDKException { generateFp(atomContainer); BitSet fp = new BitSet(FP_SIZE); for (int i = 0; i < FP_SIZE; i++) { if (isBitOn(i)) fp.set(i); } return new BitSetFingerprint(fp); } PubchemFingerprinter(IChemObjectBuilder builder); @Override IBitFingerprint getBitFingerprint(IAtomContainer atomContainer); @Override Map<String, Integer> getRawFingerprint(IAtomContainer iAtomContainer); @Override int getSize(); byte[] getFingerprintAsBytes(); static BitSet decode(String enc); @Override ICountFingerprint getCountFingerprint(IAtomContainer container); static final int FP_SIZE; }
@Test public void testfp2() throws Exception { IFingerprinter printer = new PubchemFingerprinter(DefaultChemObjectBuilder.getInstance()); 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.assertTrue(FingerprinterTool.isSubset(bs1, bs2)); Assert.assertTrue(FingerprinterTool.isSubset(bs2, bs3)); }
@Test public void testMultithreadedUsage() throws Exception { IAtomContainer mol1 = parser.parseSmiles("C=C(C1=CC=C(C=C1)O)NNC2=C(C(=NC(=C2Cl)Cl)C(=O)O)Cl"); IAtomContainer mol2 = parser .parseSmiles("C1=CC=C(C=C1)C[N+]2=C(C=C(C=C2C=CC3=CC=CC=C3)C4=CC=CC=C4)C5=CC=CC=C5"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol1); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol2); CDKHydrogenAdder adder = CDKHydrogenAdder.getInstance(mol1.getBuilder()); adder.addImplicitHydrogens(mol1); AtomContainerManipulator.convertImplicitToExplicitHydrogens(mol1); Aromaticity.cdkLegacy().apply(mol1); adder.addImplicitHydrogens(mol2); AtomContainerManipulator.convertImplicitToExplicitHydrogens(mol2); Aromaticity.cdkLegacy().apply(mol2); IFingerprinter fp = new PubchemFingerprinter(DefaultChemObjectBuilder.getInstance()); BitSet bs1 = fp.getBitFingerprint(mol1).asBitSet(); BitSet bs2 = fp.getBitFingerprint(mol2).asBitSet(); class FpRunner implements Callable<BitSet> { IAtomContainer mol; FpRunner(IAtomContainer mol) { this.mol = mol; } @Override public BitSet call() throws Exception { BitSet fp = null; IFingerprinter fpr = new PubchemFingerprinter(DefaultChemObjectBuilder.getInstance()); try { fp = fpr.getBitFingerprint(mol).asBitSet(); } catch (CDKException e) { e.printStackTrace(); } return fp; } } ExecutorService executor = Executors.newFixedThreadPool(2); List<FpRunner> tasks = new ArrayList<FpRunner>(); tasks.add(new FpRunner(mol1)); tasks.add(new FpRunner(mol2)); List<Future<BitSet>> ret = executor.invokeAll(tasks); BitSet fb1 = ret.get(0).get(); Assert.assertNotNull(fb1); BitSet fb2 = ret.get(1).get(); Assert.assertNotNull(fb2); Assert.assertEquals(bs1, fb1); Assert.assertEquals(bs2, fb2); }
@Test @Override public void testBug934819() throws Exception { IAtomContainer subStructure = bug934819_1(); IAtomContainer superStructure = bug934819_2(); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(superStructure); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(subStructure); addImplicitHydrogens(superStructure); addImplicitHydrogens(subStructure); IFingerprinter fpr = new PubchemFingerprinter(SilentChemObjectBuilder.getInstance()); IBitFingerprint superBits = fpr.getBitFingerprint(superStructure); IBitFingerprint subBits = fpr.getBitFingerprint(subStructure); org.hamcrest.MatcherAssert.assertThat( subBits.asBitSet(), is(asBitSet(9, 10, 14, 18, 19, 33, 143, 146, 255, 256, 283, 284, 285, 293, 301, 332, 344, 349, 351, 353, 355, 368, 370, 371, 376, 383, 384, 395, 401, 412, 416, 421, 423, 434, 441, 446, 449, 454, 455, 464, 470, 471, 480, 489, 490, 500, 502, 507, 513, 514, 516, 520, 524, 531, 532, 545, 546, 549, 552, 556, 558, 564, 570, 586, 592, 599, 600, 607, 633, 658, 665))); org.hamcrest.MatcherAssert.assertThat( superBits.asBitSet(), is(asBitSet(9, 10, 11, 14, 18, 19, 33, 34, 143, 146, 150, 153, 255, 256, 257, 258, 283, 284, 285, 293, 301, 332, 344, 349, 351, 353, 355, 368, 370, 371, 374, 376, 383, 384, 395, 401, 412, 416, 417, 421, 423, 427, 434, 441, 446, 449, 454, 455, 460, 464, 470, 471, 479, 480, 489, 490, 500, 502, 507, 513, 514, 516, 520, 524, 531, 532, 545, 546, 549, 552, 556, 558, 564, 570, 578, 582, 584, 586, 592, 595, 600, 603, 607, 608, 633, 634, 640, 658, 660, 664, 665, 668, 677, 678, 683))); }