-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathas2_main.py
153 lines (143 loc) · 3.68 KB
/
as2_main.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/python
import os
cwd=os.getcwd()
cwd = cwd + '/'
f2= open(cwd +'as2_temp_script.py',"r")
file_1=open(cwd +'Active_site1', "r")
ar=[]
data=[]
ar=f2.read()
temp= 'Ligand'
##pdbfile name incorporation
inf_t=[]
inp= open(cwd +'inputfile.txt',"r")
with inp as ins:
ins = [line.rstrip('\n') for line in ins]
for line in ins:
inf_t=line
inf_t2=inf_t.rstrip('.pdb')
inp.close()
flag_inputfile=0
if os.path.isfile("inputfile.pdb"):
flag_inputfile=1
if(flag_inputfile==1):
gl_input="inputfile.pdb"
if(flag_inputfile==0):
gl_input=inf_t
##lig data seperation
input_file ='Active_site2'
f3= open(cwd + input_file,"r")
tnol=0
with f3 as ins:
ins = [line.rstrip('\n') for line in ins]
for line in ins:
data.append(line)
tnol=tnol+1
#print tnol
##reading ligands
data_lig=[]
with file_1 as ins:
ins = [line.rstrip('\n') for line in ins]
for line in ins:
data_lig.append(line)
#metal
metal_data=[]
metal_present=1
f_metal= open('metal_1',"r")
metal_data_t=f_metal.readlines()
if(len(metal_data_t)==1):
metal_present=0
if(len(metal_data_t)>1):
for i in metal_data_t[1:]:
i=i.rstrip('\n')
metal_data.append(i)
#print data_lig
nlig=len(data_lig)-1
temps=[]
for t_i in range(0,len(data_lig)-1):
temps.append('Ligand'+ str(t_i))
#print temps
if(len(data)==1):
print "no lingands"
if(len(data)>1):
for i in range (0, nlig):
print i
tmp_file=('as2_script_ligand' + str(i) + '.py')
tmp_file_gl=('as2_gl_ligand' + str(i) + '.py')
f1= open(cwd +tmp_file,"w+")
f1_gl= open(cwd +tmp_file_gl,"w+")
f1.write('import pymol \nfrom pymol import stored\nfrom pymol import cmd, CmdException\ncmd=pymol.cmd\ninput_file=\'')
f1_gl.write('import pymol\nimport export_to_gl as glmol \nfrom pymol import stored\nfrom pymol import cmd, CmdException\ncmd=pymol.cmd\nmodelName=\'inputfile\'\n')
f1.write(inf_t)
f1.write("\'\ncmd.load( input_file , \'%s\' )\nmodelName=\'%s\'\n"%(inf_t2, inf_t2))
f1.write('\nprint \"Ligand')
f1_gl.write('\nprint \"Ligand')
f1.write(str(i))
f1_gl.write(str(i))
f1.write('- %s\"\nligands=[]\nligand_1'%(data_lig[i+1]))
f1_gl.write('- %s\"\nligands=[]\nligand_1'%(data_lig[i+1]))
f1.write('=\'%s\'\n'%(data_lig[i+1]))
f1_gl.write('=\'%s\'\n'%(data_lig[i+1]))
#metal data write
if(metal_present==1):
f1.write('metals=[')
f1_gl.write('metals=[')
#f1.write(data)
t_m=0;
k_m=len(metal_data)
#print metal_data
for i_m in metal_data:
f1.write('\'')
f1_gl.write('\'')
i_m=i_m.rstrip('\n')
f1.write(str(i_m))
f1_gl.write(str(i_m))
if (t_m<k_m-1):
f1.write('\',')
f1_gl.write('\',')
t_m=t_m+1
f1.write('\']\n')
f1_gl.write('\']\n')
else:
f1.write('metals=[]\n')
f1_gl.write('metals=[]\n')
## lig data
f1.write('lig_data=')
f1_gl.write('lig_data=')
#k=0
t=0
#print i, data_s, data_e
data_2=[]
temps_flag=0
temp_data=[]
for j in data:
if(j==temps[i]):
temps_flag=1
if(i<nlig-1):
if(j==temps[i+1]):
temps_flag=0
if(temps_flag==1):
temp_data.append(j)
#print k:
if(len(temp_data)==1):
f1.write('[]\n')
f1_gl.write('[]\n')
if(len(temp_data)>1):
f1.write('%s'%temp_data[1:])
f1_gl.write('%s'%temp_data[1:])
f1.write('\n')
f1_gl.write('\n')
f1.write('\n')
f1_gl.write('\n')
f1.write(ar)
f1_gl.write(ar)
f1.write('\nout_atoms()\n')
f1_gl.write('\ndef t_run():')
temp_ssn= ('as2_ligand' + str(i) + '.png')
temp_ifn= ('as2_ligand' + str(i) + '.html')
f1_gl.write("\n\tinput_file=\'%s\'\n\tmodelName=\'inputfile\'\n\tcmd.load( input_file , \'inputfile\')\n\tout_atoms()\n\tglmol.dump_rep(modelName,\'%s\',\'%s\')\n\tpymol.cmd.quit()\nt_run()\n"%(gl_input,temp_ssn,temp_ifn))
f3.close()
f1.close()
f1_gl.close()
f2.close()
file_1.close()