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
87  params.adjustDegree = true;
89  params.adjustRingCount = false;
91  params.makeDummiesQueries = false;
92  params.aromatizeIfPossible = true;
93  return params;
94 }
95 
96 typedef enum {
102  SANITIZE_ALL = 0xFFFFFFFF
104 
105 //! \brief carries out a collection of tasks for cleaning up a reaction and
106 // ensuring
107 //! that it makes "chemical sense" in the context of RDKit reacitons
108 /*!
109  This functions calls the following in sequence
110  -# RxnOps::fixRGroups()
111  -# RxnOps::fixupAtomMaps()
112  -# RxnOps::fixupTemplateAromaticity()
113  -# RxnOps::mergeHs()
114 
115  \param rxn : the ChemicalReaction to be cleaned
116 
117  \param operationThatFailed : the first (if any) sanitization operation that
118  fails is set here.
119  The values are taken from the \c SanitizeFlags
120  enum.
121  On success, the value is \c
122  SanitizeFlags::SANITIZE_NONE
123 
124  \param sanitizeOps : the bits here are used to set which sanitization
125  operations are carried
126  out. The elements of the \c SanitizeFlags enum define
127  the operations.
128 
129  <b>Notes:</b>
130  - This attempts to fix known issues with certain reaction drawers.
131  HOWEVER, if any flag is returned in operationsPerformed,
132  the reaction may still be suspect to its validity.
133  - Aromaticity can be tricky when starting with Kekule structures that
134  have query features, aromaticity works well for non-query rings, however
135  certain structures (substitutions on Kekule rings that should really be
136  aromatic) may not have enough information.
137 */
138 
139 void sanitizeRxn(ChemicalReaction &rxn,
140  unsigned int &operationsThatFailed,
141  unsigned int sanitizeOps = SANITIZE_ALL,
143 //! \overload
144 void sanitizeRxn(ChemicalReaction &rxn,
146 
147 }
148 }
149 
150 #endif
boost::uint32_t adjustDegreeFlags
Definition: MolOps.h:256
void fixAtomMaps(ChemicalReaction &rxn)
boost::uint32_t adjustRingCountFlags
Definition: MolOps.h:258
const MolOps::AdjustQueryParameters ChemDrawRxnAdjustParams()
Definition: SanitizeRxn.h:85
This is a class for storing and applying general chemical reactions.
Definition: Reaction.h:116
RxnSanitizeException(const char *msg)
Definition: SanitizeRxn.h:45
class for flagging sanitization errors
Definition: SanitizeRxn.h:43
Includes a bunch of functionality for handling Atom and Bond queries.
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