RDKit
Open-source cheminformatics and machine learning.
Toggle main menu visibility
Loading...
Searching...
No Matches
Enumerate.h
Go to the documentation of this file.
1
//
2
// Copyright (c) 2015, Novartis Institutes for BioMedical Research Inc.
3
// All rights reserved.
4
//
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are
7
// met:
8
//
9
// * Redistributions of source code must retain the above copyright
10
// notice, this list of conditions and the following disclaimer.
11
// * Redistributions in binary form must reproduce the above
12
// copyright notice, this list of conditions and the following
13
// disclaimer in the documentation and/or other materials provided
14
// with the distribution.
15
// * Neither the name of Novartis Institutes for BioMedical Research Inc.
16
// nor the names of its contributors may be used to endorse or promote
17
// products derived from this software without specific prior written
18
// permission.
19
//
20
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.n
31
//
32
#include <
RDGeneral/export.h
>
33
#ifndef RDKIT_ENUMERATE_H
34
#define RDKIT_ENUMERATE_H
35
#include "
EnumerateBase.h
"
36
37
/*! \file Enumerate.h
38
39
\brief Contains the public API of the for the reaction enumeration engine
40
41
\b Note that this should be considered beta and that the API may change in
42
future releases.
43
44
*/
45
46
namespace
RDKit
{
47
48
//! This is a class for providing enumeration options that control
49
/// how enumerations are performed.
50
/*!
51
Option
52
reagentMaxMatchCount [default INT_MAX]
53
This specifies how many times the reactant template can match a reagent.
54
55
sanePartialProducts [default false]
56
If true, forces all products of the reagent plus the product templates\n\
57
pass chemical sanitization. Note that if the product template itself\n\
58
does not pass sanitization, then none of the products will.
59
*/
60
struct
RDKIT_CHEMREACTIONS_EXPORT
EnumerationParams
{
61
int
reagentMaxMatchCount
{INT_MAX};
62
bool
sanePartialProducts
{
false
};
63
EnumerationParams
() {}
64
65
EnumerationParams
(
const
EnumerationParams
&rhs)
66
:
reagentMaxMatchCount
(rhs.
reagentMaxMatchCount
),
67
sanePartialProducts
(rhs.
sanePartialProducts
) {}
68
};
69
70
//! Helper function, remove reagents that are incompatible
71
/// with the reaction.
72
/// rxn must be sanitized, initialized and preprocessed.
73
/// this happens automatically in EnumerateLibrary
74
RDKIT_CHEMREACTIONS_EXPORT
EnumerationTypes::BBS
removeNonmatchingReagents
(
75
const
ChemicalReaction
&rxn,
EnumerationTypes::BBS
bbs,
76
const
EnumerationParams
¶ms =
EnumerationParams
());
77
78
//! This is a class for running reactions on sets of reagents.
79
/*!
80
This class is a fully self contained reaction engine that can be
81
serialized and restarted. For example, a million products can
82
be generated, the engine can be saved for later and reloaded
83
to retrieve the next million products.
84
85
basic usage will be something like:
86
\verbatim
87
ChemicalReaction rxn = ...
88
BBS bbs(num_rgroups);
89
... somehow LoadRGroups(bbs[0]);
90
... somehow LoadRGroups(bbs[1]..);
91
...
92
EnumerateLibrary enumerator(en, bbs);
93
for(; (bool)en; ++i) {
94
// This is the same as rxn.run_Reactants( reagents );
95
std::vector<MOL_SPTR_VECT> products = en.next();
96
...
97
}
98
\endverbatim
99
100
In general, reactions will enumerate to more products than desired,
101
a standard use is:
102
103
\verbatim
104
for(int i=0;i<num_samples && (bool)en; ++i) {
105
std::vector<MOL_SPTR_VECT> products = en.next();
106
...
107
}
108
\endverbatim
109
*/
110
111
class
RDKIT_CHEMREACTIONS_EXPORT
EnumerateLibrary
112
:
public
EnumerateLibraryBase
{
113
EnumerationTypes::BBS
m_bbs;
114
115
public
:
116
EnumerateLibrary
() :
EnumerateLibraryBase
(), m_bbs() {}
117
EnumerateLibrary
(
const
std::string &s) :
EnumerateLibraryBase
(), m_bbs() {
118
initFromString
(s);
119
}
120
121
EnumerateLibrary
(
const
ChemicalReaction
&rxn,
122
const
EnumerationTypes::BBS
&reagents,
123
const
EnumerationParams
¶ms =
EnumerationParams
());
124
EnumerateLibrary
(
const
ChemicalReaction
&rxn,
125
const
EnumerationTypes::BBS
&reagents,
126
const
EnumerationStrategyBase
&enumerator,
127
const
EnumerationParams
¶ms =
EnumerationParams
());
128
EnumerateLibrary
(
const
EnumerateLibrary
&rhs);
129
130
//! Return the reagents used in the library. This may be fewer reagents than
131
// the input as it is only those compatible with the reaction.
132
const
EnumerationTypes::BBS
&
getReagents
()
const
{
return
m_bbs; }
133
134
//! Get the next product set
135
std::vector<MOL_SPTR_VECT>
next
()
override
;
136
137
void
toStream
(std::ostream &ss)
const override
;
138
void
initFromStream
(std::istream &ss)
override
;
139
140
private
:
141
#ifdef RDK_USE_BOOST_SERIALIZATION
142
friend
class
boost::serialization::access;
143
template
<
class
Archive>
144
void
save(Archive &ar,
const
unsigned
int
/*version*/
)
const
{
145
ar &boost::serialization::base_object<EnumerateLibraryBase>(*
this
);
146
size_t
sz = m_bbs.size();
147
ar & sz;
148
149
std::string pickle;
150
for
(
size_t
i = 0; i < m_bbs.size(); ++i) {
151
sz = m_bbs[i].size();
152
ar & sz;
153
for
(
size_t
j = 0; j < m_bbs[i].size(); ++j) {
154
MolPickler::pickleMol
(*m_bbs[i][j], pickle);
155
ar & pickle;
156
}
157
}
158
}
159
template
<
class
Archive>
160
void
load(Archive &ar,
const
unsigned
int
/*version*/
) {
161
ar &boost::serialization::base_object<EnumerateLibraryBase>(*
this
);
162
163
size_t
sz;
164
ar & sz;
165
166
m_bbs.resize(sz);
167
168
for
(
size_t
i = 0; i < m_bbs.size(); ++i) {
169
ar & sz;
170
m_bbs[i].resize(sz);
171
std::string
pickle
;
172
for
(
size_t
j = 0; j < m_bbs[i].size(); ++j) {
173
ar &
pickle
;
174
RWMol *mol =
new
RWMol();
175
MolPickler::molFromPickle(pickle, *mol);
176
m_bbs[i][j].reset(mol);
177
}
178
}
179
}
180
181
BOOST_SERIALIZATION_SPLIT_MEMBER();
182
#endif
183
};
184
185
RDKIT_CHEMREACTIONS_EXPORT
bool
EnumerateLibraryCanSerialize
();
186
187
}
// namespace RDKit
188
#endif
EnumerateBase.h
RDKit::ChemicalReaction
This is a class for storing and applying general chemical reactions.
Definition
Reaction.h:122
RDKit::EnumerateLibraryBase::EnumerateLibraryBase
EnumerateLibraryBase()
default constructor
Definition
EnumerateBase.h:71
RDKit::EnumerateLibraryBase::initFromString
virtual void initFromString(const std::string &text)
initializes from a string pickle
Definition
EnumerateBase.h:159
RDKit::EnumerateLibrary::getReagents
const EnumerationTypes::BBS & getReagents() const
Return the reagents used in the library. This may be fewer reagents than.
Definition
Enumerate.h:132
RDKit::EnumerateLibrary::EnumerateLibrary
EnumerateLibrary(const std::string &s)
Definition
Enumerate.h:117
RDKit::EnumerateLibrary::EnumerateLibrary
EnumerateLibrary()
Definition
Enumerate.h:116
RDKit::EnumerateLibrary::EnumerateLibrary
EnumerateLibrary(const EnumerateLibrary &rhs)
RDKit::EnumerateLibrary::next
std::vector< MOL_SPTR_VECT > next() override
Get the next product set.
RDKit::EnumerateLibrary::toStream
void toStream(std::ostream &ss) const override
serializes (pickles) to a stream
RDKit::EnumerateLibrary::initFromStream
void initFromStream(std::istream &ss) override
initializes from a stream pickle
RDKit::EnumerateLibrary::EnumerateLibrary
EnumerateLibrary(const ChemicalReaction &rxn, const EnumerationTypes::BBS &reagents, const EnumerationParams ¶ms=EnumerationParams())
RDKit::EnumerateLibrary::EnumerateLibrary
EnumerateLibrary(const ChemicalReaction &rxn, const EnumerationTypes::BBS &reagents, const EnumerationStrategyBase &enumerator, const EnumerationParams ¶ms=EnumerationParams())
RDKit::EnumerationStrategyBase
Definition
EnumerationStrategyBase.h:123
RDKit::MolPickler::pickleMol
static void pickleMol(const ROMol *mol, std::ostream &ss)
pickles a molecule and sends the results to stream ss
export.h
RDKIT_CHEMREACTIONS_EXPORT
#define RDKIT_CHEMREACTIONS_EXPORT
Definition
export.h:71
RDKit::EnumerationStrategyPickler::pickle
RDKIT_CHEMREACTIONS_EXPORT void pickle(const boost::shared_ptr< EnumerationStrategyBase > &enumerator, std::ostream &ss)
pickles a EnumerationStrategy and adds the results to a stream ss
RDKit::EnumerationTypes::BBS
std::vector< MOL_SPTR_VECT > BBS
Definition
EnumerateTypes.h:42
RDKit
Std stuff.
Definition
Abbreviations.h:19
RDKit::removeNonmatchingReagents
RDKIT_CHEMREACTIONS_EXPORT EnumerationTypes::BBS removeNonmatchingReagents(const ChemicalReaction &rxn, EnumerationTypes::BBS bbs, const EnumerationParams ¶ms=EnumerationParams())
RDKit::EnumerateLibraryCanSerialize
RDKIT_CHEMREACTIONS_EXPORT bool EnumerateLibraryCanSerialize()
RDKit::EnumerationParams
Definition
Enumerate.h:60
RDKit::EnumerationParams::EnumerationParams
EnumerationParams()
Definition
Enumerate.h:63
RDKit::EnumerationParams::EnumerationParams
EnumerationParams(const EnumerationParams &rhs)
Definition
Enumerate.h:65
RDKit::EnumerationParams::reagentMaxMatchCount
int reagentMaxMatchCount
Definition
Enumerate.h:61
RDKit::EnumerationParams::sanePartialProducts
bool sanePartialProducts
Definition
Enumerate.h:62
GraphMol
ChemReactions
Enumerate
Enumerate.h
Generated on
for RDKit by
1.17.0