1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
//
// Copyright (C) 2019
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#include <catch2/catch_all.hpp>
#include <RDGeneral/types.h>
#include <RDGeneral/test.h>
#include <DataStructs/ExplicitBitVect.h>
#include <DataStructs/BitOps.h>
#include <SimDivPickers/LeaderPicker.h>
#include <iostream>
#include <fstream>
template <typename T>
class BVFunctor {
public:
BVFunctor(const T &obj) : d_obj(obj) {}
~BVFunctor() = default;
double operator()(unsigned int i, unsigned int j) {
double res = 1. - TanimotoSimilarity(*d_obj[i], *d_obj[j]);
return res;
}
const T &d_obj;
};
TEST_CASE(
"Leader Picker basics"
"[LeaderPicker]") {
std::string rdbase = getenv("RDBASE");
std::string fName =
rdbase + "/Code/SimDivPickers/Wrap/test_data/chembl_cyps.head.fps";
std::ifstream inf(fName);
std::string fpsText;
std::getline(inf, fpsText);
std::vector<std::unique_ptr<ExplicitBitVect>> fps;
while (!inf.eof() && !fpsText.empty()) {
fps.emplace_back(new ExplicitBitVect(fpsText.size() * 4));
UpdateBitVectFromFPSText(*fps.back(), fpsText);
std::getline(inf, fpsText);
};
REQUIRE(fps.size() == 1000);
BVFunctor<std::vector<std::unique_ptr<ExplicitBitVect>>> bvf(fps);
RDPickers::LeaderPicker pkr;
SECTION("basics1") {
double threshold = 0.8;
auto res = pkr.lazyPick(bvf, fps.size(), 0, threshold);
CHECK(res.size() == 146);
for (unsigned i = 0; i < res.size(); ++i) {
for (unsigned j = 0; j < i; ++j) {
CHECK(bvf(res[i], res[j]) >= threshold);
}
}
}
SECTION("basics2") {
double threshold = 0.9;
auto res = pkr.lazyPick(bvf, fps.size(), 0, threshold);
CHECK(res.size() == 14);
for (unsigned i = 0; i < res.size(); ++i) {
for (unsigned j = 0; j < i; ++j) {
CHECK(bvf(res[i], res[j]) >= threshold);
}
}
}
#ifdef RDK_BUILD_THREADSAFE_SSS
SECTION("basics multithreaded") {
double threshold = 0.8;
RDKit::INT_VECT firstPicks;
int nThreads = 0; // use max available
auto res =
pkr.lazyPick(bvf, fps.size(), 0, firstPicks, threshold, nThreads);
CHECK(res.size() == 146);
for (unsigned i = 0; i < res.size(); ++i) {
for (unsigned j = 0; j < i; ++j) {
CHECK(bvf(res[i], res[j]) >= threshold);
}
}
}
#endif
}
|