Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CorrectForPH respect perceived chains. #2678

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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