-
Notifications
You must be signed in to change notification settings - Fork 1
/
vinaOut2sdf.py
70 lines (53 loc) · 1.88 KB
/
vinaOut2sdf.py
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
#-------------------------------------------------------------------------
# Author: Yolanda
# Instructions: Vina docking results pdbqt file should be convert to sdf.
# But title (name) lost in pdbqt file, so we match to original mol2.
# Vina score should be added to sdf when converting.
#-------------------------------------------------------------------------
from pybel import *
import os
oridir = './ori_ligands_mol2/'
resdir = './out_ligands_pdbqt/'
oriLst = [i for i in os.listdir(oridir) if i.endswith('mol2')]
resLst = [i for i in os.listdir(resdir) if i.endswith('pdbqt')]
outdir = './out_ligands_sdf/'
if not os.path.exists(outdir): os.mkdir(outdir)
# Title (name) lost in pdbqt file, so we match to original mol2 file.
def matchFile(fres):
num = fres.split('_')[-1].split('.')[0]
a = '_active' in fres
for i in oriLst:
num1 = i.split('_')[-1].split('.')[0]
b = '_active' in i
if num == num1 and a==b:
return i
def getName(fori):
with open(oridir+fori) as f:
f.readline()
name = f.readline().strip()
return name
# Vina score should be added to sdf when converting.
def getVinaScore(fres):
s = ''
with open(resdir+fres) as f:
f.readline()
s = f.readline().strip()
sl = s.split()
if len(sl)>4:
vinaScore = float(sl[3])
return vinaScore
return s
if __name__ == '__main__':
for i,r in enumerate(resLst):
o = matchFile(r)
name = getName(o)
vinaScore = getVinaScore(r)
active = int('_active' in r)
mol = readfile('pdbqt',resdir+r).next()
pdb_s = mol.write('pdb') # First convert to pdb, then to sdf.
mol = readstring('pdb', pdb_s)
mol.title = name
mol.data['vina_score'] = vinaScore
mol.data['Active'] = active
mol.write('sdf',outdir+r[:-5]+'sdf')
print i, name