RDKit
Open-source cheminformatics and machine learning.
Toggle main menu visibility
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
16
#include <
GraphMol/EnumerateStereoisomers/EnumerateStereoisomers.h
>
17
#include <
GraphMol/SynthonSpaceSearch/SynthonShapeInput.h
>
18
19
#ifdef RDK_USE_BOOST_SERIALIZATION
20
#include <
RDGeneral/BoostStartInclude.h
>
21
#include <boost/archive/text_oarchive.hpp>
22
#include <boost/archive/text_iarchive.hpp>
23
#include <
RDGeneral/BoostEndInclude.h
>
24
#endif
25
26
namespace
RDKit::SynthonSpaceSearch
{
27
28
using
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.
34
const
std::vector<std::string>
CONNECTOR_SYMBOLS
{
"[U]"
,
"[Np]"
,
"[Pu]"
,
"[Am]"
};
35
constexpr
unsigned
int
MAX_CONNECTOR_NUM
{4};
36
37
struct
RDKIT_SYNTHONSPACESEARCH_EXPORT
SynthonSpaceSearchParams
{
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.
70
double
fragSimilarityAdjuster
{
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.
78
double
approxSimilarityAdjuster
{
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.
100
GaussianShape::ShapeOverlayOptions
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.
108
bool
enumerateUnspecifiedStereo
{
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.
113
EnumerateStereoisomers::StereoEnumerationOptions
stereoEnumOpts
{
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.
136
UserConfGenerator
userConformerGenerator
;
137
// An excluded volume to use in a shape search. The volume overlap and
138
// mean overlap over clashing atoms will be reported.
139
GaussianShape::ShapeInput
*
excludedVolume
{
nullptr
};
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.
158
std::uint64_t
maxPossibleHitsToWrite
{
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.
162
bool
writePossibleHitsAndStop
{
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.
169
struct
RDKIT_SYNTHONSPACESEARCH_EXPORT
ShapeBuildParams
{
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.
179
int
randomSeed
{
180
0xdac};
// Seed for random number generator. Fixed by default
181
// so the same synthon conformers are produced each time.
182
EnumerateStereoisomers::StereoEnumerationOptions
stereoEnumOpts
{
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.
210
UserConfGenerator
userConformerGenerator
;
211
};
212
213
using
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.
220
enum class
ThreadMode
:
unsigned
char
{
221
ThreadReactions
,
222
ThreadFragments
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.
230
enum class
FragSetUniquifyMode
:
unsigned
char
{
231
BySmiles
,
232
ByAtoms
233
};
234
}
// namespace RDKit::SynthonSpaceSearch
235
#endif
// SYNTHONSPACESEARCHHELPERS_H
BoostEndInclude.h
BoostStartInclude.h
EnumerateStereoisomers.h
SynthonShapeInput.h
RDKit::GaussianShape::ShapeInput
Definition
ShapeInput.h:128
RDKIT_SYNTHONSPACESEARCH_EXPORT
#define RDKIT_SYNTHONSPACESEARCH_EXPORT
Definition
export.h:731
RDKit::SynthonSpaceSearch
Definition
MemoryMappedFileReader.h:19
RDKit::SynthonSpaceSearch::FragSetUniquifyMode
FragSetUniquifyMode
Definition
SynthonSpaceSearchHelpers.h:230
RDKit::SynthonSpaceSearch::FragSetUniquifyMode::ByAtoms
@ ByAtoms
Definition
SynthonSpaceSearchHelpers.h:232
RDKit::SynthonSpaceSearch::FragSetUniquifyMode::BySmiles
@ BySmiles
Definition
SynthonSpaceSearchHelpers.h:231
RDKit::SynthonSpaceSearch::UserConfGenerator
std::function< std::unique_ptr< RWMol >( const std::string &smiles, unsigned int numConformers)> UserConfGenerator
Definition
SynthonSpaceSearchHelpers.h:28
RDKit::SynthonSpaceSearch::ShapeSet
std::vector< std::unique_ptr< SynthonShapeInput > > ShapeSet
Definition
SynthonSpaceSearchHelpers.h:213
RDKit::SynthonSpaceSearch::ThreadMode
ThreadMode
Definition
SynthonSpaceSearchHelpers.h:220
RDKit::SynthonSpaceSearch::ThreadMode::ThreadFragments
@ ThreadFragments
Definition
SynthonSpaceSearchHelpers.h:222
RDKit::SynthonSpaceSearch::ThreadMode::ThreadReactions
@ ThreadReactions
Definition
SynthonSpaceSearchHelpers.h:221
RDKit::SynthonSpaceSearch::MAX_CONNECTOR_NUM
constexpr unsigned int MAX_CONNECTOR_NUM
Definition
SynthonSpaceSearchHelpers.h:35
RDKit::SynthonSpaceSearch::CONNECTOR_SYMBOLS
const std::vector< std::string > CONNECTOR_SYMBOLS
Definition
SynthonSpaceSearchHelpers.h:34
RDKit::EnumerateStereoisomers::StereoEnumerationOptions
Definition
EnumerateStereoisomers.h:32
RDKit::GaussianShape::ShapeOverlayOptions
Definition
ShapeOverlayOptions.h:50
RDKit::SynthonSpaceSearch::ShapeBuildParams
Definition
SynthonSpaceSearchHelpers.h:169
RDKit::SynthonSpaceSearch::ShapeBuildParams::randomSeed
int randomSeed
Definition
SynthonSpaceSearchHelpers.h:179
RDKit::SynthonSpaceSearch::ShapeBuildParams::numConfs
unsigned int numConfs
Definition
SynthonSpaceSearchHelpers.h:171
RDKit::SynthonSpaceSearch::ShapeBuildParams::interimWrites
std::uint64_t interimWrites
Definition
SynthonSpaceSearchHelpers.h:202
RDKit::SynthonSpaceSearch::ShapeBuildParams::timeOut
unsigned int timeOut
Definition
SynthonSpaceSearchHelpers.h:197
RDKit::SynthonSpaceSearch::ShapeBuildParams::useProgressBar
unsigned int useProgressBar
Definition
SynthonSpaceSearchHelpers.h:187
RDKit::SynthonSpaceSearch::ShapeBuildParams::stereoEnumOpts
EnumerateStereoisomers::StereoEnumerationOptions stereoEnumOpts
Definition
SynthonSpaceSearchHelpers.h:182
RDKit::SynthonSpaceSearch::ShapeBuildParams::userConformerGenerator
UserConfGenerator userConformerGenerator
Definition
SynthonSpaceSearchHelpers.h:210
RDKit::SynthonSpaceSearch::ShapeBuildParams::maxSynthonAtoms
unsigned int maxSynthonAtoms
Definition
SynthonSpaceSearchHelpers.h:193
RDKit::SynthonSpaceSearch::ShapeBuildParams::maxEmbedAttempts
unsigned int maxEmbedAttempts
Definition
SynthonSpaceSearchHelpers.h:196
RDKit::SynthonSpaceSearch::ShapeBuildParams::interimFile
std::string interimFile
Definition
SynthonSpaceSearchHelpers.h:200
RDKit::SynthonSpaceSearch::ShapeBuildParams::rmsThreshold
double rmsThreshold
Definition
SynthonSpaceSearchHelpers.h:172
RDKit::SynthonSpaceSearch::ShapeBuildParams::shapeSimThreshold
double shapeSimThreshold
Definition
SynthonSpaceSearchHelpers.h:173
RDKit::SynthonSpaceSearch::ShapeBuildParams::numThreads
int numThreads
Definition
SynthonSpaceSearchHelpers.h:176
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams
Definition
SynthonSpaceSearchHelpers.h:37
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::hitStart
std::int64_t hitStart
Definition
SynthonSpaceSearchHelpers.h:56
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::maxPossibleHitsToWrite
std::uint64_t maxPossibleHitsToWrite
Definition
SynthonSpaceSearchHelpers.h:158
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::userConformerGenerator
UserConfGenerator userConformerGenerator
Definition
SynthonSpaceSearchHelpers.h:136
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::bestHit
bool bestHit
Definition
SynthonSpaceSearchHelpers.h:102
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::randomSeed
int randomSeed
Definition
SynthonSpaceSearchHelpers.h:61
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::useProgressBar
unsigned int useProgressBar
Definition
SynthonSpaceSearchHelpers.h:125
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::stereoEnumOpts
EnumerateStereoisomers::StereoEnumerationOptions stereoEnumOpts
Definition
SynthonSpaceSearchHelpers.h:113
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::excludedVolume
GaussianShape::ShapeInput * excludedVolume
Definition
SynthonSpaceSearchHelpers.h:139
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::possibleHitsFile
std::string possibleHitsFile
Definition
SynthonSpaceSearchHelpers.h:151
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::toTryChunkSize
std::uint64_t toTryChunkSize
Definition
SynthonSpaceSearchHelpers.h:47
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::shapeOverlayOptions
GaussianShape::ShapeOverlayOptions shapeOverlayOptions
Definition
SynthonSpaceSearchHelpers.h:101
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::maxExcludedVolume
double maxExcludedVolume
Definition
SynthonSpaceSearchHelpers.h:140
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::minHitChiralAtoms
unsigned int minHitChiralAtoms
Definition
SynthonSpaceSearchHelpers.h:91
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::maxNumFragSets
std::uint64_t maxNumFragSets
Definition
SynthonSpaceSearchHelpers.h:40
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::maxHitHeavyAtoms
int maxHitHeavyAtoms
Definition
SynthonSpaceSearchHelpers.h:86
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::randomSample
bool randomSample
Definition
SynthonSpaceSearchHelpers.h:59
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::approxSimilarityAdjuster
double approxSimilarityAdjuster
Definition
SynthonSpaceSearchHelpers.h:78
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::enumerateUnspecifiedStereo
bool enumerateUnspecifiedStereo
Definition
SynthonSpaceSearchHelpers.h:108
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::buildHits
bool buildHits
Definition
SynthonSpaceSearchHelpers.h:63
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::minHitMolWt
double minHitMolWt
Definition
SynthonSpaceSearchHelpers.h:88
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::maxHitMolWt
double maxHitMolWt
Definition
SynthonSpaceSearchHelpers.h:89
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::confRMSThreshold
double confRMSThreshold
Definition
SynthonSpaceSearchHelpers.h:97
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::writePossibleHitsAndStop
bool writePossibleHitsAndStop
Definition
SynthonSpaceSearchHelpers.h:162
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::maxHits
std::int64_t maxHits
Definition
SynthonSpaceSearchHelpers.h:38
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::fragSimilarityAdjuster
double fragSimilarityAdjuster
Definition
SynthonSpaceSearchHelpers.h:70
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::numThreads
int numThreads
Definition
SynthonSpaceSearchHelpers.h:120
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::minHitHeavyAtoms
unsigned int minHitHeavyAtoms
Definition
SynthonSpaceSearchHelpers.h:85
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::numConformers
unsigned int numConformers
Definition
SynthonSpaceSearchHelpers.h:95
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::maxMeanExcludedVolume
double maxMeanExcludedVolume
Definition
SynthonSpaceSearchHelpers.h:143
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::maxHitChiralAtoms
int maxHitChiralAtoms
Definition
SynthonSpaceSearchHelpers.h:93
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::timeOut
std::uint64_t timeOut
Definition
SynthonSpaceSearchHelpers.h:118
RDKit::SynthonSpaceSearch::SynthonSpaceSearchParams::similarityCutoff
double similarityCutoff
Definition
SynthonSpaceSearchHelpers.h:65
GraphMol
SynthonSpaceSearch
SynthonSpaceSearchHelpers.h
Generated on
for RDKit by
1.17.0