From fa854e3ca76ba98f56270524249e8d8bd042f7a8 Mon Sep 17 00:00:00 2001
From: Niklaus Johner <nij2003@med.cornell.edu>
Date: Tue, 14 Feb 2012 16:01:26 -0500
Subject: [PATCH] In the pdb_writer, changed the way atom numbers with more
 than 5 digits are handled.

In 'CHARMM' mode, "*****" are output
whereas in pdb mode, an exception is thrown.
---
 modules/io/src/mol/pdb_writer.cc | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/modules/io/src/mol/pdb_writer.cc b/modules/io/src/mol/pdb_writer.cc
index 6f9c01cb9..e18d96d7f 100644
--- a/modules/io/src/mol/pdb_writer.cc
+++ b/modules/io/src/mol/pdb_writer.cc
@@ -80,7 +80,12 @@ void write_atom(std::ostream& ostr, FormattedLine& line,
   line( 0, 6)=record_name;
   // Avoid writing out atomnumbers larger than 5 digits
   if (atomnum > 99999) {
-    line( 6, 5)=fmt::LPaddedInt(atomnum - 100000 * (atomnum / 100000));
+    if (charmm_style) {
+      line( 6, 5)=fmt::LPadded("*****");
+    } else {
+      throw IOException("Atom number is too long for PDB output." 
+                        " At most 5 digits are allowed");
+    }
   } else {
     line( 6, 5)=fmt::LPaddedInt(atomnum);
   }
-- 
GitLab