* do not remove hydrides by default

* add a minimal test

* add release note about behavior change

* require Hydrides to have degree 1

* also allow hydrides with degree 0 (ionic bond)

* suggested changes

---------

Co-authored-by: greg landrum <greg.landrum@gmail.com>
This commit is contained in:
Ricardo Rodriguez
2025-10-17 10:51:22 -04:00
committed by GitHub
parent 93d0f8bb74
commit d9850596aa
6 changed files with 39 additions and 4 deletions

View File

@@ -901,7 +901,6 @@ bool shouldRemoveH(const RWMol &mol, const Atom *atom,
}
}
}
if (!ps.removeHydrides && atom->getFormalCharge() == -1) {
return false;
}

View File

@@ -332,7 +332,7 @@ struct RDKIT_GRAPHMOL_EXPORT RemoveHsParameters {
bool removeNonimplicit = true; /**< DEPRECATED equivalent of !implicitOnly */
bool updateExplicitCount =
false; /**< DEPRECATED equivalent of updateExplicitCount */
bool removeHydrides = true; /**< Removing Hydrides */
bool removeHydrides = false; /**< Removing Hydrides */
bool removeNontetrahedralNeighbors =
false; /**< remove Hs which are bonded to atoms with specified
non-tetrahedral stereochemistry */

View File

@@ -6397,6 +6397,11 @@ M END
m = Chem.MolFromSmiles('F[H-]F', smips)
ps.removeHigherDegrees = True
m = Chem.RemoveHs(m, ps)
self.assertEqual(m.GetNumAtoms(), 3)
m = Chem.MolFromSmiles('F[H-]F', smips)
ps.removeHigherDegrees = True
ps.removeHydrides = True
m = Chem.RemoveHs(m, ps)
self.assertEqual(m.GetNumAtoms(), 2)
m = Chem.MolFromSmiles('[H][H]', smips)

View File

@@ -1107,6 +1107,14 @@ TEST_CASE("RemoveHsParameters", "[molops]") {
ps.removeHigherDegrees = true;
RWMol cp(*m);
MolOps::removeHs(cp, ps);
CHECK(cp.getNumAtoms() == 3); // b/c removeHydrides is false by default
}
{
MolOps::RemoveHsParameters ps;
ps.removeHigherDegrees = true;
ps.removeHydrides = true;
RWMol cp(*m);
MolOps::removeHs(cp, ps);
CHECK(cp.getNumAtoms() == 2);
}
}
@@ -4925,4 +4933,11 @@ M END)CTAB"_ctab;
REQUIRE(m2);
}
}
}
}
TEST_CASE("large smiles benchmark") {
std::string smiles(1000, 'C');
auto m = v2::SmilesParse::MolFromSmiles(smiles);
REQUIRE(m);
CHECK(m->getNumAtoms() == 1000);
}

View File

@@ -415,4 +415,13 @@ M END)CTAB";
CHECK(mol->getBondBetweenAtoms(10, 8)->getBondType() ==
Bond::BondType::SINGLE);
}
}
TEST_CASE("GitHub #8726: Do not remove hydrides by default") {
auto m = "[OH+][H-]"_smiles;
REQUIRE(m);
CHECK(m->getNumAtoms() == 2);
auto h_atom = m->getAtomWithIdx(1);
CHECK(h_atom->getAtomicNum() == 1);
CHECK(h_atom->getFormalCharge() == -1);
}