RDKit: RGroupDecomp.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
RGroupDecomp.h
Go to the documentation of this file.
1//
2// Copyright (c) 2017-2021, Novartis Institutes for BioMedical Research Inc.
3// and other RDKit contributors
4//
5// @@ All Rights Reserved @@
6// This file is part of the RDKit.
7// The contents are covered by the terms of the BSD license
8// which is included in the file license.txt, found at the root
9// of the RDKit source tree.
10//
11#include <RDGeneral/export.h>
12#ifndef RDKIT_RGROUPDECOMP_H
13#define RDKIT_RGROUPDECOMP_H
14
15#include "../RDKitBase.h"
16#include "RGroupDecompParams.h"
17#include <GraphMol/Substruct/SubstructMatch.h>
18#include <chrono>
19
20namespace RDKit {
21
22 struct RDKIT_RGROUPDECOMPOSITION_EXPORT RGroupDecompositionProcessResult {
23 const bool success;
24 const double score;
25 RGroupDecompositionProcessResult(const bool success, const double score)
26 : success(success), score(score) {}
27};
28
29struct RGroupMatch;
30
31 typedef std::map<std::string, ROMOL_SPTR> RGroupRow;
32 typedef std::vector<ROMOL_SPTR> RGroupColumn;
33
34 typedef std::vector<RGroupRow> RGroupRows;
35 typedef std::map<std::string, RGroupColumn> RGroupColumns;
36
37 class UsedLabelMap {
38 public:
39 UsedLabelMap(const std::map<int, int> &mapping) {
40 for (const auto &rl : mapping) {
41 d_map[rl.second] = std::make_pair(false, (rl.first > 0));
42 }
43 }
44 bool has(int label) const { return d_map.find(label) != d_map.end(); }
45 bool getIsUsed(int label) const { return d_map.at(label).first; }
46 void setIsUsed(int label) { d_map[label].first = true; }
47 bool isUserDefined(int label) const { return d_map.at(label).second; }
48
49 private:
50 std::map<int, std::pair<bool, bool>> d_map;
51};
52
53struct RGroupDecompData;
54struct RCore;
55 class RDKIT_RGROUPDECOMPOSITION_EXPORT RGroupDecomposition {
56 private:
57 RGroupDecompData *data; // implementation details
58 RGroupDecomposition(const RGroupDecomposition &); // no copy construct
59 RGroupDecomposition &operator=(
60 const RGroupDecomposition &); // Prevent assignment
61 RWMOL_SPTR outputCoreMolecule(const RGroupMatch &match,
62 const UsedLabelMap &usedRGroupMap) const;
63 int getMatchingCoreInternal(RWMol &mol, const RCore *&rcore,
64 std::vector<MatchVectType> &matches);
65 static void labelAtomBondIndices(RWMol &mol);
66 void setTargetAtomBondIndices(ROMol &mol, bool includeBondsToRLabels) const;
67
68 public:
69 RGroupDecomposition(const ROMol &core,
70 const RGroupDecompositionParameters &params =
71 RGroupDecompositionParameters());
72 RGroupDecomposition(const std::vector<ROMOL_SPTR> &cores,
73 const RGroupDecompositionParameters &params =
74 RGroupDecompositionParameters());
75
76 ~RGroupDecomposition();
77
78 //! Returns the index of the core matching the passed molecule
79 //! and optionally the matching atom indices
80 /*!
81 \param mol Molecule to check for matches
82 \param matches Optional pointer to std::vector<MatchVectType>
83 where core matches will be stored
84
85 \return the index of the matching core, or -1 if none matches
86 */
87 int getMatchingCoreIdx(const ROMol &mol,
88 std::vector<MatchVectType> *matches = nullptr);
89 //! Returns the index of the added molecule in the RGroupDecomposition
90 //! or a negative error code
91 /*!
92 \param mol Molecule to add to the decomposition
93
94 \return index of the molecule or
95 -1 if none of the core matches
96 -2 if the matched molecule has no sidechains, i.e. is the
97 same as the scaffold
98 */
99 int add(const ROMol &mol);
100 RGroupDecompositionProcessResult processAndScore();
101 bool process();
102
103 const RGroupDecompositionParameters &params() const;
104 //! return the current group labels
105 std::vector<std::string> getRGroupLabels() const;
106
107 //! return rgroups in row order group[row][attachment_point] = ROMol
108 RGroupRows getRGroupsAsRows() const;
109 //! return rgroups in column order group[attachment_point][row] = ROMol
110 RGroupColumns getRGroupsAsColumns() const;
111};
112
113 RDKIT_RGROUPDECOMPOSITION_EXPORT unsigned int RGroupDecompose(
114 const std::vector<ROMOL_SPTR> &cores, const std::vector<ROMOL_SPTR> &mols,
115 RGroupRows &rows, std::vector<unsigned int> *unmatched = nullptr,
116 const RGroupDecompositionParameters &options =
117 RGroupDecompositionParameters());
118
119 RDKIT_RGROUPDECOMPOSITION_EXPORT unsigned int RGroupDecompose(
120 const std::vector<ROMOL_SPTR> &cores, const std::vector<ROMOL_SPTR> &mols,
121 RGroupColumns &columns, std::vector<unsigned int> *unmatched = nullptr,
122 const RGroupDecompositionParameters &options =
123 RGroupDecompositionParameters());
124
125 inline bool checkForTimeout(const std::chrono::steady_clock::time_point &t0,
126 double timeout, bool throwOnTimeout = true) {
127 if (timeout <= 0) {
128 return false;
129 }
130 auto t1 = std::chrono::steady_clock::now();
131 std::chrono::duration<double> elapsed = t1 - t0;
132 if (elapsed.count() >= timeout) {
133 if (throwOnTimeout) {
134 throw std::runtime_error("operation timed out");
135 }
136 return true;
137 }
138 return false;
139}
140
141} // namespace RDKit
142
143#endif
RDKitBase.h
pulls in the core RDKit functionality
RGroupDecompParams.h
SubstructMatch.h
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::params
const RGroupDecompositionParameters & params() const
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::RGroupDecomposition
RGroupDecomposition(const ROMol &core, const RGroupDecompositionParameters &params=RGroupDecompositionParameters())
RDKit::RGroupDecomposition::add
int add(const ROMol &mol)
RDKit::RGroupDecomposition::processAndScore
RGroupDecompositionProcessResult processAndScore()
RDKit::RGroupDecomposition::getMatchingCoreIdx
int getMatchingCoreIdx(const ROMol &mol, std::vector< MatchVectType > *matches=nullptr)
RDKit::RGroupDecomposition::getRGroupLabels
std::vector< std::string > getRGroupLabels() const
return the current group labels
RDKit::ROMol
Definition ROMol.h:199
RDKit::RWMol
RWMol is a molecule class that is intended to be edited.
Definition RWMol.h:32
RDKit::UsedLabelMap
Definition RGroupDecomp.h:37
RDKit::UsedLabelMap::setIsUsed
void setIsUsed(int label)
Definition RGroupDecomp.h:46
RDKit::UsedLabelMap::getIsUsed
bool getIsUsed(int label) const
Definition RGroupDecomp.h:45
RDKit::UsedLabelMap::isUserDefined
bool isUserDefined(int label) const
Definition RGroupDecomp.h:47
RDKit::UsedLabelMap::UsedLabelMap
UsedLabelMap(const std::map< int, int > &mapping)
Definition RGroupDecomp.h:39
RDKit::UsedLabelMap::has
bool has(int label) const
Definition RGroupDecomp.h:44
export.h
RDKIT_RGROUPDECOMPOSITION_EXPORT
#define RDKIT_RGROUPDECOMPOSITION_EXPORT
Definition export.h:473
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::RGroupRow
std::map< std::string, ROMOL_SPTR > RGroupRow
Definition RGroupDecomp.h:31
RDKit::RGroupColumn
std::vector< ROMOL_SPTR > RGroupColumn
Definition RGroupDecomp.h:32
RDKit::RGroupColumns
std::map< std::string, RGroupColumn > RGroupColumns
Definition RGroupDecomp.h:35
RDKit::checkForTimeout
bool checkForTimeout(const std::chrono::steady_clock::time_point &t0, double timeout, bool throwOnTimeout=true)
Definition RGroupDecomp.h:125
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:34
RDKit::RWMOL_SPTR
boost::shared_ptr< RWMol > RWMOL_SPTR
Definition RWMol.h:222
RDKit::RCore
RCore is the core common to a series of molecules.
Definition RGroupCore.h:25
RDKit::RGroupDecompData
Definition RGroupDecompData.h:24
RDKit::RGroupDecompositionParameters
Definition RGroupDecompParams.h:39
RDKit::RGroupDecompositionProcessResult
Definition RGroupDecomp.h:22
RDKit::RGroupDecompositionProcessResult::RGroupDecompositionProcessResult
RGroupDecompositionProcessResult(const bool success, const double score)
Definition RGroupDecomp.h:25
RDKit::RGroupDecompositionProcessResult::success
const bool success
Definition RGroupDecomp.h:23
RDKit::RGroupDecompositionProcessResult::score
const double score
Definition RGroupDecomp.h:24
RDKit::RGroupMatch
RGroupMatch is the decomposition for a single molecule.
Definition RGroupMatch.h:19