def __init__(self, session, pointer_size=1.0, hand='right', emulate='mouse', tracking_space=TrackingSpace(), pinch_thresholds=(0.9, 0.6)): self._emulate = emulate # 'mouse' or 'vr' for 2d or 6d mouse mode events self._hand = hand # 'left' or 'right' self._tracking_space = tracking_space # Maps device hand position to screen. self._pinch = False # Are thumb and index finger touching? self._pinch_thresholds = pinch_thresholds # Pinch strength on and off thresholds self._last_hand_pose = None # Used for mouse mode drag events, leap device coordinates self._window_xy = None name = self._hand + ' hand' Model.__init__(self, name, session) self._set_pointer_shape(cross_diameter=pointer_size, stick_diameter=0.1 * pointer_size) if hand == 'right': self._unpinch_color = (0, 255, 0, 255) self._pinch_color = (0, 255, 255, 255) else: self._unpinch_color = (255, 255, 0, 255) self._pinch_color = (255, 0, 255, 255) self.color = self._unpinch_color
def __init__(self, name, session, foreground_color=(0, 255, 0, 255), saturation=10, color_popup=False, flip_horizontal=True, size=None, framerate=25): Model.__init__(self, name, session) self._camera = None # QCamera self.camera_name = '' self._capture = None # VideoCapture instance self.size = None # Width, height in pixels self._requested_size = size self.framerate = None # Frames per second, float self._requested_framerate = framerate self._first_image = True # Whether first image has been acquired self._last_image = None # Numpy color array (h,w,3) uint8 self.foreground_color = foreground_color # What color pixels to put in front of models self.saturation = saturation # How saturated pixel color must be to be foreground self.color_popup = color_popup self._flip_horizontal = flip_horizontal self._start_video()
def __init__(self, atomic_structure, hide_favored = False, ignore_ribbon_hides = True): ''' Create the validator object, and add it as a child model to the target structure. Args: * atomic_structure: - a :py:class:`ChimeraX.AtomicStructure` instance * hide_favored: - if True, indicators will only appear for non-favored residues. (this can be changed at any time later) * ignore_ribbon_hides: - if True, the :attr:`chimerax.HIDE_RIBBON` bit will be ignored when deciding when to display a particular annotation. This is needed because the default ChimeraX ribbon representation hides the CA for any residue whose sidechain is un-displayed or missing (meaning that the glycine CA is always hidden). ''' structure = self._atomic_structure = atomic_structure session = structure.session Model.__init__(self, 'Ramachandran Validation', session) structure.add([self]) self._ignore_ribbon_hides = ignore_ribbon_hides self._hide_favored = hide_favored from .. import molobject mgr = self._mgr = molobject.get_ramachandran_mgr(session) self._ca_radius = 0.5 self._prepare_drawings() # self._prepare_ca_display() self.track_whole_model = True t = structure.triggers self._structure_change_handler = t.add_handler('changes', self._update_graphics_if_needed)
def __init__(self, session, pointer_size=1.0, mode_left='vr', mode_right='vr', pinch_thresholds=(0.9, 0.6), max_delay=0.2, tracking_space=TrackingSpace(), head_mounted=False, debug=False): Model.__init__(self, 'Leap Motion', session) self._tracking_space = tracking_space self._max_delay = max_delay # Don't use hand positions older than this (seconds). self._hands = [ LeapHand(session, hand=hand, emulate=mode, pointer_size=pointer_size, tracking_space=tracking_space, pinch_thresholds=pinch_thresholds) for hand, mode in (('left', mode_left), ('right', mode_right)) ] self.add(self._hands) # Add hand models as children from ._leap import leap_open self._connection = leap_open(head_mounted=head_mounted, debug=debug) self._new_frame_handler = session.triggers.add_handler( 'new frame', self._new_frame)
def __init__(self, session): Model.__init__(self, 'labels', session) self.on_top = True # Should labels always appear above other graphics self._window_size = session.main_view.window_size self._labels = [] # list of ObjectLabel self._object_label = { } # Map object (Atom, Residue, Pseudobond, Bond) to ObjectLabel self._num_pixel_labels = 0 # Number of labels sized in pixels. t = session.triggers self._update_graphics_handler = t.add_handler( 'graphics update', self._update_graphics_if_needed) self._model_display_handler = t.add_handler( 'model display changed', self._model_display_changed) from chimerax.core.core_settings import settings as core_settings self._background_color_handler = core_settings.triggers.add_handler( 'setting changed', self._background_changed_cb) from chimerax.atomic import get_triggers ta = get_triggers() self._structure_change_handler = ta.add_handler( 'changes', self._structure_changed) self.use_lighting = False Model.set_color(self, (255, 255, 255, 255)) # Do not modulate texture colors self._texture_width = 2048 # Pixels. self._texture_needs_update = True # Has text, color, size, font changed. self._positions_need_update = True # Has label position changed relative to atom? self._visibility_needs_update = True # Does an atom hide require a label to hide?
def __init__(self, atomic_structure): ''' Create the validator object, and add it as a child model to the target structure. Args: * atomic_structure: - a :py:class:`ChimeraX.AtomicStructure` instance ''' structure = self._atomic_structure = atomic_structure session = structure.session Model.__init__(self, 'Rotamer Validation', session) from .. import molobject mgr = self._mgr = molobject.get_rotamer_mgr(session) self._MAX_SCALE = 2 # maximum scale factor for annotation drawings self._hide_favored = True d = self._drawing = self._rota_indicator() self.add_drawing(d) structure.add([self]) self.track_whole_model = True t = structure.triggers self._structure_change_handler = t.add_handler('changes', self._update_graphics_if_needed) self.update_graphics() self._update_needed = False
def __init__(self, session, name='Head', size=0.3, image_file=None): Model.__init__(self, name, session) self.room_position = None r = size / 2 from chimerax.surface import box_geometry va, na, ta = box_geometry((-r, -r, -0.1 * r), (r, r, 0.1 * r)) if image_file is None: from os.path import join, dirname image_file = join(dirname(__file__), self.default_face_file) from PyQt5.QtGui import QImage qi = QImage(image_file) aspect = qi.width() / qi.height() va[:, 0] *= aspect from chimerax.graphics import qimage_to_numpy, Texture rgba = qimage_to_numpy(qi) from numpy import zeros, float32 tc = zeros((24, 2), float32) tc[:] = 0.5 tc[8:12, :] = ((0, 0), (1, 0), (0, 1), (1, 1)) self.set_geometry(va, na, ta) self.color = (255, 255, 255, 255) self.texture = Texture(rgba) self.texture_coordinates = tc
def __init__(self, session, name, number, color, contour_info): Model.__init__(self, name, session) self.roi_number = number opacity = 255 self.color = tuple(color) + (opacity, ) va, ta = self._contour_lines(contour_info) self.set_geometry(va, None, ta) self.display_style = self.Mesh self.use_lighting = False
def __init__(self, session, label): name = label.name if label.name else label.text Model.__init__(self, name, session) self.label = label self._window_size = None # Full window size in render pixels self._texture_size = None # Label image size in render pixels self._texture_pixel_scale = 1 # Converts label.size from logical pixels to render pixels self._aspect = 1 # Scale y label positioning for image saving at non-screen aspect ratio self.needs_update = True
def __init__(self, session): Model.__init__(self, '2D labels', session) self._labels = [] self._named_labels = {} # Map label name to Label object from chimerax.core.core_settings import settings self.handler = settings.triggers.add_handler( 'setting changed', self._background_color_changed) session.main_view.add_overlay(self) self.model_panel_show_expanded = False
def __init__(self, session, name, room_to_scene, color=(0, 255, 0, 255)): Model.__init__(self, name, session) self._head = h = VRHeadModel(session) self.add([h]) self._hands = [] self._color = color self._gui = None # Last room to scene transformation for this peer. # Used if we are not using VR camera so have no room coordinates. self._room_to_scene = room_to_scene
def __init__(self, session, name, radius=1, height=3, color=(0, 255, 0, 255)): Model.__init__(self, name, session) from chimerax.surface import cone_geometry va, na, ta = cone_geometry(radius=radius, height=height) va[:, 2] -= 0.5 * height # Place tip of cone at origin self.set_geometry(va, na, ta) self.color = color
def __init__(self, name, session, color, center, radius): self._num_triangles = 1000 Model.__init__(self, name, session) from chimerax.surface import sphere_geometry2 va, na, ta = sphere_geometry2(self._num_triangles) self._unit_vertices = va self.set_geometry(radius * va, na, ta) self.color = color from chimerax.geometry import translation self.position = translation(center) self._radius = radius session.models.add([self])
def __init__(self, name, session, data): ''' Args: name: A descriptive name. session: The ChimeraX session. data: A Clipper HKL_data_Flag or HKL_data_Flag_bool object. ''' Model.__init__(self, name, session) self._data = data
def __init__(self, pbg_pointer, *, session=None): PseudobondGroupData.__init__(self, pbg_pointer) self._structure = s = self.structure # Keep structure in case PseudobondGroupData deleted. if session is None: session = s.session Model.__init__(self, self.name, session) self._pbond_drawing = None self._dashes = 9 self._global_group = (s is None) self._handlers = [] if s: s.add([self]) # Add pseudobond group as child model of structure
def __init__(self, name, maps, session): Model.__init__(self, name, session) self.add(maps) if maps: self.show_first_map_only(maps) self.set_maps(maps) self.surface_level_ranks = [] # Cached for normalization calculation self.image_level_ranks = [] # Cached for normalization calculation self._timer = None # Timer for updating volume viewer dialog h = session.triggers.add_handler('remove models', self._model_closed) self._close_handler = h
def __init__( self, name, session, size=(960, 540), # color frame size in pixels dsize=(1280, 720), # depth frame size in pixels frames_per_second=30, skip_frames=0, depth_scale=50, # Angstroms per meter. use_ir_projector=False, # Interferes with Vive VR tracking align_color_and_depth=True, # This slows frame rate denoise_depth=True, # Average depth values denoise_weight=0.1, # Weight factor for current frame depth denoise_color_tolerance=10 # Color matching used by denoising ): Model.__init__(self, name, session) # With VR camera depth scale is taken from camera. self._depth_scale = depth_scale # Angstroms per meter. self._first_image = True self._render_field_of_view = 69.4 # TODO: Get this from chimerax camera self._realsense_color_field_of_view = ( 69.4, 42.5) # TODO: Get this from pyrealsense self._realsense_depth_field_of_view = ( 91.2, 65.5) # TODO: Get this from pyrealsense self._use_ir_projector = use_ir_projector self._align_color_and_depth = align_color_and_depth self._denoise_depth = denoise_depth self._denoise_weight = denoise_weight self._denoise_color_tolerance = denoise_color_tolerance self._pipeline_started = False self._color_image_size = size self._depth_image_size = dsize # RealSense D435 frame rate: # 30, 15, 6 at depth 1280x720, or 60,90 at 848x480 # 6,15,30 at color 1920x1080, 60 at 1280x720 self._frames_per_second = frames_per_second self._skip_frames = skip_frames # Skip updating realsense on some graphics updates self._current_frame = 0 self._depth_texture = None t = session.triggers.add_handler('graphics update', self._update_image) self._update_trigger = t self._start_video()
def __init__(self, session, series): self.dicom_series = series path = series.paths[0] if series.dicom_class != 'RT Structure Set Storage': raise ValueError( 'DICOM file has SOPClassUID, %s, expected "RT Structure Set Storage", file %s' % (series.dicom_class, path)) if len(series.paths) > 1: raise ValueError( 'DICOM series has %d files, can only handle one file for "RT Structure Set Storage", file %s' % (len(series.paths), path)) from pydicom import dcmread d = dcmread(path) desc = d.get('SeriesDescription', '') Model.__init__(self, 'Regions %s' % desc, session) el = dicom_elements( d, { 'StructureSetROISequence': { 'ROINumber': int, 'ROIName': str }, 'ROIContourSequence': { 'ROIDisplayColor': rgb_255, 'ContourSequence': { 'ContourGeometricType': str, 'NumberOfContourPoints': int, 'ContourData': xyz_list } } }) regions = [] for rs, rcs in zip(el['StructureSetROISequence'], el['ROIContourSequence']): r = ROIContourModel(session, rs['ROIName'], rs['ROINumber'], rcs['ROIDisplayColor'], rcs['ContourSequence']) regions.append(r) self.add(regions)
def __init__(self, session, hklfile=None, shannon_rate=2.0, free_flag_label=None, auto_choose_reflection_data=True): ''' This class should hold the information that's common to all the data contained in its children (e.g. the HKLinfo object, the Cell, Spacegroup and Grid_sampling objects, the Unit_Cell, etc. ''' Model.__init__(self, 'Reflection Data', session) self.filename = None self.shannon_rate = shannon_rate self._hklinfo = None self._grid_sampling = None if hklfile is not None: self._init_from_hkl_file(hklfile, free_flag_label, auto_choose_reflection_data)
def __init__(self, session, name='GUI Panel'): Model.__init__(self, name, session) self.room_position = None self._panels = {} # Maps panel name to VRGUIPanel