foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Error message for missing component files is sub-optimal

Open roccomoretti opened this issue 3 months ago • 0 comments

If you have a path entry in a json setup file for a CIF file (e.g. as with 7o1r_from_json.json ), and you misspell the filename or otherwise don't have the CIF file in the proper path, you get a voluminous set of traceback outputs. There is a useful error message in there, but unfortunately it's buried. (The message is followed by a "The above exception was the direct cause of the following exception" traceback, so finding the actual error message is difficult.)

python3.12/site-packages/biotite/structure/io/pdbx/cif.py:866 in read                                                                                                                                                                                                                                                                                     │
│                                                                                                                                                                                                                                                                                                                                                                                                 │
│    863 │   │   """                                                                              ╭─────────── locals ───────────╮                                                                                                                                                                                                                                                                │
│    864 │   │   # File name                                                                      │ file = PosixPath('NAGG.cif') │                                                                                                                                                                                                                                                                │
│    865 │   │   if is_open_compatible(file):                                                     ╰──────────────────────────────╯                                                                                                                                                                                                                                                                │
│ ❱  866 │   │   │   with open(file, "r") as f:                                                                                                                                                                                                                                                                                                                                                   │
│    867 │   │   │   │   text = f.read()                                                                                                                                                                                                                                                                                                                                                          │
│    868 │   │   # File object                                                                                                                                                                                                                                                                                                                                                                    │
│    869 │   │   else:                                                                                                                                                                                                                                                                                                                                                                            │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
FileNotFoundError: [Errno 2] No such file or directory: 'NAGG.cif'

The above exception was the direct cause of the following exception:

... many, many lines of traceback ...

python3.12/site-packages/hydra/_internal/instantiate/_instantiate2.py:97 in _call_target                                                                                                                                                                                                                                                                  │
│                                                                                                                                                                                                                                                                                                                                                                                                 │
│    94 │   │   │   msg = f"Error in call to target '{_convert_target_to_string(_target_)}':\n{r ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── locals ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮                                     │
│    95 │   │   │   if full_key:                                                                 │ _partial_ = False                                                                                                                                                                                                                                        │                                     │
│    96 │   │   │   │   msg += f"\nfull_key: {full_key}"                                         │      args = ()                                                                                                                                                                                                                                           │                                     │
│ ❱  97 │   │   │   raise InstantiationException(msg) from e                                     │  full_key = ''                                                                                                                                                                                                                                           │                                     │
│    98                                                                                          │    kwargs = {'ckpt_path': 'rf3_latest.pt', 'inputs': '7o1r.json', 'out_dir': './', 'num_nodes': 1, 'devices_per_node': 1, 'n_recycles': 10, 'diffusion_batch_size': 5, 'num_steps': 50, 'solver': 'af3', 'early_stopping_plddt_threshold': 0.5, ... +13} │                                     │
│    99                                                                                          │       msg = "Error in call to target 'modelhub.inference_engines.rf3.RF3InferenceEngine':\nFil"+46                                                                                                                                                       │                                     │
│   100 def _convert_target_to_string(t: Any) -> Any:                                            │         v = PosixPath('/tmp/tmpwk4yxdcm')                                                                                                                                                                                                                │                                     │
│                                                                                                ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                     │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
InstantiationException: Error in call to target 'modelhub.inference_engines.rf3.RF3InferenceEngine':
FileNotFoundError(2, 'No such file or directory')

It looks like a missing/misspelled SDF file avoids the issue, putting the "the file is missing" error message directly at the end of the output:

python3.12/site-packages/atomworks/io/tools/rdkit.py:469 in sdf_to_rdkit                                                                                                                                                                                                                                                                                  │
│                                                                                                                                                                                                                                                                                                                                                                                                 │
│   466 │   │   - TypeError: If the input is neither a StringIO buffer nor a valid path          ╭──────────── locals ─────────────╮                                                                                                                                                                                                                                                              │
│   467 │   """                                                                                  │           sanitize = True       │                                                                                                                                                                                                                                                              │
│   468 │   if isinstance(sdf_path_or_buffer, str | PathLike):                                   │ sdf_path_or_buffer = 'HEMM.sdf' │                                                                                                                                                                                                                                                              │
│ ❱ 469 │   │   supplier = Chem.SDMolSupplier(str(sdf_path_or_buffer), sanitize=sanitize)        ╰─────────────────────────────────╯                                                                                                                                                                                                                                                              │
│   470 │   elif isinstance(sdf_path_or_buffer, io.StringIO):                                                                                                                                                                                                                                                                                                                                     │
│   471 │   │   supplier = Chem.SDMolSupplier(sdf_path_or_buffer, sanitize=sanitize)                                                                                                                                                                                                                                                                                                              │
│   472 │   else:                                                                                                                                                                                                                                                                                                                                                                                 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
OSError: File error: Bad input file HEMM.sdf

... many, many lines of traceback ...

python3.12/site-packages/hydra/_internal/instantiate/_instantiate2.py:97 in _call_target                                                                                                                                                                                                                                                                  │
│                                                                                                                                                                                                                                                                                                                                                                                                 │
│    94 │   │   │   msg = f"Error in call to target '{_convert_target_to_string(_target_)}':\n{r ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── locals ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮                                     │
│    95 │   │   │   if full_key:                                                                 │ _partial_ = False                                                                                                                                                                                                                                        │                                     │
│    96 │   │   │   │   msg += f"\nfull_key: {full_key}"                                         │      args = ()                                                                                                                                                                                                                                           │                                     │
│ ❱  97 │   │   │   raise InstantiationException(msg) from e                                     │  full_key = ''                                                                                                                                                                                                                                           │                                     │
│    98                                                                                          │    kwargs = {'ckpt_path': 'rf3_latest.pt', 'inputs': '7o1r.json', 'out_dir': './', 'num_nodes': 1, 'devices_per_node': 1, 'n_recycles': 10, 'diffusion_batch_size': 5, 'num_steps': 50, 'solver': 'af3', 'early_stopping_plddt_threshold': 0.5, ... +13} │                                     │
│    99                                                                                          │       msg = "Error in call to target 'modelhub.inference_engines.rf3.RF3InferenceEngine':\nOSE"+43                                                                                                                                                       │                                     │
│   100 def _convert_target_to_string(t: Any) -> Any:                                            │         v = PosixPath('/tmp/tmppf7cjbmq')                                                                                                                                                                                                                │                                     │
│                                                                                                ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                     │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
InstantiationException: Error in call to target 'modelhub.inference_engines.rf3.RF3InferenceEngine':
OSError('File error: Bad input file HEMM.sdf')

Ideally a missing CIF file should have similar useful error reporting as a missing SDF file.

roccomoretti avatar Sep 30 '25 23:09 roccomoretti