2 Interface to HB+ command line program
7 from ost
import settings
14 def _LocateHBPlus(hbplus_bin):
15 return settings.Locate(
'hbplus', explicit_file_name=hbplus_bin,
23 def _ParseOutput(ent, output):
27 for index, line
in enumerate(lines):
28 if line.startswith(
'<---DONOR---> <-ACCEPTOR-->'):
32 if len(line.strip())==0:
35 don_rnum=int(line[1:5])
43 acc_rnum=int(line[15:19])
50 donor=ent.FindAtom(don_chain,
mol.ResNum(don_rnum, don_ins_c),
52 acc=ent.FindAtom(acc_chain,
mol.ResNum(acc_rnum, acc_ins_c),
54 assert donor.IsValid()
56 hbonds.append(
HBond(donor, acc))
61 returns a list of HBonds found in the given entity (handle or view)
63 full_bin=_LocateHBPlus(hbplus_bin)
64 temp_d=tempfile.mkdtemp(prefix=
'hbplus_')
65 hb_proc=subprocess.Popen(full_bin, shell=
True, stdout=subprocess.PIPE,
66 stdin=subprocess.PIPE)
67 file_name=os.path.join(temp_d,
'ent.pdb')
68 io.SaveEntity(ent, file_name)
69 hb_proc.stdin.write(
'%s\n' % temp_d)
70 hb_proc.stdin.write(
'%s\n\n' % file_name)
71 for line
in hb_proc.stdout:
72 match=re.match(
r'Configured for (\d+) atoms and\s+(\d+) residues\.', line)
74 assert ent.atom_count<int(match.group(1))
75 assert ent.residue_count<int(match.group(2))
76 hb_out=open(os.path.join(temp_d,
'ent.hb2'),
'r')
77 hbonds=_ParseOutput(ent, hb_out)
78 os.system('rm -rf "%s"' % temp_d)
83 returns percentage of hydrogen bonds in ent1 that are also present in ent2 in
86 this function is slow as hell, and could be improved drastically by first
87 sorting the hydrogen bond lists by donor residue number.
90 hbonds_a=
HBondList(ent1, hbplus_bin=hbplus_bin)
91 hbonds_b=
HBondList(ent2, hbplus_bin=hbplus_bin)
96 acc_names_match=b.acceptor.name==a.acceptor.name
97 don_names_match=b.donor.name==a.donor.name
98 don_num=b.donor.residue.number==a.donor.residue.number
99 acc_num=b.acceptor.residue.number==a.acceptor.residue.number
100 if acc_names_match
and don_names_match
and acc_num
and don_num:
106 return float(matching)/len(hbonds_a)
110 if __name__==
'__main__':
111 print 'HBond Score:',
HBondScore(io.LoadPDB(sys.argv[1]),
112 io.LoadPDB(sys.argv[2]))