diff --git a/projects/novelfams/translate2modelcif.py b/projects/novelfams/translate2modelcif.py index ce8456bf986149ad6049ada1d4c00d2429182170..2abf2040481a8d01c515e477fdbb97be469b4cc8 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: