RDKit
Open-source cheminformatics and machine learning.
RGroupCore.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2020-2021 Novartis Institutes for BioMedical Research and
3 // 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 #ifndef RGROUP_CORE
12 #define RGROUP_CORE
13 
15 #include "../RDKitBase.h"
16 #include "RGroupUtils.h"
18 
19 // #define VERBOSE 1
20 
21 namespace RDKit {
22 
23 //! RCore is the core common to a series of molecules
24 struct RCore {
25  boost::shared_ptr<RWMol> core;
26  // core with terminal user R groups stripped for matching
27  boost::shared_ptr<RWMol> matchingMol;
28  boost::shared_ptr<RWMol> labelledCore;
29 
30  // Bitset: indices corresponding to atoms bearing user-defined labels are 1
31  boost::dynamic_bitset<> core_atoms_with_user_labels;
32  // Number of user labelled rgroups in the core
33  size_t numberUserRGroups = 0;
34  RCore() {}
35  RCore(const RWMol &c) : core(new RWMol(c)) { init(); }
36 
37  void init();
38 
39  inline bool isCoreAtomUserLabelled(int idx) const {
40  return core_atoms_with_user_labels.test(idx);
41  }
42 
45  }
46 
47  // Find all the core atoms that have user
48  // label and set their indices to 1 into core_atoms_with_user_labels
50 
51  // Return a copy of core where dummy atoms are replaced by
52  // the respective matching atom in mol, while other atoms have
53  // their aromatic flag and formal charge copied from
54  // the respective matching atom in mol
56  const ROMol &mol,
57  const MatchVectType &match) const;
58 
59  // Final core returned to user, created by extracting core from target
60  // molecule
61  std::pair<RWMOL_SPTR, bool> extractCoreFromMolMatch(
62  const ROMol &mol, const MatchVectType &match,
63  const RGroupDecompositionParameters &params) const;
64 
65  std::vector<MatchVectType> matchTerminalUserRGroups(
66  const RWMol &target, MatchVectType match,
67  const SubstructMatchParameters &sssParams) const;
68 
69  inline bool isTerminalRGroupWithUserLabel(const int idx) const {
70  return terminalRGroupDummyAtoms.find(idx) != terminalRGroupDummyAtoms.end();
71  }
72 
73  /*
74  * For when onlyMatchAtRGroups = true. Checks the query core can satisfy all
75  * attachment points. Including when two user defined attachment points can
76  * match the same target atom.
77  */
79  const ROMol &mol, const int attachmentIdx,
80  const MatchVectType &mapping) const;
81 
82  private:
83  // The set of atom indices in the core for terminal R groups with user label
84  std::set<int> terminalRGroupDummyAtoms;
85  // The set of atom indices in the core for terminal R groups with atom indices
86  // with or without user labels
87  std::set<int> terminalRGroupAtoms;
88  // An atom index map of terminal R groups to their heavy atom neighbor
89  std::map<int, int> terminalRGroupAtomToNeighbor;
90 
91  void replaceCoreAtom(RWMol &mol, Atom &atom, const Atom &other) const;
92 
93  // Convert a matching molecule index to a core index
94  int matchingIndexToCoreIndex(int matchingIndex) const;
95 
96  // Build the matching molecule (core minus user R groups)
97  void buildMatchingMol();
98 
99  // Add attachment points to unlabelled R Groups
100  void addDummyAtomsToUnlabelledCoreAtoms();
101 };
102 
103 } // namespace RDKit
104 #endif
The class for representing atoms.
Definition: Atom.h:68
RWMol is a molecule class that is intended to be edited.
Definition: RWMol.h:32
Std stuff.
Definition: Abbreviations.h:19
std::vector< std::pair< int, int > > MatchVectType
used to return matches from substructure searching, The format is (queryAtomIdx, molAtomIdx)
boost::shared_ptr< ROMol > ROMOL_SPTR
RCore is the core common to a series of molecules.
Definition: RGroupCore.h:24
std::vector< MatchVectType > matchTerminalUserRGroups(const RWMol &target, MatchVectType match, const SubstructMatchParameters &sssParams) const
size_t numberUserRGroups
Definition: RGroupCore.h:33
bool isCoreAtomUserLabelled(int idx) const
Definition: RGroupCore.h:39
void findIndicesWithRLabel()
void countUserRGroups()
Definition: RGroupCore.h:43
ROMOL_SPTR replaceCoreAtomsWithMolMatches(bool &hasCoreDummies, const ROMol &mol, const MatchVectType &match) const
bool checkAllBondsToAttachmentPointPresent(const ROMol &mol, const int attachmentIdx, const MatchVectType &mapping) const
bool isTerminalRGroupWithUserLabel(const int idx) const
Definition: RGroupCore.h:69
boost::dynamic_bitset core_atoms_with_user_labels
Definition: RGroupCore.h:31
boost::shared_ptr< RWMol > core
Definition: RGroupCore.h:25
boost::shared_ptr< RWMol > labelledCore
Definition: RGroupCore.h:28
std::pair< RWMOL_SPTR, bool > extractCoreFromMolMatch(const ROMol &mol, const MatchVectType &match, const RGroupDecompositionParameters &params) const
boost::shared_ptr< RWMol > matchingMol
Definition: RGroupCore.h:27
RCore(const RWMol &c)
Definition: RGroupCore.h:35