File: StructCheckerOptions.cpp

package info (click to toggle)
rdkit 201809.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 123,688 kB
  • sloc: cpp: 230,509; python: 70,501; java: 6,329; ansic: 5,427; sql: 1,899; yacc: 1,739; lex: 1,243; makefile: 445; xml: 229; fortran: 183; sh: 123; cs: 93
file content (700 lines) | stat: -rw-r--r-- 22,614 bytes parent folder | download
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
//
//  Copyright (C) 2016 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 <ctype.h>
#include <memory.h>
#include <errno.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <boost/property_tree/json_parser.hpp>
#include "../../RDGeneral/StreamOps.h"
#include "../FileParsers/FileParsers.h"
#include "../FileParsers/MolSupplier.h"  //SDF
#include "../SmilesParse/SmilesParse.h"
#include "StructCheckerOptions.h"

#include "AugmentedAtomData.cpp"

namespace RDKit {
namespace StructureCheck {

bool parseOptionsJSON(const std::string &json, StructCheckerOptions &op) {
  if (json.empty()) return false;
  try {
    std::istringstream ss;
    ss.str(json);
    boost::property_tree::ptree pt;
    boost::property_tree::read_json(ss, pt);
    op = StructCheckerOptions();  // reset to default values
    op.AcidityLimit = pt.get<double>("AcidityLimit", op.AcidityLimit);
    op.RemoveMinorFragments =
        pt.get<bool>("RemoveMinorFragments", op.RemoveMinorFragments);
    op.DesiredCharge = pt.get<int>("DesiredCharge", op.DesiredCharge);
    op.CheckCollisions = pt.get<bool>("CheckCollisions", op.CheckCollisions);
    op.CollisionLimitPercent =
        pt.get<int>("CollisionLimitPercent", op.CollisionLimitPercent);
    op.MaxMolSize = pt.get<int>("MaxMolSize", op.MaxMolSize);
    op.ConvertSText = pt.get<bool>("ConvertSText", op.ConvertSText);
    op.SqueezeIdentifiers =
        pt.get<bool>("SqueezeIdentifiers", op.SqueezeIdentifiers);
    op.StripZeros = pt.get<bool>("StripZeros", op.StripZeros);
    op.CheckStereo = pt.get<bool>("CheckStereo", op.CheckStereo);
    op.ConvertAtomTexts = pt.get<bool>("ConvertAtomTexts", op.ConvertAtomTexts);
    op.GroupsToSGroups = pt.get<bool>("GroupsToSGroups", op.GroupsToSGroups);
    op.Verbose = pt.get<bool>("Verbose", op.Verbose);
  } catch (boost::property_tree::json_parser_error &ex) {
    BOOST_LOG(rdErrorLog) << "JSON StructureCheck Options:" << ex.message()
                          << "\n";
    return false;
  } catch (std::exception &ex) {
    BOOST_LOG(rdErrorLog) << "JSON StructureCheck Options:" << ex.what()
                          << "\n";
    return false;
  } catch (...) {
    BOOST_LOG(rdErrorLog)
        << "JSON StructureCheck Options: Unknown exception.\n";
    return false;
  }
  return true;
}

bool loadOptionsFromFiles(
    StructCheckerOptions &op, const std::string &augmentedAtomTranslationsFile,
    const std::string &patternFile,        // file with clean patterns
    const std::string &rotatePatternFile,  // file with rotate patterns
    const std::string &stereoPatternFile,  // file with stereo patterns
    const std::string &tautomerFile) {
  bool res = true;
  if (!augmentedAtomTranslationsFile.empty())
    res &= op.loadAugmentedAtomTranslations(augmentedAtomTranslationsFile);
  if (!patternFile.empty()) res &= op.loadPatterns(patternFile);
  if (!rotatePatternFile.empty())
    res &= op.loadRotatePatterns(rotatePatternFile);
  if (!stereoPatternFile.empty())
    res &= op.loadStereoPatterns(stereoPatternFile);
  if (!tautomerFile.empty()) res &= op.loadTautomerData(tautomerFile);
  return res;
}

//=====================================================================
// File parsers helper functions:

static const char
    *bond_to_string[] =  // ordered in according with BondType values
    {"?", "-", "=", "#", "~", "-=", "-~", "=~", "*"};

// used in unit test
bool StringToAugmentedAtom(const char *str, AugmentedAtom &aa) {
  /*
  * The syntax of a augmented atom string is as follows:
  *
  *   <AAString> ::= ['@'|'!@'] <Atom Symbol> [<Charge>]
  *                 {'(' <Bond Symbol> <Atom Symbol> [<Charge>] ')'}.
  * Bond symbols and charge descriptors are defined in the symbol tables
  * 'bond_to_string' and 'charge_to_string'.
  * '@' means central atom is in ring, '!@' means central atom is not in ring,
  *omitting means any topography could match.
  */

  size_t i;
  aa.ShortName = str;

  if (str[0] == '@') {
    aa.Topology = RING;
    str++;
  } else if (str[0] == '!' && str[1] == '@') {
    aa.Topology = CHAIN;
    str++;
    str++;
  }
  aa.Ligands.clear();  // initially no ligands

  // fetch atom symbol
  if (!isalpha(*str)) {  // atom symbol is required
    BOOST_LOG(rdErrorLog) << "atom symbol is required '" << str << "'\n";
    return false;
  }
  i = 0;
  while (isalnum(str[i]) || str[i] == ',' || str[i] == '#') i++;
  aa.AtomSymbol = std::string(str, i);
  str += i;

  // charge definition
  if (str[0] == '+' && str[1] == '-') {  // "+-" - ANY_CHARGE
    aa.Charge = ANY_CHARGE;
    str += 2;
  } else if (*str == '-' || *str == '+') {
    int sign = (*str == '-') ? (-1) : (1);
    str++;
    if (*str >= '1' && *str <= '7') {
      aa.Charge = sign * (*str - '0');
      str++;
    } else {  // no match
      BOOST_LOG(rdErrorLog) << "syntax error '" << str - 1 << "'\n";
      return false;
    }
  } else
    aa.Charge = 0;  // NONE; default

  // radical definition
  if (str == strpbrk(str, "|.:") &&
      !isdigit(str[1])) {  // don't confuse with degree specification
    switch (*str) {
      case '|':
        aa.Radical = SINGLET;  // RadicalType::SINGLET;
        str++;
        break;
      case '.':
        aa.Radical = DOUBLET;
        str++;
        break;
      case ':':
        aa.Radical = TRIPLET;
        str++;
        break;
      default:
        return false;  // never
    };
  } else
    aa.Radical = RT_NONE;

  // read ligand descriptions
  while (*str == '(') {
    aa.Ligands.push_back(Ligand());
    str++;  // skip '('
    // read bond type
    bool found = false;
    for (i = 0; i < sizeof(bond_to_string) / sizeof(*bond_to_string); i++) {
      if (0 == memcmp(str, bond_to_string[i], isalpha(str[1]) ? 1 : 2)) {
        found = true;
        aa.Ligands.back().BondType = (AABondType)(i);
        str += strlen(bond_to_string[i]);
        break;
      }
    }
    if (!found) {
      BOOST_LOG(rdErrorLog) << "syntax error '" << str
                            << "'\nthere must be a bond type symbol.\n";
      return false;
    }
    if (!isalpha(*str)) { /* there must be an atom symbol */
      BOOST_LOG(rdErrorLog) << "syntax error '" << str
                            << "'\nthere must be an atom symbol.\n";
      return false;
    }

    i = 0; /* fetch atom symbol */
    while (isalnum(str[i]) || str[i] == ',' || str[i] == '#') i++;
    aa.Ligands.back().AtomSymbol = std::string(str, i);
    str += i;

    // charge definition
    if (str[0] == '+' && str[1] == '-') {  // "+-" - ANY_CHARGE
      aa.Ligands.back().Charge = ANY_CHARGE;
      str += 2;
    } else if (*str == '-' || *str == '+') {
      int sign = (*str == '-') ? (-1) : (1);
      str++;
      if (*str >= '1' && *str <= '7') {
        aa.Ligands.back().Charge = sign * (*str - '0');
        str++;
      } else {  // no match
        BOOST_LOG(rdErrorLog) << "syntax error '" << str - 1 << "'\n";
        return false;
      }
    } else
      aa.Ligands.back().Charge = 0;  // NONE; default

    // radical definition
    if (str == strpbrk(str, "|.:") &&
        !isdigit(str[1])) {  // don't confuse with degree specification
      switch (*str) {
        case '|':
          aa.Ligands.back().Radical = SINGLET;
          str++;
          break;
        case '.':
          aa.Ligands.back().Radical = DOUBLET;
          str++;
          break;
        case ':':
          aa.Ligands.back().Radical = TRIPLET;
          str++;
          break;
        default:
          return false;  // never
      };
    } else
      aa.Ligands.back().Radical = RT_NONE;

    // substitution count descriptor
    if (str[0] == ':' && isdigit(str[1])) {
      aa.Ligands.back().SubstitutionCount = str[1] - '0';
      str += 2;
    } else
      aa.Ligands.back().SubstitutionCount = 0;

    if (*str == ')')  // check for close ')'
      str++;
    else {
      BOOST_LOG(rdErrorLog) << "unclosed ( '" << str << "'\n";
      return false;
    }
  }

  if (*str != '\0') {  // there are some extra symbols after scan (inside quoted
                       // AA string)
    BOOST_LOG(rdErrorLog) << "unexpected symbols after scan '" << str << "'\n";
    return false;
  }
  return true;
}

static bool ReadAugmentedAtoms(const std::string &path,
                               std::vector<AugmentedAtom> &atoms) {
  /*
  * '*.chk' and '*.aci' files loader
  * Only the portion of the strings between the two '"' characters is used,
  * other characters are regarded as comments.
  */
  FILE *fp = fopen(path.c_str(), "r");
  if (!fp) {
    BOOST_LOG(rdErrorLog) << "could not open file '" << path << "'\n"
                          << strerror(errno) << "\n";
    return false;
  }
  unsigned n = 0;

  char str[1024];
  while (fgets(str, sizeof(str), fp)) {  // comment block in '*.aci' file
    if (*str != '#') break;
  }
  sscanf(str, "%d", &n);

  atoms.clear();
  atoms.resize(n);
  /* read: "! _N10_" - unused version string      // '*.chk' file only
              char buffer[80];
              char *cp;
              int vers_len;
              fgets(buffer, 80, fp);
              cp = strchr(buffer, '_');
              if (cp && strchr(cp + 1, '_'))
              {
                  vers_len = (int)(strchr(cp + 1, '_') - cp) - 1;
                  strncpy(aa_check_version, cp + 1, vers_len);
                  aa_check_version[vers_len] = '\0';
              }

              if (log_file)
                  fprintf(log_file, "augmented atom check version = %s\n",
     aa_check_version);
  */
  for (unsigned i = 0; i < n && !feof(fp); i++) {
    str[0] = '\0';
    if (fgets(str, sizeof(str), fp)) {
      char *s = str;
      while (*s >= ' ' && *s != '"') s++;
      if (*s == '"') {
        s++;
        size_t len = 0;
        while (s[len] >= ' ' && s[len] != '"') len++;
        s[len] = '\0';  // == atom_string
        if (!StringToAugmentedAtom(s, atoms[i])) {
          BOOST_LOG(rdErrorLog) << "unsuccessful AA parsing of " << i + 1 << " "
                                << str << "\n";
          fclose(fp);
          return false;
        }
      } else {  // incorrect text line
        BOOST_LOG(rdErrorLog) << "unsuccessful AA parsing of " << i + 1 << " "
                              << str << "\n";
        fclose(fp);
        return false;
      }
    } else if (ferror(fp)) {
      BOOST_LOG(rdErrorLog) << "unsuccessful AA parsing of " << i + 1 << " "
                            << str << "\n";
      fclose(fp);
      return false;
    }
  }
  fclose(fp);
  return true;
}

static bool ReadAAPairs(
    const std::string &path,
    std::vector<std::pair<AugmentedAtom, AugmentedAtom>> &trans_pairs) {
  /*
  * '*.trn' file loader
  * Reads file and constructs an array of pairs of augmented atom
  * descriptions. The first one being the search pattern and the second
  * one the target pattern.
  * The function expects the number of augmented atom description pairs
  * on the first line and the strings corresponding to the data structures
  * on the n following lines.
  * Only the portion of the strings between the two '"' characters is used,
  * other characters are regarded as comments.
  */
  FILE *fp = fopen(path.c_str(), "r");
  if (!fp) {
    BOOST_LOG(rdErrorLog) << "could not open file '" << path << "'\n"
                          << strerror(errno) << "\n";
    return false;
  }
  unsigned n = 0;
  fscanf(fp, "%d", &n);

  char buffer[80];

  // Reads the version from the first line in the file
  if (fgets(buffer, sizeof(buffer), fp)) {
    /*
                int  vers_len;
                char *cp;
                cp = strchr(buffer, '_');
                if (cp && strchr(cp + 1, '_'))
                {
                    vers_len = (int)(strchr(cp + 1, '_') - cp) - 1;
                    strncpy(aa_trans_version, cp + 1, vers_len);
                    aa_trans_version[vers_len] = '\0';
                }
                if (log_file)
                    fprintf(log_file, "augmented atom transformation version =
       %s\n", aa_trans_version);
    */
  }
  trans_pairs.clear();
  trans_pairs.resize(n);

  for (unsigned i = 0; i < n; i++) {
    char str[1024];
    str[0] = '\0';
    if (fgets(str, sizeof(str), fp)) {
      char *s = str;
      while (*s >= ' ' && *s != '"') s++;
      if (*s == '"') {
        s++;
        size_t len = 0;
        while (s[len] >= ' ' && s[len] != '"') len++;
        s[len] = '\0';  // == atom_string

        if (!StringToAugmentedAtom(s, trans_pairs[i].first)) {
          BOOST_LOG(rdErrorLog) << "unsuccessful translation of " << str
                                << "\n";
          fclose(fp);
          return false;
        }

        s += len;
        s++;
        // second atom quoted string
        while (*s >= ' ' && *s != '"') s++;
        if (*s == '"') {
          s++;
          len = 0;
          while (s[len] >= ' ' && s[len] != '"') len++;
          s[len] = '\0';  // == atom_string

          if (!StringToAugmentedAtom(s, trans_pairs[i].second)) {
            BOOST_LOG(rdErrorLog) << "unsuccessful translation of " << str
                                  << "\n";
            fclose(fp);
            return false;
          }
        }
      }
    }
  }
  fclose(fp);
  if (trans_pairs.size() != n) {
    BOOST_LOG(rdErrorLog) << "syntax error in translation file " << path
                          << " pair " << trans_pairs.size() + 1 << "\n";
    return false;
  }
  return true;
}

//=====================================================================
static void loadDefaultAugmentedAtoms(StructCheckerOptions &struchkOpts) {
  std::vector<AugmentedAtom> good;
  good.reserve(sizeof(DefaultGoodAtoms) / sizeof(*DefaultGoodAtoms));

  for (const auto &DefaultGoodAtom : DefaultGoodAtoms) {
    good.push_back(AugmentedAtom());
    if (!StringToAugmentedAtom(DefaultGoodAtom.str, good.back())) {
      throw "INTERNAL ERROR in default data";
    }
  }

  std::vector<AugmentedAtom> acidic;
  acidic.reserve(sizeof(DefaultAcidicAtoms) / sizeof(*DefaultAcidicAtoms));

  for (const auto &DefaultAcidicAtom : DefaultAcidicAtoms) {
    acidic.push_back(AugmentedAtom());
    if (!StringToAugmentedAtom(DefaultAcidicAtom.str, acidic.back())) {
      throw "INTERNAL ERROR in default data";
    }
  }

  std::vector<std::pair<AugmentedAtom, AugmentedAtom>> trans_pairs;
  trans_pairs.resize(sizeof(DefaultAugmentedAtomTransforms) /
                     sizeof(*DefaultAugmentedAtomTransforms));
  for (size_t i = 0; i < sizeof(DefaultAugmentedAtomTransforms) /
                             sizeof(*DefaultAugmentedAtomTransforms);
       ++i) {
    if (!StringToAugmentedAtom(DefaultAugmentedAtomTransforms[i].from,
                               trans_pairs[i].first)) {
      throw "INTERNAL Error in default augmented atom transforms";
    }
    if (!StringToAugmentedAtom(DefaultAugmentedAtomTransforms[i].to,
                               trans_pairs[i].second)) {
      throw "INTERNAL Error in default augmented atom transforms";
    }
  }

  struchkOpts.setGoodAugmentedAtoms(good);
  struchkOpts.setAcidicAugmentedAtoms(acidic);
  struchkOpts.setAugmentedAtomTranslations(trans_pairs);
}
//=====================================================================

bool StructCheckerOptions::loadAugmentedAtomTranslations(
    const std::string &path) {
  AugmentedAtomPairs.clear();
  if (path.empty()) return false;
  return ReadAAPairs(path, AugmentedAtomPairs);
}

void StructCheckerOptions::setAugmentedAtomTranslations(
    const std::vector<std::pair<AugmentedAtom, AugmentedAtom>> &aaPairs) {
  AugmentedAtomPairs = aaPairs;
}

bool StructCheckerOptions::loadAcidicAugmentedAtoms(const std::string &path) {
  AcidicAtoms.clear();
  if (path.empty()) return false;
  return ReadAugmentedAtoms(path, AcidicAtoms);
}

void StructCheckerOptions::setAcidicAugmentedAtoms(
    const std::vector<AugmentedAtom> &atoms) {
  AcidicAtoms = atoms;
}

bool StructCheckerOptions::loadGoodAugmentedAtoms(const std::string &path) {
  GoodAtoms.clear();
  if (path.empty()) return false;
  return ReadAugmentedAtoms(path, GoodAtoms);
}
void StructCheckerOptions::setGoodAugmentedAtoms(
    const std::vector<AugmentedAtom> &atoms) {
  GoodAtoms = atoms;
}

static bool loadSDF(const std::string &path, std::vector<ROMOL_SPTR> &mols) {
  mols.clear();
  try {
    SDMolSupplier suppler(path);
    while (!suppler.atEnd()) {
      ROMol *m = suppler.next();
      if (m) {
        // ?? MakeHydrogensImplicit()
        mols.push_back(ROMOL_SPTR(m));
      }
    }
  } catch (std::exception &ex) {
    BOOST_LOG(rdErrorLog) << ex.what();  // log error
    return false;
  }
  return true;
}

bool StructCheckerOptions::loadPatterns(const std::string &path) {
  Patterns.clear();
  if (path.empty()) return false;
  return loadSDF(path, Patterns);
}

void StructCheckerOptions::setPatterns(const std::vector<ROMOL_SPTR> &p) {
  Patterns = p;
}

bool StructCheckerOptions::loadRotatePatterns(const std::string &path) {
  RotatePatterns.clear();
  if (path.empty()) return false;
  return loadSDF(path, RotatePatterns);
}

void StructCheckerOptions::setRotatePatterns(const std::vector<ROMOL_SPTR> &p) {
  RotatePatterns = p;
}

bool StructCheckerOptions::loadStereoPatterns(const std::string &path) {
  StereoPatterns.clear();
  if (path.empty()) return false;
  return loadSDF(path, StereoPatterns);
}

void StructCheckerOptions::setStereoPatterns(const std::vector<ROMOL_SPTR> &p) {
  StereoPatterns = p;
}

bool StructCheckerOptions::loadTautomerData(const std::string &path) {
  ToTautomer.clear();
  FromTautomer.clear();
  if (path.empty()) return false;
  try {
    std::string ext = path.substr(path.find_last_of(".") + 1);
    if (ext == "sdf" || ext == "SDF") {
      SDMolSupplier suppler(path);
      while (!suppler.atEnd()) {
        ROMol *m1 = suppler.next();
        if (suppler.atEnd()) break;
        ROMol *m2 = suppler.next();
        if (m1 && m2) {
          // ?? MakeHydrogensImplicit()
          FromTautomer.push_back(ROMOL_SPTR(m1));
          ToTautomer.push_back(ROMOL_SPTR(m2));
        }
      }
    } else if (ext == "rdf" ||
               ext == "RDF") {  // load RD-File, see CTfile format specification
      std::ifstream in(path.c_str());
      if (!in) {
        BOOST_LOG(rdErrorLog) << "could not open file '" << path << "'\n"
                              << strerror(errno) << "\n";
        return false;
      }
      std::string str;
      unsigned line = 0;
      do {
        str = getLine(in);
        line++;
        if (str.length() >= 4 && 0 == strcmp(str.c_str(), "$RXN")) {
          while (!in.eof()) {
            str = getLine(in);
            line++;
            if (str.length() >= 4 && 0 == strcmp(str.c_str(), "$MOL")) {
              RWMol *molFrom = MolDataStreamToMol(in, line);
              if (!molFrom) {
                BOOST_LOG(rdErrorLog) << "RD-file corrupted. " << path
                                      << " line " << line << "\n";  // log error
                return false;
              }
              while (molFrom && !in.eof()) {
                str = getLine(in);
                line++;
                if (str.length() >= 4 && 0 == strcmp(str.c_str(), "$MOL")) {
                  RWMol *molTo = MolDataStreamToMol(in, line);
                  if (!molTo) {
                    BOOST_LOG(rdErrorLog) << "RD-file corrupted. " << path
                                          << " line " << line
                                          << "\n";  // log error
                    return false;
                  }
                  // ?? MakeHydrogensImplicit()
                  FromTautomer.push_back(ROMOL_SPTR(molFrom));
                  ToTautomer.push_back(ROMOL_SPTR(molTo));
                }
              }
            }
          }
        }
      } while (!in.eof());
    } else {
      BOOST_LOG(rdErrorLog) << "unsupported file type. " << path
                            << "\n";  // log error
      return false;
    }
  } catch (std::exception &ex) {
    BOOST_LOG(rdErrorLog) << ex.what() << "\n";  // log error
    return false;
  }
  return true;
}

void StructCheckerOptions::setTautomerData(const std::vector<ROMOL_SPTR> &from,
                                           const std::vector<ROMOL_SPTR> &to) {
  FromTautomer = from;
  ToTautomer = to;
}

static void parseSMARTS(std::vector<ROMOL_SPTR> &mols,
                        const std::vector<std::string> &smarts) {
  mols.clear();
  for (const auto &patt : smarts) {
    ROMol *m = SmartsToMol(patt);
    if (m) mols.push_back(ROMOL_SPTR(m));
  }
}

void StructCheckerOptions::parsePatterns(
    const std::vector<std::string> &smarts) {
  parseSMARTS(Patterns, smarts);
}

void StructCheckerOptions::parseRotatePatterns(
    const std::vector<std::string> &smarts) {
  parseSMARTS(RotatePatterns, smarts);
}

void StructCheckerOptions::parseStereoPatterns(
    const std::vector<std::string> &smarts) {
  parseSMARTS(StereoPatterns, smarts);
}

void StructCheckerOptions::parseTautomerData(
    const std::vector<std::string> &smartsFrom,
    const std::vector<std::string> &smartsTo) {
  parseSMARTS(FromTautomer, smartsFrom);
  parseSMARTS(ToTautomer, smartsTo);
}
//--------------------------------------------------------------------------

bool loadChargeDataTables(const std::string& path) {
  // TODO: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  RDUNUSED_PARAM(path);
  /*
      double Elneg0; // elneg_table[0].value;
      std::map<unsigned, double> ElnegTable;   // AtomicNumber -> eleng
      std::vector<inc_entry_t> AtomAcidity;    //atom_acidity_table[]
      std::vector<inc_entry_t> charge_inc_table;  // std::map AtomicNumber ->
     ...
      double Alpha, Beta;
      std::vector<path_entry_t> alpha_path_table, beta_path_table;
  */
  return true;
}

StructCheckerOptions::StructCheckerOptions()
    : AcidityLimit(0.0),
      RemoveMinorFragments(false),
      DesiredCharge(0),
      CheckCollisions(false),
      CollisionLimitPercent(15),
      MaxMolSize(255),
      ConvertSText(false),
      SqueezeIdentifiers(false),
      StripZeros(false),
      CheckStereo(false),
      ConvertAtomTexts(false),
      GroupsToSGroups(false),
      Verbose(false),
      Elneg0(0.0)  // elneg_table[0].value;
      ,
      Alpha(0.0),
      Beta(0.0) {
  loadDefaultAugmentedAtoms(*this);
}

}  // namespace StructureCheck
}  // namespace RDKit