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  const Atom* QueryMoleculeSingleMatchedAtom;
71  std::vector<Target> Targets;
72  SeedSet Seeds;
73  MCS McsIdx;
74 
75  public:
76 #ifdef VERBOSE_STATISTICS_ON
78 #endif
79 
81  ~MaximumCommonSubgraph() { clear(); }
82  MCSResult find(const std::vector<ROMOL_SPTR>& mols);
83  const ROMol& getQueryMolecule() const { return *QueryMolecule; }
84  unsigned getMaxNumberBonds() const { return McsIdx.BondsIdx.size(); }
85 
86  unsigned getMaxNumberAtoms() const { return McsIdx.AtomsIdx.size(); }
87  // internal:
89 
90  private:
91  void clear() {
92  Targets.clear();
93  Molecules.clear();
94  To = nanoClock();
95  }
96  void init();
97  void makeInitialSeeds();
98  bool createSeedFromMCS(size_t newQueryTarget, Seed& seed);
99  bool growSeeds(); // returns false if canceled
100  std::pair<std::string, RWMol*> generateResultSMARTSAndQueryMol(
101  const MCS& mcsIdx) const;
102  bool addFusedBondQueries(const MCS& McsIdx, RWMol* rwMol) const;
103 
104  bool match(Seed& seed);
105  bool matchIncrementalFast(Seed& seed, unsigned itarget);
106 };
107 } // namespace FMCS
108 } // namespace RDKit
static unsigned long long nanoClock(void)
Definition: DebugTrace.h:97
The class for representing atoms.
Definition: Atom.h:68
MaximumCommonSubgraph(const MCSParameters *params)
bool checkIfMatchAndAppend(Seed &seed)
MCSResult find(const std::vector< ROMOL_SPTR > &mols)
RWMol is a molecule class that is intended to be edited.
Definition: RWMol.h:32
#define RDKIT_FMCS_EXPORT
Definition: export.h:153
const uint32_t seed
Definition: MHFP.h:29
Std stuff.
Definition: Abbreviations.h:19
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)
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)