Downloading all the PDB files available for a protein all at once

457 Views Asked by At

I want to download all the 7000 suggestions of the PDB files of that specific protein in RCSB, How should I proceed?

I know that there is a download option beside each, but is there any shortcut to download all in one set?

1

There are 1 best solutions below

0
anmol_gorakshakar On

If you have a list of all the pdbs that you want to download you can use this function to download the pdb files

from requests import get
import os
def donwload_pdb(pdb_id: str,
                 download_dir: str = os.path.join(os.path.expanduser('~/'), 
                                                  'Downloads')) -> None:
    r = get(f"https://files.rcsb.org/download/{pdb_id.upper()}.pdb")
    open(os.path.join(download_dir, f"{pdb_id.upper()}.pdb"), 'w').write(r.text)
    return
pdbids: list[str] = [1xzy, 2xyz, ...]
for pdbid in pdbids:
    download_pdb(pdb_id = pdbid, donwload_dir='path/to/dir')

PS: change the download dir to a directory that exists. current default only works on macOS.