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"
20#include "TargetMatch.h"
21
22namespace RDKit {
23namespace FMCS {
24class MaximumCommonSubgraph;
25struct TargetMatch;
26
27// Reference to a fragment of source molecule
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
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
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
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
81 // seed topology with references to source molecule
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
93#endif
94 // for each target
95 std::vector<TargetMatch> MatchResult;
96
97 public:
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
The class for representing atoms.
Definition Atom.h:75
class for representing a bond
Definition Bond.h:47
unsigned int LastAddedBondsBeginIdx
Definition Seed.h:88
unsigned int addBond(const Bond *bond)
unsigned int getNumAtoms() const
Definition Seed.h:138
void createFromParent(const Seed *parent)
Definition Seed.h:123
unsigned int GrowingStage
Definition Seed.h:78
unsigned int LastAddedAtomsBeginIdx
Definition Seed.h:86
unsigned int getNumBonds() const
Definition Seed.h:139
void grow(MaximumCommonSubgraph &mcs) const
void setStoreAllDegenerateMCS(bool value)
Definition Seed.h:155
void fillNewBonds(const ROMol &qmol, MaximumCommonSubgraph *mcs=nullptr) const
unsigned int RemainingAtoms
Definition Seed.h:90
MolFragment MoleculeFragment
Definition Seed.h:80
DuplicatedSeedCache::TKey DupCacheKey
Definition Seed.h:92
std::vector< TargetMatch > MatchResult
Definition Seed.h:95
void setMoleculeFragment(const Seed &src)
Definition Seed.h:102
unsigned int RemainingBonds
Definition Seed.h:89
bool canGrowBiggerThan(unsigned int maxBonds, unsigned int maxAtoms) const
Definition Seed.h:142
unsigned int addAtom(const Atom *atom)
boost::dynamic_bitset ExcludedBonds
Definition Seed.h:84
Seed & operator=(const Seed &src)
Definition Seed.h:105
void computeRemainingSize(const ROMol &qmol)
Graph Topology
Definition Seed.h:82
#define RDKIT_FMCS_EXPORT
Definition export.h:153
Std stuff.
std::map< unsigned int, unsigned int > SeedAtomIdxMap
Definition Seed.h:32
std::vector< const Bond * > Bonds
Definition Seed.h:30
std::vector< const Atom * > Atoms
Definition Seed.h:29
NewBond(unsigned int bond_idx, unsigned int new_atom, unsigned int to_atom, const Atom *a)
Definition Seed.h:53