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 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 namespace FMCS {
36  struct MCS { // current result. Reference to a fragment of source molecule
37  std::vector<const Atom*> Atoms;
38  std::vector<const Bond*> Bonds;
39  std::vector<unsigned> AtomsIdx;
40  std::vector<unsigned> BondsIdx; // need for results and size() only !
41  const ROMol* QueryMolecule;
42  std::vector<Target> Targets;
43  };
44 
45  unsigned long long To;
46  MCSProgressData Stat;
47  MCSParameters Parameters;
48  unsigned ThresholdCount; // min number of matching
49  std::vector<const ROMol*> Molecules;
50 #ifdef FAST_SUBSTRUCT_CACHE
51  std::vector<unsigned> QueryAtomLabels; // for code Morgan. Value based on
52  // current functor and parameters
53  std::vector<unsigned> QueryBondLabels; // for code Morgan. Value based on
54  // current functor and parameters
55  SubstructureCache HashCache;
56  MatchTable QueryAtomMatchTable;
57  MatchTable QueryBondMatchTable;
58  RingMatchTableSet RingMatchTables;
59 #endif
60 #ifdef DUP_SUBSTRUCT_CACHE
61  DuplicatedSeedCache DuplicateCache;
62 #endif
63  const ROMol* QueryMolecule;
64  unsigned QueryMoleculeMatchedBonds;
65  unsigned QueryMoleculeMatchedAtoms;
66  std::vector<Target> Targets;
67  SeedSet Seeds;
68  MCS McsIdx;
69 
70  public:
71 #ifdef VERBOSE_STATISTICS_ON
73 #endif
74 
75  MaximumCommonSubgraph(const MCSParameters* params);
76  ~MaximumCommonSubgraph() { clear(); }
77  MCSResult find(const std::vector<ROMOL_SPTR>& mols);
78  const ROMol& getQueryMolecule() const { return *QueryMolecule; }
79  unsigned getMaxNumberBonds() const { return McsIdx.BondsIdx.size(); }
80 
81  unsigned getMaxNumberAtoms() const { return McsIdx.AtomsIdx.size(); }
82  // internal:
83  bool checkIfMatchAndAppend(Seed& seed);
84 
85  private:
86  void clear() {
87  Targets.clear();
88  Molecules.clear();
89  To = nanoClock();
90  }
91  void init();
92  void makeInitialSeeds();
93  bool createSeedFromMCS(size_t newQueryTarget, Seed& seed);
94  bool growSeeds(); // returns false if canceled
95  std::string generateResultSMARTS(const MCS& McsIdx) const;
96 
97  bool match(Seed& seed);
98  bool matchIncrementalFast(Seed& seed, unsigned itarget);
99 };
100 }
101 } // namespace RDKit
#define RDKIT_FMCS_EXPORT
Definition: export.h:190
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)
static unsigned long long nanoClock(void)
Definition: DebugTrace.h:96
Std stuff.
Definition: Atom.h:30