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#include <utility>
41
42namespace RDKit {
43
44//! class for flagging sanitization errors
45class RDKIT_CHEMREACTIONS_EXPORT RxnSanitizeException : public std::exception {
46 public:
47 RxnSanitizeException(const char *msg) : _msg(msg) {}
48 RxnSanitizeException(std::string msg) : _msg(std::move(msg)) {}
49 const char *what() const noexcept override { return _msg.c_str(); }
50 ~RxnSanitizeException() noexcept override = default;
51
52 private:
53 std::string _msg;
54};
55
56namespace 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
63//! RGroup
64//! labels, or add new ones if possible.
66
67//! Adjusts the reactant templates to properly match reagents
70
71//! merge query Hs if appropriate
73
74// Default adjustment parameters for matching reagents
77 params.adjustDegree = false;
79 params.adjustRingCount = false;
81 params.makeDummiesQueries = false;
82 params.aromatizeIfPossible = true;
83 return params;
84}
85
86// Default adjustment parameters for ChemDraw style matching of reagents
87// -- deprecated - renamed MatchOnlyAtRgroupsAdjustParams
88// -- this doesn't match sciquest style searching
91 << " deprecated -- please use MatchOnlyAtRgroupsAdjustParams instead"
92 << std::endl;
94 params.adjustDegree = true;
96 params.adjustRingCount = false;
98 params.makeDummiesQueries = false;
99 params.aromatizeIfPossible = true;
100 return params;
101}
102
105 params.adjustDegree = true;
107 params.adjustRingCount = false;
109 params.makeDummiesQueries = false;
110 params.aromatizeIfPossible = true;
111 return params;
112}
113
114typedef enum {
120 SANITIZE_ALL = 0xFFFFFFFF
122
123//! \brief carries out a collection of tasks for cleaning up a reaction and
124/// ensuring
125//! that it makes "chemical sense" in the context of RDKit reacitons
126/*!
127 This functions calls the following in sequence
128 -# RxnOps::fixRGroups()
129 -# RxnOps::fixupAtomMaps()
130 -# RxnOps::fixupTemplateAromaticity()
131 -# RxnOps::mergeHs()
132
133 \param rxn : the ChemicalReaction to be cleaned
134
135 \param operationThatFailed : the first (if any) sanitization operation that
136 fails is set here.
137 The values are taken from the \c SanitizeFlags
138 enum.
139 On success, the value is \c
140 SanitizeFlags::SANITIZE_NONE
141
142 \param sanitizeOps : the bits here are used to set which sanitization
143 operations are carried
144 out. The elements of the \c SanitizeFlags enum define
145 the operations.
146
147 <b>Notes:</b>
148 - This attempts to fix known issues with certain reaction drawers.
149 HOWEVER, if any flag is returned in operationsPerformed,
150 the reaction may still be suspect to its validity.
151 - Aromaticity can be tricky when starting with Kekule structures that
152 have query features, aromaticity works well for non-query rings, however
153 certain structures (substitutions on Kekule rings that should really be
154 aromatic) may not have enough information.
155*/
156
158 ChemicalReaction &rxn, unsigned int &operationsThatFailed,
159 unsigned int sanitizeOps = SANITIZE_ALL,
161//! \overload
163 ChemicalReaction &rxn,
165
166} // namespace RxnOps
167} // namespace RDKit
168
169#endif
#define BOOST_LOG(__arg__)
Definition: RDLog.h:110
RDKIT_RDGENERAL_EXPORT RDLogger rdWarningLog
This is a class for storing and applying general chemical reactions.
Definition: Reaction.h:121
class for flagging sanitization errors
Definition: SanitizeRxn.h:45
const char * what() const noexcept override
Definition: SanitizeRxn.h:49
RxnSanitizeException(std::string msg)
Definition: SanitizeRxn.h:48
~RxnSanitizeException() noexcept override=default
RxnSanitizeException(const char *msg)
Definition: SanitizeRxn.h:47
#define RDKIT_CHEMREACTIONS_EXPORT
Definition: export.h:49
@ ADJUST_IGNORENONE
Definition: MolOps.h:325
@ ADJUST_IGNOREDUMMIES
Definition: MolOps.h:328
@ ADJUST_IGNOREALL
Definition: MolOps.h:331
RDKIT_CHEMREACTIONS_EXPORT void fixAtomMaps(ChemicalReaction &rxn)
RDKIT_CHEMREACTIONS_EXPORT void adjustTemplates(ChemicalReaction &rxn, const MolOps::AdjustQueryParameters &params)
Adjusts the reactant templates to properly match reagents.
const MolOps::AdjustQueryParameters DefaultRxnAdjustParams()
Definition: SanitizeRxn.h:75
const MolOps::AdjustQueryParameters ChemDrawRxnAdjustParams()
Definition: SanitizeRxn.h:89
const MolOps::AdjustQueryParameters MatchOnlyAtRgroupsAdjustParams()
Definition: SanitizeRxn.h:103
RDKIT_CHEMREACTIONS_EXPORT void sanitizeRxn(ChemicalReaction &rxn, const MolOps::AdjustQueryParameters &params=DefaultRxnAdjustParams())
This is an overloaded member function, provided for convenience. It differs from the above function o...
@ SANITIZE_ADJUST_REACTANTS
Definition: SanitizeRxn.h:118
RDKIT_CHEMREACTIONS_EXPORT void fixRGroups(ChemicalReaction &rxn)
RDKIT_CHEMREACTIONS_EXPORT void fixHs(ChemicalReaction &rxn)
merge query Hs if appropriate
Std stuff.
Definition: Abbreviations.h:19
Parameters controlling the behavior of MolOps::adjustQueryProperties.
Definition: MolOps.h:343