diff --git a/modules/io/src/mol/sdf_reader.cc b/modules/io/src/mol/sdf_reader.cc index 09dea4696191fd9e0c7878b20776d3ba8aaf6cfa..347da9930744f1b799c44be2f409c98519ce9977 100644 --- a/modules/io/src/mol/sdf_reader.cc +++ b/modules/io/src/mol/sdf_reader.cc @@ -36,18 +36,21 @@ namespace ost { namespace io { using boost::format; SDFReader::SDFReader(const String& filename) - : infile_(filename), instream_(infile_) { - this->ClearState(); + : infile_(filename), instream_(infile_) +{ + this->ClearState(boost::filesystem::path(filename)); } SDFReader::SDFReader(const boost::filesystem::path& loc) - : infile_(loc), instream_(infile_) { - this->ClearState(); + : infile_(loc), instream_(infile_) +{ + this->ClearState(loc); } SDFReader::SDFReader(std::istream& instream) - : infile_(), instream_(instream) { - this->ClearState(); + : infile_(), instream_(instream) +{ + this->ClearState(boost::filesystem::path("")); } // import data from provided stream @@ -82,7 +85,7 @@ void SDFReader::Import(mol::EntityHandle& ent) } curr_chain_.SetStringProp(data_header, data_value); } else if (boost::iequals(line, "$$$$")) { - LOG_INFO("MOLECULE " << curr_chain_.GetName() << " (" << chain_count_ << ") added.") + LOG_VERBOSE("MOLECULE " << curr_chain_.GetName() << " (" << chain_count_ << ") added.") NextMolecule(); } } @@ -91,8 +94,9 @@ void SDFReader::Import(mol::EntityHandle& ent) << " 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_residue_=mol::ResidueHandle(); chain_count_=0; diff --git a/modules/io/src/mol/sdf_reader.hh b/modules/io/src/mol/sdf_reader.hh index 0401e6ab746b3a0a86c738599071ecb5b50f6b79..3beacc0311bf602053c1d88beab5cc29237d1915 100644 --- a/modules/io/src/mol/sdf_reader.hh +++ b/modules/io/src/mol/sdf_reader.hh @@ -39,7 +39,7 @@ public: void Import(mol::EntityHandle& ent); private: - void ClearState(); + void ClearState(const boost::filesystem::path& loc); void NextMolecule(); void ParseAndAddHeader(const String& line, int line_num, mol::EntityHandle& ent, diff --git a/modules/io/tests/test_io_sdf.cc b/modules/io/tests/test_io_sdf.cc index db108e4c52e35ef12c3e9fb7abe1c03a3216e841..08ae8d80ccd475ed20d9c2c5dba3791609149ef7 100644 --- a/modules/io/tests/test_io_sdf.cc +++ b/modules/io/tests/test_io_sdf.cc @@ -151,6 +151,13 @@ BOOST_AUTO_TEST_CASE(write_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) { mol::EntityHandle eh=mol::CreateEntity();