RDKit: Seed.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
Seed.h
Go to the documentation of this file.
1//
2// Copyright (C) 2014 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#pragma once
12#include <map>
13#include <boost/dynamic_bitset.hpp>
14#include "../RDKitBase.h"
15// algorithm optimisation definitions
16#include "DebugTrace.h"
17#include "Graph.h"
18#include "DuplicatedSeedCache.h"
19#include "SubstructMatchCustom.h"
20#include "TargetMatch.h"
21
22namespace RDKit {
23namespace FMCS {
24class MaximumCommonSubgraph;
25struct TargetMatch;
26
27// Reference to a fragment of source molecule
28 struct RDKIT_FMCS_EXPORT MolFragment {
29 std::vector<const Atom *> Atoms;
30 std::vector<const Bond *> Bonds;
31 // Full Query Molecule to Seed indices backward conversionmap
32 std::map<unsigned int, unsigned int> SeedAtomIdxMap;
33};
34
35 struct RDKIT_FMCS_EXPORT NewBond {
36 // index in qmol of new bond scheduled to be added into
37 // seed. This is outgoing bond from SourceAtomIdx
38 unsigned int BondIdx{0};
39 // index in qmol of new atom scheduled to be
40 // added into seed. Another end of new bond
41 unsigned int NewAtomIdx{0};
42 // index in the seed. RING. "New" Atom on the another
43 // end of new bond if it already exists in the seed.
44 unsigned int EndAtomIdx{0};
45 // pointer to qmol's new atom scheduled to be
46 // added into seed. Another end of new bond
47 const Atom *NewAtom{nullptr};
48
49 NewBond()
50
51 {}
52
53 NewBond(unsigned int bond_idx, unsigned int new_atom, unsigned int to_atom,
54 const Atom *a)
55 : BondIdx(bond_idx),
56 NewAtomIdx(new_atom),
57 EndAtomIdx(to_atom),
58 NewAtom(a) {}
59};
60
61 class RDKIT_FMCS_EXPORT Seed {
62 private:
63 boost::dynamic_bitset<> addNewBondsToSeed(const ROMol &qmol,
64 Seed &seed) const;
65 bool canAddAllNonFusedRingBondsConnectedToBond(
66 const Atom &srcAtom, const Bond &bond, MaximumCommonSubgraph &mcs) const;
67 void addNewBondFromAtom(const Atom &srcAtom, const Bond &bond) const;
68 // for multistage growing. all directly connected outgoing bonds
69 mutable std::vector<NewBond> NewBonds;
70 bool StoreAllDegenerateMCS = false;
71
72 public:
73 // this seed has been completely copied into list.
74 // postponed non-locked copy for MULTI_THREAD
75 bool CopyComplete{false};
76 // 0 new seed; -1 finished; n>0 in
77 // progress, exact stage of growing for SDF
78 mutable unsigned int GrowingStage{0};
79 // Reference to a fragment of source molecule
80 MolFragment MoleculeFragment;
81 // seed topology with references to source molecule
82 Graph Topology;
83
84 boost::dynamic_bitset<> ExcludedBonds;
85 // in this subgraph for improving performance of future growing
86 unsigned int LastAddedAtomsBeginIdx{0};
87 // in this subgraph for DEBUG ONLY
88 unsigned int LastAddedBondsBeginIdx{0};
89 unsigned int RemainingBonds{0};
90 unsigned int RemainingAtoms{0};
91#ifdef DUP_SUBSTRUCT_CACHE
92 DuplicatedSeedCache::TKey DupCacheKey;
93#endif
94 // for each target
95 std::vector<TargetMatch> MatchResult;
96
97 public:
98 Seed()
99
100 {}
101
102 void setMoleculeFragment(const Seed &src) {
103 MoleculeFragment = src.MoleculeFragment;
104 }
105 Seed &operator=(const Seed &src) {
106 NewBonds = src.NewBonds;
107 GrowingStage = src.GrowingStage;
108 MoleculeFragment = src.MoleculeFragment;
109 Topology = src.Topology;
110 ExcludedBonds = src.ExcludedBonds;
111 LastAddedAtomsBeginIdx = src.LastAddedAtomsBeginIdx;
112 LastAddedBondsBeginIdx = src.LastAddedBondsBeginIdx;
113 RemainingBonds = src.RemainingBonds;
114 RemainingAtoms = src.RemainingAtoms;
115 StoreAllDegenerateMCS = src.StoreAllDegenerateMCS;
116#ifdef DUP_SUBSTRUCT_CACHE
117 DupCacheKey = src.DupCacheKey;
118#endif
119 MatchResult = src.MatchResult;
120 CopyComplete = true; // LAST
121 return *this;
122 }
123 void createFromParent(const Seed *parent) {
124 MoleculeFragment = parent->MoleculeFragment;
125 Topology = parent->Topology;
126 ExcludedBonds = parent->ExcludedBonds;
127 RemainingBonds = parent->RemainingBonds;
128 RemainingAtoms = parent->RemainingAtoms;
129 StoreAllDegenerateMCS = parent->StoreAllDegenerateMCS;
130#ifdef DUP_SUBSTRUCT_CACHE
131 DupCacheKey = parent->DupCacheKey;
132#endif
133 LastAddedAtomsBeginIdx = getNumAtoms(); // previous size
134 LastAddedBondsBeginIdx = getNumBonds(); // previous size
135 GrowingStage = 0;
136 }
137
138 unsigned int getNumAtoms() const { return MoleculeFragment.Atoms.size(); }
139 unsigned int getNumBonds() const { return MoleculeFragment.Bonds.size(); }
140
141 void grow(MaximumCommonSubgraph &mcs) const;
142 bool canGrowBiggerThan(unsigned int maxBonds, unsigned int maxAtoms) const {
143 return RemainingBonds + getNumBonds() > maxBonds ||
144 (RemainingBonds + getNumBonds() == maxBonds &&
145 (RemainingAtoms + getNumAtoms() > maxAtoms ||
146 (StoreAllDegenerateMCS &&
147 RemainingAtoms + getNumAtoms() == maxAtoms)));
148 }
149 void computeRemainingSize(const ROMol &qmol);
150
151 unsigned int addAtom(const Atom *atom);
152 unsigned int addBond(const Bond *bond);
153 void fillNewBonds(const ROMol &qmol,
154 MaximumCommonSubgraph *mcs = nullptr) const;
155 void setStoreAllDegenerateMCS(bool value) { StoreAllDegenerateMCS = value; }
156};
157} // namespace FMCS
158} // namespace RDKit
DebugTrace.h
DuplicatedSeedCache.h
Graph.h
RDKitBase.h
pulls in the core RDKit functionality
SubstructMatchCustom.h
TargetMatch.h
RDKit::Atom
The class for representing atoms.
Definition Atom.h:74
RDKit::Bond
class for representing a bond
Definition Bond.h:46
RDKit::FMCS::DuplicatedSeedCache::TKey
Definition DuplicatedSeedCache.h:22
RDKit::FMCS::Graph
Definition Graph.h:26
RDKit::FMCS::MaximumCommonSubgraph
Definition MaximumCommonSubgraph.h:38
RDKit::FMCS::Seed::LastAddedBondsBeginIdx
unsigned int LastAddedBondsBeginIdx
Definition Seed.h:88
RDKit::FMCS::Seed::addBond
unsigned int addBond(const Bond *bond)
RDKit::FMCS::Seed::getNumAtoms
unsigned int getNumAtoms() const
Definition Seed.h:138
RDKit::FMCS::Seed::createFromParent
void createFromParent(const Seed *parent)
Definition Seed.h:123
RDKit::FMCS::Seed::GrowingStage
unsigned int GrowingStage
Definition Seed.h:78
RDKit::FMCS::Seed::LastAddedAtomsBeginIdx
unsigned int LastAddedAtomsBeginIdx
Definition Seed.h:86
RDKit::FMCS::Seed::getNumBonds
unsigned int getNumBonds() const
Definition Seed.h:139
RDKit::FMCS::Seed::grow
void grow(MaximumCommonSubgraph &mcs) const
RDKit::FMCS::Seed::setStoreAllDegenerateMCS
void setStoreAllDegenerateMCS(bool value)
Definition Seed.h:155
RDKit::FMCS::Seed::Seed
Seed()
Definition Seed.h:98
RDKit::FMCS::Seed::fillNewBonds
void fillNewBonds(const ROMol &qmol, MaximumCommonSubgraph *mcs=nullptr) const
RDKit::FMCS::Seed::RemainingAtoms
unsigned int RemainingAtoms
Definition Seed.h:90
RDKit::FMCS::Seed::MoleculeFragment
MolFragment MoleculeFragment
Definition Seed.h:80
RDKit::FMCS::Seed::DupCacheKey
DuplicatedSeedCache::TKey DupCacheKey
Definition Seed.h:92
RDKit::FMCS::Seed::MatchResult
std::vector< TargetMatch > MatchResult
Definition Seed.h:95
RDKit::FMCS::Seed::setMoleculeFragment
void setMoleculeFragment(const Seed &src)
Definition Seed.h:102
RDKit::FMCS::Seed::RemainingBonds
unsigned int RemainingBonds
Definition Seed.h:89
RDKit::FMCS::Seed::canGrowBiggerThan
bool canGrowBiggerThan(unsigned int maxBonds, unsigned int maxAtoms) const
Definition Seed.h:142
RDKit::FMCS::Seed::addAtom
unsigned int addAtom(const Atom *atom)
RDKit::FMCS::Seed::ExcludedBonds
boost::dynamic_bitset ExcludedBonds
Definition Seed.h:84
RDKit::FMCS::Seed::operator=
Seed & operator=(const Seed &src)
Definition Seed.h:105
RDKit::FMCS::Seed::CopyComplete
bool CopyComplete
Definition Seed.h:75
RDKit::FMCS::Seed::computeRemainingSize
void computeRemainingSize(const ROMol &qmol)
RDKit::FMCS::Seed::Topology
Graph Topology
Definition Seed.h:82
RDKit::ROMol
Definition ROMol.h:199
export.h
RDKIT_FMCS_EXPORT
#define RDKIT_FMCS_EXPORT
Definition export.h:169
RDKit::FMCS
Definition Composition2N.h:13
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::FMCS::MolFragment
Definition Seed.h:28
RDKit::FMCS::MolFragment::SeedAtomIdxMap
std::map< unsigned int, unsigned int > SeedAtomIdxMap
Definition Seed.h:32
RDKit::FMCS::MolFragment::Bonds
std::vector< const Bond * > Bonds
Definition Seed.h:30
RDKit::FMCS::MolFragment::Atoms
std::vector< const Atom * > Atoms
Definition Seed.h:29
RDKit::FMCS::NewBond::NewBond
NewBond()
Definition Seed.h:49
RDKit::FMCS::NewBond::NewAtomIdx
unsigned int NewAtomIdx
Definition Seed.h:41
RDKit::FMCS::NewBond::BondIdx
unsigned int BondIdx
Definition Seed.h:38
RDKit::FMCS::NewBond::NewBond
NewBond(unsigned int bond_idx, unsigned int new_atom, unsigned int to_atom, const Atom *a)
Definition Seed.h:53
RDKit::FMCS::NewBond::NewAtom
const Atom * NewAtom
Definition Seed.h:47
RDKit::FMCS::NewBond::EndAtomIdx
unsigned int EndAtomIdx
Definition Seed.h:44
RDKit::FMCS::TargetMatch
Definition TargetMatch.h:23