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;
55 private:
56 RGroupDecompData *data; // implementation details
57 RGroupDecomposition(const RGroupDecomposition &); // no copy construct
58 RGroupDecomposition &operator=(
59 const RGroupDecomposition &); // Prevent assignment
60 RWMOL_SPTR outputCoreMolecule(const RGroupMatch &match,
61 const UsedLabelMap &usedRGroupMap) const;
62
63 public:
65 const RGroupDecompositionParameters &params =
67 RGroupDecomposition(const std::vector<ROMOL_SPTR> &cores,
68 const RGroupDecompositionParameters &params =
70
72
73 //! Returns the index of the added molecule in the RGroupDecomposition
74 /// or a negative error code
75 /// :param mol: Molecule to add to the decomposition
76 /// :result: index of the molecle or
77 /// -1 if none of the core matches
78 /// -2 if the matched molecule has no sidechains, i.e. is the
79 /// same as the scaffold
80 int add(const ROMol &mol);
82 bool process();
83
85 //! return the current group labels
86 std::vector<std::string> getRGroupLabels() const;
87
88 //! return rgroups in row order group[row][attachment_point] = ROMol
90 //! return rgroups in column order group[attachment_point][row] = ROMol
92};
93
95 const std::vector<ROMOL_SPTR> &cores, const std::vector<ROMOL_SPTR> &mols,
96 RGroupRows &rows, std::vector<unsigned int> *unmatched = nullptr,
99
101 const std::vector<ROMOL_SPTR> &cores, const std::vector<ROMOL_SPTR> &mols,
102 RGroupColumns &columns, std::vector<unsigned int> *unmatched = nullptr,
105
106inline bool checkForTimeout(const std::chrono::steady_clock::time_point &t0,
107 double timeout, bool throwOnTimeout = true) {
108 if (timeout <= 0) {
109 return false;
110 }
111 auto t1 = std::chrono::steady_clock::now();
112 std::chrono::duration<double> elapsed = t1 - t0;
113 if (elapsed.count() >= timeout) {
114 if (throwOnTimeout) {
115 throw std::runtime_error("operation timed out");
116 }
117 return true;
118 }
119 return false;
120}
121
122} // namespace RDKit
123
124#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()
std::vector< std::string > getRGroupLabels() const
return the current group labels
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:401
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:216
RGroupDecompositionProcessResult(const bool success, const double score)
RGroupMatch is the decomposition for a single molecule.
Definition RGroupMatch.h:19