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
def segment_surface(v, sindex, descrip, color): from chimerax.core.models import Surface s = Surface('segment %d %s' % (sindex, descrip), v.session) va, na, ta = segment_surface_geometry(v, sindex) s.set_geometry(va, na, ta) s.color = segment_color(color) return s
def triangles_model(session, points, triangles, name='vtk polygons', color=(180, 180, 180, 255)): from chimerax.core.models import Surface m = Surface(name, session) from chimerax import surface normals = surface.calculate_vertex_normals(points, triangles) m.set_geometry(points, normals, triangles) m.color = color return m
def ellipsoid_surface(axes, lengths, center, color, surface, submodel_name = None, num_triangles = 1000): xf = surface.position.inverse() sa, sc = transform_ellipsoid(axes, center, xf) varray, narray, tarray = ellipsoid_geometry(sc, sa, lengths, num_triangles = num_triangles) if submodel_name is None: s = surface else: from chimerax.core.models import Surface s = Surface(submodel_name, surface.session) surface.add([s]) s.set_geometry(varray, narray, tarray) s.color = color return s
def show_hk_lattice(session, h, k, radius, orientation='222', color=(255, 255, 255, 255), sphere_factor=0, edge_radius=None, mesh=False, replace=True): varray, tarray, hex_edges = hk_icosahedron_lattice(h, k, radius, orientation) interpolate_with_sphere(varray, radius, sphere_factor) name = 'Icosahedron h = %d, k = %d' % (h, k) if mesh: model = sm = _cage_surface(session, name, replace) sm.set_geometry(varray, None, tarray) sm.color = color sm.display_style = sm.Mesh sm.edge_mask = hex_edges # Hide spokes of hexagons. if sm.id is None: session.models.add([sm]) else: # Make cage from markers. from chimerax.core.models import Surface sm = Surface(name, session) sm.set_geometry(varray, None, tarray) sm.color = color sm.display_style = sm.Mesh sm.edge_mask = hex_edges # Hide spokes of hexagons. if edge_radius is None: edge_radius = .01 * radius mset = _cage_markers(session, name) if replace else None from chimerax.markers.cmd import markers_from_mesh model = markers_from_mesh(session, [sm], color=color, edge_radius=edge_radius, markers=mset) model.name = name if mset: mset._prev_markers.delete() model.hkcage = True return model
def ellipsoid_mesh(session, name, center, radii, rotation, divisions, color, opacity): vertices, edges = lattitude_longtitude_circles(divisions) # Stretch, rotate and center vertices *= radii rotation.transform_points(vertices, in_place=True) vertices += center # Create ellipsoid model from chimerax.core.models import Surface s = Surface(name, session) normals = None s.set_geometry(vertices, normals, edges) s.color = [int(255 * r) for r in color + [opacity]] s.display_style = s.Mesh session.models.add([s])
def mesh_models(session, seg): surfs = [] from chimerax.core.models import Surface from chimerax.surface import combine_geometry_vnt for segment in seg.segments: if segment.mesh_list is None: continue geoms = [mesh_geometry(mesh, seg) for mesh in segment.mesh_list] if len(geoms) == 0: continue va, na, ta = combine_geometry_vnt(geoms) s = Surface('mesh %d' % segment.id, session) s.set_geometry(va, na, ta) # s.display_style = s.Mesh # s.use_lighting = False s.color = segment_color(segment.colour) surfs.append(s) return surfs
def create_mesh(session, c, transform, rgba, name): varray, tarray = mesh_geometry(c) if len(tarray) == 0: return None transform.transform_points(varray, in_place=True) from chimerax.core.models import Surface s = Surface(name, session) s.SESSION_SAVE_DRAWING = True s.clip_cap = True # Cap surface when clipped from chimerax.surface import calculate_vertex_normals narray = calculate_vertex_normals(varray, tarray) s.set_geometry(varray, narray, tarray) rgba8 = [int(r * 255) for r in rgba] s.color = rgba8 return s
def calculate_segmentation_surfaces(seg, where=None, each=None, region='all', step=None, color=None): # Warn if number of surfaces is large. if where is None and each is None: max_seg_id = _maximum_segment_id(seg) if max_seg_id > 100: from chimerax.core.errors import UserError raise UserError( 'Segmentation %s (#%s) has %d segments (> 100).' ' To create surface for each segment use "each segment" option.' % (seg.name, seg.id_string, max_seg_id)) # Compute surfaces conditions = (where if where else []) + ([each] if each else []) group, attribute_name = _which_segments(seg, conditions) matrix = seg.matrix(step=step, subregion=region) from . import segmentation_surfaces surfs = segmentation_surfaces(matrix, group) # Transform vertices from index to scene units and compute normals. geom = [] tf = seg.matrix_indices_to_xyz_transform(step=step, subregion=region) for region_id, va, ta in surfs: tf.transform_points(va, in_place=True) from chimerax.surface import calculate_vertex_normals na = calculate_vertex_normals(va, ta) geom.append((region_id, va, na, ta)) # Determine surface coloring. if color is None: attr = None if attribute_name == 'segment' else attribute_name colors = _attribute_colors(seg, attr).attribute_rgba # Create one or more surface models from chimerax.core.models import Surface from chimerax.surface import combine_geometry_xvnt segsurfs = [] if each is None and len(geom) > 1: # Combine multiple surfaces into one. va, na, ta = combine_geometry_xvnt(geom) name = '%s %d %ss' % (seg.name, len(geom), attribute_name) s = Surface(name, seg.session) s.clip_cap = True # Cap surface when clipped s.set_geometry(va, na, ta) if color is None: color_counts = [(colors[region_id], len(sva)) for region_id, sva, sna, sta in geom] s.vertex_colors = _vertex_colors(len(va), color_counts) else: s.color = color segsurfs.append(s) else: # Create multiple surface models for region_id, va, na, ta in geom: name = '%s %s %d' % (seg.name, attribute_name, region_id) s = Surface(name, seg.session) s.clip_cap = True # Cap surface when clipped s.set_geometry(va, na, ta) s.color = colors[region_id] if color is None else color segsurfs.append(s) return segsurfs