/** * Calculates the circular fingerprint for the given {@link IAtomContainer}, and <b>folds</b> the result into a single bitset * (see getSize()). * * @param mol IAtomContainer for which the fingerprint should be calculated. * @return the fingerprint */ @Override public IBitFingerprint getBitFingerprint(IAtomContainer mol) throws CDKException { calculate(mol); final BitSet bits = new BitSet(length); for (int n = 0; n < fplist.size(); n++) { int i = fplist.get(n).hashCode; long b = i >= 0 ? i : ((i & 0x7FFFFFFF) | (1L << 31)); bits.set((int) (b % length)); } return new BitSetFingerprint(bits); }
calculate(mol);
circ.calculate(mol);
/** * For a given molecule, determines its fingerprints and uses them to calculate a Bayesian prediction. Note that this * value is unscaled, and so it only has relative meaning within the confines of the model, i.e. higher is more likely to * be active. * * @param mol molecular structure which cannot be blank or null * @return predictor value */ public double predict(IAtomContainer mol) throws CDKException { if (mol == null || mol.getAtomCount() == 0) throw new CDKException("Molecule cannot be blank or null."); CircularFingerprinter circ = new CircularFingerprinter(classType); circ.setPerceiveStereo(optPerceiveStereo); circ.calculate(mol); // gather all of the (folded) fingerprints (eliminating duplicates) final int AND_BITS = folding - 1; // e.g. 1024/0x400 -> 1023/0x3FF: chop off higher order bits Set<Integer> hashset = new HashSet<Integer>(); for (int n = circ.getFPCount() - 1; n >= 0; n--) { int code = circ.getFP(n).hashCode; if (folding > 0) code &= AND_BITS; hashset.add(code); } // sums the corresponding contributor for each hash code generated from the molecule; note that if the // molecule generates hash codes not originally in the model, they are discarded (i.e. 0 contribution) double val = 0; for (int h : hashset) { Double c = contribs.get(h); if (c != null) val += c; } return val; }
private void checkFPSmartsForMolecule(String moleculeSmiles, String expectedFPSmarts[][]) throws Exception { Set<String> expected = new HashSet<>(); for (String[] strs : expectedFPSmarts) Collections.addAll(expected, strs); // expectedFPSmarts[][] is a double array because for each smarts // several equivalent variants // of the smarts are given e.g. CCC C(C)C IAtomContainer mol = parser.parseSmiles(moleculeSmiles); CircularFingerprinter circ = new CircularFingerprinter(); circ.calculate(mol); SmartsFragmentExtractor subsmarts = new SmartsFragmentExtractor(mol); subsmarts.setMode(SmartsFragmentExtractor.MODE_JCOMPOUNDMAPPER); int numFP = circ.getFPCount(); Set<String> actual = new HashSet<>(); for (int i = 0; i < numFP; i++) { FP fp = circ.getFP(i); actual.add(subsmarts.generate(fp.atoms)); } assertThat(actual, everyItem(isIn(expected))); } }
CircularFingerprinter circ = new CircularFingerprinter(classType); try { circ.calculate(mol); } catch (Exception ex) { System.out.println("Fingerprint calculation failed for molecule:");