diff --git a/src/phmodel.cpp b/src/phmodel.cpp index 65bef1584..8c653c366 100644 --- a/src/phmodel.cpp +++ b/src/phmodel.cpp @@ -154,6 +154,8 @@ namespace OpenBabel if (mol.GetDimension() > 0 && !mol.AutomaticFormalCharge()) return; + bool hasChainsPerceived = mol.HasChainsPerceived(); + mol.SetCorrectedForPH(); obErrorLog.ThrowError(__FUNCTION__, @@ -197,6 +199,10 @@ namespace OpenBabel } } + if (hasChainsPerceived) + { + mol.SetChainsPerceived(); + } } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0b6a6250b..6c9de0d2e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -40,7 +40,7 @@ set(lssr_parts 1 2 3 4 5) set(isomorphism_parts 1 2 3 4 5 6 7 8 9) set(multicml_parts 1) set(periodic_parts 1 2 3 4) -set(regressions_parts 1 2 221 222 223 224 225 226 227 228 229 240 241 242 1794 2111 2428 2646) +set(regressions_parts 1 2 221 222 223 224 225 226 227 228 229 240 241 242 1794 2111 2428 2646 2677) set(rotor_parts 1 2 3 4) set(shuffle_parts 1 2 3 4 5) set(smiles_parts 1 2 3) diff --git a/test/regressionstest.cpp b/test/regressionstest.cpp index 9057ba198..17bfe163a 100644 --- a/test/regressionstest.cpp +++ b/test/regressionstest.cpp @@ -646,6 +646,21 @@ void test_github_issue_2646() OB_COMPARE(can, "c1ccccc1"); } +// https://github.com/openbabel/openbabel/issues/2677 +void test_github_issue_2677() +{ + // Make sure that CorrectForPH doesn't mess up residues in pdb + OBMolPtr mol = OBTestUtil::ReadFile("1DRF.pdb"); + OB_ASSERT(mol->HasChainsPerceived()); + OBAtom *atom_before = mol->GetAtom(1); + OBResidue *res_before = atom_before->GetResidue(); + mol->AddNewHydrogens(PolarHydrogen, true); + OBAtom *atom_after = mol->GetAtom(1); + OBResidue *res_after = atom_after->GetResidue(); + OB_REQUIRE(res_after != nullptr); + OB_COMPARE(res_after->GetIdx(), res_before->GetIdx()); +} + void test_SegCopySubstructure() { // Invalid memory access (atom->GetIdx()) detected in valgrind and sometimes @@ -754,6 +769,9 @@ int regressionstest(int argc, char *argv[]) case 2646: test_github_issue_2646(); break; + case 2677: + test_github_issue_2677(); + break; // case N: // YOUR_TEST_HERE(); // Remember to update CMakeLists.txt with the number of your test