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 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.
60 
61 //! If atom maps are not defined on rgroups, attempt to deduce them from the
62 //! RGroup
63 //! labels, or add new ones if possible.
65 
66 //! 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"
91  << std::endl;
93  params.adjustDegree = true;
95  params.adjustRingCount = false;
97  params.makeDummiesQueries = false;
98  params.aromatizeIfPossible = true;
99  return params;
100 }
101 
104  params.adjustDegree = true;
106  params.adjustRingCount = false;
108  params.makeDummiesQueries = false;
109  params.aromatizeIfPossible = true;
110  return params;
111 }
112 
113 typedef enum {
119  SANITIZE_ALL = 0xFFFFFFFF
121 
122 //! \brief carries out a collection of tasks for cleaning up a reaction and
123 // ensuring
124 //! that it makes "chemical sense" in the context of RDKit reacitons
125 /*!
126  This functions calls the following in sequence
127  -# RxnOps::fixRGroups()
128  -# RxnOps::fixupAtomMaps()
129  -# RxnOps::fixupTemplateAromaticity()
130  -# RxnOps::mergeHs()
131 
132  \param rxn : the ChemicalReaction to be cleaned
133 
134  \param operationThatFailed : the first (if any) sanitization operation that
135  fails is set here.
136  The values are taken from the \c SanitizeFlags
137  enum.
138  On success, the value is \c
139  SanitizeFlags::SANITIZE_NONE
140 
141  \param sanitizeOps : the bits here are used to set which sanitization
142  operations are carried
143  out. The elements of the \c SanitizeFlags enum define
144  the operations.
145 
146  <b>Notes:</b>
147  - This attempts to fix known issues with certain reaction drawers.
148  HOWEVER, if any flag is returned in operationsPerformed,
149  the reaction may still be suspect to its validity.
150  - Aromaticity can be tricky when starting with Kekule structures that
151  have query features, aromaticity works well for non-query rings, however
152  certain structures (substitutions on Kekule rings that should really be
153  aromatic) may not have enough information.
154 */
155 
157  ChemicalReaction &rxn, unsigned int &operationsThatFailed,
158  unsigned int sanitizeOps = SANITIZE_ALL,
160 //! \overload
162  ChemicalReaction &rxn,
164 
165 } // namespace RxnOps
166 } // namespace RDKit
167 
168 #endif
BOOST_LOG
#define BOOST_LOG(__arg__)
Definition: RDLog.h:88
RDKit::MolOps::AdjustQueryParameters::aromatizeIfPossible
bool aromatizeIfPossible
Definition: MolOps.h:285
RDKit::RxnSanitizeException::RxnSanitizeException
RxnSanitizeException(const char *msg)
Definition: SanitizeRxn.h:46
RDKit::MolOps::AdjustQueryParameters
Definition: MolOps.h:277
RDKit::RxnOps::sanitizeRxn
RDKIT_CHEMREACTIONS_EXPORT void sanitizeRxn(ChemicalReaction &rxn, unsigned int &operationsThatFailed, unsigned int sanitizeOps=SANITIZE_ALL, const MolOps::AdjustQueryParameters &params=DefaultRxnAdjustParams())
carries out a collection of tasks for cleaning up a reaction and
MolOps.h
RDKit::RxnOps::adjustTemplates
RDKIT_CHEMREACTIONS_EXPORT void adjustTemplates(ChemicalReaction &rxn, const MolOps::AdjustQueryParameters &params)
Adjusts the reactant templates to properly match reagents.
RDKit::RxnOps::fixHs
RDKIT_CHEMREACTIONS_EXPORT void fixHs(ChemicalReaction &rxn)
merge query Hs if appropriate
RDKit::RxnOps::SANITIZE_NONE
@ SANITIZE_NONE
Definition: SanitizeRxn.h:114
RDKit::MolOps::AdjustQueryParameters::makeDummiesQueries
bool makeDummiesQueries
Definition: MolOps.h:283
RDKit::MolOps::AdjustQueryParameters::adjustDegree
bool adjustDegree
Definition: MolOps.h:278
RDKit::RxnOps::ChemDrawRxnAdjustParams
const MolOps::AdjustQueryParameters ChemDrawRxnAdjustParams()
Definition: SanitizeRxn.h:88
RDKit::MolOps::ADJUST_IGNOREALL
@ ADJUST_IGNOREALL
Definition: MolOps.h:274
RDKit::RxnSanitizeException::~RxnSanitizeException
~RxnSanitizeException()
Definition: SanitizeRxn.h:49
RDKit::MolOps::AdjustQueryParameters::adjustRingCountFlags
std::uint32_t adjustRingCountFlags
Definition: MolOps.h:281
RDKit::RxnOps::SanitizeRxnFlags
SanitizeRxnFlags
Definition: SanitizeRxn.h:113
RDKit::MolOps::AdjustQueryParameters::adjustRingCount
bool adjustRingCount
Definition: MolOps.h:280
RDKit::RxnOps::SANITIZE_ADJUST_REACTANTS
@ SANITIZE_ADJUST_REACTANTS
Definition: SanitizeRxn.h:117
RDKit::RxnOps::fixRGroups
RDKIT_CHEMREACTIONS_EXPORT void fixRGroups(ChemicalReaction &rxn)
Reaction.h
RDKit::ChemicalReaction
This is a class for storing and applying general chemical reactions.
Definition: Reaction.h:119
RDKit::RxnSanitizeException::RxnSanitizeException
RxnSanitizeException(const std::string &msg)
Definition: SanitizeRxn.h:47
RDKit::MolOps::ADJUST_IGNORENONE
@ ADJUST_IGNORENONE
Definition: MolOps.h:268
RDKit::RxnOps::SANITIZE_ATOM_MAPS
@ SANITIZE_ATOM_MAPS
Definition: SanitizeRxn.h:116
RDKit::RxnOps::DefaultRxnAdjustParams
const MolOps::AdjustQueryParameters DefaultRxnAdjustParams()
Definition: SanitizeRxn.h:74
RDKit
Std stuff.
Definition: Atom.h:30
RDKit::RxnOps::SANITIZE_ALL
@ SANITIZE_ALL
Definition: SanitizeRxn.h:119
RDKit::MolOps::AdjustQueryParameters::adjustDegreeFlags
std::uint32_t adjustDegreeFlags
Definition: MolOps.h:279
RDKit::RxnOps::SANITIZE_RGROUP_NAMES
@ SANITIZE_RGROUP_NAMES
Definition: SanitizeRxn.h:115
RDKIT_CHEMREACTIONS_EXPORT
#define RDKIT_CHEMREACTIONS_EXPORT
Definition: export.h:60
rdWarningLog
RDKIT_RDGENERAL_EXPORT std::shared_ptr< boost::logging::rdLogger > rdWarningLog
RDKit::RxnOps::MatchOnlyAtRgroupsAdjustParams
const MolOps::AdjustQueryParameters MatchOnlyAtRgroupsAdjustParams()
Definition: SanitizeRxn.h:102
RDKit::RxnSanitizeException::message
const char * message() const
Definition: SanitizeRxn.h:48
RDKit::RxnSanitizeException
class for flagging sanitization errors
Definition: SanitizeRxn.h:44
RDKit::MolOps::ADJUST_IGNOREDUMMIES
@ ADJUST_IGNOREDUMMIES
Definition: MolOps.h:271
RDKit::RxnOps::SANITIZE_MERGEHS
@ SANITIZE_MERGEHS
Definition: SanitizeRxn.h:118
RDKit::RxnOps::fixAtomMaps
RDKIT_CHEMREACTIONS_EXPORT void fixAtomMaps(ChemicalReaction &rxn)
export.h