Пример #1
0
def name_and_group_models(models, name_arg, path_info):
    if len(models) > 1:
        # name arg only applies to group, not underlings
        if name_arg:
            names = [name_arg] * len(models)
        elif len(path_info) == len(models):
            names = [model_name_from_path(p) for p in path_info]
        else:
            names = [model_name_from_path(path_info[0])] * len(models)
        for m, pn in zip(models, names):
            if name_arg or not m.name:
                m.name = pn
        from chimerax.core.models import Model
        names = set([m.name for m in models])
        if len(names) == 1:
            group_name = names.pop() + " group"
        elif len(path_info) == 1:
            group_name = model_name_from_path(path_info[0])
        else:
            group_name = "group"
        group = Model(group_name, models[0].session)
        group.add(models)
        return group
    model = models[0]
    if name_arg:
        model.name = name_arg
    else:
        if not model.name:
            model.name = model_name_from_path(path_info[0])
    return model
Пример #2
0
 def delete(self):
     self.session.triggers.remove_handler(self._new_frame_handler)
     self._new_frame_handler = None
     from ._leap import leap_close
     leap_close(self._connection)
     self._connection = None
     Model.delete(self)
Пример #3
0
def _transform_schematic(session, transform, center, from_rgba, to_rgba,
                         length, width, thickness):

    axis, rot_center, angle_deg, shift = transform.axis_center_angle_shift()

    # Align rot_center at same position along axis as center.
    from chimerax.geometry import inner_product
    rot_center += inner_product(center - rot_center, axis) * axis
    width_axis = center - rot_center
    varray, narray, tarray = _axis_square(axis, rot_center, width_axis, length,
                                          width, thickness)

    from chimerax.core.models import Model, Surface

    s1 = Surface('slab 1', session)
    s1.set_geometry(varray, narray, tarray)
    s1.color = from_rgba

    s2 = Surface('slab 2', session)
    from chimerax.geometry import rotation, translation
    rot2 = translation(shift * axis) * rotation(
        axis, angle_deg, center=rot_center)
    varray2 = rot2 * varray
    narray2 = rot2.transform_vectors(narray)
    s2.set_geometry(varray2, narray2, tarray)
    s2.color = to_rgba

    m = Model('transform schematic', session)
    m.add([s1, s2])

    return m
Пример #4
0
    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?
Пример #5
0
    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)
Пример #6
0
    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()
Пример #7
0
def test_ra(session):
    from chimerax.core.models import Model, Drawing
    m = Model('test', session)
    d = Drawing('ring')
    d.set_geometry(*ring_arrow_with_post(0.5, 0.05, 4, 6, 0.3, 0.1, 0.05, 1))
    m.add_drawing(d)
    session.models.add([m])
Пример #8
0
    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
Пример #9
0
    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
Пример #10
0
    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
Пример #11
0
def _group_subunit_models(session, subunit_models, name):
    from chimerax.core.models import Model
    group = Model(name, session)
    for i,m in enumerate(subunit_models):
        m.name = 'subunit %d' % (i+1)
    group.add(subunit_models)
    return group
Пример #12
0
    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)
Пример #13
0
def _add_surface(surface):
    session = surface.session
    models = session.models
    if models.have_model(surface):
        # Reusing existing model.
        return

    # Check if request model id is already being used.
    model_id = surface.id
    if model_id:
        if models.have_id(model_id):
            from chimerax.core.errors import UserError
            id_string = '.'.join('%d'%i for i in model_id)
            raise UserError('Model id #%s already in use' % id_string)

        # If parent models don't exist create grouping models.
        p = None
        for i in range(1,len(model_id)):
            if not models.have_id(model_id[:i]):
                from chimerax.core.models import Model
                m = Model('shape', session)
                m.id = model_id[:i]
                models.add([m], parent = p)
                p = m

    # Add surface.
    models.add([surface])
Пример #14
0
 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
Пример #15
0
 def _add_provenance(self, name, p):
     """Add a Model containing provenance information keyed by the given
        name (usually a filename)"""
     if self._provenance is None or self._provenance.was_deleted:
         self._provenance = Model('Provenance', self.session)
         self.add([self._provenance])
     self._provenance_map[name] = p
     self._provenance.add([p])
     return self._provenance
Пример #16
0
 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
Пример #17
0
 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
Пример #18
0
 def restore_snapshot(session, data):
     from chimerax.core.models import Model
     sh = data['symmetry manager']
     if sh is None:
         return None
     mmgr = MapMgr(sh, auto_add=False)
     Model.set_state_from_snapshot(mmgr, session, data['model state'])
     session.triggers.add_handler('end restore session', mmgr._end_restore_session_cb)
     return mmgr
Пример #19
0
 def set_state_from_snapshot(self, session, data):
     Model.set_state_from_snapshot(self, session, data['model state'])
     self.rmf_filename = data['rmf_filename']
     self.rmf_features = data['rmf_features']
     self.rmf_provenance = data['rmf_provenance']
     self.rmf_hierarchy = data['rmf_hierarchy']
     self._provenance_map = data['provenance_map']
     self._rmf_resolutions = data['rmf_resolutions']
     self._selected_rmf_resolutions = data['selected_rmf_resolutions']
     self._rmf_chains = data['rmf_chains']
