예제 #1
0
	def _getMolecules(self, assignsel, usesel, restrict):
		if assignsel or usesel:
			sel = selection.currentMolecules()
			if usesel:
				for r in selection.currentResidues():
					restrict[r] = True
				for a in selection.currentAtoms():
					restrict[a] = True
				for m in sel:
					restrict[m] = True
		if assignsel:
			molecules = sel
		else:
			molecules = []
		if not molecules:
			molecules = chimera.openModels.list(
					modelTypes=[chimera.Molecule])
		return molecules
예제 #2
0
def selMolecules(noneReturnsAll=True, implied=False, create=False):
    mol = selection.currentMolecules()
    extendSelection(mol, 'molecules', noneReturnsAll, implied, create)
    return mol
예제 #3
0
	def _selectionChangedCB(self, trigger, closure, ignore):
		from chimera import selection
		mols = selection.currentMolecules()
		selected = [ m for m in mols if m in self.molList ]
		self.modBaseTable.highlight(selected)
예제 #4
0
def unselMolecules():
	from chimera.selection import currentMolecules
	selMolecules = currentMolecules(asDict=True)
	return filter(lambda m: m not in selMolecules,
		chimera.openModels.list(modelTypes=[chimera.Molecule]))
예제 #5
0
def createHBonds(models=None, intramodel=True, intermodel=True, relax=True,
	distSlop=recDistSlop, angleSlop=recAngleSlop, twoColors=False,
	selRestrict=None, lineWidth=1.0, saveFile=None, batch=False,
	interSubmodel=False, makePseudobonds=True, retainCurrent=False,
	reveal=False, namingStyle=None, log=False, cacheDA=None,
	color=(0.0, 0.8, 0.9, 1.0), slopColor=(0.95, 0.5, 0.0, 1.0)):

	"""Wrapper to be called by gui and command line.

	   Use findHBonds for other programming applications.
	"""

	inColors = (color, slopColor)
	outColors = []
	for c in inColors:
		if isinstance(c, basestring):
			from chimera.colorTable import getColorByName
			try:
				outColors.append(getColorByName(c))
			except KeyError:
				raise "No known color named '%s'" % c
		elif isinstance(c, tuple):
			oc = chimera.MaterialColor()
			oc.ambientDiffuse = c[:3]
			if len(c) > 3:
				oc.opacity = c[-1]
			outColors.append(oc)
		else:
			outColors.append(c)
	bondColor, slopColor = outColors

	donors = acceptors = None
	if selRestrict is not None:
		selAtoms = currentAtoms(asDict=True)
		if not selAtoms:
			if batch:
				return
			raise UserError("No atoms in selection.")
		if (not intermodel or selRestrict == "both") and models is None:
			# intramodel only or both ends in selection
			models = currentMolecules()
		if selRestrict == "both":
			# both ends in selection
			donors = acceptors = selAtoms

	if models is None:
		models = chimera.openModels.list(modelTypes=[chimera.Molecule])

	if not relax:
		distSlop = angleSlop = 0.0

	if cacheDA == None:
		# cache trajectories by default
		cacheDA = len(models) == 1 and len(models[0].coordSets) > 1

	hbonds = findHBonds(models, intermodel=intermodel,
		intramodel=intramodel, distSlop=distSlop,
		angleSlop=angleSlop, donors=donors, acceptors=acceptors,
		interSubmodel=interSubmodel, cacheDA=cacheDA)
	if selRestrict and donors == None:
		hbonds = _filterBySel(hbonds, selAtoms, selRestrict)
	
	outputInfo = (intermodel, intramodel, relax, distSlop, angleSlop,
							models, hbonds)
	if log:
		import sys
		# provide a separator from other output
		print>>sys.stdout, ""
		_fileOutput(sys.stdout, outputInfo, namingStyle)
	if saveFile == '-':
		from MolInfoDialog import SaveMolInfoDialog
		SaveMolInfoDialog(outputInfo, _fileOutput,
					initialfile="hbond.info",
					title="Choose H-Bond Save File",
					historyID="H-bond info")
	elif saveFile is not None:
		_fileOutput(saveFile, outputInfo, namingStyle)

	replyobj.status("%d hydrogen bonds found\n"
				% len(hbonds), log=1, blankAfter=120)
	if not makePseudobonds:
		return

	if twoColors:
		# color relaxed constraints differently
		precise = findHBonds(models,
			intermodel=intermodel, intramodel=intramodel,
			donors=donors, acceptors=acceptors,
			interSubmodel=interSubmodel, cacheDA=cacheDA)
		if selRestrict and donors == None:
			precise = _filterBySel(precise, selAtoms, selRestrict)
		# give another opportunity to read the result...
		replyobj.status("%d hydrogen bonds found\n" % len(hbonds),
								blankAfter=120)

	from chimera.misc import getPseudoBondGroup
	pbg = getPseudoBondGroup("hydrogen bonds", issueHint=True)
	if not retainCurrent:
		pbg.deleteAll()
	pbg.lineWidth = lineWidth

	for don, acc in hbonds:
		if don.associated(acc, "hydrogen bonds"):
			continue
		pb = pbg.newPseudoBond(don, acc)
		if twoColors:
			if (don, acc) in precise:
				color = bondColor
			else:
				color = slopColor
		else:
			color = bondColor
		pb.color = color
		if reveal:
			for end in [don, acc]:
				if end.display:
					continue
				for ea in end.residue.oslChildren():
					ea.display = True
def lists(level="atom", mode="any", attribute=None):
	import chimera
	from chimera import replyobj, selection
	mode = findBestMatch(mode, ["any", "all"])
	level = findBestMatch(level, ["atom", "residue", "chain", "molecule"])
	if level == "atom":
		if attribute is None:
			attribute = "idatmType"
		_reportAtoms(selection.currentAtoms(), attribute)
	elif level == "residue":
		if mode == "any":
			residues = selection.currentResidues()
		else:
			rMap = {}
			for a in selection.currentAtoms():
				l = rMap.setdefault(a.residue, [])
				l.append(a)
			residues = []
			for r, aList in rMap.iteritems():
				if len(r.atoms) == len(aList):
					residues.append(r)
		if attribute is None:
			attribute = "type"
		_reportResidues(residues, attribute)
	elif level == "chain":
		if mode == "any":
			chains = selection.currentChains()
		else:
			rcMap = {}
			cached = set([])
			cMap = {}
			for r in selection.currentResidues():
				if r.molecule not in cached:
					cached.add(r.molecule)
					for seq in r.molecule.sequences():
						for res in seq.residues:
							rcMap[res] = seq
				try:
					seq = rcMap[r]
				except KeyError:
					pass
				else:
					l = cMap.setdefault(seq, [])
					l.append(r)
			chains = []
			for seq, rList in cMap.iteritems():
				if len(seq) == len(rList):
					chains.append(seq)
		if attribute is None:
			attribute = "chain"
		_reportChains(chains, attribute)
	elif level == "molecule":
		if mode == "any":
			molecules = selection.currentMolecules()
		else:
			mMap = {}
			for a in selection.currentAtoms():
				l = mMap.setdefault(a.molecule, [])
				l.append(a)
			molecules = []
			for m, aList in mMap.iteritems():
				if len(m.atoms) == len(aList):
					molecules.append(m)
		if attribute is None:
			attribute = "name"
		_reportModels(molecules, attribute)
	else:
		raise chimera.UserError("\"%s\": unknown listselection level"
					% level)
예제 #7
0
def unselMolecules():
    from chimera.selection import currentMolecules
    selMolecules = currentMolecules(asDict=True)
    return filter(lambda m: m not in selMolecules,
                  chimera.openModels.list(modelTypes=[chimera.Molecule]))
