diff --git a/modules/io/tests/test_io_pdb.cc b/modules/io/tests/test_io_pdb.cc
index eab0673e8ba3d02079d5f07a7f43ee27323ecf61..6a055b83fe0624cf9cb783162bc1028039b055ed 100644
--- a/modules/io/tests/test_io_pdb.cc
+++ b/modules/io/tests/test_io_pdb.cc
@@ -582,6 +582,25 @@ BOOST_AUTO_TEST_CASE(write_ter5)
                             "testfiles/pdb/ter_view-emptychain-out.pdb"));
 }
 
+BOOST_AUTO_TEST_CASE(write_ter6)
+{
+  String fname("testfiles/pdb/ter4.pdb");  
+  // this scope is required to force the writer stream to be closed before 
+  // opening the file again in compare_files. Avoids a race condition.
+  {
+    PDBReader reader(fname, IOProfile());
+    PDBWriter writer(String("testfiles/pdb/ter4-out.pdb"), IOProfile());
+    
+    mol::EntityHandle ent=mol::CreateEntity();
+    reader.Import(ent);
+    conop::Conopology& conop_inst=conop::Conopology::Instance();
+    conop_inst.ConnectAll(conop_inst.GetBuilder(), ent);
+    writer.Write(ent);
+  }
+  BOOST_CHECK(compare_files("testfiles/pdb/ter4.pdb", 
+                            "testfiles/pdb/ter4-out.pdb"));
+}
+
 BOOST_AUTO_TEST_CASE(write_conect)
 {
   // this scope is required to force the writer stream to be closed before
diff --git a/modules/io/tests/testfiles/pdb/ter4.pdb b/modules/io/tests/testfiles/pdb/ter4.pdb
new file mode 100644
index 0000000000000000000000000000000000000000..c952f237ebe84e6f4d24a6b2cf13f1ab9383e4f4
--- /dev/null
+++ b/modules/io/tests/testfiles/pdb/ter4.pdb
@@ -0,0 +1,27 @@
+CRYST1   65.500   65.500  160.000  90.00  90.00  90.00 P 4 2 2   
+ATOM      1  CB  ARG A   5      54.221  28.817  46.886  1.00 80.23      A    C  
+ATOM      2  CG  ARG A   5      54.014  28.661  48.384  1.00 79.76      A    C  
+ATOM      3  CD  ARG A   5      53.901  29.993  49.091  1.00 79.93      A    C  
+ATOM      4  NE  ARG A   5      55.153  30.743  49.053  1.00 79.60      A    N  
+ATOM      5  CZ  ARG A   5      55.375  31.851  49.753  1.00 79.44      A    C  
+ATOM      6  NH1 ARG A   5      54.425  32.333  50.545  1.00 79.21      A    N  
+ATOM      7  NH2 ARG A   5      56.543  32.475  49.661  1.00 79.57      A    N  
+ATOM      8  C   ARG A   5      54.203  27.642  44.665  1.00 80.18      A    C  
+ATOM      9  O   ARG A   5      54.697  26.854  43.860  1.00 80.24      A    O  
+ATOM     10  N   ARG A   5      55.792  26.946  46.486  1.00 80.39      A    N  
+ATOM     11  CA  ARG A   5      54.437  27.479  46.167  1.00 80.33      A    C  
+ATOM     12  N   SER A   6      53.441  28.666  44.297  1.00 80.44      A    N  
+ATOM     13  CA  SER A   6      53.129  28.922  42.897  1.00 80.22      A    C  
+ATOM     14  CB  SER A   6      52.450  30.285  42.745  1.00 79.46      A    C  
+ATOM     15  OG  SER A   6      52.075  30.513  41.398  1.00 79.08      A    O  
+ATOM     16  C   SER A   6      54.371  28.872  42.015  1.00 80.20      A    C  
+ATOM     17  O   SER A   6      54.274  28.620  40.812  1.00 80.66      A    O  
+TER      18      SER A   6                                                      
+ATOM   1680  C44 MC3 B 264      39.239  27.459  24.810  1.00 79.54      B    C  
+ATOM   1681  C43 MC3 B 264      38.743  26.476  23.747  1.00 80.47      B    C  
+TER    1682      MC3 B 264
+ATOM   1726  C44 MC3 C 265      62.635  29.009  23.846  1.00 81.10      C    C  
+ATOM   1727  C43 MC3 C 265      63.065  29.658  22.529  1.00 79.41      C    C  
+ATOM   1728  C42 MC3 C 265      61.857  29.941  21.636  1.00 79.32      C    C  
+TER    1729      MC3 C 265
+END