Skip to content
Snippets Groups Projects
Commit a6f2ea91 authored by marco's avatar marco
Browse files

detect several MODEL records without ENDMDL between them

Because there is nothing that doesn't exist at CASP, stop 
parsing when hitting a second MODEL tag as if there would 
have been and ENDMDL tag (only if SKIP_FAULTY_RECORDS 
flag is set).


git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2102 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent f254484a
No related branches found
No related tags found
No related merge requests found
......@@ -81,6 +81,7 @@ PDBReader::PDBReader(const boost::filesystem::path& loc):
void PDBReader::Init(const boost::filesystem::path& loc)
{
num_model_records_=0;
if (boost::iequals(".gz", boost::filesystem::extension(loc))) {
in_.push(boost::iostreams::gzip_decompressor());
}
......@@ -134,7 +135,7 @@ void PDBReader::Import(mol::EntityHandle& ent,
do {
if (curr_line_.empty()) {
continue;
}
}
StringRef curr_line(curr_line_.c_str(), curr_line_.size());
switch(curr_line[0]) {
case 'A':
......@@ -166,6 +167,7 @@ void PDBReader::Import(mol::EntityHandle& ent,
}
if (IEquals(curr_line.substr(0, 6), StringRef("ENDMDL", 6))) {
go_on=false;
num_model_records_=0;
break;
}
case 'H':
......@@ -182,6 +184,26 @@ void PDBReader::Import(mol::EntityHandle& ent,
} else if (IEquals(curr_line.substr(0, 6), StringRef("HELIX ", 6))) {
this->ParseHelixEntry(curr_line);
}
break;
case 'M':
case 'm':
if (curr_line.size()<6) {
continue;
}
if (IEquals(curr_line.substr(0, 6), StringRef("MODEL ", 6))) {
++num_model_records_;
if (num_model_records_<2) {
continue;
}
if (PDB::Flags() & PDB::SKIP_FAULTY_RECORDS) {
go_on=false;
num_model_records_=1;
break;
}
String msg=str(format("MODEL record without matching ENDMDL on line %d")%line_num_);
throw IOException(msg);
}
break;
case 'S':
case 's':
if (curr_line.size()<6) {
......@@ -190,6 +212,7 @@ void PDBReader::Import(mol::EntityHandle& ent,
if (IEquals(curr_line.substr(0, 6), StringRef("SHEET ", 6))) {
this->ParseStrandEntry(curr_line);
}
break;
default:
break;
}
......
......@@ -72,6 +72,7 @@ private:
int atom_count_;
int line_num_;
bool hard_end_;
int num_model_records_;
String restrict_chains_;
HSList helix_list_;
HSList strand_list_;
......
......@@ -19,6 +19,7 @@
#include <ost/mol/mol.hh>
#include <ost/io/mol/entity_io_pdb_handler.hh>
#include <ost/io/pdb_reader.hh>
#include <ost/io/io_exception.hh>
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
using boost::unit_test_framework::test_suite;
......@@ -179,4 +180,31 @@ BOOST_AUTO_TEST_CASE(only_66_cols)
reader.Import(ent);
}
BOOST_AUTO_TEST_CASE(no_endmdl_record)
{
String fname("testfiles/pdb/model.pdb");
PDBReader reader(fname);
mol::EntityHandle ent=mol::CreateEntity();
BOOST_CHECK_THROW(reader.Import(ent), IOException);
}
BOOST_AUTO_TEST_CASE(no_endmdl_record_fault_tolerant)
{
String fname("testfiles/pdb/model.pdb");
PDBReader reader(fname);
PDB::PushFlags(PDB::SKIP_FAULTY_RECORDS);
mol::EntityHandle ent=mol::CreateEntity();
reader.Import(ent);
BOOST_CHECK_EQUAL(ent.GetChainCount(), 1);
BOOST_CHECK_EQUAL(ent.GetResidueCount(), 1);
BOOST_CHECK_EQUAL(ent.GetAtomCount(), 3);
ent=mol::CreateEntity();
reader.Import(ent);
BOOST_CHECK_EQUAL(ent.GetChainCount(), 1);
BOOST_CHECK_EQUAL(ent.GetResidueCount(), 1);
BOOST_CHECK_EQUAL(ent.GetAtomCount(), 2);
PDB::PopFlags();
}
BOOST_AUTO_TEST_SUITE_END()
MODEL 1
ATOM 1 N SER 1 -84.454 -4.478 -71.554 1.00 29.08
ATOM 2 CA SER 1 -84.657 -3.972 -70.181 1.00 29.08
ATOM 3 CB SER 1 -86.156 -3.976 -69.839 1.00 29.08
MODEL 2
ATOM 1 N SER 1 -84.454 -4.478 -71.554 1.00 29.08
ATOM 2 CA SER 1 -84.657 -3.972 -70.181 1.00 29.08
MODEL 3
ATOM 1 N SER 1 -84.454 -4.478 -71.554 1.00 29.08
ATOM 2 CA SER 1 -84.657 -3.972 -70.181 1.00 29.08
ATOM 3 CB SER 1 -86.156 -3.976 -69.839 1.00 29.08
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment