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 from
54  // the respective matching atom in mol
56  const ROMol &mol,
57  const MatchVectType &match) const;
58 
59  // Final core returned to user with dummy atoms and bonds set to those in the
60  // match
61  RWMOL_SPTR coreWithMatches(const ROMol &coreReplacedAtoms) const;
62 
63  std::vector<MatchVectType> matchTerminalUserRGroups(
64  const RWMol &target, MatchVectType match,
65  const SubstructMatchParameters &sssParams) const;
66 
67  inline bool isTerminalRGroupWithUserLabel(const int idx) const {
68  return terminalRGroupAtomsWithUserLabels.find(idx) !=
69  terminalRGroupAtomsWithUserLabels.end();
70  }
71 
72  /*
73  * For when onlyMatchAtRGroups = true. Checks the query core can satisfy all
74  * attachment points. Including when two user defined attachment points can
75  * match the same target atom.
76  */
78  const ROMol &mol, const int attachmentIdx,
79  const MatchVectType &mapping) const;
80 
81  private:
82  // The set of atom indices in the core for terminal R groups with atom indices
83  std::set<int> terminalRGroupAtomsWithUserLabels;
84  // An atom index map of terminal R groups to their heavy atom neighbor
85  std::map<int, int> terminalRGroupAtomToNeighbor;
86 
87  void replaceCoreAtom(RWMol &mol, Atom &atom, const Atom &other) const;
88 
89  // Convert a matching molecule index to a core index
90  int matchingIndexToCoreIndex(int matchingIndex) const;
91 
92  // Build the matching molecule (core minus user R groups)
93  void buildMatchingMol();
94 };
95 
96 } // namespace RDKit
97 #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:18
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
boost::shared_ptr< RWMol > RWMOL_SPTR
Definition: RWMol.h:222
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
RWMOL_SPTR coreWithMatches(const ROMol &coreReplacedAtoms) const
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:67
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
boost::shared_ptr< RWMol > matchingMol
Definition: RGroupCore.h:27
RCore(const RWMol &c)
Definition: RGroupCore.h:35