11 #ifndef RD_FPBREADER_H_DEC2015
12 #define RD_FPBREADER_H_DEC2015
29 #include <boost/shared_ptr.hpp>
30 #include <boost/shared_array.hpp>
34 struct FPBReader_impl;
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) {}
96 if (df_owner)
delete dp_istrm;
118 if (!df_init)
return;
123 boost::shared_ptr<ExplicitBitVect>
getFP(
unsigned int idx)
const;
125 boost::shared_array<std::uint8_t>
getBytes(
unsigned int idx)
const;
128 std::string
getId(
unsigned int idx)
const;
130 std::pair<boost::shared_ptr<ExplicitBitVect>, std::string>
operator[](
131 unsigned int idx)
const {
132 return std::make_pair(
getFP(idx), getId(idx));
138 unsigned int minCount,
unsigned int maxCount);
147 double getTanimoto(
unsigned int idx,
const std::uint8_t *bv)
const;
150 boost::shared_array<std::uint8_t> bv)
const {
151 return getTanimoto(idx, bv.get());
169 const std::uint8_t *bv,
double threshold = 0.7,
170 bool usePopcountScreen =
true)
const;
173 boost::shared_array<std::uint8_t> bv,
double threshold = 0.7,
174 bool usePopcountScreen =
true)
const {
175 return getTanimotoNeighbors(bv.get(), threshold, usePopcountScreen);
180 bool usePopcountScreen =
true)
const;
192 double getTversky(
unsigned int idx,
const std::uint8_t *bv,
double ca,
195 double getTversky(
unsigned int idx, boost::shared_array<std::uint8_t> bv,
196 double ca,
double cb)
const {
197 return getTversky(idx, bv.get(), ca, cb);
218 const std::uint8_t *bv,
double ca,
double cb,
double threshold = 0.7,
219 bool usePopcountScreen =
true)
const;
222 boost::shared_array<std::uint8_t> bv,
double ca,
double cb,
223 double threshold = 0.7,
bool usePopcountScreen =
true)
const {
224 return getTverskyNeighbors(bv.get(), ca, cb, threshold, usePopcountScreen);
228 const ExplicitBitVect &ebv,
double ca,
double cb,
double threshold = 0.7,
229 bool usePopcountScreen =
true)
const;
236 const std::uint8_t *bv)
const;
239 boost::shared_array<std::uint8_t> bv)
const {
240 return getContainingNeighbors(bv.get());
247 std::istream *dp_istrm{
nullptr};
248 detail::FPBReader_impl *dp_impl{
nullptr};
249 bool df_owner{
false};
251 bool df_lazyRead{
false};
257 FPBReader(
const FPBReader &);
258 FPBReader &operator=(
const FPBReader &);
260 void _initFromFilename(
const char *fname,
bool lazyRead) {
261 std::istream *tmpStream =
static_cast<std::istream *
>(
262 new std::ifstream(fname, std::ios_base::binary));
263 if (!(*tmpStream) || (tmpStream->bad())) {
264 std::ostringstream errout;
265 errout <<
"Bad input file " << fname;
267 throw BadFileException(errout.str());
269 dp_istrm = tmpStream;
273 df_lazyRead = lazyRead;
a class for bit vectors that are densely occupied
class for reading and searching FPB files
double getTversky(unsigned int idx, const std::uint8_t *bv, double ca, double cb) const
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::pair< unsigned int, unsigned int > getFPIdsInCountRange(unsigned int minCount, unsigned int maxCount)
unsigned int length() const
returns the number of fingerprints
double getTanimoto(unsigned int idx, const std::uint8_t *bv) const
boost::shared_ptr< ExplicitBitVect > getFP(unsigned int idx) const
returns the requested fingerprint as an ExplicitBitVect
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, 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::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...
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
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...
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...
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::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
unsigned int nBits() const
returns the number of bits in our fingerprints
std::vector< unsigned int > getContainingNeighbors(const std::uint8_t *bv) const
returns indices of all fingerprints that completely contain this one
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
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...
void init()
Read the data from the file and initialize internal data structures.
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 > > 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...
#define RDKIT_DATASTRUCTS_EXPORT
RDKIT_FINGERPRINTS_EXPORT ExplicitBitVect * getFP(const ROMol &mol, FPType fPType)