Skip to content
Snippets Groups Projects
Commit b5ddb1e5 authored by Tobias Schmidt's avatar Tobias Schmidt
Browse files

sdf reader complains if file cannot be opened

parent e708cb1f
No related branches found
No related tags found
No related merge requests found
...@@ -36,18 +36,21 @@ namespace ost { namespace io { ...@@ -36,18 +36,21 @@ namespace ost { namespace io {
using boost::format; using boost::format;
SDFReader::SDFReader(const String& filename) SDFReader::SDFReader(const String& filename)
: infile_(filename), instream_(infile_) { : infile_(filename), instream_(infile_)
this->ClearState(); {
this->ClearState(boost::filesystem::path(filename));
} }
SDFReader::SDFReader(const boost::filesystem::path& loc) SDFReader::SDFReader(const boost::filesystem::path& loc)
: infile_(loc), instream_(infile_) { : infile_(loc), instream_(infile_)
this->ClearState(); {
this->ClearState(loc);
} }
SDFReader::SDFReader(std::istream& instream) SDFReader::SDFReader(std::istream& instream)
: infile_(), instream_(instream) { : infile_(), instream_(instream)
this->ClearState(); {
this->ClearState(boost::filesystem::path(""));
} }
// import data from provided stream // import data from provided stream
...@@ -82,7 +85,7 @@ void SDFReader::Import(mol::EntityHandle& ent) ...@@ -82,7 +85,7 @@ void SDFReader::Import(mol::EntityHandle& ent)
} }
curr_chain_.SetStringProp(data_header, data_value); curr_chain_.SetStringProp(data_header, data_value);
} else if (boost::iequals(line, "$$$$")) { } else if (boost::iequals(line, "$$$$")) {
LOG_INFO("MOLECULE " << curr_chain_.GetName() << " (" << chain_count_ << ") added.") LOG_VERBOSE("MOLECULE " << curr_chain_.GetName() << " (" << chain_count_ << ") added.")
NextMolecule(); NextMolecule();
} }
} }
...@@ -91,8 +94,9 @@ void SDFReader::Import(mol::EntityHandle& ent) ...@@ -91,8 +94,9 @@ void SDFReader::Import(mol::EntityHandle& ent)
<< " residues, " << atom_count_ << " atoms"); << " residues, " << atom_count_ << " atoms");
} }
void SDFReader::ClearState() void SDFReader::ClearState(const boost::filesystem::path& loc)
{ {
if(!infile_) throw IOException("could not open "+loc.string());
curr_chain_=mol::ChainHandle(); curr_chain_=mol::ChainHandle();
curr_residue_=mol::ResidueHandle(); curr_residue_=mol::ResidueHandle();
chain_count_=0; chain_count_=0;
......
...@@ -39,7 +39,7 @@ public: ...@@ -39,7 +39,7 @@ public:
void Import(mol::EntityHandle& ent); void Import(mol::EntityHandle& ent);
private: private:
void ClearState(); void ClearState(const boost::filesystem::path& loc);
void NextMolecule(); void NextMolecule();
void ParseAndAddHeader(const String& line, int line_num, mol::EntityHandle& ent, void ParseAndAddHeader(const String& line, int line_num, mol::EntityHandle& ent,
......
...@@ -151,6 +151,13 @@ BOOST_AUTO_TEST_CASE(write_sdf) ...@@ -151,6 +151,13 @@ BOOST_AUTO_TEST_CASE(write_sdf)
"testfiles/sdf/compound-out.sdf")); "testfiles/sdf/compound-out.sdf"));
} }
BOOST_AUTO_TEST_CASE(nonexisting_file)
{
mol::EntityHandle eh=mol::CreateEntity();
EntityIOSDFHandler sdfh;
BOOST_CHECK_THROW(sdfh.Import(eh,"non-existing-file.sdf"), IOException);
}
BOOST_AUTO_TEST_CASE(wrong_atomcount_error_sdf) BOOST_AUTO_TEST_CASE(wrong_atomcount_error_sdf)
{ {
mol::EntityHandle eh=mol::CreateEntity(); mol::EntityHandle eh=mol::CreateEntity();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment