diff --git a/modules/io/src/mol/pdb_writer.cc b/modules/io/src/mol/pdb_writer.cc
index 2b4379ae33c60476b043bb5df40cd927e3a6acbe..506345758233ec642be9c142d4104f3b178e7c99 100644
--- a/modules/io/src/mol/pdb_writer.cc
+++ b/modules/io/src/mol/pdb_writer.cc
@@ -20,9 +20,14 @@
   Author: Marco Biasini
  */
 #include <locale>
-#include <boost/format.hpp>
+
 #include <string.h>
 
+#include <boost/format.hpp>
+#include <boost/iostreams/filter/gzip.hpp>
+#include <boost/filesystem/convenience.hpp>
+#include <boost/algorithm/string.hpp>
+
 #include <ost/io/io_exception.hh>
 #include <ost/mol/atom_handle.hh>
 #include <ost/mol/residue_handle.hh>
@@ -332,7 +337,7 @@ PDBWriter::PDBWriter(std::ostream& stream, const IOProfile& profile):
   multi_model_(false), charmm_style_(profile.dialect=="CHARMM"), is_pqr_(false),
   profile_(profile)
 {
-  
+  out_.push(outstream_);
 }
 
 PDBWriter::PDBWriter(const boost::filesystem::path& filename, 
@@ -346,19 +351,28 @@ PDBWriter::PDBWriter(const boost::filesystem::path& filename,
   charmm_style_(profile.dialect=="CHARMM"), is_pqr_(false),
   profile_(profile), filename_("")
 {
+  if (boost::iequals(".gz", boost::filesystem::extension(filename))) {
+    out_.push(boost::iostreams::gzip_compressor());
+  }
+  out_.push(outstream_);
 }
 
 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), filename_(filename)
-{}
+{
+  if (boost::iequals(".gz", boost::filesystem::extension(filename))) {
+    out_.push(boost::iostreams::gzip_compressor());
+  }
+  out_.push(outstream_);
+}
 
 void PDBWriter::WriteModelLeader()
 {
   ++mol_count_;
   if (multi_model_) {
-    outstream_ << "MODEL     " << mol_count_ << std::endl;
+    out_ << "MODEL     " << mol_count_ << std::endl;
   } else if (mol_count_>1) {
     throw IOException("Trying to write several models into one file with ");
   }
@@ -367,14 +381,14 @@ void PDBWriter::WriteModelLeader()
 void PDBWriter::WriteModelTrailer()
 {
   if (multi_model_) {
-    outstream_ << "ENDMDL" << std::endl;
+    out_ << "ENDMDL" << std::endl;
   }
 }
 
 template <typename H>
 void PDBWriter::WriteModel(H ent)
 {
-  if (!outstream_) {
+  if (!out_) {
     if (!filename_.empty()) {
       std::stringstream ss;
       ss << "Can't write PDB to file '" << filename_ << "'";
@@ -384,10 +398,10 @@ void PDBWriter::WriteModel(H ent)
   }
   ForcePOSIX posix;
   this->WriteModelLeader();
-  PDBWriterImpl writer(outstream_,line_, atom_indices_, charmm_style_);
+  PDBWriterImpl writer(out_, line_, atom_indices_, charmm_style_);
   writer.SetIsPQR(is_pqr_);
   ent.Apply(writer);
-  PDBConectWriterImpl con_writer(outstream_,atom_indices_);
+  PDBConectWriterImpl con_writer(out_, atom_indices_);
   ent.Apply(con_writer);
   this->WriteModelTrailer();
 }
@@ -410,7 +424,7 @@ void PDBWriter::Write(const mol::AtomHandleList& atoms)
   mol::ChainHandle last_chain;
   for (mol::AtomHandleList::const_iterator i=atoms.begin(),
        e=atoms.end(); i!=e; ++i, ++counter) {
-    write_atom(outstream_, line_, *i, counter, is_pqr_, charmm_style_);
+    write_atom(out_, line_, *i, counter, is_pqr_, charmm_style_);
   }
   this->WriteModelTrailer();
 }
@@ -418,7 +432,7 @@ void PDBWriter::Write(const mol::AtomHandleList& atoms)
   
 PDBWriter::~PDBWriter()
 {
-  outstream_ << "END   ";
+  out_ << "END   ";
 }
 
 }}
diff --git a/modules/io/src/mol/pdb_writer.hh b/modules/io/src/mol/pdb_writer.hh
index b0e70a89f5e3478fdf572798b93a517f4988e173..d12b3219f5cd509cebefea9f1444cdd028ae7b60 100644
--- a/modules/io/src/mol/pdb_writer.hh
+++ b/modules/io/src/mol/pdb_writer.hh
@@ -43,7 +43,9 @@ class EntityHandle;
 
 namespace io {
 
+
 class DLLEXPORT_OST_IO PDBWriter {
+  typedef boost::iostreams::filtering_stream<boost::iostreams::output> OutStream;
 public:
   PDBWriter(const String& filename,
             const IOProfile& profile);
@@ -76,6 +78,7 @@ private:
   bool                is_pqr_;
   IOProfile           profile_;
   String              filename_;
+  OutStream           out_;
 };
  
 }}