11#ifndef RD_FPBREADER_H_DEC2015
12#define RD_FPBREADER_H_DEC2015
29#include <boost/shared_ptr.hpp>
30#include <boost/shared_array.hpp>
68 FPBReader(
const char *fname,
bool lazyRead =
false) {
69 _initFromFilename(fname, lazyRead);
72 FPBReader(
const std::string &fname,
bool lazyRead =
false) {
73 _initFromFilename(fname.c_str(), lazyRead);
87 FPBReader(std::istream *inStream,
bool takeOwnership =
true,
88 bool lazyRead =
false)
91 df_owner(takeOwnership),
93 df_lazyRead(lazyRead) {}
127 boost::shared_ptr<ExplicitBitVect>
getFP(
unsigned int idx)
const;
129 boost::shared_array<std::uint8_t>
getBytes(
unsigned int idx)
const;
132 std::string
getId(
unsigned int idx)
const;
134 std::pair<boost::shared_ptr<ExplicitBitVect>, std::string>
operator[](
135 unsigned int idx)
const {
136 return std::make_pair(
getFP(idx), getId(idx));
142 unsigned int minCount,
unsigned int maxCount);
151 double getTanimoto(
unsigned int idx,
const std::uint8_t *bv)
const;
154 boost::shared_array<std::uint8_t> bv)
const {
155 return getTanimoto(idx, bv.get());
173 const std::uint8_t *bv,
double threshold = 0.7,
174 bool usePopcountScreen =
true)
const;
177 boost::shared_array<std::uint8_t> bv,
double threshold = 0.7,
178 bool usePopcountScreen =
true)
const {
179 return getTanimotoNeighbors(bv.get(), threshold, usePopcountScreen);
184 bool usePopcountScreen =
true)
const;
196 double getTversky(
unsigned int idx,
const std::uint8_t *bv,
double ca,
199 double getTversky(
unsigned int idx, boost::shared_array<std::uint8_t> bv,
200 double ca,
double cb)
const {
201 return getTversky(idx, bv.get(), ca, cb);
222 const std::uint8_t *bv,
double ca,
double cb,
double threshold = 0.7,
223 bool usePopcountScreen =
true)
const;
226 boost::shared_array<std::uint8_t> bv,
double ca,
double cb,
227 double threshold = 0.7,
bool usePopcountScreen =
true)
const {
228 return getTverskyNeighbors(bv.get(), ca, cb, threshold, usePopcountScreen);
232 const ExplicitBitVect &ebv,
double ca,
double cb,
double threshold = 0.7,
233 bool usePopcountScreen =
true)
const;
240 const std::uint8_t *bv)
const;
243 boost::shared_array<std::uint8_t> bv)
const {
244 return getContainingNeighbors(bv.get());
251 std::istream *dp_istrm{
nullptr};
252 detail::FPBReader_impl *dp_impl{
nullptr};
253 bool df_owner{
false};
255 bool df_lazyRead{
false};
261 FPBReader(
const FPBReader &);
262 FPBReader &operator=(
const FPBReader &);
264 void _initFromFilename(
const char *fname,
bool lazyRead) {
265 std::istream *tmpStream =
static_cast<std::istream *
>(
266 new std::ifstream(fname, std::ios_base::binary));
267 if (!(*tmpStream) || (tmpStream->bad())) {
268 std::ostringstream errout;
269 errout <<
"Bad input file " << fname;
271 throw BadFileException(errout.str());
273 dp_istrm = tmpStream;
277 df_lazyRead = lazyRead;
a class for bit vectors that are densely occupied
class for reading and searching FPB files
std::vector< unsigned int > getContainingNeighbors(boost::shared_array< std::uint8_t > bv) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::pair< unsigned int, unsigned int > getFPIdsInCountRange(unsigned int minCount, unsigned int maxCount)
std::vector< std::pair< double, unsigned int > > getTanimotoNeighbors(const std::uint8_t *bv, double threshold=0.7, bool usePopcountScreen=true) const
returns tanimoto neighbors that are within a similarity threshold
std::vector< std::pair< double, unsigned int > > getTanimotoNeighbors(const ExplicitBitVect &ebv, double threshold=0.7, bool usePopcountScreen=true) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::vector< std::pair< double, unsigned int > > getTverskyNeighbors(const std::uint8_t *bv, double ca, double cb, double threshold=0.7, bool usePopcountScreen=true) const
returns Tversky neighbors that are within a similarity threshold
std::vector< unsigned int > getContainingNeighbors(const std::uint8_t *bv) const
returns indices of all fingerprints that completely contain this one
double getTversky(unsigned int idx, const std::uint8_t *bv, double ca, double cb) const
std::vector< std::pair< double, unsigned int > > getTverskyNeighbors(boost::shared_array< std::uint8_t > bv, double ca, double cb, double threshold=0.7, bool usePopcountScreen=true) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
unsigned int length() const
returns the number of fingerprints
boost::shared_array< std::uint8_t > getBytes(unsigned int idx) const
returns the requested fingerprint as an array of bytes
double getTanimoto(unsigned int idx, const std::uint8_t *bv) const
std::vector< std::pair< double, unsigned int > > getTverskyNeighbors(const ExplicitBitVect &ebv, double ca, double cb, double threshold=0.7, bool usePopcountScreen=true) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
boost::shared_ptr< ExplicitBitVect > getFP(unsigned int idx) const
returns the requested fingerprint as an ExplicitBitVect
double getTanimoto(unsigned int idx, boost::shared_array< std::uint8_t > bv) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
double getTversky(unsigned int idx, boost::shared_array< std::uint8_t > bv, double ca, double cb) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::pair< boost::shared_ptr< ExplicitBitVect >, std::string > operator[](unsigned int idx) const
returns the fingerprint and id of the requested fingerprint
std::vector< std::pair< double, unsigned int > > getTanimotoNeighbors(boost::shared_array< std::uint8_t > bv, double threshold=0.7, bool usePopcountScreen=true) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
double getTversky(unsigned int idx, const ExplicitBitVect &ebv, double ca, double cb) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
FPBReader(std::istream *inStream, bool takeOwnership=true, bool lazyRead=false)
ctor for reading from an open istream
FPBReader(const char *fname, bool lazyRead=false)
ctor for reading from a named file
FPBReader(const std::string &fname, bool lazyRead=false)
This is an overloaded member function, provided for convenience. It differs from the above function o...
unsigned int nBits() const
returns the number of bits in our fingerprints
std::vector< unsigned int > getContainingNeighbors(const ExplicitBitVect &ebv) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
double getTanimoto(unsigned int idx, const ExplicitBitVect &ebv) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::string getId(unsigned int idx) const
returns the id of the requested fingerprint
void init()
Read the data from the file and initialize internal data structures.
#define RDKIT_DATASTRUCTS_EXPORT
bool rdvalue_is(const RDValue_cast_t)
RDKIT_FINGERPRINTS_EXPORT ExplicitBitVect * getFP(const ROMol &mol, FPType fPType)