RDKit: SearchResults.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
SearchResults.h
Go to the documentation of this file.
1//
2// Copyright (C) David Cosgrove 2024.
3//
4// @@ All Rights Reserved @@
5// This file is part of the RDKit.
6// The contents are covered by the terms of the BSD license
7// which is included in the file license.txt, found at the root
8// of the RDKit source tree.
9//
10
11#ifndef RDKIT_SYNTHONSPACE_SEARCHRESULTS_H
12#define RDKIT_SYNTHONSPACE_SEARCHRESULTS_H
13
14#include <functional>
15#include <RDGeneral/export.h>
16#include <GraphMol/ROMol.h>
17
18namespace RDKit::SynthonSpaceSearch {
19
20// takes vector of search results; returns true if enough hits have been
21// returned, false if the search should continue.
22// Invoking the callback transfers ownership of the molecules to the
23// callee, which avoids an extra copy of the molecule.
24 using SearchResultCallback =
25 std::function<bool(std::vector<std::unique_ptr<ROMol>> &)>;
26
27// A class holding a set of results from a search. Contains the hit
28// molecules and information about how the search progressed, whether
29// it timed out etc.
30 class RDKIT_SYNTHONSPACESEARCH_EXPORT SearchResults {
31 public:
32 explicit SearchResults() : d_maxNumResults(0) {}
33 SearchResults(std::vector<std::unique_ptr<ROMol>> &&mols,
34 std::uint64_t maxNumRes, bool timedOut, bool cancelled);
35 SearchResults(const SearchResults &other);
36 SearchResults(SearchResults &&other) = default;
37 ~SearchResults() = default;
38
39 SearchResults &operator=(const SearchResults &other);
40 SearchResults &operator=(SearchResults &&other) = default;
41
42 /*!
43 * Returns the upper bound on the number of results the search might return.
44 * There may be fewer than this in practice for several reasons such as
45 * duplicate reagent sets being removed or the final product not matching the
46 * query even though the synthons suggested it would.
47 *
48 * @return int
49 */
50 std::uint64_t getMaxNumResults() const { return d_maxNumResults; }
51 /*!
52 * Returns the hit molecules from the search. Not necessarily all
53 * those possible, just the maximum number requested.
54 *
55 * @return std::vector<std::unique_ptr<ROMol>>
56 */
57 const std::vector<std::unique_ptr<ROMol>> &getHitMolecules() const {
58 return d_hitMolecules;
59 }
60
61 /*!
62 * Returns whether the search timed out or not,
63 * @return bool
64 */
65 bool getTimedOut() const { return d_timedOut; }
66 /*!
67 * Returns whether the search was cancelled or not,
68 * @return bool
69 */
70 bool getCancelled() const { return d_cancelled; }
71
72 // Merge other into this, keeping only molecules with unique
73 // names and destroying contents of other on exit.
74 void mergeResults(SearchResults &other);
75
76 private:
77 std::vector<std::unique_ptr<ROMol>> d_hitMolecules;
78 // Only used when merging in another set, so will be
79 // filled in then if needed, empty otherwise.
80 std::unordered_set<std::string> d_molNames;
81
82 std::uint64_t d_maxNumResults;
83 bool d_timedOut{false};
84 bool d_cancelled{false};
85};
86
87} // namespace RDKit::SynthonSpaceSearch
88
89#endif // RDKIT_SYNTHONSPACE_SEARCHRESULTS_H
ROMol.h
Defines the primary molecule class ROMol as well as associated typedefs.
RDKit::SynthonSpaceSearch::SearchResults::getHitMolecules
const std::vector< std::unique_ptr< ROMol > > & getHitMolecules() const
Definition SearchResults.h:57
RDKit::SynthonSpaceSearch::SearchResults::getMaxNumResults
std::uint64_t getMaxNumResults() const
Definition SearchResults.h:50
RDKit::SynthonSpaceSearch::SearchResults::~SearchResults
~SearchResults()=default
RDKit::SynthonSpaceSearch::SearchResults::operator=
SearchResults & operator=(SearchResults &&other)=default
RDKit::SynthonSpaceSearch::SearchResults::SearchResults
SearchResults(const SearchResults &other)
RDKit::SynthonSpaceSearch::SearchResults::operator=
SearchResults & operator=(const SearchResults &other)
RDKit::SynthonSpaceSearch::SearchResults::mergeResults
void mergeResults(SearchResults &other)
RDKit::SynthonSpaceSearch::SearchResults::getCancelled
bool getCancelled() const
Definition SearchResults.h:70
RDKit::SynthonSpaceSearch::SearchResults::SearchResults
SearchResults()
Definition SearchResults.h:32
RDKit::SynthonSpaceSearch::SearchResults::SearchResults
SearchResults(std::vector< std::unique_ptr< ROMol > > &&mols, std::uint64_t maxNumRes, bool timedOut, bool cancelled)
RDKit::SynthonSpaceSearch::SearchResults::SearchResults
SearchResults(SearchResults &&other)=default
RDKit::SynthonSpaceSearch::SearchResults::getTimedOut
bool getTimedOut() const
Definition SearchResults.h:65
export.h
RDKIT_SYNTHONSPACESEARCH_EXPORT
#define RDKIT_SYNTHONSPACESEARCH_EXPORT
Definition export.h:577
RDKit::SynthonSpaceSearch
Definition MemoryMappedFileReader.h:19
RDKit::SynthonSpaceSearch::SearchResultCallback
std::function< bool(std::vector< std::unique_ptr< ROMol > > &)> SearchResultCallback
Definition SearchResults.h:24