Ejemplo n.º 1
0
 def center_on_atom(self, atom_pos):
     """ Only change the center of viewpoint of the camera.
     It does not change (yet) the position of the camera.
     atom_pos is a vector containing the XYZ coordinates
     of the selected atom.
     """
     if op.get_euclidean(self.target_point, atom_pos) != 0:
         cam_pos = self.get_cam_pos()
         glMatrixMode(GL_MODELVIEW)
         modelview = glGetDoublev(GL_MODELVIEW_MATRIX)
         up = modelview[:3, 1]
         zrp = self.zrp
         dist = op.get_euclidean(zrp, atom_pos)
         vec_dir = op.unit_vector([atom_pos[0]-zrp[0], atom_pos[1]-zrp[1], atom_pos[2]-zrp[2]])
         add_z = (self.z_far - self.z_near)/2
         dist_z = op.get_euclidean(cam_pos, zrp)
         if dist_z < add_z:
             add_z = dist_z - 0.1
         cycles = 15
         to_add = float(dist/cycles)
         for i in range(1, cycles):
             aum = i*to_add
             pto = [zrp[0]+vec_dir[0]*aum, zrp[1]+vec_dir[1]*aum, zrp[2]+vec_dir[2]*aum]
             self.z_far = dist_z + add_z
             self.z_near = dist_z - add_z
             self.fog_start = self.z_far - 1.5
             self.fog_end = self.z_far
             dist_z = op.get_euclidean(cam_pos, pto)
             #x, y, width, height = self.get_allocation()
             glMatrixMode(GL_PROJECTION)
             glLoadIdentity()
             gluPerspective(self.fovy, float(self.width)/float(self.height), self.z_near, self.z_far)
             glFogf(GL_FOG_START, self.fog_start)
             glFogf(GL_FOG_END, self.fog_end)
             glMatrixMode(GL_MODELVIEW)
             glLoadIdentity()
             gluLookAt(cam_pos[0], cam_pos[1], cam_pos[2],
                   pto[0], pto[1], pto[2],
                   up[0], up[1], up[2])
             self.updateGL()
         if dist%0.1 > 0:
             dist_z = op.get_euclidean(cam_pos, atom_pos)
             self.z_far = dist_z + add_z
             self.z_near = dist_z - add_z
             self.fog_start = self.z_far - 1.5
             self.fog_end = self.z_far
             #x, y, width, height = self.get_allocation()
             glMatrixMode(GL_PROJECTION)
             glLoadIdentity()
             gluPerspective(self.fovy, float(self.width)/float(self.height), self.z_near, self.z_far)
             glFogf(GL_FOG_START, self.fog_start)
             glFogf(GL_FOG_END, self.fog_end)
             glMatrixMode(GL_MODELVIEW)
             glLoadIdentity()
             gluLookAt(cam_pos[0], cam_pos[1], cam_pos[2], atom_pos[0], atom_pos[1], atom_pos[2], up[0], up[1], up[2])
         self.updateGL()
Ejemplo n.º 2
0
 def look_at(self, target):
     """ Function doc
     """
     assert (self.position[0] != target[0] and self.position[1] != target[1]
             and self.position[2] != target[2])
     direction = op.unit_vector(target - self.position)
     self.vertical_angle = -math.asin(direction[1]) * 180 / math.pi
     self.horizontal_angle = -(math.atan2(-direction[0], -direction[2]) *
                               180 / math.pi)
     self._normalize_angles()
     return True
Ejemplo n.º 3
0
 def edit_draw(self, mouse_x, mouse_y):
     """ Function doc """
     proj = np.matrix(self.proj_mat)
     view = np.matrix(self.view_mat)
     model = np.matrix(self.model_mat)
     i_proj = proj.I
     i_view = view.I
     i_model = model.I
     i_mvp = i_proj * i_view * i_model
     mod = self.get_viewport_pos(mouse_x, mouse_y)
     mod.append(1)
     mod = np.matrix(mod)
     mod = (mod * i_mvp).A1
     mod /= mod[3]
     u_vec = op.unit_vector(mod[:3] - self.cam_pos)
     v_vec = op.unit_vector(-self.cam_pos)
     angle = np.radians(op.get_angle(v_vec, u_vec))
     hypo = op.get_euclidean(self.cam_pos, [0, 0, 0]) / np.cos(angle)
     test = u_vec * hypo
     mod = self.cam_pos + test
     self.add_points(mod[:3])
     self.parent_widget.queue_draw()
Ejemplo n.º 4
0
 def edit_draw(self, mouse_x, mouse_y):
     """ Function doc """
     proj = np.matrix(self.proj_mat)
     view = np.matrix(self.view_mat)
     model = np.matrix(self.model_mat)
     i_proj = proj.I
     i_view = view.I
     i_model = model.I
     i_mvp = i_proj * i_view * i_model
     mod = self.get_viewport_pos(mouse_x, mouse_y)
     mod.append(1)
     mod = np.matrix(mod)
     mod = (mod*i_mvp).A1
     mod /= mod[3]
     u_vec = op.unit_vector(mod[:3] - self.cam_pos)
     v_vec = op.unit_vector(-self.cam_pos)
     angle = np.radians(op.get_angle(v_vec, u_vec))
     hypo = op.get_euclidean(self.cam_pos, [0,0,0]) / np.cos(angle)
     test = u_vec * hypo
     mod = self.cam_pos + test
     self.add_points(mod[:3])
     self.parent_widget.queue_draw()
Ejemplo n.º 5
0
 def pressed_c(self, pdb_resids=20):
     """ Test Cartoon
     """
     import numpy as np, operations as op
     cart = [(1,'N'), (2,'H'), (3,'H'), (4,'H'), (5,'H'),
             (6,'H'), (7,'H'), (8,'H'), (9,'N'), (10,'N'),
             (11,'N'), (12,'N'), (13,'N'), (14,'N'), (15,'N'),
             (16,'N'), (17,'N'), (18,'N'), (19,'N'), (20,'N')]
     frame = self.data[0]
     i = 0
     cartoons = []
     while i < len(frame.ribbons):
         if cart[i][1] == 'N':
             temp = (0, frame.ribbons[i])
             cartoons.append(temp)
             i += 1
         elif cart[i][1] == 'H':
             atom1 = frame.ribbons[i][0]
             while cart[i][1] == 'H':
                 i += 1
             atom2 = frame.ribbons[i][0]
             arr1 = np.array([0, 0, 1])
             arr2 = op.unit_vector(atom2.pos - atom1.pos)
             angle = op.get_angle(arr1, arr2)
             vec_o = np.cross(arr1, arr2)
             length = op.get_euclidean(atom1.pos, atom2.pos)
             temp = (1,(atom1, length, angle, vec_o))
             cartoons.append(temp)
     self.gl_crt_li = glGenLists(1)
     glNewList(self.gl_crt_li, GL_COMPILE)
     for car in cartoons:
         if car[0] == 0:
             rep.draw_ribbon(car[1][0], car[1][1], car[1][2], car[1][3])
         elif car[0] == 1:
             rep.draw_helix(car[1][2], car[1][3], car[1][1], car[1][0])
     glEndList()
     self.CARTOON = True
     return True