/** * * @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 Fingerprinter().getBitFingerprint(container).asBitSet(); this.fingerprintAsLong = convert(this.fingerprint); }
public BitSet getBitFingerprint(IAtomContainer container, int size) throws Exception { BitSet bitSet = new BitSet(size); encodePaths(container, super.getSearchDepth(), bitSet, size); return bitSet; } }
/** {@inheritDoc} */ @Override public int getSize() { return fingerprinter.getSize() + RESERVED_BITS; }
private int hashRevPath(List<IAtom> apath, List<IBond> bpath) { int hash = 0; int last = apath.size() - 1; hash = appendHash(hash, getAtomSymbol(apath.get(last))); for (int i = last-1; i >= 0; i--) { final IAtom next = apath.get(i); final IBond bond = bpath.get(i); hash = appendHash(hash, getBondSymbol(bond)); hash = appendHash(hash, getAtomSymbol(next)); } return hash; }
private int encodeUniquePath(List<IAtom> apath, List<IBond> bpath, StringBuilder buffer) { if (bpath.size() == 0) return getAtomSymbol(apath.get(0)).hashCode(); final int x; if (compare(apath, bpath) >= 0) { x = hashPath(apath, bpath); } else { x = hashRevPath(apath, bpath); } return x; }
@Test public void testgetBitFingerprint_IAtomContainer() throws java.lang.Exception { Fingerprinter fingerprinter = new Fingerprinter(); IAtomContainer mol = TestMoleculeFactory.makeIndole(); IBitFingerprint bs = fingerprinter.getBitFingerprint(mol); Assert.assertNotNull(bs); Assert.assertEquals(fingerprinter.getSize(), bs.size()); }
@Test public void pseudoAtomFingerprint() throws CDKException { final SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance()); final String query = "*1CCCC1"; final String indole = "N1CCCC1"; IAtomContainer queryMol = smipar.parseSmiles(query); IAtomContainer indoleMol = smipar.parseSmiles(indole); Fingerprinter fpr = new Fingerprinter(); BitSet fp1 = fpr.getFingerprint(queryMol); BitSet fp2 = fpr.getFingerprint(indoleMol); assertTrue(FingerprinterTool.isSubset(fp2, fp1)); assertFalse(FingerprinterTool.isSubset(fp1, fp2)); fpr.setHashPseudoAtoms(true); BitSet fp3 = fpr.getFingerprint(queryMol); BitSet fp4 = fpr.getFingerprint(indoleMol); assertFalse(FingerprinterTool.isSubset(fp4, fp3)); assertFalse(FingerprinterTool.isSubset(fp3, fp4)); }
@Test public void testVersion() { Fingerprinter fpr = new Fingerprinter(1024, 7); fpr.setPathLimit(2000); fpr.setHashPseudoAtoms(true); String expected = "CDK-Fingerprinter/" + CDK.getVersion() + " searchDepth=7 pathLimit=2000 hashPseudoAtoms=true"; assertThat(fpr.getVersionDescription(), CoreMatchers.is(expected)); } }
/** * Constructs a fingerprint generator that creates fingerprints of * the given size, using a generation algorithm with the given search * depth. * * @param size The desired size of the fingerprint * @param searchDepth The desired depth of search */ public ExtendedFingerprinter(int size, int searchDepth) { this.fingerprinter = new Fingerprinter(size - RESERVED_BITS, searchDepth); }
/** * Generates a fingerprint of the default size for the given AtomContainer. * *@param container The AtomContainer for which a Fingerprint is generated */ @Override public IBitFingerprint getBitFingerprint(IAtomContainer container) throws CDKException { return getBitFingerprint(container, null); }
@Test public void testGetSearchDepth() throws java.lang.Exception { Fingerprinter fingerprinter = new Fingerprinter(512, 3); Assert.assertNotNull(fingerprinter); Assert.assertEquals(3, fingerprinter.getSearchDepth()); }
/** * Compares a path of atoms with it's self to give the * lexicographically lowest traversal (forwards or backwards). * @param apath path of atoms * @param bpath path of bonds * @return <0 forward is lower >0 reverse is lower */ private int compare(List<IAtom> apath, List<IBond> bpath) { int i = 0; int len = apath.size(); int j = len - 1; int cmp = compare(apath.get(i), apath.get(j)); if (cmp != 0) return cmp; i++; j--; while (j != 0) { cmp = compare(bpath.get(i-1), bpath.get(j)); if (cmp != 0) return cmp; cmp = compare(apath.get(i), apath.get(j)); if (cmp != 0) return cmp; i++; j--; } return 0; }
@Test public void pseudoAtomFingerprintArom() throws CDKException { final SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance()); final String query = "*1cccc1"; final String indole = "o1cccc1"; IAtomContainer queryMol = smipar.parseSmiles(query); IAtomContainer indoleMol = smipar.parseSmiles(indole); Fingerprinter fpr = new Fingerprinter(); BitSet fp1 = fpr.getFingerprint(queryMol); BitSet fp2 = fpr.getFingerprint(indoleMol); assertTrue(FingerprinterTool.isSubset(fp2, fp1)); assertFalse(FingerprinterTool.isSubset(fp1, fp2)); fpr.setHashPseudoAtoms(true); BitSet fp3 = fpr.getFingerprint(queryMol); BitSet fp4 = fpr.getFingerprint(indoleMol); assertFalse(FingerprinterTool.isSubset(fp4, fp3)); assertFalse(FingerprinterTool.isSubset(fp3, fp4)); }
@Override public IFingerprinter getBitFingerprinter() { return new Fingerprinter(); }
IBitFingerprint fingerprint = fingerprinter.getBitFingerprint(container); int size = this.getSize(); double weight = MolecularFormulaManipulator.getTotalNaturalAbundance(MolecularFormulaManipulator
private int hashPath(List<IAtom> apath, List<IBond> bpath) { int hash = 0; hash = appendHash(hash, getAtomSymbol(apath.get(0))); for (int i = 1; i < apath.size(); i++) { final IAtom next = apath.get(i); final IBond bond = bpath.get(i-1); hash = appendHash(hash, getBondSymbol(bond)); hash = appendHash(hash, getAtomSymbol(next)); } return hash; }
/** * * @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 Fingerprinter().getBitFingerprint(container).asBitSet(); this.fingerprintAsLong = convert(this.fingerprint); }
@Test public void testGetSize() throws java.lang.Exception { IFingerprinter fingerprinter = new Fingerprinter(512); Assert.assertNotNull(fingerprinter); Assert.assertEquals(512, fingerprinter.getSize()); }
@Test public void testCalculate_BitFingerprint() throws java.lang.Exception { IAtomContainer mol1 = TestMoleculeFactory.makeIndole(); IAtomContainer mol2 = TestMoleculeFactory.makePyrrole(); Fingerprinter fp = new Fingerprinter(1024, 8); double similarity = Tanimoto.calculate(fp.getBitFingerprint(mol1), fp.getBitFingerprint(mol2)); Assert.assertEquals(0.3939, similarity, 0.01); }
@Test public void testBondPermutation() throws CDKException { IAtomContainer pamine = makePropylAmine(); Fingerprinter fp = new Fingerprinter(); IBitFingerprint bs1 = fp.getBitFingerprint(pamine); AtomContainerBondPermutor acp = new AtomContainerBondPermutor(pamine); while (acp.hasNext()) { IAtomContainer container = acp.next(); IBitFingerprint bs2 = fp.getBitFingerprint(container); assertTrue(bs1.equals(bs2)); } }