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 <unordered_map>
15#include <functional>
16#include <boost/unordered/unordered_flat_set.hpp>
17#include <RDGeneral/export.h>
18#include <GraphMol/ROMol.h>
19
21
22// takes vector of search results; returns true if enough hits have been
23// returned, false if the search should continue.
24// Invoking the callback transfers ownership of the molecules to the
25// callee, which avoids an extra copy of the molecule.
27 std::function<bool(std::vector<std::unique_ptr<ROMol>> &)>;
28
29// A class holding a set of results from a search. Contains the hit
30// molecules and information about how the search progressed, whether
31// it timed out etc.
33 public:
34 explicit SearchResults() : d_maxNumResults(0) {}
35 SearchResults(std::vector<std::unique_ptr<ROMol>> &&mols,
36 std::unique_ptr<ROMol> &&bestHit, std::uint64_t maxNumRes,
37 bool timedOut, bool cancelled);
39 SearchResults(SearchResults &&other) = default;
40 ~SearchResults() = default;
41
44
45 /*!
46 * Returns the upper bound on the number of results the search might return.
47 * There may be fewer than this in practice for several reasons such as
48 * duplicate reagent sets being removed or the final product not matching the
49 * query even though the synthons suggested it would.
50 *
51 * @return int
52 */
53 std::uint64_t getMaxNumResults() const { return d_maxNumResults; }
54 /*!
55 * Returns the hit molecules from the search. Not necessarily all
56 * those possible, just the maximum number requested.
57 *
58 * @return const std::vector<std::unique_ptr<ROMol>> &
59 */
60 const std::vector<std::unique_ptr<ROMol>> &getHitMolecules() const {
61 return d_hitMolecules;
62 }
63
64 /*!
65 * Returns the best hit found in a similarity search, even when none
66 * were under the search threshold. May be empty, for example if it
67 * was a substructure search. Also, may be empty if none of the synthons
68 * matched within the fragment similarity threshold i.e. nothing came close
69 * to a match.
70 *
71 * @return const std::unique_ptr<ROMol> &
72 */
73 const std::unique_ptr<ROMol> &getBestHit() const { return d_bestHitFound; }
74
75 /*!
76 * Returns whether the search timed out or not,
77 * @return bool
78 */
79 bool getTimedOut() const { return d_timedOut; }
80 /*!
81 * Returns whether the search was cancelled or not,
82 * @return bool
83 */
84 bool getCancelled() const { return d_cancelled; }
85
86 // Merge other into this, keeping only molecules with unique
87 // names and destroying contents of other on exit. If an
88 // incoming molecule is the same name as one already present
89 // and both have "Similarity" prop, then the one with the
90 // higher value is kept.
92
93 private:
94 std::vector<std::unique_ptr<ROMol>> d_hitMolecules;
95 // Only used when merging in another set, so will be
96 // filled in then if needed, empty otherwise.
97 std::unordered_map<std::string, size_t> d_molNames;
98
99 std::uint64_t d_maxNumResults;
100 bool d_timedOut{false};
101 bool d_cancelled{false};
102
103 // Even if there were no hits within the cutoff, the similarity
104 // searches will but the best hit it found in this molecule, with
105 // the similarity value in the "Similarity" property as for the
106 // genuine hits.
107 std::unique_ptr<ROMol> d_bestHitFound;
108};
109
110} // namespace RDKit::SynthonSpaceSearch
111
112#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)
const std::unique_ptr< ROMol > & getBestHit() const
SearchResults & operator=(const SearchResults &other)
void mergeResults(SearchResults &other)
SearchResults(SearchResults &&other)=default
SearchResults(std::vector< std::unique_ptr< ROMol > > &&mols, std::unique_ptr< ROMol > &&bestHit, std::uint64_t maxNumRes, bool timedOut, bool cancelled)
#define RDKIT_SYNTHONSPACESEARCH_EXPORT
Definition export.h:731
std::function< bool(std::vector< std::unique_ptr< ROMol > > &)> SearchResultCallback