RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
SynthonSpaceSearchHelpers.h
Go to the documentation of this file.
1//
2// Copyright (C) David Cosgrove 2025.
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 SYNTHONSPACESEARCHHELPERS_H
12#define SYNTHONSPACESEARCHHELPERS_H
13
14#include <functional>
15
18
19#ifdef RDK_USE_BOOST_SERIALIZATION
21#include <boost/archive/text_oarchive.hpp>
22#include <boost/archive/text_iarchive.hpp>
24#endif
25
27
28using UserConfGenerator = std::function<std::unique_ptr<RWMol>(
29 const std::string &smiles, unsigned int numConformers)>;
30
31// This the maximum number of connectors that we can deal with at the moment.
32// In reality, there may be fewer than this. However, the key limit is in
33// The symbols used for the connectors in Enamine REAL etc.
34const std::vector<std::string> CONNECTOR_SYMBOLS{"[U]", "[Np]", "[Pu]", "[Am]"};
35constexpr unsigned int MAX_CONNECTOR_NUM{4};
36
38 std::int64_t maxHits{1000}; // The maximum number of hits to return.
39 // Use -1 for no maximum.
40 std::uint64_t maxNumFragSets{
41 100000}; // The maximum number of fragment sets the query can
42 // be broken into. Big molecules will create huge
43 // numbers of fragment sets that may cause excessive
44 // memory use. If the number of fragment sets hits this
45 // number, fragmentation stops and the search results
46 // will likely be incomplete.
47 std::uint64_t toTryChunkSize{
48 2500000}; // For similarity searching, especially
49 // fingerprint similarity, there can be a
50 // very large number of possible hits to
51 // screen which can use a lot of memory and
52 // crash the program. It will also be very
53 // slow. To alleviate the memory use, the
54 // possible hits are processed in chunks.
55 // This parameter sets the chunk size.
56 std::int64_t hitStart{0}; // Sequence number of hit to start from. So that
57 // you can return the next N hits of a search
58 // having already obtained N-1.
59 bool randomSample{false}; // If true, returns a random sample of the hit
60 // hits, up to maxHits in number.
61 int randomSeed{-1}; // Seed for random-number generator. -1 means use
62 // a random seed (std::random_device).
63 bool buildHits{true}; // If false, reports the maximum number of hits that
64 // the search could produce, but doesn't return them.
65 double similarityCutoff{0.5}; // Similarity cutoff for returning hits by
66 // fingerprint similarity. The default is
67 // appropriate for a Morgan fingerprint of
68 // radius=2, it may need changing for other
69 // fingerprint types.
71 0.1}; // Similarity values for fragments are generally low
72 // due to low bit densities. For the fragment
73 // matching, reduce the similarity cutoff
74 // by this amount. A higher number will give slower search
75 // times, a lower number will give faster searches at the
76 // risk of missing some hits. The value you use should have
77 // a positive correlation with your FOMO.
79 0.1}; // The fingerprint search uses an approximate similarity method
80 // before building a product and doing a final check. The
81 // similarityCutoff is reduced by this value for the approximate
82 // check. A lower value will give faster run times at the
83 // risk of missing some hits. The value you use should have a
84 // positive correlation with your FOMO.
85 unsigned int minHitHeavyAtoms{0}; // Minimum number of heavy atoms in a hit.
86 int maxHitHeavyAtoms{-1}; // Maximum number of heavy atoms in a hit.
87 // -1 means no maximum.
88 double minHitMolWt{0}; // Minimum molecular weight for a hit.
89 double maxHitMolWt{-1}; // Maximum molecular weight for a hit. -1.0 means
90 // no maximum.
91 unsigned int minHitChiralAtoms{
92 0}; // Minimum number of chiral atoms in a hit.
93 int maxHitChiralAtoms{-1}; // Maximum number of chiral atoms in a hit.
94 // -1 means no maximum.
95 unsigned int numConformers{100}; // When doing a shape search, the number of
96 // conformers to use for each molecule.
97 double confRMSThreshold{0.5}; // When doing a shape search, the RMS threshold
98 // to use when pruning conformers. Passed
99 // directly to EmbedMultipleConfs.
101 shapeOverlayOptions; // Options to use when shape searching.
102 bool bestHit{false}; // If true, when doing a shape search it will return the
103 // hit conformer with the best shape match to a query
104 // conformer. If false it will just return the first
105 // hit conformer that exceeds the similarity cutoff.
106 // The latter will be faster but the returned hit
107 // conformations likely to be less relevant.
109 false}; // When doing a shape search, if there is
110 // unspecified stereochemistry in either
111 // the query or potential hit, enumerate and
112 // test all possibilities.
114 true, true, false, true,
115 0, 0xdac}; // Options for stereoisomer enumeration. Over-ride default
116 // tryEmbedding of false and use fixed randomSeed for
117 // consistency of results from run to run.
118 std::uint64_t timeOut{600}; // Maximum number of seconds to spend on a single
119 // search. 0 means no maximum.
120 int numThreads = 1; // The number of threads to use. If > 0, will use that
121 // number. If <= 0, will use the number of hardware
122 // threads plus this number. So if the number of
123 // hardware threads is 8, and numThreads is -1, it will
124 // use 7 threads.
125 unsigned int useProgressBar{0}; // Makes a progress bar of given width. The
126 // number given is the number of '*'
127 // characters in a full bar. There will be
128 // about another 35 characters or so
129 // depending on the size of the job. 0
130 // means no bar.
131 // User-supplied function that takes a SMILES string and a maximum number
132 // of conformers to be generated and returns a multi-conformer molecule.
133 // Returns nullptr if it fails. Use something different from the RDKit
134 // conformer generator if preferred. Used for creating conformers of
135 // potential hits to compare against the query.
137 // An excluded volume to use in a shape search. The volume overlap and
138 // mean overlap over clashing atoms will be reported.
140 double maxExcludedVolume{-1.0}; // Maximum allowed excluded volume for a hit
141 // to be accepted. Default -1.0 means no
142 // maximum.
143 double maxMeanExcludedVolume{-1.0}; // Maximum mean excluded volume for a hit
144 // to be accepted. The mean is the total
145 // excluded volume divided by the number
146 // of clashing atoms (within 2 CARBON_RAD
147 // of an excluded volume atom). To try
148 // and distinguish between a mild clash
149 // over the whole hit and a few atoms
150 // having a really bad clash.
151 std::string possibleHitsFile; // Name of a file to save the possible hits to.
152 // These are the combinations of synthons that
153 // might match the query but need building and
154 // final checking. Each line has a
155 // space-separated list of the synthons and the
156 // hit's name. The file will be emptied and
157 // re-filled if it already exists.
159 10000000}; // Maximum number of lines to write to possibleHitsFile.
160 // When dealing with huge synthon spaces it's very
161 // easy to fill a disk.
163 false}; // If true, creates the possibleHitsFile
164 // and stops without doing the final
165 // building and checking.
166};
167
168// Options to be passed to buildSynthonShapes.
170 // The relevant ones are passed directly into EmbedMultipleConfs.
171 unsigned int numConfs{100}; // Max number of conformations per synthon
172 double rmsThreshold{0.5}; // RMS threshold used when pruning conformations
173 double shapeSimThreshold{0.95}; // This is passed to pruneShapes(). For each
174 // synthon, no 2 shapes will be more similar
175 // to each other than the threshold.
176 int numThreads{1}; // The number of threads to use. If > 0, will use that
177 // number. If <= 0, will use the number of hardware
178 // threads plus this number.
180 0xdac}; // Seed for random number generator. Fixed by default
181 // so the same synthon conformers are produced each time.
183 true, true, false, true,
184 0, 0xdac}; // Options for stereoisomer enumeration. Over-ride default
185 // tryEmbedding of false and use fixed randomSeed for
186 // consistency of results from run to run.
187 unsigned int useProgressBar{0}; // Makes a progress bar of given width. The
188 // number given is the number of '*'
189 // characters in a full bar. There will be
190 // about another 35 characters or so
191 // depending on the size of the job. 0
192 // means no bar.
193 unsigned int maxSynthonAtoms{0}; // If > 0, sets a maximum number of heavy
194 // atoms, excluding dummies, for a synthon
195 // to have a shape made.
196 unsigned int maxEmbedAttempts{10}; // Maximum attempts for an embedding.
197 unsigned int timeOut{60}; // Maximum time in seconds to spend on each synthon
198 // when generating conformers.
199 std::string
200 interimFile; // Interim file to write SynthonSpace to. In the event of
201 // a failure, a restart from this file will be possible.
202 std::uint64_t interimWrites{
203 1000}; // If an interim file has been given, every this
204 // many shapes write a new version of the file. If 0, don't
205 // do any writing.
206 // User-supplied function that takes a SMILES string and a maximum number
207 // of conformers to be generated and returns a multi-conformer molecule.
208 // Returns nullptr if it fails. Use something different from the RDKit
209 // conformer generator if preferred.
211};
212
213using ShapeSet = std::vector<std::unique_ptr<SynthonShapeInput>>;
214
215// Experiments have shown that it's quicker to parallelise the search
216// at the SynthonSet level for substructure searches, but at the
217// FragSet level for the slower searches such as fingerprints, Rascal
218// and shape. This enum is used to control which is done in a particular
219// case.
220enum class ThreadMode : unsigned char {
223};
224
225// When uniquifying the split molecules in details::splitMolecule,
226// whether to do it by SMILES (most common) or by atom indices.
227// The latter is for shape searching where 2 fragment sets can have the
228// same SMILES strings but be from different partitions of the atoms and
229// hence have different shapes, if there's partial symmetry in the molecule.
230enum class FragSetUniquifyMode : unsigned char {
233};
234} // namespace RDKit::SynthonSpaceSearch
235#endif // SYNTHONSPACESEARCHHELPERS_H
#define RDKIT_SYNTHONSPACESEARCH_EXPORT
Definition export.h:731
std::vector< std::unique_ptr< SynthonShapeInput > > ShapeSet
std::function< std::unique_ptr< RWMol >( const std::string &smiles, unsigned int numConformers)> UserConfGenerator
constexpr unsigned int MAX_CONNECTOR_NUM
const std::vector< std::string > CONNECTOR_SYMBOLS
EnumerateStereoisomers::StereoEnumerationOptions stereoEnumOpts
EnumerateStereoisomers::StereoEnumerationOptions stereoEnumOpts