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 
29  const std::uint32_t c1[], const std::uint32_t c2[], const ROMol& mol1,
30  const FMCS::Graph& query, const ROMol& mol2, const FMCS::Graph& target,
31  const MCSParameters* p);
32 
33 bool FinalMatchCheckFunction(const std::uint32_t c1[], const std::uint32_t c2[],
34  const ROMol& mol1, const FMCS::Graph& query,
35  const ROMol& mol2, const FMCS::Graph& target,
36  const MCSParameters* p);
37 
38 namespace FMCS {
40  struct MCS { // current result. Reference to a fragment of source molecule
41  std::vector<const Atom*> Atoms;
42  std::vector<const Bond*> Bonds;
43  std::vector<unsigned> AtomsIdx;
44  std::vector<unsigned> BondsIdx; // need for results and size() only !
45  const ROMol* QueryMolecule;
46  std::vector<Target> Targets;
47  };
48 
49  unsigned long long To;
50  MCSProgressData Stat;
51  MCSParameters Parameters;
52  unsigned ThresholdCount; // min number of matching
53  std::vector<const ROMol*> Molecules;
54 #ifdef FAST_SUBSTRUCT_CACHE
55  std::vector<unsigned> QueryAtomLabels; // for code Morgan. Value based on
56  // current functor and parameters
57  std::vector<unsigned> QueryBondLabels; // for code Morgan. Value based on
58  // current functor and parameters
59  SubstructureCache HashCache;
60  MatchTable QueryAtomMatchTable;
61  MatchTable QueryBondMatchTable;
62  RingMatchTableSet RingMatchTables;
63 #endif
64 #ifdef DUP_SUBSTRUCT_CACHE
65  DuplicatedSeedCache DuplicateCache;
66 #endif
67  const ROMol* QueryMolecule;
68  unsigned QueryMoleculeMatchedBonds;
69  unsigned QueryMoleculeMatchedAtoms;
70  std::vector<Target> Targets;
71  SeedSet Seeds;
72  MCS McsIdx;
73 
74  public:
75 #ifdef VERBOSE_STATISTICS_ON
77 #endif
78 
80  ~MaximumCommonSubgraph() { clear(); }
81  MCSResult find(const std::vector<ROMOL_SPTR>& mols);
82  const ROMol& getQueryMolecule() const { return *QueryMolecule; }
83  unsigned getMaxNumberBonds() const { return McsIdx.BondsIdx.size(); }
84 
85  unsigned getMaxNumberAtoms() const { return McsIdx.AtomsIdx.size(); }
86  // internal:
88 
89  private:
90  void clear() {
91  Targets.clear();
92  Molecules.clear();
93  To = nanoClock();
94  }
95  void init();
96  void makeInitialSeeds();
97  bool createSeedFromMCS(size_t newQueryTarget, Seed& seed);
98  bool growSeeds(); // returns false if canceled
99  std::pair<std::string, RWMol*> generateResultSMARTSAndQueryMol(
100  const MCS& mcsIdx) const;
101  bool addFusedBondQueries(const MCS& McsIdx, RWMol* rwMol) 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:39
RDKit::MCSParameters
Definition: FMCS.h:131
RDKit::FMCS::MaximumCommonSubgraph::find
MCSResult find(const std::vector< ROMOL_SPTR > &mols)
SubstructureCache.h
RDKit::MCSResult
Definition: FMCS.h:153
RDKit::FinalMatchCheckFunction
bool FinalMatchCheckFunction(const std::uint32_t c1[], const std::uint32_t c2[], const ROMol &mol1, const FMCS::Graph &query, const ROMol &mol2, const FMCS::Graph &target, const MCSParameters *p)
RDKit::RWMol
RWMol is a molecule class that is intended to be edited.
Definition: RWMol.h:31
TargetMatch.h
RDKit::FMCS::Seed
Definition: Seed.h:62
RDKit::FMCS::MaximumCommonSubgraph::getQueryMolecule
const ROMol & getQueryMolecule() const
Definition: MaximumCommonSubgraph.h:82
Target.h
RDKit::FMCS::MaximumCommonSubgraph::getMaxNumberAtoms
unsigned getMaxNumberAtoms() const
Definition: MaximumCommonSubgraph.h:85
RDKit::MHFPFingerprints::FNV::seed
const uint32_t seed
Definition: MHFP.h:29
RDKit::FMCS::MaximumCommonSubgraph::VerboseStatistics
ExecStatistics VerboseStatistics
Definition: MaximumCommonSubgraph.h:76
MatchTable.h
RDKit::ROMol
Definition: ROMol.h:171
RDKit::FinalChiralityCheckFunction
bool FinalChiralityCheckFunction(const std::uint32_t c1[], const std::uint32_t c2[], const ROMol &mol1, const FMCS::Graph &query, const ROMol &mol2, const FMCS::Graph &target, const MCSParameters *p)
RDKit::MCS
@ MCS
Definition: RGroupDecomp.h:52
RDKit::FMCS::DuplicatedSeedCache
Definition: DuplicatedSeedCache.h:19
RDKit::FMCS::MaximumCommonSubgraph::~MaximumCommonSubgraph
~MaximumCommonSubgraph()
Definition: MaximumCommonSubgraph.h:80
SeedSet.h
RDKit::FMCS::RingMatchTableSet
Definition: RingMatchTableSet.h:18
RDKit::FMCS::SeedSet
Definition: SeedSet.h:19
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::Graph
Definition: Graph.h:24
RDKit::FMCS::ExecStatistics
Definition: DebugTrace.h:113
DebugTrace.h
RDKit::FMCS::MaximumCommonSubgraph::checkIfMatchAndAppend
bool checkIfMatchAndAppend(Seed &seed)
RDKit::MCSProgressData
Definition: FMCS.h:115
RDKit::FMCS::MaximumCommonSubgraph::getMaxNumberBonds
unsigned getMaxNumberBonds() const
Definition: MaximumCommonSubgraph.h:83
DuplicatedSeedCache.h
RDKit::FMCS::SubstructureCache
Definition: SubstructureCache.h:24
RingMatchTableSet.h
RDKit::FMCS::MaximumCommonSubgraph::MaximumCommonSubgraph
MaximumCommonSubgraph(const MCSParameters *params)
export.h