Files
rdkit/Code/MinimalLib/JSONParsers.cpp
Paolo Tosco 9c7ffb33e9 Expose reading/writing PNG metadata to CFFI and MinimalLib (#8381)
* get SynthonSpace.cpp to build also when RDK_USE_BOOST_SERIALIZATION is
not defined

* test should not fail when RDK_USE_BOOST_SERIALIZATION is not defined

* - expose reading/writing PNG metadata to CFFI and MinimalLib
- add relevant CFFI and MinimalLib unit tests
- add RDK_USE_BOOST_PROGRAM_OPTIONS CMake option
- enable using standalone zlib in the absence of boost::iostreams for parsing PNG files
- enable linking against maeparser in the absence of boost::iostreams also on Windows
- enable building RDKit in the absence of boost::program_options

* add check for boost::program_options

* change size_t into std::uint64_t in SearchResults for consistency with doTheSearch() which uses std::uint64_t

* change size_t into std::uint64_t in SearchResults for consistency with
SynthonSpaceSearcher::doTheSearch()

* set CMake policy to allow YAeHMOP to require a version which is not
actually supported

* reverted External/YAeHMOP/CMakeLists.txt to master version

* check if Windows build will work

* fix build

* configure zlib install location

* build zlib dependency

* include zlib header directory

* explicitly set PropertyFlags.AllProps so the test does not fail on
static builds

---------

Co-authored-by: ptosco <paolo.tosco@novartis.com>
2025-07-23 17:10:38 +02:00

123 lines
4.9 KiB
C++

//
// 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);
}
}
void updatePNGMetadataParamsFromJSON(PNGMetadataParams &params,
const char *details_json) {
if (details_json && strlen(details_json)) {
boost::property_tree::ptree pt;
std::istringstream ss;
ss.str(details_json);
boost::property_tree::read_json(ss, pt);
params.includePkl = pt.get("includePkl", params.includePkl);
params.includeSmiles = pt.get("includeSmiles", params.includeSmiles);
params.includeMol = pt.get("includeMol", params.includeMol);
updatePropertyPickleOptionsFromJSON(params.propertyFlags, details_json);
updateSmilesWriteParamsFromJSON(params.smilesWriteParams, details_json);
unsigned int restoreBondDirs = params.restoreBondDirs;
updateCXSmilesFieldsFromJSON(params.cxSmilesFlags, restoreBondDirs,
details_json);
params.restoreBondDirs =
RestoreBondDirOption::_from_integral(restoreBondDirs);
}
}
} // end namespace MinimalLib
} // end namespace RDKit