From 53a6eb5840edcee41ceb02395f20319c28774af3 Mon Sep 17 00:00:00 2001
From: Xavier Robin <xavalias-github@xavier.robin.name>
Date: Thu, 1 Jun 2023 18:49:59 +0200
Subject: [PATCH] fix: permit trailing blank space in atoms block

---
 modules/io/src/mol/sdf_reader.cc | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/modules/io/src/mol/sdf_reader.cc b/modules/io/src/mol/sdf_reader.cc
index ec84d1a01..9c832e6ae 100644
--- a/modules/io/src/mol/sdf_reader.cc
+++ b/modules/io/src/mol/sdf_reader.cc
@@ -188,9 +188,15 @@ void SDFReader::ParseAndAddAtom(const String& line, int line_num,
   LOG_TRACE( "line: [" << line << "]" );
 
   if(line.length()<48 || line.length()>69) {
-    String msg="Bad atom line %d: Not correct number of characters on the"
-               " line: %i (should be between 48 and 69)";
-    throw IOException(str(format(msg) % line_num % line.length()));
+    // Handle the case where we have trailing space characters
+    if (line.length()>69 && boost::trim_copy(line.substr(69)) == "") {
+      LOG_DEBUG( "Ignoring trailing space" );
+    }
+    else {
+      String msg="Bad atom line %d: Not correct number of characters on the"
+                 " line: %i (should be between 48 and 69)";
+      throw IOException(str(format(msg) % line_num % line.length()));
+    }
   }
   int anum = line_num-4;  // start at 1 on fifth line since first four lines are header
   String s_posx=line.substr(0,10);
@@ -255,7 +261,7 @@ void SDFReader::ParseAndAddBond(const String& line, int line_num,
   if(line.length()<9 || line.length()>21) {
     // Handle the case where we have trailing space characters
     if (line.length()>21 && boost::trim_copy(line.substr(21)) == "") {
-      LOG_ERROR( "Ignoring trailing space" );
+      LOG_DEBUG( "Ignoring trailing space" );
     }
     else {
       String msg="Bad bond line %d: Not correct number of characters on the"
-- 
GitLab