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 {
222 m->updatePropertyCache();
224 return boost::shared_ptr<ROMol>(m);
227 virtual unsigned int size()
const {
228 return rdcast<unsigned int>(mols.size());
231 std::vector<std::string> &
getMols() {
return mols; }
232 const std::vector<std::string> &
getMols()
const {
return mols; }
237 std::vector<ExplicitBitVect *> fps;
241 for (
size_t i = 0; i < fps.size(); ++i)
delete fps[i];
244 virtual unsigned int size()
const {
245 return rdcast<unsigned int>(fps.size());
250 fps.push_back(makeFingerprint(m));
251 return rdcast<unsigned int>(fps.size() - 1);
257 return rdcast<unsigned int>(fps.size() - 1);
370 boost::shared_ptr<MolHolderBase> molholder;
371 boost::shared_ptr<FPHolderBase> fpholder;
379 mols(molholder.get())
383 : molholder(molecules), fpholder(), mols(molholder.get()), fps(nullptr) {}
386 boost::shared_ptr<FPHolderBase> fingerprints)
387 : molholder(molecules),
388 fpholder(fingerprints),
389 mols(molholder.get()),
390 fps(fpholder.get()) {}
395 mols(molholder.get()),
408 boost::shared_ptr<FPHolderBase> &
getFpHolder() {
return fpholder; }
416 PRECONDITION(mols,
"Molecule holder NULL in SubstructLibrary");
457 bool recursionPossible =
true,
458 bool useChirality =
true,
459 bool useQueryQueryMatches =
false,
461 int maxResults = -1);
479 const ROMol &query,
unsigned int startIdx,
unsigned int endIdx,
480 bool recursionPossible =
true,
bool useChirality =
true,
481 bool useQueryQueryMatches =
false,
int numThreads = -1,
482 int maxResults = -1);
497 bool useChirality =
true,
498 bool useQueryQueryMatches =
false,
499 int numThreads = -1);
515 unsigned int endIdx,
bool recursionPossible =
true,
516 bool useChirality =
true,
517 bool useQueryQueryMatches =
false,
518 int numThreads = -1);
533 bool useChirality =
true,
bool useQueryQueryMatches =
false,
534 int numThreads = -1);
550 bool hasMatch(
const ROMol &query,
unsigned int startIdx,
unsigned int endIdx,
551 bool recursionPossible =
true,
bool useChirality =
true,
552 bool useQueryQueryMatches =
false,
int numThreads = -1);
558 boost::shared_ptr<ROMol>
getMol(
unsigned int idx)
const {
560 PRECONDITION(mols,
"molholder is null in SubstructLibrary");
570 PRECONDITION(mols,
"molholder is null in SubstructLibrary");
576 PRECONDITION(mols,
"molholder is null in SubstructLibrary");
577 return rdcast<unsigned int>(molholder->size());
582 mols = molholder.get();
583 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)