From 90d361f24675d53a880017d8d7ccd0952b3523b5 Mon Sep 17 00:00:00 2001
From: Xavier Robin <xavier.robin@unibas.ch>
Date: Fri, 2 Feb 2024 16:12:03 +0100
Subject: [PATCH] fix: clean error message for missing compound lib

Until now, the actions were failing with somewhat cryptic messages
raised from arbitrary locations. This one should be more user-friendly.
---
 actions/ost-compare-ligand-structures | 12 ++++++++++++
 actions/ost-compare-structures        | 11 +++++++++++
 2 files changed, 23 insertions(+)

diff --git a/actions/ost-compare-ligand-structures b/actions/ost-compare-ligand-structures
index e8af175af..dd82320f1 100644
--- a/actions/ost-compare-ligand-structures
+++ b/actions/ost-compare-ligand-structures
@@ -56,6 +56,7 @@ and "unassigned_reference_ligands".
 import argparse
 import json
 import os
+import sys
 import traceback
 
 import ost
@@ -295,6 +296,16 @@ def _ParseArgs():
     return parser.parse_args()
 
 
+def _CheckCompoundLib():
+    clib = ost.conop.GetDefaultLib()
+    if not clib:
+        ost.LogError("A compound library is required for this action. "
+                     "Please refer to the OpenStructure website: "
+                     "https://openstructure.org/docs/conop/compoundlib/.")
+        sys.tracebacklimit = 0
+        raise RuntimeError("No compound library found")
+
+
 def _GetStructureFormat(structure_path, sformat=None):
     """Get the structure format and return it as "pdb" or "mmcif".
     """
@@ -580,6 +591,7 @@ def _Process(model, model_ligands, reference, reference_ligands, args):
 def _Main():
 
     args = _ParseArgs()
+    _CheckCompoundLib()
     ost.PushVerbosityLevel(args.verbosity)
     try:
         # Load structures
diff --git a/actions/ost-compare-structures b/actions/ost-compare-structures
index 56b040fb3..6cb962d52 100644
--- a/actions/ost-compare-structures
+++ b/actions/ost-compare-structures
@@ -80,6 +80,7 @@ ost compare-structures -m model.pdb -r reference.cif -c A:B B:A
 import argparse
 import os
 import json
+import sys
 import traceback
 import math
 
@@ -526,6 +527,15 @@ def _ParseArgs():
  
     return parser.parse_args()
 
+def _CheckCompoundLib():
+    clib = ost.conop.GetDefaultLib()
+    if not clib:
+        ost.LogError("A compound library is required for this action. "
+                     "Please refer to the OpenStructure website: "
+                     "https://openstructure.org/docs/conop/compoundlib/.")
+        sys.tracebacklimit = 0
+        raise RuntimeError("No compound library found")
+
 def _RoundOrNone(num, decimals = 3):
     """ Helper to create valid JSON output
     """
@@ -852,6 +862,7 @@ def _Process(model, reference, args, model_format, reference_format):
 def _Main():
 
     args = _ParseArgs()
+    _CheckCompoundLib()
     try:
         compute_cad = args.cad_score or args.local_cad_score
         if compute_cad and not args.residue_number_alignment:
-- 
GitLab