コード例 #1
0
 def _label_objects(self, r):
     # Label CA atom so label does not jump around.
     la = [a for a in r.atoms if a.name == self._label_atom_name]
     from chimerax.core.objects import Objects
     if len(la) == 1:
         from chimerax.atomic import Atoms
         objects = Objects(atoms=Atoms(la))
         otype = 'atoms'
     else:
         # If no CA atom them label center of residue
         objects = Objects(atoms=r.atoms)
         otype = 'residues'
     return objects, otype
コード例 #2
0
ファイル: atomspec.py プロジェクト: Yongcheng123/ChimeraX
 def _filter_parts(self, model, atoms, num_atoms):
     if not self.my_parts:
         mask = model.atomspec_filter(self.Symbol, atoms, num_atoms,
                                      None, self.my_attrs)
         return atoms.filter(mask)
     from ..objects import Objects
     results = Objects()
     for part in self.my_parts:
         my_part = self.my_parts.__class__(part)
         mask = model.atomspec_filter(self.Symbol, atoms, num_atoms,
                                      my_part, self.my_attrs)
         sub_atoms = atoms.filter(mask)
         if len(sub_atoms) > 0:
             results.add_atoms(sub_atoms)
     return results.atoms
コード例 #3
0
ファイル: select.py プロジェクト: Yongcheng123/ChimeraX
def _select_sequence(objects, sequence):
    from chimerax.atomic import Residues, Residue
    sel_residues = set()
    base_search_string = sequence.upper()
    protein_search_string = base_search_string.replace('B', '[DN]').replace('Z', '[EQ]')
    nucleic_search_string = base_search_string.replace('R', '[AG]').replace('Y', '[CTU]').replace(
        'N', '[ACGTU]')
    orig_res = objects.residues
    for chain in orig_res.chains.unique():
        search_string = protein_search_string \
            if chain.polymer_type == Residue.PT_PROTEIN else nucleic_search_string
        try:
            ranges = chain.search(search_string, case_sensitive=True)
        except ValueError as e:
            from chimerax.core.errors import UserError
            raise UserError(e)
        for start, length in ranges:
            sel_residues.update([r for r in chain.residues[start:start+length] if r])
    residues = Residues(sel_residues)
    atoms = residues.intersect(orig_res).atoms
    from chimerax.core.objects import Objects
    fobj = Objects(atoms = atoms, bonds = atoms.intra_bonds,
                   pseudobonds = atoms.intra_pseudobonds,
                   models = atoms.structures.unique())
    return fobj
コード例 #4
0
ファイル: presets.py プロジェクト: QChASM/SEQCROW
def indexLabel(session, models=None):
    from chimerax.core.objects import Objects
    from chimerax.atomic import AtomicStructure, Atoms
    from chimerax.label.label3d import label
    from SEQCROW.utils import contrast_bw

    if models is None:
        models = session.models.list(type=AtomicStructure)
    elif isinstance(models, AtomicStructure):
        models = [models]

    for m in models:
        for i, atom in enumerate(m.atoms):
            l = str(i + 1)
            ele_color = atom.color[:-1]
            if contrast_bw(ele_color) == "black":
                label_color = (0, 0, 0, 255)
            else:
                label_color = (255, 255, 255, 255)
            label(
                session,
                objects=Objects(atoms=Atoms([atom])),
                object_type='atoms',
                text=l,
                offset=(-0.11 * len(l), -0.2, -0.2),
                height=0.4,
                on_top=True,
                color=label_color,
            )
コード例 #5
0
def set_to_default_cartoon(session, model = None):
    '''
    Adjust the ribbon representation to provide information without
    getting in the way.
    '''
    from chimerax.core.commands import atomspec
    from chimerax.std_commands import cartoon
    from chimerax.nucleotides.cmd import nucleotides
    from chimerax.atomic import AtomicStructures
    if model is None:
        aspec = None
        models = None
        atoms = None
    else:
        models = AtomicStructures([model])
        atoms = model.atoms
        atoms.displays=False
        atoms[exclude_nonpolar_hydrogens(atoms)].displays=True
        # atoms[atoms.idatm_types!='HC'].displays=True
        # arg = atomspec.AtomSpecArg('thearg')
        # aspec= arg.parse('#' + model.id_string, session)[0]
    cartoon.cartoon(session, atoms = atoms, suppress_backbone_display=False)
    cartoon.cartoon_style(session, atoms = atoms, width=0.4, thickness=0.1, arrows_helix=True, arrow_scale = 2)
    cartoon.cartoon_tether(session, structures=models, opacity=0)
    nucleotides(session, 'atoms')
    from chimerax.std_commands import color
    from chimerax.core.objects import Objects
    objects = Objects(models=models, atoms=atoms)
    color.color(session, objects, color='bychain', target='ac')
    color.color(session, objects, color='byhetero', target='a')
コード例 #6
0
def rotamers(session, residues, res_type, *, rot_lib=None, log=True):
    ''' Command to display possible side-chain rotamers '''

    residues = _check_residues(residues)

    if rot_lib is None:
        rot_lib = session.rotamers.default_command_library_name

    ret_val = []
    from . import swap_res
    from chimerax.atomic import AtomicStructures
    from chimerax.core.objects import Objects
    for r in residues:
        if res_type == "same":
            r_type = r.name
        else:
            r_type = res_type.upper()
        rotamers = swap_res.get_rotamers(session,
                                         r,
                                         res_type=r_type,
                                         rot_lib=rot_lib,
                                         log=log)
        mgr = _RotamerStateManager(session, r, rotamers)
        if session.ui.is_gui:
            from .tool import RotamerDialog
            RotamerDialog(session, "%s Side-Chain Rotamers" % r, mgr, res_type,
                          rot_lib)
        ret_val.append(mgr)
        rot_structs = AtomicStructures(rotamers)
        rot_objects = Objects(atoms=rot_structs.atoms, bonds=rot_structs.bonds)
        from chimerax.std_commands.color import color
        color(session, rot_objects, color="byelement")
        from chimerax.std_commands.size import size
        size(session, rot_objects, stick_radius=0.1)
    return ret_val
コード例 #7
0
ファイル: mouselabel.py プロジェクト: Yongcheng123/ChimeraX
    def _label_pick(self, pick, color = None, background = None,
                    size = None, height = None):
        if pick is None:
            from .label3d import label_delete
            label_delete(self.session, object_type = 'residues')
            from chimerax.core.commands import log_equivalent_command
            log_equivalent_command(self.session, 'label delete residues')
            return

        from chimerax import atomic
        if isinstance(pick, atomic.PickedAtom):
            atoms = pick.atom.residue.atoms
        elif isinstance(pick, atomic.PickedResidue):
            atoms = pick.residue.atoms
        elif isinstance(pick, atomic.PickedBond):
            atoms = atomic.Atoms(pick.bond.atoms)  # Convert tuple to Atoms
        elif isinstance(pick, atomic.PickedPseudobond):
            atoms = atomic.Atoms(pick.pbond.atoms)  # Convert tuple to Atoms
        else:
            return

        from chimerax.core.objects import Objects
        objects = Objects(atoms = atoms)
        object_type = 'residues'
        
        ses = self.session
        from .label3d import label, label_delete
        if label_delete(ses, objects, object_type) == 0:
            label(ses, objects, object_type, color=color, bg_color=background,
                  size=size, height=height)
            from chimerax.core.commands import log_equivalent_command, residues_specifier, options_text
            rspec = residues_specifier(objects)
            opts = options_text((('color',color), ('bg_color',background), 
                                 ('size',size), ('height',height)))
            log_equivalent_command(ses, 'label %s %s' % (rspec, opts))
コード例 #8
0
ファイル: cmd.py プロジェクト: Yongcheng123/ChimeraX
def marker_segment(session,
                   marker_set,
                   position,
                   to_position,
                   radius=0.5,
                   color=(255, 255, 0, 255),
                   coordinate_system=None,
                   label=None,
                   label_height=1.0,
                   label_color='default'):

    mset = _create_marker_set(session, marker_set)
    center1 = position.scene_coordinates(coordinate_system)
    center2 = to_position.scene_coordinates(coordinate_system)

    m1 = mset.create_marker(center1, color, radius)
    m2 = mset.create_marker(center2, color, radius)
    from . import create_link
    link = create_link(m1, m2, color, radius)

    if label is not None:
        from chimerax.label.label3d import label as make_label
        from chimerax.core.objects import Objects
        from chimerax.atomic import Bonds
        lo = Objects(bonds=Bonds([link]))
        make_label(session,
                   lo,
                   object_type='bonds',
                   text=label,
                   color=label_color,
                   height=label_height)

    return m1, m2
コード例 #9
0
ファイル: atomspec.py プロジェクト: Yongcheng123/ChimeraX
 def find_matches(self, session, models, results, ordered):
     if self.model is None:
         # No reference atomspec, so do nothing
         return
     from ..objects import Objects
     my_results = Objects()
     zone_results = Objects()
     self.model.find_matches(session, models, my_results, ordered)
     if my_results.num_atoms > 0:
         # expand my_results before combining with results
         coords = my_results.atoms.scene_coords
         for m in session.models.list():
             m.atomspec_zone(session, coords, self.distance,
                             self.target_type, self.operator, zone_results)
     results.combine(zone_results)
     if '<' in self.operator:
         results.combine(my_results)
コード例 #10
0
 def _show_labels(self):
     # Show residue labels for nearby residues
     r = self._zone_center_residue
     lres = self._nearby_residues(r, self._label_distance)
     from chimerax.core.objects import Objects
     aobj = Objects(atoms = lres.atoms)
     from chimerax.label.label3d import label, label_delete
     ses = self.session
     label_delete(ses)
     label(ses, aobj, 'residues', size = self._label_size, height = self._label_height,
           color = self._label_color, bg_color = self._label_background)
     self._labeled_residues = aobj
コード例 #11
0
ファイル: tool.py プロジェクト: salilab/rmf_chimerax
    def _get_selected_features(self, tree):
        def get_child_chimera_obj(feat):
            for child in feat.children:
                o = child.chimera_obj
                if o:
                    yield o
                for obj in get_child_chimera_obj(child):
                    yield obj

        def get_selection():
            for f in tree.selectedIndexes():
                feat = f.internalPointer()
                obj = feat.chimera_obj
                # Prefer to select pseudobonds (even from children)
                if (obj is not None
                        and (not isinstance(obj, Atoms) or not feat.children)):
                    yield obj
                else:
                    for obj in get_child_chimera_obj(feat):
                        yield obj

        s = list(get_selection())
        objs = Objects()
        objs.add_pseudobonds(
            Pseudobonds(x for x in s if isinstance(x, Pseudobond)))
        for x in s:
            if isinstance(x, Atoms):
                objs.add_atoms(x)
        return objs
コード例 #12
0
 def _show_label(self):
     # Add distance label
     from chimerax.label.label3d import label
     from chimerax.core.objects import Objects
     from chimerax.atomic import Bonds
     b = Objects(bonds=Bonds([self._link]))
     text, h = self._label_text_and_height()
     from chimerax.core.colors import Color
     label(self.session,
           objects=b,
           object_type='bonds',
           text=text,
           height=h,
           color=Color(self._color))
コード例 #13
0
ファイル: presets.py プロジェクト: pk-organics/SEQCROW
def indexLabel(session, models=None):
    from chimerax.core.objects import Objects
    from chimerax.atomic import AtomicStructure, Atoms
    from chimerax.label.label3d import label

    if models is None:
        models = session.models.list(type=AtomicStructure)
    elif isinstance(models, AtomicStructure):
        models = [models]

    for m in models:
        for i, atom in enumerate(m.atoms):
            l = str(i + 1)
            label(session, objects=Objects(atoms=Atoms([atom])), object_type='atoms', \
                text=l, offset=(-0.11*len(l),-0.2,-0.2), height=0.4, on_top=True)
コード例 #14
0
def default_atom_visualisation(model):
    session = model.session
    from chimerax.core.objects import Objects
    from chimerax.std_commands import color
    from chimerax.atomic import Atom
    atoms = model.atoms
    ao = Objects(atoms=atoms)
    color.color(session, ao, color='bychain')
    color.color(session, ao, color='byhetero')
    model.bonds.radii = 0.2
    model.bonds.displays = True
    atoms.draw_modes = Atom.STICK_STYLE
    atoms.displays = True
    from chimerax.clipper.util import nonpolar_hydrogens
    atoms[nonpolar_hydrogens(atoms)].displays = False
    model.residues.ribbon_displays = True
コード例 #15
0
 def restore_snapshot(session, data):
     from . import cmd
     from chimerax.core.objects import Objects
     from chimerax.core.errors import UserError
     for name, value in data["spec"]:
         try:
             cmd.name(session, name, value, skip_check=True)
         except UserError as e:
             session.logger.warning("Name \"%s\" not restored: %s" %
                                    (name, str(e)))
     for name, value in data["frozen"]:
         try:
             cmd.name_frozen(session, name, Objects(**value))
         except UserError as e:
             session.logger.warning("Frozen name \"%s\" not restored: %s" %
                                    (name, str(e)))
     return session.basic_actions
コード例 #16
0
ファイル: select.py プロジェクト: Yongcheng123/ChimeraX
def _filter_pseudobonds_by_length(objects, minimum_length, maximum_length):
    if (minimum_length is None and maximum_length is None) or objects.num_pseudobonds == 0:
        return objects

    pbonds = objects.pseudobonds
    lengths = pbonds.lengths
    if minimum_length is not None and maximum_length is not None:
        from numpy import logical_and
        keep = logical_and((lengths >= minimum_length), (lengths <= maximum_length))
    elif minimum_length is not None:
        keep = (lengths >= minimum_length)
    elif maximum_length is not None:
        keep = (lengths <= maximum_length)
        
    from chimerax.core.objects import Objects
    fobj = Objects(pseudobonds = pbonds.filter(keep))
    return fobj
