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"
18#include <chrono>
19
20namespace RDKit {
21
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
31typedef std::map<std::string, ROMOL_SPTR> RGroupRow;
32typedef std::vector<ROMOL_SPTR> RGroupColumn;
33
34typedef std::vector<RGroupRow> RGroupRows;
35typedef std::map<std::string, RGroupColumn> RGroupColumns;
36
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;
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:
70 const RGroupDecompositionParameters &params =
72 RGroupDecomposition(const std::vector<ROMOL_SPTR> &cores,
73 const RGroupDecompositionParameters &params =
75
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);
101 bool process();
102
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
109 //! return rgroups in column order group[attachment_point][row] = ROMol
111};
112
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 =
118
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 =
124
125inline 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
RGroupRows getRGroupsAsRows() const
return rgroups in row order group[row][attachment_point] = ROMol
RGroupDecomposition(const std::vector< ROMOL_SPTR > &cores, const RGroupDecompositionParameters &params=RGroupDecompositionParameters())
const RGroupDecompositionParameters & params() const
RGroupColumns getRGroupsAsColumns() const
return rgroups in column order group[attachment_point][row] = ROMol
RGroupDecomposition(const ROMol &core, const RGroupDecompositionParameters &params=RGroupDecompositionParameters())
int add(const ROMol &mol)
RGroupDecompositionProcessResult processAndScore()
int getMatchingCoreIdx(const ROMol &mol, std::vector< MatchVectType > *matches=nullptr)
std::vector< std::string > getRGroupLabels() const
return the current group labels
RWMol is a molecule class that is intended to be edited.
Definition RWMol.h:32
void setIsUsed(int label)
bool getIsUsed(int label) const
bool isUserDefined(int label) const
UsedLabelMap(const std::map< int, int > &mapping)
bool has(int label) const
#define RDKIT_RGROUPDECOMPOSITION_EXPORT
Definition export.h:441
Std stuff.
bool rdvalue_is(const RDValue_cast_t)
std::map< std::string, ROMOL_SPTR > RGroupRow
std::vector< ROMOL_SPTR > RGroupColumn
std::map< std::string, RGroupColumn > RGroupColumns
bool checkForTimeout(const std::chrono::steady_clock::time_point &t0, double timeout, bool throwOnTimeout=true)
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())
std::vector< RGroupRow > RGroupRows
boost::shared_ptr< RWMol > RWMOL_SPTR
Definition RWMol.h:222
RCore is the core common to a series of molecules.
Definition RGroupCore.h:25
RGroupDecompositionProcessResult(const bool success, const double score)
RGroupMatch is the decomposition for a single molecule.
Definition RGroupMatch.h:19