File: FMCS.cpp

package info (click to toggle)
rdkit 202503.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 220,160 kB
  • sloc: cpp: 399,240; python: 77,453; ansic: 25,517; java: 8,173; javascript: 4,005; sql: 2,389; yacc: 1,565; lex: 1,263; cs: 1,081; makefile: 580; xml: 229; fortran: 183; sh: 105
file content (1017 lines) | stat: -rw-r--r-- 38,806 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
//
//  Copyright (C) 2014 Novartis Institutes for BioMedical Research
//
//   @@ All Rights Reserved @@
//  This file is part of the RDKit.
//  The contents are covered by the terms of the BSD license
//  which is included in the file license.txt, found at the root
//  of the RDKit source tree.
//
#include <list>
#include <algorithm>
#include <cmath>

#include <RDGeneral/BoostStartInclude.h>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <RDGeneral/BoostEndInclude.h>

#include <iostream>
#include <sstream>
#include "SubstructMatchCustom.h"
#include "MaximumCommonSubgraph.h"
#include <GraphMol/QueryOps.h>

namespace RDKit {

namespace {
struct cmpCStr {
  bool operator()(const char *a, const char *b) const {
    return std::strcmp(a, b) < 0;
  }
};
}  // namespace

void MCSParameters::setMCSAtomTyperFromEnum(AtomComparator atomComp) {
  switch (atomComp) {
    case AtomCompareAny:
      AtomTyper = MCSAtomCompareAny;
      break;
    case AtomCompareElements:
      AtomTyper = MCSAtomCompareElements;
      break;
    case AtomCompareIsotopes:
      AtomTyper = MCSAtomCompareIsotopes;
      break;
    case AtomCompareAnyHeavyAtom:
      AtomTyper = MCSAtomCompareAnyHeavyAtom;
      break;
    default:
      throw ValueErrorException("Unknown AtomComparator");
  }
}

void MCSParameters::setMCSAtomTyperFromConstChar(const char *atomComp) {
  PRECONDITION(atomComp, "atomComp must not be NULL");
  static const std::map<const char *, AtomComparator, cmpCStr>
      atomCompStringToEnum = {{"Any", AtomCompareAny},
                              {"Elements", AtomCompareElements},
                              {"Isotopes", AtomCompareIsotopes},
                              {"AnyHeavy", AtomCompareAnyHeavyAtom}};
  const auto it = atomCompStringToEnum.find(atomComp);
  // we accept "def" as a no-op
  if (it != atomCompStringToEnum.end()) {
    setMCSAtomTyperFromEnum(it->second);
  }
}

void MCSParameters::setMCSBondTyperFromEnum(BondComparator bondComp) {
  switch (bondComp) {
    case BondCompareAny:
      BondTyper = MCSBondCompareAny;
      break;
    case BondCompareOrder:
      BondTyper = MCSBondCompareOrder;
      break;
    case BondCompareOrderExact:
      BondTyper = MCSBondCompareOrderExact;
      break;
    default:
      throw ValueErrorException("Unknown BondComparator");
  }
}

void MCSParameters::setMCSBondTyperFromConstChar(const char *bondComp) {
  PRECONDITION(bondComp, "bondComp must not be NULL");
  static const std::map<const char *, BondComparator, cmpCStr>
      bondCompStringToEnum = {{"Any", BondCompareAny},
                              {"Order", BondCompareOrder},
                              {"OrderExact", BondCompareOrderExact}};
  const auto it = bondCompStringToEnum.find(bondComp);
  // we accept "def" as a no-op
  if (it != bondCompStringToEnum.end()) {
    setMCSBondTyperFromEnum(it->second);
  }
}

void parseMCSParametersJSON(const char *json, MCSParameters *params) {
  if (!params || !json || !strlen(json)) {
    return;
  }
  std::istringstream ss;
  ss.str(json);
  boost::property_tree::ptree pt;
  boost::property_tree::read_json(ss, pt);

  auto &p = *params;
  p.MaximizeBonds = pt.get<bool>("MaximizeBonds", p.MaximizeBonds);
  p.Threshold = pt.get<double>("Threshold", p.Threshold);
  p.Timeout = pt.get<unsigned int>("Timeout", p.Timeout);
  p.AtomCompareParameters.MatchValences =
      pt.get<bool>("MatchValences", p.AtomCompareParameters.MatchValences);
  p.AtomCompareParameters.MatchChiralTag =
      pt.get<bool>("MatchChiralTag", p.AtomCompareParameters.MatchChiralTag);
  p.AtomCompareParameters.MatchFormalCharge = pt.get<bool>(
      "MatchFormalCharge", p.AtomCompareParameters.MatchFormalCharge);
  p.AtomCompareParameters.RingMatchesRingOnly = pt.get<bool>(
      "RingMatchesRingOnly", p.AtomCompareParameters.RingMatchesRingOnly);
  p.AtomCompareParameters.MaxDistance =
      pt.get<double>("MaxDistance", p.AtomCompareParameters.MaxDistance);
  p.BondCompareParameters.RingMatchesRingOnly = pt.get<bool>(
      "RingMatchesRingOnly", p.BondCompareParameters.RingMatchesRingOnly);
  p.AtomCompareParameters.RingMatchesRingOnly = pt.get<bool>(
      "AtomRingMatchesRingOnly", p.AtomCompareParameters.RingMatchesRingOnly);
  p.BondCompareParameters.RingMatchesRingOnly = pt.get<bool>(
      "BondRingMatchesRingOnly", p.BondCompareParameters.RingMatchesRingOnly);
  p.BondCompareParameters.CompleteRingsOnly = pt.get<bool>(
      "CompleteRingsOnly", p.BondCompareParameters.CompleteRingsOnly);
  p.AtomCompareParameters.CompleteRingsOnly = pt.get<bool>(
      "AtomCompleteRingsOnly", p.AtomCompareParameters.CompleteRingsOnly);
  p.BondCompareParameters.CompleteRingsOnly = pt.get<bool>(
      "BondCompleteRingsOnly", p.BondCompareParameters.CompleteRingsOnly);
  p.BondCompareParameters.MatchFusedRings =
      pt.get<bool>("MatchFusedRings", p.BondCompareParameters.MatchFusedRings);
  p.BondCompareParameters.MatchFusedRingsStrict = pt.get<bool>(
      "MatchFusedRingsStrict", p.BondCompareParameters.MatchFusedRingsStrict);
  p.BondCompareParameters.MatchStereo =
      pt.get<bool>("MatchStereo", p.BondCompareParameters.MatchStereo);
  p.StoreAll = pt.get<bool>("StoreAll", p.StoreAll);

  p.setMCSAtomTyperFromConstChar(
      pt.get<std::string>("AtomCompare", "def").c_str());
  p.setMCSBondTyperFromConstChar(
      pt.get<std::string>("BondCompare", "def").c_str());

  p.InitialSeed = pt.get<std::string>("InitialSeed", "");
}

MCSResult findMCS(const std::vector<ROMOL_SPTR> &mols,
                  const MCSParameters *params) {
  MCSParameters p;
  if (nullptr == params) {
    params = &p;
  }
  RDKit::FMCS::MaximumCommonSubgraph fmcs(params);
  return fmcs.find(mols);
}

MCSResult findMCS_P(const std::vector<ROMOL_SPTR> &mols,
                    const char *params_json) {
  MCSParameters p;
  parseMCSParametersJSON(params_json, &p);
  return findMCS(mols, &p);
}

MCSResult findMCS(const std::vector<ROMOL_SPTR> &mols, bool maximizeBonds,
                  double threshold, unsigned int timeout, bool verbose,
                  bool matchValences, bool ringMatchesRingOnly,
                  bool completeRingsOnly, bool matchChiralTag,
                  AtomComparator atomComp, BondComparator bondComp) {
  return findMCS(mols, maximizeBonds, threshold, timeout, verbose,
                 matchValences, ringMatchesRingOnly, completeRingsOnly,
                 matchChiralTag, atomComp, bondComp, IgnoreRingFusion);
}

MCSResult findMCS(const std::vector<ROMOL_SPTR> &mols, bool maximizeBonds,
                  double threshold, unsigned int timeout, bool verbose,
                  bool matchValences, bool ringMatchesRingOnly,
                  bool completeRingsOnly, bool matchChiralTag,
                  AtomComparator atomComp, BondComparator bondComp,
                  RingComparator ringComp) {
  MCSParameters ps;
  ps.MaximizeBonds = maximizeBonds;
  ps.Threshold = threshold;
  ps.Timeout = timeout;
  ps.Verbose = verbose;
  ps.setMCSAtomTyperFromEnum(atomComp);
  ps.AtomCompareParameters.MatchValences = matchValences;
  ps.AtomCompareParameters.MatchChiralTag = matchChiralTag;
  ps.AtomCompareParameters.RingMatchesRingOnly = ringMatchesRingOnly;
  ps.setMCSBondTyperFromEnum(bondComp);
  ps.BondCompareParameters.RingMatchesRingOnly = ringMatchesRingOnly;
  ps.BondCompareParameters.CompleteRingsOnly = completeRingsOnly;
  ps.BondCompareParameters.MatchFusedRings = (ringComp != IgnoreRingFusion);
  ps.BondCompareParameters.MatchFusedRingsStrict =
      (ringComp == StrictRingFusion);
  return findMCS(mols, &ps);
}

bool MCSProgressCallbackTimeout(const MCSProgressData &,
                                const MCSParameters &params, void *userData) {
  PRECONDITION(userData, "userData must not be NULL");
  auto t0 = static_cast<unsigned long long *>(userData);
  unsigned long long t = nanoClock();
  return !params.Timeout || (t - *t0 <= params.Timeout * 1000000ULL);
}

// PREDEFINED FUNCTORS:

//=== ATOM COMPARE ========================================================
bool checkAtomRingMatch(const MCSAtomCompareParameters &p, const ROMol &mol1,
                        unsigned int atom1, const ROMol &mol2,
                        unsigned int atom2) {
  if (p.RingMatchesRingOnly) {
    const auto ri1 = mol1.getRingInfo();
    const auto ri2 = mol2.getRingInfo();
    bool atom1inRing = (ri1->numAtomRings(atom1) > 0);
    bool atom2inRing = (ri2->numAtomRings(atom2) > 0);
    return atom1inRing == atom2inRing;
  } else {
    return true;
  }
}

bool checkAtomCharge(const MCSAtomCompareParameters &, const ROMol &mol1,
                     unsigned int atom1, const ROMol &mol2,
                     unsigned int atom2) {
  const auto a1 = mol1.getAtomWithIdx(atom1);
  const auto a2 = mol2.getAtomWithIdx(atom2);
  return a1->getFormalCharge() == a2->getFormalCharge();
}

bool checkAtomChirality(const MCSAtomCompareParameters &, const ROMol &mol1,
                        unsigned int atom1, const ROMol &mol2,
                        unsigned int atom2) {
  const auto a1 = mol1.getAtomWithIdx(atom1);
  const auto a2 = mol2.getAtomWithIdx(atom2);
  const auto ac1 = a1->getChiralTag();
  const auto ac2 = a2->getChiralTag();
  if (ac1 == Atom::CHI_TETRAHEDRAL_CW || ac1 == Atom::CHI_TETRAHEDRAL_CCW) {
    return (ac2 == Atom::CHI_TETRAHEDRAL_CW ||
            ac2 == Atom::CHI_TETRAHEDRAL_CCW);
  }
  return true;
}

bool checkAtomDistance(const MCSAtomCompareParameters &p, const ROMol &mol1,
                       unsigned int atom1, const ROMol &mol2,
                       unsigned int atom2) {
  const auto &ci1 = mol1.getConformer();
  const auto &ci2 = mol2.getConformer();
  const auto &pos1 = ci1.getAtomPos(atom1);
  const auto &pos2 = ci2.getAtomPos(atom2);
  bool withinRange = (pos1 - pos2).length() <= p.MaxDistance;
  return withinRange;
}

bool MCSAtomCompareAny(const MCSAtomCompareParameters &p, const ROMol &mol1,
                       unsigned int atom1, const ROMol &mol2,
                       unsigned int atom2, void *) {
  if (p.MatchChiralTag && !checkAtomChirality(p, mol1, atom1, mol2, atom2)) {
    return false;
  }
  if (p.MatchFormalCharge && !checkAtomCharge(p, mol1, atom1, mol2, atom2)) {
    return false;
  }
  if (p.MaxDistance > 0 && !checkAtomDistance(p, mol1, atom1, mol2, atom2)) {
    return false;
  }
  if (p.RingMatchesRingOnly) {
    return checkAtomRingMatch(p, mol1, atom1, mol2, atom2);
  }

  return true;
}

bool MCSAtomCompareElements(const MCSAtomCompareParameters &p,
                            const ROMol &mol1, unsigned int atom1,
                            const ROMol &mol2, unsigned int atom2, void *) {
  const auto a1 = mol1.getAtomWithIdx(atom1);
  const auto a2 = mol2.getAtomWithIdx(atom2);
  if (a1->getAtomicNum() != a2->getAtomicNum()) {
    return false;
  }
  if (p.MatchValences && a1->getTotalValence() != a2->getTotalValence()) {
    return false;
  }
  if (p.MatchChiralTag && !checkAtomChirality(p, mol1, atom1, mol2, atom2)) {
    return false;
  }
  if (p.MatchFormalCharge && !checkAtomCharge(p, mol1, atom1, mol2, atom2)) {
    return false;
  }
  if (p.MaxDistance > 0 && !checkAtomDistance(p, mol1, atom1, mol2, atom2)) {
    return false;
  }
  if (p.RingMatchesRingOnly) {
    return checkAtomRingMatch(p, mol1, atom1, mol2, atom2);
  }
  return true;
}

bool MCSAtomCompareIsotopes(const MCSAtomCompareParameters &p,
                            const ROMol &mol1, unsigned int atom1,
                            const ROMol &mol2, unsigned int atom2, void *) {
  // ignore everything except isotope information:
  const auto a1 = mol1.getAtomWithIdx(atom1);
  const auto a2 = mol2.getAtomWithIdx(atom2);
  if (a1->getIsotope() != a2->getIsotope()) {
    return false;
  }
  if (p.MatchChiralTag && !checkAtomChirality(p, mol1, atom1, mol2, atom2)) {
    return false;
  }
  if (p.MatchFormalCharge && !checkAtomCharge(p, mol1, atom1, mol2, atom2)) {
    return false;
  }
  if (p.MaxDistance > 0 && !checkAtomDistance(p, mol1, atom1, mol2, atom2)) {
    return false;
  }
  if (p.RingMatchesRingOnly) {
    return checkAtomRingMatch(p, mol1, atom1, mol2, atom2);
  }
  return true;
}

bool MCSAtomCompareAnyHeavyAtom(const MCSAtomCompareParameters &p,
                                const ROMol &mol1, unsigned int atom1,
                                const ROMol &mol2, unsigned int atom2, void *) {
  const auto a1 = mol1.getAtomWithIdx(atom1);
  const auto a2 = mol2.getAtomWithIdx(atom2);
  // Any atom, including H, matches another atom of the same type,  according to
  // the other flags
  if (a1->getAtomicNum() == a2->getAtomicNum() ||
      (a1->getAtomicNum() > 1 && a2->getAtomicNum() > 1)) {
    return MCSAtomCompareAny(p, mol1, atom1, mol2, atom2, nullptr);
  }
  return false;
}

//=== BOND COMPARE ========================================================

class BondMatchOrderMatrix {
  bool MatchMatrix[Bond::ZERO + 1][Bond::ZERO + 1];

