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 #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 
41 namespace RDKit {
42 
43 //! class for flagging sanitization errors
44 class RDKIT_CHEMREACTIONS_EXPORT RxnSanitizeException : public std::exception {
45  public:
46  RxnSanitizeException(const char *msg) : _msg(msg){};
47  RxnSanitizeException(const std::string &msg) : _msg(msg){};
48  const char *message() const { return _msg.c_str(); };
49  ~RxnSanitizeException() throw(){};
50 
51  private:
52  std::string _msg;
53 };
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.
61 
62 //! If atom maps are not defined on rgroups, attempt to deduce them from the RGroup
63 //! labels, or add new ones if possible.
65 
66 
67 //! Adjusts the reactant templates to properly match reagents
69 
70 //! merge query Hs if appropriate
72 
73 // Default adjustment parameters for matching reagents
76  params.adjustDegree = false;
78  params.adjustRingCount = false;
80  params.makeDummiesQueries = false;
81  params.aromatizeIfPossible = true;
82  return params;
83 }
84 
85 // Default adjustment parameters for ChemDraw style matching of reagents
86 // -- deprecated - renamed MatchOnlyAtRgroupsAdjustParams
87 // -- this doesn't match sciquest style searching
90  " deprecated -- please use MatchOnlyAtRgroupsAdjustParams instead" << std::endl;
92  params.adjustDegree = true;
94  params.adjustRingCount = false;
96  params.makeDummiesQueries = false;
97  params.aromatizeIfPossible = true;
98  return params;
99 }
100 
103  params.adjustDegree = true;
105  params.adjustRingCount = false;
107  params.makeDummiesQueries = false;
108  params.aromatizeIfPossible = true;
109  return params;
110 }
111 
112 typedef enum {
118  SANITIZE_ALL = 0xFFFFFFFF
120 
121 //! \brief carries out a collection of tasks for cleaning up a reaction and
122 // ensuring
123 //! that it makes "chemical sense" in the context of RDKit reacitons
124 /*!
125  This functions calls the following in sequence
126  -# RxnOps::fixRGroups()
127  -# RxnOps::fixupAtomMaps()
128  -# RxnOps::fixupTemplateAromaticity()
129  -# RxnOps::mergeHs()
130 
131  \param rxn : the ChemicalReaction to be cleaned
132 
133  \param operationThatFailed : the first (if any) sanitization operation that
134  fails is set here.
135  The values are taken from the \c SanitizeFlags
136  enum.
137  On success, the value is \c
138  SanitizeFlags::SANITIZE_NONE
139 
140  \param sanitizeOps : the bits here are used to set which sanitization
141  operations are carried
142  out. The elements of the \c SanitizeFlags enum define
143  the operations.
144 
145  <b>Notes:</b>
146  - This attempts to fix known issues with certain reaction drawers.
147  HOWEVER, if any flag is returned in operationsPerformed,
148  the reaction may still be suspect to its validity.
149  - Aromaticity can be tricky when starting with Kekule structures that
150  have query features, aromaticity works well for non-query rings, however
151  certain structures (substitutions on Kekule rings that should really be
152  aromatic) may not have enough information.
153 */
154 
156  unsigned int &operationsThatFailed,
157  unsigned int sanitizeOps = SANITIZE_ALL,
159 //! \overload
162 
163 }
164 }
165 
166 #endif
boost::uint32_t adjustDegreeFlags
Definition: MolOps.h:276
#define BOOST_LOG(__arg__)
Definition: RDLog.h:88
RDKIT_CHEMREACTIONS_EXPORT void fixHs(ChemicalReaction &rxn)
merge query Hs if appropriate
boost::uint32_t adjustRingCountFlags
Definition: MolOps.h:278
const MolOps::AdjustQueryParameters ChemDrawRxnAdjustParams()
Definition: SanitizeRxn.h:88
This is a class for storing and applying general chemical reactions.
Definition: Reaction.h:118
const MolOps::AdjustQueryParameters MatchOnlyAtRgroupsAdjustParams()
Definition: SanitizeRxn.h:101
const char * message() const
Definition: SanitizeRxn.h:48
RDKIT_CHEMREACTIONS_EXPORT void sanitizeRxn(ChemicalReaction &rxn, const MolOps::AdjustQueryParameters &params=DefaultRxnAdjustParams())
RxnSanitizeException(const char *msg)
Definition: SanitizeRxn.h:46
class for flagging sanitization errors
Definition: SanitizeRxn.h:44
Std stuff.
Definition: Atom.h:30
const MolOps::AdjustQueryParameters DefaultRxnAdjustParams()
Definition: SanitizeRxn.h:74
RDKIT_CHEMREACTIONS_EXPORT void fixRGroups(ChemicalReaction &rxn)
RDKIT_CHEMREACTIONS_EXPORT void adjustTemplates(ChemicalReaction &rxn, const MolOps::AdjustQueryParameters &params)
Adjusts the reactant templates to properly match reagents.
#define RDKIT_CHEMREACTIONS_EXPORT
Definition: export.h:60
RDKIT_CHEMREACTIONS_EXPORT void fixAtomMaps(ChemicalReaction &rxn)
RDKIT_RDGENERAL_EXPORT boost::logging::rdLogger * rdWarningLog
RxnSanitizeException(const std::string &msg)
Definition: SanitizeRxn.h:47