diff --git a/modules/io/src/mol/pdb_writer.cc b/modules/io/src/mol/pdb_writer.cc index 8878fb16d1a4cd9a47fc6579110529b15d09d3e9..98022a0a55f073fadd7fe4063fddd9bbb462f6be 100644 --- a/modules/io/src/mol/pdb_writer.cc +++ b/modules/io/src/mol/pdb_writer.cc @@ -339,13 +339,14 @@ PDBWriter::PDBWriter(const boost::filesystem::path& filename, #endif mol_count_(0), line_(80), multi_model_(false), charmm_style_(profile.dialect=="CHARMM"), is_pqr_(false), - profile_(profile) -{} + profile_(profile), filename_("") +{ +} PDBWriter::PDBWriter(const String& filename, const IOProfile& profile): outfile_(filename.c_str()), outstream_(outfile_), mol_count_(0), line_(80), multi_model_(false), charmm_style_(profile.dialect=="CHARMM"), - is_pqr_(false), profile_(profile) + is_pqr_(false), profile_(profile), filename_(filename) {} void PDBWriter::WriteModelLeader() @@ -368,6 +369,14 @@ void PDBWriter::WriteModelTrailer() template <typename H> void PDBWriter::WriteModel(H ent) { + if (!outstream_) { + if (!filename_.empty()) { + std::stringstream ss; + ss << "Can't write PDB to file '" << filename_ << "'"; + throw IOException(ss.str()); + } + throw IOException("Can't write PDB. Bad stream"); + } ForcePOSIX posix; this->WriteModelLeader(); PDBWriterImpl writer(outstream_,line_, atom_indices_, charmm_style_); diff --git a/modules/io/src/mol/pdb_writer.hh b/modules/io/src/mol/pdb_writer.hh index c849fd279eb1581f43616f04df8dffbb8c8a78c2..b0e70a89f5e3478fdf572798b93a517f4988e173 100644 --- a/modules/io/src/mol/pdb_writer.hh +++ b/modules/io/src/mol/pdb_writer.hh @@ -75,6 +75,7 @@ private: bool charmm_style_; bool is_pqr_; IOProfile profile_; + String filename_; }; }}