RDKit: SubstructLibrary.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
SubstructLibrary.h
Go to the documentation of this file.
1// Copyright (c) 2017-2021, Novartis Institutes for BioMedical Research Inc.
2// and other RDKit contributors
3//
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are
8// met:
9//
10// * Redistributions of source code must retain the above copyright
11// notice, this list of conditions and the following disclaimer.
12// * Redistributions in binary form must reproduce the above
13// copyright notice, this list of conditions and the following
14// disclaimer in the documentation and/or other materials provided
15// with the distribution.
16// * Neither the name of Novartis Institutes for BioMedical Research Inc.
17// nor the names of its contributors may be used to endorse or promote
18// products derived from this software without specific prior written
19// permission.
20//
21// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32//
33#ifndef RDK_SUBSTRUCT_LIBRARY
34#define RDK_SUBSTRUCT_LIBRARY
35#include <utility>
36
37#include <RDGeneral/export.h>
38#include <GraphMol/RDKitBase.h>
39#include <GraphMol/MolPickler.h>
40#include <GraphMol/MolBundle.h>
41#include <GraphMol/SmilesParse/SmilesParse.h>
42#include <GraphMol/SmilesParse/SmilesWrite.h>
43#include <GraphMol/Fingerprints/Fingerprints.h>
44#include <GraphMol/Substruct/SubstructMatch.h>
45#include <DataStructs/ExplicitBitVect.h>
46#include <DataStructs/BitOps.h>
47#include <GraphMol/MolOps.h>
48#include <GraphMol/TautomerQuery/TautomerQuery.h>
49#include <GraphMol/GeneralizedSubstruct/XQMol.h>
50
51#include <algorithm>
52#include <string>
53#include <boost/lexical_cast.hpp>
54
55namespace RDKit {
56
57using GeneralizedSubstruct::ExtendedQueryMol;
58
59 RDKIT_SUBSTRUCTLIBRARY_EXPORT bool SubstructLibraryCanSerialize();
60
61//! Base class API for holding molecules to substructure search.
62/*!
63 This is an API that hides the implementation details used for
64 indexing molecules for substructure searching. It simply
65 provides an API for adding and getting molecules from a set.
66 */
67 class RDKIT_SUBSTRUCTLIBRARY_EXPORT MolHolderBase {
68 public:
69 virtual ~MolHolderBase() {}
70
71 //! Add a new molecule to the substructure search library
72 //! Returns the molecules index in the library
73 virtual unsigned int addMol(const ROMol &m) = 0;
74
75 // implementations should throw IndexError on out of range
76 virtual boost::shared_ptr<ROMol> getMol(unsigned int) const = 0;
77
78 //! Get the current library size
79 virtual unsigned int size() const = 0;
80};
81
82//! Concrete class that holds molecules in memory
83/*!
84 This is currently one of the faster implementations.
85 However it is very memory intensive.
86*/
87 class RDKIT_SUBSTRUCTLIBRARY_EXPORT MolHolder : public MolHolderBase {
88 std::vector<boost::shared_ptr<ROMol>> mols;
89
90 public:
91 MolHolder() : MolHolderBase(), mols() {}
92
93 unsigned int addMol(const ROMol &m) override {
94 mols.push_back(boost::make_shared<ROMol>(m));
95 return size() - 1;
96 }
97
98 boost::shared_ptr<ROMol> getMol(unsigned int idx) const override {
99 if (idx >= mols.size()) {
100 throw IndexErrorException(idx);
101 }
102 return mols[idx];
103 }
104
105 unsigned int size() const override {
106 return rdcast<unsigned int>(mols.size());
107 }
108
109 std::vector<boost::shared_ptr<ROMol>> &getMols() { return mols; }
110 const std::vector<boost::shared_ptr<ROMol>> &getMols() const { return mols; }
111};
112
113//! Concrete class that holds binary cached molecules in memory
114/*!
115 This implementation uses quite a bit less memory than the
116 non cached implementation. However, due to the reduced speed
117 it should be used in conjunction with a pattern fingerprinter.
118
119 See RDKit::FPHolder
120*/
121 class RDKIT_SUBSTRUCTLIBRARY_EXPORT CachedMolHolder : public MolHolderBase {
122 std::vector<std::string> mols;
123
124 public:
125 CachedMolHolder() : MolHolderBase(), mols() {}
126
127 unsigned int addMol(const ROMol &m) override {
128 mols.emplace_back();
129 MolPickler::pickleMol(m, mols.back());
130 return size() - 1;
131 }
132
133 //! Adds a pickled binary molecule, no validity checking of the input
134 //! is done.
135 unsigned int addBinary(const std::string &pickle) {
136 mols.push_back(pickle);
137 return size() - 1;
138 }
139
140 boost::shared_ptr<ROMol> getMol(unsigned int idx) const override {
141 if (idx >= mols.size()) {
142 throw IndexErrorException(idx);
143 }
144 boost::shared_ptr<ROMol> mol(new ROMol);
145 MolPickler::molFromPickle(mols[idx], mol.get());
146 return mol;
147 }
148
149 unsigned int size() const override {
150 return rdcast<unsigned int>(mols.size());
151 }
152
153 std::vector<std::string> &getMols() { return mols; }
154 const std::vector<std::string> &getMols() const { return mols; }
155};
156
157//! Concrete class that holds smiles strings in memory
158/*!
159 This implementation uses quite a bit less memory than the
160 cached binary or uncached implementation. However, due to the
161 reduced speed it should be used in conjunction with a pattern
162 fingerprinter.
163
164 See RDKit::FPHolder
165*/
166 class RDKIT_SUBSTRUCTLIBRARY_EXPORT CachedSmilesMolHolder
167 : public MolHolderBase {
168 std::vector<std::string> mols;
169
170 public:
171 CachedSmilesMolHolder() : MolHolderBase(), mols() {}
172
173 unsigned int addMol(const ROMol &m) override {
174 bool doIsomericSmiles = true;
175 mols.push_back(MolToSmiles(m, doIsomericSmiles));
176 return size() - 1;
177 }
178
179 //! Add a smiles to the dataset, no validation is done
180 //! to the inputs.
181 unsigned int addSmiles(const std::string &smiles) {
182 mols.push_back(smiles);
183 return size() - 1;
184 }
185
186 boost::shared_ptr<ROMol> getMol(unsigned int idx) const override {
187 if (idx >= mols.size()) {
188 throw IndexErrorException(idx);
189 }
190
191 boost::shared_ptr<ROMol> mol(SmilesToMol(mols[idx]));
192 return mol;
193 }
194
195 unsigned int size() const override {
196 return rdcast<unsigned int>(mols.size());
197 }
198
199 std::vector<std::string> &getMols() { return mols; }
200 const std::vector<std::string> &getMols() const { return mols; }
201};
202
203//! Concrete class that holds trusted smiles strings in memory
204/*!
205 A trusted smiles is essentially a smiles string that
206 RDKit has generated. This indicates that fewer
207 sanitization steps are required. See
208 http://rdkit.blogspot.com/2016/09/avoiding-unnecessary-work-and.html
209
210 This implementation uses quite a bit less memory than the
211 cached binary or uncached implementation. However, due to the
212 reduced speed it should be used in conjunction with a pattern
213 fingerprinter.
214
215 See RDKit::FPHolder
216*/
217 class RDKIT_SUBSTRUCTLIBRARY_EXPORT CachedTrustedSmilesMolHolder
218 : public MolHolderBase {
219 std::vector<std::string> mols;
220
221 public:
222 CachedTrustedSmilesMolHolder() : MolHolderBase(), mols() {}
223
224 unsigned int addMol(const ROMol &m) override {
225 bool doIsomericSmiles = true;
226 mols.push_back(MolToSmiles(m, doIsomericSmiles));
227 return size() - 1;
228 }
229
230 //! Add a smiles to the dataset, no validation is done
231 //! to the inputs.
232 unsigned int addSmiles(const std::string &smiles) {
233 mols.push_back(smiles);
234 return size() - 1;
235 }
236
237 boost::shared_ptr<ROMol> getMol(unsigned int idx) const override {
238 if (idx >= mols.size()) {
239 throw IndexErrorException(idx);
240 }
241
242 RWMol *m = SmilesToMol(mols[idx], 0, false);
243 if (m) {
244 m->updatePropertyCache();
245 }
246 return boost::shared_ptr<ROMol>(m);
247 }
248
249 unsigned int size() const override {
250 return rdcast<unsigned int>(mols.size());
251 }
252
253 std::vector<std::string> &getMols() { return mols; }
254 const std::vector<std::string> &getMols() const { return mols; }
255};
256
257//! Base FPI for the fingerprinter used to rule out impossible matches
258 class RDKIT_SUBSTRUCTLIBRARY_EXPORT FPHolderBase {
259 std::vector<ExplicitBitVect *> fps;
260
261 public:
262 virtual ~FPHolderBase() {
263 for (size_t i = 0; i < fps.size(); ++i) {
264 delete fps[i];
265 }
266 }
267
268 virtual unsigned int size() const { return rdcast<unsigned int>(fps.size()); }
269
270 //! Adds a molecule to the fingerprinter
271 unsigned int addMol(const ROMol &m) {
272 fps.push_back(makeFingerprint(m));
273 return rdcast<unsigned int>(fps.size() - 1);
274 }
275
276 //! Adds a raw bit vector pointer to the fingerprinter, which takes ownership
277 //! PLEASE NOTE: make sure that the passed ExplicitBitVect
278 //! is compatible with the one generated by makeFingerprint()
279 unsigned int addFingerprint(ExplicitBitVect *v) {
280 fps.push_back(v);
281 return rdcast<unsigned int>(fps.size() - 1);
282 }
283
284 //! Adds a raw bit vector to the fingerprinter
285 //! PLEASE NOTE: make sure that the passed ExplicitBitVect
286 //! is compatible with the one generated by makeFingerprint()
287 unsigned int addFingerprint(const ExplicitBitVect &v) {
288 return addFingerprint(new ExplicitBitVect(v));
289 }
290
291 //! Return false if a substructure search can never match the molecule
292 bool passesFilter(unsigned int idx, const ExplicitBitVect &query) const {
293 if (idx >= fps.size()) {
294 throw IndexErrorException(idx);
295 }
296
297 return AllProbeBitsMatch(query, *fps[idx]);
298 }
299
300 //! Get the bit vector at the specified index (throws IndexError if out of
301 //! range)
302 const ExplicitBitVect &getFingerprint(unsigned int idx) const {
303 if (idx >= fps.size()) {
304 throw IndexErrorException(idx);
305 }
306 return *fps[idx];
307 }
308
309 //! make the query vector
310 //! Caller owns the vector!
311 virtual ExplicitBitVect *makeFingerprint(const ROMol &m) const = 0;
312
313 std::vector<ExplicitBitVect *> &getFingerprints() { return fps; }
314 const std::vector<ExplicitBitVect *> &getFingerprints() const { return fps; }
315};
316
317//! Uses the pattern fingerprinter with a user-defined number of bits (default:
318//! 2048) to rule out matches
319 class RDKIT_SUBSTRUCTLIBRARY_EXPORT PatternHolder : public FPHolderBase {
320 unsigned int numBits;
321
322 public:
323 PatternHolder() : FPHolderBase(), numBits(defaultNumBits()) {}
324 PatternHolder(unsigned int numBits) : FPHolderBase(), numBits(numBits) {}
325 //! Caller owns the vector!
326 ExplicitBitVect *makeFingerprint(const ROMol &m) const override {
327 return PatternFingerprintMol(m, numBits);
328 }
329 const unsigned int &getNumBits() const { return numBits; };
330 unsigned int &getNumBits() { return numBits; };
331 static unsigned int defaultNumBits() {
332 static const unsigned int DEFAULT_NUM_BITS = 2048;
333 return DEFAULT_NUM_BITS;
334 };
335};
336
337 class RDKIT_SUBSTRUCTLIBRARY_EXPORT TautomerPatternHolder
338 : public PatternHolder {
339 public:
340 TautomerPatternHolder() : PatternHolder() {}
341 TautomerPatternHolder(unsigned int numBits) : PatternHolder(numBits) {}
342 ExplicitBitVect *makeFingerprint(const ROMol &m) const override {
343 std::vector<unsigned int> *atomCounts = nullptr;
344 ExplicitBitVect *setOnlyBits = nullptr;
345 const bool tautomericFingerprint = true;
346 return PatternFingerprintMol(m, getNumBits(), atomCounts, setOnlyBits,
347 tautomericFingerprint);
348 }
349};
350
351 class RDKIT_SUBSTRUCTLIBRARY_EXPORT KeyHolderBase {
352 public:
353 virtual ~KeyHolderBase() {}
354
355 //! Add a key to the database getting it from the molecule
356 virtual unsigned int addMol(const ROMol &m) = 0;
357
358 //! Add a key to the database, this needs to be in the same order
359 //! as the molecule, no validation is done
360 virtual unsigned int addKey(const std::string &) = 0;
361
362 // !get the key at the requested index
363 // implementations should throw IndexError on out of range
364 virtual const std::string &getKey(unsigned int) const = 0;
365
366 // !get keys from a bunch of indices
367 virtual std::vector<std::string> getKeys(
368 const std::vector<unsigned int> &indices) const = 0;
369 //! Get the current keeyholder size
370 virtual unsigned int size() const = 0;
371};
372
373 class RDKIT_SUBSTRUCTLIBRARY_EXPORT KeyFromPropHolder : public KeyHolderBase {
374 std::string propname;
375 std::vector<std::string> keys;
376 const std::string empty_string = {};
377
378 public:
379 KeyFromPropHolder(const std::string &propname = "_Name")
380 : propname(propname) {}
381
382 std::string &getPropName() { return propname; }
383 const std::string &getPropName() const { return propname; }
384
385 std::vector<std::string> &getKeys() { return keys; }
386 const std::vector<std::string> &getKeys() const { return keys; }
387
388 unsigned int addMol(const ROMol &m) override {
389 std::string key;
390 if (m.getPropIfPresent(propname, key)) {
391 keys.push_back(std::move(key));
392 } else {
393 // XXX is this a warning? it could be verbose. Should we push back the
394 // string repr of the
395 // numeric index?
396 const static std::string prefix("LIBIDX-");
397 keys.emplace_back(prefix + boost::lexical_cast<std::string>(keys.size()));
398 }
399 return keys.size() - 1u;
400 };
401
402 unsigned int addKey(const std::string &key) override {
403 keys.push_back(key);
404 return keys.size() - 1u;
405 }
406
407 const std::string &getKey(unsigned int idx) const override {
408 if (idx >= keys.size()) {
409 throw IndexErrorException(idx);
410 }
411 return keys[idx];
412 }
413
414 std::vector<std::string> getKeys(
415 const std::vector<unsigned int> &indices) const override {
416 std::vector<std::string> res;
417 std::transform(indices.begin(), indices.end(), std::back_inserter(res),
418 [=](unsigned idx) { return keys.at(idx); });
419 return res;
420 }
421 unsigned int size() const override { return keys.size(); }
422};
423
424//! Substructure Search a library of molecules
425/*! This class allows for multithreaded substructure searches of
426 large datasets.
427
428 The implementations can use fingerprints to speed up searches
429 and have molecules cached as binary forms to reduce memory
430 usage.
431
432 basic usage:
433 \code
434 SubstructLibrary lib;
435 lib.addMol(mol);
436 std::vector<unsigned int> results = lib.getMatches(query);
437 for(std::vector<unsigned int>::const_iterator matchIndex=results.begin();
438 matchIndex != results.end();
439 ++matchIndex) {
440 boost::shared_ptr<ROMol> match = lib.getMol(*matchIndex);
441 }
442 \endcode
443
444 Using different mol holders and pattern fingerprints.
445
446 \code
447 boost::shared_ptr<CachedTrustedSmilesMolHolder> molHolder = \
448 boost::make_shared<CachedTrustedSmilesMolHolder>();
449 boost::shared_ptr<PatternHolder> patternHolder = \
450 boost::make_shared<PatternHolder>();
451
452 SubstructLibrary lib(molHolder, patternHolder);
453 lib.addMol(mol);
454 \endcode
455
456 Cached molecule holders create molecules on demand. There are currently
457 three styles of cached molecules.
458
459 CachedMolHolder: stores molecules in the rdkit binary format.
460 CachedSmilesMolHolder: stores molecules in smiles format.
461 CachedTrustedSmilesMolHolder: stores molecules in smiles format.
462
463 The CachedTrustedSmilesMolHolder is made to add molecules from
464 a trusted source. This makes the basic assumption that RDKit was
465 used to sanitize and canonicalize the smiles string. In practice
466 this is considerably faster than using arbitrary smiles strings since
467 certain assumptions can be made. Molecules generated from trusted
468 smiles do not have ring information (although this is created
469 in the molecule being searched if necessary).
470
471 When loading from external data, as opposed to using the "addMol" API,
472 care must be taken to ensure that the pattern fingerprints and smiles
473 are synchronized.
474
475 Each pattern holder has an API point for making its fingerprint. This
476 is useful to ensure that the pattern stored in the database will be
477 compatible with the patterns made when analyzing queries.
478
479 \code
480 boost::shared_ptr<CachedTrustedSmilesMolHolder> molHolder = \
481 boost::make_shared<CachedTrustedSmilesMolHolder>();
482 boost::shared_ptr<PatternHolder> patternHolder = \
483 boost::make_shared<PatternHolder>();
484
485 // the PatternHolder instance is able to make fingerprints.
486 // These, of course, can be read from a file. For demonstration
487 // purposes we construct them here.
488 const std::string trustedSmiles = "c1ccccc1";
489 ROMol *m = SmilesToMol(trustedSmiles);
490 const ExplicitBitVect *bitVector = patternHolder->makeFingerprint(*m);
491
492 // The trusted smiles and bitVector can be read from any source.
493 // This is the fastest way to load a substruct library.
494 molHolder->addSmiles( trustedSmiles );
495 patternHolder->addFingerprint( *bitVector );
496 SubstructLibrary lib(molHolder, patternHolder);
497 delete m;
498 delete bitVector;
499 \endcode
500
501 Finally, using the KeyFromPropHolder will store user ids or keys.
502 By default, it uses RDKit's default _Name prop, but can be changed
503 to any property.
504
505 \code
506 boost::shared_ptr<CachedTrustedSmilesMolHolder> molHolder = \
507 boost::make_shared<CachedTrustedSmilesMolHolder>();
508 boost::shared_ptr<KeyFromPropHolder> keyHolder = \
509 boost::make_shared<KeyFromPropHolder>();
510 SubstructLibrary lib(molHolder, keyHolder);
511 ...
512
513 You can get the keys in multiple through the use of the keyholder
514 auto key = lib.getKeys().getKey(idx);
515 auto keys = lib.getKeys().getKeys(lib.GetMatch(query));
516 \endcode
517
518*/
519 class RDKIT_SUBSTRUCTLIBRARY_EXPORT SubstructLibrary {
520 boost::shared_ptr<MolHolderBase> molholder;
521 boost::shared_ptr<FPHolderBase> fpholder;
522 boost::shared_ptr<KeyHolderBase> keyholder;
523
524 MolHolderBase *mols; // used for a small optimization
525 FPHolderBase *fps{nullptr};
526 bool is_tautomerquery = false;
527 std::vector<unsigned int> searchOrder;
528
529 public:
530 SubstructLibrary()
531 : molholder(new MolHolder),
532 fpholder(),
533 keyholder(),
534 mols(molholder.get()) {}
535
536 SubstructLibrary(boost::shared_ptr<MolHolderBase> molecules)
537 : molholder(std::move(molecules)),
538 fpholder(),
539 keyholder(),
540 mols(molholder.get()),
541 fps(nullptr) {}
542
543 SubstructLibrary(boost::shared_ptr<MolHolderBase> molecules,
544 boost::shared_ptr<FPHolderBase> fingerprints)
545 : molholder(std::move(molecules)),
546 fpholder(std::move(fingerprints)),
547 keyholder(),
548 mols(molholder.get()),
549 fps(fpholder.get()) {
550 if (fpholder.get() &&
551 dynamic_cast<TautomerPatternHolder *>(fpholder.get()) != nullptr) {
552 is_tautomerquery = true;
553 }
554 }
555
556 SubstructLibrary(boost::shared_ptr<MolHolderBase> molecules,
557 boost::shared_ptr<KeyHolderBase> keys)
558 : molholder(std::move(molecules)),
559 fpholder(),
560 keyholder(std::move(keys)),
561 mols(molholder.get()),
562 fps(nullptr) {
563 if (fpholder.get() &&
564 dynamic_cast<TautomerPatternHolder *>(fpholder.get()) != nullptr) {
565 is_tautomerquery = true;
566 }
567 }
568
569 SubstructLibrary(boost::shared_ptr<MolHolderBase> molecules,
570 boost::shared_ptr<FPHolderBase> fingerprints,
571 boost::shared_ptr<KeyHolderBase> keys)
572 : molholder(std::move(molecules)),
573 fpholder(std::move(fingerprints)),
574 keyholder(std::move(keys)),
575 mols(molholder.get()),
576 fps(fpholder.get()) {
577 if (fpholder.get() &&
578 dynamic_cast<TautomerPatternHolder *>(fpholder.get()) != nullptr) {
579 is_tautomerquery = true;
580 }
581 }
582
583 SubstructLibrary(const std::string &pickle)
584 : molholder(new MolHolder),
585 fpholder(),
586 mols(molholder.get()),
587 fps(nullptr) {
588 initFromString(pickle);
589 if (fpholder.get() &&
590 dynamic_cast<TautomerPatternHolder *>(fpholder.get()) != nullptr) {
591 is_tautomerquery = true;
592 }
593 }
594
595 //! Get the underlying molecule holder implementation
596 boost::shared_ptr<MolHolderBase> &getMolHolder() { return molholder; }
597
598 const boost::shared_ptr<MolHolderBase> &getMolHolder() const {
599 return molholder;
600 }
601
602 //! Get the underlying molecule holder implementation
603 boost::shared_ptr<FPHolderBase> &getFpHolder() { return fpholder; }
604
605 //! Get the underlying molecule holder implementation
606 const boost::shared_ptr<FPHolderBase> &getFpHolder() const {
607 return fpholder;
608 }
609
610 //! Get the underlying molecule holder implementation
611 boost::shared_ptr<KeyHolderBase> &getKeyHolder() { return keyholder; }
612
613 //! Get the underlying molecule holder implementation
614 const boost::shared_ptr<KeyHolderBase> &getKeyHolder() const {
615 return keyholder;
616 }
617
618 const MolHolderBase &getMolecules() const {
619 PRECONDITION(mols, "Molecule holder NULL in SubstructLibrary");
620 return *mols;
621 }
622
623 //! Get the underlying fingerprint implementation.
624 /*! Throws a value error if no fingerprints have been set */
625 FPHolderBase &getFingerprints() {
626 if (!fps) {
627 throw ValueErrorException("Substruct Library does not have fingerprints");
628 }
629 return *fps;
630 }
631
632 const FPHolderBase &getFingerprints() const {
633 if (!fps) {
634 throw ValueErrorException("Substruct Library does not have fingerprints");
635 }
636 return *fps;
637 }
638
639 //! Get the underlying key holder implementation.
640 /*! Throws a value error if no keyholder have been set */
641 KeyHolderBase &getKeys() {
642 if (!keyholder.get()) {
643 throw ValueErrorException("Substruct Library does not have fingerprints");
644 }
645 return *keyholder.get();
646 }
647
648 //! Get the underlying key holder implementation.
649 /*! Throws a value error if no keyholder have been set */
650 const KeyHolderBase &getKeys() const {
651 if (!keyholder.get()) {
652 throw ValueErrorException("Substruct Library does not have fingerprints");
653 }
654 return *keyholder.get();
655 }
656
657 //! Add a molecule to the library
658 /*!
659 \param mol Molecule to add
660
661 returns index for the molecule in the library
662 */
663 unsigned int addMol(const ROMol &mol);
664
665 //! Get the matching indices for the query
666 /*!
667 \param query Query or Tautomer Query to match against molecules
668 \param recursionPossible flags whether or not recursive matches are allowed
669 [default true]
670 \param useChirality use atomic CIP codes as part of the comparison
671 [default true]
672 \param useQueryQueryMatches if set, the contents of atom and bond queries
673 will be used as part of the matching
674 [default false]
675 \param numThreads If -1 use all available processors [default -1]
676 \param maxResults Maximum results to return, -1 means return all
677 [default -1]
678 */
679 template <class Query>
680 std::vector<unsigned int> getMatches(const Query &query,
681 bool recursionPossible = true,
682 bool useChirality = true,
683 bool useQueryQueryMatches = false,
684 int numThreads = -1,
685 int maxResults = -1) const {
686 SubstructMatchParameters params;
687 params.recursionPossible = recursionPossible;
688 params.useChirality = useChirality;
689 params.useQueryQueryMatches = useQueryQueryMatches;
690 return getMatches(query, 0, size(), params, numThreads, maxResults);
691 }
692 //! overload
693 template <class Query>
694 std::vector<unsigned int> getMatches(const Query &query,
695 const SubstructMatchParameters &params,
696 int numThreads = -1,
697 int maxResults = -1) const {
698 return getMatches(query, 0, size(), params, numThreads, maxResults);
699 }
700 //! Get the matching indices for the query between the given indices
701 /*!
702 \param query Query to match against molecules
703 \param startIdx Start index of the search
704 \param endIdx Ending idx (non-inclusive) of the search.
705 \param recursionPossible flags whether or not recursive matches are allowed
706 [default true]
707 \param useChirality use atomic CIP codes as part of the comparison
708 [default true]
709 \param useQueryQueryMatches if set, the contents of atom and bond queries
710 will be used as part of the matching
711 [default false]
712 \param numThreads If -1 use all available processors [default -1]
713 \param maxResults Maximum results to return, -1 means return all
714 [default -1]
715 */
716 template <class Query>
717 std::vector<unsigned int> getMatches(
718 const Query &query, unsigned int startIdx, unsigned int endIdx,
719 bool recursionPossible = true, bool useChirality = true,
720 bool useQueryQueryMatches = false, int numThreads = -1,
721 int maxResults = -1) const {
722 SubstructMatchParameters params;
723 params.recursionPossible = recursionPossible;
724 params.useChirality = useChirality;
725 params.useQueryQueryMatches = useQueryQueryMatches;
726 return getMatches(query, startIdx, endIdx, params, numThreads, maxResults);
727 };
728 //! overload
729 std::vector<unsigned int> getMatches(const ROMol &query,
730 unsigned int startIdx,
731 unsigned int endIdx,
732 const SubstructMatchParameters &params,
733 int numThreads = -1,
734 int maxResults = -1) const;
735 //! overload
736 std::vector<unsigned int> getMatches(const MolBundle &query,
737 unsigned int startIdx,
738 unsigned int endIdx,
739 const SubstructMatchParameters &params,
740 int numThreads = -1,
741 int maxResults = -1) const;
742 //! overload
743 std::vector<unsigned int> getMatches(const TautomerQuery &query,
744 unsigned int startIdx,
745 unsigned int endIdx,
746 const SubstructMatchParameters &params,
747 int numThreads = -1,
748 int maxResults = -1) const;
749 //! overload
750 std::vector<unsigned int> getMatches(const ExtendedQueryMol &query,
751 unsigned int startIdx,
752 unsigned int endIdx,
753 const SubstructMatchParameters &params,
754 int numThreads = -1,
755 int maxResults = -1) const;
756
757 //! Return the number of matches for the query
758 /*!
759 \param query Molecule or Tautomer Query to match against molecules
760 \param recursionPossible flags whether or not recursive matches are allowed
761 [default true]
762 \param useChirality use atomic CIP codes as part of the comparison
763 [default true]
764 \param useQueryQueryMatches if set, the contents of atom and bond queries
765 will be used as part of the matching
766 [default false]
767 \param numThreads If -1 use all available processors [default -1]
768 */
769 template <class Query>
770 unsigned int countMatches(const Query &query, bool recursionPossible = true,
771 bool useChirality = true,
772 bool useQueryQueryMatches = false,
773 int numThreads = -1) const {
774 SubstructMatchParameters params;
775 params.recursionPossible = recursionPossible;
776 params.useChirality = useChirality;
777 params.useQueryQueryMatches = useQueryQueryMatches;
778 return countMatches(query, 0, size(), params, numThreads);
779 }
780 //! overload
781 template <class Query>
782 unsigned int countMatches(const Query &query,
783 const SubstructMatchParameters &params,
784 int numThreads = -1) const {
785 return countMatches(query, 0, size(), params, numThreads);
786 }
787
788 //! Return the number of matches for the query
789
790 //! Return the number of matches for the query between the given indices
791 /*!
792 \param query Query to match against molecules
793 \param startIdx Start index of the search
794 \param endIdx Ending idx (non-inclusive) of the search.
795 \param recursionPossible flags whether or not recursive matches are allowed
796 [default true]
797 \param useChirality use atomic CIP codes as part of the comparison
798 [default true]
799 \param useQueryQueryMatches if set, the contents of atom and bond queries
800 will be used as part of the matching
801 [default false]
802 \param numThreads If -1 use all available processors [default -1]
803 */
804 template <class Query>
805 unsigned int countMatches(const Query &query, unsigned int startIdx,
806 unsigned int endIdx, bool recursionPossible = true,
807 bool useChirality = true,
808 bool useQueryQueryMatches = false,
809 int numThreads = -1) const {
810 SubstructMatchParameters params;
811 params.recursionPossible = recursionPossible;
812 params.useChirality = useChirality;
813 params.useQueryQueryMatches = useQueryQueryMatches;
814 return countMatches(query, startIdx, endIdx, params, numThreads);
815 };
816
817 //! overload
818 unsigned int countMatches(const ROMol &query, unsigned int startIdx,
819 unsigned int endIdx,
820 const SubstructMatchParameters &params,
821 int numThreads = -1) const;
822 //! overload
823 unsigned int countMatches(const TautomerQuery &query, unsigned int startIdx,
824 unsigned int endIdx,
825 const SubstructMatchParameters &params,
826 int numThreads = -1) const;
827 //! overload
828 unsigned int countMatches(const MolBundle &query, unsigned int startIdx,
829 unsigned int endIdx,
830 const SubstructMatchParameters &params,
831 int numThreads = -1) const;
832 //! overload
833 unsigned int countMatches(const ExtendedQueryMol &query,
834 unsigned int startIdx, unsigned int endIdx,
835 const SubstructMatchParameters &params,
836 int numThreads = -1) const;
837
838 //! Returns true if any match exists for the query
839 /*!
840 \param query Molecule or Tautomer Query to match against molecules
841 \param recursionPossible flags whether or not recursive matches are allowed
842 [default true]
843 \param useChirality use atomic CIP codes as part of the comparison
844 [default true]
845 \param useQueryQueryMatches if set, the contents of atom and bond queries
846 will be used as part of the matching
847 [default false]
848 \param numThreads If -1 use all available processors [default -1]
849 */
850 template <class Query>
851 bool hasMatch(const Query &query, bool recursionPossible = true,
852 bool useChirality = true, bool useQueryQueryMatches = false,
853 int numThreads = -1) const {
854 SubstructMatchParameters params;
855 params.recursionPossible = recursionPossible;
856 params.useChirality = useChirality;
857 params.useQueryQueryMatches = useQueryQueryMatches;
858 return hasMatch(query, 0, size(), params, numThreads);
859 }
860 //! overload
861 template <class Query>
862 bool hasMatch(const Query &query, const SubstructMatchParameters &params,
863 int numThreads = -1) const {
864 return hasMatch(query, 0, size(), params, numThreads);
865 }
866 //! Returns true if any match exists for the query between the specified
867 //! indices
868 /*!
869 \param query Query to match against molecules
870 \param startIdx Start index of the search
871 \param endIdx Ending idx (inclusive) of the search.
872 \param recursionPossible flags whether or not recursive matches are
873 allowed [default true] \param useChirality use atomic CIP codes as part
874 of the comparison [default true] \param useQueryQueryMatches if set, the
875 contents of atom and bond queries will be used as part of the matching
876 [default false]
877 \param numThreads If -1 use all available processors [default -1]
878 */
879 template <class Query>
880 bool hasMatch(const Query &query, unsigned int startIdx, unsigned int endIdx,
881 bool recursionPossible = true, bool useChirality = true,
882 bool useQueryQueryMatches = false, int numThreads = -1) const {
883 SubstructMatchParameters params;
884 params.recursionPossible = recursionPossible;
885 params.useChirality = useChirality;
886 params.useQueryQueryMatches = useQueryQueryMatches;
887 return hasMatch(query, startIdx, endIdx, params, numThreads);
888 };
889 //! overload
890 bool hasMatch(const ROMol &query, unsigned int startIdx, unsigned int endIdx,
891 const SubstructMatchParameters &params,
892 int numThreads = -1) const;
893 //! overload
894 bool hasMatch(const TautomerQuery &query, unsigned int startIdx,
895 unsigned int endIdx, const SubstructMatchParameters &params,
896 int numThreads = -1) const;
897 //! overload
898 bool hasMatch(const MolBundle &query, unsigned int startIdx,
899 unsigned int endIdx, const SubstructMatchParameters &params,
900 int numThreads = -1) const;
901 //! overload
902 bool hasMatch(const ExtendedQueryMol &query, unsigned int startIdx,
903 unsigned int endIdx, const SubstructMatchParameters &params,
904 int numThreads = -1) const;
905 //! Returns the molecule at the given index
906 /*!
907 \param idx Index of the molecule in the library (n.b. could contain
908 null)
909 */
910 boost::shared_ptr<ROMol> getMol(unsigned int idx) const {
911 // expects implementation to throw IndexError if out of range
912 PRECONDITION(mols, "molholder is null in SubstructLibrary");
913 return mols->getMol(idx);
914 }
915
916 //! Returns the molecule at the given index
917 /*!
918 \param idx Index of the molecule in the library (n.b. could contain
919 null)
920 */
921 boost::shared_ptr<ROMol> operator[](unsigned int idx) {
922 // expects implementation to throw IndexError if out of range
923 PRECONDITION(mols, "molholder is null in SubstructLibrary");
924 return mols->getMol(idx);
925 }
926
927 //! return the number of molecules in the library
928 unsigned int size() const {
929 PRECONDITION(mols, "molholder is null in SubstructLibrary");
930 return rdcast<unsigned int>(molholder->size());
931 }
932
933 //! does error checking
934 void setSearchOrder(const std::vector<unsigned int> &order) {
935 for (const auto idx : order) {
936 if (idx >= mols->size()) {
937 throw IndexErrorException(idx);
938 }
939 }
940 searchOrder = order;
941 }
942
943 const std::vector<unsigned int> &getSearchOrder() const {
944 return searchOrder;
945 }
946
947 std::vector<unsigned int> &getSearchOrder() { return searchOrder; }
948 //! access required for serialization
949 void resetHolders() {
950 is_tautomerquery = false;
951 mols = molholder.get();
952 fps = fpholder.get();
953 if (fps && dynamic_cast<TautomerPatternHolder *>(fps) != nullptr) {
954 is_tautomerquery = true;
955 }
956 }
957
958 //! serializes (pickles) to a stream
959 void toStream(std::ostream &ss) const;
960 //! returns a string with a serialized (pickled) representation
961 std::string Serialize() const;
962 //! initializes from a stream pickle
963 void initFromStream(std::istream &ss);
964 //! initializes from a string pickle
965 void initFromString(const std::string &text);
966};
967} // namespace RDKit
968
969#include "SubstructLibrarySerialization.h"
970#endif
BitOps.h
Contains general bit-comparison and similarity operations.
AllProbeBitsMatch
RDKIT_DATASTRUCTS_EXPORT bool AllProbeBitsMatch(const char *probe, const char *ref)
ExplicitBitVect.h
Fingerprints.h
rdcast
#define rdcast
Definition Invariant.h:191
PRECONDITION
#define PRECONDITION(expr, mess)
Definition Invariant.h:108
MolBundle.h
Defines a class for managing bundles of molecules.
MolOps.h
MolPickler.h
RDKitBase.h
pulls in the core RDKit functionality
SmilesParse.h
SmilesWrite.h
SubstructLibrarySerialization.h
SubstructMatch.h
TautomerQuery.h
XQMol.h
ExplicitBitVect
a class for bit vectors that are densely occupied
Definition ExplicitBitVect.h:29
IndexErrorException
Class to allow us to throw an IndexError from C++ and have it make it back to Python.
Definition Exceptions.h:20
RDKit::CachedMolHolder::getMols
std::vector< std::string > & getMols()
Definition SubstructLibrary.h:153
RDKit::CachedMolHolder::size
unsigned int size() const override
Get the current library size.
Definition SubstructLibrary.h:149
RDKit::CachedMolHolder::addMol
unsigned int addMol(const ROMol &m) override
Definition SubstructLibrary.h:127
RDKit::CachedMolHolder::CachedMolHolder
CachedMolHolder()
Definition SubstructLibrary.h:125
RDKit::CachedMolHolder::getMol
boost::shared_ptr< ROMol > getMol(unsigned int idx) const override
Definition SubstructLibrary.h:140
RDKit::CachedMolHolder::getMols
const std::vector< std::string > & getMols() const
Definition SubstructLibrary.h:154
RDKit::CachedMolHolder::addBinary
unsigned int addBinary(const std::string &pickle)
Definition SubstructLibrary.h:135
RDKit::CachedSmilesMolHolder::CachedSmilesMolHolder
CachedSmilesMolHolder()
Definition SubstructLibrary.h:171
RDKit::CachedSmilesMolHolder::getMols
std::vector< std::string > & getMols()
Definition SubstructLibrary.h:199
RDKit::CachedSmilesMolHolder::addSmiles
unsigned int addSmiles(const std::string &smiles)
Definition SubstructLibrary.h:181
RDKit::CachedSmilesMolHolder::getMols
const std::vector< std::string > & getMols() const
Definition SubstructLibrary.h:200
RDKit::CachedSmilesMolHolder::addMol
unsigned int addMol(const ROMol &m) override
Definition SubstructLibrary.h:173
RDKit::CachedSmilesMolHolder::getMol
boost::shared_ptr< ROMol > getMol(unsigned int idx) const override
Definition SubstructLibrary.h:186
RDKit::CachedSmilesMolHolder::size
unsigned int size() const override
Get the current library size.
Definition SubstructLibrary.h:195
RDKit::CachedTrustedSmilesMolHolder::getMols
std::vector< std::string > & getMols()
Definition SubstructLibrary.h:253
RDKit::CachedTrustedSmilesMolHolder::addSmiles
unsigned int addSmiles(const std::string &smiles)
Definition SubstructLibrary.h:232
RDKit::CachedTrustedSmilesMolHolder::addMol
unsigned int addMol(const ROMol &m) override
Definition SubstructLibrary.h:224
RDKit::CachedTrustedSmilesMolHolder::getMols
const std::vector< std::string > & getMols() const
Definition SubstructLibrary.h:254
RDKit::CachedTrustedSmilesMolHolder::getMol
boost::shared_ptr< ROMol > getMol(unsigned int idx) const override
Definition SubstructLibrary.h:237
RDKit::CachedTrustedSmilesMolHolder::size
unsigned int size() const override
Get the current library size.
Definition SubstructLibrary.h:249
RDKit::CachedTrustedSmilesMolHolder::CachedTrustedSmilesMolHolder
CachedTrustedSmilesMolHolder()
Definition SubstructLibrary.h:222
RDKit::FPHolderBase
Base FPI for the fingerprinter used to rule out impossible matches.
Definition SubstructLibrary.h:258
RDKit::FPHolderBase::getFingerprints
std::vector< ExplicitBitVect * > & getFingerprints()
Definition SubstructLibrary.h:313
RDKit::FPHolderBase::addMol
unsigned int addMol(const ROMol &m)
Adds a molecule to the fingerprinter.
Definition SubstructLibrary.h:271
RDKit::FPHolderBase::size
virtual unsigned int size() const
Definition SubstructLibrary.h:268
RDKit::FPHolderBase::getFingerprints
const std::vector< ExplicitBitVect * > & getFingerprints() const
Definition SubstructLibrary.h:314
RDKit::FPHolderBase::~FPHolderBase
virtual ~FPHolderBase()
Definition SubstructLibrary.h:262
RDKit::FPHolderBase::passesFilter
bool passesFilter(unsigned int idx, const ExplicitBitVect &query) const
Return false if a substructure search can never match the molecule.
Definition SubstructLibrary.h:292
RDKit::FPHolderBase::addFingerprint
unsigned int addFingerprint(ExplicitBitVect *v)
Definition SubstructLibrary.h:279
RDKit::FPHolderBase::getFingerprint
const ExplicitBitVect & getFingerprint(unsigned int idx) const
Definition SubstructLibrary.h:302
RDKit::FPHolderBase::addFingerprint
unsigned int addFingerprint(const ExplicitBitVect &v)
Definition SubstructLibrary.h:287
RDKit::FPHolderBase::makeFingerprint
virtual ExplicitBitVect * makeFingerprint(const ROMol &m) const =0
RDKit::KeyFromPropHolder::KeyFromPropHolder
KeyFromPropHolder(const std::string &propname="_Name")
Definition SubstructLibrary.h:379
RDKit::KeyFromPropHolder::getKey
const std::string & getKey(unsigned int idx) const override
Definition SubstructLibrary.h:407
RDKit::KeyFromPropHolder::addKey
unsigned int addKey(const std::string &key) override
Definition SubstructLibrary.h:402
RDKit::KeyFromPropHolder::size
unsigned int size() const override
Get the current keeyholder size.
Definition SubstructLibrary.h:421
RDKit::KeyFromPropHolder::getKeys
const std::vector< std::string > & getKeys() const
Definition SubstructLibrary.h:386
RDKit::KeyFromPropHolder::getKeys
std::vector< std::string > & getKeys()
Definition SubstructLibrary.h:385
RDKit::KeyFromPropHolder::getKeys
std::vector< std::string > getKeys(const std::vector< unsigned int > &indices) const override
Definition SubstructLibrary.h:414
RDKit::KeyFromPropHolder::getPropName
const std::string & getPropName() const
Definition SubstructLibrary.h:383
RDKit::KeyFromPropHolder::addMol
unsigned int addMol(const ROMol &m) override
Add a key to the database getting it from the molecule.
Definition SubstructLibrary.h:388
RDKit::KeyFromPropHolder::getPropName
std::string & getPropName()
Definition SubstructLibrary.h:382
RDKit::KeyHolderBase
Definition SubstructLibrary.h:351
RDKit::KeyHolderBase::getKeys
virtual std::vector< std::string > getKeys(const std::vector< unsigned int > &indices) const =0
RDKit::KeyHolderBase::getKey
virtual const std::string & getKey(unsigned int) const =0
RDKit::KeyHolderBase::~KeyHolderBase
virtual ~KeyHolderBase()
Definition SubstructLibrary.h:353
RDKit::KeyHolderBase::addMol
virtual unsigned int addMol(const ROMol &m)=0
Add a key to the database getting it from the molecule.
RDKit::KeyHolderBase::size
virtual unsigned int size() const =0
Get the current keeyholder size.
RDKit::KeyHolderBase::addKey
virtual unsigned int addKey(const std::string &)=0
RDKit::MolBundle
MolBundle contains a collection of related ROMols.
Definition MolBundle.h:59
RDKit::MolHolderBase
Base class API for holding molecules to substructure search.
Definition SubstructLibrary.h:67
RDKit::MolHolderBase::addMol
virtual unsigned int addMol(const ROMol &m)=0
RDKit::MolHolderBase::size
virtual unsigned int size() const =0
Get the current library size.
RDKit::MolHolderBase::getMol
virtual boost::shared_ptr< ROMol > getMol(unsigned int) const =0
RDKit::MolHolderBase::~MolHolderBase
virtual ~MolHolderBase()
Definition SubstructLibrary.h:69
RDKit::MolHolder
Concrete class that holds molecules in memory.
Definition SubstructLibrary.h:87
RDKit::MolHolder::MolHolder
MolHolder()
Definition SubstructLibrary.h:91
RDKit::MolHolder::addMol
unsigned int addMol(const ROMol &m) override
Definition SubstructLibrary.h:93
RDKit::MolHolder::getMols
const std::vector< boost::shared_ptr< ROMol > > & getMols() const
Definition SubstructLibrary.h:110
RDKit::MolHolder::size
unsigned int size() const override
Get the current library size.
Definition SubstructLibrary.h:105
RDKit::MolHolder::getMol
boost::shared_ptr< ROMol > getMol(unsigned int idx) const override
Definition SubstructLibrary.h:98
RDKit::MolHolder::getMols
std::vector< boost::shared_ptr< ROMol > > & getMols()
Definition SubstructLibrary.h:109
RDKit::MolPickler::molFromPickle
static void molFromPickle(const std::string &pickle, ROMol *mol, unsigned int propertyFlags)
constructs a molecule from a pickle stored in a string
RDKit::MolPickler::pickleMol
static void pickleMol(const ROMol *mol, std::ostream &ss)
pickles a molecule and sends the results to stream ss
RDKit::PatternHolder::PatternHolder
PatternHolder(unsigned int numBits)
Definition SubstructLibrary.h:324
RDKit::PatternHolder::getNumBits
const unsigned int & getNumBits() const
Definition SubstructLibrary.h:329
RDKit::PatternHolder::getNumBits
unsigned int & getNumBits()
Definition SubstructLibrary.h:330
RDKit::PatternHolder::defaultNumBits
static unsigned int defaultNumBits()
Definition SubstructLibrary.h:331
RDKit::PatternHolder::PatternHolder
PatternHolder()
Definition SubstructLibrary.h:323
RDKit::PatternHolder::makeFingerprint
ExplicitBitVect * makeFingerprint(const ROMol &m) const override
Caller owns the vector!
Definition SubstructLibrary.h:326
RDKit::ROMol
Definition ROMol.h:199
RDKit::RWMol
RWMol is a molecule class that is intended to be edited.
Definition RWMol.h:32
RDKit::SubstructLibrary::countMatches
unsigned int countMatches(const Query &query, bool recursionPossible=true, bool useChirality=true, bool useQueryQueryMatches=false, int numThreads=-1) const
Return the number of matches for the query.
Definition SubstructLibrary.h:770
RDKit::SubstructLibrary::countMatches
unsigned int countMatches(const ExtendedQueryMol &query, unsigned int startIdx, unsigned int endIdx, const SubstructMatchParameters &params, int numThreads=-1) const
overload
RDKit::SubstructLibrary::addMol
unsigned int addMol(const ROMol &mol)
Add a molecule to the library.
RDKit::SubstructLibrary::getMatches
std::vector< unsigned int > getMatches(const ROMol &query, unsigned int startIdx, unsigned int endIdx, const SubstructMatchParameters &params, int numThreads=-1, int maxResults=-1) const
overload
RDKit::SubstructLibrary::initFromStream
void initFromStream(std::istream &ss)
initializes from a stream pickle
RDKit::SubstructLibrary::getKeys
KeyHolderBase & getKeys()
Get the underlying key holder implementation.
Definition SubstructLibrary.h:641
RDKit::SubstructLibrary::getMatches
std::vector< unsigned int > getMatches(const ExtendedQueryMol &query, unsigned int startIdx, unsigned int endIdx, const SubstructMatchParameters &params, int numThreads=-1, int maxResults=-1) const
overload
RDKit::SubstructLibrary::getMol
boost::shared_ptr< ROMol > getMol(unsigned int idx) const
Returns the molecule at the given index.
Definition SubstructLibrary.h:910
RDKit::SubstructLibrary::getMolHolder
boost::shared_ptr< MolHolderBase > & getMolHolder()
Get the underlying molecule holder implementation.
Definition SubstructLibrary.h:596
RDKit::SubstructLibrary::hasMatch
bool hasMatch(const Query &query, bool recursionPossible=true, bool useChirality=true, bool useQueryQueryMatches=false, int numThreads=-1) const
Returns true if any match exists for the query.
Definition SubstructLibrary.h:851
RDKit::SubstructLibrary::SubstructLibrary
SubstructLibrary(boost::shared_ptr< MolHolderBase > molecules, boost::shared_ptr< FPHolderBase > fingerprints, boost::shared_ptr< KeyHolderBase > keys)
Definition SubstructLibrary.h:569
RDKit::SubstructLibrary::SubstructLibrary
SubstructLibrary()
Definition SubstructLibrary.h:530
RDKit::SubstructLibrary::countMatches
unsigned int countMatches(const Query &query, unsigned int startIdx, unsigned int endIdx, bool recursionPossible=true, bool useChirality=true, bool useQueryQueryMatches=false, int numThreads=-1) const
Return the number of matches for the query.
Definition SubstructLibrary.h:805
RDKit::SubstructLibrary::getMatches
std::vector< unsigned int > getMatches(const MolBundle &query, unsigned int startIdx, unsigned int endIdx, const SubstructMatchParameters &params, int numThreads=-1, int maxResults=-1) const
overload
RDKit::SubstructLibrary::getMatches
std::vector< unsigned int > getMatches(const Query &query, const SubstructMatchParameters &params, int numThreads=-1, int maxResults=-1) const
overload
Definition SubstructLibrary.h:694
RDKit::SubstructLibrary::getFpHolder
boost::shared_ptr< FPHolderBase > & getFpHolder()
Get the underlying molecule holder implementation.
Definition SubstructLibrary.h:603
RDKit::SubstructLibrary::getMatches
std::vector< unsigned int > getMatches(const Query &query, bool recursionPossible=true, bool useChirality=true, bool useQueryQueryMatches=false, int numThreads=-1, int maxResults=-1) const
Get the matching indices for the query.
Definition SubstructLibrary.h:680
RDKit::SubstructLibrary::getMolecules
const MolHolderBase & getMolecules() const
Definition SubstructLibrary.h:618
RDKit::SubstructLibrary::initFromString
void initFromString(const std::string &text)
initializes from a string pickle
RDKit::SubstructLibrary::countMatches
unsigned int countMatches(const Query &query, const SubstructMatchParameters &params, int numThreads=-1) const
overload
Definition SubstructLibrary.h:782
RDKit::SubstructLibrary::getKeys
const KeyHolderBase & getKeys() const
Get the underlying key holder implementation.
Definition SubstructLibrary.h:650
RDKit::SubstructLibrary::getKeyHolder
const boost::shared_ptr< KeyHolderBase > & getKeyHolder() const
Get the underlying molecule holder implementation.
Definition SubstructLibrary.h:614
RDKit::SubstructLibrary::hasMatch
bool hasMatch(const ExtendedQueryMol &query, unsigned int startIdx, unsigned int endIdx, const SubstructMatchParameters &params, int numThreads=-1) const
overload
RDKit::SubstructLibrary::hasMatch
bool hasMatch(const ROMol &query, unsigned int startIdx, unsigned int endIdx, const SubstructMatchParameters &params, int numThreads=-1) const
overload
RDKit::SubstructLibrary::countMatches
unsigned int countMatches(const MolBundle &query, unsigned int startIdx, unsigned int endIdx, const SubstructMatchParameters &params, int numThreads=-1) const
overload
RDKit::SubstructLibrary::getFingerprints
FPHolderBase & getFingerprints()
Get the underlying fingerprint implementation.
Definition SubstructLibrary.h:625
RDKit::SubstructLibrary::setSearchOrder
void setSearchOrder(const std::vector< unsigned int > &order)
does error checking
Definition SubstructLibrary.h:934
RDKit::SubstructLibrary::hasMatch
bool hasMatch(const Query &query, unsigned int startIdx, unsigned int endIdx, bool recursionPossible=true, bool useChirality=true, bool useQueryQueryMatches=false, int numThreads=-1) const
Definition SubstructLibrary.h:880
RDKit::SubstructLibrary::getFingerprints
const FPHolderBase & getFingerprints() const
Definition SubstructLibrary.h:632
RDKit::SubstructLibrary::SubstructLibrary
SubstructLibrary(boost::shared_ptr< MolHolderBase > molecules, boost::shared_ptr< KeyHolderBase > keys)
Definition SubstructLibrary.h:556
RDKit::SubstructLibrary::hasMatch
bool hasMatch(const MolBundle &query, unsigned int startIdx, unsigned int endIdx, const SubstructMatchParameters &params, int numThreads=-1) const
overload
RDKit::SubstructLibrary::countMatches
unsigned int countMatches(const ROMol &query, unsigned int startIdx, unsigned int endIdx, const SubstructMatchParameters &params, int numThreads=-1) const
overload
RDKit::SubstructLibrary::hasMatch
bool hasMatch(const Query &query, const SubstructMatchParameters &params, int numThreads=-1) const
overload
Definition SubstructLibrary.h:862
RDKit::SubstructLibrary::SubstructLibrary
SubstructLibrary(boost::shared_ptr< MolHolderBase > molecules, boost::shared_ptr< FPHolderBase > fingerprints)
Definition SubstructLibrary.h:543
RDKit::SubstructLibrary::getKeyHolder
boost::shared_ptr< KeyHolderBase > & getKeyHolder()
Get the underlying molecule holder implementation.
Definition SubstructLibrary.h:611
RDKit::SubstructLibrary::hasMatch
bool hasMatch(const TautomerQuery &query, unsigned int startIdx, unsigned int endIdx, const SubstructMatchParameters &params, int numThreads=-1) const
overload
RDKit::SubstructLibrary::getSearchOrder
const std::vector< unsigned int > & getSearchOrder() const
Definition SubstructLibrary.h:943
RDKit::SubstructLibrary::resetHolders
void resetHolders()
access required for serialization
Definition SubstructLibrary.h:949
RDKit::SubstructLibrary::size
unsigned int size() const
return the number of molecules in the library
Definition SubstructLibrary.h:928
RDKit::SubstructLibrary::getMatches
std::vector< unsigned int > getMatches(const Query &query, unsigned int startIdx, unsigned int endIdx, bool recursionPossible=true, bool useChirality=true, bool useQueryQueryMatches=false, int numThreads=-1, int maxResults=-1) const
Get the matching indices for the query between the given indices.
Definition SubstructLibrary.h:717
RDKit::SubstructLibrary::SubstructLibrary
SubstructLibrary(boost::shared_ptr< MolHolderBase > molecules)
Definition SubstructLibrary.h:536
RDKit::SubstructLibrary::SubstructLibrary
SubstructLibrary(const std::string &pickle)
Definition SubstructLibrary.h:583
RDKit::SubstructLibrary::Serialize
std::string Serialize() const
returns a string with a serialized (pickled) representation
RDKit::SubstructLibrary::countMatches
unsigned int countMatches(const TautomerQuery &query, unsigned int startIdx, unsigned int endIdx, const SubstructMatchParameters &params, int numThreads=-1) const
overload
RDKit::SubstructLibrary::getMatches
std::vector< unsigned int > getMatches(const TautomerQuery &query, unsigned int startIdx, unsigned int endIdx, const SubstructMatchParameters &params, int numThreads=-1, int maxResults=-1) const
overload
RDKit::SubstructLibrary::toStream
void toStream(std::ostream &ss) const
serializes (pickles) to a stream
RDKit::SubstructLibrary::operator[]
boost::shared_ptr< ROMol > operator[](unsigned int idx)
Returns the molecule at the given index.
Definition SubstructLibrary.h:921
RDKit::SubstructLibrary::getFpHolder
const boost::shared_ptr< FPHolderBase > & getFpHolder() const
Get the underlying molecule holder implementation.
Definition SubstructLibrary.h:606
RDKit::SubstructLibrary::getMolHolder
const boost::shared_ptr< MolHolderBase > & getMolHolder() const
Definition SubstructLibrary.h:598
RDKit::SubstructLibrary::getSearchOrder
std::vector< unsigned int > & getSearchOrder()
Definition SubstructLibrary.h:947
RDKit::TautomerPatternHolder
Definition SubstructLibrary.h:338
RDKit::TautomerPatternHolder::makeFingerprint
ExplicitBitVect * makeFingerprint(const ROMol &m) const override
Caller owns the vector!
Definition SubstructLibrary.h:342
RDKit::TautomerPatternHolder::TautomerPatternHolder
TautomerPatternHolder()
Definition SubstructLibrary.h:340
RDKit::TautomerPatternHolder::TautomerPatternHolder
TautomerPatternHolder(unsigned int numBits)
Definition SubstructLibrary.h:341
RDKit::TautomerQuery
Definition TautomerQuery.h:37
ValueErrorException
Class to allow us to throw a ValueError from C++ and have it make it back to Python.
Definition Exceptions.h:40
export.h
RDKIT_SUBSTRUCTLIBRARY_EXPORT
#define RDKIT_SUBSTRUCTLIBRARY_EXPORT
Definition export.h:561
RDKit::v1::SmilesToMol
RDKit::RWMol * SmilesToMol(const std::string &smi, const SmilesParserParams &ps)
Definition SmilesParse.h:118
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::PatternFingerprintMol
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::MolToSmiles
RDKIT_SMILESPARSE_EXPORT std::string MolToSmiles(const ROMol &mol, const SmilesWriteParams &params)
returns canonical SMILES for a molecule
RDKit::SubstructLibraryCanSerialize
RDKIT_SUBSTRUCTLIBRARY_EXPORT bool SubstructLibraryCanSerialize()
RDKit::GeneralizedSubstruct::ExtendedQueryMol
Definition XQMol.h:31
RDKit::SubstructMatchParameters
Definition SubstructMatch.h:42
RDKit::SubstructMatchParameters::useChirality
bool useChirality
Definition SubstructMatch.h:43
RDKit::SubstructMatchParameters::recursionPossible
bool recursionPossible
Allow recursive queries.
Definition SubstructMatch.h:53
RDKit::SubstructMatchParameters::useQueryQueryMatches
bool useQueryQueryMatches
Definition SubstructMatch.h:49