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
66 public:
68 const RGroupDecompositionParameters &params =
70 RGroupDecomposition(const std::vector<ROMOL_SPTR> &cores,
71 const RGroupDecompositionParameters &params =
73
75
76 //! Returns the index of the core matching the passed molecule
77 //! and optionally the matching atom indices
78 /*!
79 \param mol Molecule to check for matches
80 \param matches Optional pointer to std::vector<MatchVectType>
81 where core matches will be stored
82
83 \return the index of the matching core, or -1 if none matches
84 */
85 int getMatchingCoreIdx(const ROMol &mol,
86 std::vector<MatchVectType> *matches = nullptr);
87 //! Returns the index of the added molecule in the RGroupDecomposition
88 //! or a negative error code
89 /*!
90 \param mol Molecule to add to the decomposition
91
92 \return index of the molecule or
93 -1 if none of the core matches
94 -2 if the matched molecule has no sidechains, i.e. is the
95 same as the scaffold
96 */
97 int add(const ROMol &mol);
99 bool process();
100
102 //! return the current group labels
103 std::vector<std::string> getRGroupLabels() const;
104
105 //! return rgroups in row order group[row][attachment_point] = ROMol
107 //! return rgroups in column order group[attachment_point][row] = ROMol
109};
110
112 const std::vector<ROMOL_SPTR> &cores, const std::vector<ROMOL_SPTR> &mols,
113 RGroupRows &rows, std::vector<unsigned int> *unmatched = nullptr,
116
118 const std::vector<ROMOL_SPTR> &cores, const std::vector<ROMOL_SPTR> &mols,
119 RGroupColumns &columns, std::vector<unsigned int> *unmatched = nullptr,
122
123inline bool checkForTimeout(const std::chrono::steady_clock::time_point &t0,
124 double timeout, bool throwOnTimeout = true) {
125 if (timeout <= 0) {
126 return false;
127 }
128 auto t1 = std::chrono::steady_clock::now();
129 std::chrono::duration<double> elapsed = t1 - t0;
130 if (elapsed.count() >= timeout) {
131 if (throwOnTimeout) {
132 throw std::runtime_error("operation timed out");
133 }
134 return true;
135 }
136 return false;
137}
138
139} // namespace RDKit
140
141#endif
pulls in the core RDKit functionality
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:417
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:221
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