From 9cc7c4af37d1859aa9a3bf38590e64f4958ee9a2 Mon Sep 17 00:00:00 2001
From: Niklaus Johner <nij2003@med.cornell.edu>
Date: Tue, 7 Feb 2012 13:19:51 -0500
Subject: [PATCH] Allows to write out pdbs with more than 99999 atoms This fix
 simply keeps the last 5 digits of the atom numbers

---
 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 17f891d57..6f9c01cb9 100644
--- a/modules/io/src/mol/pdb_writer.cc
+++ b/modules/io/src/mol/pdb_writer.cc
@@ -78,7 +78,12 @@ void write_atom(std::ostream& ostr, FormattedLine& line,
   
   geom::Vec3 p=atom.GetPos();
   line( 0, 6)=record_name;
-  line( 6, 5)=fmt::LPaddedInt(atomnum);
+  // Avoid writing out atomnumbers larger than 5 digits
+  if (atomnum > 99999) {
+    line( 6, 5)=fmt::LPaddedInt(atomnum - 100000 * (atomnum / 100000));
+  } else {
+    line( 6, 5)=fmt::LPaddedInt(atomnum);
+  }
   String atom_name=atom.GetName();
   if (atom_name.size()>4) {
     throw IOException("Atom name '"+atom.GetQualifiedName()+
-- 
GitLab