Пример #1
0
def _show_axis(session, tf, color, length, radius, coordinate_system):

    axis, axis_point, angle, axis_shift = tf.axis_center_angle_shift()
    if angle < 0.1:
        from chimerax.core.errors import UserError
        raise UserError('Rotation angle is near zero (%g degrees)' % angle)

    b = coordinate_system.bounds()
    if b is None:
        from chimerax.core.errors import UserError
        raise UserError('Model %s must be visible to show axis' %
                        coordinate_system)

    from chimerax.geometry import project_to_axis
    axis_center = project_to_axis(b.center(), axis, axis_point)
    axis_length = b.width() if length is None else length
    hl = 0.5 * axis_length
    ap1 = axis_center - hl * axis
    ap2 = axis_center + hl * axis

    from chimerax.markers import MarkerSet, create_link

    mset = MarkerSet(session, 'rotation axis')
    mset.scene_position = coordinate_system.scene_position

    r = 0.025 * axis_length if radius is None else radius
    m1 = mset.create_marker(ap1, color, r)
    m2 = mset.create_marker(ap2, color, r)
    b = create_link(m1, m2, color, r)
    b.halfbond = True

    session.models.add([mset])

    return mset
Пример #2
0
def surface_path(session,
                 surface,
                 length=100,
                 rgba=(255, 255, 0, 255),
                 radius=1,
                 geodesic=True):
    ep = edge_pairs(surface.triangles)
    from random import choice
    e = choice(tuple(ep.keys()))
    #    e = first_element(ep.keys())
    vertices = surface.vertices
    if geodesic:
        tnormals = edge_triangle_normals(surface.vertices, surface.triangles)
        # Start in direction perpendicular to starting edge.
        eo = (e[1], e[0])
        ev = edge_vector(eo, vertices)
        from chimerax.geometry import cross_product, normalize_vector
        direction = normalize_vector(cross_product(tnormals[eo], ev))
    else:
        direction, tnormals = None
    points = make_surface_path(e, ep, length, vertices, direction, tnormals)
    from chimerax.markers import MarkerSet, create_link
    ms = MarkerSet(session, 'surface path')
    mprev = None
    for id, xyz in enumerate(points):
        m = ms.create_marker(xyz, rgba, radius, id)
        if mprev is not None:
            create_link(mprev, m, rgba=rgba, radius=radius)
        mprev = m
    session.models.add([ms])
Пример #3
0
def read_swc(session, path):

    f = open(path, 'r')
    lines = f.readlines()
    f.close()

    points = parse_swc_points(lines)
    i2m = {}
    from chimerax.markers import MarkerSet, create_link
    from os.path import basename
    name = basename(path)
    mset = MarkerSet(session, name)
    tcolors = {
        1: (255, 255, 255, 255),  # soma, white
        2: (128, 128, 128, 255),  # axon gray
        3: (0, 255, 0, 255),  # basal dendrite, green
        4: (255, 0, 255, 255),  # apical dendrite, magenta
    }
    other_color = (255, 255, 0, 255)  # yellow
    for n, t, x, y, z, r, pid in points:
        if r < 0:
            r = 0.5
        color = tcolors.get(t, other_color)
        i2m[n] = m = mset.create_marker((x, y, z), color, r, id=n)
        if pid in i2m:
            m2 = i2m[pid]
            rlink = min(r, m2.radius)
            create_link(m, m2, color, rlink)
    msg = 'Opened neuron traces %s' % name
    return [mset], msg
Пример #4
0
def place_marker(session, xyz, color, radius, model_name, model_id=None):

    # Locate specified marker model
    mset = None
    from chimerax.markers import MarkerSet
    if model_id is not None:
        msets = session.models.list(model_id=model_id, type=MarkerSet)
        if len(msets) >= 1:
            mset = msets[0]

    if mset is None:
        # Create a new marker model
        mset = MarkerSet(session, model_name)
        mset.id = model_id
        session.models.add([mset])

    # Place marker at center position.
    mset.create_marker(xyz, color, radius)
Пример #5
0
def create_centroid_path(session, name, xyz, radius, color):

    from chimerax.markers import MarkerSet, create_link
    mset = MarkerSet(session, name)
    mprev = None
    for p in xyz:
        m = mset.create_marker(p, color, radius)
        if mprev:
            create_link(mprev, m, rgba = color, radius = radius/2)
        mprev = m
    session.models.add([mset])
    return mset
Пример #6
0
def markblobs(session, surface, radius=0.5, color=(255, 255, 0, 255)):
    centers = surface_blob_centers(surface)
    scene_centers = surface.scene_position * centers
    from chimerax.markers import MarkerSet
    marker_set = MarkerSet(session, name=surface.name)
    markers = [
        marker_set.create_marker(center, color, radius)
        for center in scene_centers
    ]
    session.models.add([marker_set])
    session.logger.status('Found %d connected surface pieces' % len(markers),
                          log=True)
    return markers
Пример #7
0
def place_markers(session,
                  coords,
                  radius=0.5,
                  color=(180, 180, 180, 255),
                  name='path',
                  pair_map={}):
    '''
    Create a MarkerSet with markers at positions specified by coords which maps
    an integer index to a Place instance.  The origin of the Place i.e. where
    it maps (0,0,0) is the location of the marker.  Markers with consecutive
    integer indices are connected with links, and pairs of markers specified
    in pair_map (mapping index to index) are also connected by links.  Markers
    have residue number equal to their index.  The MarkerSet is returned.
    '''
    from chimerax.markers import MarkerSet, create_link
    mset = MarkerSet(session, name)

    # Create markers.
    mmap = {}
    btf = sorted(coords.items())
    for b, tf in btf:
        xyz = tf.origin()
        mmap[b] = m = mset.create_marker(xyz, color, radius, id=b)
        m.extra_attributes = e = {'base_placement': tf}
        if b in pair_map:
            e['paired_with'] = pair_map[b]

    # Link consecutive markers.
    rl = 0.5 * radius
    for b, tf in btf:
        if b + 1 in mmap:
            create_link(mmap[b], mmap[b + 1], color, rl)

    # Link base pairs.
    for b1, b2 in pair_map.items():
        if b1 < b2 and b1 in mmap and b2 in mmap:
            create_link(mmap[b1], mmap[b2], color, rl)

    return mset