예제 #8
0
def _nextSel():
    sel = selection.ItemizedSelection()
    sel.add(selection.currentBarrenGraphs())
    if selLevel == SELRES:
        items = []
        addResidues = {}
        for r in selection.currentResidues():
            addResidues[r] = 1
        selPseudoBonds = filter(
            lambda e, PB=chimera.PseudoBond: isinstance(e, PB),
            selection.currentEdges())
        # for currently selected chain-trace pseudobonds
        # act as if they select their residues
        for ct in filter(
                lambda e: isinstance(e.pseudoBondGroup, chimera.ChainTrace),
                selPseudoBonds):
            addResidues[ct.atoms[0].residue] = 1
            addResidues[ct.atoms[1].residue] = 1
        for r in addResidues.keys():
            items.extend(r.atoms)
        sel.add(items)
        sel.addImplied(vertices=0)
        sel.add(selPseudoBonds)
        # add chain trace pseudobonds that should be selected
        sel.add(selChainTrace(sel))

    elif selLevel == SELCHAIN:
        chainIDs = {}
        for a in selection.currentAtoms():
            chainID = a.residue.id.chainId
            try:
                chainIDs[a.molecule][chainID] = 1
            except KeyError:
                chainIDs[a.molecule] = {chainID: 1}
        items = []
        for m, ids in chainIDs.items():
            for a in m.atoms:
                if not ids.has_key(a.residue.id.chainId):
                    continue
                items.append(a)
                items.extend(a.bonds)
        pbgs = {}
        for pb in filter(lambda b, PB=chimera.PseudoBond: isinstance(b, PB),
                         selection.currentEdges()):
            pbgs[pb.pseudoBondGroup] = 1
        for pbg in pbgs.keys():
            if isinstance(pbg, chimera.ChainTrace):
                continue
            items.extend(pbg.pseudoBonds)
        sel.add(items)
        sel.add(selChainTrace(sel))

    elif selLevel == SELSUBMODEL:
        items = []
        for m in selection.currentMolecules():
            items.extend(m.atoms)
            items.extend(m.bonds)
        items.extend(
            filter(lambda e, PB=chimera.PseudoBond: isinstance(e, PB),
                   selection.currentEdges()))
        sel.add(items)
        sel.add(selChainTrace(sel))
    elif selLevel == SELMODEL:
        molDict = {}
        for m in selection.currentMolecules():
            osl = m.oslIdent()
            if '.' in osl:
                molDict[osl[:osl.index('.')]] = 1
            else:
                molDict[m] = 1
        items = []
        for mosl in molDict.keys():
            if isinstance(mosl, basestring):
                for m in selection.OSLSelection(mosl).molecules():
                    items.extend(m.atoms)
                    items.extend(m.bonds)
            else:
                items.extend(mosl.atoms)
                items.extend(mosl.bonds)
        items.extend(
            filter(lambda e, PB=chimera.PseudoBond: isinstance(e, PB),
                   selection.currentEdges()))
        sel.add(items)
        sel.add(selChainTrace(sel))
    elif selLevel == SELALL:
        global _topValid
        _topValid = True
        items = []
        if selection.currentMolecules():
            for m in chimera.openModels.list():
                if hasattr(m, 'atoms'):
                    items.extend(m.atoms)
                    items.extend(m.bonds)
        for e in selection.currentEdges():
            if isinstance(e, chimera.PseudoBond):
                pbsSelected = True
                break
        else:
            pbsSelected = False
        if pbsSelected:
            mgr = chimera.PseudoBondMgr.mgr()
            for grp in mgr.pseudoBondGroups:
                items.extend(grp.pseudoBonds)
        sel.add(items)
        sel.add(selChainTrace(sel))
        global _selAllHandler
        if _selAllHandler is not None:
            _selAllHandler = \
             chimera.openModels.addAddHandler(
               _addModelHandler, None)
    else:
        raise ValueError, "Bad selection level"

    # Handle selected surface pieces
    from Surface import selected_surface_pieces
    plist = selected_surface_pieces()
    mlist = set([p.model for p in plist])
    if selLevel == SELALL and len(mlist) > 0:
        from _surface import SurfaceModel
        mlist = chimera.openModels.list(modelTypes=[SurfaceModel])
    sel.add(mlist)

    return sel
예제 #9
0
def selMolecules(noneReturnsAll=True, implied=False, create=False):
	mol = selection.currentMolecules()
	extendSelection(mol, 'molecules', noneReturnsAll, implied, create)
	return mol