diff --git a/modules/io/src/mol/pdb_reader.cc b/modules/io/src/mol/pdb_reader.cc index 7bafa40a0db2c538dc0d6e883bde35fc90896960..a1e1b0718e2c04b5cd2f44d404621deb4050d918 100644 --- a/modules/io/src/mol/pdb_reader.cc +++ b/modules/io/src/mol/pdb_reader.cc @@ -647,6 +647,16 @@ void PDBReader::ParseAndAddAtom(const StringRef& line, int line_num, ++atom_count_; } } else { + mol::AtomHandle atom=curr_residue_.FindAtom(aname); + if (atom.IsValid()) { + if (profile_.fault_tolerant) { + LOG_WARNING("duplicate atom '" << aname << "' in residue " + << curr_residue_); + return; + } + throw IOException("duplicate atom '"+aname+"' in residue "+ + curr_residue_.GetQualifiedName()); + } ah=editor.InsertAtom(curr_residue_, aname, apos, s_ele); ++atom_count_; } diff --git a/modules/io/tests/test_io_pdb.cc b/modules/io/tests/test_io_pdb.cc index 878a645d3b9e8c560f37ca387c4976d493e099c6..3b5335eef7ea65a265feb73c23b0c3d7608e1fb0 100644 --- a/modules/io/tests/test_io_pdb.cc +++ b/modules/io/tests/test_io_pdb.cc @@ -463,6 +463,28 @@ BOOST_AUTO_TEST_CASE(res_name_mismatch_pedantic) BOOST_CHECK_THROW(reader.Import(ent), IOException); } +BOOST_AUTO_TEST_CASE(duplicate_atom_strict) +{ + String fname("testfiles/pdb/more-than-one-name.pdb"); + IOProfile profile; + PDBReader reader(fname, profile); + mol::EntityHandle ent=mol::CreateEntity(); + BOOST_CHECK_THROW(reader.Import(ent), IOException); +} + +BOOST_AUTO_TEST_CASE(duplicate_atom_tolerant) +{ + String fname("testfiles/pdb/duplicate-atom.pdb"); + IOProfile profile; + profile.fault_tolerant=true; + PDBReader reader(fname, profile); + mol::EntityHandle ent=mol::CreateEntity(); + BOOST_CHECK_NO_THROW(reader.Import(ent)); + BOOST_CHECK_EQUAL(ent.GetChainCount(), 1); + BOOST_CHECK_EQUAL(ent.GetResidueCount(), 1); + BOOST_CHECK_EQUAL(ent.GetAtomCount(), 2); +} + BOOST_AUTO_TEST_CASE(res_name_mismatch_tolerant) { String fname("testfiles/pdb/more-than-one-name.pdb"); diff --git a/modules/io/tests/testfiles/pdb/duplicate-atom.pdb b/modules/io/tests/testfiles/pdb/duplicate-atom.pdb new file mode 100644 index 0000000000000000000000000000000000000000..0cc10b3c820ab49e256a17969de501b88da1b9f3 --- /dev/null +++ b/modules/io/tests/testfiles/pdb/duplicate-atom.pdb @@ -0,0 +1,4 @@ +ATOM 1 N GLU A 7 6.454 -37.820 25.751 1.00 96.94 N +ATOM 2 CA GLU A 7 5.179 -37.470 26.444 1.00 97.55 C +ATOM 2 CA GLU A 7 5.179 -37.470 26.444 1.00 97.55 C +END \ No newline at end of file