RDKit
Open-source cheminformatics and machine learning.
MolEnumerator.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2020 Greg Landrum and T5 Informatics GmbH
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 #ifndef RDKIT_MOLENUMERATOR_H
11 #define RDKIT_MOLENUMERATOR_H
12 
13 #include <RDGeneral/export.h>
14 #include <GraphMol/RDKitBase.h>
15 #include <GraphMol/MolBundle.h>
16 
17 #include <vector>
18 #include <map>
19 #include <string>
20 #include <memory>
21 
22 namespace RDKit {
23 class ChemicalReaction;
24 namespace MolEnumerator {
25 
26 //! abstract base class for the a molecule enumeration operation
28  public:
30  virtual ~MolEnumeratorOp(){};
31  //! returns a vector of the number of possible variations at variability point
32  //! covered by this operation
33  virtual std::vector<size_t> getVariationCounts() const = 0;
34  //! returns a the molecule corresponding to a particular variation
35  /*! which.size() should be equal to the number of variation counts.
36  */
37  virtual std::unique_ptr<ROMol> operator()(
38  const std::vector<size_t> &which) const = 0;
39  //! initializes this operation to work on a particular molecule
40  virtual void initFromMol(const ROMol &mol) = 0;
41  //! polymorphic copy
42  virtual std::unique_ptr<MolEnumeratorOp> copy() const = 0;
43 };
44 
45 //! Molecule enumeration operation corresponding to position variation bonds
46 /*! This uses ATTACH and ENDPTS properties on bonds and requires that the bond
47  * has one dummy atom (which will be discarded). The other atom of the bond will
48  * be connected to the atoms listed in the ENDPTS property
49  */
51  public:
53  PositionVariationOp(const std::shared_ptr<ROMol> mol) : dp_mol(mol) {
54  PRECONDITION(mol, "bad molecule");
55  initFromMol();
56  };
57  PositionVariationOp(const ROMol &mol) : dp_mol(new ROMol(mol)) {
58  initFromMol();
59  };
61  : dp_mol(other.dp_mol), d_variationPoints(other.d_variationPoints){};
63  if (&other == this) {
64  return *this;
65  }
66  dp_mol = other.dp_mol;
67  d_variationPoints = other.d_variationPoints;
68  return *this;
69  };
70  //! \override
71  std::vector<size_t> getVariationCounts() const override;
72 
73  //! \override
74  std::unique_ptr<ROMol> operator()(
75  const std::vector<size_t> &which) const override;
76 
77  //! \override
78  void initFromMol(const ROMol &mol) override;
79 
80  //! \override
81  std::unique_ptr<MolEnumeratorOp> copy() const override {
82  return std::unique_ptr<MolEnumeratorOp>(new PositionVariationOp(*this));
83  }
84 
85  private:
86  std::shared_ptr<ROMol> dp_mol{nullptr};
87  std::vector<std::pair<unsigned int, std::vector<unsigned int>>>
88  d_variationPoints{};
89  std::vector<size_t> d_dummiesAtEachPoint{};
90  void initFromMol();
91 };
92 
93 //! Molecule enumeration operation corresponding to LINKNODES
94 /*!
95  */
97  public:
99  LinkNodeOp(const std::shared_ptr<ROMol> mol) : dp_mol(mol) {
100  PRECONDITION(mol, "bad molecule");
101  initFromMol();
102  };
103  LinkNodeOp(const ROMol &mol) : dp_mol(new ROMol(mol)) { initFromMol(); };
104  LinkNodeOp(const LinkNodeOp &other)
105  : dp_mol(other.dp_mol),
106  dp_frame(other.dp_frame),
107  d_countAtEachPoint(other.d_countAtEachPoint),
108  d_variations(other.d_variations),
109  d_pointRanges(other.d_pointRanges),
110  d_isotopeMap(other.d_isotopeMap){};
111  LinkNodeOp &operator=(const LinkNodeOp &other) {
112  if (&other == this) {
113  return *this;
114  }
115  dp_mol = other.dp_mol;
116  dp_frame = other.dp_frame;
117  d_countAtEachPoint = other.d_countAtEachPoint;
118  d_variations = other.d_variations;
119  d_pointRanges = other.d_pointRanges;
120  d_isotopeMap = other.d_isotopeMap;
121  return *this;
122  };
123  //! \override
124  std::vector<size_t> getVariationCounts() const override;
125 
126  //! \override
127  std::unique_ptr<ROMol> operator()(
128  const std::vector<size_t> &which) const override;
129 
130  //! \override
131  void initFromMol(const ROMol &mol) override;
132 
133  //! \override
134  std::unique_ptr<MolEnumeratorOp> copy() const override {
135  return std::unique_ptr<MolEnumeratorOp>(new LinkNodeOp(*this));
136  }
137 
138  private:
139  std::shared_ptr<ROMol> dp_mol{nullptr};
140  std::shared_ptr<RWMol> dp_frame{nullptr};
141  std::vector<size_t> d_countAtEachPoint{};
142  std::vector<std::tuple<unsigned, unsigned, unsigned>> d_variations;
143  std::vector<std::pair<unsigned, unsigned>> d_pointRanges;
144  std::map<unsigned, unsigned> d_isotopeMap;
145 
146  void initFromMol();
147 };
148 
149 //! Parameters used to control the molecule enumeration
151  bool sanitize = false;
152  size_t maxToEnumerate = 1000;
153  bool doRandom = false; //< not yet implemented
154  int randomSeed = -1; //< not yet implemented
155  std::shared_ptr<MolEnumeratorOp> dp_operation;
156 };
157 
158 //! Returns a MolBundle containing the molecules resulting from applying the
159 //! operator contained in \c params to \c mol.
161 enumerate(const ROMol &mol, const MolEnumeratorParams &params);
162 } // namespace MolEnumerator
163 } // namespace RDKit
164 
165 #endif
#define PRECONDITION(expr, mess)
Definition: Invariant.h:109
Defines a class for managing bundles of molecules.
pulls in the core RDKit functionality
MolBundle contains a collection of related ROMols.
Definition: MolBundle.h:39
Molecule enumeration operation corresponding to LINKNODES.
Definition: MolEnumerator.h:96
LinkNodeOp(const LinkNodeOp &other)
LinkNodeOp & operator=(const LinkNodeOp &other)
void initFromMol(const ROMol &mol) override
\override
LinkNodeOp(const std::shared_ptr< ROMol > mol)
Definition: MolEnumerator.h:99
std::unique_ptr< MolEnumeratorOp > copy() const override
\override
std::vector< size_t > getVariationCounts() const override
\override
std::unique_ptr< ROMol > operator()(const std::vector< size_t > &which) const override
\override
abstract base class for the a molecule enumeration operation
Definition: MolEnumerator.h:27
virtual std::unique_ptr< MolEnumeratorOp > copy() const =0
polymorphic copy
virtual std::unique_ptr< ROMol > operator()(const std::vector< size_t > &which) const =0
returns a the molecule corresponding to a particular variation
virtual std::vector< size_t > getVariationCounts() const =0
virtual void initFromMol(const ROMol &mol)=0
initializes this operation to work on a particular molecule
Molecule enumeration operation corresponding to position variation bonds.
Definition: MolEnumerator.h:50
std::unique_ptr< MolEnumeratorOp > copy() const override
\override
Definition: MolEnumerator.h:81
std::vector< size_t > getVariationCounts() const override
\override
PositionVariationOp & operator=(const PositionVariationOp &other)
Definition: MolEnumerator.h:62
void initFromMol(const ROMol &mol) override
\override
PositionVariationOp(const PositionVariationOp &other)
Definition: MolEnumerator.h:60
PositionVariationOp(const std::shared_ptr< ROMol > mol)
Definition: MolEnumerator.h:53
std::unique_ptr< ROMol > operator()(const std::vector< size_t > &which) const override
\override
#define RDKIT_MOLENUMERATOR_EXPORT
Definition: export.h:450
RDKIT_MOLENUMERATOR_EXPORT MolBundle enumerate(const ROMol &mol, const MolEnumeratorParams &params)
Std stuff.
Definition: Abbreviations.h:17
Parameters used to control the molecule enumeration.
std::shared_ptr< MolEnumeratorOp > dp_operation