def translation_step(points, point_weights, center, data_array, xyz_to_ijk_transform, ijk_step_size, metric, syminv=[], values=None, gradients=None): g = gradient_direction(points, point_weights, data_array, xyz_to_ijk_transform, metric, syminv=syminv, values=values, gradients=gradients) from numpy import array, float, dot as matrix_multiply gijk = matrix_multiply(xyz_to_ijk_transform.matrix[:, :3], g) from chimerax.geometry import norm, place n = norm(gijk) if n > 0: delta = g * (ijk_step_size / n) else: delta = array((0, 0, 0), float) delta_tf = place.translation(delta) return delta_tf
def move(session, by, modelspec=None): spec = modelspec.evaluate(session) import numpy by_vector = numpy.array(by) from chimerax.geometry import place translation = place.translation(by_vector) for m in spec.models: m.position = translation * m.position
def check_space_navigator(self, *_): e = self.device.last_event() if e is None: return rot, trans, buttons = e from math import sqrt # Rotation rx, ry, rz = rot # 10 bits, signed, +/-512 rmag = sqrt(rx*rx + ry*ry + rz*rz) # Translation tx, ty, tz = trans # 10 bits, signed, +/-512 tmag = sqrt(tx*tx + ty*ty + tz*tz) if self.dominant: if tmag < rmag: tmag = 0 if rmag < tmag: rmag = 0 if self.fly_mode: rt = 50 if abs(ry) > abs(rx)+rt and abs(ry) > abs(rz)+rt: rx = rz = 0 else: ry = 0 rmag = sqrt(rx*rx + ry*ry + rz*rz) from numpy import array, float32 from chimerax.geometry import place if rmag > 0: axis = array((rx/rmag, ry/rmag, rz/rmag), float32) f = 3 if self.fly_mode else 30 angle = self.speed*(f*rmag/512) rtf = place.rotation(axis, angle) self.apply_transform(rtf) if tmag > 0: axis = array((tx/tmag, ty/tmag, tz/tmag), float32) # view_width = v.camera.view_width(v.center_of_rotation) b = self.view.drawing_bounds() if not b is None: f = .1 if self.fly_mode else 1 view_width = b.xyz_max - b.xyz_min shift = axis * 0.15 * self.speed * view_width * f * tmag/512 ttf = place.translation(shift) self.apply_transform(ttf) if 'N1' in buttons or 31 in buttons or 'Left' in buttons: self.button_pressed(self.button_1_action) if 'N2' in buttons or 'Right' in buttons: self.button_pressed(self.button_2_action)
def view(self, camera_position, view_num): ''' Return the Place coordinate frame of the camera. As a transform it maps camera coordinates to scene coordinates. ''' if view_num is None: v = camera_position else: xoffset = self._x_offset_scene(view_num) from chimerax.geometry import place t = place.translation((xoffset, 0, 0)) v = camera_position * t return v
def angle_step(axis, points, center, xyz_to_ijk_transform, ijk_step_size): from chimerax.geometry.place import cross_product_matrix, translation tf = xyz_to_ijk_transform.zero_translation() * cross_product_matrix( axis) * translation(-center) from chimerax.geometry.vector import maximum_norm av = maximum_norm(points, tf.matrix) if av > 0: from math import pi angle = (ijk_step_size / av) * 180.0 / pi else: angle = 0 return angle
def view(self, camera_position, view_num): ''' Return the Place coordinate frame for a specific camera view number. As a transform it maps camera coordinates to scene coordinates. ''' if view_num is None: v = camera_position else: # Stereo eyes view in same direction with position shifted along x. s = -1 if view_num == 0 else 1 es = self.eye_separation_scene from chimerax.geometry import place t = place.translation((s * 0.5 * es, 0, 0)) v = camera_position * t return v