コード例 #1
0
ファイル: chainID.py プロジェクト: davem22101/semanticscience
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
ファイル: chainID.py プロジェクト: davem22101/semanticscience
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
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
ファイル: chain.py プロジェクト: davem22101/semanticscience
					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()