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  public:
24  MCSAtomCompareParameters() : MatchValences(false), MatchChiralTag(false) {}
25  };
26 
31  public:
32  MCSBondCompareParameters() : RingMatchesRingOnly(false), CompleteRingsOnly(false), MatchStereo(false) {}
33  };
34 
35  typedef bool (*MCSFinalMatchCheckFunction)(const short unsigned c1[], const short unsigned c2[],
36  const ROMol& mol1, const FMCS::Graph& query, const ROMol& mol2, const FMCS::Graph& target, const MCSParameters* p);
37  typedef bool (*MCSAtomCompareFunction)(const MCSAtomCompareParameters& p, const ROMol& mol1, unsigned int atom1, const ROMol& mol2, unsigned int atom2, void* userData);
38  typedef bool (*MCSBondCompareFunction)(const MCSBondCompareParameters& p, const ROMol& mol1, unsigned int bond1, const ROMol& mol2, unsigned int bond2, void* userData);
39 
40  // Some predefined functors:
41  bool MCSAtomCompareAny (const MCSAtomCompareParameters& p, const ROMol& mol1, unsigned int atom1, const ROMol& mol2, unsigned int atom2, void* userData);
42 
43  bool MCSAtomCompareElements (const MCSAtomCompareParameters& p, const ROMol& mol1, unsigned int atom1, const ROMol& mol2, unsigned int atom2, void* userData);
44  bool MCSAtomCompareIsotopes (const MCSAtomCompareParameters& p, const ROMol& mol1, unsigned int atom1, const ROMol& mol2, unsigned int atom2, void* userData);
45 
46  bool MCSBondCompareAny (const MCSBondCompareParameters& p, const ROMol& mol1, unsigned int bond1, const ROMol& mol2, unsigned int bond2, void* userData);
47  bool MCSBondCompareOrder (const MCSBondCompareParameters& p, const ROMol& mol1, unsigned int bond1, const ROMol& mol2, unsigned int bond2, void* userData); // ignore Aromatization
48  bool MCSBondCompareOrderExact(const MCSBondCompareParameters&p, const ROMol& mol1, unsigned int bond1, const ROMol& mol2, unsigned int bond2, void* userData);
49 
50  struct MCSProgressData {
51  unsigned NumAtoms;
52  unsigned NumBonds;
53  unsigned SeedProcessed;
54  public:
55  MCSProgressData() : NumAtoms(0), NumBonds(0), SeedProcessed(0) {}
56  };
57 
58  typedef bool (*MCSProgressCallback)(const MCSProgressData& stat, const MCSParameters &params, void* userData);
59  bool MCSProgressCallbackTimeout(const MCSProgressData& stat, const MCSParameters &params, void* userData);
60 
61  struct MCSParameters {
63  double Threshold;
64  unsigned Timeout; // in seconds
65  bool Verbose;
71  MCSProgressCallback ProgressCallback; // return false to interrupt execution
73  MCSFinalMatchCheckFunction FinalMatchChecker; // FinalChiralityCheckFunction() to check chirality
74  public:
75  MCSParameters(): MaximizeBonds(true)
76  , Threshold(1.0) // match to all
77  , Timeout(-1)
78  , Verbose(false)
79  , AtomTyper(MCSAtomCompareElements)
80  , BondTyper(MCSBondCompareOrder)
81  , CompareFunctionsUserData(0)
82  , ProgressCallback(MCSProgressCallbackTimeout)
83  , ProgressCallbackUserData(0)
84  , FinalMatchChecker(0)
85  {}
86  };
87 
88  struct MCSResult {
89  unsigned NumAtoms;
90  unsigned NumBonds;
91  std::string SmartsString;
92  bool Canceled; // interrupted by timeout or user defined progress callback. Contains valid current MCS !
93  public:
94  MCSResult() : NumAtoms(0), NumBonds(0), Canceled(false) {}
95  bool isCompleted()const {
96  return !Canceled;
97  }
98  };
99 
100  void parseMCSParametersJSON (const char* json, MCSParameters* params);
101 
102  MCSResult findMCS (const std::vector<ROMOL_SPTR>& mols, const MCSParameters* params=0);
103  MCSResult findMCS_P (const std::vector<ROMOL_SPTR>& mols, const char* params_json);
104 
105  typedef enum {
109  } AtomComparator;
110  typedef enum {
114  } BondComparator;
115  MCSResult findMCS (const std::vector<ROMOL_SPTR>& mols,
116  bool maximizeBonds,
117  double threshold=1.0,
118  unsigned timeout=3600,
119  bool verbose=false,
120  bool matchValences=false,
121  bool ringMatchesRingOnly=false,
122  bool completeRingsOnly=false,
123  bool matchChiralTag=false,
124  AtomComparator atomComp=AtomCompareElements,
125  BondComparator bondComp=BondCompareOrder);
126 
127 } // namespace RDKit
128 
MCSFinalMatchCheckFunction FinalMatchChecker
Definition: FMCS.h:73
unsigned NumAtoms
Definition: FMCS.h:89
double Threshold
Definition: FMCS.h:63
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:37
bool MCSAtomCompareElements(const MCSAtomCompareParameters &p, const ROMol &mol1, unsigned int atom1, const ROMol &mol2, unsigned int atom2, void *userData)
unsigned SeedProcessed
Definition: FMCS.h:53
unsigned NumAtoms
Definition: FMCS.h:51
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:105
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:105
MCSAtomCompareFunction AtomTyper
Definition: FMCS.h:68
void * CompareFunctionsUserData
Definition: FMCS.h:70
bool Canceled
Definition: FMCS.h:92
bool MCSBondCompareOrderExact(const MCSBondCompareParameters &p, const ROMol &mol1, unsigned int bond1, const ROMol &mol2, unsigned int bond2, void *userData)
MCSProgressCallback ProgressCallback
Definition: FMCS.h:71
bool MCSBondCompareOrder(const MCSBondCompareParameters &p, const ROMol &mol1, unsigned int bond1, const ROMol &mol2, unsigned int bond2, void *userData)
void * ProgressCallbackUserData
Definition: FMCS.h:72
MCSBondCompareFunction BondTyper
Definition: FMCS.h:69
bool isCompleted() const
Definition: FMCS.h:95
bool MaximizeBonds
Definition: FMCS.h:62
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:35
bool(* MCSProgressCallback)(const MCSProgressData &stat, const MCSParameters &params, void *userData)
Definition: FMCS.h:58
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:67
void parseMCSParametersJSON(const char *json, MCSParameters *params)
std::string SmartsString
Definition: FMCS.h:91
MCSResult findMCS_P(const std::vector< ROMOL_SPTR > &mols, const char *params_json)
unsigned Timeout
Definition: FMCS.h:64
BondComparator
Definition: FMCS.h:110
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:38
unsigned NumBonds
Definition: FMCS.h:90
MCSAtomCompareParameters AtomCompareParameters
Definition: FMCS.h:66
unsigned NumBonds
Definition: FMCS.h:52