-
Notifications
You must be signed in to change notification settings - Fork 2
/
Multimer.py
executable file
·215 lines (149 loc) · 6.98 KB
/
Multimer.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
# Copyright (c) 2012 EPFL (Ecole Polytechnique federale de Lausanne)
# Laboratory for Biomolecular Modeling, School of Life Sciences
#
# POW is free software ;
# you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation ;
# either version 2 of the License, or (at your option) any later version.
# POW is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY ;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with POW ;
# if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
#
# Author : Matteo Degiacomi, [email protected]
# Web site : http://lbm.epfl.ch
import numpy as np
from Protein import Protein
from copy import deepcopy
import time
class Multimer:
def __init__(self,pdb):
#store a Protein structure
self.pdb = pdb
def _move_extreme_point_to_origin(self):
#get the extreme point on the x axis and move the atom corresponding to it to the origin
xyzMaxIndex = np.argmax(self.monomer,axis=0)
maxAtom = self.monomer[xyzMaxIndex[0]]
self.monomer -= np.array([maxAtom[0],maxAtom[1],0])
def _move_monomer_to_origin(self):
xyzCenter = np.mean(self.monomer,axis=0)
self.monomer -= xyzCenter
def _translate(self):
self.monomer -= np.array([self.radius,0,0])
def _rotation(self):
#angle in numpy need to be given in rad -> rad = deg * pi/180
alpha = np.radians(self.pos[0])
beta = np.radians(self.pos[1])
gamma = np.radians(self.pos[2])
#rotation autour axe x
#|1 0 0 |
#|0 np.cos(alpha) -np.sin(alpha)|
#|0 np.sin(alpha) np.cos(alpha) |
Rx = np.array([[1,0,0], [0, np.cos(alpha), -np.sin(alpha)], [0, np.sin(alpha), np.cos(alpha)]])
Ry = np.array([[np.cos(beta), 0, np.sin(beta)], [0, 1, 0], [-np.sin(beta), 0, np.cos(beta)]])
Rz = np.array([[np.cos(gamma), -np.sin(gamma), 0], [np.sin(gamma), np.cos(gamma), 0], [0,0,1]])
rotation = np.dot(Rx,np.dot(Ry,Rz))
#multiply rotation matrix with each atom of the monomer
self.monomer = np.dot(self.monomer,rotation)
def _circular_symmetry(self):
#create the number of monomer required for the multimer and rotate them around the z axis
for i in xrange(0,self.degree,1):
#number of degree to rotate
self.angle = np.radians(i*(360/self.degree))
#print "angle %s for multimer %s"%(angle,i)
self.Rz = np.array([[np.cos(self.angle), -(np.sin(self.angle)), 0], [(np.sin(self.angle)), (np.cos(self.angle)), 0], [0,0,1]])
self.multimer.append(np.dot(self.monomer,self.Rz))
def _get_max_from_multimer(self):
arrayMax = []
#calculate the position of each monomer maximum and store them in an array
for m in xrange(0,self.degree,1):
arrayMax.append(np.amax(self.multimer[m],axis=0))
#get the maximum among all monomer
maxXYZ = np.amax(arrayMax,axis=0);
return maxXYZ
def _get_min_from_multimer(self):
arrayMin = []
#calculate the position of each monomer minimum and store them in an array
for m in xrange(0,self.degree,1):
arrayMin.append(np.amin(self.multimer[m],axis=0))
#get the minimum among all monomer
minXYZ = np.amin(arrayMin,axis=0);
return minXYZ
def create_multimer(self, degree, radius, pos):
self.degree = degree
self.radius = radius
self.pos = pos
self.multimer = []
self.monomer = deepcopy(self.pdb.data[:,5:8])
self._move_monomer_to_origin()
self._rotation()
self._move_extreme_point_to_origin()
self._translate()
self._circular_symmetry()
def multimer_to_origin(self):
m=self.get_multimer_xyz()
center = np.mean(m,axis=0)
for i in xrange(0,self.degree,1):
self.multimer[i][:,0] -= center[0]
self.multimer[i][:,1] -= center[1]
self.multimer[i][:,2] -= center[2]
def z_to_origin(self):
zCenter = np.mean(self.multimer[0],axis=0)[2]
for i in xrange(0,self.degree,1):
self.multimer[i][:,2] -= zCenter
def z_shift(self,z):
for i in xrange(0,self.degree,1):
self.multimer[i][:,2] += z
def z_rotation(self,angle):
#rotation of the whole assembly around around z
theta = np.radians(angle)
Rz = np.array([[np.cos(theta), -np.sin(theta), 0], [np.sin(theta), np.cos(theta), 0], [0,0,1]])
for i in xrange(0,self.degree,1):
M=self.multimer[i]
self.multimer[i] = np.dot(M,Rz)
def atomselect(self,unit,chain,resid,atom,get_index=False):
[m,index]=self.pdb.atomselect(chain,resid,atom,True)
atoms = self.multimer[unit-1][index]
if get_index==True:
return [atoms, index]
else:
return atoms
def get_width(self):
maxXYZ = self._get_max_from_multimer()
minXYZ = self._get_min_from_multimer()
return(maxXYZ[0]-minXYZ[0])
def get_height(self):
maxXYZ = self._get_max_from_multimer()
minXYZ = self._get_min_from_multimer()
return(maxXYZ[2]-minXYZ[2])
def get_multimer_uxyz(self):
return self.multimer
def get_multimer_xyz(self):
multimerxyz = []
for i in xrange(0,len(self.multimer),1):
multimerxyz.extend(self.multimer[i])
return multimerxyz
def distance(self,atom1,atom2):
#atom1np = np.array(atom1[0])
#atom2np = np.array(atom2[0])
#diff = atom1np - atom2np
#return np.sqrt(np.dot(diff,diff))
d=[]
for i in xrange(0,len(atom1),1):
d.append(np.sqrt(np.sum((atom2-atom1[i])**2,axis=1)))
dist=np.array(d)
return np.min(d)
def write_PDB(self,outname):
chain_converter = ('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z')
f_out=open(outname,"w")
for j in xrange(0,self.degree,1):
self.pdb.set_xyz(self.multimer[j])
#map intergers to characters from input data (default: all the protein)
data_list=self.pdb.mapping(self.pdb.data)
for i in xrange(0,len(data_list),1):
#create and write PDB line
l=(data_list[i][0],data_list[i][1],data_list[i][2],chain_converter[j],data_list[i][4],data_list[i][5],data_list[i][6],data_list[i][7],data_list[i][8],data_list[i][9],data_list[i][10])
L='ATOM %5i %-4s%-4s%1s%4i %8.3f%8.3f%8.3f%6.2f%6.2f %2s\n'%l
f_out.write(L)
f_out.write("TER\n")
f_out.close()