From 06358987337811d6bc8314ba635c6a7543f0b78e Mon Sep 17 00:00:00 2001 From: marco <marco@5a81b35b-ba03-0410-adc8-b2c5c5119f08> Date: Mon, 19 Apr 2010 14:54:20 +0000 Subject: [PATCH] don't try to read PDB file past end git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2052 5a81b35b-ba03-0410-adc8-b2c5c5119f08 --- modules/io/src/mol/pdb_io.hh | 4 +++- modules/io/src/mol/pdb_reader.cc | 11 +++++++++-- modules/io/src/mol/pdb_reader.hh | 1 + modules/io/tests/test_io_pdb.cc | 10 +++++++++- modules/io/tests/testfiles/pdb/end.pdb | 3 +++ 5 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 modules/io/tests/testfiles/pdb/end.pdb diff --git a/modules/io/src/mol/pdb_io.hh b/modules/io/src/mol/pdb_io.hh index 54edc8a13..140db87e3 100644 --- a/modules/io/src/mol/pdb_io.hh +++ b/modules/io/src/mol/pdb_io.hh @@ -64,7 +64,9 @@ struct PDB { /// PDB::JOIN_SPREAD_ATOM_RECORDS and CoordGroups. /// /// The atoms are accessible via PDBReader::GetSequentialAtoms() - SEQUENTIAL_ATOM_IMPORT=32 + SEQUENTIAL_ATOM_IMPORT=32, + /// \brief only import C-alpha atoms + CALPHA_ONLY=64 } Type; }; diff --git a/modules/io/src/mol/pdb_reader.cc b/modules/io/src/mol/pdb_reader.cc index e4a68ee11..ec0dbaccb 100644 --- a/modules/io/src/mol/pdb_reader.cc +++ b/modules/io/src/mol/pdb_reader.cc @@ -92,11 +92,15 @@ void PDBReader::Init(const boost::filesystem::path& loc) } else { is_pqr_=false; } + hard_end_=false; } bool PDBReader::HasNext() { + if (hard_end_) { + return false; + } // since helix and sheet have to appear before any atom/hetatm records // a HELIX/SHEET entry implies a next model. while (std::getline(in_, curr_line_) && ++line_num_) { @@ -108,7 +112,8 @@ bool PDBReader::HasNext() IEquals(curr_line.substr(0, 6), StringRef("SHEET ", 6)) || IEquals(curr_line.substr(0, 6), StringRef("HELIX ", 6))) { return true; - } else if (IEquals(curr_line, StringRef("END", 3))) { + } else if (IEquals(curr_line.substr(0, 3), StringRef("END", 3))) { + hard_end_=true; return false; } } @@ -149,6 +154,7 @@ void PDBReader::Import(mol::EntityHandle& ent, continue; } if (IEquals(curr_line.substr(0, 3), StringRef("END", 3))) { + hard_end_=true; go_on=false; break; } @@ -184,7 +190,7 @@ void PDBReader::Import(mol::EntityHandle& ent, default: break; } - } while (std::getline(in_, curr_line_) && ++line_num_); + } while (std::getline(in_, curr_line_) && ++line_num_ && go_on); LOGN_MESSAGE("imported " << chain_count_ << " chains, " << residue_count_ << " residues, " @@ -241,6 +247,7 @@ void PDBReader::ClearState() chain_count_=0; residue_count_=0; atom_count_=0; + hard_end_=false; helix_list_.clear(); strand_list_.clear(); sequential_atom_list_.clear(); diff --git a/modules/io/src/mol/pdb_reader.hh b/modules/io/src/mol/pdb_reader.hh index 5beb44eb3..5c85e23a1 100644 --- a/modules/io/src/mol/pdb_reader.hh +++ b/modules/io/src/mol/pdb_reader.hh @@ -81,6 +81,7 @@ private: int residue_count_; int atom_count_; int line_num_; + bool hard_end_; String restrict_chains_; HSList helix_list_; HSList strand_list_; diff --git a/modules/io/tests/test_io_pdb.cc b/modules/io/tests/test_io_pdb.cc index 8ae918f4f..64f46c26b 100644 --- a/modules/io/tests/test_io_pdb.cc +++ b/modules/io/tests/test_io_pdb.cc @@ -76,7 +76,15 @@ BOOST_AUTO_TEST_CASE(atom_record) BOOST_CHECK_EQUAL(a2.GetProp().occupancy, 1.0); BOOST_CHECK_EQUAL(a2.GetProp().element, "C"); BOOST_CHECK_EQUAL(a2.GetProp().is_hetatm, true); - +} + +BOOST_AUTO_TEST_CASE(end_record) +{ + String fname("testfiles/pdb/end.pdb"); + PDBReader reader(fname); + mol::EntityHandle ent=mol::CreateEntity(); + reader.Import(ent); + BOOST_CHECK_EQUAL(ent.GetAtomCount(), 1); } BOOST_AUTO_TEST_CASE(join_spread_records_on) diff --git a/modules/io/tests/testfiles/pdb/end.pdb b/modules/io/tests/testfiles/pdb/end.pdb new file mode 100644 index 000000000..daf824177 --- /dev/null +++ b/modules/io/tests/testfiles/pdb/end.pdb @@ -0,0 +1,3 @@ +ATOM 1 N MET A 1 16.000 64.000 8.000 0.50 1.00 N +END +ATOM 2 CA MET A 1 32.000-128.000 -2.500 1.00128.00 C -- GitLab