From 628a91e85a623fed1e2d253881f7c67c936a3b43 Mon Sep 17 00:00:00 2001
From: B13nch3n <b13nch3n_01@theb-si.de>
Date: Tue, 4 Oct 2022 14:23:10 +0200
Subject: [PATCH] Abort if model of requested rank is not found.

---
 translate2modelcif.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/translate2modelcif.py b/translate2modelcif.py
index ef2bd8d..77f93e7 100644
--- a/translate2modelcif.py
+++ b/translate2modelcif.py
@@ -46,9 +46,10 @@ def _parse_args():
         + "'<UniProtKB AC>-<UniProtKB AC>'",
     )
     parser.add_argument(
-        "--rank", type=str,
+        "--rank",
+        type=str,
         default=None,
-        help="Only process the model with this rank."
+        help="Only process the model with this rank.",
     )
     parser.add_argument(
         "--out_dir",
@@ -946,12 +947,14 @@ def _main():
     config_data = _parse_colabfold_config(cnfg)
 
     # iterate model directory
+    found_ranked = False
     for fle in sorted(os.listdir(opts.model_dir)):
         # iterate PDB files
         if not fle.endswith(".pdb"):
             continue
         if opts.rank is not None and f"rank_{opts.rank}" not in fle:
             continue
+        found_ranked = True
         print(f"  translating {fle}...")
         pdb_start = timer()
         file_prfx, uid = _check_model_extra_files_present(opts.model_dir, fle)
@@ -983,6 +986,8 @@ def _main():
         )
         print(f"  ... done with {fle} ({timer()-pdb_start:.2f}s).")
 
+    if opts.rank and not found_ranked:
+        _abort_msg(f"Could not find model of requested rank '{opts.rank}'")
     print(f"... done with {opts.model_dir}.")
 
 
-- 
GitLab