@@ -516,27 +516,27 @@ def _parse_conect(conect):
516
516
range (n_bond_atoms ))
517
517
return atom_id , bond_atoms
518
518
519
- def fetch_pdb (PDB_IDS = None ,
520
- cache_path = None ,
521
- progressbar = False ,
522
- file_format = "pdb.gz" ,
523
- ):
524
-
519
+ def fetch_pdb (
520
+ PDB_IDS = None ,
521
+ cache_path = None ,
522
+ progressbar = False ,
523
+ file_format = "pdb.gz" ,
524
+ ):
525
525
"""
526
526
Download one or more PDB files from the RCSB Protein Data Bank and cache them locally.
527
527
528
528
Given one or multiple PDB IDs, downloads the corresponding structure files in the specified
529
529
format and stores them in a local cache directory. If files are cached on disk, fetch_pdb() will skip the download and use
530
530
the cached version instead.
531
-
531
+
532
532
Returns the path(s) as a string to the downloaded files.
533
533
534
534
Parameters
535
535
----------
536
536
PDB_IDS : str or sequence of str
537
537
A single PDB ID as a string, or a sequence of PDB IDs to fetch.
538
538
cache_path : str or pathlib.Path
539
- Directory where downloaded file(s) will be cached.
539
+ Directory where downloaded file(s) will be cached.
540
540
file_format : str
541
541
The file extension/format to download (e.g., "cif", "pdb")
542
542
progressbar : bool, optional
@@ -552,7 +552,7 @@ def fetch_pdb(PDB_IDS=None,
552
552
------
553
553
requests.exceptions.HTTPError
554
554
If an invalid PDB code or file format is specified.
555
-
555
+
556
556
Notes
557
557
-----
558
558
This function downloads using the API established here at https://www.rcsb.org/docs/programmatic-access/file-download-services.
@@ -580,29 +580,40 @@ def fetch_pdb(PDB_IDS=None,
580
580
[<Universe with 3816 atoms>, <Universe with 2824 atoms>]
581
581
582
582
"""
583
-
584
-
583
+
585
584
try :
586
585
import pooch
587
586
except ModuleNotFoundError :
588
- raise ModuleNotFoundError ('pooch is needed as a dependency for fetch_pdb()' )
587
+ raise ModuleNotFoundError (
588
+ "pooch is needed as a dependency for fetch_pdb()"
589
+ )
589
590
590
591
if isinstance (PDB_IDS , str ):
591
592
PDB_IDS = (PDB_IDS ,)
592
593
593
594
if cache_path is None :
594
- cache_path = pooch .os_cache ('pdb_cache' )
595
+ cache_path = pooch .os_cache ("pdb_cache" )
596
+
597
+ # Have to do this dictionary approach instead of using Pooch.retrieve in order to prevent the hardcoded known_hash warning from showing up.
598
+ registry_dictionary = {
599
+ f"{ PDB_ID } .{ file_format } " : None for PDB_ID in PDB_IDS
600
+ }
595
601
596
- # Have to do this dictionary approach instead of using Pooch.retrieve in order to prevent the hardcoded known_hash warning from showing up
597
- registry_dictionary = {f'{ PDB_ID } .{ file_format } ' : None for PDB_ID in PDB_IDS }
598
-
599
602
downloader = pooch .create (
600
603
path = cache_path ,
601
604
base_url = "https://files.wwpdb.org/download/" ,
602
- registry = registry_dictionary
605
+ registry = registry_dictionary ,
603
606
)
604
607
605
608
if len (PDB_IDS ) == 1 :
606
- return str (downloader .fetch (fname = tuple (registry_dictionary .keys ())[0 ], progressbar = progressbar ))
609
+ return str (
610
+ downloader .fetch (
611
+ fname = tuple (registry_dictionary .keys ())[0 ],
612
+ progressbar = progressbar ,
613
+ )
614
+ )
607
615
else :
608
- return [downloader .fetch (fname = file_name , progressbar = progressbar ) for file_name in registry_dictionary .keys ()]
616
+ return [
617
+ downloader .fetch (fname = file_name , progressbar = progressbar )
618
+ for file_name in registry_dictionary .keys ()
619
+ ]
0 commit comments