示例#1
0
def prev_updateChains(trigName, myData, changes):
	if changes and not changes.created and not changes.deleted:
		return

	unseen = prevChainIDs.copy()
	new = {}
	for mol in chimera.openModels.list(modelTypes=[chimera.Molecule]):
		for res in mol.residues:
			chainID = res.id.chainId
			if prevChainIDs.has_key(chainID):
				if unseen.has_key(chainID):
					del unseen[chainID]
			else:
				new[chainID] = 1
	if not new and not unseen:
		return
	for newChainID in new.keys():
		selMgr.addSelector(registrant, [selMgr.CHAINID,
					chainIDtoName(newChainID)],
					selectorTemplate % (newChainID,))
	prevChainIDs.update(new)
	for formerChainID in unseen.keys():
		selMgr.deleteSelector(registrant, [selMgr.CHAINID,
					chainIDtoName(formerChainID)])
		del prevChainIDs[formerChainID]
	
	selMgr.makeCallbacks()
示例#2
0
def prev_updateChains(trigName, myData, changes):
    if changes and not changes.created and not changes.deleted:
        return

    unseen = prevChainIDs.copy()
    new = {}
    for mol in chimera.openModels.list(modelTypes=[chimera.Molecule]):
        for res in mol.residues:
            chainID = res.id.chainId
            if prevChainIDs.has_key(chainID):
                if unseen.has_key(chainID):
                    del unseen[chainID]
            else:
                new[chainID] = 1
    if not new and not unseen:
        return
    for newChainID in new.keys():
        selMgr.addSelector(
            registrant,
            [selMgr.CHAINID, chainIDtoName(newChainID)],
            selectorTemplate % (newChainID, ))
    prevChainIDs.update(new)
    for formerChainID in unseen.keys():
        selMgr.deleteSelector(
            registrant,
            [selMgr.CHAINID, chainIDtoName(formerChainID)])
        del prevChainIDs[formerChainID]

    selMgr.makeCallbacks()
示例#3
0
def updateResidues(trigName, myData, changes):
	if changes and not changes.created and not changes.deleted:
		return
	unseen = prevResidues.copy()
	from chimera.resCode import nucleic3to1, protein3to1
	new = {}
	for mol in chimera.openModels.list(modelTypes=[chimera.Molecule]):
		for res in mol.residues:
			if prevResidues.has_key(res.type):
				if unseen.has_key(res.type):
					del unseen[res.type]
			else:
				# we will add 1 to these numbers when 
				# selectors are registered, so that
				# other residue-menu entries precede these
				# selectors are are separated from them
				# with a menu separator
				if res.type in protein3to1:
					grouping = 2
				elif res.type in nucleic3to1:
					grouping = 1
				else:
					grouping = 0
				new[res.type] = grouping
	if not new and not unseen:
		return
	for newResType, grouping in new.items():
		selMgr.addSelector(registrant, [selMgr.RESIDUE,
			SortString(newResType, cmpVal=1)],
			selectorTemplate % (newResType,), grouping=grouping+1)
	counts = [0] * 3
	for grouping in prevResidues.values():
		counts[grouping] += 1
	prevResidues.update(new)
	for formerResType in unseen.keys():
		selMgr.deleteSelector(registrant,
					[selMgr.RESIDUE, formerResType])
		del prevResidues[formerResType]
	newCounts = [0] * 3
	for grouping in prevResidues.values():
		newCounts[grouping] += 1
	for i, oldCount in enumerate(counts):
		newCount = newCounts[i]
		needOld = oldCount > 1
		needNew = newCount > 1
		if needNew == needOld:
			continue
		groupNames = [
			SortString("all nonstandard", cmpVal=0),
			SortString("standard nucleic acids", cmpVal=0),
			SortString("standard amino acids", cmpVal=0)
		]
		if needNew:
			# add a group entry
			selMgr.addSelector(registrant, [selMgr.RESIDUE,
				groupNames[i]], groupTemplate % [
					("not ", "standard3to1"),
					("", "nucleic3to1"),
					("", "protein3to1")
				][i], grouping=i+1)
		else:
			# delete old group entry
			selMgr.deleteSelector(registrant,
					[selMgr.RESIDUE, groupNames[i]])
	
	selMgr.makeCallbacks()
示例#4
0
def updateChains(trigName, myData, changes):
	if changes and not changes.created and not changes.deleted:
		return

	global prevChainIDs
	# would like a two-level shallow copy!
	unseen = {}
	for chainID, prevMols in prevChainIDs.items():
		unseen[chainID] = prevMols.copy()
	nextChainIDs = {}
	new = {}
	for mol in chimera.openModels.list(modelTypes=[chimera.Molecule]):
		for res in mol.residues:
			chainID = res.id.chainId
			if chainID in nextChainIDs:
				if mol in nextChainIDs[chainID]:
					continue
				nextChainIDs[chainID].add(mol)
			else:
				nextChainIDs[chainID] = set([mol])
			if chainID in unseen and mol in unseen[chainID]:
				unseen[chainID].remove(mol)
				if not unseen[chainID]:
					del unseen[chainID]
			if chainID in prevChainIDs \
			and mol in prevChainIDs[chainID]:
				continue
			if chainID in new:
				new[chainID].add(mol)
			else:
				new[chainID] = set([mol])
	if not new and not unseen:
		return
	# if prev and next differ in need for rollover, nuke the old 
	# selectors (put the old ones in 'unseen' and the next ones in 'new')
	for chainID, prevMols in prevChainIDs.items():
		if chainID in nextChainIDs:
			numNext = len(nextChainIDs[chainID])
		else:
			numNext = 0
		if (len(prevMols) <= 1) == (numNext <= 1):
			continue
		unseen.setdefault(chainID, set()).update(prevMols)
		if len(prevMols) > 1:
			selMgr.deleteSelector(registrant, [selMgr.CHAINID,
					chainIDtoName(chainID), "all"])
		if numNext:
			new.setdefault(chainID, set()).update(nextChainIDs[chainID])
	for chainID, mols in unseen.items():
		chainName = chainIDtoName(chainID)
		prevMols = prevChainIDs[chainID]
		if len(prevMols) == 1:
			# non-rollover
			selMgr.deleteSelector(registrant, [selMgr.CHAINID,
							chainName], prune=True)
		else:
			for mol in mols:
				selMgr.deleteSelector(registrant,
						[selMgr.CHAINID, chainName,
						molToName(mol)], prune=True)
	for mols in unseen.values():
		for mol in mols:
			if mol not in _molNames:
				continue
			for nmols in nextChainIDs.values():
				if mol in nmols:
					break
			else:
				del _molNames[mol]
	for chainID, mols in new.items():
		chainName = chainIDtoName(chainID)
		nextMols = nextChainIDs[chainID]
		if len(nextMols) == 1:
			# non-rollover
			selMgr.addSelector(registrant, [selMgr.CHAINID,
						chainName], selector(chainID),
						grouping=0)
		else:
			for mol in mols:
				selMgr.addSelector(registrant, [selMgr.CHAINID,
						chainName, molToName(mol)],
						selector(chainID, mol))
			selMgr.addSelector(registrant, [selMgr.CHAINID,
					chainName, "all"], selector(chainID),
					grouping=1)

	prevChainIDs = nextChainIDs
	selMgr.makeCallbacks()
示例#5
0
frequentElements = ["C", "O", "N", "H", "P", "S"]
elementRanges = [("Ac", "Ba"), ("Be", "Cl"), ("Cm", "F"), ("Fe", "Hg"),
                 ("Ho", "Lu"), ("Md", "Ni"), ("No", "Po"), ("Pr", "S"),
                 ("Sb", "Tc"), ("Te", "Zr")]
selectorTemplate = """\
selAdd = []
for mol in molecules:
        for atom in mol.atoms:
                if atom.element.name == '%s':
                        selAdd.append(atom)
sel.add(selAdd)
"""
from chimera import elements
for element in frequentElements:
    selMgr.addSelector("element",
                       [selMgr.CHEMISTRY, elementSelCategory, element],
                       selectorTemplate % (element, ))
for element in elements.name:
    if element == "LP":
        # ignore lone pair "element"
        continue
    for range in elementRanges:
        if element < range[0] or element > range[1]:
            continue
        selMgr.addSelector("element", [
            selMgr.CHEMISTRY, elementSelCategory, "other",
            "%s-%s" % range, element
        ], selectorTemplate % (element, ))
        break
selMgr.makeCallbacks()
del element, range
示例#6
0
					selAdd.extend(atoms[bbAtom])
				except KeyError:
					pass
		else:
			for name, atomList in atoms.items():
				if not bbAtoms.has_key(name):
					selAdd.extend(atomList)
sel.add(selAdd)
sel.addImplied(vertices=0)
"""
chainInfo = {
	"minimal":
		{ "backbone": 1, "minimal": 1, "fullSide": 0 },
	"full":
		{ "backbone": 1, "minimal": 0, "fullSide": 0 },
	"with CA/C1'":
		{ "backbone": 0, "minimal": 0, "fullSide": 1 },
	"without CA/C1'":
		{ "backbone": 0, "minimal": 0, "fullSide": 0 }
}
for chainType, infoDict in chainInfo.items():
	if infoDict["backbone"]:
		subCat = "backbone"
	else:
		subCat = "side chain/base"
	selMgr.addSelector("main/side chain", [selMgr.STRUCTURE,
		subCat, chainType], selectorTemplate % infoDict)
selMgr.makeCallbacks()
del chainType, infoDict

示例#7
0
def updateChains(trigName, myData, changes):
    if changes and not changes.created and not changes.deleted:
        return

    global prevChainIDs
    # would like a two-level shallow copy!
    unseen = {}
    for chainID, prevMols in prevChainIDs.items():
        unseen[chainID] = prevMols.copy()
    nextChainIDs = {}
    new = {}
    for mol in chimera.openModels.list(modelTypes=[chimera.Molecule]):
        for res in mol.residues:
            chainID = res.id.chainId
            if chainID in nextChainIDs:
                if mol in nextChainIDs[chainID]:
                    continue
                nextChainIDs[chainID].add(mol)
            else:
                nextChainIDs[chainID] = set([mol])
            if chainID in unseen and mol in unseen[chainID]:
                unseen[chainID].remove(mol)
                if not unseen[chainID]:
                    del unseen[chainID]
            if chainID in prevChainIDs \
            and mol in prevChainIDs[chainID]:
                continue
            if chainID in new:
                new[chainID].add(mol)
            else:
                new[chainID] = set([mol])
    if not new and not unseen:
        return
    # if prev and next differ in need for rollover, nuke the old
    # selectors (put the old ones in 'unseen' and the next ones in 'new')
    for chainID, prevMols in prevChainIDs.items():
        if chainID in nextChainIDs:
            numNext = len(nextChainIDs[chainID])
        else:
            numNext = 0
        if (len(prevMols) <= 1) == (numNext <= 1):
            continue
        unseen.setdefault(chainID, set()).update(prevMols)
        if len(prevMols) > 1:
            selMgr.deleteSelector(
                registrant,
                [selMgr.CHAINID, chainIDtoName(chainID), "all"])
        if numNext:
            new.setdefault(chainID, set()).update(nextChainIDs[chainID])
    for chainID, mols in unseen.items():
        chainName = chainIDtoName(chainID)
        prevMols = prevChainIDs[chainID]
        if len(prevMols) == 1:
            # non-rollover
            selMgr.deleteSelector(registrant, [selMgr.CHAINID, chainName],
                                  prune=True)
        else:
            for mol in mols:
                selMgr.deleteSelector(
                    registrant, [selMgr.CHAINID, chainName,
                                 molToName(mol)],
                    prune=True)
    for mols in unseen.values():
        for mol in mols:
            if mol not in _molNames:
                continue
            for nmols in nextChainIDs.values():
                if mol in nmols:
                    break
            else:
                del _molNames[mol]
    for chainID, mols in new.items():
        chainName = chainIDtoName(chainID)
        nextMols = nextChainIDs[chainID]
        if len(nextMols) == 1:
            # non-rollover
            selMgr.addSelector(registrant, [selMgr.CHAINID, chainName],
                               selector(chainID),
                               grouping=0)
        else:
            for mol in mols:
                selMgr.addSelector(registrant,
                                   [selMgr.CHAINID, chainName,
                                    molToName(mol)], selector(chainID, mol))
            selMgr.addSelector(registrant, [selMgr.CHAINID, chainName, "all"],
                               selector(chainID),
                               grouping=1)

    prevChainIDs = nextChainIDs
    selMgr.makeCallbacks()
示例#8
0
# --- UCSF Chimera Copyright ---
# Copyright (c) 2000 Regents of the University of California.
# All rights reserved.  This software provided pursuant to a
# license agreement containing restrictions on its disclosure,
# duplication and use.  This notice must be embedded in or
# attached to all copies, including partial copies, of the
# software or any revisions or derivations thereof.
# --- UCSF Chimera Copyright ---
#
# $Id: ss.py 26655 2009-01-07 22:02:30Z gregc $

from manager import selMgr

# register some element type selectors
ssSelCategory = "secondary structure"
selectorTemplate = """\
selAdd = []
for mol in molecules:
        for res in mol.residues:
                if res.is%s:
                        selAdd.append(res)
