RDKit
Open-source cheminformatics and machine learning.
MaximumCommonSubgraph.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 <vector>
13 #include <string>
14 #include <stdexcept>
15 #include "../RDKitBase.h"
16 #include "FMCS.h"
17 #include "DebugTrace.h" // algorithm filter definitions
18 #include "SeedSet.h"
19 #include "Target.h"
20 #include "SubstructureCache.h"
21 #include "DuplicatedSeedCache.h"
22 #include "MatchTable.h"
23 #include "TargetMatch.h"
24 #include "RingMatchTableSet.h"
25 
26 namespace RDKit {
27 
28 inline bool FinalChiralityCheckFunction(const short unsigned c1[],
29  const short unsigned c2[], const ROMol& mol1,
30  const FMCS::Graph& query, const ROMol& mol2,
31  const FMCS::Graph& target,
32  const MCSParameters* p);
33 
34 bool FinalMatchCheckFunction(const short unsigned c1[],
35  const short unsigned c2[], const ROMol& mol1,
36  const FMCS::Graph& query, const ROMol& mol2,
37  const FMCS::Graph& target,
38  const MCSParameters* p);
39 
40 namespace FMCS {
42  struct MCS { // current result. Reference to a fragment of source molecule
43  std::vector<const Atom*> Atoms;
44  std::vector<const Bond*> Bonds;
45  std::vector<unsigned> AtomsIdx;
46  std::vector<unsigned> BondsIdx; // need for results and size() only !
47  const ROMol* QueryMolecule;
48  std::vector<Target> Targets;
49  };
50 
51  unsigned long long To;
52  MCSProgressData Stat;
53  MCSParameters Parameters;
54  unsigned ThresholdCount; // min number of matching
55  std::vector<const ROMol*> Molecules;
56 #ifdef FAST_SUBSTRUCT_CACHE
57  std::vector<unsigned> QueryAtomLabels; // for code Morgan. Value based on
58  // current functor and parameters
59  std::vector<unsigned> QueryBondLabels; // for code Morgan. Value based on
60  // current functor and parameters
61  SubstructureCache HashCache;
62  MatchTable QueryAtomMatchTable;
63  MatchTable QueryBondMatchTable;
64  RingMatchTableSet RingMatchTables;
65 #endif
66 #ifdef DUP_SUBSTRUCT_CACHE
67  DuplicatedSeedCache DuplicateCache;
68 #endif
69  const ROMol* QueryMolecule;
70  unsigned QueryMoleculeMatchedBonds;
71  unsigned QueryMoleculeMatchedAtoms;
72  std::vector<Target> Targets;
73  SeedSet Seeds;
74  MCS McsIdx;
75 
76  public:
77 #ifdef VERBOSE_STATISTICS_ON
79 #endif
80 
81  MaximumCommonSubgraph(const MCSParameters* params);
82  ~MaximumCommonSubgraph() { clear(); }
83  MCSResult find(const std::vector<ROMOL_SPTR>& mols);
84  const ROMol& getQueryMolecule() const { return *QueryMolecule; }
85  unsigned getMaxNumberBonds() const { return McsIdx.BondsIdx.size(); }
86 
87  unsigned getMaxNumberAtoms() const { return McsIdx.AtomsIdx.size(); }
88  // internal:
89  bool checkIfMatchAndAppend(Seed& seed);
90 
91  private:
92  void clear() {
93  Targets.clear();
94  Molecules.clear();
95  To = nanoClock();
96  }
97  void init();
98  void makeInitialSeeds();
99  bool createSeedFromMCS(size_t newQueryTarget, Seed& seed);
100  bool growSeeds(); // returns false if canceled
101  std::string generateResultSMARTS(const MCS& McsIdx) const;
102 
103  bool match(Seed& seed);
104  bool matchIncrementalFast(Seed& seed, unsigned itarget);
105 };
106 } // namespace FMCS
107 } // namespace RDKit
RDKit::FMCS::MaximumCommonSubgraph
Definition: MaximumCommonSubgraph.h:41
RDKit::MCSParameters
Definition: FMCS.h:94
SubstructureCache.h
RDKit::MCSResult
Definition: FMCS.h:112
RDKit::FinalChiralityCheckFunction
bool FinalChiralityCheckFunction(const short unsigned c1[], const short unsigned c2[], const ROMol &mol1, const FMCS::Graph &query, const ROMol &mol2, const FMCS::Graph &target, const MCSParameters *p)
TargetMatch.h
RDKit::FMCS::Seed
Definition: Seed.h:62
RDKit::FMCS::MaximumCommonSubgraph::getQueryMolecule
const ROMol & getQueryMolecule() const
Definition: MaximumCommonSubgraph.h:84
Target.h
RDKit::FMCS::MaximumCommonSubgraph::getMaxNumberAtoms
unsigned getMaxNumberAtoms() const
Definition: MaximumCommonSubgraph.h:87
RDKit::FMCS::MaximumCommonSubgraph::VerboseStatistics
ExecStatistics VerboseStatistics
Definition: MaximumCommonSubgraph.h:78
MatchTable.h
RDKit::ROMol
Definition: ROMol.h:171
RDKit::MCS
@ MCS
Definition: RGroupDecomp.h:52
RDKit::FMCS::DuplicatedSeedCache
Definition: DuplicatedSeedCache.h:19
RDKit::FMCS::MaximumCommonSubgraph::~MaximumCommonSubgraph
~MaximumCommonSubgraph()
Definition: MaximumCommonSubgraph.h:82
SeedSet.h
RDKit::FMCS::RingMatchTableSet
Definition: RingMatchTableSet.h:18
RDKit::FMCS::SeedSet
Definition: SeedSet.h:19
RDKit::FinalMatchCheckFunction
bool FinalMatchCheckFunction(const short unsigned c1[], const short unsigned c2[], const ROMol &mol1, const FMCS::Graph &query, const ROMol &mol2, const FMCS::Graph &target, const MCSParameters *p)
RDKit
Std stuff.
Definition: Atom.h:30
FMCS.h
RDKIT_FMCS_EXPORT
#define RDKIT_FMCS_EXPORT
Definition: export.h:203
RDKit::FMCS::TArray2D< bool >
nanoClock
static unsigned long long nanoClock(void)
Definition: DebugTrace.h:96
RDKit::FMCS::ExecStatistics
Definition: DebugTrace.h:113
DebugTrace.h
RDKit::MCSProgressData
Definition: FMCS.h:78
RDKit::FMCS::MaximumCommonSubgraph::getMaxNumberBonds
unsigned getMaxNumberBonds() const
Definition: MaximumCommonSubgraph.h:85
DuplicatedSeedCache.h
RDKit::FMCS::SubstructureCache
Definition: SubstructureCache.h:24
RingMatchTableSet.h
export.h