Loading...
Searching...
No Matches
SanitizeRxn.h
Go to the documentation of this file.
//
// Copyright (c) 2015, Novartis Institutes for BioMedical Research Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Novartis Institutes for BioMedical Research Inc.
// nor the names of its contributors may be used to endorse or promote
// products derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#include <RDGeneral/export.h>
#ifndef RDKIT_SANITIZERXN_H
#define RDKIT_SANITIZERXN_H
#include "Reaction.h"
#include <GraphMol/MolOps.h>
#include <string>
#include <exception>
#include <utility>
namespace RDKit {
//! class for flagging sanitization errors
class RDKIT_CHEMREACTIONS_EXPORT RxnSanitizeException : public std::exception {
public:
RxnSanitizeException(const char *msg) : _msg(msg) {}
RxnSanitizeException(std::string msg) : _msg(std::move(msg)) {}
const char *what() const noexcept override { return _msg.c_str(); }
~RxnSanitizeException() noexcept override = default;
private:
std::string _msg;
};
namespace RxnOps {
//! Any dummy atom with a map but no RGroup label, should be an RGroup
//! in RDKit's view of a reaction.
//! See if these atoms can be salvaged into RGroups.
RDKIT_CHEMREACTIONS_EXPORT void fixRGroups(ChemicalReaction &rxn);
//! If atom maps are not defined on rgroups, attempt to deduce them from the
//! RGroup
//! labels, or add new ones if possible.
RDKIT_CHEMREACTIONS_EXPORT void fixAtomMaps(ChemicalReaction &rxn);
//! Adjusts the reactant templates to properly match reagents
RDKIT_CHEMREACTIONS_EXPORT void adjustTemplates(
const MOL_SPTR_VECT &templates,
const MolOps::AdjustQueryParameters &params);
//! merge query Hs if appropriate
RDKIT_CHEMREACTIONS_EXPORT void fixHs(ChemicalReaction &rxn);
// Default adjustment parameters for matching reagents
inline const MolOps::AdjustQueryParameters DefaultRxnAdjustParams() {
MolOps::AdjustQueryParameters params;
params.adjustDegree = false;
params.adjustDegreeFlags = MolOps::ADJUST_IGNOREALL;
params.adjustRingCount = false;
params.adjustRingCountFlags = MolOps::ADJUST_IGNOREALL;
params.makeDummiesQueries = false;
params.aromatizeIfPossible = true;
return params;
}
// Default adjustment parameters for ChemDraw style matching of reagents
// -- deprecated - renamed MatchOnlyAtRgroupsAdjustParams
// -- this doesn't match sciquest style searching
inline const MolOps::AdjustQueryParameters ChemDrawRxnAdjustParams() {
BOOST_LOG(rdWarningLog)
<< " deprecated -- please use MatchOnlyAtRgroupsAdjustParams instead"
<< std::endl;
MolOps::AdjustQueryParameters params;
params.adjustDegree = true;
params.adjustDegreeFlags = MolOps::ADJUST_IGNOREDUMMIES;
params.adjustRingCount = false;
params.adjustRingCountFlags = MolOps::ADJUST_IGNORENONE;
params.makeDummiesQueries = false;
params.aromatizeIfPossible = true;
return params;
}
inline const MolOps::AdjustQueryParameters MatchOnlyAtRgroupsAdjustParams() {
MolOps::AdjustQueryParameters params;
params.adjustDegree = true;
params.adjustDegreeFlags = MolOps::ADJUST_IGNOREDUMMIES;
params.adjustRingCount = false;
params.adjustRingCountFlags = MolOps::ADJUST_IGNORENONE;
params.makeDummiesQueries = false;
params.aromatizeIfPossible = true;
return params;
}
typedef enum {
SANITIZE_NONE = 0x0,
SANITIZE_RGROUP_NAMES = 0x1,
SANITIZE_ATOM_MAPS = 0x2,
SANITIZE_ADJUST_REACTANTS = 0x4,
SANITIZE_MERGEHS = 0x8,
SANITIZE_ADJUST_PRODUCTS = 0x10,
SANITIZE_ALL = 0xFFFFFFFF
} SanitizeRxnFlags;
//! \brief carries out a collection of tasks for cleaning up a reaction and
/// ensuring
//! that it makes "chemical sense" in the context of RDKit reacitons
/*!
This functions calls the following in sequence
-# RxnOps::fixRGroups()
-# RxnOps::fixupAtomMaps()
-# RxnOps::fixupTemplateAromaticity()
-# RxnOps::mergeHs()
\param rxn : the ChemicalReaction to be cleaned
\param operationThatFailed : the first (if any) sanitization operation that
fails is set here.
The values are taken from the \c SanitizeFlags
enum.
On success, the value is \c
SanitizeFlags::SANITIZE_NONE
\param sanitizeOps : the bits here are used to set which sanitization
operations are carried
out. The elements of the \c SanitizeFlags enum define
the operations.
<b>Notes:</b>
- This attempts to fix known issues with certain reaction drawers.
HOWEVER, if any flag is returned in operationsPerformed,
the reaction may still be suspect to its validity.
- Aromaticity can be tricky when starting with Kekule structures that
have query features, aromaticity works well for non-query rings, however
certain structures (substitutions on Kekule rings that should really be
aromatic) may not have enough information.
*/
RDKIT_CHEMREACTIONS_EXPORT void sanitizeRxn(
ChemicalReaction &rxn, unsigned int &operationsThatFailed,
unsigned int sanitizeOps = SANITIZE_ALL,
const MolOps::AdjustQueryParameters &params = DefaultRxnAdjustParams());
//! \overload
RDKIT_CHEMREACTIONS_EXPORT void sanitizeRxn(
ChemicalReaction &rxn,
const MolOps::AdjustQueryParameters &params = DefaultRxnAdjustParams());
//! Does the usual molecular sanitization on each reactant, agent, and product
/// of the reaction
RDKIT_CHEMREACTIONS_EXPORT void sanitizeRxnAsMols(
ChemicalReaction &rxn,
unsigned int sanitizeOps = MolOps::SanitizeFlags::SANITIZE_ALL);
} // namespace RxnOps
} // namespace RDKit
#endif
MolOps.h
BOOST_LOG
#define BOOST_LOG(__arg__)
Definition RDLog.h:110
rdWarningLog
RDKIT_RDGENERAL_EXPORT RDLogger rdWarningLog
Reaction.h
RDKit::ChemicalReaction
This is a class for storing and applying general chemical reactions.
Definition Reaction.h:122
RDKit::RxnSanitizeException::what
const char * what() const noexcept override
Definition SanitizeRxn.h:49
RDKit::RxnSanitizeException::RxnSanitizeException
RxnSanitizeException(std::string msg)
Definition SanitizeRxn.h:48
RDKit::RxnSanitizeException::~RxnSanitizeException
~RxnSanitizeException() noexcept override=default
RDKit::RxnSanitizeException::RxnSanitizeException
RxnSanitizeException(const char *msg)
Definition SanitizeRxn.h:47
export.h
RDKIT_CHEMREACTIONS_EXPORT
#define RDKIT_CHEMREACTIONS_EXPORT
Definition export.h:57
RDKit::MolOps::ADJUST_IGNORENONE
@ ADJUST_IGNORENONE
Definition MolOps.h:399
RDKit::MolOps::ADJUST_IGNOREDUMMIES
@ ADJUST_IGNOREDUMMIES
Definition MolOps.h:402
RDKit::MolOps::ADJUST_IGNOREALL
@ ADJUST_IGNOREALL
Definition MolOps.h:405
RDKit::RxnOps
Definition SanitizeRxn.h:56
RDKit::RxnOps::fixAtomMaps
RDKIT_CHEMREACTIONS_EXPORT void fixAtomMaps(ChemicalReaction &rxn)
RDKit::RxnOps::DefaultRxnAdjustParams
const MolOps::AdjustQueryParameters DefaultRxnAdjustParams()
Definition SanitizeRxn.h:76
RDKit::RxnOps::ChemDrawRxnAdjustParams
const MolOps::AdjustQueryParameters ChemDrawRxnAdjustParams()
Definition SanitizeRxn.h:90
RDKit::RxnOps::sanitizeRxnAsMols
RDKIT_CHEMREACTIONS_EXPORT void sanitizeRxnAsMols(ChemicalReaction &rxn, unsigned int sanitizeOps=MolOps::SanitizeFlags::SANITIZE_ALL)
RDKit::RxnOps::MatchOnlyAtRgroupsAdjustParams
const MolOps::AdjustQueryParameters MatchOnlyAtRgroupsAdjustParams()
Definition SanitizeRxn.h:104
RDKit::RxnOps::SANITIZE_ADJUST_REACTANTS
@ SANITIZE_ADJUST_REACTANTS
Definition SanitizeRxn.h:119
RDKit::RxnOps::SANITIZE_MERGEHS
@ SANITIZE_MERGEHS
Definition SanitizeRxn.h:120
RDKit::RxnOps::SANITIZE_ALL
@ SANITIZE_ALL
Definition SanitizeRxn.h:122
RDKit::RxnOps::SANITIZE_ATOM_MAPS
@ SANITIZE_ATOM_MAPS
Definition SanitizeRxn.h:118
RDKit::RxnOps::SANITIZE_ADJUST_PRODUCTS
@ SANITIZE_ADJUST_PRODUCTS
Definition SanitizeRxn.h:121
RDKit::RxnOps::SANITIZE_NONE
@ SANITIZE_NONE
Definition SanitizeRxn.h:116
RDKit::RxnOps::SANITIZE_RGROUP_NAMES
@ SANITIZE_RGROUP_NAMES
Definition SanitizeRxn.h:117
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 ensuring that it makes "chemical sen...
RDKit::RxnOps::adjustTemplates
RDKIT_CHEMREACTIONS_EXPORT void adjustTemplates(const MOL_SPTR_VECT &templates, const MolOps::AdjustQueryParameters &params)
Adjusts the reactant templates to properly match reagents.
RDKit::RxnOps::fixRGroups
RDKIT_CHEMREACTIONS_EXPORT void fixRGroups(ChemicalReaction &rxn)
RDKit::RxnOps::fixHs
RDKIT_CHEMREACTIONS_EXPORT void fixHs(ChemicalReaction &rxn)
merge query Hs if appropriate
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::MOL_SPTR_VECT
std::vector< boost::shared_ptr< ROMol > > MOL_SPTR_VECT
Definition FragCatParams.h:21
RDKit::MolOps::AdjustQueryParameters
Parameters controlling the behavior of MolOps::adjustQueryProperties.
Definition MolOps.h:417
RDKit::MolOps::AdjustQueryParameters::adjustDegreeFlags
std::uint32_t adjustDegreeFlags
Definition MolOps.h:419
RDKit::MolOps::AdjustQueryParameters::makeDummiesQueries
bool makeDummiesQueries
Definition MolOps.h:425
RDKit::MolOps::AdjustQueryParameters::adjustRingCountFlags
std::uint32_t adjustRingCountFlags
Definition MolOps.h:422
RDKit::MolOps::AdjustQueryParameters::adjustDegree
bool adjustDegree
Definition MolOps.h:418
RDKit::MolOps::AdjustQueryParameters::aromatizeIfPossible
bool aromatizeIfPossible
Definition MolOps.h:428
RDKit::MolOps::AdjustQueryParameters::adjustRingCount
bool adjustRingCount
Definition MolOps.h:421