 public:
  BondMatchOrderMatrix(bool ignoreAromatization) {
    memset(MatchMatrix, 0, sizeof(MatchMatrix));
    // fill cells of the same and unspecified type
    for (size_t i = 0; i <= Bond::ZERO; ++i) {
      MatchMatrix[i][i] = true;
      MatchMatrix[Bond::UNSPECIFIED][i] = MatchMatrix[i][Bond::UNSPECIFIED] =
          true;
      MatchMatrix[Bond::ZERO][i] = MatchMatrix[i][Bond::ZERO] = true;
    }
    if (ignoreAromatization) {
      MatchMatrix[Bond::SINGLE][Bond::AROMATIC] =
          MatchMatrix[Bond::AROMATIC][Bond::SINGLE] = true;
      MatchMatrix[Bond::SINGLE][Bond::ONEANDAHALF] =
          MatchMatrix[Bond::ONEANDAHALF][Bond::SINGLE] = true;
      MatchMatrix[Bond::DOUBLE][Bond::TWOANDAHALF] =
          MatchMatrix[Bond::TWOANDAHALF][Bond::DOUBLE] = true;
      MatchMatrix[Bond::TRIPLE][Bond::THREEANDAHALF] =
          MatchMatrix[Bond::THREEANDAHALF][Bond::TRIPLE] = true;
      MatchMatrix[Bond::QUADRUPLE][Bond::FOURANDAHALF] =
          MatchMatrix[Bond::FOURANDAHALF][Bond::QUADRUPLE] = true;
      MatchMatrix[Bond::QUINTUPLE][Bond::FIVEANDAHALF] =
          MatchMatrix[Bond::FIVEANDAHALF][Bond::QUINTUPLE] = true;
    }
  }
  inline bool isEqual(unsigned int i, unsigned int j) const {
    return MatchMatrix[i][j];
  }
};

bool checkBondStereo(const MCSBondCompareParameters &, const ROMol &mol1,
                     unsigned int bond1, const ROMol &mol2,
                     unsigned int bond2) {
  const auto b1 = mol1.getBondWithIdx(bond1);
  const auto b2 = mol2.getBondWithIdx(bond2);
  auto bs1 = b1->getStereo();
  auto bs2 = b2->getStereo();
  if (b1->getBondType() == Bond::DOUBLE && b2->getBondType() == Bond::DOUBLE) {
    if (bs1 > Bond::STEREOANY && !(bs2 > Bond::STEREOANY)) {
      return false;
    } else {
      return bs1 == bs2;
    }
  }
  return true;
}

bool havePairOfCompatibleRings(const MCSBondCompareParameters &,
                               const ROMol &mol1, unsigned int bond1,
                               const ROMol &mol2, unsigned int bond2) {
  const auto ri1 = mol1.getRingInfo();
  const auto ri2 = mol2.getRingInfo();
  const auto &bondRings1 = ri1->bondRings();
  const auto &bondRings2 = ri2->bondRings();
  for (unsigned int ringIdx1 : ri1->bondMembers(bond1)) {
    const auto &ring1 = bondRings1.at(ringIdx1);
    bool isRing1Fused = ri1->isRingFused(ringIdx1);
    for (unsigned int ringIdx2 : ri2->bondMembers(bond2)) {
      const auto &ring2 = bondRings2.at(ringIdx2);
      if (ring1.size() == ring2.size()) {
        return true;
      }
      if (isRing1Fused && ring2.size() > ring1.size()) {
        return true;
      }
      bool isRing2Fused = ri2->isRingFused(ringIdx2);
      if (isRing2Fused && ring1.size() > ring2.size()) {
        return true;
      }
    }
  }
  return false;
}

bool checkBondRingMatch(const MCSBondCompareParameters &p, const ROMol &mol1,
                        unsigned int bond1, const ROMol &mol2,
                        unsigned int bond2) {
  const auto ri1 = mol1.getRingInfo();
  const auto ri2 = mol2.getRingInfo();
  // indices of rings in the query molecule
  const auto &ringIndices1 = ri1->bondMembers(bond1);
  // indices of rings in the target molecule
  const auto &ringIndices2 = ri2->bondMembers(bond2);
  bool bond1inRing = !ringIndices1.empty();
  bool bond2inRing = !ringIndices2.empty();
  bool res = (bond1inRing == bond2inRing);
  // if rings should be complete, we need to check upfront that there
  // is at least one pair of compatible rings; if there isn't, there
  // will never be a chance of complete match, so we should fail early
  if (p.CompleteRingsOnly && bond1inRing && bond2inRing) {
    res = havePairOfCompatibleRings(p, mol1, bond1, mol2, bond2);
  }

  // bond are both either in a ring or not
  return res;
}

bool MCSBondCompareAny(const MCSBondCompareParameters &p, const ROMol &mol1,
                       unsigned int bond1, const ROMol &mol2,
                       unsigned int bond2, void *) {
  if (p.MatchStereo && !checkBondStereo(p, mol1, bond1, mol2, bond2)) {
    return false;
  }
  if (p.RingMatchesRingOnly) {
    return checkBondRingMatch(p, mol1, bond1, mol2, bond2);
  }
  return true;
}

bool MCSBondCompareOrder(const MCSBondCompareParameters &p, const ROMol &mol1,
                         unsigned int bond1, const ROMol &mol2,
                         unsigned int bond2, void *) {
  static const BondMatchOrderMatrix match(true);  // ignore Aromatization
  const auto b1 = mol1.getBondWithIdx(bond1);
  const auto b2 = mol2.getBondWithIdx(bond2);
  auto t1 = b1->getBondType();
  auto t2 = b2->getBondType();
  if (match.isEqual(t1, t2)) {
    if (p.MatchStereo && !checkBondStereo(p, mol1, bond1, mol2, bond2)) {
      return false;
    }
    if (p.RingMatchesRingOnly) {
      return checkBondRingMatch(p, mol1, bond1, mol2, bond2);
    }
    return true;
  }
  return false;
}

bool MCSBondCompareOrderExact(const MCSBondCompareParameters &p,
                              const ROMol &mol1, unsigned int bond1,
                              const ROMol &mol2, unsigned int bond2, void *) {
  static const BondMatchOrderMatrix match(false);  // AROMATIC != SINGLE
  const auto b1 = mol1.getBondWithIdx(bond1);
  const auto b2 = mol2.getBondWithIdx(bond2);
  auto t1 = b1->getBondType();
  auto t2 = b2->getBondType();
  if (match.isEqual(t1, t2)) {
    if (p.MatchStereo && !checkBondStereo(p, mol1, bond1, mol2, bond2)) {
      return false;
    }
    if (p.RingMatchesRingOnly) {
      return checkBondRingMatch(p, mol1, bond1, mol2, bond2);
    }
    return true;
  }
  return false;
}

//=== RING COMPARE ========================================================
namespace {
// there are 3 bitsets for each ring
// isMCSRingBond: bits are set in correspondence of ring bond indices which are
// part of MCS.
// isMCSRingBondFused: bits are set in correspondence of ring bond
// indices which are part of MCS and are fused.
// isMCSRingBondNonFused: bits are set in correspondence of ring bond indices
// which are part of MCS and are not fused.
class RingBondCountVect {
 public:
  RingBondCountVect(const ROMol &mol)
      : d_mol(mol), d_ringInfo(mol.getRingInfo()) {
    d_ringBondCountVect.resize(d_ringInfo->numRings());
    d_isMCSBond.resize(mol.getNumBonds());
    for (auto &ringBondCount : d_ringBondCountVect) {
      ringBondCount.isMCSRingBond.resize(mol.getNumBonds());
      ringBondCount.isMCSRingBondNonFused.resize(mol.getNumBonds());
      ringBondCount.isMCSRingBondFused.resize(mol.getNumBonds());
    }
  }
  // In the 1st pass, we set fused/non-fused bits simply based on
  // numBondRings.
  void setMCSBondBitsPass1(unsigned int beginAtomIdx, unsigned int endAtomIdx,
                           const std::uint32_t c[], const FMCS::Graph &graph) {
    const auto bond =
        d_mol.getBondBetweenAtoms(graph[c[beginAtomIdx]], graph[c[endAtomIdx]]);
    CHECK_INVARIANT(bond, "");
    const auto bi = bond->getIdx();
    d_isMCSBond.set(bi);
    if (!d_ringInfo->numBondRings(bi)) {
      return;
    }
    if (d_ringInfo->numBondRings(bi) == 1) {
      const auto ringIdx = d_ringInfo->bondMembers(bi).front();
      d_ringBondCountVect[ringIdx].isMCSRingBond.set(bi);
      d_ringBondCountVect[ringIdx].isMCSRingBondNonFused.set(bi);
    } else {
      for (const auto &ringIdx : d_ringInfo->bondMembers(bi)) {
        d_ringBondCountVect[ringIdx].isMCSRingBond.set(bi);
        d_ringBondCountVect[ringIdx].isMCSRingBondFused.set(bi);
      }
    }
  }
  // In the 2nd pass, we refine the above as certain bonds originally
  // marked as fused can be relabelled as non-fused
  void setMCSBondBitsPass2() {
    for (auto &ringBondCount : d_ringBondCountVect) {
      ringBondCount.nonFusedCountPass1 =
          ringBondCount.isMCSRingBondNonFused.count();
      ringBondCount.fusedCountPass1 = ringBondCount.isMCSRingBondFused.count();
    }
    for (unsigned int bi = 0; bi < d_mol.getNumBonds(); ++bi) {
      if (!d_isMCSBond.test(bi)) {
        continue;
      }
      int fusedBondRingIdx = -1;
      unsigned int fusedBondCount = 0;
      for (auto &ringBondCount : d_ringBondCountVect) {
        if (!ringBondCount.isMCSRingBondFused.test(bi)) {
          continue;
        }
        auto ringIdx = &ringBondCount - &d_ringBondCountVect.front();
        if (ringBondCount.nonFusedCountPass1 == 0 &&
            ringBondCount.fusedCountPass1 <
                d_ringInfo->bondRings().at(ringIdx).size()) {
          ringBondCount.isMCSRingBondFused.set(bi, false);
        } else {
          ++fusedBondCount;
          fusedBondRingIdx = ringIdx;
        }
      }
      if (fusedBondCount == 1) {
        d_ringBondCountVect[fusedBondRingIdx].isMCSRingBondNonFused.set(bi);
        d_ringBondCountVect[fusedBondRingIdx].isMCSRingBondFused.set(bi, false);
      }
    }
  }
  bool isRingFusionHonored() {
    for (const auto &ringBondCount : d_ringBondCountVect) {
      unsigned int ringIdx = &ringBondCount - &d_ringBondCountVect.front();
      const auto &bondRings = d_ringInfo->bondRings().at(ringIdx);
      // if all or no bonds of this ring are part of MCS, no need to do further
      // checks
      const auto numRingBondsInMCS = ringBondCount.isMCSRingBond.count();
      if (!numRingBondsInMCS || numRingBondsInMCS == bondRings.size()) {
        continue;
      }
      // check ring bonds:
      // if they are non-fused, it's OK
      // if they are fused but classified as non-fused, it's OK
      // otherwise count a missing fused bond
      // if the sum of missing fused bonds + fused bonds in MCS + non-fused
      // bonds in MCS equals to the ring size, then we have failed the check
      const auto numNonFusedRingBondsInMCS =
          ringBondCount.isMCSRingBondNonFused.count();
      const auto numFusedRingBondsInMCS =
          ringBondCount.isMCSRingBondFused.count();
      const auto numMissingFusedBonds = std::count_if(
          bondRings.begin(), bondRings.end(),
          [this, &ringBondCount](const auto bi) {
            return (d_ringInfo->numBondRings(bi) > 1 &&
                    !ringBondCount.isMCSRingBondNonFused.test(bi) &&
                    !ringBondCount.isMCSRingBondFused.test(bi));
          });
      if (numMissingFusedBonds + numFusedRingBondsInMCS +
              numNonFusedRingBondsInMCS ==
          bondRings.size()) {
        return false;
      }
    }
    return true;
  }

