/** * * @param container * @throws CDKException */ public Fragment(IAtomContainer container) throws CDKException { if (container == null) { throw new CDKException("NULL container not supported"); } this.container = container; this.fingerprint = new ShortestPathFingerprinter().getBitFingerprint(container).asBitSet(); this.fingerprintAsLong = convert(this.fingerprint); }
private void addUniquePath(IAtomContainer container, BitSet bitSet) { Integer[] hashes = findPaths(container); for (Integer hash : hashes) { int position = getRandomNumber(hash); bitSet.set(position); } }
@Test public void testgetBitFingerprint_IAtomContainer() throws java.lang.Exception { ShortestPathFingerprinter fingerprinter = new ShortestPathFingerprinter(); IAtomContainer mol = TestMoleculeFactory.makeIndole(); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); IBitFingerprint bs = fingerprinter.getBitFingerprint(mol); Assert.assertNotNull(bs); Assert.assertEquals(fingerprinter.getSize(), bs.size()); }
@Override public IFingerprinter getBitFingerprinter() { return new ShortestPathFingerprinter(); }
/** * Generates a shortest path based BitSet fingerprint for the given AtomContainer. * * @param ac The AtomContainer for which a fingerprint is generated * @exception CDKException if there error in aromaticity perception or other CDK functions * @return A {@link BitSet} representing the fingerprint */ @Override public IBitFingerprint getBitFingerprint(IAtomContainer ac) throws CDKException { IAtomContainer atomContainer = null; try { atomContainer = (IAtomContainer) ac.clone(); } catch (CloneNotSupportedException ex) { logger.error("Failed to clone the molecule:", ex); } Aromaticity.cdkLegacy().apply(atomContainer); BitSet bitSet = new BitSet(fingerprintLength); if (!ConnectivityChecker.isConnected(atomContainer)) { IAtomContainerSet partitionedMolecules = ConnectivityChecker.partitionIntoMolecules(atomContainer); for (IAtomContainer container : partitionedMolecules.atomContainers()) { addUniquePath(container, bitSet); } } else { addUniquePath(atomContainer, bitSet); } return new BitSetFingerprint(bitSet); }
@Test public void testGetSize() throws java.lang.Exception { IFingerprinter fingerprinter = new ShortestPathFingerprinter(512); Assert.assertNotNull(fingerprinter); Assert.assertEquals(512, fingerprinter.getSize()); }
@Test public void testAtomPermutation() throws CDKException { IAtomContainer pamine = makePropylAmine(); ShortestPathFingerprinter fp = new ShortestPathFingerprinter(); IBitFingerprint bs1 = fp.getBitFingerprint(pamine); AtomContainerAtomPermutor acp = new AtomContainerAtomPermutor(pamine); while (acp.hasNext()) { IAtomContainer container = acp.next(); IBitFingerprint bs2 = fp.getBitFingerprint(container); Assert.assertTrue(bs1.equals(bs2)); } }
private void addUniquePath(IAtomContainer atomContainer, Map<String, Integer> uniquePaths) { Integer[] hashes; hashes = findPaths(atomContainer); for (Integer hash : hashes) { int position = getRandomNumber(hash); uniquePaths.put(String.valueOf(position), hash); } }
@Test public void testBondPermutation() throws CDKException { IAtomContainer pamine = makePropylAmine(); ShortestPathFingerprinter fp = new ShortestPathFingerprinter(); IBitFingerprint bs1 = fp.getBitFingerprint(pamine); AtomContainerBondPermutor acp = new AtomContainerBondPermutor(pamine); while (acp.hasNext()) { IAtomContainer container = acp.next(); IBitFingerprint bs2 = fp.getBitFingerprint(container); Assert.assertTrue(bs1.equals(bs2)); } }
@Test public void testBondPermutation2() throws CDKException { IAtomContainer pamine = TestMoleculeFactory.makeCyclopentane(); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(pamine); ShortestPathFingerprinter fp = new ShortestPathFingerprinter(); IBitFingerprint bs1 = fp.getBitFingerprint(pamine); AtomContainerBondPermutor acp = new AtomContainerBondPermutor(pamine); while (acp.hasNext()) { IAtomContainer container = acp.next(); IBitFingerprint bs2 = fp.getBitFingerprint(container); Assert.assertTrue(bs1.equals(bs2)); } }
@Test public void testAtomPermutation2() throws CDKException { IAtomContainer pamine = TestMoleculeFactory.makeCyclopentane(); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(pamine); ShortestPathFingerprinter fp = new ShortestPathFingerprinter(); IBitFingerprint bs1 = fp.getBitFingerprint(pamine); AtomContainerAtomPermutor acp = new AtomContainerAtomPermutor(pamine); while (acp.hasNext()) { IAtomContainer container = acp.next(); IBitFingerprint bs2 = fp.getBitFingerprint(container); Assert.assertTrue(bs1.equals(bs2)); } }
/** * @cdk.bug 2819557 * * @throws org.openscience.cdk.exception.CDKException */ @Test public void testBug2819557() throws CDKException { IAtomContainer butane = makeButane(); IAtomContainer propylAmine = makePropylAmine(); ShortestPathFingerprinter fp = new ShortestPathFingerprinter(); BitSet b1 = fp.getBitFingerprint(butane).asBitSet(); BitSet b2 = fp.getBitFingerprint(propylAmine).asBitSet(); Assert.assertFalse("butane should not be a substructure of propylamine", FingerprinterTool.isSubset(b2, b1)); }
@Test public void testFingerprinterBitSetSize() throws Exception { ShortestPathFingerprinter fingerprinter = new ShortestPathFingerprinter(1024); Assert.assertNotNull(fingerprinter); IAtomContainer mol = TestMoleculeFactory.makeIndole(); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); BitSet bs = fingerprinter.getBitFingerprint(mol).asBitSet(); Assert.assertEquals(1024, bs.length()); // highest set bit Assert.assertEquals(1024, bs.size()); // actual bit set size }
@Test public void testGenerateFingerprintMultiphtalene() throws InvalidSmilesException, Exception { String smiles = "C1=CC2=CC=C3C4=CC5=CC6=CC=CC=C6C=C5C=C4C=CC3=C2C=C1"; SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer molecule = smilesParser.parseSmiles(smiles); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); ShortestPathFingerprinter fingerprint = new ShortestPathFingerprinter(1024); BitSet fingerprint1; fingerprint1 = fingerprint.getBitFingerprint(molecule).asBitSet(); org.junit.Assert.assertEquals(15, fingerprint1.cardinality()); }
@Test public void testFingerprinter_int_int() throws java.lang.Exception { ShortestPathFingerprinter fingerprinter = new ShortestPathFingerprinter(1024); Assert.assertNotNull(fingerprinter); IAtomContainer mol = TestMoleculeFactory.makeIndole(); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); BitSet bs = fingerprinter.getBitFingerprint(mol).asBitSet(); IAtomContainer frag1 = TestMoleculeFactory.makePyrrole(); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(frag1); BitSet bs1 = fingerprinter.getBitFingerprint(frag1).asBitSet(); Assert.assertTrue(FingerprinterTool.isSubset(bs, bs1)); }
@Test public void testFingerprinter() throws java.lang.Exception { ShortestPathFingerprinter fingerprinter = new ShortestPathFingerprinter(); Assert.assertNotNull(fingerprinter); IAtomContainer mol = TestMoleculeFactory.makeIndole(); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); BitSet bs = fingerprinter.getBitFingerprint(mol).asBitSet(); IAtomContainer frag1 = TestMoleculeFactory.makePyrrole(); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(frag1); BitSet bs1 = fingerprinter.getBitFingerprint(frag1).asBitSet(); Assert.assertTrue(FingerprinterTool.isSubset(bs, bs1)); }
@Test public void testFingerprinter_int() throws java.lang.Exception { ShortestPathFingerprinter fingerprinter = new ShortestPathFingerprinter(512); Assert.assertNotNull(fingerprinter); IAtomContainer mol = TestMoleculeFactory.makeIndole(); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); BitSet bs = fingerprinter.getBitFingerprint(mol).asBitSet(); IAtomContainer frag1 = TestMoleculeFactory.makePyrrole(); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(frag1); BitSet bs1 = fingerprinter.getBitFingerprint(frag1).asBitSet(); Assert.assertTrue(FingerprinterTool.isSubset(bs, bs1)); }
@Test public void testRegression() throws Exception { IAtomContainer mol1 = TestMoleculeFactory.makeIndole(); IAtomContainer mol2 = TestMoleculeFactory.makePyrrole(); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol1); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol2); ShortestPathFingerprinter fingerprinter = new ShortestPathFingerprinter(); IBitFingerprint bs1 = fingerprinter.getBitFingerprint(mol1); Assert.assertEquals( "Seems the fingerprint code has changed. This will cause a number of other tests to fail too!", 22, bs1.cardinality()); IBitFingerprint bs2 = fingerprinter.getBitFingerprint(mol2); Assert.assertEquals( "Seems the fingerprint code has changed. This will cause a number of other tests to fail too!", 11, bs2.cardinality()); }
@Test public void testGenerateFingerprintAnthracene() throws InvalidSmilesException, Exception { String smiles = "C1=CC2=CC3=CC=CC=C3C=C2C=C1"; SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer molecule = smilesParser.parseSmiles(smiles); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); Aromaticity.cdkLegacy().apply(molecule); ShortestPathFingerprinter fingerprint = new ShortestPathFingerprinter(1024); BitSet fingerprint1; fingerprint1 = fingerprint.getBitFingerprint(molecule).asBitSet(); org.junit.Assert.assertEquals(10, fingerprint1.cardinality()); }
@Test public void testGenerateFingerprintNaphthalene() throws InvalidSmilesException, Exception { String smiles = "C1=CC2=CC=CC=C2C=C1"; SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer molecule = smilesParser.parseSmiles(smiles); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); Aromaticity.cdkLegacy().apply(molecule); ShortestPathFingerprinter fingerprint = new ShortestPathFingerprinter(1024); BitSet fingerprint1; fingerprint1 = fingerprint.getBitFingerprint(molecule).asBitSet(); org.junit.Assert.assertEquals(8, fingerprint1.cardinality()); }