def buildChainMenu(self, event=None): if not hasattr(self, 'chainVar'): self.chainVar = {} if not hasattr(self, 'oldchainVar'): self.oldchainVar = {} chMols = MoleculeSet([]) if len(self.molSet): chMols = MoleculeSet( filter(lambda x: Chain in x.levels, self.molSet)) chainIDList = [] if len(chMols): chains = chMols.findType(Chain) if chains == None: return for i in chains: chainIDList.append(i.full_name()) self.buildMenu(self.chainMB, chainIDList, self.chainVar, self.oldchainVar, self.getChainVal)
def getObjects(self, column): # return a list of objects associated with this node and possibly # other seleted nodes. For selection we return a list for each type # ( i.e. Atom, Residue, etc..) # if the node is selected, collect object from all other selected nodes resultAtoms = AtomSet([]) resultResidues = ResidueSet([]) resultChains = ChainSet([]) resultMolecules = MoleculeSet([]) buttonValue = self.chkbtVar[column].get() if self.selected: for node in self.tree.list_selected: node.chkbtVar[column].set(buttonValue) result = node.getNodes(column) obj = result[0] if isinstance(obj, Atom): resultAtoms += result elif isinstance(obj, Residue): resultResidues += result elif isinstance(obj, Chain): resultChains += result elif isinstance(obj, Molecule) or isinstance(obj, Protein): resultMolecules += result result = [] if len(resultAtoms): result.append(resultAtoms) if len(resultResidues): result.append(resultResidues) if len(resultChains): result.append(resultChains) if len(resultMolecules): result.append(resultMolecules) return result else: return [self.getNodes(column)]
def doit(self, Klass, KlassSet=None): if type(Klass) == types.StringType: if Klass in self.levelDict.keys(): Klass = self.levelDict[Klass] else: msg = Klass + "string does not map to a valid level" self.warningMsg(msg) return "ERROR" if Klass is Protein: Klass = Molecule if len(self.vf.selection): self.vf.selection = self.vf.selection.findType(Klass).uniq() else: if Klass == Molecule: self.vf.selection = MoleculeSet([]) elif Klass == Chain: self.vf.selection = ChainSet([]) elif Klass == Residue: self.vf.selection = ResidueSet([]) elif Klass == Atom: self.vf.selection = AtomSet([]) self.vf.selectionLevel = Klass self.vf.ICmdCaller.setLevel(Klass, KlassSet=None) if self.vf.hasGui: col = self.vf.ICmdCaller.levelColors[Klass.__name__] c = (col[0] / 1.5, col[1] / 1.5, col[2] / 1.5) self.vf.GUI.pickLabel.configure(background=TkColor(c)) msg = '%d %s(s)' % (len( self.vf.selection), self.vf.selectionLevel.__name__) self.vf.GUI.pickLabel.configure(text=msg) if hasattr(self.vf, 'select'): self.vf.select.updateSelectionIcons() self.levelVar.set(self.vf.selectionLevel.__name__)
def addSetLine(self, name, set): """ add a line to the dashboard with a given molecular fragment """ from MolKit.molecule import MoleculeSet node = MoleculeSet() node.setSetAttribute('_set', set) node.setSetAttribute('name', name) node.setSetAttribute('treeNodeClass', SetWithButtons) self.onAddObjectToViewer(node)
def __init__(self, master, check=0, molSet=MoleculeSet([]), userPref='cS', vf=None, all=1, crColor=(0., 1., 0), clearButton=True, showButton=True, sets=None, **kw): if not kw.get('packCfg'): self.packCfg = {'side': 'top', 'anchor': 'w', 'fill': 'x'} self.sets = sets #all is a shortcut to use all of default values if 'all' in kw.keys(): all = 1 elif __debug__: if check: apply(checkKeywords, ('stringSelector', self.entryKeywords), kw) Tkinter.Frame.__init__(self, master) ##???? Tkinter.Pack.config(self, side='left', anchor='w') #to make a stringSelector need vf, moleculeSet, selString self.master = master self.molSet = molSet self.residueSelector = ResidueSetSelector() self.atomSelector = AtomSetSelector() self.userPref = userPref self.vf = vf if not self.vf is None: self.addGeom(crColor) else: self.showCross = None self.molCts = {} self.chainCts = {} # optsDict includes defaults for all possible widgets # in practice # user can specify which widgets to put into gui d = self.optsDict = {} #first check for menubuttons: llists = [self.entryKeywords, self.menuKeywords, self.buttonKeywords] if all: if not clearButton: self.buttonKeywords.remove("clearBut") if not showButton: self.buttonKeywords.remove("showBut") for l in llists: for key in l: d[key] = 1 else: for l in llists: for key in l: d[key] = kw.get(key) self.flexChildren = { 'mol': ['molLabel', 'molEntry'], 'chain': ['chainLabel', 'chainEntry'], 'res': ['resLabel', 'resEntry'], 'atom': ['atomLabel', 'atomEntry'], } for w in ['molWids', 'chainWids', 'resWids', 'atomWids']: if kw.get(w): lab = w[:-4] s = lab + 'Label' d[s] = 1 s1 = lab + 'Entry' d[s1] = 1 # instantiate all Tkinter variables (?) #DON"T HAVE ANY??? self.buildTkVars() # only build requested widgets(?) self.buildifdDict() # build commandDictionary self.buildCmdDict() self.buildGUI()
def go(self): msgStr = None if self.moleculeSet: self.molSet = self.getMolecules(self.moleculeSet, self.selList[0]) else: self.molSet = None return [] # return [], msgStr # SPLIT here if mol.children==Atoms # possibly: self.Mols4levels=filter(lambda x: x.childrenSetClass == ChainSet, self.molSet) # then process the others separately....????????? # eg self.Mols2levels=filter(lambda x: x.childrenSetClass == AtomSet, self.molSet) # self.Mols2levels would get fed to self.getAtoms and two results ???merged??? if not self.molSet: self.chainSet = None msgStr = str(self.selList[0]) + " selected no molecules" return [] # return [], msgStr noChainMols = MoleculeSet( [x for x in self.molSet if Chain not in x.levels]) haveChainMols = MoleculeSet( [x for x in self.molSet if Chain in x.levels]) # build the residues belonging to molecules w/ no Chains (!WEIRD!) ncrs = ResidueSet() for item in noChainMols: if Residue in item.levels: itemRes = item.allAtoms.parent.uniq() ncrs = ncrs + itemRes if ncrs: noChainResSet = self.getResidues(ncrs, self.selList[2]) if not noChainResSet: noChainResSet = ResidueSet() else: noChainResSet = ResidueSet() if len(haveChainMols): self.chainSet = self.getChains(haveChainMols.findType(Chain), self.selList[1]) if self.chainSet: haveChainResSet = self.getResidues(self.chainSet.findType(Residue), self.selList[2]) # also test noChainMols for residues if haveChainResSet: self.resSet = haveChainResSet + noChainResSet else: self.resSet = noChainResSet else: self.resSet = noChainResSet ##don't return unless selList[2]!==[''] if self.selList[1] != ['']: msgStr = str(self.selList[1]) + " selected no chains" return [] # return [], msgStr # now: if self.selList for Chain and Residue level was empty, get the Atoms from noChains if self.selList[1] == [''] and self.selList[2] == ['']: tla = AtomSet() for item in noChainMols: if Residue not in item.levels: tla = tla + item.allAtoms twoLevelAtoms = tla else: twoLevelAtoms = AtomSet() if self.resSet: resAts = self.resSet.findType(Atom) if twoLevelAtoms: resAts = resAts + twoLevelAtoms self.atomSet = self.getAtoms(resAts, self.selList[3]) else: if self.selList[2] != ['']: msgStr = str(self.selList[2]) + " selected no residues" return [] # return [], msgStr else: self.atomSet = self.getAtoms(twoLevelAtoms, self.selList[3]) selNodes = self.atomSet # find correct levelType to return # need to split atomSet into two parts: if self.atomSet: haveChainAtoms = AtomSet( [x for x in self.atomSet if x.top != x.parent]) haveNoChainAtoms = self.atomSet - haveChainAtoms if self.selList[3] == ['']: # change atoms to residues if haveChainAtoms: selNodes = haveChainAtoms.parent.uniq() else: selNodes = ResidueSet() if self.selList[2] == ['']: # change residues to chains if len(selNodes): selNodes = selNodes.parent.uniq() if self.selList[1] == ['']: # change chains to molecules if haveNoChainAtoms: noChainTops = haveNoChainAtoms.top.uniq() else: noChainTops = ProteinSet() if selNodes: selTops = selNodes.top.uniq() else: selTops = ProteinSet() selNodes = selTops + noChainTops if self.selList[0] == ['']: # change molecules to molecules(?)in the case of no strs if selNodes.__class__ != MoleculeSet: selNodes = MoleculeSet(selNodes.top.uniq()) else: msgStr = str(self.selList[3]) + " selected no atoms" for item in ['moleculeSet', 'molSet', 'chainSet', 'resSet', 'atomSet']: if hasattr(self, item): delattr(self, item) # exec('del self.'+item) return selNodes
msg = rec_file + " not found" assert os.path.exists(rec_file), msg recs = Read(rec_file) rec = recs[0] # locate the receptor atom css = CompoundStringSelector() rec_ats = css.select(recs, ratom_name)[0] msg = ratom_name + " did not match exactly 1 atom in " + rec_file assert len(rec_ats) == 1, msg rec_at = rec_ats[0] rec_at_coords = rec_at.coords if verbose: print("found rec_at = ", rec_at.full_name(), end=' ') print("with initial coords = ", rec_at.coords) # locate the ligand atom lig_ats = css.select(MoleculeSet([d.ligMol]), latom_name)[0] assert len(lig_ats) == 1 lig_at = lig_ats[0] print("found lig_at =>", lig_at.full_name()) print("initial coords=", lig_at.coords) init_coords = lig_at.coords #open the outputfile if os.path.exists(outputfilename): fptr = open(outputfilename, 'a') else: fptr = open(outputfilename, 'w') ostr = "run rec_at coords lig_at coords distance \n" fptr.write(ostr) print(" opened output file:", outputfilename) # set the pose to Run 1 ctr = 1