RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
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.
65RDKIT_CHEMREACTIONS_EXPORT void fixAtomMaps(ChemicalReaction &rxn);
66
67//! Adjusts the reactant templates to properly match reagents
68RDKIT_CHEMREACTIONS_EXPORT void adjustTemplates(
70
71//! merge query Hs if appropriate
73
74// Default adjustment parameters for matching reagents
75inline const MolOps::AdjustQueryParameters DefaultRxnAdjustParams() {
77 params.adjustDegree = false;
78 params.adjustDegreeFlags = MolOps::ADJUST_IGNOREALL;
79 params.adjustRingCount = false;
80 params.adjustRingCountFlags = MolOps::ADJUST_IGNOREALL;
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
89inline const MolOps::AdjustQueryParameters ChemDrawRxnAdjustParams() {
91 << " deprecated -- please use MatchOnlyAtRgroupsAdjustParams instead"
92 << std::endl;
94 params.adjustDegree = true;
95 params.adjustDegreeFlags = MolOps::ADJUST_IGNOREDUMMIES;
96 params.adjustRingCount = false;
97 params.adjustRingCountFlags = MolOps::ADJUST_IGNORENONE;
98 params.makeDummiesQueries = false;
99 params.aromatizeIfPossible = true;
100 return params;
101}
102
103inline const MolOps::AdjustQueryParameters MatchOnlyAtRgroupsAdjustParams() {
105 params.adjustDegree = true;
106 params.adjustDegreeFlags = MolOps::ADJUST_IGNOREDUMMIES;
107 params.adjustRingCount = false;
108 params.adjustRingCountFlags = MolOps::ADJUST_IGNORENONE;
109 params.makeDummiesQueries = false;
110 params.aromatizeIfPossible = true;
111 return params;
112}
113
114typedef enum {
115 SANITIZE_NONE = 0x0,
116 SANITIZE_RGROUP_NAMES = 0x1,
117 SANITIZE_ATOM_MAPS = 0x2,
118 SANITIZE_ADJUST_REACTANTS = 0x4,
119 SANITIZE_MERGEHS = 0x8,
120 SANITIZE_ALL = 0xFFFFFFFF
121} SanitizeRxnFlags;
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
157RDKIT_CHEMREACTIONS_EXPORT void sanitizeRxn(
158 ChemicalReaction &rxn, unsigned int &operationsThatFailed,
159 unsigned int sanitizeOps = SANITIZE_ALL,
160 const MolOps::AdjustQueryParameters &params = DefaultRxnAdjustParams());
161//! \overload
162RDKIT_CHEMREACTIONS_EXPORT void sanitizeRxn(
163 ChemicalReaction &rxn,
164 const MolOps::AdjustQueryParameters &params = DefaultRxnAdjustParams());
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
Std stuff.
Parameters controlling the behavior of MolOps::adjustQueryProperties.
Definition MolOps.h:343