Fix indexing of heavy atoms in PubChemShape (#8417)

* Fix indexing of heavy atoms.

* Increment j. Doh!

* Add include guard for the hpp.

---------

Co-authored-by: David Cosgrove <david@cozchemix.co.uk>
This commit is contained in:
David Cosgrove
2025-04-08 08:41:46 +01:00
committed by GitHub
parent d8dc968eaa
commit 73382748bc
3 changed files with 12 additions and 6 deletions

View File

@@ -283,15 +283,16 @@ ShapeInput PrepareConformer(const ROMol &mol, int confId, bool useColors) {
res.shift = {-ave.x, -ave.y, -ave.z};
res.coord.resize(nAlignmentAtoms * 3);
for (unsigned i = 0; i < nAtoms; ++i) {
for (unsigned i = 0, j = 0; i < nAtoms; ++i) {
// use only non-H for alignment
if (mol.getAtomWithIdx(i)->getAtomicNum() > 1) {
RDGeom::Point3D pos = conformer.getAtomPos(i);
pos -= ave;
res.coord[i * 3] = pos.x;
res.coord[(i * 3) + 1] = pos.y;
res.coord[(i * 3) + 2] = pos.z;
res.coord[j * 3] = pos.x;
res.coord[(j * 3) + 1] = pos.y;
res.coord[(j * 3) + 2] = pos.z;
++j;
}
}

View File

@@ -2,6 +2,9 @@
#include <map>
#include <vector>
#ifndef RDKIT_PUBCHEMSHAPE_GUARD
#define RDKIT_PUBCHEMSHAPE_GUARD
//! The input for the pubchem shape alignment code
struct RDKIT_PUBCHEMSHAPE_EXPORT ShapeInput {
std::vector<float> coord;
@@ -66,3 +69,5 @@ RDKIT_PUBCHEMSHAPE_EXPORT std::pair<double, double> AlignMolecule(
int refConfId = -1, int fitConfId = -1, bool useColors = true,
double opt_param = 1.0, unsigned int max_preiters = 10u,
unsigned int max_postiters = 30u);
#endif

View File

@@ -278,7 +278,7 @@ TEST_CASE("Github #8096") {
REQUIRE(m2);
std::vector<float> matrix(12, 0.0);
auto [nbr_st, nbr_ct] = AlignMolecule(*m1, *m2, matrix);
CHECK_THAT(nbr_st, Catch::Matchers::WithinAbs(0.940, 0.005));
CHECK_THAT(nbr_ct, Catch::Matchers::WithinAbs(0.902, 0.005));
CHECK_THAT(nbr_st, Catch::Matchers::WithinAbs(1.0, 0.005));
CHECK_THAT(nbr_ct, Catch::Matchers::WithinAbs(1.0, 0.005));
}
}