RDKit
Open-source cheminformatics and machine learning.
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
68 
69 //! merge query Hs if appropriate
70 void fixHs(ChemicalReaction &rxn);
71 
72 // Default adjustment parameters for matching reagents
75  params.adjustDegree = false;
77  params.adjustRingCount = false;
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
89  " deprecated -- please use MatchOnlyAtRgroupsAdjustParams instead" << std::endl;
91  params.adjustDegree = true;
93  params.adjustRingCount = false;
95  params.makeDummiesQueries = false;
96  params.aromatizeIfPossible = true;
97  return params;
98 }
99 
102  params.adjustDegree = true;
104  params.adjustRingCount = false;
106  params.makeDummiesQueries = false;
107  params.aromatizeIfPossible = true;
108  return params;
109 }
110 
111 typedef enum {
117  SANITIZE_ALL = 0xFFFFFFFF
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,
158 //! \overload
159 void sanitizeRxn(ChemicalReaction &rxn,
161 
162 }
163 }
164 
165 #endif
boost::uint32_t adjustDegreeFlags
Definition: MolOps.h:258
void fixAtomMaps(ChemicalReaction &rxn)
#define BOOST_LOG(__arg__)
Definition: RDLog.h:87
boost::uint32_t adjustRingCountFlags
Definition: MolOps.h:260
const MolOps::AdjustQueryParameters ChemDrawRxnAdjustParams()
Definition: SanitizeRxn.h:87
This is a class for storing and applying general chemical reactions.
Definition: Reaction.h:116
const MolOps::AdjustQueryParameters MatchOnlyAtRgroupsAdjustParams()
Definition: SanitizeRxn.h:100
boost::logging::rdLogger * rdWarningLog
RxnSanitizeException(const char *msg)
Definition: SanitizeRxn.h:45
class for flagging sanitization errors
Definition: SanitizeRxn.h:43
Std stuff.
Definition: Atom.h:29
const MolOps::AdjustQueryParameters DefaultRxnAdjustParams()
Definition: SanitizeRxn.h:73
void sanitizeRxn(ChemicalReaction &rxn, const MolOps::AdjustQueryParameters &params=DefaultRxnAdjustParams())
void fixRGroups(ChemicalReaction &rxn)
const char * message() const
Definition: SanitizeRxn.h:47
void fixHs(ChemicalReaction &rxn)
merge query Hs if appropriate
void adjustTemplates(ChemicalReaction &rxn, const MolOps::AdjustQueryParameters &params)
Adjusts the reactant templates to properly match reagents.
RxnSanitizeException(const std::string &msg)
Definition: SanitizeRxn.h:46