Created
August 3, 2021 10:18
-
-
Save alisterburt/d9c1f932498dd1e55ddce48b41e9c741 to your computer and use it in GitHub Desktop.
pdb downloader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| from pathlib import Path | |
| import click | |
| import requests | |
| def download_pdb(accession_code: str, destination: Path): | |
| accession_code = accession_code.upper() | |
| url = f'https://files.rcsb.org/download/{accession_code}.pdb' | |
| request = requests.get(url, allow_redirects=True) | |
| with open(destination, mode='wb') as f: | |
| f.write(request.content) | |
| @click.command() | |
| @click.argument('accession_code') | |
| def cli(accession_code: str): | |
| output_filename = f'{accession_code}.pdb' | |
| download_pdb(accession_code, output_filename) | |
| if __name__ == '__main__': | |
| cli() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment