Beispiel #1
0
    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
Beispiel #2
0
 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
Beispiel #3
0
    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