def _create_opengl_context(self): if self._initialization_failed: return False # Create opengl context w = self._window from chimerax.graphics import OpenGLContext, OpenGLVersionError, OpenGLError self._opengl_context = c = OpenGLContext(w, self.session.ui.primaryScreen()) # Create texture drawing to render status messages from chimerax.graphics import Drawing, Render self._drawing = Drawing('statusbar') self._drawing2 = Drawing('secondary statusbar') self._renderer = r = Render(c) try: if not r.make_current(): raise RuntimeError('Failed to make status line opengl context current') except (OpenGLError, OpenGLVersionError): self._opengl_context = None self._renderer = None self._initialization_failed = True self.session.logger.warning('No statusbar messages will be shown due to inadequate OpenGL') return False lw, lh = w.width(), w.height() r.initialize_opengl(lw, lh) r.set_background_color(self.background_color) return True
def area_in_circles_on_unit_sphere(circles, draw=False, draw_center=(0, 0, 0), draw_radius=1): # Check if sphere is outside all other spheres. if len(circles) == 0: return 0 if draw: from chimerax.graphics import Drawing surfc = Drawing('circles') s0 = (draw_center, draw_radius) draw_circles(circles, s0, surfc, width=0.01, offset=0.01) cint, lc, nreg = circle_intersections(circles, draw) if draw: surfi = Drawing('boundary points') draw_sphere_points([ci.point for ci in cint], s0, surfi, (.8, .2, 0, 1), offset=0.02) # Check if circles cover the sphere if len(cint) == 0 and len(lc) == 0: return 4 * pi # Connect circle arcs to form boundary paths. paths = boundary_paths(cint) # print('boundary lengths', ','.join(str(nr) for nr in [1]*len(lc) + [len(p) for p in paths]), # (('for %d regions' % (nreg + len(lc))) if nreg < len(paths) else '')) if draw: surfb = Drawing('boundary') for bp in paths: draw_boundary(bp, s0, surfb, color=(.8, .5, .5, 1), width=0.01, offset=0.02) draw_circles(tuple(lc), s0, surfb, color=(.8, .5, .5, 1), width=0.01, offset=0.02) la = lone_circles_area(lc) ba = bounded_area(paths, nreg) area = la + ba if draw: draw.add_models((surfc, surfi, surfb)) return area
def draw(self, renderer, draw_pass): r = renderer ww, wh = r.render_size() from chimerax.graphics.camera import ortho projection = ortho(0, ww, 0, wh, -1, 1) r.set_projection_matrix(projection) Drawing.draw(self, renderer, draw_pass) r.set_projection_matrix(((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)))
def __init__(self, axis_length=20.0, axis_radius=0.05, axis_colors=[(255, 0, 0, 255), (0, 255, 0, 255), (0, 0, 255, 255)]): # self._center = None Drawing.__init__(self, 'HKL Axes') # self.pickable = False # Don't set depth in frontCenter mode. # self.no_cofr = True # Don't include in cofr calculation. self._create_geometry(axis_length, axis_radius, axis_colors)
def __init__(self, name, session): self._name = name Drawing.__init__(self, name) self.session = session self._id = None self._added_to_session = False self._deleted = False self._selection_coupled = None from .triggerset import TriggerSet self.triggers = TriggerSet() self.triggers.add_trigger("deleted")
def delete(self): '''Supported API. Delete this model.''' if self._deleted: raise RuntimeError('Model %s was deleted twice' % self._name) models = self.session.models if models.have_model(self): models.close([self]) # Remove from open models list. return self._deleted = True Drawing.delete(self) self.triggers.activate_trigger("deleted", self) self.session = None
def sphere_model(indices, centers, radii, ntri=2000): from chimerax.graphics import Drawing s = Drawing('spheres') from .shapes import sphere_geometry for i in indices: va, na, ta = sphere_geometry(ntri) va = va * radii[i] + centers[i] p = s.new_drawing(str(i)) p.set_geometry(va, na, ta) return s
def __init__(self, session, axis_length=2.0, axis_radius=0.05, axis_colors=[(255, 0, 0, 255), (0, 255, 0, 255), (0, 0, 255, 255)]): self._session = session self._center = None Drawing.__init__(self, 'Pivot indicator') self.pickable = False # Don't set depth in frontCenter mode. self._create_geometry(axis_length, axis_radius, axis_colors) h = session.triggers.add_handler('graphics update', self._update_position) self._update_handler = h
def __init__(self, session): self._step_multiplier = 1 super().__init__(session) from chimerax.graphics import Drawing d = self._drawing = Drawing('Depth Indicator') d.set_geometry(*self._drawing_geometry()) d.display = False self.view.drawing.add_drawing(d)
def sym_axis_drawing_screw(fold_symmetry, screw_component, axyz0, axyz1, base_radius=0.3): ''' Just draw as a dashed cylinder for now. ''' import numpy from chimerax.surface.shapes import dashed_cylinder_geometry from chimerax.geometry import Places, cylinder_rotations, rotation n = len(axyz0) radius = base_radius * (1 + 0.1 * fold_symmetry) radii = numpy.ones(n, numpy.float32) * radius rot44 = numpy.empty([n, 4, 4], numpy.float32) cylinder_rotations(axyz0, axyz1, radii, rot44) rot44[:, 3, :3] = 0.5 * (axyz0 + axyz1) from chimerax.graphics import Drawing d = Drawing('{}-fold screw axis'.format(fold_symmetry)) d.set_geometry(*dashed_cylinder_geometry(segments=15)) d.color = _symmetry_colors[fold_symmetry][1] d.positions = Places(opengl_array=rot44) return d
def first_intercept(self, mxyz1, mxyz2, exclude=None): # Pick atom associated with surface patch from chimerax.graphics import Drawing, PickedTriangle p = Drawing.first_intercept(self, mxyz1, mxyz2, exclude) if not isinstance(p, PickedTriangle) or p.drawing() is not self: return p t = p.triangle_number v = self.triangles[t, 0] v2a = self.vertex_to_atom_map() if v2a is None: pa = p else: a = v2a[v] atom = self.atoms[a] from .structure import PickedAtom pa = PickedAtom(atom, p.distance) return pa
def split_surfaces(plist, session, in_place=False): surf = None if not in_place: name = '%s split' % plist[0].surface.name if plist else 'split surface' from chimerax.graphics import Drawing surf = Drawing(name) session.models.add_models([surf]) pplist = [] for p in plist: pieces = split_surface_piece(p, surf or p.surface) pplist.extend(pieces) if pieces: # TODO: Select pieces if original surface selected. if in_place: p.surface.remove_drawing(p) else: p.display = False return pplist
def sym_axis_drawing_standard(fold_symmetry, axyz0, axyz1, base_radius=0.3): import numpy radius = base_radius * (1 + 0.1 * fold_symmetry) n = len(axyz0) radii = numpy.ones(n, numpy.float32) * radius from chimerax.geometry import Places, cylinder_rotations, rotation rot44 = numpy.empty([n, 4, 4], numpy.float32) cylinder_rotations(axyz0, axyz1, radii, rot44) rot44[:, 3, :3] = 0.5 * (axyz0 + axyz1) vertices = [] normals = [] triangles = [] colors = [] angle = 360 / fold_symmetry v, n, t = cylindrical_wedge_geometry(angle=angle, nc=3) colors_base = numpy.ones((len(v), 4), numpy.uint8) # colors_1 = numpy.array([_symmetry_colors[fold_symmetry]]*len(v), numpy.uint8) # colors_2 = numpy.ones(colors_1.shape, numpy.uint8) * 255 for i in range(fold_symmetry): colors_base[:, :] = _symmetry_colors[fold_symmetry][i] r = rotation((0, 0, 1), angle * i) vertices.append(r * v) normals.append(r.apply_without_translation(n)) triangles.append(t + len(v) * i) colors.append(colors_base.copy()) vertices = numpy.concatenate(vertices) normals = numpy.concatenate(normals) triangles = numpy.concatenate(triangles) colors = numpy.concatenate(colors) from chimerax.graphics import Drawing d = Drawing('{}-fold symmetry axis'.format(fold_symmetry)) d.set_geometry(vertices, normals, triangles) d.set_vertex_colors(colors) d.positions = Places(opengl_array=rot44) # d.position = Place(axes=place.axes(), origin = constant_point + (f0+f1/2)*axis_direction) return d
def unit_cell_box_drawing(unit_cell_corners, corner_radius=1.0, origin_radius=2.0, cylinder_radius=0.2): from chimerax.graphics import Drawing md = Drawing('Unit cell box') cd = Drawing('Corners') ed = Drawing('Edges') md.add_drawing(cd) md.add_drawing(ed) from chimerax.surface.shapes import sphere_geometry2, cylinder_geometry cd.set_geometry(*sphere_geometry2(80)) ed.set_geometry(*cylinder_geometry()) from chimerax.geometry import Places, cylinder_rotations import numpy shift_and_scale = numpy.empty((8, 4), numpy.float32) shift_and_scale[:, :3] = unit_cell_corners shift_and_scale[1:, 3] = corner_radius shift_and_scale[0, 3] = origin_radius cd.positions = Places(shift_and_scale=shift_and_scale) edges = [[0, 1], [0, 2], [0, 4], [1, 3], [1, 5], [2, 3], [2, 6], [3, 7], [4, 5], [4, 6], [5, 7], [6, 7]] xyz = [[], []] for e in edges: for i in range(2): xyz[i].append(unit_cell_corners[e[i]]) xyz0, xyz1 = [numpy.array(x) for x in xyz] rot44 = numpy.empty((12, 4, 4), numpy.float32) cylinder_rotations(xyz0, xyz1, numpy.ones(12, numpy.float32) * cylinder_radius, rot44) rot44[:, 3, :3] = 0.5 * (xyz0 + xyz1) ed.positions = Places(opengl_array=rot44) return md
def __init__(self, name): Drawing.__init__(self, name) self._size = (1, 1) # Meters
def _set_display(self, display): Drawing.set_display(self, display) self.session.triggers.activate_trigger(MODEL_DISPLAY_CHANGED, self)
def set_selected(self, sel, *, fire_trigger=True): Drawing.set_highlighted(self, sel) if fire_trigger: self._selection_changed()