forked from rdkit/rdkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace awful enum reflection macros with Better Enums (rdkit#7913)
* - moved SMILES and RGroupDecomp JSON parsers to their own translation units - added missing DLL export decorators that had been previously forgotten - changed the signatures of MolToCXSmiles and updateCXSmilesFieldsFromJSON to replace enum parameters with the underlying types - updated ReleaseNotes.md * make sure cxSmilesFields is only updated if the JSON string contains keys belonging to the CXSmilesFields enum * added missing copyright notices --------- Co-authored-by: ptosco <[email protected]>
- Loading branch information
Showing
18 changed files
with
374 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,35 @@ | ||
|
||
rdkit_library(RGroupDecomposition RGroupDecomp.cpp RGroupDecompData.cpp RGroupData.cpp RGroupUtils.cpp RGroupCore.cpp | ||
RGroupDecompParams.cpp RGroupScore.cpp RGroupFingerprintScore.cpp RGroupGa.cpp | ||
rdkit_library(RGroupDecomposition RGroupDecomp.cpp RGroupDecompData.cpp | ||
RGroupData.cpp RGroupUtils.cpp RGroupCore.cpp | ||
RGroupDecompParams.cpp RGroupScore.cpp RGroupFingerprintScore.cpp | ||
RGroupGa.cpp RGroupDecompJSONParsers.cpp | ||
LINK_LIBRARIES | ||
FMCS ChemTransforms SubstructMatch SmilesParse Fingerprints | ||
GraphMol RDGeneral ga MolEnumerator TautomerQuery ) | ||
GraphMol RDGeneral ga MolEnumerator TautomerQuery) | ||
target_compile_definitions(RGroupDecomposition PRIVATE RDKIT_RGROUPDECOMPOSITION_BUILD) | ||
|
||
rdkit_headers( | ||
RGroupDecomp.h RGroupDecompParams.h | ||
DEST GraphMol/RGroupDecomposition) | ||
RGroupDecomp.h RGroupDecompParams.h RGroupDecompJSONParsers.h | ||
DEST GraphMol/RGroupDecomposition) | ||
|
||
if(RDK_BUILD_PYTHON_WRAPPERS) | ||
add_subdirectory(Wrap) | ||
add_subdirectory(Wrap) | ||
endif() | ||
|
||
rdkit_test(testRGroupDecomp testRGroupDecomp.cpp | ||
LINK_LIBRARIES RGroupDecomposition ) | ||
LINK_LIBRARIES RGroupDecomposition) | ||
|
||
rdkit_test(testRGroupDecompInternals testRGroupInternals.cpp | ||
LINK_LIBRARIES RGroupDecomposition ) | ||
LINK_LIBRARIES RGroupDecomposition) | ||
|
||
rdkit_catch_test(rgroupCatchTests catch_rgd.cpp | ||
LINK_LIBRARIES RGroupDecomposition ) | ||
LINK_LIBRARIES RGroupDecomposition) | ||
|
||
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS program_options CONFIG) | ||
if(RDK_BUILD_CPP_TESTS AND Boost_FOUND) | ||
add_executable(gaExample GaExample.cpp) | ||
if(NOT Boost_USE_STATIC_LIBS) | ||
target_compile_definitions(gaExample PUBLIC -DBOOST_PROGRAM_OPTIONS_DYN_LINK) | ||
endif() | ||
target_link_libraries(gaExample RGroupDecomposition ${Boost_PROGRAM_OPTIONS_LIBRARY}) | ||
endif() | ||
add_executable(gaExample GaExample.cpp) | ||
if(NOT Boost_USE_STATIC_LIBS) | ||
target_compile_definitions(gaExample PUBLIC -DBOOST_PROGRAM_OPTIONS_DYN_LINK) | ||
endif() | ||
target_link_libraries(gaExample RGroupDecomposition ${Boost_PROGRAM_OPTIONS_LIBRARY}) | ||
endif() |
89 changes: 89 additions & 0 deletions
89
Code/GraphMol/RGroupDecomposition/RGroupDecompJSONParsers.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// | ||
// 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 "RGroupDecompJSONParsers.h" | ||
#include <RDGeneral/BoostStartInclude.h> | ||
#include <boost/property_tree/ptree.hpp> | ||
#include <boost/property_tree/json_parser.hpp> | ||
#include <RDGeneral/BoostEndInclude.h> | ||
|
||
namespace RDKit { | ||
|
||
void updateRGroupDecompositionParametersFromJSON( | ||
RGroupDecompositionParameters ¶ms, const std::string &details_json) { | ||
updateRGroupDecompositionParametersFromJSON(params, details_json.c_str()); | ||
} | ||
|
||
void updateRGroupDecompositionParametersFromJSON( | ||
RGroupDecompositionParameters ¶ms, const char *details_json) { | ||
if (details_json && strlen(details_json)) { | ||
std::istringstream ss; | ||
boost::property_tree::ptree pt; | ||
ss.str(details_json); | ||
boost::property_tree::read_json(ss, pt); | ||
|
||
std::string labels; | ||
labels = pt.get<std::string>("labels", labels); | ||
if (RGroupLabels::_is_valid(labels.c_str())) { | ||
params.labels = RGroupLabels::_from_string(labels.c_str()); | ||
} | ||
|
||
std::string matchingStrategy; | ||
matchingStrategy = | ||
pt.get<std::string>("matchingStrategy", matchingStrategy); | ||
if (RGroupMatching::_is_valid(matchingStrategy.c_str())) { | ||
params.matchingStrategy = | ||
RGroupMatching::_from_string(matchingStrategy.c_str()); | ||
} | ||
|
||
std::string scoreMethod; | ||
scoreMethod = pt.get<std::string>("scoreMethod", scoreMethod); | ||
if (RGroupScore::_is_valid(scoreMethod.c_str())) { | ||
params.scoreMethod = RGroupScore::_from_string(scoreMethod.c_str()); | ||
} | ||
|
||
std::string rgroupLabelling; | ||
rgroupLabelling = pt.get<std::string>("rgroupLabelling", rgroupLabelling); | ||
if (RGroupLabelling::_is_valid(rgroupLabelling.c_str())) { | ||
params.rgroupLabelling = | ||
RGroupLabelling::_from_string(rgroupLabelling.c_str()); | ||
} | ||
|
||
std::string alignment; | ||
alignment = pt.get<std::string>("alignment", alignment); | ||
if (RGroupCoreAlignment::_is_valid(alignment.c_str())) { | ||
params.alignment = RGroupCoreAlignment::_from_string(alignment.c_str()); | ||
} | ||
|
||
params.chunkSize = pt.get<unsigned int>("chunkSize", params.chunkSize); | ||
params.onlyMatchAtRGroups = | ||
pt.get<bool>("onlyMatchAtRGroups", params.onlyMatchAtRGroups); | ||
params.removeAllHydrogenRGroups = pt.get<bool>( | ||
"removeAllHydrogenRGroups", params.removeAllHydrogenRGroups); | ||
params.removeAllHydrogenRGroupsAndLabels = | ||
pt.get<bool>("removeAllHydrogenRGroupsAndLabels", | ||
params.removeAllHydrogenRGroupsAndLabels); | ||
params.removeHydrogensPostMatch = pt.get<bool>( | ||
"removeHydrogensPostMatch", params.removeHydrogensPostMatch); | ||
params.allowNonTerminalRGroups = | ||
pt.get<bool>("allowNonTerminalRGroups", params.allowNonTerminalRGroups); | ||
params.allowMultipleRGroupsOnUnlabelled = | ||
pt.get<bool>("allowMultipleRGroupsOnUnlabelled", | ||
params.allowMultipleRGroupsOnUnlabelled); | ||
params.doTautomers = pt.get<bool>("doTautomers", params.doTautomers); | ||
params.doEnumeration = pt.get<bool>("doEnumeration", params.doEnumeration); | ||
params.includeTargetMolInResults = pt.get<bool>( | ||
"includeTargetMolInResults", params.includeTargetMolInResults); | ||
params.timeout = pt.get<double>("timeout", params.timeout); | ||
} | ||
} | ||
|
||
} // end namespace RDKit |
24 changes: 24 additions & 0 deletions
24
Code/GraphMol/RGroupDecomposition/RGroupDecompJSONParsers.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// 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. | ||
// | ||
|
||
#pragma once | ||
|
||
#include "RGroupDecompParams.h" | ||
|
||
namespace RDKit { | ||
|
||
RDKIT_RGROUPDECOMPOSITION_EXPORT void | ||
updateRGroupDecompositionParametersFromJSON( | ||
RGroupDecompositionParameters ¶ms, const std::string &details_json); | ||
RDKIT_RGROUPDECOMPOSITION_EXPORT void | ||
updateRGroupDecompositionParametersFromJSON( | ||
RGroupDecompositionParameters ¶ms, const char *details_json); | ||
|
||
} // end namespace RDKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.