def _createRotation(self): selBonds = selection.currentBonds() if len(selBonds) == 1: addRotation(selBonds[0]) return replyobj.error("Exactly one bond must be selected " "in graphics window\n")
def unselBonds(): from chimera.selection import currentBonds selBonds = currentBonds(asDict=True) unsel = [] for m in chimera.openModels.list(modelTypes=[chimera.Molecule]): unsel.extend(filter(lambda b: b not in selBonds, m.bonds)) return unsel
def selected_links(self): links = [] bonds = selection.currentBonds() for b in bonds: if self.bond_to_link.has_key(b): links.append(self.bond_to_link[b]) return links
def selected_links(self): links = [] from chimera.selection import currentBonds bonds = currentBonds() for b in bonds: if self.bond_to_link.has_key(b): links.append(self.bond_to_link[b]) return links
def print_path_length(): from chimera import selection bonds = selection.currentBonds() msg = '%d bonds with total length %g\n' % (len(bonds), path_length(bonds)) from chimera import replyobj replyobj.status(msg) # Show on status line replyobj.message(msg) # Record in reply log
def select_connected(): 'Select atoms and bonds connected to currently selected atoms and bnods' from chimera import selection, Atom atoms_and_bonds = selection.currentAtoms() + selection.currentBonds() reached = set(atoms_and_bonds) i = 0 while i < len(atoms_and_bonds): ab = atoms_and_bonds[i] if isinstance(ab, Atom): n = ([b for b in ab.bonds if not b in reached] + [a for a in ab.neighbors if not a in reached]) else: n = [a for a in ab.atoms if not a in reached] atoms_and_bonds.extend(n) reached.update(set(n)) i += 1 selection.setCurrent(atoms_and_bonds)
def print_model_path_lengths(): from chimera import selection bonds = selection.currentBonds() mbonds = {} for b in bonds: m = b.molecule if m in mbonds: mbonds[m].append(b) else: mbonds[m] = [b] for m, bonds in mbonds.items(): msg = ('%s: %d bonds with total length %g\n' % (m.name, len(bonds), path_length(bonds))) from chimera import replyobj replyobj.status(msg) # Show on status line replyobj.message(msg) # Record in reply log
def zone_cb(self, event=None): self.message('') surface = self.chosen_surface() if surface == None: self.message('Select a surface') return radius = self.radius_from_gui() if radius == None: return from chimera import selection atoms = selection.currentAtoms() bonds = selection.currentBonds() from SurfaceZone import path_points, surface_zone points = path_points(atoms, bonds, surface.openState.xform.inverse()) if len(points) > 0: surface_zone(surface, points, radius, auto_update=True) else: self.message('No atoms are selected')
def zone_cb(self, event = None): self.message('') surface = self.chosen_surface() if surface == None: self.message('Select a surface') return radius = self.radius_from_gui() if radius == None: return from chimera import selection atoms = selection.currentAtoms() bonds = selection.currentBonds() from SurfaceZone import path_points, surface_zone points = path_points(atoms, bonds, surface.openState.xform.inverse()) if len(points) > 0: surface_zone(surface, points, radius, auto_update = True) else: self.message('No atoms are selected')
def color_zone_cb(self, event = None): self.message('') surface = self.chosen_surface() if surface == None: self.message('Select a surface') return radius = self.radius_from_gui() if radius == None: return xform_to_surface = surface.openState.xform.inverse() from chimera import selection atoms = selection.currentAtoms() bonds = selection.currentBonds() from ColorZone import points_and_colors, color_zone points, colors = points_and_colors(atoms, bonds, xform_to_surface) if len(points) > 0: color_zone(surface, points, colors, radius, auto_update = True) else: self.message('No atoms are selected')
def _any_selected(self): from chimera import selection, Molecule, MSMSModel, PseudoBondGroup text = "" numAtoms = len(selection.currentAtoms()) if numAtoms: text = "%d atom" % numAtoms if numAtoms > 1: text += "s" numBonds = len(selection.currentBonds()) if numBonds: if text: text += ", " text += "%d bond" % numBonds if numBonds > 1: text += "s" numEdges = len(selection.currentEdges()) if numEdges != numBonds: if text: text += ", " numPBonds = numEdges - numBonds text += "%d pbond" % numPBonds if numPBonds > 1: text += "s" graphs = selection.currentGraphs() numSurfs = numObjs = 0 for g in graphs: if isinstance(g, (Molecule, PseudoBondGroup)): continue if isinstance(g, MSMSModel) or "surf" in g.__class__.__name__.lower(): numSurfs += 1 else: numObjs += 1 if numSurfs: if text: text += ", " text += "%d surf" % numSurfs if numSurfs > 1: text += "s" if numObjs: if text: text += ", " text += "%d obj" % numObjs if numObjs > 1: text += "s" import help if not text: help.register(self.selections_button, balloon="no selection") show_message("selection cleared", blankAfter=5) return False else: help.register(self.selections_button, balloon=text) if self.first_selection: self.first_selection = False show_message(text, followWith="up-arrow to increase selection " "(atoms->residues->chains etc.)") else: show_message(text) return True
def selBonds(noneReturnsAll=True, implied=False, create=False): bonds = selection.currentBonds() extendSelection(bonds, 'bonds', noneReturnsAll, implied, create) return bonds