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 <boost/unordered/unordered_flat_set.hpp>
16#include <RDGeneral/export.h>
17#include <GraphMol/ROMol.h>
18
20
21// takes vector of search results; returns true if enough hits have been
22// returned, false if the search should continue.
23// Invoking the callback transfers ownership of the molecules to the
24// callee, which avoids an extra copy of the molecule.
26 std::function<bool(std::vector<std::unique_ptr<ROMol>> &)>;
27
28// A class holding a set of results from a search. Contains the hit
29// molecules and information about how the search progressed, whether
30// it timed out etc.
32 public:
33 explicit SearchResults() : d_maxNumResults(0) {}
34 SearchResults(std::vector<std::unique_ptr<ROMol>> &&mols,
35 std::uint64_t maxNumRes, bool timedOut, bool cancelled);
37 SearchResults(SearchResults &&other) = default;
38 ~SearchResults() = default;
39
42
43 /*!
44 * Returns the upper bound on the number of results the search might return.
45 * There may be fewer than this in practice for several reasons such as
46 * duplicate reagent sets being removed or the final product not matching the
47 * query even though the synthons suggested it would.
48 *
49 * @return int
50 */
51 std::uint64_t getMaxNumResults() const { return d_maxNumResults; }
52 /*!
53 * Returns the hit molecules from the search. Not necessarily all
54 * those possible, just the maximum number requested.
55 *
56 * @return std::vector<std::unique_ptr<ROMol>>
57 */
58 const std::vector<std::unique_ptr<ROMol>> &getHitMolecules() const {
59 return d_hitMolecules;
60 }
61
62 /*!
63 * Returns whether the search timed out or not,
64 * @return bool
65 */
66 bool getTimedOut() const { return d_timedOut; }
67 /*!
68 * Returns whether the search was cancelled or not,
69 * @return bool
70 */
71 bool getCancelled() const { return d_cancelled; }
72
73 // Merge other into this, keeping only molecules with unique
74 // names and destroying contents of other on exit.
76
77 private:
78 std::vector<std::unique_ptr<ROMol>> d_hitMolecules;
79 // Only used when merging in another set, so will be
80 // filled in then if needed, empty otherwise.
81 boost::unordered_flat_set<std::string> d_molNames;
82
83 std::uint64_t d_maxNumResults;
84 bool d_timedOut{false};
85 bool d_cancelled{false};
86};
87
88} // namespace RDKit::SynthonSpaceSearch
89
90#endif // RDKIT_SYNTHONSPACE_SEARCHRESULTS_H
Defines the primary molecule class ROMol as well as associated typedefs.
const std::vector< std::unique_ptr< ROMol > > & getHitMolecules() const
SearchResults & operator=(SearchResults &&other)=default
SearchResults(const SearchResults &other)
SearchResults & operator=(const SearchResults &other)
void mergeResults(SearchResults &other)
SearchResults(std::vector< std::unique_ptr< ROMol > > &&mols, std::uint64_t maxNumRes, bool timedOut, bool cancelled)
SearchResults(SearchResults &&other)=default
#define RDKIT_SYNTHONSPACESEARCH_EXPORT
Definition export.h:585
std::function< bool(std::vector< std::unique_ptr< ROMol > > &)> SearchResultCallback