예제 #1
0
    def show_curve(self,
                   radius=0,
                   band_length=0,
                   segment_subdivisions=10,
                   circle_subdivisions=15):

        m = self.molecule
        if m is None:
            return

        import tube
        s, plist = tube.tube_through_atoms(m.atoms, radius, band_length,
                                           segment_subdivisions,
                                           circle_subdivisions)
        if s is None:
            return

        s.name = 'path tracer curve'
        self.curve_parameters = (radius, band_length, segment_subdivisions)
        self.curve_model = s
        from chimera import addModelClosedCallback
        addModelClosedCallback(s, self.curve_model_closed_cb)

        import SimpleSession
        SimpleSession.noAutoRestore(s)
예제 #2
0
    def show_cb(self, event=None, model_id=None):

        radius = self.radius.value(self.default_radius)
        sphere_factor = self.sphere_factor.value(0)
        surface_style = self.surface_style.get()
        orientation = self.orientation_name()
        subdivision_levels = self.subdivision_levels(radius)

        if self.surface_model == None:
            import _surface
            sm = _surface.SurfaceModel()
            sm.name = 'Icosahedron'
            self.surface_model = sm
            import chimera
            chimera.addModelClosedCallback(sm, self.surface_closed_cb)
            self.surface_piece = None

        from Icosahedron import make_icosahedron_surface
        p = make_icosahedron_surface(radius, orientation, subdivision_levels,
                                     sphere_factor, surface_style,
                                     self.color.rgba, self.surface_model)

        if self.surface_piece:
            self.surface_model.removePiece(self.surface_piece)
        else:
            from chimera import openModels as om
            if model_id is None:
                id = subid = om.Default
            else:
                id, subid = model_id
            om.add([self.surface_model], baseId=id, subid=subid)

        self.surface_piece = p
예제 #3
0
  def show_cb(self, event = None, model_id = None):

    radius = self.radius.value(self.default_radius)
    sphere_factor = self.sphere_factor.value(0)
    surface_style = self.surface_style.get()
    orientation = self.orientation_name()
    subdivision_levels = self.subdivision_levels(radius)

    if self.surface_model == None:
      import _surface
      sm = _surface.SurfaceModel()
      sm.name = 'Icosahedron'
      self.surface_model = sm
      import chimera
      chimera.addModelClosedCallback(sm, self.surface_closed_cb)
      self.surface_piece = None

    from Icosahedron import make_icosahedron_surface
    p = make_icosahedron_surface(radius, orientation, subdivision_levels,
                                 sphere_factor, surface_style, self.color.rgba,
                                 self.surface_model)
    
    if self.surface_piece:
      self.surface_model.removePiece(self.surface_piece)
    else:
      from chimera import openModels as om
      if model_id is None:
        id = subid = om.Default
      else:
        id, subid = model_id
      om.add([self.surface_model], baseId = id, subid = subid)

    self.surface_piece = p
    def create_box(self):

        m = chimera.Molecule()
        m.name = 'Subregion Selection Box'
        chimera.openModels.add([m], noprefs=True)
        chimera.addModelClosedCallback(m, self.model_closed_cb)

        rid = chimera.MolResId(1)
        r = m.newResidue('markers', rid)

        corners = []
        for name in ('a000', 'a001', 'a010', 'a011', 'a100', 'a101', 'a110',
                     'a111'):
            a = m.newAtom(name, chimera.elements.H)
            r.addAtom(a)
            corners.append(a)

        green = chimera.MaterialColor(0, 1, 0, 1)
        for a1, a2 in ((0, 1), (2, 3), (4, 5), (6, 7), (0, 2), (1, 3), (4, 6),
                       (5, 7), (0, 4), (1, 5), (2, 6), (3, 7)):
            b = m.newBond(corners[a1], corners[a2])
            b.halfbond = 0
            b.drawMode = chimera.Bond.Wire
            b.color = green

        return corners
예제 #5
0
    def __init__(self,
                 molecule,
                 category,
                 probeRadius=1.4,
                 allComponents=True,
                 vertexDensity=2.0):

        SurfaceModel.__init__(self)

        name = 'MSMS %s surface of %s' % (category, molecule.name)
        SurfaceModel.__setattr__(self, 'name', name)
        SurfaceModel.__setattr__(self, 'piecesAreSelectable', True)
        SurfaceModel.__setattr__(self, 'oneTransparentLayer', True)

        init = {
            'molecule': molecule,
            'colorMode': self.ByAtom,
            'visibilityMode': self.ByAtom,
            'density': vertexDensity,
            'probeRadius': probeRadius,
            'category': category,
            'allComponents': allComponents,
            'atomMap': None,  # vertex number to Atom
            'surface_piece': None,
            'srf': None,  # MSMS surface object
            'triData': None,  # MSMS triangle data
            'areaSES': 0.0,
            'areaSAS': 0.0,
            'calculationFailed': False,
        }
        self.__dict__.update(init)

        from _surface import SurfacePiece
        self.surface_piece_defaults = {
            'drawMode': self.Filled,
            'lineWidth': 1.0,
            'pointSize': 1.0,
            'useLighting': True,
            'twoSidedLighting': True,
            'smoothLines': False,
            'transparencyBlendMode': SurfacePiece.SRC_ALPHA_DST_1_MINUS_ALPHA,
        }

        self.update_surface()

        # Detect changes in atom color, atom surfaceColor, atom surfaceOpacity,
        #   molecule color, atom surfaceDisplay.
        from chimera import triggers as t
        self.molecule_handler = t.addHandler('Molecule', self.molecule_cb,
                                             None)

        # Detect when surface or molecule deleted.
        from chimera import addModelClosedCallback
        addModelClosedCallback(self, self.surface_closed_cb)
        addModelClosedCallback(self.molecule, self.molecule_closed_cb)

        import Surface
        Surface.set_coloring_method('msms', self, self.custom_coloring)
        Surface.set_visibility_method('msms', self, self.custom_visibility)
예제 #6
0
    def make_model(self, length, thickness, rgb, label, xy_offset, label_rgb,
                   model_id):

        m = chimera.Molecule()
        m.name = 'scale bar'

        #
        # Need to create a residue because atom without residue causes
        # unknown C++ exceptions.
        #
        rid = chimera.MolResId(1)
        r = m.newResidue('sb', rid)

        atoms = []
        for name, pos in (('1', (-length / 2.0, 0, 0)), ('2', (length / 2.0, 0,
                                                               0)),
                          ('label', (xy_offset[0],
                                     xy_offset[1] + thickness / 2.0, 0))):
            a = m.newAtom(name, chimera.elements.H)
            r.addAtom(a)
            c = chimera.Coord()
            c.x, c.y, c.z = pos
            a.setCoord(c)  # a.coord = c does not work
            a.display = 0
            atoms.append(a)
        m.atom1, m.atom2, m.label_atom = atoms
        m.label_atom.color = background_color()
        m.label_atom.display = 1

        b = m.newBond(m.atom1, m.atom2)
        b.display = b.Always
        b.drawMode = b.Stick
        b.radius = thickness / 2.0
        b.color = chimera_color(rgb)
        b.halfbond = 0
        m.label_atom.label = label
        m.label_atom.labelColor = chimera_color(label_rgb)

        self.model = m

        if model_id == None:
            id, subid = (self.model_id(), chimera.openModels.Default)
        else:
            id, subid = model_id
        chimera.openModels.add([m], baseId=id, subid=subid)
        chimera.addModelClosedCallback(m, self.model_closed_cb)

        import SimpleSession
        SimpleSession.noAutoRestore(m)

        m.openState.active = False
        z_near, z_far = clip_plane_positions()
        self.set_depth(.5 * (z_near + z_far))
        self.set_screen_position(self.screen_position)
        self.orientation_cb()

        return m
예제 #7
0
  def make_model(self, length, thickness, rgb, label, xy_offset, label_rgb,
                 model_id):

    m = chimera.Molecule()
    m.name = 'scale bar'
    
    #
    # Need to create a residue because atom without residue causes
    # unknown C++ exceptions.
    #
    rid = chimera.MolResId(1)
    r = m.newResidue('sb', rid)

    atoms = []
    for name, pos in (('1', (-length/2.0, 0, 0)),
                      ('2', (length/2.0, 0, 0)),
                      ('label',
                       (xy_offset[0], xy_offset[1] + thickness/2.0, 0))):
      a = m.newAtom(name, chimera.elements.H)
      r.addAtom(a)
      c = chimera.Coord()
      c.x, c.y, c.z = pos
      a.setCoord(c)                               # a.coord = c does not work
      a.display = 0
      atoms.append(a)
    m.atom1, m.atom2, m.label_atom = atoms
    m.label_atom.color = background_color()
    m.label_atom.display = 1
    
    b = m.newBond(m.atom1, m.atom2)
    b.display = b.Always
    b.drawMode = b.Stick
    b.radius = thickness/2.0
    b.color = chimera_color(rgb)
    b.halfbond = 0
    m.label_atom.label = label
    m.label_atom.labelColor = chimera_color(label_rgb)

    self.model = m

    if model_id == None:
      id, subid = (self.model_id(), chimera.openModels.Default)
    else:
      id, subid = model_id
    chimera.openModels.add([m], baseId = id, subid = subid)
    chimera.addModelClosedCallback(m, self.model_closed_cb)

    import SimpleSession
    SimpleSession.noAutoRestore(m)

    m.openState.active = False
    z_near, z_far = clip_plane_positions()
    self.set_depth(.5 * (z_near + z_far))
    self.set_screen_position(self.screen_position)
    self.orientation_cb()

    return m
    def auto_recolor(self, model, color_source, caps_only):

        add_callback = not self.models.has_key(model)
        self.models[model] = (color_source, caps_only)
        from Surface import set_coloring_method
        set_coloring_method('surface color', model, self.stop_coloring)
        if add_callback:
            model.addGeometryChangedCallback(self.surface_changed_cb)
            from chimera import addModelClosedCallback
            addModelClosedCallback(model, self.model_closed_cb)
예제 #9
0
    def auto_dust(self, model, method, limit):

        add_callback = not self.models.has_key(model)
        self.models[model] = (method, limit)
        from Surface import set_visibility_method
        set_visibility_method('hide dust', model, self.stop_hiding_dust)
        if add_callback:
            model.addGeometryChangedCallback(self.surface_changed_cb)
            import chimera
            chimera.addModelClosedCallback(model, self.model_closed_cb)
    def auto_zone(self, model, points, colors, distance):

        add_callback = not self.models.has_key(model)
        self.models[model] = (points, colors, distance)
        from Surface import set_coloring_method
        set_coloring_method('color zone', model, self.stop_zone)
        if add_callback:
            model.addGeometryChangedCallback(self.surface_changed_cb)
            import chimera
            chimera.addModelClosedCallback(model, self.model_closed_cb)
예제 #11
0
    def auto_recolor(self, model, color_source, caps_only):

        add_callback = not self.models.has_key(model)
        self.models[model] = (color_source, caps_only)
        from Surface import set_coloring_method
        set_coloring_method('surface color', model, self.stop_coloring)
        if add_callback:
            model.addGeometryChangedCallback(self.surface_changed_cb)
            from chimera import addModelClosedCallback
            addModelClosedCallback(model, self.model_closed_cb)
예제 #12
0
    def auto_zone(self, model, points, colors, distance):

        add_callback = not self.models.has_key(model)
        self.models[model] = (points, colors, distance)
        from Surface import set_coloring_method
        set_coloring_method('color zone', model, self.stop_zone)
        if add_callback:
            model.addGeometryChangedCallback(self.surface_changed_cb)
            import chimera
            chimera.addModelClosedCallback(model, self.model_closed_cb)
예제 #13
0
    def auto_dust(self, model, method, limit):

        add_callback = not self.models.has_key(model)
        self.models[model] = (method, limit)
        from Surface import set_visibility_method
        set_visibility_method('hide dust', model, self.stop_hiding_dust)
        if add_callback:
            model.addGeometryChangedCallback(self.surface_changed_cb)
            import chimera
            chimera.addModelClosedCallback(model, self.model_closed_cb)
예제 #14
0
    def __init__(self, molecule, category, probeRadius = 1.4,
                 allComponents = True, vertexDensity = 2.0):

        SurfaceModel.__init__(self)

        name = 'MSMS %s surface of %s' % (category, molecule.name)
        SurfaceModel.__setattr__(self, 'name', name)
        SurfaceModel.__setattr__(self, 'piecesAreSelectable', True)
        SurfaceModel.__setattr__(self, 'oneTransparentLayer', True)

        init = {
            'molecule': molecule,
            'colorMode': self.ByAtom,
            'visibilityMode': self.ByAtom,
            'density': vertexDensity,
            'probeRadius': probeRadius,
            'category': category,
            'allComponents': allComponents,
            'atomMap': None,            # vertex number to Atom
            'surface_piece': None,
            'srf': None,                # MSMS surface object
            'triData': None,            # MSMS triangle data
            'areaSES': 0.0,
            'areaSAS': 0.0,
	    'calculationFailed': False,
            }
        self.__dict__.update(init)

        from _surface import SurfacePiece
        self.surface_piece_defaults = {
            'drawMode': self.Filled,
            'lineWidth': 1.0,
            'pointSize': 1.0,
            'useLighting': True,
            'twoSidedLighting': True,
            'smoothLines': False,
            'transparencyBlendMode': SurfacePiece.SRC_ALPHA_DST_1_MINUS_ALPHA,
            }

        self.update_surface()

        # Detect changes in atom color, atom surfaceColor, atom surfaceOpacity,
        #   molecule color, atom surfaceDisplay.
        from chimera import triggers as t
        self.molecule_handler = t.addHandler('Molecule', self.molecule_cb, None)

        # Detect when surface or molecule deleted.
        from chimera import addModelClosedCallback
        addModelClosedCallback(self, self.surface_closed_cb)
        addModelClosedCallback(self.molecule, self.molecule_closed_cb)

        import Surface
        Surface.set_coloring_method('msms', self, self.custom_coloring)
        Surface.set_visibility_method('msms', self, self.custom_visibility)
