Skip to content

Commit

Permalink
Make CorrectForPH respect perceived chains.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikw committed Mar 5, 2024
1 parent 32cf131 commit 1e20208
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/phmodel.cpp
Expand Up @@ -154,6 +154,8 @@ namespace OpenBabel
if (mol.GetDimension() > 0 && !mol.AutomaticFormalCharge())
return;

bool hasChainsPerceived = mol.HasChainsPerceived();

mol.SetCorrectedForPH();

obErrorLog.ThrowError(__FUNCTION__,
Expand Down Expand Up @@ -197,6 +199,10 @@ namespace OpenBabel
}
}

if (hasChainsPerceived)
{
mol.SetChainsPerceived();
}
}


Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions test/regressionstest.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1e20208

Please sign in to comment.