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