@Deprecated public CircularFingerprinter.FP[] getRelevantFingerprintDetails() { final ArrayList<CircularFingerprinter.FP> list = new ArrayList<>(); for (int k=0; k < circularFingerprinter.getFPCount(); ++k) { final CircularFingerprinter.FP fp = circularFingerprinter.getFP(k); if (HASH_SET.containsKey(fp.hashCode)) { list.add(fp); } } Collections.sort(list, new Comparator<CircularFingerprinter.FP>() { @Override public int compare(CircularFingerprinter.FP o1, CircularFingerprinter.FP o2) { return Integer.compare(o1.hashCode, o2.hashCode); } }); return list.toArray(new CircularFingerprinter.FP[list.size()]); }
for (int n = circ.getFPCount() - 1; n >= 0; n--) { int code = circ.getFP(n).hashCode; if (folding > 0) code &= AND_BITS;
public CircularFingerprinter.FP[] getFingerprintDetails() { final CircularFingerprinter.FP[] ary = new CircularFingerprinter.FP[HASH_SET.size()]; for (int k=0; k < circularFingerprinter.getFPCount(); ++k) { final CircularFingerprinter.FP fp = circularFingerprinter.getFP(k); if (HASH_SET.containsKey(fp.hashCode)) { ary[HASH_SET.get(fp.hashCode)] = fp; } } return ary; }
/** * 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.FP[] obtained = new CircularFingerprinter.FP[circ.getFPCount()]; for (int n = 0; n < circ.getFPCount(); n++) obtained[n] = circ.getFP(n);