Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
surf_param.py
Go to the documentation of this file.
1 # Import python modules
2 from string import *
3 import math
4 
5 # Import Rosetta modules
6 from rosetta import *
7 from rosetta.protocols.rigid import *
8 import rosetta.core.scoring.solid_surface
9 
10 #============defining objects=====================
11 #Vector objects in Rosetta
12 BodyPosition = rosetta.numeric
13 #for vector, use as body.xyzVector_double
14 
15 #============defining functions====================
16 def load(file):
17  file = open(file, 'r').readlines()
18  loaded_file = []
19  for line in file:
20  loaded_file.append(strip(line))
21  return loaded_file
22 
23 def get_markers(pdb):
24  n=0
25  for atom in pdb:
26  if pdb[n][:6]=='SURFA0':
27  Ax = float(pdb[n][30:38])
28  Ay = float(pdb[n][38:46])
29  Az = float(pdb[n][46:54])
30  SURFA0 = BodyPosition.xyzVector_double(Ax,Ay,Az)
31  if pdb[n][:6]=='SURFA1':
32  Bx = float(pdb[n][30:38])
33  By = float(pdb[n][38:46])
34  Bz = float(pdb[n][46:54])
35  SURFA1 = BodyPosition.xyzVector_double(Bx,By,Bz)
36  if pdb[n][:6]=='SURFA2':
37  Cx = float(pdb[n][30:38])
38  Cy = float(pdb[n][38:46])
39  Cz = float(pdb[n][46:54])
40  SURFA2 = BodyPosition.xyzVector_double(Cx,Cy,Cz)
41  n = n+1
42  return (SURFA0,SURFA1, SURFA2)
43 
44 
45 
46 #==============protein_surfacemove_symmetry==============
47 '''
48 moving protein to the projected center of geometry of surface by symmetry
49 '''
50 #center of geometry of protein P
51 #*****need to define pose and prot_length
52 
53 def centerG_P(pose,prot_length):
54  center_of_geo_prot = BodyPosition.xyzVector_double(0,0,0)
55  for i in range(1, pose.total_residue()+1):
56  if (pose.residue(i).is_protein() == True):
57  ca_pose = pose.residue(i).atom('CA').xyz()
58  center_of_geo_prot = center_of_geo_prot + ca_pose
59  center_of_geo_prot = (center_of_geo_prot/prot_length)
60  return center_of_geo_prot
61 
62 #center of geometry of surface S
63 def centerG_S(pose,prot_length):
64  center_of_geo_surf = BodyPosition.xyzVector_double(0,0,0)
65  for i in range(1, pose.total_residue()+1):
66  if (pose.residue(i).is_ligand() == True):
67  surf_pose = pose.residue(i).xyz(pose.residue(i).nbr_atom())
68  center_of_geo_surf = center_of_geo_surf + surf_pose
69  center_of_geo_surf = (center_of_geo_surf/(pose.total_residue() - prot_length))
70  return center_of_geo_surf
71 
72 #anti parallel vector
74  anti_parallel_vector = vector * -1
75  return anti_parallel_vector
76 
77 #...................Built in rosetta vector stuff.............
78 def length(vector):
79  length = vector.norm
80  return length
81 
82 def unit_vector(vector):
83  unit_vector = vector.normalize()
84  return unit_vector
85 
86 def dot_product(vector1, vector2):
87  dot_product = vector1.dot_product(vector2)
88  return dot_product
89 
90 def inner_product(vector1, vector2):
91  inner_product = vector1.inner_product(vector2)
92  return inner_product
93 
94 def cross_product(vector1, vector2):
95  cross_product = vector1.cross_product(vector2)
96  return cross_product
97 
98 def normal_vector(vector1, vector2):
99  normal_vector = cross_product(vector1, vector2)
100  return normal_vector
101 
102 def normalto3points(pointA, pointB, pointC):
103  vAB = pointB - pointA
104  vAC = pointC - pointA
105  normal = normal_vector(vAB, vAC)
106  return normal
107 
108 #calculate a point from 2 intersecting lines
109 #--------------------------------
110 # |
111 # ---B-*----------
112 # |
113 # C
114 # |
115 
116 def point2lines2(point1, point2, vectorB, vectorC):
117  CB = point2 - point1
118  crossBC = cross_product(vectorB, vectorC)
119  CB_C = cross_product(vectorC, crossBC)
120  DD = dot_product(crossBC,crossBC)
121  t = dot_product(CB, CB_C)/DD
122  intersection = point1 + vectorB * t
123  return intersection
124 
125 #calculate a point from 2 intersected lines
126 def point2lines3(point1, point2, vectorB, vectorC):
127  CB = point2 - point1
128  cross1C = cross_product(CB, vectorC)
129  crossBC = cross_product(vectorB, vectorC)
130  w = dot_product(cross1C, crossBC)
131  DD = inner_product(crossBC, crossBC)
132  t = w/DD
133  intersection = point1 + vectorB * t
134  return intersection
135 
136 #calculate a plane from 3 points; returns A, B, C, D in A(x1-x)+B(y1-y)+C(z1-z)+D=0
137 def plane3points(pointA, pointB, pointC):
138  normal_to_3points = normalto3points(pointA, pointB, pointC)
139  Aplane = normal_to_3points.x
140  Bplane = normal_to_3points.y
141  Cplane = normal_to_3points.z
142  Dplane = -(Aplane*pointA.x + Bplane*pointA.y + Cplane*pointA.z)
143  return (Aplane, Bplane, Cplane, Dplane)
144 
145 #calculate a point in a plane hit from a point out of plane normal
146 def point_intersect_plane(plane_abcd, point_out_of_plane, antiparallel_normal_vector):
147  t = -(plane_abcd[0] * point_out_of_plane.x + plane_abcd[1]* point_out_of_plane.y \
148  + plane_abcd[2]*point_out_of_plane.z + plane_abcd[3])/(plane_abcd[0]*\
149  plane_abcd[0] + plane_abcd[1]*plane_abcd[1] + plane_abcd[2]*plane_abcd[2])
150  point_of_intersection = point_out_of_plane - t * antiparallel_normal_vector
151  return point_of_intersection
152 
153 
154 #print info:
155 #d_Psurfport_cG = length(Psurface_Nprotein, centerG_surface)
156 def print_surf_move(tDistanceB, tDistanceC, Psurface_Nprotein, centerG_surface, CA_centerG_protein, plane0, findProteinZ):
157  print "tDistanceB = "+str(tDistanceB)+" tDistanceC= "+str(tDistanceC)
158  print "distance protein is away from the surface: "+str(length(findProteinZ))
159  print "centerG_surface:"
160  print centerG_surface
161  print "CA_centerG_protein:"
162  print CA_centerG_protein
163  print "the equation plane of surface"
164  print "with with pt= the intersection point of the antiparallel normal vector and the surface plane:"
165  print "("+str(plane0[0])+")*("+str(Psurface_Nprotein.x)+"-x)+("+str(plane0[1])+")*("+str(Psurface_Nprotein.y)+"-y)+("+str(plane0[2])+")*("+str(Psurface_Nprotein.z)+"-z)+("+str(plane0[3])+")=0"
166  print "distance protein is away from the surface: "+str(length(findProteinZ))
167 
168 #Translating
169 def Translate_to_center(pose, start, Translate):
170  dock_jump=start-1
171  Prot_trans=RigidBodyTransMover(pose,dock_jump)
172  Prot_trans.trans_axis(Translate)
173  Prot_trans.step_size(length(Translate))
174  Prot_trans.apply(pose)
175 
176 def Translate_up(pose,start,axis,mag):
177  dock_jump=start-1
178  Prot_trans=RigidBodyTransMover(pose,dock_jump)
179  Prot_trans.trans_axis(axis)
180  Prot_trans.step_size(mag)
181  Prot_trans.apply(pose)
182 
183 
184 #=================vector stuff; the main part=====================
185 def surface_symm_move(pose, start, end, SURFA0, SURFA1, SURFA2):
186 
187  #Define protein length
188  prot_length = end-start+1
189 
190  #center of geometry of protein
191  CA_centerG_protein = centerG_P(pose,prot_length)
192 
193  #center of geometry of surface
194  centerG_surface = centerG_S(pose,prot_length)
195 
196  #initial ABC points
197  surface3pointA0 = SURFA0
198  surface3pointB0 = SURFA1
199  surface3pointC0 = SURFA2
200 
201  #two basis vectors of the surface crystal system; unit cell dimension
202  vAB0 = surface3pointB0 - surface3pointA0
203  vAC0 = surface3pointC0 - surface3pointA0
204 
205  #fix the ABC in the center of surface
206  surface3pointA = centerG_surface
207  surface3pointB = centerG_surface + vAB0
208  surface3pointC = centerG_surface + vAC0
209 
210 
211  vAB = surface3pointB - surface3pointA
212  vAC = surface3pointC - surface3pointA
213 
214  #find the normal vector the surface of the vectors AB, AC
215  Nprotein_to_surface = normalto3points(surface3pointA, surface3pointB, surface3pointC)
216 
217  #vector antiparallel
218  iNprotein_to_surface = anti_parallel_vector(Nprotein_to_surface)
219 
220  #find the equation of the plane
221  plane0 =plane3points(surface3pointA, surface3pointB, surface3pointC)
222 
223  #find the intersection point of the antiparallel normal vector and the surface plane
224  Psurface_Nprotein = point_intersect_plane(plane0, CA_centerG_protein, iNprotein_to_surface)
225 
226  #find the vector difference of the noraml intersection point and the center of geometry of the protein
227  findProteinZ = Psurface_Nprotein - CA_centerG_protein
228 
229  #find the 2 first intersection points
230  IntersectPoint1 = point2lines3(centerG_surface,Psurface_Nprotein, vAC, vAB)
231  IntersectPoint2 = point2lines3(centerG_surface,Psurface_Nprotein, vAB, vAC)
232 
233  #check = normalto3points(centerG_surface, IntersectPoint1, IntersectPoint2)
234  #print "Compare with Nprotein_to_surface:"
235  #print check.normalize()
236 
237  #find the distances from the center of surface parallel AB, AC
238  tCvector = IntersectPoint1 - Psurface_Nprotein
239  tDistanceC = length(tCvector)
240  tBvector = IntersectPoint2 - Psurface_Nprotein
241  tDistanceB = length(tBvector)
242 
243  #begin the criteria to move or not the surface to center the protein
244  ABdistance = length(vAB0)
245  ACdistance = length(vAC0)
246 
247  """
248  #print info: initial
249  """
250  #print "........................coordinates..........................."
251  #print_surf_move(tDistanceB, tDistanceC, Psurface_Nprotein, centerG_surface, CA_centerG_protein, plane0, findProteinZ)
252 
253  """
254  translation conditions
255  """
256 
257  #Initialize translation vector
258  Translate = BodyPosition.xyzVector_double(0.0,0.0,0.0)
259 
260  if (tDistanceC <= ACdistance and tDistanceB <= ABdistance):
261  New_centerG_protein = CA_centerG_protein
262  #print "No move!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
263 
264  else:
265 
266  """
267  Begin move criteria
268  """
269 
270  if (tDistanceC > ACdistance):
271  #print "Yes move C!!!!!!!!!!!!!!!!!!!!"
272  cc = tDistanceC / ACdistance
273  icc = int(cc)
274  floor_ceil_icc = cc - icc
275  IntersectPoint1 = (cc-icc)*(IntersectPoint1 - centerG_surface)/cc + centerG_surface;
276 
277  if (tDistanceB > ABdistance):
278  #print "Yes move B!!!!!!!!!!!!!!!!!!!!"
279  bb = tDistanceB / ABdistance
280  ibb = int(bb)
281  floor_ceil_ibb = bb - ibb
282  IntersectPoint2 = (bb-ibb)*(IntersectPoint2 - centerG_surface)/bb + centerG_surface;
283 
284  fvAB = IntersectPoint2 - centerG_surface
285  fvAC = IntersectPoint1 - centerG_surface
286  tDistanceC = length( fvAC )
287  tDistanceB = length( fvAB )
288 
289  #Find the final intersection point
290  FinalPointPlane1 = point2lines3 ( IntersectPoint1, IntersectPoint2, fvAB, fvAC );
291  New_centerG_protein = FinalPointPlane1 - findProteinZ;
292 
293  #Calculate new translationvector
294  Translate = New_centerG_protein - CA_centerG_protein
295  Translate_to_center(pose, start, Translate)
296 
297  #print "Check final centerG of protein:"
298  #final_centerG_protein = centerG_P(pose,prot_length)
299  #print final_centerG_protein
300  #Trnaslate protein up
301  #if length(final_centerG_protein-centerG_surface) < 20:
302  # print "translated up"
303  # Translate_up(pose,start,Nprotein_to_surface,80)
304 
305 
306  """
307  #print info: final
308  """
309  #print "..................Translated coordinates......................"
310  #print "Translation x= "+str(Translate.x)+" y= "+str(Translate.y)+" z= "+str(Translate.z)
311  #print "\n"
312 
313 
xyzVector< Real > xyz(Real const &r1, Real const &omega1, Real const &t, Real const &dz1, Real const &delta_omega1, Real const &delta_z1)
Returns the x-, y-, and z-coordinates of a point on a helix given r1, omega1, and t...
Definition: HelixParams.cc:67
bool open(utility::io::izstream &db_stream, std::string const &db_file, bool warn)
Open a database file on a provided stream.
Definition: open.cc:55
std::string & strip(std::string &s, std::string const &chars)
Strip Specified Characters from a string's Tails.