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