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