Skip to content

Fix FileNotFoundError when custom template filenames use upper-case PDB codes or extensions - #851

Open
crfield18 wants to merge 2 commits into
sokrypton:mainfrom
crfield18:main
Open

Fix FileNotFoundError when custom template filenames use upper-case PDB codes or extensions#851
crfield18 wants to merge 2 commits into
sokrypton:mainfrom
crfield18:main

Conversation

@crfield18

Copy link
Copy Markdown

File changed: AlphaFold2.ipynb

Issue

AlphaFold's _get_pdb_id_and_chain (alphafold/data/templates.py) always lowercases the 4-character PDB code before looking up the template file on disk. The notebook saves uploaded custom templates using their original casing:

for fn in uploaded.keys():
    os.rename(fn,os.path.join(custom_template_path,fn))

So uploading e.g. 5HBF.cif causes:

FileNotFoundError: [Errno 2] No such file or directory: '<jobname>/template/5hbf.cif'

Fix

Normalize the filename's stem and extension to lower case before saving:

for fn in uploaded.keys():
    base, ext = os.path.splitext(fn)
    dest_fn = base.lower() + ext.lower()
    os.rename(fn, os.path.join(custom_template_path, dest_fn))
    print(f"saved template: {fn} -> {dest_fn}")

Handles .pdb/.cif uploads in any casing (5HBF.CIF, 5hbf.PDB, etc.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant