RDKit: SanitizeRxn.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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