RDKit
Open-source cheminformatics and machine learning.
RGroupDecomp.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Novartis Institutes for BioMedical Research
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 #include <RDGeneral/export.h>
11 #ifndef RDKIT_RGROUPDECOMP_H
12 #define RDKIT_RGROUPDECOMP_H
13 
14 #include "../RDKitBase.h"
16 #include <chrono>
17 
18 namespace RDKit {
19 
20 //! Compute the isomorphic degenerative points in the
21 //! molecule. These are points that are symmetrically
22 //! equivalent.
23 /*!
24  \param mol Molecule to compute the degenerative points
25 
26  \return the set of degenerative points (set<unsigned int>)
27 */
28 
29 typedef enum {
30  IsotopeLabels = 0x01,
31  AtomMapLabels = 0x02,
35  DummyAtomLabels = 0x20, // These are rgroups but will get relabelled
36  AutoDetect = 0xFF,
37 } RGroupLabels;
38 
39 typedef enum {
40  Greedy = 0x01,
41  GreedyChunks = 0x02,
42  Exhaustive = 0x04, // not really useful for large sets
45 
46 typedef enum {
47  AtomMap = 0x01,
48  Isotope = 0x02,
49  MDLRGroup = 0x04,
51 
52 typedef enum {
53  // DEPRECATED, remove the folowing line in release 2021.03
54  None = 0x0,
55  NoAlignment = 0x0,
56  MCS = 0x01,
58 
60  unsigned int labels = AutoDetect;
61  unsigned int matchingStrategy = GreedyChunks;
62  unsigned int rgroupLabelling = AtomMap | MDLRGroup;
63  unsigned int alignment = MCS;
64 
65  unsigned int chunkSize = 5;
66  bool onlyMatchAtRGroups = false;
67  bool removeAllHydrogenRGroups = true;
68  bool removeHydrogensPostMatch = true;
69  double timeout = -1.0; ///< timeout in seconds. <=0 indicates no timeout
70 
71  // Determine how to assign the rgroup labels from the given core
72  unsigned int autoGetLabels(const RWMol &);
73 
74  // Prepare the core for substructure searching and rgroup assignment
75  bool prepareCore(RWMol &, const RWMol *alignCore);
76 
77  private:
78  int indexOffset{-1};
79 };
80 
81 typedef std::map<std::string, boost::shared_ptr<ROMol>> RGroupRow;
82 typedef std::vector<boost::shared_ptr<ROMol>> RGroupColumn;
83 
84 typedef std::vector<RGroupRow> RGroupRows;
85 typedef std::map<std::string, RGroupColumn> RGroupColumns;
86 
87 struct RGroupDecompData;
89  RGroupDecompData *data; // implementation details
90  RGroupDecomposition(const RGroupDecomposition &); // no copy construct
91  RGroupDecomposition &operator=(
92  const RGroupDecomposition &); // Prevent assignment
93 
94  public:
96  const RGroupDecompositionParameters &params =
98  RGroupDecomposition(const std::vector<ROMOL_SPTR> &cores,
99  const RGroupDecompositionParameters &params =
101 
103 
104  int add(const ROMol &mol);
105  bool process();
106 
108  //! return the current group labels
109  std::vector<std::string> getRGroupLabels() const;
110 
111  //! return rgroups in row order group[row][attachment_point] = ROMol
113  //! return rgroups in column order group[attachment_point][row] = ROMol
115 };
116 
118  const std::vector<ROMOL_SPTR> &cores, const std::vector<ROMOL_SPTR> &mols,
119  RGroupRows &rows, std::vector<unsigned int> *unmatched = nullptr,
120  const RGroupDecompositionParameters &options =
122 
124  const std::vector<ROMOL_SPTR> &cores, const std::vector<ROMOL_SPTR> &mols,
125  RGroupColumns &columns, std::vector<unsigned int> *unmatched = nullptr,
126  const RGroupDecompositionParameters &options =
128 
129 inline bool checkForTimeout(const std::chrono::steady_clock::time_point &t0,
130  double timeout, bool throwOnTimeout = true) {
131  if (timeout <= 0) return false;
132  auto t1 = std::chrono::steady_clock::now();
133  std::chrono::duration<double> elapsed = t1 - t0;
134  if (elapsed.count() >= timeout) {
135  if (throwOnTimeout) {
136  throw std::runtime_error("operation timed out");
137  }
138  return true;
139  }
140  return false;
141 }
142 
143 } // namespace RDKit
144 
145 #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())
RGroupColumns getRGroupsAsColumns() const
return rgroups in column order group[attachment_point][row] = ROMol
const RGroupDecompositionParameters & params() const
RGroupDecomposition(const ROMol &core, const RGroupDecompositionParameters &params=RGroupDecompositionParameters())
int add(const ROMol &mol)
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:31
#define RDKIT_RGROUPDECOMPOSITION_EXPORT
Definition: export.h:619
Std stuff.
Definition: Abbreviations.h:17
RGroupCoreAlignment
Definition: RGroupDecomp.h:52
@ NoAlignment
Definition: RGroupDecomp.h:55
RGroupMatching
Definition: RGroupDecomp.h:39
@ NoSymmetrization
Definition: RGroupDecomp.h:43
@ Greedy
Definition: RGroupDecomp.h:40
@ Exhaustive
Definition: RGroupDecomp.h:42
@ GreedyChunks
Definition: RGroupDecomp.h:41
std::vector< boost::shared_ptr< ROMol > > RGroupColumn
Definition: RGroupDecomp.h:82
std::map< std::string, RGroupColumn > RGroupColumns
Definition: RGroupDecomp.h:85
RGroupLabels
Definition: RGroupDecomp.h:29
@ MDLRGroupLabels
Definition: RGroupDecomp.h:34
@ AtomMapLabels
Definition: RGroupDecomp.h:31
@ AtomIndexLabels
Definition: RGroupDecomp.h:32
@ RelabelDuplicateLabels
Definition: RGroupDecomp.h:33
@ AutoDetect
Definition: RGroupDecomp.h:36
@ DummyAtomLabels
Definition: RGroupDecomp.h:35
@ IsotopeLabels
Definition: RGroupDecomp.h:30
RGroupLabelling
Definition: RGroupDecomp.h:46
@ MDLRGroup
Definition: RGroupDecomp.h:49
@ AtomMap
Definition: RGroupDecomp.h:47
@ Isotope
Definition: RGroupDecomp.h:48
bool checkForTimeout(const std::chrono::steady_clock::time_point &t0, double timeout, bool throwOnTimeout=true)
Definition: RGroupDecomp.h:129
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
Definition: RGroupDecomp.h:84
std::map< std::string, boost::shared_ptr< ROMol > > RGroupRow
Definition: RGroupDecomp.h:81
unsigned int autoGetLabels(const RWMol &)
bool prepareCore(RWMol &, const RWMol *alignCore)