From ed96fc9c877277cfd5497c57ef2a3273cfc78945 Mon Sep 17 00:00:00 2001 From: Stefan Bienert <stefan.bienert@unibas.ch> Date: Tue, 5 Dec 2023 09:59:15 +0100 Subject: [PATCH] Handle empty PDB files/ files w/o entities. --- projects/novelfams/translate2modelcif.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/projects/novelfams/translate2modelcif.py b/projects/novelfams/translate2modelcif.py index 2abf204..d4392f0 100644 --- a/projects/novelfams/translate2modelcif.py +++ b/projects/novelfams/translate2modelcif.py @@ -262,7 +262,12 @@ def _get_sequence(chn, use_auth=False): class _InvalidCoordinateError(RuntimeError): - """Exception for weird coordinates ina PDB file, used internally to skip + """Exception for weird coordinates in a PDB file, used internally to skip + such PDB files.""" + + +class _NoEntitiesError(RuntimeError): + """Exception for PDB files w/o entities (empty?), used internally to skip such PDB files.""" @@ -270,6 +275,14 @@ def _get_entities(pdb_file, fam_name): """Gather data for the mmCIF (target) entities.""" try: ost_ent = io.LoadPDB(pdb_file) + except OSError as exc: + if str(exc).endswith(" doesn't contain any entities"): + _warn_msg( + f"PDB file '{pdb_file}' does not have entities (maybe empty)." + ) + raise _NoEntitiesError() from exc + _warn_msg(f"Exception for '{pdb_file}'") + raise except Exception as exc: if str(exc).startswith("invalid coordinate on line "): _warn_msg( @@ -599,7 +612,7 @@ def _main(): f_name, opts, ) - except _InvalidCoordinateError: + except (_InvalidCoordinateError, _NoEntitiesError): continue # report progress after a bit of time -- GitLab