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

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
parent 8b63a957
Branches
Tags
No related merge requests found
......@@ -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;
};
......
......@@ -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();
......
......@@ -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_;
......
......@@ -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)
......
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment