def pretty_protein(sele="(all)"): """DESCRIPTION This is my default display. It displays the protein as cartoon, but highlights ligands and ions as sticks or spheres. USAGE pretty_protein [selection] AUTHOR Spencer Bliven """ cmd.hide("lines",sele) cmd.hide("everything","( %s ) and solvent"%sele) cmd.show("cartoon",sele) # disulfides cmd.show("sticks","( %s ) and (cys/ca+cb+sg) and byres (cys/sg and bound_to cys/sg)"%sele) # ligands cmd.show("sticks","( %s ) and hetatm and not solvent and not hydrogen and not resn MSE"%sele) # metals cmd.show("spheres","( %s ) and not elem c+n+o+h+s and not resn MSE"%sele) # color carbon by chain & others by element util.cbc(sele) util.cnc(sele)
def Show_Results(self): i = 0 for key in sorted(self.dictSimData.keys()): Result = self.ResultsContainer.Get_ResultID(key) if Result is not None: try: ResultID = str( Result.ResultID) if Result.ResultID != -1 else 'REF' ResultName = 'RESULT_' + ResultID + '__' ResultHBondsName = 'RESULT_' + ResultID + '_H_BONDS__' cmd.load(Result.ResultFile, ResultName, state=1) cmd.refresh() cmd.color(self.PymolColorList[i], ResultName) util.cnc(ResultName) cmd.refresh() self.Nice_Display(Result, ResultName) self.Highlight_HBonds(Result, ResultName, ResultHBondsName) except: continue i += 1
def EditView(self): #Display the ligand with the new coordinates #print "will load " + self.LigandObj + " in state " + str(self.State) try: cmd.load(self.top.listTmpPDB[self.TOP + 1], self.LigandObj, self.State) cmd.refresh() # No flexible side-chain(s) if self.selSideChains == '': selString = self.selLigand + " or " + self.selTarget else: selString = self.selSideChains + " or " + self.selLigand + " or " + self.selTarget #print selString # Create solution object # Object contains the whole protein-ligand complex SolutionObj = "TOP_" + str(self.TOP + 1) + "__" cmd.create(SolutionObj, selString, self.State, self.State) cmd.refresh() # Color ligand of solution TOP Selection = "(resn LIG & " + SolutionObj + " & present)" cmd.color(self.top.top.PymolColorList[self.TOP], Selection) util.cnc(Selection) cmd.refresh() # Color side-chains of solution TOP if self.selSideChains != '': selSC = self.selSideChains.replace(self.TargetObj, SolutionObj) cmd.color(self.top.top.PymolColorList[self.TOP], selSC) util.cnc(selSC) cmd.refresh() #cmd.show(self.DefaultDisplay, "(resn LIG & sol_*__ & present)") cmd.show(self.top.DefaultDisplay, "(resn LIG & " + SolutionObj + " & present)") cmd.refresh() if self.selSideChains != '': #cmd.show("sticks", self.selSideChains.replace(self.TargetName__,"sol_*__")) cmd.show( "sticks", self.selSideChains.replace(self.TargetObj, SolutionObj)) cmd.refresh() except: self.CriticalError("Could not refresh the visual display") return 1 return 0
def EditView(self): #Display the ligand with the new coordinates #print "will load " + self.LigandObj + " in state " + str(self.State) try: cmd.load(self.top.listTmpPDB[self.TOP+1], self.LigandObj, self.State) cmd.refresh() # No flexible side-chain(s) if self.selSideChains == '': selString = self.selLigand + " or " + self.selTarget else: selString = self.selSideChains + " or " + self.selLigand + " or " + self.selTarget #print selString # Create solution object # Object contains the whole protein-ligand complex SolutionObj = "TOP_" + str(self.TOP+1) + "__" cmd.create(SolutionObj, selString, self.State, self.State) cmd.refresh() # Color ligand of solution TOP Selection = "(resn LIG & " + SolutionObj + " & present)" cmd.color(self.top.top.PymolColorList[self.TOP], Selection) util.cnc(Selection) cmd.refresh() # Color side-chains of solution TOP if self.selSideChains != '': selSC = self.selSideChains.replace(self.TargetObj,SolutionObj) cmd.color(self.top.top.PymolColorList[self.TOP], selSC) util.cnc(selSC) cmd.refresh() #cmd.show(self.DefaultDisplay, "(resn LIG & sol_*__ & present)") cmd.show(self.top.DefaultDisplay, "(resn LIG & " + SolutionObj + " & present)") cmd.refresh() if self.selSideChains != '': #cmd.show("sticks", self.selSideChains.replace(self.TargetName__,"sol_*__")) cmd.show("sticks", self.selSideChains.replace(self.TargetObj,SolutionObj)) cmd.refresh() except: self.CriticalError("Could not refresh the visual display") return 1 return 0
def finalCosmetics(self): #make everything look nice for ensemble in self.currentLabel.ensembles: if len(self.currentLabel.ensembles[ensemble].rotamers) > 0: #show all conformations and do some coloring cmd.set("all_states", 1) self.toggleStatesCaption = 'Toggle states: ON' cmd.color( "blue", "%s_%s_%s" % (self.residue1Name, self.currentLabel.identifier, ensemble)) cmd.color( "red", "%s_%s_%s & name %s" % (self.residue1Name, self.currentLabel.identifier, ensemble, self.currentLabel.highlight)) util.cnc("%s_%s_%s" % (self.residue1Name, self.currentLabel.identifier, ensemble)) identifierLabel = "%s|%s|%s|%s|%s" % ( self.residue1Name, self.currentLabel.identifier, self.vdwRestraints, self.thoroughness, ensemble) #pseudoatom at average N1 position stored.label = [] cmd.iterate_state( 0, "%s_%s_%s & name %s" % (self.residue1Name, self.currentLabel.identifier, ensemble, self.currentLabel.spinLocation), 'stored.label.append((x,y,z))') atoms1 = numpy.array(stored.label) #create pseudoatom at average coordinate of each ensemble avgAtoms = numpy.average(atoms1, axis=0) self.createPseudoatom( avgAtoms, "%s_%s_label" % (self.residue1Name, ensemble), 1) cmd.set("sphere_scale", "0.5", "%s_%s_label" % (self.residue1Name, ensemble)) cmd.label("%s_%s_label" % (self.residue1Name, ensemble), ` identifierLabel `) cmd.show("label") cmd.show("spheres", "name PS1") cmd.group( "%s%s" % (self.object_prefix, str(self.numberOfLabel)), "%s*, labelEnvironment_%s,%s*" % ("currentLabel", "currentLabel", self.residue1Name))
def Nice_Display(self, Result, ResultName): cmd.hide('everything', ResultName) cmd.refresh() cmd.show('cartoon', ResultName) cmd.refresh() for opt in Result.Optimizable: if opt.rnc[:3] == 'LIG': cmd.show('lines', 'byres(resn LIG around 5.0) & ' + ResultName) res = opt.rnc[:3].replace('-', '') num = opt.rnc[3:len(opt.rnc) - 1].replace('-', '') chn = opt.rnc[-1:].replace('-', '') sele = 'resn ' + res + ' & resi ' + num + ' & chain \'' + chn + '\' & ' + ResultName cmd.show('sticks', sele) cmd.color('white', sele) util.cnc(ResultName) cmd.refresh()
def color_obj(rainbow=0,cnc=1): """ AUTHOR Gareth Stockwell Modified by Spencer Bliven USAGE color_obj(rainbow=0, cnc=0) ARGUMENTS rainbow = integer: 0 to use the 22 named colors, or 1 to generate a rainbow based on the number of objects currently cnc = integer: 0 to color all atoms by object, 1 to color non-carbon atoms according to their element. NOTES This function colours each object currently in the PyMOL heirarchy with a different colour. Colours used are either the 22 named colours used by PyMOL (in which case the 23rd object, if it exists, gets the same colour as the first), or are the colours of the rainbow If cnc is set, color non-carbon atoms by their element SEE ALSO util.color_objs() """ # Process arguments rainbow = int(rainbow) cnc = int(cnc) # Get names of all PyMOL objects obj_list = cmd.get_names('objects') if rainbow: print "\nColouring objects as rainbow\n" nobj = len(obj_list) # Create colours starting at blue(240) to red(0), using intervals # of 240/(nobj-1) for j in range(nobj): hsv = (240-j*240/(nobj-1), 1, 1) # Convert to RGB rgb = hsv_to_rgb(hsv) # Define the new colour cmd.set_color("col" + str(j), rgb) print obj_list[j], rgb # Colour the object cmd.color("col" + str(j), obj_list[j]) else: print "\nColouring objects using PyMOL defined colours\n" # List of available colours colours = ['red', 'green', 'blue', 'yellow', 'violet', 'cyan', \ 'salmon', 'lime', 'pink', 'slate', 'magenta', 'orange', 'marine', \ 'olive', 'purple', 'teal', 'forest', 'firebrick', 'chocolate', \ 'wheat', 'white', 'grey' ] ncolours = len(colours) # Loop over objects i = 0 for obj in obj_list: print " ", obj, colours[i] cmd.color(colours[i], obj) i = i+1 if(i == ncolours): i = 0 if cnc: #color non-carbons appropriately util.cnc()