Fix RDKit 2025.09 compatibility for deprecated valence API#108
Fix RDKit 2025.09 compatibility for deprecated valence API#108evasnow1992 wants to merge 2 commits intoNVIDIA-Digital-Bio:mainfrom
Conversation
RDKit 2025.09+ deprecates getExplicitValence()/getImplicitValence() in favor of getValence(ValenceType::EXPLICIT/IMPLICIT). The previous version guard (#if RDKIT_VERSION_NUM) was non-functional because RDKIT_VERSION_NUM is not defined in any RDKit version — the conda-forge librdkit-dev ships unsubstituted CMake template placeholders in versions.h. Replace with SFINAE-based compile-time detection: checks if RDKit::Atom::ValenceType exists as a nested type. If present (2025+), uses the new API; if absent (2024), falls back to the old API with deprecation warnings suppressed via pragma. Zero runtime cost. Also suppress deprecation warnings in test_molecules.cu for the same API calls used in test helper functions.
|
| Filename | Overview |
|---|---|
| src/utils/rdkit_compat.h | New SFINAE compatibility header that correctly detects RDKit::Atom::ValenceType at compile time and dispatches to either the new getValence() API (2025.09+) or the deprecated getExplicitValence()/getImplicitValence() with suppressed warnings. Logic is sound for C++20. |
| src/substruct/molecules.cpp | Replaces the non-functional #if RDKIT_VERSION_NUM guard with calls to the new compat helpers. Minor: <RDGeneral/versions.h> is now an unused include since the only consumer (RDKIT_VERSION_NUM) was removed. |
| tests/test_molecules.cu | Test helper now calls nvMolKit::compat::getExplicitValence/getImplicitValence instead of the deprecated API directly, keeping the test consistent with production code and resolving the previous review thread's concern. |
Last reviewed commit: 65a064d
Extract SFINAE-based valence compat helpers from molecules.cpp into src/utils/rdkit_compat.h so both production code and tests use the same compile-time dispatch. Removes pragma workarounds from test_molecules.cu in favor of nvMolKit::compat::getExplicitValence() and getImplicitValence(). When RDKit removes the deprecated API, only rdkit_compat.h needs updating.
|
|
||
| // RDKit 2025.09+ deprecates getExplicitValence()/getImplicitValence() | ||
| // in favor of getValence(ValenceType). Detect at compile time via SFINAE. | ||
| template <typename T, typename = void> struct HasValenceType : std::false_type {}; |
There was a problem hiding this comment.
Since we switched to c++20, most things that SFINAE were used for are better represented with concepts. Like:
template <typename T>
concept HasValenceType = requires { typename T::ValenceType; };
Then in the implementation, it should be as simple as
if constexpr (HasValenceType<RDKit::Atom>) {
// modern path
} else {
// legacy path
}
RDKit 2025.09+ deprecates getExplicitValence()/getImplicitValence() in favor of getValence(ValenceType::EXPLICIT/IMPLICIT). The previous version guard (#if RDKIT_VERSION_NUM) was non-functional because RDKIT_VERSION_NUM is not defined in any RDKit version — the conda-forge librdkit-dev ships unsubstituted CMake template placeholders in versions.h.
Replace with SFINAE-based compile-time detection: checks if RDKit::Atom::ValenceType exists as a nested type. If present (2025+), uses the new API; if absent (2024), falls back to the old API with deprecation warnings suppressed via pragma. Zero runtime cost.
Also suppress deprecation warnings in test_molecules.cu for the same API calls used in test helper functions.