def buildCloseContactAtoms(self, percentCutoff, ligand, comment="USER AD> "): pairDict = self.distanceSelector.select(ligand.allAtoms, self.macro_atoms, percentCutoff=percentCutoff) self.pairDict = pairDict #reset here lig_close_ats = AtomSet() macro_close_ats = AtomSet() cdict = {} for k,v in list(pairDict.items()): if len(v): cdict[k] = 1 for at in v: if at not in macro_close_ats: cdict[at] = 1 closeAtoms = AtomSet(list(cdict.keys())) lig_close_ats = closeAtoms.get(lambda x: x.top==ligand).uniq() #ligClAtStr = lig_close_ats.full_name() ligClAtStr = comment + "lig_close_ats: %d\n" %( len(lig_close_ats)) if len(lig_close_ats): ligClAtStr += comment + "%s\n" %( lig_close_ats.full_name()) macro_close_ats = closeAtoms.get(lambda x: x in self.macro_atoms).uniq() macroClAtStr = comment + "macro_close_ats: %d\n" %( len(macro_close_ats)) if len(macro_close_ats): macroClAtStr += comment + "%s\n" %( macro_close_ats.full_name()) #macroClAtStr = "macro_close_ats: " + len(macro_close_ats)+"\n" +macro_close_ats.full_name() rdict = self.results rdict['lig_close_atoms'] = lig_close_ats rdict['macro_close_atoms'] = macro_close_ats if self.verbose: print("macroClAtStr=", macroClAtStr) if self.verbose: print("ligClAtStr=", ligClAtStr) if self.verbose: print("returning "+ macroClAtStr + '==' + ligClAtStr) return macroClAtStr , ligClAtStr
def buildCloseContactAtoms(self, percentCutoff, ligand, comment="USER AD> "): pairDict = self.distanceSelector.select(ligand.allAtoms, self.macro_atoms, percentCutoff=percentCutoff) self.pairDict = pairDict #reset here lig_close_ats = AtomSet() macro_close_ats = AtomSet() cdict = {} for k,v in pairDict.items(): if len(v): cdict[k] = 1 for at in v: if at not in macro_close_ats: cdict[at] = 1 closeAtoms = AtomSet(cdict.keys()) lig_close_ats = closeAtoms.get(lambda x: x.top==ligand).uniq() #ligClAtStr = lig_close_ats.full_name() ligClAtStr = comment + "lig_close_ats: %d\n" %( len(lig_close_ats)) if len(lig_close_ats): ligClAtStr += comment + "%s\n" %( lig_close_ats.full_name()) macro_close_ats = closeAtoms.get(lambda x: x in self.macro_atoms).uniq() macroClAtStr = comment + "macro_close_ats: %d\n" %( len(macro_close_ats)) if len(macro_close_ats): macroClAtStr += comment + "%s\n" %( macro_close_ats.full_name()) #macroClAtStr = "macro_close_ats: " + len(macro_close_ats)+"\n" +macro_close_ats.full_name() rdict = self.results rdict['lig_close_atoms'] = lig_close_ats rdict['macro_close_atoms'] = macro_close_ats if self.verbose: print "macroClAtStr=", macroClAtStr if self.verbose: print "ligClAtStr=", ligClAtStr if self.verbose: print "returning "+ macroClAtStr + '==' + ligClAtStr return macroClAtStr , ligClAtStr
def setupUndoAfter(self, ats, angle,**kw): #no atoms, <4 atoms, aSet = AtomSet(self.atomList) self.undoMenuString = self.name if len(self.atomList)==0: undoCmd = 'self.setTorsionGC.atomList=[]; self.setTorsionGC.update()' elif len(self.atomList)<4: #need to step back here undoCmd = 'self.setTorsionGC.atomList=self.setTorsionGC.atomList[:-1]; self.setTorsionGC.update()' elif self.origValue==self.oldValue: return else: restoreAngle = self.origValue self.undoNow = 1 undoCmd = 'self.setTorsionGC(\''+ aSet.full_name()+ '\',' + str(restoreAngle) + ', topCommand=0)' self.vf.undo.addEntry((undoCmd), (self.name))
def setupUndoAfter(self, ats, angle, **kw): #no atoms, <4 atoms, aSet = AtomSet(self.atomList) self.undoMenuString = self.name if len(self.atomList) == 0: undoCmd = 'self.setTorsionGC.atomList=[]; self.setTorsionGC.update()' elif len(self.atomList) < 4: #need to step back here undoCmd = 'self.setTorsionGC.atomList=self.setTorsionGC.atomList[:-1]; self.setTorsionGC.update()' elif self.origValue == self.oldValue: return else: restoreAngle = self.origValue self.undoNow = 1 undoCmd = 'self.setTorsionGC(\'' + aSet.full_name() + '\',' + str( restoreAngle) + ', topCommand=0)' self.vf.undo.addEntry((undoCmd), (self.name))
class AddBondsGUICommand(MVCommand, MVAtomICOM): """ The AddBondGUICommand provides an interactive way of creating bonds between two given atoms by picking on them. To use this command you need first to load it into PMV. Then you can find the entry 'addBonds' under the Edit menu. To add bonds you just need to pick on the 2 atoms you want to bind. If you drag select a bunch of atoms, the command will buildBondsByDistance between them.This command is undoable. \nPackage : Pmv \nModule : bondsCommands \nClass : AddBondsGUICommand \nCommand : addBondsGC \nSynopsis:\n None<-addBondsGC(atoms)\n \nRequired Arguments:\n atoms : atom(s)\n """ def __init__(self, func=None): MVCommand.__init__(self, func) MVAtomICOM.__init__(self) self.atomList = AtomSet([]) self.undoAtList = AtomSet([]) self.labelStrs = [] def onRemoveObjectFromViewer(self, obj): removeAts = AtomSet([]) for at in self.atomList: if at in obj.allAtoms: removeAts.append(at) self.atomList = self.atomList - removeAts removeAts = AtomSet([]) for at in self.undoAtList: if at in obj.allAtoms: removeAts.append(at) self.undoAtList = self.undoAtList - removeAts self.update() def onAddCmdToViewer(self): if not self.vf.commands.has_key('setICOM'): self.vf.loadCommand('interactiveCommands', 'setICOM', 'Pmv', topCommand=0) if not self.vf.commands.has_key('addBonds'): self.vf.loadCommand('bondsCommands', 'addBonds', 'Pmv', topCommand=0) if not self.vf.commands.has_key('removeBondsGC'): self.vf.loadCommand('bondsCommands', 'removeBondsGC', 'Pmv', topCommand=0) self.masterGeom = Geom('addBondsGeom', shape=(0, 0), pickable=0, protected=True) self.masterGeom.isScalable = 0 self.spheres = Spheres(name='addBondsSpheres', shape=(0, 3), inheritMaterial=0, radii=0.2, quality=15, materials=((1., 1., 0.), ), protected=True) if not self.vf.commands.has_key('labelByExpression'): self.vf.loadCommand('labelCommands', [ 'labelByExpression', ], 'Pmv', topCommand=0) if self.vf.hasGui: miscGeom = self.vf.GUI.miscGeom self.vf.GUI.VIEWER.AddObject(self.masterGeom, parent=miscGeom) self.vf.GUI.VIEWER.AddObject(self.spheres, parent=self.masterGeom) def __call__(self, atoms, **kw): """None<-addBondsGC(atoms) \natoms : atom(s)""" if type(atoms) is StringType: self.nodeLogString = "'" + atoms + "'" ats = self.vf.expandNodes(atoms) if not len(ats): return 'ERROR' return apply(self.doitWrapper, (ats, ), kw) def doit(self, ats): if len(ats) > 2: if len(self.atomList): atSet = ats + self.atomList else: atSet = ats parent = atSet[0].parent parent.buildBondsByDistanceOnAtoms(atSet) self.atomList = AtomSet([]) self.update(True) else: lenAts = len(self.atomList) last = None if lenAts: last = self.atomList[-1] top = self.atomList[0].top for at in ats: #check for repeats of same atom if lenAts and at == last: continue #lenAts = len(self.atomList) #if lenAts and at==self.atomList[-1]: # continue if lenAts and at.top != self.atomList[-1].top: msg = "intermolecular bond to %s disallowed" % ( at.full_name()) self.warningMsg(msg) self.atomList.append(at) self.undoAtList.append(at) lenAts = len(self.atomList) self.update(True) #if only have one atom, there is nothing else to do if lenAts < 2: return #now build bonds between pairs of atoms atSet = self.atomList if lenAts % 2 != 0: atSet = atSet[:-1] #all pairs of atoms will be bonded #so keep only the last one self.atomList = atSet[-1:] lenAts = lenAts - 1 else: self.vf.labelByExpression(self.atomList, negate=1, topCommand=0) self.atomList = AtomSet([]) for i in range(0, lenAts, 2): at1 = atSet[i] at2 = atSet[i + 1] self.vf.addBonds(at1, at2, origin='UserDefined', topCommand=0) self.update(True) def applyTransformation(self, pt, mat): pth = [pt[0], pt[1], pt[2], 1.0] return Numeric.dot(mat, pth)[:3] def getTransformedCoords(self, atom): if not atom.top.geomContainer: return atom.coords g = atom.top.geomContainer.geoms['master'] c = self.applyTransformation(atom.coords, g.GetMatrix(g)) return c.astype('f') def update(self, event=None): if not len(self.atomList): self.spheres.Set(vertices=[], tagModified=False) self.vf.labelByExpression(self.atomList, negate=1, topCommand=0) if self.vf.hasGui: self.vf.GUI.VIEWER.Redraw() return self.lineVertices = [] #each time have to recalculate lineVertices for at in self.atomList: c1 = self.getTransformedCoords(at) self.lineVertices.append(tuple(c1)) if event: self.spheres.Set(vertices=self.lineVertices, tagModified=False) self.vf.labelByExpression(self.atomList, function='lambda x: x.full_name()', lambdaFunc=1, textcolor='yellow', format='', negate=0, location='Last', log=0, font='arial1.glf', only=1, topCommand=0) #setting spheres doesn't trigger redraw so do it explicitly if self.vf.hasGui: self.vf.GUI.VIEWER.Redraw() def guiCallback(self, event=None): self.save = self.vf.ICmdCaller.commands.value["Shift_L"] self.vf.setICOM(self, modifier="Shift_L", topCommand=0) def setupUndoAfter(self, ats, **kw): lenUndoAts = len(self.undoAtList) lenAts = len(ats) if lenAts == 1: #after adding 1 self.atomList would be 1 or 0 if len(self.atomList) == 1: s = '0' ustr = '"c=self.addBondsGC; self.labelByExpression(c.atomList, negate=1, topCommand=0);c.atomList=c.atomList[:' + s + '];c.undoAtList=c.undoAtList[:-1];c.update()"' else: self.vf.undoCmdStack.remove(self.prev_undoCmds) ind = str(lenUndoAts - 2) ustr = '"c=self.addBondsGC;nodes=self.expandNodes(' + '\'' + self.undoAtList[ -2:].full_name( ) + '\'' + '); bonds=nodes.bonds[0];self.removeBondsGC(bonds, topCommand=0);c.atomList=nodes[:1];c.undoAtList=c.undoAtList[:' + ind + '];c.update()"' elif lenUndoAts > lenAts: ustr = '"c=self.addBondsGC;nodes=self.expandNodes(' + '\'' + ats.full_name( ) + '\'' + ');bonds = nodes.bonds[0];self.removeBondsGC(bonds, topCommand=0);c.undoAtList=c.undoAtList[:' + str( lenAts) + ']"' else: ustr = '"c=self.addBondsGC;nodes=self.expandNodes(' + '\'' + ats.full_name( ) + '\'' + ');bonds = nodes.bonds[0];self.removeBondsGC(bonds, topCommand=0);c.undoAtList=c.undoAtList[:0]"' if len(self.atomList) and lenAts > 1: atStr = self.atomList.full_name() estr = ';nodes=self.expandNodes(' + '\'' + self.atomList.full_name( ) + '\'' + ');c.atomList=nodes;c.update()"' ustr = ustr + estr self.undoCmds = "exec(" + ustr + ")" self.prev_undoCmds = (self.undoCmds, "addBondsGC") def startICOM(self): self.vf.setIcomLevel(Atom, topCommand=0) def stopICOM(self): if len(self.atomList) != 0: self.vf.labelByExpression(self.atomList, negate=1, topCommand=0) del self.atomList[:] self.labelStrs = [] self.spheres.Set(vertices=[], tagModified=False) self.vf.GUI.VIEWER.Redraw() self.save = None
class AddBondsGUICommand(MVCommand, MVAtomICOM): """ The AddBondGUICommand provides an interactive way of creating bonds between two given atoms by picking on them. To use this command you need first to load it into PMV. Then you can find the entry 'addBonds' under the Edit menu. To add bonds you just need to pick on the 2 atoms you want to bind. If you drag select a bunch of atoms, the command will buildBondsByDistance between them.This command is undoable. \nPackage : Pmv \nModule : bondsCommands \nClass : AddBondsGUICommand \nCommand : addBondsGC \nSynopsis:\n None<-addBondsGC(atoms)\n \nRequired Arguments:\n atoms : atom(s)\n """ def __init__(self, func=None): MVCommand.__init__(self, func) MVAtomICOM.__init__(self) self.atomList = AtomSet([]) self.undoAtList = AtomSet([]) self.labelStrs = [] def onRemoveObjectFromViewer(self, obj): removeAts = AtomSet([]) for at in self.atomList: if at in obj.allAtoms: removeAts.append(at) self.atomList = self.atomList - removeAts removeAts = AtomSet([]) for at in self.undoAtList: if at in obj.allAtoms: removeAts.append(at) self.undoAtList = self.undoAtList - removeAts self.update() def onAddCmdToViewer(self): if not self.vf.commands.has_key('setICOM'): self.vf.loadCommand('interactiveCommands', 'setICOM', 'Pmv', topCommand=0) if not self.vf.commands.has_key('addBonds'): self.vf.loadCommand('bondsCommands', 'addBonds', 'Pmv', topCommand=0) if not self.vf.commands.has_key('removeBondsGC'): self.vf.loadCommand('bondsCommands', 'removeBondsGC', 'Pmv', topCommand=0) self.masterGeom = Geom('addBondsGeom',shape=(0,0), pickable=0, protected=True) self.masterGeom.isScalable = 0 self.spheres = Spheres(name='addBondsSpheres', shape=(0,3), inheritMaterial=0, radii=0.2, quality=15, materials = ((1.,1.,0.),), protected=True) if not self.vf.commands.has_key('labelByExpression'): self.vf.loadCommand('labelCommands', ['labelByExpression',], 'Pmv', topCommand=0) if self.vf.hasGui: miscGeom = self.vf.GUI.miscGeom self.vf.GUI.VIEWER.AddObject(self.masterGeom, parent=miscGeom) self.vf.GUI.VIEWER.AddObject(self.spheres, parent=self.masterGeom) def __call__(self, atoms, **kw): """None<-addBondsGC(atoms) \natoms : atom(s)""" if type(atoms) is StringType: self.nodeLogString = "'"+atoms+"'" ats = self.vf.expandNodes(atoms) if not len(ats): return 'ERROR' return apply(self.doitWrapper, (ats,), kw) def doit(self, ats): if len(ats)>2: if len(self.atomList): atSet = ats + self.atomList else: atSet = ats parent = atSet[0].parent parent.buildBondsByDistanceOnAtoms(atSet) self.atomList = AtomSet([]) self.update(True) else: lenAts = len(self.atomList) last = None if lenAts: last = self.atomList[-1] top = self.atomList[0].top for at in ats: #check for repeats of same atom if lenAts and at==last: continue #lenAts = len(self.atomList) #if lenAts and at==self.atomList[-1]: # continue if lenAts and at.top!=self.atomList[-1].top: msg = "intermolecular bond to %s disallowed"%(at.full_name()) self.warningMsg(msg) self.atomList.append(at) self.undoAtList.append(at) lenAts = len(self.atomList) self.update(True) #if only have one atom, there is nothing else to do if lenAts<2: return #now build bonds between pairs of atoms atSet = self.atomList if lenAts%2!=0: atSet = atSet[:-1] #all pairs of atoms will be bonded #so keep only the last one self.atomList = atSet[-1:] lenAts = lenAts -1 else: self.vf.labelByExpression(self.atomList, negate=1, topCommand=0) self.atomList = AtomSet([]) for i in range(0, lenAts, 2): at1 = atSet[i] at2 = atSet[i+1] self.vf.addBonds(at1, at2, origin='UserDefined', topCommand=0) self.update(True) def applyTransformation(self, pt, mat): pth = [pt[0], pt[1], pt[2], 1.0] return Numeric.dot(mat, pth)[:3] def getTransformedCoords(self, atom): if not atom.top.geomContainer: return atom.coords g = atom.top.geomContainer.geoms['master'] c = self.applyTransformation(atom.coords, g.GetMatrix(g)) return c.astype('f') def update(self, event=None): if not len(self.atomList): self.spheres.Set(vertices=[], tagModified=False) self.vf.labelByExpression(self.atomList, negate=1, topCommand=0) if self.vf.hasGui: self.vf.GUI.VIEWER.Redraw() return self.lineVertices=[] #each time have to recalculate lineVertices for at in self.atomList: c1 = self.getTransformedCoords(at) self.lineVertices.append(tuple(c1)) if event: self.spheres.Set(vertices=self.lineVertices, tagModified=False) self.vf.labelByExpression(self.atomList, function = 'lambda x: x.full_name()', lambdaFunc = 1, textcolor = 'yellow', format = '', negate = 0, location = 'Last', log = 0, font = 'arial1.glf', only = 1, topCommand=0) #setting spheres doesn't trigger redraw so do it explicitly if self.vf.hasGui: self.vf.GUI.VIEWER.Redraw() def guiCallback(self, event=None): self.save = self.vf.ICmdCaller.commands.value["Shift_L"] self.vf.setICOM(self, modifier="Shift_L", topCommand=0) def setupUndoAfter(self, ats, **kw): lenUndoAts = len(self.undoAtList) lenAts = len(ats) if lenAts==1: #after adding 1 self.atomList would be 1 or 0 if len(self.atomList)==1: s = '0' ustr='"c=self.addBondsGC; self.labelByExpression(c.atomList, negate=1, topCommand=0);c.atomList=c.atomList[:'+s+'];c.undoAtList=c.undoAtList[:-1];c.update()"' else: self.vf.undoCmdStack.remove(self.prev_undoCmds) ind = str(lenUndoAts - 2) ustr = '"c=self.addBondsGC;nodes=self.expandNodes('+'\''+self.undoAtList[-2:].full_name()+'\''+'); bonds=nodes.bonds[0];self.removeBondsGC(bonds, topCommand=0);c.atomList=nodes[:1];c.undoAtList=c.undoAtList[:'+ind+'];c.update()"' elif lenUndoAts>lenAts: ustr='"c=self.addBondsGC;nodes=self.expandNodes('+'\''+ats.full_name()+'\''+');bonds = nodes.bonds[0];self.removeBondsGC(bonds, topCommand=0);c.undoAtList=c.undoAtList[:'+str(lenAts)+']"' else: ustr='"c=self.addBondsGC;nodes=self.expandNodes('+'\''+ats.full_name()+'\''+');bonds = nodes.bonds[0];self.removeBondsGC(bonds, topCommand=0);c.undoAtList=c.undoAtList[:0]"' if len(self.atomList) and lenAts>1: atStr = self.atomList.full_name() estr = ';nodes=self.expandNodes('+'\''+self.atomList.full_name()+'\''+');c.atomList=nodes;c.update()"' ustr = ustr + estr self.undoCmds = "exec("+ustr+")" self.prev_undoCmds = (self.undoCmds, "addBondsGC") def startICOM(self): self.vf.setIcomLevel( Atom, topCommand=0) def stopICOM(self): if len(self.atomList)!=0: self.vf.labelByExpression(self.atomList, negate=1, topCommand = 0) del self.atomList[:] self.labelStrs = [] self.spheres.Set(vertices=[], tagModified=False) self.vf.GUI.VIEWER.Redraw() self.save = None