예제 #15
0
    def __init__(self,
                 name,
                 matrix,
                 matrix_id,
                 transform,
                 align=None,
                 message_cb=None):

        self.name = name

        self.matrix = matrix
        self.matrix_id = matrix_id  # indicates if matrix changed
        self.matrix_range = None

        self.transform = transform

        self.volume = None  # Volume_Model
        self.add_handler = None

        from chimera import Model, addModelClosedCallback
        if isinstance(align, Model):
            self.attached_model = align
            addModelClosedCallback(self.attached_model,
                                   self.attached_model_closed_cb)
        else:
            self.attached_model = None

        self.message_cb = message_cb

        self.transfer_function = ()
        self.brightness_factor = 1
        self.transparency_depth = 0
        self.colormap_size = 256
        self.clamp = False

        self.color_mode = 'auto8'
        self.c_mode = 'rgba8'
        self.projection_mode = 'auto'
        self.p_mode = '2d-xyz'
        self.use_plane_callback = True  # Avoids allocating 3d color array
        self.dim_transparent_voxels = True
        self.bt_correction = False
        self.minimal_texture_memory = False
        self.maximum_intensity_projection = False
        self.linear_interpolation = True
        self.show_outline_box = True
        self.outline_box_rgb = (1, 1, 1)
        self.outline_box_linewidth = 1

        self.update_colors = False
예제 #16
0
    def settings_changed_cb(self, event=None):

        if not self.have_phantom():
            return

        phantom_on = self.phantom_on.get()
        if not phantom_on:
            if self.cursor_model:
                chimera.openModels.close([self.cursor_model])
            return

        phantom_range_mm = float_variable_value(self.phantom_range)
        box_size_mm = (phantom_range_mm, phantom_range_mm, phantom_range_mm)

        shape = self.cursor_shape.get()
        from _phantomcursor import Cursor_Model
        cursor_shape = {
            'cross': Cursor_Model.Cross,
            'jack': Cursor_Model.Jack,
            'sphere': Cursor_Model.Sphere,
            'volume crosshair': Cursor_Model.Cross,
        }[shape]

        cursor_size = float_variable_value(self.cursor_size)
        r, g, b = self.cursor_color.rgb
        cursor_color = chimera.MaterialColor(r, g, b)

        pd = self.phantom_device
        cm = self.cursor_model
        if pd == None or cm == None:
            pd, cm = self.make_phantom_cursor_model(box_size_mm, cursor_shape,
                                                    cursor_size, cursor_color)
            self.phantom_device = pd
            self.cursor_model = cm
            chimera.addModelClosedCallback(cm, self.model_closed_cb)
        else:
            pd.box_size_mm = box_size_mm
            cm.cursor_style = cursor_shape
            cm.cursor_size = cursor_size
            cm.cursor_color = cursor_color

        crosshair_on = (self.cursor_shape.get() == 'volume crosshair')
        cm.show_crosshair = crosshair_on

        self.update_force_field()
예제 #17
0
  def settings_changed_cb(self, event = None):

    if not self.have_phantom():
      return
    
    phantom_on = self.phantom_on.get()
    if not phantom_on:
      if self.cursor_model:
	chimera.openModels.close([self.cursor_model])
      return

    phantom_range_mm = float_variable_value(self.phantom_range)
    box_size_mm = (phantom_range_mm, phantom_range_mm, phantom_range_mm)

    shape = self.cursor_shape.get()
    from _phantomcursor import Cursor_Model
    cursor_shape = {'cross': Cursor_Model.Cross,
                    'jack': Cursor_Model.Jack,
                    'sphere': Cursor_Model.Sphere,
                    'volume crosshair': Cursor_Model.Cross,
                    }[shape]

    cursor_size = float_variable_value(self.cursor_size)
    r,g,b = self.cursor_color.rgb
    cursor_color = chimera.MaterialColor(r,g,b)

    pd = self.phantom_device
    cm = self.cursor_model
    if pd == None or cm == None:
      pd, cm = self.make_phantom_cursor_model(box_size_mm, cursor_shape,
					      cursor_size, cursor_color)
      self.phantom_device = pd
      self.cursor_model = cm
      chimera.addModelClosedCallback(cm, self.model_closed_cb)
    else:
      pd.box_size_mm = box_size_mm
      cm.cursor_style = cursor_shape
      cm.cursor_size = cursor_size
      cm.cursor_color = cursor_color

    crosshair_on = (self.cursor_shape.get() == 'volume crosshair')
    cm.show_crosshair = crosshair_on

    self.update_force_field()
예제 #18
0
  def __init__(self, name, matrix, matrix_id, transform,
               align = None, message_cb = None):

    self.name = name

    self.matrix = matrix
    self.matrix_id = matrix_id          # indicates if matrix changed
    self.matrix_range = None

    self.transform = transform

    self.volume = None                  # Volume_Model
    self.add_handler = None

    from chimera import Model, addModelClosedCallback
    if isinstance(align, Model):
      self.attached_model = align
      addModelClosedCallback(self.attached_model, self.attached_model_closed_cb)
    else:
      self.attached_model = None

    self.message_cb = message_cb

    self.transfer_function = ()
    self.brightness_factor = 1
    self.transparency_depth = 0
    self.colormap_size = 256
    self.clamp = False

    self.color_mode = 'auto8'
    self.c_mode = 'rgba8'
    self.projection_mode = 'auto'
    self.p_mode = '2d-xyz'
    self.use_plane_callback = True      # Avoids allocating 3d color array
    self.dim_transparent_voxels = True
    self.bt_correction = False
    self.minimal_texture_memory = False
    self.maximum_intensity_projection = False
    self.linear_interpolation = True
    self.show_outline_box = True
    self.outline_box_rgb = (1,1,1)
    self.outline_box_linewidth = 1

    self.update_colors = False
예제 #19
0
  def show_in_volume_viewer(self):

    data_seq = list(self.data_sets)
    data_seq.sort(lambda a,b: cmp(a.time, b.time))
    from VolumeViewer import volume_from_grid_data
    data_regions = [volume_from_grid_data(g, show_data = False)
                    for g in data_seq]
    self.data_regions = list(data_regions)

    # Add callbacks to detect when volume data sets are closed.
    import chimera
    for v in data_regions:
      chimera.addModelClosedCallback(v, self.volume_closed)

    if data_regions:
      dr = data_regions[0]
      from VolumeViewer import set_active_volume
      set_active_volume(dr)
      dr.initialize_thresholds()
      dr.show()
예제 #20
0
    def show_in_volume_viewer(self):

        data_seq = list(self.data_sets)
        data_seq.sort(lambda a, b: cmp(a.time, b.time))
        from VolumeViewer import volume_from_grid_data
        data_regions = [
            volume_from_grid_data(g, show_data=False) for g in data_seq
        ]
        self.data_regions = list(data_regions)

        # Add callbacks to detect when volume data sets are closed.
        import chimera
        for v in data_regions:
            chimera.addModelClosedCallback(v, self.volume_closed)

        if data_regions:
            dr = data_regions[0]
            from VolumeViewer import set_active_volume
            set_active_volume(dr)
            dr.initialize_thresholds()
            dr.show()
예제 #21
0
    def open_model(self):

        from chimera import openModels, addModelClosedCallback
        openModels.add([self.volume], sameAs=self.attached_model)
        addModelClosedCallback(self.volume, self.model_closed_cb)
예제 #22
0
    def set_volume(self, volume):

        self.volume = volume

        from chimera import addModelClosedCallback
        addModelClosedCallback(volume, self.volume_closed_cb)
    def set_volume(self, volume):

        self.volume = volume

        from chimera import addModelClosedCallback
        addModelClosedCallback(volume, self.volume_closed_cb)
예제 #24
0
    def set_marker_molecule(self, mol):

        self.molecule = mol
        mol.marker_set = self
        from chimera import addModelClosedCallback
        addModelClosedCallback(mol, self.model_closed_cb)
예제 #25
0
  def open_model(self):

    from chimera import openModels, addModelClosedCallback
    openModels.add([self.volume], sameAs = self.attached_model)
    addModelClosedCallback(self.volume, self.model_closed_cb)