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(
69 const MOL_SPTR_VECT &templates,
70 const MolOps::AdjustQueryParameters &params);
71
72//! merge query Hs if appropriate
74
75// Default adjustment parameters for matching reagents
76inline const MolOps::AdjustQueryParameters DefaultRxnAdjustParams() {
78 params.adjustDegree = false;
79 params.adjustDegreeFlags = MolOps::ADJUST_IGNOREALL;
80 params.adjustRingCount = false;
81 params.adjustRingCountFlags = MolOps::ADJUST_IGNOREALL;
82 params.makeDummiesQueries = false;
83 params.aromatizeIfPossible = true;
84 return params;
85}
86
87// Default adjustment parameters for ChemDraw style matching of reagents
88// -- deprecated - renamed MatchOnlyAtRgroupsAdjustParams
89// -- this doesn't match sciquest style searching
90inline const MolOps::AdjustQueryParameters ChemDrawRxnAdjustParams() {
92 << " deprecated -- please use MatchOnlyAtRgroupsAdjustParams instead"
93 << std::endl;
95 params.adjustDegree = true;
96 params.adjustDegreeFlags = MolOps::ADJUST_IGNOREDUMMIES;
97 params.adjustRingCount = false;
98 params.adjustRingCountFlags = MolOps::ADJUST_IGNORENONE;
99 params.makeDummiesQueries = false;
100 params.aromatizeIfPossible = true;
101 return params;
102}
103
104inline const MolOps::AdjustQueryParameters MatchOnlyAtRgroupsAdjustParams() {
106 params.adjustDegree = true;
107 params.adjustDegreeFlags = MolOps::ADJUST_IGNOREDUMMIES;
108 params.adjustRingCount = false;
109 params.adjustRingCountFlags = MolOps::ADJUST_IGNORENONE;
110 params.makeDummiesQueries = false;
111 params.aromatizeIfPossible = true;
112 return params;
113}
114
115typedef enum {
116 SANITIZE_NONE = 0x0,
117 SANITIZE_RGROUP_NAMES = 0x1,
118 SANITIZE_ATOM_MAPS = 0x2,
119 SANITIZE_ADJUST_REACTANTS = 0x4,
120 SANITIZE_MERGEHS = 0x8,
121 SANITIZE_ADJUST_PRODUCTS = 0x10,
122 SANITIZE_ALL = 0xFFFFFFFF
123} SanitizeRxnFlags;
124
125//! \brief carries out a collection of tasks for cleaning up a reaction and
126/// ensuring
127//! that it makes "chemical sense" in the context of RDKit reacitons
128/*!
129 This functions calls the following in sequence
130 -# RxnOps::fixRGroups()
131 -# RxnOps::fixupAtomMaps()
132 -# RxnOps::fixupTemplateAromaticity()
133 -# RxnOps::mergeHs()
134
135 \param rxn : the ChemicalReaction to be cleaned
136
137 \param operationThatFailed : the first (if any) sanitization operation that
138 fails is set here.
139 The values are taken from the \c SanitizeFlags
140 enum.
141 On success, the value is \c
142 SanitizeFlags::SANITIZE_NONE
143
144 \param sanitizeOps : the bits here are used to set which sanitization
145 operations are carried
146 out. The elements of the \c SanitizeFlags enum define
147 the operations.
148
149 <b>Notes:</b>
150 - This attempts to fix known issues with certain reaction drawers.
151 HOWEVER, if any flag is returned in operationsPerformed,
152 the reaction may still be suspect to its validity.
153 - Aromaticity can be tricky when starting with Kekule structures that
154 have query features, aromaticity works well for non-query rings, however
155 certain structures (substitutions on Kekule rings that should really be
156 aromatic) may not have enough information.
157*/
158
159RDKIT_CHEMREACTIONS_EXPORT void sanitizeRxn(
160 ChemicalReaction &rxn, unsigned int &operationsThatFailed,
161 unsigned int sanitizeOps = SANITIZE_ALL,
162 const MolOps::AdjustQueryParameters &params = DefaultRxnAdjustParams());
163//! \overload
164RDKIT_CHEMREACTIONS_EXPORT void sanitizeRxn(
165 ChemicalReaction &rxn,
166 const MolOps::AdjustQueryParameters &params = DefaultRxnAdjustParams());
167
168//! Does the usual molecular sanitization on each reactant, agent, and product
169/// of the reaction
170RDKIT_CHEMREACTIONS_EXPORT void sanitizeRxnAsMols(
171 ChemicalReaction &rxn,
172 unsigned int sanitizeOps = MolOps::SanitizeFlags::SANITIZE_ALL);
173
174} // namespace RxnOps
175} // namespace RDKit
176
177#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.
std::vector< boost::shared_ptr< ROMol > > MOL_SPTR_VECT
Parameters controlling the behavior of MolOps::adjustQueryProperties.
Definition MolOps.h:392