RDKit: RGroupCore.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
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
14#include <GraphMol/SmilesParse/SmartsWrite.h>
15#include "../RDKitBase.h"
16#include "RGroupUtils.h"
17#include "GraphMol/Substruct/SubstructMatch.h"
18
19// #define VERBOSE 1
20
21namespace RDKit {
22class TautomerQuery;
23
24//! RCore is the core common to a series of molecules
25 struct RCore {
26 boost::shared_ptr<RWMol> core;
27 // core with terminal user R groups stripped for matching
28 boost::shared_ptr<RWMol> matchingMol;
29 boost::shared_ptr<RWMol> labelledCore;
30
31 // Bitset: indices corresponding to atoms bearing user-defined labels are 1
32 boost::dynamic_bitset<> core_atoms_with_user_labels;
33 // Number of user labelled rgroups in the core
34 size_t numberUserRGroups = 0;
35 RCore() {}
36 RCore(const RWMol &c) : core(new RWMol(c)) { init(); }
37
38 void init();
39
40 inline bool isCoreAtomUserLabelled(int idx) const {
41 return core_atoms_with_user_labels.test(idx);
42 }
43
44 void countUserRGroups() {
45 numberUserRGroups = core_atoms_with_user_labels.count();
46 }
47
48 // Find all the core atoms that have user
49 // label and set their indices to 1 into core_atoms_with_user_labels
50 void findIndicesWithRLabel();
51
52 // Return a copy of core where dummy atoms are replaced by
53 // the respective matching atom in mol, while other atoms have
54 // their aromatic flag and formal charge copied from
55 // the respective matching atom in mol
56 ROMOL_SPTR replaceCoreAtomsWithMolMatches(const ROMol &mol,
57 const MatchVectType &match) const;
58
59 // Final core returned to user, created by extracting core from target
60 // molecule
61 RWMOL_SPTR 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 std::shared_ptr<TautomerQuery> getMatchingTautomerQuery();
70
71 inline bool isTerminalRGroupWithUserLabel(const int idx) const {
72 return terminalRGroupAtomToNeighbor.find(idx) !=
73 terminalRGroupAtomToNeighbor.end();
74 }
75
76 /*
77 * For when onlyMatchAtRGroups = true. Checks the query core can satisfy all
78 * attachment points. Including when two user defined attachment points can
79 * match the same target atom.
80 */
81 [[deprecated("please use checkAllBondsToRGroupPresent")]]
82 bool checkAllBondsToAttachmentPointPresent(
83 const ROMol &mol, const int attachmentIdx,
84 const MatchVectType &mapping) const;
85
86 /*
87 * For when onlyMatchAtRGroups = true. Checks the query core can satisfy all
88 * attachment points. Including when two user defined attachment points can
89 * match the same target atom.
90 */
91 bool checkAllBondsToRGroupPresent(
92 const ROMol &mol, const int attachmentIdx,
93 const std::vector<std::vector<int>> &targetToCoreIndices) const;
94
95 private:
96 // The set of atom indices in the core for terminal R groups with atom indices
97 // with or without user labels
98 std::set<int> terminalRGroupAtoms;
99 // An atom index map of terminal R groups to their heavy atom neighbor
100 std::map<int, int> terminalRGroupAtomToNeighbor;
101 // TautomerQuery for matching
102 bool checkedForTautomerQuery = false;
103 std::shared_ptr<TautomerQuery> matchingTautomerQuery = nullptr;
104
105 void replaceCoreAtom(RWMol &mol, Atom &atom, const Atom &other) const;
106
107 // Convert a matching molecule index to a core index
108 int matchingIndexToCoreIndex(int matchingIndex) const;
109
110 // Build the matching molecule (core minus user R groups)
111 void buildMatchingMol();
112
113 // Add attachment points to unlabelled R Groups
114 void addDummyAtomsToUnlabelledCoreAtoms();
115};
116
117} // namespace RDKit
118#endif
RDKitBase.h
pulls in the core RDKit functionality
RGroupUtils.h
SmartsWrite.h
SubstructMatch.h
RDKit::Atom
The class for representing atoms.
Definition Atom.h:74
RDKit::ROMol
Definition ROMol.h:199
RDKit::RWMol
RWMol is a molecule class that is intended to be edited.
Definition RWMol.h:32
RDKit::TautomerQuery
Definition TautomerQuery.h:37
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::MatchVectType
std::vector< std::pair< int, int > > MatchVectType
used to return matches from substructure searching, The format is (queryAtomIdx, molAtomIdx)
Definition FragFPGenerator.h:24
RDKit::ROMOL_SPTR
boost::shared_ptr< ROMol > ROMOL_SPTR
Definition ChemTransforms.h:22
RDKit::RWMOL_SPTR
boost::shared_ptr< RWMol > RWMOL_SPTR
Definition RWMol.h:222
RDKit::RCore::numberUserRGroups
size_t numberUserRGroups
Definition RGroupCore.h:34
RDKit::RCore::isCoreAtomUserLabelled
bool isCoreAtomUserLabelled(int idx) const
Definition RGroupCore.h:40
RDKit::RCore::findIndicesWithRLabel
void findIndicesWithRLabel()
RDKit::RCore::countUserRGroups
void countUserRGroups()
Definition RGroupCore.h:44
RDKit::RCore::replaceCoreAtomsWithMolMatches
ROMOL_SPTR replaceCoreAtomsWithMolMatches(const ROMol &mol, const MatchVectType &match) const
RDKit::RCore::RCore
RCore()
Definition RGroupCore.h:35
RDKit::RCore::checkAllBondsToAttachmentPointPresent
bool checkAllBondsToAttachmentPointPresent(const ROMol &mol, const int attachmentIdx, const MatchVectType &mapping) const
RDKit::RCore::extractCoreFromMolMatch
RWMOL_SPTR extractCoreFromMolMatch(const ROMol &mol, const MatchVectType &match, const RGroupDecompositionParameters &params) const
RDKit::RCore::isTerminalRGroupWithUserLabel
bool isTerminalRGroupWithUserLabel(const int idx) const
Definition RGroupCore.h:71
RDKit::RCore::init
void init()
RDKit::RCore::core_atoms_with_user_labels
boost::dynamic_bitset core_atoms_with_user_labels
Definition RGroupCore.h:32
RDKit::RCore::core
boost::shared_ptr< RWMol > core
Definition RGroupCore.h:26
RDKit::RCore::getMatchingTautomerQuery
std::shared_ptr< TautomerQuery > getMatchingTautomerQuery()
RDKit::RCore::labelledCore
boost::shared_ptr< RWMol > labelledCore
Definition RGroupCore.h:29
RDKit::RCore::matchTerminalUserRGroups
std::vector< MatchVectType > matchTerminalUserRGroups(const RWMol &target, MatchVectType match, const SubstructMatchParameters &sssParams) const
RDKit::RCore::checkAllBondsToRGroupPresent
bool checkAllBondsToRGroupPresent(const ROMol &mol, const int attachmentIdx, const std::vector< std::vector< int > > &targetToCoreIndices) const
RDKit::RCore::matchingMol
boost::shared_ptr< RWMol > matchingMol
Definition RGroupCore.h:28
RDKit::RCore::RCore
RCore(const RWMol &c)
Definition RGroupCore.h:36
RDKit::RGroupDecompositionParameters
Definition RGroupDecompParams.h:39
RDKit::SubstructMatchParameters
Definition SubstructMatch.h:42