|
18 | 18 | DISTUTILS_FOUND = True |
19 | 19 |
|
20 | 20 |
|
| 21 | +CIF_URL = "ftp://ftp.wwpdb.org/pub/pdb/data/monomers/components.cif.gz" |
| 22 | + |
| 23 | + |
21 | 24 | class package_install_data(install_data): |
22 | 25 | def run(self): |
23 | 26 | ## need to change self.install_dir to the actual library dir |
@@ -407,44 +410,51 @@ def buildlib(opts): |
407 | 410 | """Download and construct the mmLib monomer library. |
408 | 411 | """ |
409 | 412 | import urllib2 |
| 413 | + import zipfile |
| 414 | + import gzip |
| 415 | + import mmLib.mmCIF |
| 416 | + import cStringIO |
410 | 417 |
|
411 | 418 | LIB_FILE = os.path.join("mmLib", "Data", "Monomers.zip") |
412 | 419 | 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) |
440 | 452 |
|
441 | 453 | 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) |
445 | 455 |
|
446 | 456 | cif_file = mmLib.mmCIF.mmCIFFile() |
447 | | - cif_file.load_file(TMP_PATH) |
| 457 | + cif_file.load_file(CIF_PATH) |
448 | 458 |
|
449 | 459 | if not os.path.isdir(LIB_PATH): |
450 | 460 | os.mkdir(LIB_PATH) |
@@ -528,7 +538,7 @@ def usage(): |
528 | 538 | print " Epidoc program." |
529 | 539 | print " buildlib" |
530 | 540 | print " Download the RCSB monomer library from" |
531 | | - print " http://pdb.rutgers.edu/public-component-erf.cif and" |
| 541 | + print " " + CIF_URL |
532 | 542 | print " use it to build the mmLib monomer library in" |
533 | 543 | print " mmLib/Data/Monomers" |
534 | 544 |
|
|
0 commit comments