RDKit
Open-source cheminformatics and machine learning.
Toggle main menu visibility
Loading...
Searching...
No Matches
SanitizeRxn.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.
31
//
32
#include <
RDGeneral/export.h
>
33
#ifndef RDKIT_SANITIZERXN_H
34
#define RDKIT_SANITIZERXN_H
35
36
#include "
Reaction.h
"
37
#include <
GraphMol/MolOps.h
>
38
#include <string>
39
#include <exception>
40
#include <utility>
41
42
namespace
RDKit
{
43
44
//! class for flagging sanitization errors
45
class
RDKIT_CHEMREACTIONS_EXPORT
RxnSanitizeException
:
public
std::exception {
46
public
:
47
RxnSanitizeException
(
const
char
*msg) : _msg(msg) {}
48
RxnSanitizeException
(std::string msg) : _msg(std::move(msg)) {}
49
const
char
*
what
() const noexcept
override
{
return
_msg.c_str(); }
50
~RxnSanitizeException
() noexcept override = default;
51
52
private:
53
std::
string
_msg;
54
};
55
56
namespace
RxnOps
{
57
//! Any dummy atom with a map but no RGroup label, should be an RGroup
58
//! in RDKit's view of a reaction.
59
//! See if these atoms can be salvaged into RGroups.
60
RDKIT_CHEMREACTIONS_EXPORT
void
fixRGroups
(
ChemicalReaction
&rxn);
61
62
//! If atom maps are not defined on rgroups, attempt to deduce them from the
63
//! RGroup
64
//! labels, or add new ones if possible.
65
RDKIT_CHEMREACTIONS_EXPORT
void
fixAtomMaps
(
ChemicalReaction
&rxn);
66
67
//! Adjusts the reactant templates to properly match reagents
68
RDKIT_CHEMREACTIONS_EXPORT
void
adjustTemplates
(
69
const
MOL_SPTR_VECT
&templates,
70
const
MolOps::AdjustQueryParameters
¶ms);
71
72
//! merge query Hs if appropriate
73
RDKIT_CHEMREACTIONS_EXPORT
void
fixHs
(
ChemicalReaction
&rxn);
74
75
// Default adjustment parameters for matching reagents
76
inline
const
MolOps::AdjustQueryParameters
DefaultRxnAdjustParams
() {
77
MolOps::AdjustQueryParameters
params;
78
params.
adjustDegree
=
false
;
79
params.
adjustDegreeFlags
=
MolOps::ADJUST_IGNOREALL
;
80
params.
adjustRingCount
=
false
;
81
params.
adjustRingCountFlags
=
MolOps::ADJUST_IGNOREALL
;
82
params.
makeDummiesQueries
=
false
;
83
params.
aromatizeIfPossible
=
true
;
84
return
params;
85
}
86
87
// Default adjustment parameters for ChemDraw style matching of reagents
88
// -- deprecated - renamed MatchOnlyAtRgroupsAdjustParams
89
// -- this doesn't match sciquest style searching
90
inline
const
MolOps::AdjustQueryParameters
ChemDrawRxnAdjustParams
() {
91
BOOST_LOG
(
rdWarningLog
)
92
<<
" deprecated -- please use MatchOnlyAtRgroupsAdjustParams instead"
93
<< std::endl;
94
MolOps::AdjustQueryParameters
params;
95
params.
adjustDegree
=
true
;
96
params.
adjustDegreeFlags
=
MolOps::ADJUST_IGNOREDUMMIES
;
97
params.
adjustRingCount
=
false
;
98
params.
adjustRingCountFlags
=
MolOps::ADJUST_IGNORENONE
;
99
params.
makeDummiesQueries
=
false
;
100
params.
aromatizeIfPossible
=
true
;
101
return
params;
102
}
103
104
inline
const
MolOps::AdjustQueryParameters
MatchOnlyAtRgroupsAdjustParams
() {
105
MolOps::AdjustQueryParameters
params;
106
params.
adjustDegree
=
true
;
107
params.
adjustDegreeFlags
=
MolOps::ADJUST_IGNOREDUMMIES
;
108
params.
adjustRingCount
=
false
;
109
params.
adjustRingCountFlags
=
MolOps::ADJUST_IGNORENONE
;
110
params.
makeDummiesQueries
=
false
;
111
params.
aromatizeIfPossible
=
true
;
112
return
params;
113
}
114
115
typedef
enum
{
116
SANITIZE_NONE
= 0x0,
117
SANITIZE_RGROUP_NAMES
= 0x1,
118
SANITIZE_ATOM_MAPS
= 0x2,
119
SANITIZE_ADJUST_REACTANTS
= 0x4,
120
SANITIZE_MERGEHS
= 0x8,
121
SANITIZE_ADJUST_PRODUCTS
= 0x10,
122
SANITIZE_ALL
= 0xFFFFFFFF
123
} SanitizeRxnFlags;
124
125
//! \brief carries out a collection of tasks for cleaning up a reaction and
126
/// ensuring
127
//! that it makes "chemical sense" in the context of RDKit reacitons
128
/*!
129
This functions calls the following in sequence
130
-# RxnOps::fixRGroups()
131
-# RxnOps::fixupAtomMaps()
132
-# RxnOps::fixupTemplateAromaticity()
133
-# RxnOps::mergeHs()
134
135
\param rxn : the ChemicalReaction to be cleaned
136
137
\param operationThatFailed : the first (if any) sanitization operation that
138
fails is set here.
139
The values are taken from the \c SanitizeFlags
140
enum.
141
On success, the value is \c
142
SanitizeFlags::SANITIZE_NONE
143
144
\param sanitizeOps : the bits here are used to set which sanitization
145
operations are carried
146
out. The elements of the \c SanitizeFlags enum define
147
the operations.
148
149
<b>Notes:</b>
150
- This attempts to fix known issues with certain reaction drawers.
151
HOWEVER, if any flag is returned in operationsPerformed,
152
the reaction may still be suspect to its validity.
153
- Aromaticity can be tricky when starting with Kekule structures that
154
have query features, aromaticity works well for non-query rings, however
155
certain structures (substitutions on Kekule rings that should really be
156
aromatic) may not have enough information.
157
*/
158
159
RDKIT_CHEMREACTIONS_EXPORT
void
sanitizeRxn
(
160
ChemicalReaction
&rxn,
unsigned
int
&operationsThatFailed,
161
unsigned
int
sanitizeOps =
SANITIZE_ALL
,
162
const
MolOps::AdjustQueryParameters
¶ms =
DefaultRxnAdjustParams
());
163
//! \overload
164
RDKIT_CHEMREACTIONS_EXPORT
void
sanitizeRxn
(
165
ChemicalReaction
&rxn,
166
const
MolOps::AdjustQueryParameters
¶ms =
DefaultRxnAdjustParams
());
167
168
//! Does the usual molecular sanitization on each reactant, agent, and product
169
/// of the reaction
170
RDKIT_CHEMREACTIONS_EXPORT
void
sanitizeRxnAsMols
(
171
ChemicalReaction
&rxn,
172
unsigned
int
sanitizeOps = MolOps::SanitizeFlags::SANITIZE_ALL);
173
174
}
// namespace RxnOps
175
}
// namespace RDKit
176
177
#endif
MolOps.h
BOOST_LOG
#define BOOST_LOG(__arg__)
Definition
RDLog.h:109
rdWarningLog
RDKIT_RDGENERAL_EXPORT RDLogger rdWarningLog
Reaction.h
RDKit::ChemicalReaction
This is a class for storing and applying general chemical reactions.
Definition
Reaction.h:122
RDKit::RxnSanitizeException::what
const char * what() const noexcept override
Definition
SanitizeRxn.h:49
RDKit::RxnSanitizeException::RxnSanitizeException
RxnSanitizeException(std::string msg)
Definition
SanitizeRxn.h:48
RDKit::RxnSanitizeException::~RxnSanitizeException
~RxnSanitizeException() noexcept override=default
RDKit::RxnSanitizeException::RxnSanitizeException
RxnSanitizeException(const char *msg)
Definition
SanitizeRxn.h:47
export.h
RDKIT_CHEMREACTIONS_EXPORT
#define RDKIT_CHEMREACTIONS_EXPORT
Definition
export.h:71
RDKit::MolOps::ADJUST_IGNORENONE
@ ADJUST_IGNORENONE
Definition
MolOps.h:399
RDKit::MolOps::ADJUST_IGNOREDUMMIES
@ ADJUST_IGNOREDUMMIES
Definition
MolOps.h:402
RDKit::MolOps::ADJUST_IGNOREALL
@ ADJUST_IGNOREALL
Definition
MolOps.h:405
RDKit::RxnOps
Definition
SanitizeRxn.h:56
RDKit::RxnOps::fixAtomMaps
RDKIT_CHEMREACTIONS_EXPORT void fixAtomMaps(ChemicalReaction &rxn)
RDKit::RxnOps::DefaultRxnAdjustParams
const MolOps::AdjustQueryParameters DefaultRxnAdjustParams()
Definition
SanitizeRxn.h:76
RDKit::RxnOps::ChemDrawRxnAdjustParams
const MolOps::AdjustQueryParameters ChemDrawRxnAdjustParams()
Definition
SanitizeRxn.h:90
RDKit::RxnOps::sanitizeRxnAsMols
RDKIT_CHEMREACTIONS_EXPORT void sanitizeRxnAsMols(ChemicalReaction &rxn, unsigned int sanitizeOps=MolOps::SanitizeFlags::SANITIZE_ALL)
RDKit::RxnOps::MatchOnlyAtRgroupsAdjustParams
const MolOps::AdjustQueryParameters MatchOnlyAtRgroupsAdjustParams()
Definition
SanitizeRxn.h:104
RDKit::RxnOps::SANITIZE_ADJUST_REACTANTS
@ SANITIZE_ADJUST_REACTANTS
Definition
SanitizeRxn.h:119
RDKit::RxnOps::SANITIZE_MERGEHS
@ SANITIZE_MERGEHS
Definition
SanitizeRxn.h:120
RDKit::RxnOps::SANITIZE_ALL
@ SANITIZE_ALL
Definition
SanitizeRxn.h:122
RDKit::RxnOps::SANITIZE_ATOM_MAPS
@ SANITIZE_ATOM_MAPS
Definition
SanitizeRxn.h:118
RDKit::RxnOps::SANITIZE_ADJUST_PRODUCTS
@ SANITIZE_ADJUST_PRODUCTS
Definition
SanitizeRxn.h:121
RDKit::RxnOps::SANITIZE_NONE
@ SANITIZE_NONE
Definition
SanitizeRxn.h:116
RDKit::RxnOps::SANITIZE_RGROUP_NAMES
@ SANITIZE_RGROUP_NAMES
Definition
SanitizeRxn.h:117
RDKit::RxnOps::sanitizeRxn
RDKIT_CHEMREACTIONS_EXPORT void sanitizeRxn(ChemicalReaction &rxn, unsigned int &operationsThatFailed, unsigned int sanitizeOps=SANITIZE_ALL, const MolOps::AdjustQueryParameters ¶ms=DefaultRxnAdjustParams())
carries out a collection of tasks for cleaning up a reaction and ensuring that it makes "chemical sen...
RDKit::RxnOps::adjustTemplates
RDKIT_CHEMREACTIONS_EXPORT void adjustTemplates(const MOL_SPTR_VECT &templates, const MolOps::AdjustQueryParameters ¶ms)
Adjusts the reactant templates to properly match reagents.
RDKit::RxnOps::fixRGroups
RDKIT_CHEMREACTIONS_EXPORT void fixRGroups(ChemicalReaction &rxn)
RDKit::RxnOps::fixHs
RDKIT_CHEMREACTIONS_EXPORT void fixHs(ChemicalReaction &rxn)
merge query Hs if appropriate
RDKit
Std stuff.
Definition
Abbreviations.h:19
RDKit::MOL_SPTR_VECT
std::vector< boost::shared_ptr< ROMol > > MOL_SPTR_VECT
Definition
FragCatParams.h:21
RDKit::MolOps::AdjustQueryParameters
Parameters controlling the behavior of MolOps::adjustQueryProperties.
Definition
MolOps.h:417
RDKit::MolOps::AdjustQueryParameters::adjustDegreeFlags
std::uint32_t adjustDegreeFlags
Definition
MolOps.h:419
RDKit::MolOps::AdjustQueryParameters::makeDummiesQueries
bool makeDummiesQueries
Definition
MolOps.h:425
RDKit::MolOps::AdjustQueryParameters::adjustRingCountFlags
std::uint32_t adjustRingCountFlags
Definition
MolOps.h:422
RDKit::MolOps::AdjustQueryParameters::adjustDegree
bool adjustDegree
Definition
MolOps.h:418
RDKit::MolOps::AdjustQueryParameters::aromatizeIfPossible
bool aromatizeIfPossible
Definition
MolOps.h:428
RDKit::MolOps::AdjustQueryParameters::adjustRingCount
bool adjustRingCount
Definition
MolOps.h:421
GraphMol
ChemReactions
SanitizeRxn.h
Generated on
for RDKit by
1.17.0