* Fixes #2224

* test the basics
This commit is contained in:
Greg Landrum
2019-01-21 17:31:02 +01:00
committed by Brian Kelley
parent bac0318ab4
commit 069e920645
4 changed files with 56 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
//
// Copyright (C) 2003-2018 Greg Landrum and Rational Discovery LLC
// Copyright (C) 2003-2019 Greg Landrum and Rational Discovery LLC
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
@@ -567,7 +567,7 @@ void removeHs(RWMol &mol, bool implicitOnly, bool updateExplicitCount,
BOOST_LOG(rdWarningLog)
<< "WARNING: not removing hydrogen atom without neighbors"
<< std::endl;
} else {
} else if (!atom->hasQuery()) {
if (atom->hasProp(common_properties::isImplicit)) {
removeIt = true;
if (atom->getDegree() == 1) {

View File

@@ -1,5 +1,5 @@
//
// Copyright (C) 2001-2017 Greg Landrum and Rational Discovery LLC
// Copyright (C) 2001-2019 Greg Landrum and Rational Discovery LLC
// Copyright (c) 2014, Novartis Institutes for BioMedical Research Inc.
//
// @@ All Rights Reserved @@
@@ -216,6 +216,8 @@ RDKIT_GRAPHMOL_EXPORT void addHs(RWMol &mol, bool explicitOnly = false,
- Hs that are part of the definition of double bond Stereochemistry
will not be removed
- Hs that are not connected to anything else will not be removed
- Hs that have a query defined (i.e. hasQuery() returns true) will not
be removed
- the caller is responsible for <tt>delete</tt>ing the pointer this
returns.

View File

@@ -107,3 +107,33 @@ TEST_CASE("github #299", "[bug, molops, SSSR]"){
}
}
TEST_CASE("github #2224", "[bug, molops, removeHs, query]"){
SECTION("the original report"){
std::string pathName = getenv("RDBASE");
pathName += "/Code/GraphMol/test_data/";
std::unique_ptr<RWMol> mol(MolFileToMol(pathName + "github2224_1.mol"));
REQUIRE(mol);
REQUIRE(mol->getNumAtoms()==7);
}
SECTION("basics") {
SmilesParserParams ps;
ps.removeHs = false;
ps.sanitize = true;
std::unique_ptr<ROMol> mol(SmilesToMol("C[H]", ps));
REQUIRE(mol);
REQUIRE(mol->getNumAtoms()==2);
{ // The H without a query is removed
std::unique_ptr<ROMol> m2(MolOps::removeHs(*mol));
CHECK(m2->getNumAtoms()==1);
}
{ // but if we add a query feature it's not removed
RWMol m2(*mol);
m2.replaceAtom(1,new QueryAtom(1));
m2.getAtomWithIdx(1)->setAtomicNum(1);
MolOps::removeHs(m2);
CHECK(m2.getNumAtoms()==2);
}
}
}

View File

@@ -0,0 +1,21 @@
MJ150720
7 7 1 0 0 0 0 0 0 0999 V2000
-2.5670 0.8362 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-3.2814 0.4237 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-3.2814 -0.4013 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-2.5670 -0.8138 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.8525 -0.4013 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.8525 0.4237 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-2.5670 1.6612 0.0000 L 0 0 0 0 0 0 0 0 0 0 0 0
1 2 2 0 0 0 0
2 3 1 0 0 0 0
3 4 2 0 0 0 0
4 5 1 0 0 0 0
5 6 2 0 0 0 0
6 1 1 0 0 0 0
1 7 1 0 0 0 0
7 F 3 1 6 7
M ALS 7 3 F H C N
M END