Skip to content

Commit 61a11a2

Browse files
author
Massimiliano
committed
Download zipped version of components.cif in buildlib()
1 parent 0bce1dd commit 61a11a2

File tree

1 file changed

+42
-32
lines changed

1 file changed

+42
-32
lines changed

pymmlib/setup.py

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
DISTUTILS_FOUND = True
1919

2020

21+
CIF_URL = "ftp://ftp.wwpdb.org/pub/pdb/data/monomers/components.cif.gz"
22+
23+
2124
class package_install_data(install_data):
2225
def run(self):
2326
## need to change self.install_dir to the actual library dir
@@ -407,44 +410,51 @@ def buildlib(opts):
407410
"""Download and construct the mmLib monomer library.
408411
"""
409412
import urllib2
413+
import zipfile
414+
import gzip
415+
import mmLib.mmCIF
416+
import cStringIO
410417

411418
LIB_FILE = os.path.join("mmLib", "Data", "Monomers.zip")
412419
LIB_PATH = os.path.join("mmLib", "Data", "Monomers")
413-
TMP_PATH = "components.cif"
414-
URL = "ftp://ftp.wwpdb.org/pub/pdb/data/monomers/components.cif"
415-
416-
print "[BUILDLIB] downloading %s" % (URL)
417-
418-
fil = open(TMP_PATH, "w")
419-
420-
furl = urllib2.urlopen(URL)
421-
meta = furl.info()
422-
size = None
423-
if len(meta.getheaders("Content-Length")):
424-
size = int(meta.getheaders("Content-Length")[0])/1000
425-
426-
block_sz = 8192
427-
downloaded = 0
428-
while True:
429-
buffer = furl.read(block_sz)
430-
if not buffer: break
431-
downloaded += len(buffer)
432-
fil.write(buffer)
433-
print "\r[BUILDLIB] progress: %d KB out of %s " % (downloaded/1000,
434-
'--' if not size else str(size)),
435-
fil.close()
436-
print ''
437-
print "[BUILDLIB] constructing library from %s" % (TMP_PATH)
438-
439-
import mmLib.mmCIF
420+
CIF_ARCHIVE_PATH = "components.cif.gz"
421+
CIF_PATH = "components.cif"
422+
423+
if not os.path.exists(CIF_ARCHIVE_PATH) and not os.path.exists(CIF_PATH):
424+
print "[BUILDLIB] downloading %s" % CIF_URL
425+
426+
fil = open(CIF_ARCHIVE_PATH, "w")
427+
428+
furl = urllib2.urlopen(CIF_URL)
429+
meta = furl.info()
430+
size = None
431+
if len(meta.getheaders("Content-Length")):
432+
size = int(meta.getheaders("Content-Length")[0])/1000
433+
434+
block_sz = 8192
435+
downloaded = 0
436+
while True:
437+
buffer = furl.read(block_sz)
438+
if not buffer: break
439+
downloaded += len(buffer)
440+
fil.write(buffer)
441+
print "\r[BUILDLIB] progress: %d KB out of %s " % (downloaded/1000, '--' if not size else str(size)),
442+
print ''
443+
fil.close()
444+
445+
if not os.path.exists(CIF_PATH):
446+
# inflate components.cif
447+
with gzip.open(CIF_ARCHIVE_PATH, 'rb') as zf:
448+
with open(CIF_PATH, 'wb') as f_out:
449+
f_out.writelines(zf)
450+
451+
print "[BUILDLIB] constructing library from %s" % (CIF_PATH)
440452

441453
if opts["zip"]:
442-
import zipfile
443-
import cStringIO
444-
zf = zipfile.ZipFile(LIB_FILE, "w")
454+
zf = zipfile.ZipFile(LIB_FILE, "w", zipfile.ZIP_DEFLATED)
445455

446456
cif_file = mmLib.mmCIF.mmCIFFile()
447-
cif_file.load_file(TMP_PATH)
457+
cif_file.load_file(CIF_PATH)
448458

449459
if not os.path.isdir(LIB_PATH):
450460
os.mkdir(LIB_PATH)
@@ -528,7 +538,7 @@ def usage():
528538
print " Epidoc program."
529539
print " buildlib"
530540
print " Download the RCSB monomer library from"
531-
print " http://pdb.rutgers.edu/public-component-erf.cif and"
541+
print " " + CIF_URL
532542
print " use it to build the mmLib monomer library in"
533543
print " mmLib/Data/Monomers"
534544

0 commit comments

Comments
 (0)