RDKit: MaximumCommonSubgraph.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
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
25namespace RDKit {
26
27 inline bool FinalChiralityCheckFunction(
28 const std::uint32_t c1[], const std::uint32_t c2[], const ROMol &mol1,
29 const FMCS::Graph &query, const ROMol &mol2, const FMCS::Graph &target,
30 const MCSParameters *p);
31
32 bool FinalMatchCheckFunction(const std::uint32_t c1[], const std::uint32_t c2[],
33 const ROMol &mol1, const FMCS::Graph &query,
34 const ROMol &mol2, const FMCS::Graph &target,
35 const MCSParameters *p);
36
37namespace FMCS {
38 class RDKIT_FMCS_EXPORT MaximumCommonSubgraph {
39 // current result. Reference to a fragment of source molecule
40 struct MCS {
41 std::vector<const Atom *> Atoms;
42 std::vector<const Bond *> Bonds;
43 const ROMol *QueryMolecule;
44 std::vector<Target> Targets;
45 };
46 unsigned long long To;
47 MCSProgressData Stat;
48 detail::MCSParametersInternal Parameters;
49 // min number of matches
50 unsigned int ThresholdCount;
51 std::vector<const ROMol *> Molecules;
52#ifdef FAST_SUBSTRUCT_CACHE
53 // for Morgan code. Value based on current functor and parameters
54 std::vector<unsigned int> QueryAtomLabels;
55 // for Morgan code. Value based on current functor and parameters
56 std::vector<unsigned int> QueryBondLabels;
57 SubstructureCache HashCache;
58 MatchTable QueryAtomMatchTable;
59 MatchTable QueryBondMatchTable;
60#endif
61#ifdef DUP_SUBSTRUCT_CACHE
62 DuplicatedSeedCache DuplicateCache;
63#endif
64 const ROMol *QueryMolecule;
65 unsigned int QueryMoleculeMatchedBonds;
66 unsigned int QueryMoleculeMatchedAtoms;
67 const Atom *QueryMoleculeSingleMatchedAtom;
68 std::vector<Target> Targets;
69 SeedSet Seeds;
70 MCS McsIdx;
71 std::map<std::vector<unsigned int>, MCS> DegenerateMcsMap;
72
73 public:
74#ifdef VERBOSE_STATISTICS_ON
75 ExecStatistics VerboseStatistics;
76#endif
77
78 MaximumCommonSubgraph(const MCSParameters *params);
79 ~MaximumCommonSubgraph() { clear(); }
80 MCSResult find(const std::vector<ROMOL_SPTR> &mols);
81 const ROMol &getQueryMolecule() const { return *QueryMolecule; }
82 unsigned int getMaxNumberBonds() const { return McsIdx.Bonds.size(); }
83
84 unsigned int getMaxNumberAtoms() const { return McsIdx.Atoms.size(); }
85 bool checkIfMatchAndAppend(Seed &seed);
86 bool match(Seed &seed);
87 const MCSParameters &parameters() const { return Parameters; }
88 MCSParameters &parameters() { return Parameters; }
89
90 private:
91 void clear() {
92 Targets.clear();
93 Molecules.clear();
94 To = nanoClock();
95 }
96 void init(size_t startIdx);
97 void makeInitialSeeds();
98 bool createSeedFromMCS(size_t newQueryTarget, Seed &seed);
99 bool growSeeds(); // returns false if canceled
100 std::pair<std::string, ROMOL_SPTR> generateResultSMARTSAndQueryMol(
101 const MCS &mcsIdx) const;
102
103 bool matchIncrementalFast(Seed &seed, unsigned int itarget);
104};
105} // namespace FMCS
106} // namespace RDKit
DebugTrace.h
nanoClock
static unsigned long long nanoClock(void)
Definition DebugTrace.h:96
DuplicatedSeedCache.h
FMCS.h
MatchTable.h
RDKitBase.h
pulls in the core RDKit functionality
SeedSet.h
SubstructureCache.h
TargetMatch.h
Target.h
RDKit::Atom
The class for representing atoms.
Definition Atom.h:74
RDKit::FMCS::DuplicatedSeedCache
Definition DuplicatedSeedCache.h:19
RDKit::FMCS::Graph
Definition Graph.h:26
RDKit::FMCS::MaximumCommonSubgraph::~MaximumCommonSubgraph
~MaximumCommonSubgraph()
Definition MaximumCommonSubgraph.h:79
RDKit::FMCS::MaximumCommonSubgraph::getMaxNumberBonds
unsigned int getMaxNumberBonds() const
Definition MaximumCommonSubgraph.h:82
RDKit::FMCS::MaximumCommonSubgraph::MaximumCommonSubgraph
MaximumCommonSubgraph(const MCSParameters *params)
RDKit::FMCS::MaximumCommonSubgraph::getMaxNumberAtoms
unsigned int getMaxNumberAtoms() const
Definition MaximumCommonSubgraph.h:84
RDKit::FMCS::MaximumCommonSubgraph::match
bool match(Seed &seed)
RDKit::FMCS::MaximumCommonSubgraph::parameters
MCSParameters & parameters()
Definition MaximumCommonSubgraph.h:88
RDKit::FMCS::MaximumCommonSubgraph::checkIfMatchAndAppend
bool checkIfMatchAndAppend(Seed &seed)
RDKit::FMCS::MaximumCommonSubgraph::VerboseStatistics
ExecStatistics VerboseStatistics
Definition MaximumCommonSubgraph.h:75
RDKit::FMCS::MaximumCommonSubgraph::find
MCSResult find(const std::vector< ROMOL_SPTR > &mols)
RDKit::FMCS::MaximumCommonSubgraph::parameters
const MCSParameters & parameters() const
Definition MaximumCommonSubgraph.h:87
RDKit::FMCS::MaximumCommonSubgraph::getQueryMolecule
const ROMol & getQueryMolecule() const
Definition MaximumCommonSubgraph.h:81
RDKit::FMCS::SeedSet
Definition SeedSet.h:19
RDKit::FMCS::Seed
Definition Seed.h:61
RDKit::FMCS::SubstructureCache
Definition SubstructureCache.h:23
RDKit::ROMol
Definition ROMol.h:199
export.h
RDKIT_FMCS_EXPORT
#define RDKIT_FMCS_EXPORT
Definition export.h:169
RDKit::FMCS
Definition Composition2N.h:13
RDKit::FMCS::MatchTable
TArray2D< bool > MatchTable
Definition MatchTable.h:48
RDKit
Std stuff.
Definition Abbreviations.h:19
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::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::FMCS::ExecStatistics
Definition DebugTrace.h:113
RDKit::MCSParameters
Definition FMCS.h:147
RDKit::MCSProgressData
Definition FMCS.h:131
RDKit::MCSResult
Definition FMCS.h:194
RDKit::detail::MCSParametersInternal
Definition FMCS.h:186