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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
dali_file = "dali.txt"
pdb_dir = "dali_pdb"
max_pairs = 10
def fetch_pdb(pdbCode,outFile):
try:
import urllib.request as urllib
except ImportError:
import urllib
import gzip
import os
remoteCode = pdbCode.upper()
if not os.path.exists(pdb_dir):
os.mkdir(pdb_dir)
if not os.path.exists(outFile):
try:
filename = urllib.urlretrieve(
'http://www.rcsb.org/pdb/cgi/export.cgi/' +
remoteCode + '.pdb.gz?format=PDB&pdbId=' +
remoteCode + '&compression=gz')[0]
except:
print("warning: %s not found.\n"%pdbCode)
else:
if (os.path.getsize(filename) > 0): # If 0, then pdb code was invalid
try:
abort = 0
open(outFile, 'w').write(gzip.open(filename).read())
print("fetched: %s"%(pdbCode))
except IOError:
abort = 1
if abort:
os.remove(outFile)
else:
print("warning: %s not valid.\n"%pdbCode)
os.remove(filename)
from pymol import cmd
strip = lambda s: s.strip()
import os
seen = {}
input = open(dali_file).readlines()
input_state = 0
while 1:
try:
line = input.pop(0)
except IndexError:
break
if input_state == 0:
if line[0:11]=='## MATRICES':
line = input.pop(0)
if line[0:12]==' NR. STRID1':
input_state = 1
elif input_state == 1:
if strip(line)=='':
input_state = 2
elif line[4:5]==':':
trg = strip(line[6:12])
src = strip(line[13:19])
trg_code = trg[0:4]
src_code = src[0:4]
if trg_code not in seen:
trg_file = pdb_dir+os.sep+trg_code+".pdb"
fetch_pdb(trg_code,trg_file)
cmd.load(trg_file)
seen[trg_code]=1
if src_code not in seen:
src_file = pdb_dir+os.sep+src_code+".pdb"
fetch_pdb(src_code,src_file)
cmd.load(src_file)
seen[src_code]=1
matrix = []
for a in range(0,3):
matrix.append(float(strip(line[29:38])))
matrix.append(float(strip(line[39:48])))
matrix.append(float(strip(line[49:58])))
matrix.append(float(strip(line[59:78])))
matrix.extend([0.0,0.0,0.0,1.0])
max_pairs = max_pairs - 1
if max_pairs<0:
break
|