Skip to content
Browse files

Use urlretrieve to smartly download PDB archives

Reading the entire contents into memory with urlopen is a bad idea. With
large crystal structures, it can result in saving an incomplete .gz
archive (raising an Exception on retrieve_pdb_file). Let urllib handle
downloading the file instead.
  • Loading branch information...
1 parent f676792 commit 7282e80ed6a65a10c5c624b2a7ec787656437a15 @DavidCain DavidCain committed with etal Jan 9, 2013
Showing with 3 additions and 3 deletions.
  1. +3 −3 Bio/PDB/PDBList.py
View
6 Bio/PDB/PDBList.py
@@ -25,7 +25,8 @@
import gzip
import os
import shutil
-from urllib2 import urlopen as _urlopen
+import urllib
+from urllib2 import urlopen as _urlopen # urllib made too many FTP conn's
import warnings
from Bio import BiopythonDeprecationWarning
@@ -237,8 +238,7 @@ def retrieve_pdb_file(self,pdb_code, obsolete=0, compression=None,
# Retrieve the file
print "Downloading PDB structure '%s'..." % pdb_code
- lines = _urlopen(url).read()
- open(filename,'wb').write(lines)
+ urllib.urlretrieve(url, filename)
# Uncompress the file
gz = gzip.open(filename, 'rb')

0 comments on commit 7282e80

Please sign in to comment.
Something went wrong with that request. Please try again.