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
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.
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.
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);
36 SearchResults(SearchResults &&other) = default;
37 ~SearchResults() = default;
38
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.
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
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:577
std::function< bool(std::vector< std::unique_ptr< ROMol > > &)> SearchResultCallback