sel.add(selAdd)
sel.addImplied(vertices=0)
"""
for ssType in ["helix", "turn", "strand"]:
    selMgr.addSelector("secondary structure",
                       [selMgr.STRUCTURE, ssSelCategory, ssType],
                       selectorTemplate % (ssType.capitalize(), ))
selMgr.makeCallbacks()
del ssType
				addBonds[bond] = 1
		if addBonds or not atom.bonds:
			selAdd.update(addBonds)
			selAdd[atom] = 1
sel.add(selAdd)
"""

comboModes = [
	("wire", chimera.Atom.Dot, chimera.Bond.Wire),
	("stick", chimera.Atom.EndCap, chimera.Bond.Stick),
	("ball and stick", chimera.Atom.Ball, chimera.Bond.Stick),
	("sphere", chimera.Atom.Sphere, chimera.Bond.Wire)
]
registrant = "draw mode"
for name, atomMode, bondMode in comboModes:
	selMgr.addSelector(registrant, [dmSelCategory, name],
			combinedSelectorTemplate % (atomMode, bondMode))
for name, atomMode in [	("dot", chimera.Atom.Dot),
			("endcap (stick)", chimera.Atom.EndCap),
			("ball", chimera.Atom.Ball),
			("sphere", chimera.Atom.Sphere) ]:
	selMgr.addSelector(registrant, [dmSelCategory, dmAtomCategory, name],
					atomSelectorTemplate % atomMode)
for name, bondMode in [	("wire", chimera.Bond.Wire),
			("stick", chimera.Bond.Stick), ]:
	selMgr.addSelector(registrant, [dmSelCategory, dmBondCategory, name],
					bondSelectorTemplate % bondMode)
selMgr.makeCallbacks()
del name, atomMode, bondMode

示例#10
0
elementRanges = [
  ("Ac", "Ba"), ("Be", "Cl"), ("Cm", "F"), ("Fe", "Hg"), ("Ho", "Lu"),
  ("Md", "Ni"), ("No", "Po"), ("Pr", "S"), ("Sb", "Tc"), ("Te", "Zr")
]
selectorTemplate = """\
selAdd = []
for mol in molecules:
        for atom in mol.atoms:
                if atom.element.name == '%s':
                        selAdd.append(atom)
sel.add(selAdd)
"""
from chimera import elements
for element in frequentElements:
	selMgr.addSelector("element",
			[selMgr.CHEMISTRY, elementSelCategory, element],
			selectorTemplate % (element,))
for element in elements.name:
	if element == "LP":
		# ignore lone pair "element"
		continue
	for range in elementRanges:
		if element < range[0] or element > range[1]:
			continue
		selMgr.addSelector("element", [selMgr.CHEMISTRY,
			elementSelCategory, "other", "%s-%s" % range, element],
			selectorTemplate % (element,))
		break
selMgr.makeCallbacks()
del element, range
        "backbone": 1,
        "minimal": 1,
        "fullSide": 0
    },
    "full": {
        "backbone": 1,
        "minimal": 0,
        "fullSide": 0
    },
    "with CA/C1'": {
        "backbone": 0,
        "minimal": 0,
        "fullSide": 1
    },
    "without CA/C1'": {
        "backbone": 0,
        "minimal": 0,
        "fullSide": 0
    }
}
for chainType, infoDict in chainInfo.items():
    if infoDict["backbone"]:
        subCat = "backbone"
    else:
        subCat = "side chain/base"
    selMgr.addSelector("main/side chain",
                       [selMgr.STRUCTURE, subCat, chainType],
                       selectorTemplate % infoDict)
selMgr.makeCallbacks()
del chainType, infoDict
# Copyright (c) 2000 Regents of the University of California.
# All rights reserved.  This software provided pursuant to a
# license agreement containing restrictions on its disclosure,
# duplication and use.  This notice must be embedded in or
# attached to all copies, including partial copies, of the
# software or any revisions or derivations thereof.
# --- UCSF Chimera Copyright ---
#
# $Id: proteinNuc.py 26655 2009-01-07 22:02:30Z gregc $

from manager import selMgr

# register some protein/nucleic selectors
selectorTemplate = """\
from chimera.misc import principalAtom
selAdd = []
for mol in molecules:
        for res in mol.residues:
		pa = principalAtom(res)
                if pa and pa.name in %s:
                        selAdd.append(res)
sel.add(selAdd)
sel.addImplied(vertices=0)
"""
for name, pa in [("protein", ["CA"]), ("nucleic acid", ["C4'", "P"])]:
	selMgr.addSelector("protein/nucleic", [selMgr.STRUCTURE, name],
						selectorTemplate % (repr(pa),))
selMgr.makeCallbacks()
del name, pa