1

我一直在尝试从蛋白质数据库下载 .pdb 文件。我编写了以下代码块来提取这些文件,但是我正在下载的文件包含网页。

#Sector C - Processing block:
RefinedPDBCodeList = [] #C1
with open('RefinedPDBCodeList') as inputfile:
    for line in inputfile:
         RefinedPDBCodeList.append(line.strip().split(','))

print(RefinedPDBCodeList[0])
['101m.pdb']

import urllib.request      
for i in range(0, 1): #S2 - range(0, len(RefinedPDBCodeList)):
    path=urllib.request.urlretrieve('http://www.rcsb.org/pdb/explore/explore.do?structureId=101m', '101m.pdb')
4

3 回答 3

6

看来您的基本网址错误。请尝试:

urllib.request.urlretrieve('http://files.rcsb.org/download/101M.pdb', '101m.pdb')
于 2016-05-19T23:44:47.137 回答
1

BioPython 提供了一种检索方法PDBList.retrieve_pdb_file。但是,这依赖于 PDB FTP 服务。如果由于某种原因(防火墙等)未打开 FTP 端口,则可以使用此功能:

def download_pdb(pdbcode, datadir, downloadurl="https://files.rcsb.org/download/"):
    """
    Downloads a PDB file from the Internet and saves it in a data directory.
    :param pdbcode: The standard PDB ID e.g. '3ICB' or '3icb'
    :param datadir: The directory where the downloaded file will be saved
    :param downloadurl: The base PDB download URL, cf.
        `https://www.rcsb.org/pages/download/http#structures` for details
    :return: the full path to the downloaded PDB file or None if something went wrong
    """
    pdbfn = pdbcode + ".pdb"
    url = downloadurl + pdbfn
    outfnm = os.path.join(datadir, pdbfn)
    try:
        urllib.request.urlretrieve(url, outfnm)
        return outfnm
    except Exception as err:
        print(str(err), file=sys.stderr)
        return None
于 2021-01-31T13:25:11.833 回答
0

该 URL 已被更新(虽然旧 URL 暂时重定向到新 URL):

urllib.request.urlretrieve('https://files.rcsb.org/download/101M.pdb', '101m.pdb')

请参阅https://www.rcsb.org/pdb/static.do?p=download/http/index.html以获取 RCSB PDB 提供的不同下载的完整 URL 列表。

于 2017-12-15T17:23:44.100 回答