-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.py
266 lines (234 loc) · 10.6 KB
/
functions.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
from pymol import cmd
from pymol import math
import numpy
import random
import matplotlib
import matplotlib.pyplot as plt
id=1 #name id
#***********************************************************************
# helper functions
#***********************************************************************
#___________call functions______________________________________________
#Funktionsaufrufe
def choose(Filename1,Filename2,grid,rotation,pathToSave,fileType, angleSteps,choice):
loadFiles(Filename1,Filename2)
if choice==1:
createGrid(grid,rotation,Filename2[:-5],Filename1[:-5],pathToSave,fileType)
if choice==2:
automationGrid(grid,angleSteps,Filename2[:-5],Filename1[:-5],pathToSave,fileType)
if choice==3:
analyse(randomGrid(grid,Filename2[:-5],Filename1[:-5],pathToSave,fileType))
deleteFunction()
#___________load Files__________________________________________________
def loadFiles(FileName1,FileName2):
cmd.reinitialize()
cmd.load(FileName1)
cmd.load(FileName2)
pseudoAtoms()
orientateHalogen(FileName2[:-5])
orientateNitrogen(FileName1[:-5])
#___________get coords from atoms_______________________________________
def getCoords(AtomName):
model = cmd.get_model(AtomName)
coords = []
for atom in model.atom:
coords = atom.coord
return coords
#___________move in origin______________________________________________
def moveOrigin(AtomName,FileName):
NewCoords = getCoords(AtomName)
cmd.translate([NewCoords[0]*(-1), NewCoords[1]*(-1), NewCoords[2]*(-1)],FileName)
#___________define pseudoatoms__________________________________________
def pseudoAtoms():
cmd.pseudoatom("pseudoX", pos=[1,0,0])
cmd.pseudoatom("pseudoY", pos=[0,1,0])
cmd.pseudoatom("pseudoZ", pos=[0,0,1])
cmd.pseudoatom("pseudoXZ", pos=[1,0,1])
cmd.pseudoatom("Oreo", pos=[0,0,0])
cmd.color("pink", "pseudoX")
cmd.color("pink", "pseudoY")
cmd.color("pink", "pseudoZ")
#___________delete all unnecessary_______________________________________
def deleteFunction():
cmd.delete("pseudoX")
cmd.delete("pseudoY")
cmd.delete("pseudoZ")
cmd.delete("pseudoXZ")
cmd.delete("Oreo")
cmd.delete("SecondNeighbor")
cmd.delete("Nitrogen")
cmd.delete("Hydr")
cmd.delete("HydrNeighbor")
cmd.delete("Halogen")
cmd.delete("FirstNeighbor")
cmd.delete("SecondNeighbor")
cmd.delete("SecondAtom")
cmd.delete("NitrogenN")
cmd.delete("NitrogenNH")
cmd.delete("CAtom")
#***********************************************************************
# selection and orientation functions
#***********************************************************************
#___________selection of Nitrogen_______________________________________
def selectNitrogen():
cmd.select ("Nitrogen", "e. N")
cmd.select("Hydr", "e. H")
cmd.select("HydrNeighbor", "neighbor Hydr")
cmd.select("NitrogenNH", "Nitrogen and HydrNeighbor")
cmd.select("NitrogenN", "Nitrogen and not NitrogenNH")
cmd.select("CAtom", "(neighbor NitrogenN) and (neighbor NitrogenNH) ")
#___________selection of Halogen________________________________________
def selectHalogen():
cmd.select("Halogen", "e. Cl or e. Br or e. I")
cmd.select("FirstNeighbor", "neighbor Halogen")
cmd.select("SecondNeighbor", "(neighbor FirstNeighbor) and not Halogen")
model_neighbor=cmd.get_model("SecondNeighbor")
for atom in model_neighbor.atom:
cmd.select("SecondAtom", "id %s and ibenz"%(atom.id))
#___________orientate Halogen___________________________________________
def orientateHalogen(FileName):
selectHalogen()
moveOrigin("Halogen",FileName)
cn=getCoords("FirstNeighbor")
if(cn[0]>0):
rotateY(FileName,-angleY("FirstNeighbor","pseudoZ"),"FirstNeighbor")
else:
rotateY(FileName,angleY("FirstNeighbor","pseudoZ"),"FirstNeighbor")
rotateX(FileName,-angleX("FirstNeighbor","pseudoY"),"FirstNeighbor")
sa=getCoords("SecondAtom")
if(sa[2]>0):
rotateY(FileName,angleY("SecondAtom","pseudoX"),"SecondAtom")
else:
rotateY(FileName,-angleY("SecondAtom","pseudoX"),"SecondAtom")
#___________orientate Nitrogen__________________________________________
def orientateNitrogen(FileName):
selectNitrogen()
moveOrigin("NitrogenN",FileName)
if(getCoords("NitrogenNH")[0]>0):
rotateY(FileName,-angleY("NitrogenNH","pseudoZ"),"NitrogenNH")
else:
rotateY(FileName,angleY("NitrogenNH","pseudoZ"),"NitrogenNH")
if(getCoords("NitrogenNH")[1]>0):
rotateX(FileName,angleX("NitrogenNH","pseudoZ"),"NitrogenNH")
else:
rotateX(FileName,-angleX("NitrogenNH","pseudoZ"),"NitrogenNH")
if(getCoords("CAtom")[1]>0):
rotateZ(FileName,-angleZ("CAtom","pseudoZ"),"CAtom")
else:
rotateZ(FileName,angleZ("CAtom","pseudoZ"),"CAtom")
#___________calculate angle for y-rotation______________________________
def angleY(MoleculeName,Axis):
co=getCoords(MoleculeName)
name = "pseudo_%s"%(MoleculeName)
cmd.pseudoatom(name, pos=[co[0],0,co[2]])
angleY=cmd.get_angle(name,"Oreo",Axis,0)
cmd.delete(name)
return(angleY)
#___________calculate angle for z-rotation______________________________
def angleZ(MoleculeName,Axis):
angleZ = cmd.get_angle("pseudoXZ",Axis,MoleculeName,0)
return(angleZ)
#___________calculate angle for x-rotation______________________________
def angleX(MoleculeName,Axis):
angleX = cmd.get_angle(MoleculeName,"Oreo",Axis,0)
return(angleX)
#___________rotate on y-axis____________________________________________
def rotateY(FileName,Angle,MoleculeName):
cmd.rotate("y",Angle,FileName,0,1,None,"0,0,0")
#___________rotate on x-axis____________________________________________
def rotateX(FileName,Angle,MoleculeName):
cmd.rotate("x",Angle,FileName,0,1,None,"0,0,0")
#___________rotate on z-axis____________________________________________
def rotateZ(FileName,Angle,MoleculeName):
cmd.rotate("z", Angle,FileName,0,1,None,"0,0,0")
#***********************************************************************
# Grid functions
#***********************************************************************
#___________create Grid_________________________________________________
def createGrid(Grid,Rotation,MoleculeName,BotMol,PathToSave,FileType):
cmd.copy("copy_%s" %id,MoleculeName)
rotateAll(Rotation[0],Rotation[1],Rotation[2],"copy_%s" %id)
for i in numpy.arange(-Grid[1]/float(2),(Grid[1]+Grid[3])/float(2),Grid[3]):
for j in numpy.arange(-Grid[0]/float(2),(Grid[0]+Grid[3])/float(2),Grid[3]):
cmd.create("ID_%s_x_%s_y_%s_z_%s_l_%sw_%s"%(id,Rotation[0],Rotation[1],Rotation[2],j,i),"copy_%s" %id)
cmd.translate([i,Grid[2],j],"ID_%s_x_%s_y_%s_z_%s_l_%sw_%s"%(id,Rotation[0],Rotation[1],Rotation[2],j,i))
cmd.select("sID_%s_x_%s_y_%s_z_%s_l_%sw_%s"%(id,Rotation[0],Rotation[1],Rotation[2],j,i),"ID_%s_x_%s_y_%s_z_%s_l_%sw_%s %s"%(id,Rotation[0],Rotation[1],Rotation[2],j,i,BotMol))
cmd.create("mID_%s_x_%s_y_%s_z_%s_l_%sw_%s"%(id,Rotation[0],Rotation[1],Rotation[2],j,i),"sID_%s_x_%s_y_%s_z_%s_l_%sw_%s"%(id,Rotation[0],Rotation[1],Rotation[2],j,i))
cmd.save("%s/_ID_%s_x_%s_y_%s_z_%s_l_%sw_%s.%s"%(PathToSave,id,Rotation[0],Rotation[1],Rotation[2],j,i,FileType),"mID_%s_x_%s_y_%s_z_%s_l_%sw_%s"%(id,Rotation[0],Rotation[1],Rotation[2],j,i))
cmd.delete("sID_%s_x_%s_y_%s_z_%s_l_%sw_%s"%(id,Rotation[0],Rotation[1],Rotation[2],j,i))
cmd.delete("mID_%s_x_%s_y_%s_z_%s_l_%sw_%s"%(id,Rotation[0],Rotation[1],Rotation[2],j,i))
cmd.delete("copy_%s"%id)
global id
id +=1
#___________rotation for Grid___________________________________________
def rotateAll(x,y,z,FileName):
cmd.rotate("z",z,FileName,0,1,None,"0,0,0")
cmd.rotate("x",x,FileName,0,1,None,"0,0,0")
cmd.rotate("y",y,FileName,0,1,None,"0,0,0")
#___________generate automation Grid_____________________________________
def automationGrid(Grid,angleStep,MoleculeName,BotMol,PathToSave,FileType):
for y in numpy.arange(-90,90+angleStep,angleStep):
for x in numpy.arange(-60,60+angleStep,angleStep):
for z in numpy.arange(-60,60+angleStep,angleStep):
createGrid(Grid,[x,y,z],MoleculeName,BotMol,PathToSave,FileType)
#___________generate random Grid_________________________________________
def randomGrid(Grid,MoleculeName,BotMol,PathToSave,FileType):
rand = random.randint(10,20)
randX = []
randY = []
randZ = []
for i in numpy.arange(0,rand):
x = random.randint(-60,60)
y = random.randint(-90,90)
z = random.randint(-60,60)
createGrid(Grid,[x,y,z],MoleculeName,BotMol,PathToSave,FileType)
randX.extend([x])
randY.extend([y])
randZ.extend([z])
return([randX,randY,randZ,rand])
#___________generate analyse for random Grid_____________________________
def analyse(values):
x = numpy.arange(1,values[3]+1)
mx = [numpy.average(values[0]) for i in values[0]]
m1 = [0 for i in values[0]]
fig,ax = plt.subplots()
plt.xlabel('number of simulations')
plt.ylabel('rotation degree')
plt.title('x rotation')
plt.grid(True)
plt.text(0.5,61,'mean = %s'%mx[0])
plt.xticks(numpy.arange(0,values[3]+1,20))
plt.yticks(numpy.arange(-65,65,5))
ax.scatter(x,values[0],label='data',marker='o')
ax.plot(x,mx,label='mean',linestyle='--',c='red')
ax.plot(x,m1,label='zero',linestyle='solid',linewidth=2.5 ,c='black')
ax.legend(loc='upper right')
plt.savefig("xRotation.png")
my = [numpy.average(values[1]) for i in values[1]]
fig,ax = plt.subplots()
plt.xlabel('number of simulations')
plt.ylabel('rotation degree')
plt.title('y rotation')
plt.grid(True)
plt.text(0.5,91,'mean = %s'%my[0])
plt.xticks(numpy.arange(0,values[3]+1,20))
plt.yticks(numpy.arange(-90,90,10))
ax.scatter(x,values[1],label='data',marker='o')
ax.plot(x,my,label='mean',linestyle='--',c='red')
ax.plot(x,m1,label='zero',linestyle='solid',linewidth=2.5 ,c='black')
ax.legend(loc='upper right')
plt.savefig("yRotation.png")
mz = [numpy.average(values[2]) for i in values[2]]
fig,ax = plt.subplots()
plt.xlabel('number of simulations')
plt.ylabel('rotation degree')
plt.title('z rotation')
plt.grid(True)
plt.text(0.5,61,'mean = %s'%mz[0])
plt.xticks(numpy.arange(0,values[3]+1,20))
plt.yticks(numpy.arange(-65,65,5))
ax.scatter(x,values[2],label='data',marker='o')
ax.plot(x,mz,label='mean',linestyle='--',c='red')
ax.plot(x,m1,label='zero',linestyle='solid',linewidth=2.5 ,c='black')
ax.legend(loc='upper right')
plt.savefig("zRotation.png")