Пример #20
0
 def restore_snapshot(cls, session, data):
     from chimerax.core.models import Model
     dtype = data['hkl data type']
     container = data['container']
     hklinfo = container.hklinfo
     hkldata = data['hkl data']
     clipper_array = dtype(hklinfo)
     clipper_array.set_data(*hkldata)
     rd = cls('', session, clipper_array)
     Model.set_state_from_snapshot(rd, session, data['model state'])
     return rd
Пример #21
0
 def delete(self):
     if self._global_group:
         pbm = self.session.pb_manager
         pbm._delete_group(self)
     else:
         s = self._structure
         if s and not s.deleted:
             s._delete_pseudobond_group(self)
         self._structure = None
     Model.delete(self)
     self._pbond_drawing = None
Пример #22
0
 def restore_snapshot(session, data):
     if data['structure'] is not None:
         grp = data['structure'].pseudobond_group(data['category'], create_type=None)
     else:
         grp = session.pb_manager.get_group(data['category'], create=False)
     if 'model state' in data:
         Model.set_state_from_snapshot(grp, session, data['model state'])
     grp._dashes = data['dashes']
     from .molobject import set_custom_attrs
     set_custom_attrs(grp, data)
     return grp
Пример #23
0
    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
Пример #24
0
 def restore_snapshot(session, data):
     from chimerax.core.models import Model
     cm = data['crystal manager']
     if cm is None:
         return None
     xmapset = XmapSet(cm, auto_add_to_session=False)
     Model.set_state_from_snapshot(xmapset, session, data['model state'])
     xmapset._f_sigf_data_name = data['F/sigF']
     xmapset._session_restore_live_update = data['live update']
     session.triggers.add_handler('end restore session',
                                  xmapset._end_restore_session_cb)
     return xmapset
Пример #25
0
 def restore_snapshot(session, data):
     v = data.get('volume')
     if v is None:
         return None
     s = FastVolumeSurface(v, data['level'], data['rgba'],
                           data.get('show_mesh', False))
     from chimerax.core.models import Model
     Model.set_state_from_snapshot(s, session, data['model state'])
     if v._style_when_shown == 'image':
         s.display = False
     v._surfaces.append(s)
     return s
Пример #26
0
 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])
Пример #27
0
 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
Пример #28
0
    def draw(self, renderer, draw_pass):
        '''Render a color and depth texture pair.'''
        if self._first_image:
            return

        draw = ((draw_pass == self.OPAQUE_DRAW_PASS and self.opaque_texture)
                or (draw_pass == self.TRANSPARENT_DRAW_PASS
                    and not self.opaque_texture))
        if not draw:
            return

        r = renderer
        r.disable_shader_capabilities(r.SHADER_LIGHTING | r.SHADER_STEREO_360
                                      |  # Avoid geometry shift
                                      r.SHADER_DEPTH_CUE | r.SHADER_SHADOW
                                      | r.SHADER_MULTISHADOW
                                      | r.SHADER_CLIP_PLANES)
        r.enable_capabilities |= r.SHADER_ALPHA_DEPTH

        # If the desired field of view of the texture does not match the camera field of view
        # then adjust projection size.  Also if the apect ratio of the target framebuffer and
        # the aspect ratio of the texture don't match adjust the projection size.
        w, h = r.render_size()
        vw, vh = self.size
        if vw * h > vh * w:
            # Video aspect is wider than window aspect. Fit height, clip width.
            sx = (vw / vh) / (w / h)
            sy = 1
        else:
            # Video aspect is narrower than window aspect. Fit width, clip height.
            sx = 1
            sy = (w / h) / (vw / vh)

        cur_proj = r.current_projection_matrix
        proj = ((sx, 0, 0, 0), (0, sy, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1))
        r.set_projection_matrix(proj)

        from chimerax.geometry import place
        p0 = place.identity()
        cur_view = r.current_view_matrix
        r.set_view_matrix(p0)
        r.set_model_matrix(p0)
        r.enable_blending(False)

        Model.draw(self, r, draw_pass)

        # Restore view and projection matrices since drawings are not supposed to change these.
        r.set_projection_matrix(cur_proj)
        r.set_view_matrix(cur_view)

        r.enable_capabilities &= ~r.SHADER_ALPHA_DEPTH
        r.disable_shader_capabilities(0)
Пример #29
0
 def restore_snapshot(session, data):
     from chimerax.core.models import Model
     rdc = ReflectionDataContainer(session)
     Model.set_state_from_snapshot(rdc, session, data['model state'])
     rdc.filename = data['original filename']
     from chimerax.clipper.clipper_python import (Resolution, Spgr_descr,
                                                  Spacegroup, Cell_descr,
                                                  Cell, HKL_info)
     res = Resolution(data['resolution'])
     cell = Cell(Cell_descr(*data['cell dim'], *data['cell angles']))
     spgr_descr = Spgr_descr(data['hall symbol'], Spgr_descr.Hall)
     rdc._hklinfo = HKL_info(Spacegroup(spgr_descr), cell, res, True)
     return rdc
Пример #30
0
    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