-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch_pdb.py
31 lines (26 loc) · 1.03 KB
/
fetch_pdb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import urllib.request
def download_pdb(pdb_id, filename=None):
"""
指定された PDB ID を参照して、PDB ファイルをダウンロードし、
given_ID.pdb として保存します。
Parameters:
pdb_id (str): PDB の ID(例: '1ABC')
filename (str): 保存するファイル名(指定しない場合は given_ID.pdb として保存)
"""
pdb_id = pdb_id.lower()
url = f"https://files.rcsb.org/download/{pdb_id}.pdb"
if not filename:
filename = f"{pdb_id}.pdb"
try:
urllib.request.urlretrieve(url, filename)
print(f"PDB file for {pdb_id} downloaded as {filename}")
except Exception as e:
print(f"Failed to download PDB file for {pdb_id}: {e}")
# 使用例
pdb_id = input("Enter PDB ID (q to quit): ")
if pdb_id == "q":
exit()
output_file = input("Enter output filename(if not provided, pdb_id.pdb will be created in current directory): ")
if output_file == "":
output_file = "./" + pdb_id + ".pdb"
download_pdb(pdb_id, output_file)