31 #ifndef RDK_SUBSTRUCT_LIBRARY
32 #define RDK_SUBSTRUCT_LIBRARY
62 virtual boost::shared_ptr<ROMol>
getMol(
unsigned int)
const = 0;
65 virtual unsigned int size()
const = 0;
74 std::vector<boost::shared_ptr<ROMol>> mols;
80 mols.push_back(boost::make_shared<ROMol>(m));
84 virtual boost::shared_ptr<ROMol>
getMol(
unsigned int idx)
const {
89 virtual unsigned int size()
const {
90 return rdcast<unsigned int>(mols.size());
93 std::vector<boost::shared_ptr<ROMol>> &
getMols() {
return mols; }
94 const std::vector<boost::shared_ptr<ROMol>> &
getMols()
const {
return mols; }
106 std::vector<std::string> mols;
124 virtual boost::shared_ptr<ROMol>
getMol(
unsigned int idx)
const {
126 boost::shared_ptr<ROMol> mol(
new ROMol);
131 virtual unsigned int size()
const {
132 return rdcast<unsigned int>(mols.size());
135 std::vector<std::string> &
getMols() {
return mols; }
136 const std::vector<std::string> &
getMols()
const {
return mols; }
150 std::vector<std::string> mols;
156 bool doIsomericSmiles =
true;
164 mols.push_back(smiles);
168 virtual boost::shared_ptr<ROMol>
getMol(
unsigned int idx)
const {
171 boost::shared_ptr<ROMol> mol(
SmilesToMol(mols[idx]));
175 virtual unsigned int size()
const {
176 return rdcast<unsigned int>(mols.size());
179 std::vector<std::string> &
getMols() {
return mols; }
180 const std::vector<std::string> &
getMols()
const {
return mols; }
199 std::vector<std::string> mols;
205 bool doIsomericSmiles =
true;
213 mols.push_back(smiles);
217 virtual boost::shared_ptr<ROMol>
getMol(
unsigned int idx)
const {
221 m->updatePropertyCache();
222 return boost::shared_ptr<ROMol>(m);
225 virtual unsigned int size()
const {
226 return rdcast<unsigned int>(mols.size());
229 std::vector<std::string> &
getMols() {
return mols; }
230 const std::vector<std::string> &
getMols()
const {
return mols; }
235 std::vector<ExplicitBitVect *> fps;
239 for (
size_t i = 0; i < fps.size(); ++i)
delete fps[i];
242 virtual unsigned int size()
const {
243 return rdcast<unsigned int>(fps.size());
248 fps.push_back(makeFingerprint(m));
249 return rdcast<unsigned int>(fps.size() - 1);
255 return rdcast<unsigned int>(fps.size() - 1);
368 boost::shared_ptr<MolHolderBase> molholder;
369 boost::shared_ptr<FPHolderBase> fpholder;
377 mols(molholder.get())
381 : molholder(molecules), fpholder(), mols(molholder.get()), fps(nullptr) {}
384 boost::shared_ptr<FPHolderBase> fingerprints)
385 : molholder(molecules),
386 fpholder(fingerprints),
387 mols(molholder.get()),
388 fps(fpholder.get()) {}
393 mols(molholder.get()),
406 boost::shared_ptr<FPHolderBase> &
getFpHolder() {
return fpholder; }
414 PRECONDITION(mols,
"Molecule holder NULL in SubstructLibrary");
455 bool recursionPossible =
true,
456 bool useChirality =
true,
457 bool useQueryQueryMatches =
false,
459 int maxResults = -1);
477 const ROMol &query,
unsigned int startIdx,
unsigned int endIdx,
478 bool recursionPossible =
true,
bool useChirality =
true,
479 bool useQueryQueryMatches =
false,
int numThreads = -1,
480 int maxResults = -1);
495 bool useChirality =
true,
496 bool useQueryQueryMatches =
false,
497 int numThreads = -1);
513 unsigned int endIdx,
bool recursionPossible =
true,
514 bool useChirality =
true,
515 bool useQueryQueryMatches =
false,
516 int numThreads = -1);
531 bool useChirality =
true,
bool useQueryQueryMatches =
false,
532 int numThreads = -1);
548 bool hasMatch(
const ROMol &query,
unsigned int startIdx,
unsigned int endIdx,
549 bool recursionPossible =
true,
bool useChirality =
true,
550 bool useQueryQueryMatches =
false,
int numThreads = -1);
556 boost::shared_ptr<ROMol>
getMol(
unsigned int idx)
const {
558 PRECONDITION(mols,
"molholder is null in SubstructLibrary");
568 PRECONDITION(mols,
"molholder is null in SubstructLibrary");
574 PRECONDITION(mols,
"molholder is null in SubstructLibrary");
575 return rdcast<unsigned int>(molholder->size());
580 mols = molholder.get();
581 fps = fpholder.get();
Contains general bit-comparison and similarity operations.
RDKIT_DATASTRUCTS_EXPORT bool AllProbeBitsMatch(const char *probe, const char *ref)
#define PRECONDITION(expr, mess)
pulls in the core RDKit functionality
a class for bit vectors that are densely occupied
Class to allow us to throw an IndexError from C++ and have it make it back to Python.
Concrete class that holds binary cached molecules in memory.
virtual unsigned int addMol(const ROMol &m)
const std::vector< std::string > & getMols() const
virtual unsigned int size() const
Get the current library size.
virtual boost::shared_ptr< ROMol > getMol(unsigned int idx) const
std::vector< std::string > & getMols()
unsigned int addBinary(const std::string &pickle)
Concrete class that holds smiles strings in memory.
std::vector< std::string > & getMols()
unsigned int addSmiles(const std::string &smiles)
const std::vector< std::string > & getMols() const
virtual unsigned int addMol(const ROMol &m)
virtual unsigned int size() const
Get the current library size.
virtual boost::shared_ptr< ROMol > getMol(unsigned int idx) const
Concrete class that holds trusted smiles strings in memory.
virtual unsigned int addMol(const ROMol &m)
std::vector< std::string > & getMols()
unsigned int addSmiles(const std::string &smiles)
virtual boost::shared_ptr< ROMol > getMol(unsigned int idx) const
virtual unsigned int size() const
Get the current library size.
CachedTrustedSmilesMolHolder()
const std::vector< std::string > & getMols() const
Base FPI for the fingerprinter used to rule out impossible matches.
const ExplicitBitVect & getFingerprint(unsigned int idx) const
unsigned int addMol(const ROMol &m)
Adds a molecule to the fingerprinter.
virtual unsigned int size() const
std::vector< ExplicitBitVect * > & getFingerprints()
virtual ExplicitBitVect * makeFingerprint(const ROMol &m) const =0
bool passesFilter(unsigned int idx, const ExplicitBitVect &query) const
Return false if a substructure search can never match the molecule.
const std::vector< ExplicitBitVect * > & getFingerprints() const
unsigned int addFingerprint(const ExplicitBitVect &v)
Adds a raw bit vector to the fingerprinter.
Base class API for holding molecules to substructure search.
virtual unsigned int addMol(const ROMol &m)=0
virtual unsigned int size() const =0
Get the current library size.
virtual boost::shared_ptr< ROMol > getMol(unsigned int) const =0
Concrete class that holds molecules in memory.
const std::vector< boost::shared_ptr< ROMol > > & getMols() const
virtual boost::shared_ptr< ROMol > getMol(unsigned int idx) const
std::vector< boost::shared_ptr< ROMol > > & getMols()
virtual unsigned int addMol(const ROMol &m)
virtual unsigned int size() const
Get the current library size.
static void molFromPickle(const std::string &pickle, ROMol *mol)
constructs a molecule from a pickle stored in a string
static void pickleMol(const ROMol *mol, std::ostream &ss)
pickles a molecule and sends the results to stream ss
Uses the pattern fingerprinter to rule out matches.
virtual ExplicitBitVect * makeFingerprint(const ROMol &m) const
Caller owns the vector!
RWMol is a molecule class that is intended to be edited.
Substructure Search a library of molecules.
unsigned int addMol(const ROMol &mol)
Add a molecule to the library.
boost::shared_ptr< ROMol > getMol(unsigned int idx) const
Returns the molecule at the given index.
void initFromStream(std::istream &ss)
initializes from a stream pickle
const MolHolderBase & getMolecules() const
const FPHolderBase & getFingerprints() const
bool hasMatch(const ROMol &query, unsigned int startIdx, unsigned int endIdx, bool recursionPossible=true, bool useChirality=true, bool useQueryQueryMatches=false, int numThreads=-1)
void initFromString(const std::string &text)
initializes from a string pickle
const boost::shared_ptr< FPHolderBase > & getFpHolder() const
Get the underlying molecule holder implementation.
FPHolderBase & getFingerprints()
Get the underlying fingerprint implementation.
bool hasMatch(const ROMol &query, bool recursionPossible=true, bool useChirality=true, bool useQueryQueryMatches=false, int numThreads=-1)
Returns true if any match exists for the query.
boost::shared_ptr< MolHolderBase > & getMolHolder()
Get the underlying molecule holder implementation.
unsigned int countMatches(const ROMol &query, unsigned int startIdx, unsigned int endIdx, bool recursionPossible=true, bool useChirality=true, bool useQueryQueryMatches=false, int numThreads=-1)
Return the number of matches for the query between the given indices.
boost::shared_ptr< FPHolderBase > & getFpHolder()
Get the underlying molecule holder implementation.
SubstructLibrary(boost::shared_ptr< MolHolderBase > molecules, boost::shared_ptr< FPHolderBase > fingerprints)
std::vector< unsigned int > getMatches(const ROMol &query, bool recursionPossible=true, bool useChirality=true, bool useQueryQueryMatches=false, int numThreads=-1, int maxResults=-1)
Get the matching indices for the query.
std::vector< unsigned int > getMatches(const ROMol &query, unsigned int startIdx, unsigned int endIdx, bool recursionPossible=true, bool useChirality=true, bool useQueryQueryMatches=false, int numThreads=-1, int maxResults=-1)
Get the matching indices for the query between the given indices.
unsigned int countMatches(const ROMol &query, bool recursionPossible=true, bool useChirality=true, bool useQueryQueryMatches=false, int numThreads=-1)
Return the number of matches for the query.
void resetHolders()
access required for serialization
unsigned int size() const
return the number of molecules in the library
SubstructLibrary(boost::shared_ptr< MolHolderBase > molecules)
SubstructLibrary(const std::string &pickle)
std::string Serialize() const
returns a string with a serialized (pickled) representation
const boost::shared_ptr< MolHolderBase > & getMolHolder() const
void toStream(std::ostream &ss) const
serializes (pickles) to a stream
boost::shared_ptr< ROMol > operator[](unsigned int idx)
Returns the molecule at the given index.
Class to allow us to throw a ValueError from C++ and have it make it back to Python.
#define RDKIT_SUBSTRUCTLIBRARY_EXPORT
RDKIT_CHEMREACTIONS_EXPORT void pickle(const boost::shared_ptr< EnumerationStrategyBase > &enumerator, std::ostream &ss)
pickles a EnumerationStrategy and adds the results to a stream ss
RDKIT_SMILESPARSE_EXPORT std::string MolToSmiles(const ROMol &mol, bool doIsomericSmiles=true, bool doKekule=false, int rootedAtAtom=-1, bool canonical=true, bool allBondsExplicit=false, bool allHsExplicit=false, bool doRandom=false)
returns canonical SMILES for a molecule
RDKIT_FINGERPRINTS_EXPORT ExplicitBitVect * PatternFingerprintMol(const ROMol &mol, unsigned int fpSize=2048, std::vector< unsigned int > *atomCounts=nullptr, ExplicitBitVect *setOnlyBits=nullptr, bool tautomericFingerprint=false)
Generates a topological fingerprint for a molecule using a series of pre-defined structural patterns.
RDKIT_SUBSTRUCTLIBRARY_EXPORT bool SubstructLibraryCanSerialize()
RDKIT_SMILESPARSE_EXPORT RWMol * SmilesToMol(const std::string &smi, const SmilesParserParams ¶ms)