From d4dcb0b9b76205d6f44342383ad880905ffe8a47 Mon Sep 17 00:00:00 2001
From: Stefan Bienert <stefan.bienert@unibas.ch>
Date: Mon, 4 Dec 2023 14:21:50 +0100
Subject: [PATCH] Deal with 'nan' coordinates.

---
 projects/novelfams/translate2modelcif.py | 27 +++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/projects/novelfams/translate2modelcif.py b/projects/novelfams/translate2modelcif.py
index ce8456b..2abf204 100644
--- a/projects/novelfams/translate2modelcif.py
+++ b/projects/novelfams/translate2modelcif.py
@@ -261,9 +261,23 @@ def _get_sequence(chn, use_auth=False):
     return sqe
 
 
+class _InvalidCoordinateError(RuntimeError):
+    """Exception for weird coordinates ina PDB file, used internally to skip
+    such PDB files."""
+
+
 def _get_entities(pdb_file, fam_name):
     """Gather data for the mmCIF (target) entities."""
-    ost_ent = io.LoadPDB(pdb_file)
+    try:
+        ost_ent = io.LoadPDB(pdb_file)
+    except Exception as exc:
+        if str(exc).startswith("invalid coordinate on line "):
+            _warn_msg(
+                f"PDB file '{pdb_file}' containes invalid coordinate(s)."
+            )
+            raise _InvalidCoordinateError() from exc
+        _warn_msg(f"Exception for '{pdb_file}'")
+        raise
     if ost_ent.chain_count != 1:
         raise RuntimeError(f"Unexpected oligomer in {pdb_file}")
     chn = ost_ent.chains[0]
@@ -579,11 +593,14 @@ def _main():
     print(f"Processing {n_mdls} models.")
     tmstmp = s_tmstmp
     for f_name in sorted(pdb_files):
-        _translate2modelcif(
-            f_name,
-            opts,
-        )
         n_mdls -= 1
+        try:
+            _translate2modelcif(
+                f_name,
+                opts,
+            )
+        except _InvalidCoordinateError:
+            continue
 
         # report progress after a bit of time
         if timer() - tmstmp > 60:
-- 
GitLab