-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use centralized downloading logic for RCSb
- Loading branch information
Showing
2 changed files
with
7 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,15 @@ | ||
# Copyright (c) 2024 Chai Discovery, Inc. | ||
# Licensed under the Apache License, Version 2.0. | ||
# See the LICENSE file for details. | ||
import logging | ||
import urllib.request | ||
from pathlib import Path | ||
|
||
from chai_lab.utils.paths import download_if_not_exists | ||
|
||
|
||
def download_cif_file(pdb_id: str, directory: Path) -> Path: | ||
"""Download the cif file for the given PDB ID from RCSB into the directory.""" | ||
outfile = directory / f"{pdb_id}.cif.gz" | ||
if outfile.is_file() and outfile.stat().st_size > 0: | ||
logging.warning( | ||
f"Destination for {pdb_id=} already exists: {outfile}; will not overwrite" | ||
) | ||
return outfile | ||
source_url = f"https://files.rcsb.org/download/{pdb_id}.cif.gz" | ||
logging.info(f"Fetching {source_url} -> {outfile}") | ||
retrieved, _ = urllib.request.urlretrieve(url=source_url, filename=outfile) | ||
retrieved_path = Path(retrieved) | ||
assert retrieved_path == outfile | ||
assert retrieved_path.exists() and retrieved_path.stat().st_size > 0 | ||
return retrieved_path | ||
download_if_not_exists(source_url, outfile) | ||
assert outfile.exists() and outfile.stat().st_size > 0 | ||
return outfile |
This file contains 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