RGroupDecomp.h
Go to the documentation of this file.
//
// Copyright (c) 2017-2021, Novartis Institutes for BioMedical Research Inc.
// and other RDKit contributors
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#include <RDGeneral/export.h>
#ifndef RDKIT_RGROUPDECOMP_H
#define RDKIT_RGROUPDECOMP_H
#include "../RDKitBase.h"
#include <GraphMol/Substruct/SubstructMatch.h>
#include <chrono>
namespace RDKit {
//! Compute the isomorphic degenerative points in the
//! molecule. These are points that are symmetrically
//! equivalent.
/*!
\param mol Molecule to compute the degenerative points
\return the set of degenerative points (set<unsigned int>)
*/
typedef enum {
IsotopeLabels = 0x01,
AtomMapLabels = 0x02,
AtomIndexLabels = 0x04,
RelabelDuplicateLabels = 0x08,
MDLRGroupLabels = 0x10,
DummyAtomLabels = 0x20, // These are rgroups but will get relabelled
AutoDetect = 0xFF,
} RGroupLabels;
typedef enum {
Greedy = 0x01,
GreedyChunks = 0x02,
Exhaustive = 0x04, // not really useful for large sets
NoSymmetrization = 0x08,
GA = 0x10,
} RGroupMatching;
typedef enum {
AtomMap = 0x01,
Isotope = 0x02,
MDLRGroup = 0x04,
} RGroupLabelling;
typedef enum {
// DEPRECATED, remove the following line in release 2021.03
None = 0x0,
NoAlignment = 0x0,
MCS = 0x01,
} RGroupCoreAlignment;
typedef enum {
Match = 0x1,
FingerprintVariance = 0x4,
} RGroupScore;
struct RDKIT_RGROUPDECOMPOSITION_EXPORT RGroupDecompositionProcessResult {
const bool success;
const double score;
RGroupDecompositionProcessResult(const bool success, const double score)
: success(success), score(score) {}
};
struct RGroupMatch;
struct RDKIT_RGROUPDECOMPOSITION_EXPORT RGroupDecompositionParameters {
unsigned int labels = AutoDetect;
unsigned int matchingStrategy = GreedyChunks;
unsigned int scoreMethod = Match;
unsigned int rgroupLabelling = AtomMap | MDLRGroup;
unsigned int alignment = MCS;
unsigned int chunkSize = 5;
//! only allow rgroup decomposition at the specified rgroups
bool onlyMatchAtRGroups = false;
//! remove all user-defined rgroups that only have hydrogens
bool removeAllHydrogenRGroups = true;
//! remove all user-defined rgroups that only have hydrogens,
//! and also remove the corresponding labels from the core
bool removeAllHydrogenRGroupsAndLabels = true;
//! remove all hydrogens from the output molecules
bool removeHydrogensPostMatch = true;
//! allow labelled Rgroups of degree 2 or more
bool allowNonTerminalRGroups = false;
double timeout = -1.0; ///< timeout in seconds. <=0 indicates no timeout
// Determine how to assign the rgroup labels from the given core
unsigned int autoGetLabels(const RWMol &);
// Prepare the core for substructure searching and rgroup assignment
bool prepareCore(RWMol &, const RWMol *alignCore);
// Parameters specific to GA
// GA population size or -1 to use best guess
int gaPopulationSize = -1;
// GA maximum number of operations or -1 to use best guess
int gaMaximumOperations = -1;
// GA number of operations permitted without improvement before exiting (-1
// for best guess)
int gaNumberOperationsWithoutImprovement = -1;
// GA random number seed (-1 for default, -2 for random seed)
int gaRandomSeed = -1;
// Number of runs
int gaNumberRuns = 1;
// Sequential or parallel runs?
#ifdef RDK_THREADSAFE_SSS
bool gaParallelRuns = true;
#else
bool gaParallelRuns = false;
#endif
// Controls the way substructure matching with the core is done
SubstructMatchParameters substructmatchParams;
RGroupDecompositionParameters() { substructmatchParams.useChirality = true; }
private:
int indexOffset{-1};
void checkNonTerminal(const Atom &atom) const;
};
typedef std::map<std::string, ROMOL_SPTR> RGroupRow;
typedef std::vector<ROMOL_SPTR> RGroupColumn;
typedef std::vector<RGroupRow> RGroupRows;
typedef std::map<std::string, RGroupColumn> RGroupColumns;
class UsedLabelMap {
public:
UsedLabelMap(const std::map<int, int> &mapping) {
for (const auto &rl : mapping) {
d_map[rl.second] = std::make_pair(false, (rl.first > 0));
}
}
bool getIsUsed(int label) const { return d_map.at(label).first; }
void setIsUsed(int label) { d_map[label].first = true; }
bool isUserDefined(int label) const { return d_map.at(label).second; }
private:
std::map<int, std::pair<bool, bool>> d_map;
};
struct RGroupDecompData;
class RDKIT_RGROUPDECOMPOSITION_EXPORT RGroupDecomposition {
private:
RGroupDecompData *data; // implementation details
RGroupDecomposition(const RGroupDecomposition &); // no copy construct
RGroupDecomposition &operator=(
const RGroupDecomposition &); // Prevent assignment
RWMOL_SPTR outputCoreMolecule(const RGroupMatch &match,
const UsedLabelMap &usedRGroupMap) const;
std::map<int, bool> getBlankRGroupMap() const;
public:
RGroupDecomposition(const ROMol &core,
const RGroupDecompositionParameters &params =
RGroupDecompositionParameters());
RGroupDecomposition(const std::vector<ROMOL_SPTR> &cores,
const RGroupDecompositionParameters &params =
RGroupDecompositionParameters());
~RGroupDecomposition();
//! Returns the index of the added molecule in the RGroupDecomposition
/// or a negative error code
/// :param mol: Molecule to add to the decomposition
/// :result: index of the molecle or
/// -1 if none of the core matches
/// -2 if the matched molecule has no sidechains, i.e. is the
/// same as the scaffold
int add(const ROMol &mol);
RGroupDecompositionProcessResult processAndScore();
bool process();
const RGroupDecompositionParameters &params() const;
//! return the current group labels
std::vector<std::string> getRGroupLabels() const;
//! return rgroups in row order group[row][attachment_point] = ROMol
RGroupRows getRGroupsAsRows() const;
//! return rgroups in column order group[attachment_point][row] = ROMol
RGroupColumns getRGroupsAsColumns() const;
};
RDKIT_RGROUPDECOMPOSITION_EXPORT unsigned int RGroupDecompose(
const std::vector<ROMOL_SPTR> &cores, const std::vector<ROMOL_SPTR> &mols,
RGroupRows &rows, std::vector<unsigned int> *unmatched = nullptr,
const RGroupDecompositionParameters &options =
RGroupDecompositionParameters());
RDKIT_RGROUPDECOMPOSITION_EXPORT unsigned int RGroupDecompose(
const std::vector<ROMOL_SPTR> &cores, const std::vector<ROMOL_SPTR> &mols,
RGroupColumns &columns, std::vector<unsigned int> *unmatched = nullptr,
const RGroupDecompositionParameters &options =
RGroupDecompositionParameters());
inline bool checkForTimeout(const std::chrono::steady_clock::time_point &t0,
double timeout, bool throwOnTimeout = true) {
if (timeout <= 0) return false;
auto t1 = std::chrono::steady_clock::now();
std::chrono::duration<double> elapsed = t1 - t0;
if (elapsed.count() >= timeout) {
if (throwOnTimeout) {
throw std::runtime_error("operation timed out");
}
return true;
}
return false;
}
} // namespace RDKit
#endif
SubstructMatch.h
RDKit::RGroupDecomposition
Definition: RGroupDecomp.h:154
RDKit::RGroupDecomposition::getRGroupsAsRows
RGroupRows getRGroupsAsRows() const
return rgroups in row order group[row][attachment_point] = ROMol
RDKit::RGroupDecomposition::RGroupDecomposition
RGroupDecomposition(const std::vector< ROMOL_SPTR > &cores, const RGroupDecompositionParameters &params=RGroupDecompositionParameters())
RDKit::RGroupDecomposition::~RGroupDecomposition
~RGroupDecomposition()
RDKit::RGroupDecomposition::getRGroupsAsColumns
RGroupColumns getRGroupsAsColumns() const
return rgroups in column order group[attachment_point][row] = ROMol
RDKit::RGroupDecomposition::process
bool process()
RDKit::RGroupDecomposition::params
const RGroupDecompositionParameters & params() const
RDKit::RGroupDecomposition::RGroupDecomposition
RGroupDecomposition(const ROMol &core, const RGroupDecompositionParameters &params=RGroupDecompositionParameters())
RDKit::RGroupDecomposition::add
int add(const ROMol &mol)
RDKit::RGroupDecomposition::processAndScore
RGroupDecompositionProcessResult processAndScore()
RDKit::RGroupDecomposition::getRGroupLabels
std::vector< std::string > getRGroupLabels() const
return the current group labels
RDKit::ROMol
Definition: ROMol.h:178
RDKit::RWMol
RWMol is a molecule class that is intended to be edited.
Definition: RWMol.h:32
RDKit::UsedLabelMap
Definition: RGroupDecomp.h:138
RDKit::UsedLabelMap::setIsUsed
void setIsUsed(int label)
Definition: RGroupDecomp.h:146
RDKit::UsedLabelMap::getIsUsed
bool getIsUsed(int label) const
Definition: RGroupDecomp.h:145
RDKit::UsedLabelMap::isUserDefined
bool isUserDefined(int label) const
Definition: RGroupDecomp.h:147
RDKit::UsedLabelMap::UsedLabelMap
UsedLabelMap(const std::map< int, int > &mapping)
Definition: RGroupDecomp.h:140
export.h
RDKIT_RGROUPDECOMPOSITION_EXPORT
#define RDKIT_RGROUPDECOMPOSITION_EXPORT
Definition: export.h:385
RDKit
Std stuff.
Definition: Abbreviations.h:18
RDKit::RGroupScore
RGroupScore
Definition: RGroupDecomp.h:61
RDKit::Match
@ Match
Definition: RGroupDecomp.h:62
RDKit::FingerprintVariance
@ FingerprintVariance
Definition: RGroupDecomp.h:63
RDKit::RGroupCoreAlignment
RGroupCoreAlignment
Definition: RGroupDecomp.h:54
RDKit::None
@ None
Definition: RGroupDecomp.h:56
RDKit::NoAlignment
@ NoAlignment
Definition: RGroupDecomp.h:57
RDKit::MCS
@ MCS
Definition: RGroupDecomp.h:58
RDKit::RGroupMatching
RGroupMatching
Definition: RGroupDecomp.h:40
RDKit::NoSymmetrization
@ NoSymmetrization
Definition: RGroupDecomp.h:44
RDKit::Greedy
@ Greedy
Definition: RGroupDecomp.h:41
RDKit::Exhaustive
@ Exhaustive
Definition: RGroupDecomp.h:43
RDKit::GreedyChunks
@ GreedyChunks
Definition: RGroupDecomp.h:42
RDKit::GA
@ GA
Definition: RGroupDecomp.h:45
RDKit::RGroupRow
std::map< std::string, ROMOL_SPTR > RGroupRow
Definition: RGroupDecomp.h:132
RDKit::RGroupColumn
std::vector< ROMOL_SPTR > RGroupColumn
Definition: RGroupDecomp.h:133
RDKit::RGroupColumns
std::map< std::string, RGroupColumn > RGroupColumns
Definition: RGroupDecomp.h:136
RDKit::RGroupLabels
RGroupLabels
Definition: RGroupDecomp.h:30
RDKit::MDLRGroupLabels
@ MDLRGroupLabels
Definition: RGroupDecomp.h:35
RDKit::AtomMapLabels
@ AtomMapLabels
Definition: RGroupDecomp.h:32
RDKit::AtomIndexLabels
@ AtomIndexLabels
Definition: RGroupDecomp.h:33
RDKit::RelabelDuplicateLabels
@ RelabelDuplicateLabels
Definition: RGroupDecomp.h:34
RDKit::AutoDetect
@ AutoDetect
Definition: RGroupDecomp.h:37
RDKit::DummyAtomLabels
@ DummyAtomLabels
Definition: RGroupDecomp.h:36
RDKit::IsotopeLabels
@ IsotopeLabels
Definition: RGroupDecomp.h:31
RDKit::RGroupLabelling
RGroupLabelling
Definition: RGroupDecomp.h:48
RDKit::MDLRGroup
@ MDLRGroup
Definition: RGroupDecomp.h:51
RDKit::AtomMap
@ AtomMap
Definition: RGroupDecomp.h:49
RDKit::Isotope
@ Isotope
Definition: RGroupDecomp.h:50
RDKit::checkForTimeout
bool checkForTimeout(const std::chrono::steady_clock::time_point &t0, double timeout, bool throwOnTimeout=true)
Definition: RGroupDecomp.h:207
RDKit::RGroupDecompose
RDKIT_RGROUPDECOMPOSITION_EXPORT unsigned int RGroupDecompose(const std::vector< ROMOL_SPTR > &cores, const std::vector< ROMOL_SPTR > &mols, RGroupRows &rows, std::vector< unsigned int > *unmatched=nullptr, const RGroupDecompositionParameters &options=RGroupDecompositionParameters())
RDKit::RGroupRows
std::vector< RGroupRow > RGroupRows
Definition: RGroupDecomp.h:135
RDKit::RWMOL_SPTR
boost::shared_ptr< RWMol > RWMOL_SPTR
Definition: RWMol.h:222
RDKit::RGroupDecompData
Definition: RGroupDecompData.h:25
RDKit::RGroupDecompositionParameters
Definition: RGroupDecomp.h:75
RDKit::RGroupDecompositionParameters::autoGetLabels
unsigned int autoGetLabels(const RWMol &)
RDKit::RGroupDecompositionParameters::prepareCore
bool prepareCore(RWMol &, const RWMol *alignCore)
RDKit::RGroupDecompositionParameters::RGroupDecompositionParameters
RGroupDecompositionParameters()
Definition: RGroupDecomp.h:125
RDKit::RGroupDecompositionParameters::substructmatchParams
SubstructMatchParameters substructmatchParams
Definition: RGroupDecomp.h:123
RDKit::RGroupDecompositionProcessResult
Definition: RGroupDecomp.h:66
RDKit::RGroupDecompositionProcessResult::RGroupDecompositionProcessResult
RGroupDecompositionProcessResult(const bool success, const double score)
Definition: RGroupDecomp.h:69
RDKit::RGroupDecompositionProcessResult::success
const bool success
Definition: RGroupDecomp.h:67
RDKit::RGroupDecompositionProcessResult::score
const double score
Definition: RGroupDecomp.h:68
RDKit::RGroupMatch
RGroupMatch is the decomposition for a single molecule.
Definition: RGroupMatch.h:19
RDKit::SubstructMatchParameters
Definition: SubstructMatch.h:33
RDKit::SubstructMatchParameters::useChirality
bool useChirality
Definition: SubstructMatch.h:34