コード例 #17
0
 def _is_nonmatching(self, name):
     try:
         return self._nonmatching[name]
     except KeyError:
         from chimerax.core.commands import get_selector, is_selector_atomic
         from chimerax.core.objects import Objects
         sel = get_selector(name)
         if callable(sel):
             objs = Objects()
             sel(self.session, self.session.models.list(), objs)
             nonmatching = objs.num_atoms == 0 and objs.num_pseudobonds == 0
         elif isinstance(sel, Objects):
             nonmatching = sel.num_atoms == 0 and sel.num_pseudobonds == 0
         else:
             # Do not know, so assume it matches something
             nonmatching = is_selector_atomic(name)
         self._nonmatching[name] = nonmatching
         return nonmatching
コード例 #18
0
ファイル: atomspec.py プロジェクト: Yongcheng123/ChimeraX
 def find_selected_parts(self, model, atoms, num_atoms, results):
     # Only filter if a spec for this level is present
     # TODO: account for my_attrs in addition to my_parts
     if self.my_parts or self.my_attrs:
         atoms = self._filter_parts(model, atoms, num_atoms)
         num_atoms = len(atoms)
     if len(atoms) == 0:
         return
     if self.sub_parts is None:
         results.add_model(model)
         results.add_atoms(atoms)
         return
     from ..objects import Objects
     sub_results = Objects()
     for subpart in self.sub_parts:
         subpart.find_selected_parts(model, atoms, num_atoms, sub_results)
     if sub_results.num_atoms > 0:
         results.add_model(model)
         results.add_atoms(sub_results.atoms)
コード例 #19
0
ファイル: atomspec.py プロジェクト: Yongcheng123/ChimeraX
def _add_model_parts(session, model, sub_parts, results, ordered):
    if not model.atomspec_has_atoms():
        if not sub_parts:
            results.add_model(model)
            if model.atomspec_has_pseudobonds():
                results.add_pseudobonds(model.atomspec_pseudobonds())
        return
    atoms = model.atomspec_atoms(ordered=ordered)
    if not sub_parts:
        results.add_model(model)
        results.add_atoms(atoms)
    else:
        # Has sub-model selector, filter atoms
        from ..objects import Objects
        my_results = Objects()
        num_atoms = len(atoms)
        for chain_spec in sub_parts:
            chain_spec.find_selected_parts(model, atoms, num_atoms, my_results)
        if my_results.num_atoms > 0:
            results.add_model(model)
            results.add_atoms(my_results.atoms)
コード例 #20
0
 def show_surfaces(self, mol, res, grid_spacing, new_model, session):
     if new_model:
         m = mol.copy('%s assembly %s' % (mol.name, self.id))
         m.ignore_assemblies = True
         session.models.add([m])
     else:
         m = mol
     included_atoms, excluded_atoms = self._partition_atoms(
         m.atoms, self._chain_ids())
     if new_model:
         excluded_atoms.delete()
     from chimerax.surface import surface, surface_hide_patches
     surfs = surface(session,
                     included_atoms,
                     grid_spacing=grid_spacing,
                     resolution=res)
     if not new_model and len(excluded_atoms) > 0:
         from chimerax.core.objects import Objects
         surface_hide_patches(session, Objects(atoms=excluded_atoms))
     for s in surfs:
         mmcif_cid = mmcif_chain_ids(s.atoms[:1], self.from_mmcif)[0]
         s.positions = self._chain_operators(mmcif_cid)
コード例 #21
0
ファイル: tool.py プロジェクト: salilab/rmf_chimerax
    def _get_selected_chimera_objects(self, tree):
        def _get_node_objects(node, objs):
            o = node.chimera_obj
            if o and not o.deleted:
                objs.append(o)
            for child in node._filtered_children:
                _get_node_objects(child, objs)

        objs = []
        inds = tree.selectedIndexes()
        for ind in inds:
            _get_node_objects(ind.internalPointer(), objs)
        # If empty selection, use the root instead
        if not inds:
            _get_node_objects(tree.model().rmf_hierarchy, objs)
        objects = Objects()
        objects.add_atoms(Atoms(x for x in objs if isinstance(x, Atom)))
        objects.add_bonds(Bonds(x for x in objs if isinstance(x, Bond)))
        return objects
コード例 #22
0
ファイル: atomspec.py プロジェクト: Yongcheng123/ChimeraX
 def evaluate(self, session, models, *, top=True, ordered=False):
     """Return Objects for model elements that match."""
     from ..objects import Objects
     results = Objects()
     return self.find_matches(session, models, results, ordered)