* Fix #8638

* add a test

---------

Co-authored-by: greg landrum <greg.landrum@gmail.com>
This commit is contained in:
Patrick Kunzmann
2025-07-25 14:33:32 +02:00
committed by GitHub
parent 34e80ab764
commit c20b2a906b
2 changed files with 12 additions and 2 deletions

View File

@@ -1442,14 +1442,14 @@ void ResonanceMolSupplier::mainLoop(unsigned int ti, unsigned int nt) {
// atoms and bonds which do not belong to a conjugated group are given
// index -1
void ResonanceMolSupplier::assignConjGrpIdx() {
unsigned int na = d_mol->getNumAtoms();
d_atomConjGrpIdx.resize(na, -1);
unsigned int nb = d_mol->getNumBonds();
if (!nb) {
return;
}
std::stack<unsigned int> bondIndexStack;
d_bondConjGrpIdx.resize(nb, -1);
unsigned int na = d_mol->getNumAtoms();
d_atomConjGrpIdx.resize(na, -1);
for (d_nConjGrp = 0; true; ++d_nConjGrp) {
for (const auto b : d_mol->bonds()) {
unsigned int i = b->getIdx();

View File

@@ -29,6 +29,7 @@
#include <GraphMol/SmilesParse/SmilesParse.h>
#include <GraphMol/SmilesParse/SmilesWrite.h>
#include <GraphMol/SmilesParse/SmartsWrite.h>
#include <GraphMol/Resonance.h>
#include <GraphMol/test_fixtures.h>
using namespace RDKit;
@@ -4837,3 +4838,12 @@ TEST_CASE("clearPropertyCache") {
CHECK(atom->needsUpdatePropertyCache());
}
}
TEST_CASE(
"github #8638: ResonanceMolSupplier raises an error if Mol has no bonds") {
auto mol = "C"_smiles;
REQUIRE(mol);
ResonanceMolSupplier rsuppl(*mol);
CHECK(rsuppl.getNumConjGrps() == 0);
CHECK(rsuppl.getAtomConjGrpIdx(0) == -1);
}