2 Interface to HB+ command line program
7 from ost
import settings
15 def _LocateHBPlus(hbplus_bin):
16 return settings.Locate(
'hbplus', explicit_file_name=hbplus_bin,
24 def _ParseOutput(ent, output):
28 for index, line
in enumerate(lines):
29 if line.startswith(
'<---DONOR---> <-ACCEPTOR-->'):
33 if len(line.strip())==0:
36 don_rnum=int(line[1:5])
44 acc_rnum=int(line[15:19])
51 donor=ent.FindAtom(don_chain,
mol.ResNum(don_rnum, don_ins_c),
53 acc=ent.FindAtom(acc_chain,
mol.ResNum(acc_rnum, acc_ins_c),
55 assert donor.IsValid()
57 hbonds.append(
HBond(donor, acc))
62 returns a list of HBonds found in the given entity (handle or view)
64 full_bin=_LocateHBPlus(hbplus_bin)
65 temp_d=tempfile.mkdtemp(prefix=
'hbplus_')
66 file_name=os.path.join(temp_d,
'ent.pdb')
67 io.SaveEntity(ent, file_name)
68 hb_proc=subprocess.Popen(full_bin, shell=
True, stdout=subprocess.PIPE,
69 stdin=subprocess.PIPE)
70 hb_proc.stdin.write((
'%s\n' % temp_d).encode())
71 hb_proc.stdin.write((
'%s\n\n' % file_name).encode())
72 stdout,_ = hb_proc.communicate()
74 for line
in stdout.decode().splitlines():
75 match=re.match(
r'Configured for (\d+) atoms and\s+(\d+) residues\.', line)
77 assert ent.atom_count<int(match.group(1))
78 assert ent.residue_count<int(match.group(2))
79 hb_out=open(os.path.join(temp_d,
'ent.hb2'),
'r')
80 hbonds=_ParseOutput(ent, hb_out)
87 returns percentage of hydrogen bonds in ent1 that are also present in ent2 in
90 this function is slow as hell, and could be improved drastically by first
91 sorting the hydrogen bond lists by donor residue number.
94 hbonds_a=
HBondList(ent1, hbplus_bin=hbplus_bin)
95 hbonds_b=
HBondList(ent2, hbplus_bin=hbplus_bin)
100 acc_names_match=b.acceptor.name==a.acceptor.name
101 don_names_match=b.donor.name==a.donor.name
102 don_num=b.donor.residue.number==a.donor.residue.number
103 acc_num=b.acceptor.residue.number==a.acceptor.residue.number
104 if acc_names_match
and don_names_match
and acc_num
and don_num:
110 return float(matching)/len(hbonds_a)
114 if __name__==
'__main__':
115 print(
'HBond Score:',
HBondScore(io.LoadPDB(sys.argv[1]),
116 io.LoadPDB(sys.argv[2])))