From 4e15e70b3085649ade46241ad3da9025ae89be94 Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@unibas.ch>
Date: Sun, 31 Dec 2023 14:48:38 +0100
Subject: [PATCH] mmcif writer: better checking for valid resnums in resnum
 based alignments

---
 modules/io/src/mol/mmcif_writer.cc | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/modules/io/src/mol/mmcif_writer.cc b/modules/io/src/mol/mmcif_writer.cc
index d3a0aa4f1..8d3afe053 100644
--- a/modules/io/src/mol/mmcif_writer.cc
+++ b/modules/io/src/mol/mmcif_writer.cc
@@ -559,12 +559,26 @@ namespace {
     int num_mon_ids = info.mon_ids.size();
     for(auto res: res_list) {
       int num = res.GetNumber().GetNum();
+      char ins_code = res.GetNumber().GetInsCode();
       if(num < 1) {
         std::stringstream ss;
-        ss << "Cannot perform resnum based alignment with invalid resnum in ";
-        ss << "residue " << res;
+        ss << "Try to construct resnum based alignments. Negative residue ";
+        ss << "numbers are not allowed in this case. Got: ";
+        ss << num << " in residue " << res;
+        ss << ". You may set mmcif_conform flag to False to write something ";
+        ss << "but be aware of the consequences...";
         throw ost::io::IOException(ss.str());
-      } else if (num > num_mon_ids) {
+      }
+      if(ins_code != '\0') {
+        std::stringstream ss;
+        ss << "Try to construct resnum based alignments. Insertion codes ";
+        ss << "are not allowed in this case. Got: ";
+        ss << ins_code << " in residue " << res;
+        ss << ". You may set mmcif_conform flag to False to write something ";
+        ss << "but be aware of the consequences...";
+        throw ost::io::IOException(ss.str());
+      }
+      if (num > num_mon_ids) {
         ++n_beyond;
       } else {
         if(info.mon_ids[num-1] == "-") {
-- 
GitLab