From caa6e1f62e1a4da7c1ad21ee46a73b38309a4779 Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@unibas.ch>
Date: Wed, 24 Jan 2024 09:04:35 +0100
Subject: [PATCH] mmcif writer: bugfix

---
 modules/io/src/mol/mmcif_writer.cc | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/modules/io/src/mol/mmcif_writer.cc b/modules/io/src/mol/mmcif_writer.cc
index 12c31d54a..aaf024717 100644
--- a/modules/io/src/mol/mmcif_writer.cc
+++ b/modules/io/src/mol/mmcif_writer.cc
@@ -1418,15 +1418,18 @@ MMCifWriterEntity MMCifWriterEntity::FromPolymer(const String& entity_poly_type,
   ent.branch_type = "";
   ent.mon_ids = mon_ids;
   for(auto mon_id: mon_ids) {
-    // one letter codes rely on compound library
-    ost::conop::CompoundPtr compound = 
-    compound_lib->FindCompound(mon_id, ost::conop::Compound::PDB);
-    if(compound) {
-      ent.seq_olcs.push_back(MonIDToOLC(mon_id));
-      ent.seq_can_olcs.push_back(String(1, compound->GetOneLetterCode()));
+    ent.seq_olcs.push_back(MonIDToOLC(mon_id));
+    if(ent.seq_olcs.back().size() == 1) {
+      ent.seq_can_olcs.push_back(ent.seq_olcs.back());
     } else {
-      ent.seq_olcs.push_back("(" + mon_id + ")");
-      ent.seq_can_olcs.push_back("(" + mon_id + ")");
+      ost::conop::CompoundPtr compound = 
+      compound_lib->FindCompound(mon_id, ost::conop::Compound::PDB);
+      char olc = compound->GetOneLetterCode();
+      if(olc < 'A' || olc > 'Z') {
+        ent.seq_can_olcs.push_back("(" + mon_id + ")");  
+      } else {
+        ent.seq_can_olcs.push_back(String(1, olc));
+      }
     }
   }
   return ent;
-- 
GitLab