def select(self, only=False): from chimera.selection import setCurrent, addCurrent if only: setCurrent(self.bond) else: addCurrent(self.bond)
def selUp(): global _selChangeHandler, _atomChangeHandler needHandlers = False if not _selInfos[SELATOM:]: needHandlers = True _selInfos.append(_infoFromSel(selection.copyCurrent())) # go up levels until the selection changes global _IchangedSel, selLevel _IchangedSel = False while selLevel < SELALL: selLevel += 1 try: nextSel = _selInfos[selLevel][0] if selLevel == SELALL \ and not _topValid: raise IndexError, "new models present" except IndexError: nextSel = _nextSel() _selInfos.append(_infoFromSel(nextSel)) if len(nextSel) != len(_selInfos[selLevel - 1][0]): if not needHandlers: _IchangedSel = True selection.setCurrent(nextSel) break # delay the handlers until here in case setting the selection # causes other things to get selected (e.g. axes/planes) if needHandlers: _atomChangeHandler = chimera.triggers.addHandler( "Atom", _atomChangeCB, None) _selChangeHandler = chimera.triggers.addHandler( "selection changed", _selChangeCB, None)
def select_atoms_outside_map(): from chimera.replyobj import status, info from VolumeViewer import active_volume dr = active_volume() if dr is None: status('No density map opened.') return if dr.surface_model() == None or not dr.surface_model().display: status('No surface shown for map.') return levels = dr.surface_levels if len(levels) == 0: status('No surface shown for map.') return contour_level = min(levels) from chimera import selection atoms = selection.currentAtoms() aolist = atoms_outside_map(atoms, dr, contour_level) msg = ('%d of %d selected atoms outside %s at level %.5g' % (len(aolist), len(atoms), dr.name, contour_level)) status(msg) info(msg + '\n') selection.setCurrent(aolist)
def select_markers(markers, only=True): atoms = [m.atom for m in markers] from chimera.selection import setCurrent, addCurrent if only: setCurrent(atoms) else: addCurrent(atoms)
def restoreSelections(curSelIds, savedSels): selection.setCurrent(map(idLookup, curSelIds)) for selInfo in savedSels: selName, ids = selInfo sel = selection.ItemizedSelection() sel.add(map(idLookup, ids)) chimera.selection.saveSel(selName, sel)
def restoreSelections(curSelOsls, savedSels): selection.setCurrent(weedOSLlist(curSelOsls)) for selInfo in savedSels: selName, osls = selInfo sel = selection.ItemizedSelection() sel.add(weedOSLlist(osls)) chimera.selection.saveSel(selName, sel)
def restoreSelections(curSelIds, savedSels): from chimera import selection selection.setCurrent(map(idLookup, curSelIds)) for selInfo in savedSels: selName, ids = selInfo sel = selection.ItemizedSelection() sel.add(map(idLookup, ids)) chimera.selection.saveSel(selName, sel)
def _distTableSelCB(self, selDists): if self.distSelectsAtomsVar.get(): select = [] select.extend(selDists) for sd in selDists: select.extend(sd.atoms) selection.setCurrent(select) else: selection.removeCurrent(self.distances) selection.addCurrent(selDists)
def _angleTableSelCB(self, selAngles): if self.angleSelectsComponentsVar.get(): select = [] for atoms in selAngles: select.extend(atoms) atomSet = set(atoms) for a in atoms: for b in a.bonds: if b.otherAtom(a) in atomSet: select.append(b) selection.setCurrent(select)
def _itemsSelectAtoms(self, items, add=False): atoms = set() for item in items: atoms.update(item.atoms) if self.geomSelAtomsVar.get(): if add: selection.addCurrent(atoms) else: selection.setCurrent(atoms) elif set(atoms) == set(selection.currentAtoms()): selection.removeCurrent(atoms)
def selDown(): if not _selInfos[SELATOM:]: return # keep lowering level until selection changes global _IchangedSel, selLevel _IchangedSel = False while selLevel > SELNONE: selLevel -= 1 if len(_selInfos[selLevel][0]) != len(_selInfos[selLevel + 1][0]): _IchangedSel = True selection.setCurrent(_selInfos[selLevel][0]) break
def select_atoms_and_chains(atoms, cplist): # Don't select chains where atoms are selected. rlist = list(set([a.residue for a in atoms])) import MultiScale ac = set(MultiScale.containing_chain_pieces(cplist, rlist)) splist = [cp.surface_piece for cp in cplist if not cp in ac and cp.surface_piece != None] from chimera import selection sel = selection.ItemizedSelection() sel.add(atoms + splist) sel.addImplied(vertices = False, edges = True) # Select bonds selection.setCurrent(sel)
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 doApply(self, target, solid, track, selAtoms, bias, prune, pruneDistance): m1, m2 = target if prune: m1_list = SurfMaker.GetAtomList(m1, m2, pruneDistance) m2_list = SurfMaker.GetAtomList(m2, m1, pruneDistance) else: m1_list = SurfMaker.GetAtomList(m1) m2_list = SurfMaker.GetAtomList(m2) if not m1_list or not m2_list: raise chimera.UserError("No interface surface found") p = SurfMaker.UnpackIntersurfData(m1_list, m2_list) tetras = SurfMaker.ComputeTetrahedralization(p) surfPoints, surfTriangles, surfAtoms = SurfMaker.ComputeSurface(p, tetras, bias) surfMetric = [ getDistance(x[0], x[1]) for x in surfAtoms ] lo = min(surfMetric) hi = max(surfMetric) scale = hi - lo markers = [ (lo + m['xy'][0] * scale, m['rgba']) for m in self.histogramMarkers ] surfColors = [ getHistogramColor(x, markers) for x in surfMetric ] self.histogramData = (lo, hi, surfMetric) def myMakeBars(numBins, data=self.histogramData): return makeBars(numBins, data) self.histogram["datasource"] = (lo, hi, myMakeBars) self._show_geometry(surfPoints, surfTriangles, surfColors, solid, track) if selAtoms: from chimera import selection atomSet = set([]) for a1, a2 in surfAtoms: atomSet.add(a1) atomSet.add(a2) sel = selection.ItemizedSelection() sel.add(atomSet) sel.addImplied(vertices=False) selection.setCurrent(sel)
# rc('aromatic disk') # modify model to display double and triple bonds rc('select #0') atoms = currentAtoms() bondsList = [] for a in atoms: for b in bonds: if b not in bondsList: bondsList = bondsList + [b] for bond in bondsList: setCurrent(bond) length = bond.length() length = format(length, '.3f') if float(length) in doubleBonds: rc('setattr b radius 0.2 sel;wait') elif float(length) in tripleBonds: rc('setattr b radius 0.3 sel;wait') rc('windowsize 800 800;wait') rc('setzoom 30.0;wait') rc('center;wait') # take images of molecule i = 0
def select_all(): 'Select all models' from chimera import selection, openModels selection.setCurrent(openModels.list())
def clear_selection(): 'Clear selection' from chimera import selection selection.setCurrent([])