RDKit: FMCS.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
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#include <RDGeneral/export.h>
11#pragma once
12#include <vector>
13#include <string>
14#include <stdexcept>
15#include "../RDKitBase.h"
16#include "Graph.h"
17
18namespace RDKit {
19
20struct MCSParameters;
21
22 typedef enum {
23 AtomCompareAny,
24 AtomCompareElements,
25 AtomCompareIsotopes,
26 AtomCompareAnyHeavyAtom
27} AtomComparator;
28
29 typedef enum {
30 BondCompareAny,
31 BondCompareOrder,
32 BondCompareOrderExact
33} BondComparator;
34
35 typedef enum {
36 IgnoreRingFusion,
37 PermissiveRingFusion,
38 StrictRingFusion
39} RingComparator;
40
41 struct RDKIT_FMCS_EXPORT MCSAtomCompareParameters {
42 bool MatchValences = false;
43 bool MatchChiralTag = false;
44 bool MatchFormalCharge = false;
45 bool RingMatchesRingOnly = false;
46 bool CompleteRingsOnly = false;
47 bool MatchIsotope = false;
48 double MaxDistance = -1.0;
49};
50
51 struct RDKIT_FMCS_EXPORT MCSBondCompareParameters {
52 bool RingMatchesRingOnly = false;
53 bool CompleteRingsOnly = false;
54 bool MatchFusedRings = false;
55 bool MatchFusedRingsStrict = false;
56 bool MatchStereo = false;
57};
58
59 typedef bool (*MCSAtomCompareFunction)(const MCSAtomCompareParameters &,
60 const ROMol &, unsigned int,
61 const ROMol &, unsigned int, void *);
62 typedef bool (*MCSBondCompareFunction)(const MCSBondCompareParameters &,
63 const ROMol &, unsigned int,
64 const ROMol &, unsigned int, void *);
65 typedef bool (*MCSAcceptanceFunction)(const ROMol &, const ROMol &,
66 const std::vector<std::pair<int, int>> &,
67 const std::vector<std::pair<int, int>> &,
68 const MCSParameters *);
69 typedef bool (*MCSFinalMatchCheckFunction)(const std::uint32_t[],
70 const std::uint32_t[], const ROMol &,
71 const FMCS::Graph &, const ROMol &,
72 const FMCS::Graph &,
73 const MCSParameters *);
74
75// Some predefined functors:
76 RDKIT_FMCS_EXPORT bool checkAtomRingMatch(const MCSAtomCompareParameters &p,
77 const ROMol &mol1, unsigned int atom1,
78 const ROMol &mol2,
79 unsigned int atom2);
80 RDKIT_FMCS_EXPORT bool checkAtomCharge(const MCSAtomCompareParameters &p,
81 const ROMol &mol1, unsigned int atom1,
82 const ROMol &mol2, unsigned int atom2);
83 RDKIT_FMCS_EXPORT bool checkAtomChirality(const MCSAtomCompareParameters &p,
84 const ROMol &mol1, unsigned int atom1,
85 const ROMol &mol2,
86 unsigned int atom2);
87 RDKIT_FMCS_EXPORT bool checkAtomDistance(const MCSAtomCompareParameters &p,
88 const ROMol &mol1, unsigned int atom1,
89 const ROMol &mol2, unsigned int atom2);
90
91 RDKIT_FMCS_EXPORT bool MCSAtomCompareAny(const MCSAtomCompareParameters &p,
92 const ROMol &mol1, unsigned int atom1,
93 const ROMol &mol2, unsigned int atom2,
94 void *userData);
95 RDKIT_FMCS_EXPORT bool MCSAtomCompareAnyHeavyAtom(
96 const MCSAtomCompareParameters &p, const ROMol &mol1, unsigned int atom1,
97 const ROMol &mol2, unsigned int atom2, void *userData);
98
99 RDKIT_FMCS_EXPORT bool MCSAtomCompareElements(
100 const MCSAtomCompareParameters &p, const ROMol &mol1, unsigned int atom1,
101 const ROMol &mol2, unsigned int atom2, void *userData);
102 RDKIT_FMCS_EXPORT bool MCSAtomCompareIsotopes(
103 const MCSAtomCompareParameters &p, const ROMol &mol1, unsigned int atom1,
104 const ROMol &mol2, unsigned int atom2, void *userData);
105
106 RDKIT_FMCS_EXPORT bool checkBondStereo(const MCSBondCompareParameters &p,
107 const ROMol &mol1, unsigned int bond1,
108 const ROMol &mol2, unsigned int bond2);
109
110 RDKIT_FMCS_EXPORT bool havePairOfCompatibleRings(
111 const MCSBondCompareParameters &p, const ROMol &mol1, unsigned int bond1,
112 const ROMol &mol2, unsigned int bond2);
113
114 RDKIT_FMCS_EXPORT bool checkBondRingMatch(const MCSBondCompareParameters &p,
115 const ROMol &mol1, unsigned int bond1,
116 const ROMol &mol2,
117 unsigned int bond2);
118
119 RDKIT_FMCS_EXPORT bool MCSBondCompareAny(const MCSBondCompareParameters &p,
120 const ROMol &mol1, unsigned int bond1,
121 const ROMol &mol2, unsigned int bond2,
122 void *userData);
123 RDKIT_FMCS_EXPORT bool MCSBondCompareOrder(
124 const MCSBondCompareParameters &p, const ROMol &mol1, unsigned int bond1,
125 const ROMol &mol2, unsigned int bond2,
126 void *userData); // ignore Aromatization
127 RDKIT_FMCS_EXPORT bool MCSBondCompareOrderExact(
128 const MCSBondCompareParameters &p, const ROMol &mol1, unsigned int bond1,
129 const ROMol &mol2, unsigned int bond2, void *userData);
130
131 struct RDKIT_FMCS_EXPORT MCSProgressData {
132 unsigned int NumAtoms{0};
133 unsigned int NumBonds{0};
134 unsigned int SeedProcessed{0};
135
136 public:
137 MCSProgressData() {}
138};
139
140 typedef bool (*MCSProgressCallback)(const MCSProgressData &stat,
141 const MCSParameters &params,
142 void *userData);
143 RDKIT_FMCS_EXPORT bool MCSProgressCallbackTimeout(const MCSProgressData &stat,
144 const MCSParameters &params,
145 void *userData);
146
147 struct RDKIT_FMCS_EXPORT MCSParameters {
148 MCSParameters() {}
149 MCSParameters(const MCSParameters *other) : MCSParameters() {
150 if (other) {
151 *this = *other;
152 }
153 }
154 MCSParameters(const MCSParameters &other) = default;
155 MCSParameters &operator=(const MCSParameters &other) = default;
156 virtual ~MCSParameters() {}
157 bool StoreAll = false;
158 bool MaximizeBonds = true;
159 double Threshold = 1.0; // match all molecules
160 unsigned int Timeout = 0; // in seconds
161 bool Verbose = false;
162 MCSAtomCompareParameters AtomCompareParameters;
163 MCSBondCompareParameters BondCompareParameters;
164 MCSAtomCompareFunction AtomTyper = MCSAtomCompareElements;
165 MCSBondCompareFunction BondTyper = MCSBondCompareOrder;
166 void *CompareFunctionsUserData = nullptr;
167 MCSProgressCallback ProgressCallback =
168 nullptr; // return false to interrupt execution
169 void *ProgressCallbackUserData = nullptr;
170 // FinalMatchCheckFunction() to accept/reject a growing MCS candidate based on
171 // user-defined criteria
172 MCSFinalMatchCheckFunction FinalMatchChecker = nullptr;
173 void *FinalMatchCheckerUserData = nullptr;
174 // ShouldAcceptMCS() to accept/reject a fully-grown MCS candidate based on
175 // user-defined criteria
176 MCSAcceptanceFunction ShouldAcceptMCS = nullptr;
177 void *ShouldAcceptMCSUserData = nullptr;
178 std::string InitialSeed = ""; // user defined or empty string (default)
179 void setMCSAtomTyperFromEnum(AtomComparator atomComp);
180 void setMCSAtomTyperFromConstChar(const char *atomComp);
181 void setMCSBondTyperFromEnum(BondComparator bondComp);
182 void setMCSBondTyperFromConstChar(const char *bondComp);
183};
184
185 namespace detail {
186 struct MCSParametersInternal : public MCSParameters {
187 MCSParametersInternal() {}
188 ~MCSParametersInternal() override {}
189 MCSParametersInternal(const MCSParameters *params);
190 MCSFinalMatchCheckFunction UserFinalMatchChecker = nullptr;
191};
192} // end namespace detail
193
194 struct RDKIT_FMCS_EXPORT MCSResult {
195 unsigned int NumAtoms{0};
196 unsigned int NumBonds{0};
197 std::string SmartsString;
198 bool Canceled{false}; // interrupted by timeout or user defined progress
199 // callback. Contains valid current MCS !
200 ROMOL_SPTR QueryMol;
201 std::map<std::string, ROMOL_SPTR> DegenerateSmartsQueryMolDict;
202
203 public:
204 MCSResult() {}
205 bool isCompleted() const { return !Canceled; }
206};
207
208 RDKIT_FMCS_EXPORT void parseMCSParametersJSON(const char *json,
209 MCSParameters *params);
210
211 RDKIT_FMCS_EXPORT MCSResult findMCS(const std::vector<ROMOL_SPTR> &mols,
212 const MCSParameters *params = nullptr);
213 RDKIT_FMCS_EXPORT MCSResult findMCS_P(const std::vector<ROMOL_SPTR> &mols,
214 const char *params_json);
215
216 RDKIT_FMCS_EXPORT MCSResult findMCS(
217 const std::vector<ROMOL_SPTR> &mols, bool maximizeBonds, double threshold,
218 unsigned int timeout, bool verbose, bool matchValences,
219 bool ringMatchesRingOnly, bool completeRingsOnly, bool matchChiralTag,
220 AtomComparator atomComp, BondComparator bondComp, RingComparator ringComp);
221 RDKIT_FMCS_EXPORT MCSResult findMCS(
222 const std::vector<ROMOL_SPTR> &mols, bool maximizeBonds,
223 double threshold = 1.0, unsigned int timeout = 3600, bool verbose = false,
224 bool matchValences = false, bool ringMatchesRingOnly = false,
225 bool completeRingsOnly = false, bool matchChiralTag = false,
226 AtomComparator atomComp = AtomCompareElements,
227 BondComparator bondComp = BondCompareOrder);
228
229} // namespace RDKit
Graph.h
RDKitBase.h
pulls in the core RDKit functionality
RDKit::FMCS::Graph
Definition Graph.h:26
RDKit::ROMol
Definition ROMol.h:199
export.h
RDKIT_FMCS_EXPORT
#define RDKIT_FMCS_EXPORT
Definition export.h:169
RDKit::detail
Definition FMCS.h:185
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::findMCS_P
RDKIT_FMCS_EXPORT MCSResult findMCS_P(const std::vector< ROMOL_SPTR > &mols, const char *params_json)
RDKit::MCSAtomCompareAnyHeavyAtom
RDKIT_FMCS_EXPORT bool MCSAtomCompareAnyHeavyAtom(const MCSAtomCompareParameters &p, const ROMol &mol1, unsigned int atom1, const ROMol &mol2, unsigned int atom2, void *userData)
RDKit::AtomComparator
AtomComparator
Definition FMCS.h:22
RDKit::AtomCompareElements
@ AtomCompareElements
Definition FMCS.h:24
RDKit::AtomCompareAnyHeavyAtom
@ AtomCompareAnyHeavyAtom
Definition FMCS.h:26
RDKit::AtomCompareAny
@ AtomCompareAny
Definition FMCS.h:23
RDKit::AtomCompareIsotopes
@ AtomCompareIsotopes
Definition FMCS.h:25
RDKit::BondComparator
BondComparator
Definition FMCS.h:29
RDKit::BondCompareOrderExact
@ BondCompareOrderExact
Definition FMCS.h:32
RDKit::BondCompareAny
@ BondCompareAny
Definition FMCS.h:30
RDKit::BondCompareOrder
@ BondCompareOrder
Definition FMCS.h:31
RDKit::checkBondRingMatch
RDKIT_FMCS_EXPORT bool checkBondRingMatch(const MCSBondCompareParameters &p, const ROMol &mol1, unsigned int bond1, const ROMol &mol2, unsigned int bond2)
RDKit::MCSAtomCompareElements
RDKIT_FMCS_EXPORT bool MCSAtomCompareElements(const MCSAtomCompareParameters &p, const ROMol &mol1, unsigned int atom1, const ROMol &mol2, unsigned int atom2, void *userData)
RDKit::MCSFinalMatchCheckFunction
bool(* MCSFinalMatchCheckFunction)(const std::uint32_t[], const std::uint32_t[], const ROMol &, const FMCS::Graph &, const ROMol &, const FMCS::Graph &, const MCSParameters *)
Definition FMCS.h:69
RDKit::checkAtomDistance
RDKIT_FMCS_EXPORT bool checkAtomDistance(const MCSAtomCompareParameters &p, const ROMol &mol1, unsigned int atom1, const ROMol &mol2, unsigned int atom2)
RDKit::checkBondStereo
RDKIT_FMCS_EXPORT bool checkBondStereo(const MCSBondCompareParameters &p, const ROMol &mol1, unsigned int bond1, const ROMol &mol2, unsigned int bond2)
RDKit::parseMCSParametersJSON
RDKIT_FMCS_EXPORT void parseMCSParametersJSON(const char *json, MCSParameters *params)
RDKit::MCSBondCompareFunction
bool(* MCSBondCompareFunction)(const MCSBondCompareParameters &, const ROMol &, unsigned int, const ROMol &, unsigned int, void *)
Definition FMCS.h:62
RDKit::MCSBondCompareAny
RDKIT_FMCS_EXPORT bool MCSBondCompareAny(const MCSBondCompareParameters &p, const ROMol &mol1, unsigned int bond1, const ROMol &mol2, unsigned int bond2, void *userData)
RDKit::findMCS
RDKIT_FMCS_EXPORT MCSResult findMCS(const std::vector< ROMOL_SPTR > &mols, const MCSParameters *params=nullptr)
RDKit::MCSAtomCompareAny
RDKIT_FMCS_EXPORT bool MCSAtomCompareAny(const MCSAtomCompareParameters &p, const ROMol &mol1, unsigned int atom1, const ROMol &mol2, unsigned int atom2, void *userData)
RDKit::MCSAtomCompareFunction
bool(* MCSAtomCompareFunction)(const MCSAtomCompareParameters &, const ROMol &, unsigned int, const ROMol &, unsigned int, void *)
Definition FMCS.h:59
RDKit::MCSBondCompareOrder
RDKIT_FMCS_EXPORT bool MCSBondCompareOrder(const MCSBondCompareParameters &p, const ROMol &mol1, unsigned int bond1, const ROMol &mol2, unsigned int bond2, void *userData)
RDKit::checkAtomRingMatch
RDKIT_FMCS_EXPORT bool checkAtomRingMatch(const MCSAtomCompareParameters &p, const ROMol &mol1, unsigned int atom1, const ROMol &mol2, unsigned int atom2)
RDKit::RingComparator
RingComparator
Definition FMCS.h:35
RDKit::StrictRingFusion
@ StrictRingFusion
Definition FMCS.h:38
RDKit::IgnoreRingFusion
@ IgnoreRingFusion
Definition FMCS.h:36
RDKit::PermissiveRingFusion
@ PermissiveRingFusion
Definition FMCS.h:37
RDKit::checkAtomCharge
RDKIT_FMCS_EXPORT bool checkAtomCharge(const MCSAtomCompareParameters &p, const ROMol &mol1, unsigned int atom1, const ROMol &mol2, unsigned int atom2)
RDKit::MCSAtomCompareIsotopes
RDKIT_FMCS_EXPORT bool MCSAtomCompareIsotopes(const MCSAtomCompareParameters &p, const ROMol &mol1, unsigned int atom1, const ROMol &mol2, unsigned int atom2, void *userData)
RDKit::ROMOL_SPTR
boost::shared_ptr< ROMol > ROMOL_SPTR
Definition ChemTransforms.h:22
RDKit::havePairOfCompatibleRings
RDKIT_FMCS_EXPORT bool havePairOfCompatibleRings(const MCSBondCompareParameters &p, const ROMol &mol1, unsigned int bond1, const ROMol &mol2, unsigned int bond2)
RDKit::checkAtomChirality
RDKIT_FMCS_EXPORT bool checkAtomChirality(const MCSAtomCompareParameters &p, const ROMol &mol1, unsigned int atom1, const ROMol &mol2, unsigned int atom2)
RDKit::MCSProgressCallback
bool(* MCSProgressCallback)(const MCSProgressData &stat, const MCSParameters &params, void *userData)
Definition FMCS.h:140
RDKit::MCSProgressCallbackTimeout
RDKIT_FMCS_EXPORT bool MCSProgressCallbackTimeout(const MCSProgressData &stat, const MCSParameters &params, void *userData)
RDKit::MCSAcceptanceFunction
bool(* MCSAcceptanceFunction)(const ROMol &, const ROMol &, const std::vector< std::pair< int, int > > &, const std::vector< std::pair< int, int > > &, const MCSParameters *)
Definition FMCS.h:65
RDKit::MCSBondCompareOrderExact
RDKIT_FMCS_EXPORT bool MCSBondCompareOrderExact(const MCSBondCompareParameters &p, const ROMol &mol1, unsigned int bond1, const ROMol &mol2, unsigned int bond2, void *userData)
RDKit::MCSAtomCompareParameters
Definition FMCS.h:41
RDKit::MCSAtomCompareParameters::MatchChiralTag
bool MatchChiralTag
Definition FMCS.h:43
RDKit::MCSAtomCompareParameters::MaxDistance
double MaxDistance
Definition FMCS.h:48
RDKit::MCSAtomCompareParameters::MatchValences
bool MatchValences
Definition FMCS.h:42
RDKit::MCSAtomCompareParameters::MatchIsotope
bool MatchIsotope
Definition FMCS.h:47
RDKit::MCSAtomCompareParameters::MatchFormalCharge
bool MatchFormalCharge
Definition FMCS.h:44
RDKit::MCSAtomCompareParameters::CompleteRingsOnly
bool CompleteRingsOnly
Definition FMCS.h:46
RDKit::MCSAtomCompareParameters::RingMatchesRingOnly
bool RingMatchesRingOnly
Definition FMCS.h:45
RDKit::MCSBondCompareParameters
Definition FMCS.h:51
RDKit::MCSBondCompareParameters::MatchFusedRings
bool MatchFusedRings
Definition FMCS.h:54
RDKit::MCSBondCompareParameters::RingMatchesRingOnly
bool RingMatchesRingOnly
Definition FMCS.h:52
RDKit::MCSBondCompareParameters::MatchFusedRingsStrict
bool MatchFusedRingsStrict
Definition FMCS.h:55
RDKit::MCSBondCompareParameters::CompleteRingsOnly
bool CompleteRingsOnly
Definition FMCS.h:53
RDKit::MCSBondCompareParameters::MatchStereo
bool MatchStereo
Definition FMCS.h:56
RDKit::MCSParameters
Definition FMCS.h:147
RDKit::MCSParameters::ProgressCallbackUserData
void * ProgressCallbackUserData
Definition FMCS.h:169
RDKit::MCSParameters::StoreAll
bool StoreAll
Definition FMCS.h:157
RDKit::MCSParameters::InitialSeed
std::string InitialSeed
Definition FMCS.h:178
RDKit::MCSParameters::MCSParameters
MCSParameters(const MCSParameters *other)
Definition FMCS.h:149
RDKit::MCSParameters::setMCSBondTyperFromEnum
void setMCSBondTyperFromEnum(BondComparator bondComp)
RDKit::MCSParameters::FinalMatchChecker
MCSFinalMatchCheckFunction FinalMatchChecker
Definition FMCS.h:172
RDKit::MCSParameters::ShouldAcceptMCSUserData
void * ShouldAcceptMCSUserData
Definition FMCS.h:177
RDKit::MCSParameters::setMCSBondTyperFromConstChar
void setMCSBondTyperFromConstChar(const char *bondComp)
RDKit::MCSParameters::~MCSParameters
virtual ~MCSParameters()
Definition FMCS.h:156
RDKit::MCSParameters::AtomTyper
MCSAtomCompareFunction AtomTyper
Definition FMCS.h:164
RDKit::MCSParameters::MCSParameters
MCSParameters(const MCSParameters &other)=default
RDKit::MCSParameters::FinalMatchCheckerUserData
void * FinalMatchCheckerUserData
Definition FMCS.h:173
RDKit::MCSParameters::operator=
MCSParameters & operator=(const MCSParameters &other)=default
RDKit::MCSParameters::MCSParameters
MCSParameters()
Definition FMCS.h:148
RDKit::MCSParameters::MaximizeBonds
bool MaximizeBonds
Definition FMCS.h:158
RDKit::MCSParameters::Timeout
unsigned int Timeout
Definition FMCS.h:160
RDKit::MCSParameters::Threshold
double Threshold
Definition FMCS.h:159
RDKit::MCSParameters::BondTyper
MCSBondCompareFunction BondTyper
Definition FMCS.h:165
RDKit::MCSParameters::setMCSAtomTyperFromConstChar
void setMCSAtomTyperFromConstChar(const char *atomComp)
RDKit::MCSParameters::Verbose
bool Verbose
Definition FMCS.h:161
RDKit::MCSParameters::setMCSAtomTyperFromEnum
void setMCSAtomTyperFromEnum(AtomComparator atomComp)
RDKit::MCSParameters::ShouldAcceptMCS
MCSAcceptanceFunction ShouldAcceptMCS
Definition FMCS.h:176
RDKit::MCSParameters::AtomCompareParameters
MCSAtomCompareParameters AtomCompareParameters
Definition FMCS.h:162
RDKit::MCSParameters::CompareFunctionsUserData
void * CompareFunctionsUserData
Definition FMCS.h:166
RDKit::MCSParameters::ProgressCallback
MCSProgressCallback ProgressCallback
Definition FMCS.h:167
RDKit::MCSParameters::BondCompareParameters
MCSBondCompareParameters BondCompareParameters
Definition FMCS.h:163
RDKit::MCSProgressData
Definition FMCS.h:131
RDKit::MCSProgressData::NumAtoms
unsigned int NumAtoms
Definition FMCS.h:132
RDKit::MCSProgressData::NumBonds
unsigned int NumBonds
Definition FMCS.h:133
RDKit::MCSProgressData::SeedProcessed
unsigned int SeedProcessed
Definition FMCS.h:134
RDKit::MCSProgressData::MCSProgressData
MCSProgressData()
Definition FMCS.h:137
RDKit::MCSResult
Definition FMCS.h:194
RDKit::MCSResult::NumBonds
unsigned int NumBonds
Definition FMCS.h:196
RDKit::MCSResult::QueryMol
ROMOL_SPTR QueryMol
Definition FMCS.h:200
RDKit::MCSResult::SmartsString
std::string SmartsString
Definition FMCS.h:197
RDKit::MCSResult::Canceled
bool Canceled
Definition FMCS.h:198
RDKit::MCSResult::DegenerateSmartsQueryMolDict
std::map< std::string, ROMOL_SPTR > DegenerateSmartsQueryMolDict
Definition FMCS.h:201
RDKit::MCSResult::NumAtoms
unsigned int NumAtoms
Definition FMCS.h:195
RDKit::MCSResult::isCompleted
bool isCompleted() const
Definition FMCS.h:205
RDKit::MCSResult::MCSResult
MCSResult()
Definition FMCS.h:204
RDKit::detail::MCSParametersInternal::MCSParametersInternal
MCSParametersInternal()
Definition FMCS.h:187
RDKit::detail::MCSParametersInternal::MCSParametersInternal
MCSParametersInternal(const MCSParameters *params)
RDKit::detail::MCSParametersInternal::~MCSParametersInternal
~MCSParametersInternal() override
Definition FMCS.h:188
RDKit::detail::MCSParametersInternal::UserFinalMatchChecker
MCSFinalMatchCheckFunction UserFinalMatchChecker
Definition FMCS.h:190