File: JSONParsers.cpp

package info (click to toggle)
rdkit 202503.1-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • 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: 578; xml: 229; fortran: 183; sh: 105
file content (103 lines) | stat: -rw-r--r-- 4,065 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
//
//  Copyright (C) 2024 Novartis Biomedical Research and other RDKit contributors
//
//   @@ 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.
//

#define USE_BETTER_ENUMS
#include "JSONParsers.h"
#include <GraphMol/MolPickler.h>
#include <GraphMol/FileParsers/PNGParser.h>
#include <GraphMol/SmilesParse/SmilesJSONParsers.h>
#include <RDGeneral/BoostStartInclude.h>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <RDGeneral/BoostEndInclude.h>

namespace RDKit {
namespace MinimalLib {

void updatePropertyPickleOptionsFromJSON(unsigned int &propFlags,
                                         const char *details_json) {
  if (details_json && details_json[0]) {
    std::istringstream ss;
    boost::property_tree::ptree pt;
    ss.str(details_json);
    boost::property_tree::read_json(ss, pt);
    const auto nodeIt = pt.find("propertyFlags");
    if (nodeIt != pt.not_found()) {
      auto propertyFlagsFromJson =
          (+PicklerOps::PropertyPickleOptions::NoProps)._to_integral();
      for (const auto *key : PicklerOps::PropertyPickleOptions::_names()) {
        if (nodeIt->second.get(key, false)) {
          propertyFlagsFromJson |=
              PicklerOps::PropertyPickleOptions::_from_string(key)
                  ._to_integral();
        }
      }
      propFlags = propertyFlagsFromJson;
    }
  }
}

void updateSanitizeFlagsFromJSON(unsigned int &sanitizeFlags,
                                 const char *details_json) {
  if (details_json && details_json[0]) {
    std::istringstream ss;
    boost::property_tree::ptree pt;
    ss.str(details_json);
    boost::property_tree::read_json(ss, pt);
    auto sanitizeFlagsFromJson =
        (+MolOps::SanitizeFlags::SANITIZE_NONE)._to_integral();
    for (const auto *key : MolOps::SanitizeFlags::_names()) {
      if (pt.get(key, false)) {
        sanitizeFlagsFromJson |=
            MolOps::SanitizeFlags::_from_string(key)._to_integral();
      }
    }
    sanitizeFlags = sanitizeFlagsFromJson;
  }
}

void updateRemoveHsParametersFromJSON(MolOps::RemoveHsParameters &ps,
                                      bool &sanitize,
                                      const char *details_json) {
  if (details_json && details_json[0]) {
    boost::property_tree::ptree pt;
    std::istringstream ss;
    ss.str(details_json);
    boost::property_tree::read_json(ss, pt);
    ps.removeDegreeZero = pt.get("removeDegreeZero", ps.removeDegreeZero);
    ps.removeHigherDegrees =
        pt.get("removeHigherDegrees", ps.removeHigherDegrees);
    ps.removeOnlyHNeighbors =
        pt.get("removeOnlyHNeighbors", ps.removeOnlyHNeighbors);
    ps.removeIsotopes = pt.get("removeIsotopes", ps.removeIsotopes);
    ps.removeAndTrackIsotopes =
        pt.get("removeAndTrackIsotopes", ps.removeAndTrackIsotopes);
    ps.removeDummyNeighbors =
        pt.get("removeDummyNeighbors", ps.removeDummyNeighbors);
    ps.removeDefiningBondStereo =
        pt.get("removeDefiningBondStereo", ps.removeDefiningBondStereo);
    ps.removeWithWedgedBond =
        pt.get("removeWithWedgedBond", ps.removeWithWedgedBond);
    ps.removeWithQuery = pt.get("removeWithQuery", ps.removeWithQuery);
    ps.removeMapped = pt.get("removeMapped", ps.removeMapped);
    ps.removeInSGroups = pt.get("removeInSGroups", ps.removeInSGroups);
    ps.showWarnings = pt.get("showWarnings", ps.showWarnings);
    ps.removeNonimplicit = pt.get("removeNonimplicit", ps.removeNonimplicit);
    ps.updateExplicitCount =
        pt.get("updateExplicitCount", ps.updateExplicitCount);
    ps.removeHydrides = pt.get("removeHydrides", ps.removeHydrides);
    ps.removeNontetrahedralNeighbors = pt.get("removeNontetrahedralNeighbors",
                                              ps.removeNontetrahedralNeighbors);
    sanitize = pt.get("sanitize", sanitize);
  }
}

}  // end namespace MinimalLib
}  // end namespace RDKit