 private:
  struct BondCount {
    boost::dynamic_bitset<> isMCSRingBond;
    boost::dynamic_bitset<> isMCSRingBondNonFused;
    unsigned int nonFusedCountPass1 = 0;
    boost::dynamic_bitset<> isMCSRingBondFused;
    unsigned int fusedCountPass1 = 0;
  };
  const ROMol &d_mol;
  const RingInfo *d_ringInfo;
  std::vector<BondCount> d_ringBondCountVect;
  boost::dynamic_bitset<> d_isMCSBond;
};
}  // end of anonymous namespace

inline bool ringFusionCheck(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) {
  /*
  Consider this case: MCS between
  2-methylbicyclo[4.3.0]nonane and 1-methylbicyclo[3.1.0]hexane

                \__
                /  \_                          \___
                \__/ \                         / \/
                   \ /                         \ /
                    C                           C
                    H2                          H2

  In permissive mode, we are happy for methylcyclohexane to be the MCS.
  in strict mode, we don't want methylcyclohexane to be the MCS.

                                      \__
                                      /  \
                                      \__/

  When methylcyclohexane is checked against 2-methylbicyclo[4.3.0]nonane
  there is no missing fused bond. This is OK for permissive mode.
  In strict mode, we also need to check against 1-methylbicyclo[3.1.0]hexane,
  where there is indeed a missing fused bond.
  Basically, in permissive mode one of two molecules is allowed to fail the
  match, but not both. In strict mode, none is.
  */
  bool res = true;
  if (boost::num_edges(target) < boost::num_edges(query)) {
    return true;
  }
  RingBondCountVect mol1RingBondCountVect(mol1);
  RingBondCountVect mol2RingBondCountVect(mol2);
  auto queryEdges = boost::edges(query);
  std::for_each(queryEdges.first, queryEdges.second,
                [&c1, &c2, &query, &target, &mol1RingBondCountVect,
                 &mol2RingBondCountVect](const auto &edge) {
                  const auto beginAtomIdx = boost::source(edge, query);
                  const auto endAtomIdx = boost::target(edge, query);
                  mol1RingBondCountVect.setMCSBondBitsPass1(
                      beginAtomIdx, endAtomIdx, c1, query);
                  mol2RingBondCountVect.setMCSBondBitsPass1(
                      beginAtomIdx, endAtomIdx, c2, target);
                });
  mol1RingBondCountVect.setMCSBondBitsPass2();
  mol2RingBondCountVect.setMCSBondBitsPass2();
  bool mol1Honored = mol1RingBondCountVect.isRingFusionHonored();
  bool mol2Honored = mol2RingBondCountVect.isRingFusionHonored();
  if (p.BondCompareParameters.MatchFusedRingsStrict) {
    res = mol1Honored && mol2Honored;
  } else {
    res = mol1Honored || mol2Honored;
  }
  return res;
}

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) {
  PRECONDITION(p, "p must not be NULL");
  if ((p->BondCompareParameters.MatchFusedRings ||
       p->BondCompareParameters.MatchFusedRingsStrict) &&
      !ringFusionCheck(c1, c2, mol1, query, mol2, target, *p)) {
    return false;
  }
  if (p->AtomCompareParameters.MatchChiralTag &&
      !FinalChiralityCheckFunction(c1, c2, mol1, query, mol2, target, p)) {
    return false;
  }
  const auto ip = dynamic_cast<const detail::MCSParametersInternal *>(p);
  if (ip && ip->UserFinalMatchChecker) {
    return ip->UserFinalMatchChecker(c1, c2, mol1, query, mol2, target, p);
  }
  return true;
}

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 * /*unused*/) {
  const unsigned int qna = boost::num_vertices(query);  // getNumAtoms()
  // check chiral atoms only:
  for (unsigned int i = 0; i < qna; ++i) {
    const auto a1 = mol1.getAtomWithIdx(query[c1[i]]);
    const auto ac1 = a1->getChiralTag();

    const auto a2 = mol2.getAtomWithIdx(target[c2[i]]);
    const auto ac2 = a2->getChiralTag();

    ///*------------------ OLD Code :
    // ???: non chiral query atoms ARE ALLOWED TO MATCH to Chiral target atoms
    // (see test for issue 481)
    if (a1->getDegree() <
            3 ||  // #688: doesn't deal with "explicit" Hs properly
        !(ac1 == Atom::CHI_TETRAHEDRAL_CW ||
          ac1 == Atom::CHI_TETRAHEDRAL_CCW)) {
      continue;  // skip non chiral center QUERY atoms
    }
    if (!(ac2 == Atom::CHI_TETRAHEDRAL_CW ||
          ac2 == Atom::CHI_TETRAHEDRAL_CCW)) {
      return false;
    }
    //--------------------
    /* More accurate check:

            if( !(ac1 == Atom::CHI_TETRAHEDRAL_CW || ac1 ==
       Atom::CHI_TETRAHEDRAL_CCW)
             && !(ac2 == Atom::CHI_TETRAHEDRAL_CW || ac2 ==
       Atom::CHI_TETRAHEDRAL_CCW))
                continue; // skip check if both atoms are non chiral center

            if(!(   (ac1 == Atom::CHI_TETRAHEDRAL_CW || ac1 ==
       Atom::CHI_TETRAHEDRAL_CCW)
                 && (ac2 == Atom::CHI_TETRAHEDRAL_CW || ac2 ==
       Atom::CHI_TETRAHEDRAL_CCW)))//ac2 != ac1)
                 return false; // both atoms must be chiral or not without a
       query priority
    */
    const unsigned int a1Degree =
        boost::out_degree(c1[i], query);  // a1.getDegree();
    // number of all connected atoms in a seed
    if (a1Degree > a2->getDegree()) {  // #688 was != . // FIX issue 631
      // printf("atoms Degree (%u, %u) %u [%u], %u\n", query[c1[i]],
      // target[c2[i]], a1Degree, a1.getDegree(), a2.getDegree());
      if (1 == a1Degree && a1->getDegree() == a2->getDegree()) {
        continue;  // continue to grow the seed
      } else {
        return false;
      }
    }

    INT_LIST qOrder;
    for (unsigned int j = 0; j < qna && qOrder.size() != a1Degree; ++j) {
      const auto qB = mol1.getBondBetweenAtoms(query[c1[i]], query[c1[j]]);
      if (qB) {
        qOrder.push_back(qB->getIdx());
      }
    }

    // #688
    INT_LIST qmoOrder;
    {
      for (const auto &nbri :
           boost::make_iterator_range(mol1.getAtomBonds(a1))) {
        int dbidx = mol1[nbri]->getIdx();
        if (std::find(qOrder.begin(), qOrder.end(), dbidx) != qOrder.end()) {
          qmoOrder.push_back(dbidx);
        }
        //            else
        //                qmoOrder.push_back(-1);
      }
    }
    int qPermCount =  // was: a1.getPerturbationOrder(qOrder);
        static_cast<int>(countSwapsToInterconvert(qmoOrder, qOrder));

    INT_LIST mOrder;
    for (unsigned int j = 0; j < qna && mOrder.size() != a2->getDegree(); ++j) {
      const auto mB = mol2.getBondBetweenAtoms(target[c2[i]], target[c2[j]]);
      if (mB) {
        mOrder.push_back(mB->getIdx());
      }
    }

    // #688
    while (mOrder.size() < a2->getDegree()) {
      mOrder.push_back(-1);
    }
    INT_LIST moOrder;
    for (const auto &nbri : boost::make_iterator_range(mol2.getAtomBonds(a2))) {
      int dbidx = mol2[nbri]->getIdx();
      if (std::find(mOrder.begin(), mOrder.end(), dbidx) != mOrder.end()) {
        moOrder.push_back(dbidx);
      } else {
        moOrder.push_back(-1);
      }
    }

    int mPermCount =  // was: a2.getPerturbationOrder(mOrder);
        static_cast<int>(countSwapsToInterconvert(moOrder, mOrder));
    //----

    if ((qPermCount % 2 == mPermCount % 2 &&
         a1->getChiralTag() != a2->getChiralTag()) ||
        (qPermCount % 2 != mPermCount % 2 &&
         a1->getChiralTag() == a2->getChiralTag())) {
      return false;
    }
  }

  // check double bonds ONLY (why ???)
  std::map<unsigned int, unsigned int> qMap;
  for (unsigned int j = 0; j < qna; ++j) {
    qMap[query[c1[j]]] = j;
  }
  for (const auto &bondIdx : boost::make_iterator_range(boost::edges(query))) {
    const auto qBnd = mol1.getBondWithIdx(query[bondIdx]);
    if (qBnd->getBondType() != Bond::DOUBLE ||
        qBnd->getStereo() <= Bond::STEREOANY) {
      continue;
    }
    // don't think this can actually happen, but check to be sure:
    if (qBnd->getStereoAtoms().size() != 2) {  // MUST check it in the seed, not
                                               // in full query molecule, but
                                               // never happens !!!
      continue;
    }

    const auto mBnd =
        mol2.getBondBetweenAtoms(target[c2[qMap[qBnd->getBeginAtomIdx()]]],
                                 target[c2[qMap[qBnd->getEndAtomIdx()]]]);
    CHECK_INVARIANT(mBnd, "Matching bond not found");
    if (mBnd->getBondType() != Bond::DOUBLE ||
        mBnd->getStereo() <= Bond::STEREOANY) {
      continue;
    }
    // don't think this can actually happen, but check to be sure:
    if (mBnd->getStereoAtoms().size() != 2) {
      continue;
    }

    unsigned int end1Matches = 0;
    unsigned int end2Matches = 0;
    if (target[c2[qMap[qBnd->getBeginAtomIdx()]]] ==
        rdcast<unsigned int>(mBnd->getBeginAtomIdx())) {
      // query Begin == mol Begin
      if (target[c2[qMap[qBnd->getStereoAtoms()[0]]]] ==
          rdcast<unsigned int>(mBnd->getStereoAtoms()[0])) {
        end1Matches = 1;
      }
      if (target[c2[qMap[qBnd->getStereoAtoms()[1]]]] ==
          rdcast<unsigned int>(mBnd->getStereoAtoms()[1])) {
        end2Matches = 1;
      }
    } else {
      // query End == mol Begin
      if (target[c2[qMap[qBnd->getStereoAtoms()[0]]]] ==
          rdcast<unsigned int>(mBnd->getStereoAtoms()[1])) {
        end1Matches = 1;
      }
      if (target[c2[qMap[qBnd->getStereoAtoms()[1]]]] ==
          rdcast<unsigned int>(mBnd->getStereoAtoms()[0])) {
        end2Matches = 1;
      }
    }
    // std::cerr<<"  bnd: "<<qBnd->getIdx()<<":"<<qBnd->getStereo()<<" -
    // "<<mBnd->getIdx()<<":"<<mBnd->getStereo()<<"  --  "<<end1Matches<<"
    // "<<end2Matches<<std::endl;
    if (mBnd->getStereo() == qBnd->getStereo() &&
        (end1Matches + end2Matches) == 1) {
      return false;
    }
    if (mBnd->getStereo() != qBnd->getStereo() &&
        (end1Matches + end2Matches) != 1) {
      return false;
    }
  }
  return true;
}

bool FinalChiralityCheckFunction_1(const short unsigned int c1[],
                                   const short unsigned int c2[],
                                   const ROMol &mol1, const FMCS::Graph &query,
                                   const ROMol &mol2, const FMCS::Graph &target,
                                   const MCSParameters *) {
  const unsigned int qna = boost::num_vertices(query);  // getNumAtoms()
  // check chiral atoms:
  for (unsigned int i = 0; i < qna; ++i) {
    const auto a1 = mol1.getAtomWithIdx(query[c1[i]]);
    const auto ac1 = a1->getChiralTag();
    if (!(ac1 == Atom::CHI_TETRAHEDRAL_CW ||
          ac1 == Atom::CHI_TETRAHEDRAL_CCW)) {
      continue;  // skip non chiral center query atoms
    }
    const auto a2 = mol2.getAtomWithIdx(target[c2[i]]);
    const auto ac2 = a2->getChiralTag();
    if (!(ac2 == Atom::CHI_TETRAHEDRAL_CW ||
          ac2 == Atom::CHI_TETRAHEDRAL_CCW)) {
      continue;  // skip non chiral center TARGET atoms even if query atom is
    }
    // chiral
    ////                return false;
    // both atoms are chiral:
    const unsigned int a1Degree =
        boost::out_degree(c1[i], query);  // a1.getDegree();
    if (a1Degree != a2->getDegree()) {  // number of all connected atoms in seed
      return false;                     // ???
    }
    INT_LIST qOrder;
    for (unsigned int j = 0; j < qna && qOrder.size() != a1Degree; ++j) {
      const auto qB = mol1.getBondBetweenAtoms(query[c1[i]], query[c1[j]]);
      if (qB) {
        qOrder.push_back(qB->getIdx());
      }
    }

    int qPermCount = a1->getPerturbationOrder(qOrder);
    INT_LIST mOrder;
    for (unsigned int j = 0; j < qna && mOrder.size() != a2->getDegree(); ++j) {
      const auto mB = mol2.getBondBetweenAtoms(target[c2[i]], target[c2[j]]);
      if (mB) {
        mOrder.push_back(mB->getIdx());
      }
    }
    int mPermCount = a2->getPerturbationOrder(mOrder);

    if ((qPermCount % 2 == mPermCount % 2 &&
         a1->getChiralTag() != a2->getChiralTag()) ||
        (qPermCount % 2 != mPermCount % 2 &&
         a1->getChiralTag() == a2->getChiralTag())) {
      return false;
    }
  }

  // check double bonds ONLY (why ???)
  std::map<unsigned int, unsigned int> qMap;
  for (unsigned int j = 0; j < qna; ++j) {
    qMap[query[c1[j]]] = j;
  }
  for (const auto &bondIdx : boost::make_iterator_range(boost::edges(query))) {
    const auto qBnd = mol1.getBondWithIdx(query[bondIdx]);
    if (qBnd->getBondType() != Bond::DOUBLE ||
        qBnd->getStereo() <= Bond::STEREOANY) {
      continue;
    }
    // don't think this can actually happen, but check to be sure:
    if (qBnd->getStereoAtoms().size() != 2) {  // MUST check it in the seed, not
                                               // in full query molecule, but
                                               // never happens !!!
      continue;
    }

    const Bond *mBnd =
        mol2.getBondBetweenAtoms(target[c2[qMap[qBnd->getBeginAtomIdx()]]],
                                 target[c2[qMap[qBnd->getEndAtomIdx()]]]);
    CHECK_INVARIANT(mBnd, "Matching bond not found");
    if (mBnd->getBondType() != Bond::DOUBLE ||
        mBnd->getStereo() <= Bond::STEREOANY) {
      continue;
    }
    // don't think this can actually happen, but check to be sure:
    if (mBnd->getStereoAtoms().size() != 2) {
      continue;
    }

    unsigned int end1Matches = 0;
    unsigned int end2Matches = 0;
    if (target[c2[qMap[qBnd->getBeginAtomIdx()]]] == mBnd->getBeginAtomIdx()) {
      // query Begin == mol Begin
      if (target[c2[qMap[qBnd->getStereoAtoms()[0]]]] ==
          rdcast<unsigned int>(mBnd->getStereoAtoms()[0])) {
        end1Matches = 1;
      }
      if (target[c2[qMap[qBnd->getStereoAtoms()[1]]]] ==
          rdcast<unsigned int>(mBnd->getStereoAtoms()[1])) {
        end2Matches = 1;
      }
    } else {
      // query End == mol Begin
      if (target[c2[qMap[qBnd->getStereoAtoms()[0]]]] ==
          rdcast<unsigned int>(mBnd->getStereoAtoms()[1])) {
        end1Matches = 1;
      }
      if (target[c2[qMap[qBnd->getStereoAtoms()[1]]]] ==
          rdcast<unsigned int>(mBnd->getStereoAtoms()[0])) {
        end2Matches = 1;
      }
    }
    // std::cerr<<"  bnd: "<<qBnd->getIdx()<<":"<<qBnd->getStereo()<<" -
    // "<<mBnd->getIdx()<<":"<<mBnd->getStereo()<<"  --  "<<end1Matches<<"
    // "<<end2Matches<<std::endl;
    if (mBnd->getStereo() == qBnd->getStereo() &&
        (end1Matches + end2Matches) == 1) {
      return false;
    }
    if (mBnd->getStereo() != qBnd->getStereo() &&
        (end1Matches + end2Matches) != 1) {
      return false;
    }
  }
  return true;
}

namespace detail {
MCSParametersInternal::MCSParametersInternal(const MCSParameters *params)
    : MCSParameters(params) {
  UserFinalMatchChecker = FinalMatchChecker;
  FinalMatchChecker = FinalMatchCheckFunction;
}
}  // end namespace detail

}  // namespace RDKit