RDKit: FMCS.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

FMCS.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 "Graph.h"
16 #ifndef RDKIT_WRAP_DECL
17 #define RDKIT_WRAP_DECL
18 #endif
19
20 namespace RDKit {
21 struct MCSParameters;
22
23 struct MCSAtomCompareParameters {
24 bool MatchValences;
25 bool MatchChiralTag;
26 bool MatchFormalCharge;
27
28 public:
29 MCSAtomCompareParameters()
30 : MatchValences(false), MatchChiralTag(false), MatchFormalCharge(false) {}
31 };
32
33 struct MCSBondCompareParameters {
34 bool RingMatchesRingOnly;
35 bool CompleteRingsOnly;
36 bool MatchStereo;
37
38 public:
39 MCSBondCompareParameters()
40 : RingMatchesRingOnly(false),
41 CompleteRingsOnly(false),
42 MatchStereo(false) {}
43 };
44
45 typedef bool (*MCSFinalMatchCheckFunction)(
46 const short unsigned c1[], const short unsigned c2[], const ROMol& mol1,
47 const FMCS::Graph& query, const ROMol& mol2, const FMCS::Graph& target,
48 const MCSParameters* p);
49 typedef bool (*MCSAtomCompareFunction)(const MCSAtomCompareParameters& p,
50 const ROMol& mol1, unsigned int atom1,
51 const ROMol& mol2, unsigned int atom2,
52 void* userData);
53 typedef bool (*MCSBondCompareFunction)(const MCSBondCompareParameters& p,
54 const ROMol& mol1, unsigned int bond1,
55 const ROMol& mol2, unsigned int bond2,
56 void* userData);
57
58 // Some predefined functors:
59 RDKIT_WRAP_DECL bool MCSAtomCompareAny(const MCSAtomCompareParameters& p,
60 const ROMol& mol1, unsigned int atom1,
61 const ROMol& mol2, unsigned int atom2,
62 void* userData);
63
64 RDKIT_WRAP_DECL bool MCSAtomCompareElements(const MCSAtomCompareParameters& p,
65 const ROMol& mol1,
66 unsigned int atom1,
67 const ROMol& mol2,
68 unsigned int atom2, void* userData);
69 RDKIT_WRAP_DECL bool MCSAtomCompareIsotopes(const MCSAtomCompareParameters& p,
70 const ROMol& mol1,
71 unsigned int atom1,
72 const ROMol& mol2,
73 unsigned int atom2, void* userData);
74
75 RDKIT_WRAP_DECL bool MCSBondCompareAny(const MCSBondCompareParameters& p,
76 const ROMol& mol1, unsigned int bond1,
77 const ROMol& mol2, unsigned int bond2,
78 void* userData);
79 RDKIT_WRAP_DECL bool MCSBondCompareOrder(
80 const MCSBondCompareParameters& p, const ROMol& mol1, unsigned int bond1,
81 const ROMol& mol2, unsigned int bond2,
82 void* userData); // ignore Aromatization
83 RDKIT_WRAP_DECL bool MCSBondCompareOrderExact(
84 const MCSBondCompareParameters& p, const ROMol& mol1, unsigned int bond1,
85 const ROMol& mol2, unsigned int bond2, void* userData);
86
87 struct MCSProgressData {
88 unsigned NumAtoms;
89 unsigned NumBonds;
90 unsigned SeedProcessed;
91
92 public:
93 MCSProgressData() : NumAtoms(0), NumBonds(0), SeedProcessed(0) {}
94 };
95
96 typedef bool (*MCSProgressCallback)(const MCSProgressData& stat,
97 const MCSParameters& params,
98 void* userData);
99 bool MCSProgressCallbackTimeout(const MCSProgressData& stat,
100 const MCSParameters& params, void* userData);
101
102 struct MCSParameters {
103 bool MaximizeBonds;
104 double Threshold;
105 unsigned Timeout; // in seconds
106 bool Verbose;
107 MCSAtomCompareParameters AtomCompareParameters;
108 MCSBondCompareParameters BondCompareParameters;
109 MCSAtomCompareFunction AtomTyper;
110 MCSBondCompareFunction BondTyper;
111 void* CompareFunctionsUserData;
112 MCSProgressCallback ProgressCallback; // return false to interrupt execution
113 void* ProgressCallbackUserData;
114 MCSFinalMatchCheckFunction
115 FinalMatchChecker; // FinalChiralityCheckFunction() to check chirality
116 std::string InitialSeed; // user defined or empty string (default)
117 public:
118 MCSParameters()
119 : MaximizeBonds(true),
120 Threshold(1.0) // match to all
121 ,
122 Timeout(-1),
123 Verbose(false),
124 AtomTyper(MCSAtomCompareElements),
125 BondTyper(MCSBondCompareOrder),
126 CompareFunctionsUserData(0),
127 ProgressCallback(0),
128 ProgressCallbackUserData(0),
129 FinalMatchChecker(0),
130 InitialSeed("") {}
131 };
132
133 struct MCSResult {
134 unsigned NumAtoms;
135 unsigned NumBonds;
136 std::string SmartsString;
137 bool Canceled; // interrupted by timeout or user defined progress callback.
138 // Contains valid current MCS !
139 public:
140 MCSResult() : NumAtoms(0), NumBonds(0), Canceled(false) {}
141 bool isCompleted() const { return !Canceled; }
142 };
143
144 void parseMCSParametersJSON(const char* json, MCSParameters* params);
145
146 MCSResult findMCS(const std::vector<ROMOL_SPTR>& mols,
147 const MCSParameters* params = 0);
148 MCSResult findMCS_P(const std::vector<ROMOL_SPTR>& mols,
149 const char* params_json);
150
151 typedef enum {
152 AtomCompareAny,
153 AtomCompareElements,
154 AtomCompareIsotopes
155 } AtomComparator;
156 typedef enum {
157 BondCompareAny,
158 BondCompareOrder,
159 BondCompareOrderExact
160 } BondComparator;
161 MCSResult findMCS(const std::vector<ROMOL_SPTR>& mols, bool maximizeBonds,
162 double threshold = 1.0, unsigned timeout = 3600,
163 bool verbose = false, bool matchValences = false,
164 bool ringMatchesRingOnly = false,
165 bool completeRingsOnly = false, bool matchChiralTag = false,
166 AtomComparator atomComp = AtomCompareElements,
167 BondComparator bondComp = BondCompareOrder);
168
169 } // namespace RDKit
RDKit::MCSBondCompareAny
RDKIT_WRAP_DECL bool MCSBondCompareAny(const MCSBondCompareParameters &p, const ROMol &mol1, unsigned int bond1, const ROMol &mol2, unsigned int bond2, void *userData)
RDKit::MCSParameters::FinalMatchChecker
MCSFinalMatchCheckFunction FinalMatchChecker
Definition: FMCS.h:115
RDKit::MCSBondCompareOrder
RDKIT_WRAP_DECL bool MCSBondCompareOrder(const MCSBondCompareParameters &p, const ROMol &mol1, unsigned int bond1, const ROMol &mol2, unsigned int bond2, void *userData)
RDKit::MCSResult::NumAtoms
unsigned NumAtoms
Definition: FMCS.h:134
RDKit::MCSBondCompareParameters::RingMatchesRingOnly
bool RingMatchesRingOnly
Definition: FMCS.h:34
RDKit::MCSParameters::Threshold
double Threshold
Definition: FMCS.h:104
RDKit::MCSAtomCompareParameters
Definition: FMCS.h:23
RDKit::MCSBondCompareParameters
Definition: FMCS.h:33
RDKit::MCSParameters::Verbose
bool Verbose
Definition: FMCS.h:106
RDKit::MCSProgressData
Definition: FMCS.h:87
RDKit::MCSAtomCompareFunction
bool(* MCSAtomCompareFunction)(const MCSAtomCompareParameters &p, const ROMol &mol1, unsigned int atom1, const ROMol &mol2, unsigned int atom2, void *userData)
Definition: FMCS.h:49
RDKit::MCSProgressData::SeedProcessed
unsigned SeedProcessed
Definition: FMCS.h:90
RDKit::MCSProgressData::NumAtoms
unsigned NumAtoms
Definition: FMCS.h:88
RDKit::BondCompareOrder
Definition: FMCS.h:158
RDKit::MCSBondCompareParameters::MCSBondCompareParameters
MCSBondCompareParameters()
Definition: FMCS.h:39
RDKit::AtomCompareIsotopes
Definition: FMCS.h:154
RDKit::MCSBondCompareParameters::CompleteRingsOnly
bool CompleteRingsOnly
Definition: FMCS.h:35
RDKit::AtomComparator
AtomComparator
Definition: FMCS.h:151
RDKit::ROMol
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:103
RDKit::MCSParameters::AtomTyper
MCSAtomCompareFunction AtomTyper
Definition: FMCS.h:109
RDKIT_WRAP_DECL
#define RDKIT_WRAP_DECL
Definition: FMCS.h:17
RDKit::MCSParameters::CompareFunctionsUserData
void * CompareFunctionsUserData
Definition: FMCS.h:111
RDKit::MCSAtomCompareParameters::MatchFormalCharge
bool MatchFormalCharge
Definition: FMCS.h:26
RDKit::BondCompareOrderExact
Definition: FMCS.h:159
RDKit::MCSResult::Canceled
bool Canceled
Definition: FMCS.h:137
RDKit::MCSParameters::ProgressCallback
MCSProgressCallback ProgressCallback
Definition: FMCS.h:112
RDKit::MCSParameters::ProgressCallbackUserData
void * ProgressCallbackUserData
Definition: FMCS.h:113
RDKit::MCSParameters::BondTyper
MCSBondCompareFunction BondTyper
Definition: FMCS.h:110
RDKit::MCSResult::isCompleted
bool isCompleted() const
Definition: FMCS.h:141
RDKit::FMCS::Graph
Definition: Graph.h:22
RDKit::BondCompareAny
Definition: FMCS.h:157
RDKit::MCSAtomCompareParameters::MatchValences
bool MatchValences
Definition: FMCS.h:24
RDKit::MCSParameters::MaximizeBonds
bool MaximizeBonds
Definition: FMCS.h:103
RDKit::MCSFinalMatchCheckFunction
bool(* MCSFinalMatchCheckFunction)(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)
Definition: FMCS.h:45
RDKit::MCSProgressCallback
bool(* MCSProgressCallback)(const MCSProgressData &stat, const MCSParameters &params, void *userData)
Definition: FMCS.h:96
RDKit
Std stuff.
Definition: Atom.h:29
RDKit::MCSProgressCallbackTimeout
bool MCSProgressCallbackTimeout(const MCSProgressData &stat, const MCSParameters &params, void *userData)
RDKit::MCSAtomCompareIsotopes
RDKIT_WRAP_DECL bool MCSAtomCompareIsotopes(const MCSAtomCompareParameters &p, const ROMol &mol1, unsigned int atom1, const ROMol &mol2, unsigned int atom2, void *userData)
RDKit::MCSProgressData::MCSProgressData
MCSProgressData()
Definition: FMCS.h:93
RDKit::MCSAtomCompareParameters::MCSAtomCompareParameters
MCSAtomCompareParameters()
Definition: FMCS.h:29
RDKit::MCSResult::MCSResult
MCSResult()
Definition: FMCS.h:140
RDKit::MCSParameters::BondCompareParameters
MCSBondCompareParameters BondCompareParameters
Definition: FMCS.h:108
RDKit::parseMCSParametersJSON
void parseMCSParametersJSON(const char *json, MCSParameters *params)
Graph.h
RDKit::MCSResult::SmartsString
std::string SmartsString
Definition: FMCS.h:136
RDKit::MCSAtomCompareElements
RDKIT_WRAP_DECL bool MCSAtomCompareElements(const MCSAtomCompareParameters &p, const ROMol &mol1, unsigned int atom1, const ROMol &mol2, unsigned int atom2, void *userData)
RDKit::MCSParameters
Definition: FMCS.h:102
RDKit::findMCS_P
MCSResult findMCS_P(const std::vector< ROMOL_SPTR > &mols, const char *params_json)
RDKit::MCSParameters::Timeout
unsigned Timeout
Definition: FMCS.h:105
RDKit::BondComparator
BondComparator
Definition: FMCS.h:156
RDKit::MCSAtomCompareAny
RDKIT_WRAP_DECL bool MCSAtomCompareAny(const MCSAtomCompareParameters &p, const ROMol &mol1, unsigned int atom1, const ROMol &mol2, unsigned int atom2, void *userData)
RDKit::findMCS
MCSResult findMCS(const std::vector< ROMOL_SPTR > &mols, const MCSParameters *params=0)
RDKit::AtomCompareElements
Definition: FMCS.h:153
RDKit::MCSBondCompareFunction
bool(* MCSBondCompareFunction)(const MCSBondCompareParameters &p, const ROMol &mol1, unsigned int bond1, const ROMol &mol2, unsigned int bond2, void *userData)
Definition: FMCS.h:53
RDKit::MCSResult
Definition: FMCS.h:133
RDKit::MCSBondCompareParameters::MatchStereo
bool MatchStereo
Definition: FMCS.h:36
RDKit::MCSBondCompareOrderExact
RDKIT_WRAP_DECL bool MCSBondCompareOrderExact(const MCSBondCompareParameters &p, const ROMol &mol1, unsigned int bond1, const ROMol &mol2, unsigned int bond2, void *userData)
RDKit::MCSAtomCompareParameters::MatchChiralTag
bool MatchChiralTag
Definition: FMCS.h:25
RDKit::MCSResult::NumBonds
unsigned NumBonds
Definition: FMCS.h:135
RDKit::AtomCompareAny
Definition: FMCS.h:152
RDKit::MCSParameters::AtomCompareParameters
MCSAtomCompareParameters AtomCompareParameters
Definition: FMCS.h:107
RDKit::MCSParameters::InitialSeed
std::string InitialSeed
Definition: FMCS.h:116
RDKit::MCSProgressData::NumBonds
unsigned NumBonds
Definition: FMCS.h:89
RDKit::MCSParameters::MCSParameters
MCSParameters()
Definition: FMCS.h:118