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