From 07ad0998da33f33ce285c0a1a2cb6ca9d42ce899 Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@stud.unibas.ch>
Date: Fri, 6 Sep 2013 14:03:21 +0200
Subject: [PATCH] avoid crash, when terminal residuename consists of 4 letters

Standard residue names have three letters. In case of the CHARMM
dialect, also four letters are allowed. This has been neglected
when writing the terminal residue.
---
 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 bdb445f6c..1e4d46e0f 100644
--- a/modules/io/src/mol/pdb_writer.cc
+++ b/modules/io/src/mol/pdb_writer.cc
@@ -290,7 +290,12 @@ public:
     counter_++;
     line_(0, 6)=StringRef("TER   ", 6);
     write_serial(counter_, line_);
-    line_(17, 3)=fmt::LPadded(res.GetKey());
+    if(charmm_style_){
+      line_(17, 4)=fmt::RPadded(res.GetKey());
+    }
+    else{
+      line_(17, 3)=fmt::LPadded(res.GetKey()); 
+    }
     if (!res.GetChain().GetName().empty() && !charmm_style_) {
       line_[21]=res.GetChain().GetName()[0];
     }
-- 
GitLab