-
Notifications
You must be signed in to change notification settings - Fork 0
/
PED_VS.py
119 lines (100 loc) · 4.64 KB
/
PED_VS.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# ********************************************************************************************************************************
# *************************** A VIRTUAL SCREENING SOFTWARE BASED ON PED MOLECULAR DESCRIPTORS ************************************
# ********************************************************************************************************************************
# Antonio Oliver Gelabert ( ORCID : http://orcid.org/0000-0001-8571-2733 )
# March, 2020
# For more details and citation : https://www.nature.com/articles/srep43738
# *******************************************************************************************************************************
# PARAMETERS
#
# EXAMPLE USAGE
import os
import numpy as np
import pandas as pd
import argparse
directory_in_str="."
directory = os.fsencode(directory_in_str)
#t0= tm.clock()
# Parsing optional arguments of the program
ap = argparse.ArgumentParser()
ap.add_argument("-iq", "--iq", required=False, default='query.mol2', help="3D query filename file")
ap.add_argument("-fmin", "--filtmin", required=False, default='1', help="Mininum distance filter (in Amstrongs). Default value: 1 Amstrong")
ap.add_argument("-fmax", "--filtmax", required=False, default='99999999', help="maximum area filter (in Amstrongs). Default value:no limit")
args = vars(ap.parse_args())
# Assign args to program variables
fquery=args["iq"]
fmax=float(args["filtmax"])
fmin=float(args["filtmin"])
mdesc=[]
sim=[]
desf = open('PED_comp_'+fquery+'_vs_mol2files.shd', 'w')
scores= open('PED_comp_'+fquery+'_vs_mol2files_scores.shd', 'w')
desf.write('u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,label,S\n')
for file in os.listdir(directory):
filename = os.fsdecode(file)
file=fquery
fat = open("atoms.txt", 'w')
fat.write("Id Atype x y z Otype Str1 Str2 Charge\n")
with open(file) as f:
for line in f:
if line.rstrip() == "@<TRIPOS>ATOM":
print("")
for line in f:
if line.rstrip() == "@<TRIPOS>BOND":
break
fat.write(line.rstrip()+'\n')
fat.close()
df=pd.read_csv('atoms.txt', delimiter=r"\s+")
Eij=[]
for index, row in df.iterrows():
# print(row['x'], row['y'],row['z'],row['Charge'])
for index2, row2 in df.iterrows():
if(index2>index):
dij=((row['x']-row2['x'])**2+(row['y']-row2['y'])**2+(row['z']-row2['z'])**2)**0.5
if(dij > 1.0):
Eij.append(row['Charge']*row2['Charge']/dij*14.4)
PED=[]
Eij.sort(reverse = True)
PED.extend(Eij[0:6])
PED.extend(Eij[len(Eij)-6:len(Eij)])
if filename.endswith(".mol2"):
file=filename
fat = open("atoms.txt", 'w')
fat.write("Id Atype x y z Otype Str1 Str2 Charge\n")
with open(file) as f:
for line in f:
if line.rstrip() == "@<TRIPOS>ATOM":
for line in f:
if line.rstrip() == "@<TRIPOS>BOND":
break
fat.write(line.rstrip()+'\n')
fat.close()
df=pd.read_csv('atoms.txt', delimiter=r"\s+")
Eij=[]
for index, row in df.iterrows():
for index2, row2 in df.iterrows():
if(index2>index):
dij=((row['x']-row2['x'])**2+(row['y']-row2['y'])**2+(row['z']-row2['z'])**2)**0.5
if(dij > fmin) & (dij < fmax):
Eij.append(row['Charge']*row2['Charge']/dij*14.4)
PED2=[]
Eij.sort(reverse = True)
PED2.extend(Eij[0:6])
PED2.extend(Eij[len(Eij)-6:len(Eij)])
MhD=0.0
for i in range(0,len(PED2)-1):
MhD=MhD+1/12*np.absolute(PED[i]-PED2[i])
S=1.0/(1.0+MhD)
scores.write(filename+','+str(np.round(S,4))+'\n')
fat.close()
sim.append(S)
mdesc.extend(PED)
desf.write(str(round(PED2[0],4))+','+str(round(PED2[1],4))+','+str(round(PED2[2],4))+','+str(round(PED2[3],4))+','+str(round(PED2[4],4))+','+str(round(PED2[5],4))+','+str(round(PED2[6],4))+','+str(round(PED2[7],4))+','+str(round(PED2[8],4))+','+str(round(PED2[9],4))+','+str(round(PED2[10],4))+','+str(round(PED2[11],4))+', '+filename+','+str(round(S,4))+'\n')
desf.close()
df=pd.read_csv('PED_comp_'+fquery+'_vs_mol2files.shd')
dfs=df.sort_values(by='S', ascending=False)
desfs = open('PED_comp_'+fquery+'_vs_ranked.shd', 'w')
#for index, row in desfs.iterrows():
desfs.write(str(dfs))
desfs.close()
scores.close()