def testExportStyle(self): cmd.fab('ACDEF', 'm1') cmd.hide() cmd.show('cartoon', 'resi 1-3') cmd.show('lines', 'resn CYS') cmd.show('sticks', 'resn ASP+PHE') cmd.show('spheres', 'resn GLU') cmd.set('stick_ball', 1, 'resn PHE') cmd.set('stick_ball_ratio', 1.5, 'm1') testlabel = 'Hello "World"' cmd.label('name SG', repr(testlabel)) with testing.mktemp('.mae') as filename: cmd.save(filename) cmd.delete('*') cmd.load(filename, 'm2') g_labels = [] cmd.iterate('name SG', 'g_labels.append(label)', space=locals()) cmd.alter('*', 'b = 1 if s.stick_ball else 0') self._assertCountEqual('rep cartoon & guide', 'resi 1-3 & guide') self._assertCountEqual('rep lines', 'resn CYS', delta=1) self._assertCountEqual('rep sticks', 'resn ASP+PHE') self._assertCountEqual('rep spheres', 'resn GLU') self._assertCountEqual('b > 0.5', 'resn PHE') self.assertTrue(cmd.get_setting_float('stick_ball_ratio', 'm2') > 1.1) self.assertEqual(g_labels[0], testlabel)
def occupiedWaters(sele=None, fName="fixedProtonations.txt"): '''Color the occupied waters in a different color. ''' WAT_COLOR = {"IPE_UNOCC":"white", "IPE_OCC":"blue", "CRY_UNOCC":"yellow", "CRY_OCC":"red"} extra = "" if sele: extra = " and %s" % sele cmd.color(WAT_COLOR["IPE_UNOCC"], "resn hoh and chain x" + extra) cmd.set("sphere_scale", "0.1", "resn hoh and chain x" + extra) cmd.color(WAT_COLOR["CRY_UNOCC"], "resn hoh and chain a" + extra) cmd.set("sphere_scale", "0.2", "resn hoh and chain a" + extra) cmd.show("spheres", "resn hoh" + extra) cmd.set("label_position", (0,-1.5,0)) if os.path.exists(fName): counter = 0 for eachLine in open(fName): fields = eachLine.split() if fields[0][:3] != "HOH": continue chainId = fields[0][3] resSeq = int(fields[0][-4:]) selection = ("resn hoh and chain %c and resi %d" % (chainId, resSeq)) + extra if int(fields[1]) != DUMMY_WATER: cmd.set("sphere_scale", "0.3", selection) if chainId == 'A': cmd.color(WAT_COLOR["CRY_OCC"], selection) cmd.label(selection, '"A" + resi') elif chainId == 'X': cmd.color(WAT_COLOR["IPE_OCC"], selection) cmd.label(selection, '"X" + resi') counter += 1 print "%d occupied waters colored" % counter
def testRepsExist(self): cmd.viewport(200, 150) cmd.load(self.datafile('1oky-frag.pdb'), 'm1') # make some nonbonded cmd.unbond('resi 115-', 'resi 115-') # labels cmd.label('all', 'name') # measurements cmd.distance('measure1', 'index 1', 'index 10') cmd.angle('measure1', 'index 1', 'index 10', 'index 20') cmd.dihedral('measure1', 'index 1', 'index 10', 'index 20', 'index 30') # color test setup cmd.color('white', '*') cmd.set('ambient', 1) cmd.set('depth_cue', 0) cmd.set('antialias', 0) cmd.set('line_smooth', 0) cmd.orient() # test most reps for rep in REPS: cmd.show_as(rep) self.assertImageHasColor('white', msg='rep missing: ' + rep) # test cartoon cmd.show_as('cartoon') for cart in CARTOONS: cmd.cartoon(cart) self.assertImageHasColor('white', msg='cartoon missing: ' + cart)
def load(): cmd.set("valence") r = 0 list = glob("pdb/*/*") # while list[0]!="pdb/f8/pdb1f8u": # list.pop(0) for file in list: try: cmd.delete('pdb') cmd.load(file,'pdb') cmd.set_title('pdb',1,os.path.split(file)[-1]) cmd.rewind() cmd.orient('pdb') cmd.refresh() cmd.zoom('center',16) cmd.label("polymer and (name ca or elem P)","'//%s/%s/%s`%s/%s'%(segi,chain,resn,resi,name)") cmd.refresh() sys.__stderr__.write(".") sys.__stderr__.flush() n = cmd.count_states() if n>1: cmd.rewind() sys.__stderr__.write(file+"\n") sys.__stderr__.flush() for a in range(1,n+1): cmd.forward() cmd.refresh() except: traceback.print_exc()
def rpcLabel(pos, labelText, id='lab1', color=(1, 1, 1)): """ create a text label Arguments: pos: a 3 tuple with the position of the label text: a string with the label color: a 3 tuple with the color of the label. (1,1,1) is white id: (OPTIONAL) the name of the object to be created NOTE: at the moment this is, how you say, a hack """ x, y, z = pos text = """ Atom 1 0 0 0 0 0 0 0 0 0999 V2000 % 10.4f% 10.4f%10.4f C 0 0 0 0 0 0 0 0 0 0 0 0 M END""" % (x, y, z) cmd.read_molstr(text, id) cmd.label("%s" % (id), '"%s"' % labelText) cmd.hide("nonbonded", id) cmd.set_color("%s-color" % id, color) cmd.color("%s-color" % id, id) return 1
def DNA_selections(display='all'): bbatoms = 'name C2\*+C3\*+C4\*+C5\*+P+O3\*+O4\*+O5\*+O1P+O2P+H1\*+1H2\*+2H2\*+H3\*+H4\*+1H5\*+2H5\*+c2\'+c3\'+c4\'+c5\'+o3\'+o4\'+o5\'+op2+op1+h1\'+1h2\'+2h2\'+h3\'+h4\'+1h5\'+2h5\'' waters = 'n. wo6+wn7+wn6+wn4+wo4 or r. hoh' cmd.select('DNA', 'r. g+a+c+t+gua+ade+cyt+thy+da+dc+dg+dt+5mc',enable=0) cmd.select('notDNA','not DNA',enable=0) cmd.select('DNAbases','DNA and not %s' % bbatoms ,enable=0) cmd.select('DNAbb','DNA and %s' % bbatoms ,enable=0) cmd.select('sc_base','byres notDNA w. 7 of DNAbases',enable=0) cmd.select('sc_base','sc_base and not n. c+n+o',enable=0) cmd.select('dna_h2o','%s w. 3.6 of DNAbases' %waters ,enable=0) cmd.set('sphere_transparency','0.5'); cmd.color('marine','dna_h2o') cmd.do('selectPolarProtons') # color_by_chains() cmd.color('gray','e. c') cmd.select('pbb','notDNA and n. c+n+ca',enable=0) if display != 'none': cmd.label('n. c1\*+c1\' and DNA','\'%s%s(%s)\' % (chain,resi,resn)') cmd.set('label_color','white') if display == 'all': # display things cmd.show('sticks','DNAbases or sc_base') cmd.show('ribbon','DNAbb') cmd.show('cartoon','notDNA') cmd.show('spheres','dna_h2o') cmd.hide('everything','e. h and not polar_protons')
def _testLabelByAtomType(self): cmd.load(self.datafile('1oky.pdb.gz')) cmd.remove("alt 'B'") cmd.label('resn STU', 'text_type') c3labels = [] cmd.iterate("resn STU", "c3labels.append(label == 'C.3')", space=locals()) self.assertEquals(sum(c3labels), 8)
def read_siftp(filename): try: #first line in file contains averaged sift with open(filename, 'r') as f: siftline = f.readline() min_aa, sift = siftline.split(':') sift = sift.split(' ') print sift for interaction in range(9): selection = [] for index in range(len(sift[interaction::9])): if index == len(sift[interaction::9]) - 1: print len(sift[interaction::9]) print 'index',index, print 'interaction',sift[interaction::9][index] if sift[interaction::9][index].strip() != '0': if interaction == 8: print sift[interaction::9][index] print int(min_aa) + index print sift[index:index + 9] selection.append(str(int(min_aa)+index)) if len(selection) > 0: cmd.select ( InteractionButton[interaction]+'_'+InteractionName[interaction], 'resi ' + "+".join(selection) ) if interaction == 0: cmd.show ( 'sticks', InteractionButton[interaction]+'_'+InteractionName[interaction] ) cmd.remove ( 'hydro' ) print InteractionButton[interaction]+'_'+InteractionName[interaction], 'resi ' + "+".join(selection) del selection with open(filename) as f: f.readline() #print 'here we go' for line in f.readlines(): try: #print line resi= line.split()[0] fp = line.split()[1:] fp = ''.join(fp) #print resi,fp if fp != '000000000': #print 'yes',fp cmd.select('residue '+resi,'resi '+ resi) cmd.show('sticks','resi '+ resi) cmd.label('residue '+resi,'resi') else: #cmd.select('residue '+resi,'resi '+ resi) #cmd.label('residue '+resi,'"no"') #print 'no',fp pass except: pass except Exception, e: print "Failed to open file %s\n%s" % (filename, e)
def load_labels(): file_labels = open_it() i = 0 for line in open(file_labels, "r"): i = i + 1 selec = "resi " + str(i) txt = line.split() cmd.label(selec, txt[0])
def load_net(): file_coors= open_it() net=network(file_coors) for ii in range(net.num_nodes): cmd.pseudoatom('net',pos=net.node[ii].coors,resi=ii,chain='A') selec='resi '+str(ii) cmd.alter(selec,'resn='+'"'+net.node[ii].label+'"') cmd.label(selec,'"'+net.node[ii].label+'"') cmd.alter(selec,'b='+str(net.node[ii].weight)) cmd.alter(selec,'q='+str(net.node[ii].cluster)) for ii in range(net.num_nodes): for jj in net.node[ii].link.keys(): cmd.bond('resi '+str(ii),'resi '+str(jj)) cmd.spectrum('b','blue_red')
def testAtomLevelSettingsOnRemove2(self): if cmd.get_setting_int('suspend_undo'): self.skipTest("need suspend_undo=0") cmd.load(self.datafile("1molecule.mae")) cmd.load(self.datafile("1molecule.mae")) cmd.label("index 10", "'Test Label'") plv = [ 5., 0., 0.] cmd.alter("index 10", "s.label_placement_offset = %s" % plv) cmd.remove("index 10") cmd.undo() stored.offset = None cmd.iterate("index 10", "stored.offset = list(s.label_placement_offset)") self.assertEqual(stored.offset, plv)
def residues_around_ligand(selection="het"): # # Usage: # run /path/to/residues_around_ligand.py # sele ATP, resname ATP # residues_around_ligand ATP # cmd.select("near", "%s around 5" % selection) cmd.select("nearres", "br. near") cmd.select("sidechain", "not (name c+n+o) in nearres") cmd.show("sticks", "nearres") cmd.label("n. CA and nearres", '"%s, %s" % (resn, resi)') cmd.set("label_color", "white", "sidechain") cmd.set("label_size", "-0.6") cmd.color("blue", "name n*") cmd.color("red", "name o*") cmd.deselect()
def draw(G): for r in G: for p in G[r].keys(): if 'pK' in p: resnum = G[r]['resnum'] source = G[r][p] ch,tresnum,tres = source.split(':') tresnum=int(tresnum) srcatom=titatoms[tres] clr = sourceclrs[source] print resnum,tresnum,clr labelatom=pkatoms[p] cmd.select('bb','resi %s and name %s' %(resnum,labelatom)) cmd.show('spheres','bb') cmd.color(clr,'bb') atom = titatoms[tres] cmd.select('tit','resi %s' %(tresnum)) cmd.color(clr,'tit') cmd.show('sticks','tit') cmd.label('tit and name %s' %atom,'resn+resi')
def testLabelUnicode(self): if sys.version_info[0] < 3: uchr = unichr else: uchr = chr stored.L_unicode = u''.join(uchr(i) for i in range(32, 0x1FF)) stored.L_utf8 = stored.L_unicode.encode('utf-8') self.assertTrue(not isinstance(stored.L_unicode, bytes)) self.assertTrue(isinstance(stored.L_utf8, bytes)) cmd.pseudoatom('pseudo_unicode', label=stored.L_unicode) cmd.pseudoatom('pseudo_utf8', label=stored.L_utf8) cmd.pseudoatom('label_unicode') cmd.pseudoatom('label_utf8') cmd.label('label_unicode', 'stored.L_unicode') cmd.label('label_utf8', 'stored.L_utf8') stored.check_unicode = [] cmd.iterate('all', 'stored.check_unicode.append(label == stored.L_unicode)') self.assertTrue(all(stored.check_unicode))
def do_pick(self,bondFlag): self.obj_name = None # if 'pk1' in cmd.get_names('selections'): if cmd.count_atoms('pk1',1): self.obj_name = cmd.identify('pk1',1)[0][0] model = cmd.get_model("(pk1)") self.atom = model.atom.pop() if not self.labeling: cmd.label("(pk1)", '""') elif self.atom.name == 'CA': cmd.label("(pk1)", '" %s %s" % (resn,resi)') else: cmd.label("(pk1)", '" %s %s" % (name,resi)') cmd.unpick() cmd.refresh_wizard()
def showhbnet(hbFile="hb.txt"): g = loadHbNet(hbFile) cmd.set("sphere_transparency", 0.7) cmd.set("line_width", 0.5) for eachRes in g.nodes(): # only show the residues in the network that have connection with the key residues. if not isShowing(g, eachRes): continue resName = eachRes[:3] chainId = eachRes[3] resSeq = int(eachRes[4:]) # the schiff's base is specail, it's a combination of Lys216 and the retinal. if eachRes == "RSBA0216": selection = "(r. lys and c. a and i. 216) or (r. ret)" cmd.show("lines", selection) cmd.label("r. lys and c. a and i. 216 and name ca", '"RSB"') util.cbag(selection) continue selection = "(r. %s and c. %c and i. %d)" % (resName, chainId, resSeq) if resName == "HOH": cmd.show("spheres", selection) cmd.set("sphere_scale", 0.15) cmd.label(selection, "chain+resi") else: cmd.show("lines", selection) cmd.label(selection+" and name ca", "resn+resi") util.cbag(selection) # hide all the hydrogens. cmd.hide("everything", "h.")
def rlabel(): cmd = "n. C1'", '"%s %s" % (resn, resi)' print('label ' + cmd) cmd.label(cmd)
def show_AtomsNumber(self): cmd.label(self.LigDisplay, "\"%d\" % ID") cmd.refresh()
dirpath = tempfile.mkdtemp() zip_dir = 'out.zip' with zipfile.ZipFile(zip_dir) as hs_zip: hs_zip.extractall(dirpath) cmd.load(join(dirpath, "protein.pdb"), "protein") cmd.show("cartoon", "protein") if dirpath: f = join(dirpath, "label_threshold_10.mol2") else: f = "label_threshold_10.mol2" cmd.load(f, 'label_threshold_10') cmd.hide('everything', 'label_threshold_10') cmd.label("label_threshold_10", "name") cmd.set("label_font_id", 7) cmd.set("label_size", -0.4) if dirpath: f = join(dirpath, "label_threshold_14.mol2") else: f = "label_threshold_14.mol2" cmd.load(f, 'label_threshold_14') cmd.hide('everything', 'label_threshold_14') cmd.label("label_threshold_14", "name") cmd.set("label_font_id", 7) cmd.set("label_size", -0.4) if dirpath:
dirpath = tempfile.mkdtemp() zip_dir = 'out.zip' with zipfile.ZipFile(zip_dir) as hs_zip: hs_zip.extractall(dirpath) cmd.load(join(dirpath,"protein.pdb"), "protein") cmd.show("cartoon", "protein") if dirpath: f = join(dirpath, "label_threshold_10.mol2") else: f = "label_threshold_10.mol2" cmd.load(f, 'label_threshold_10') cmd.hide('everything', 'label_threshold_10') cmd.label("label_threshold_10", "name") cmd.set("label_font_id", 7) cmd.set("label_size", -0.4) if dirpath: f = join(dirpath, "label_threshold_14.mol2") else: f = "label_threshold_14.mol2" cmd.load(f, 'label_threshold_14') cmd.hide('everything', 'label_threshold_14') cmd.label("label_threshold_14", "name") cmd.set("label_font_id", 7) cmd.set("label_size", -0.4)
def select_mutated(obj1,obj2,sele2=None): """ DESCRIPTION "select_mutated" finds and selects the amino acid differences in the second object when compared to the first object. It highlights the mutations in yellow sticks for easy identification. This new function can also handle length changes by using PyMOL's built-in align method. Some parts of this script were taken from a similar script written by Christoph Malisi, located on the PyMOL wiki at www.pymolwiki.org/index.php/Color_By_Mutations USAGE select_mutated wild_type_object_to_compare_to, mutant_object_to_select, selection_of_mutant_residues_to_limit_comparison_to EXAMPLES select_mutated 1xuu, 1ame, 1ame and chain g + 1ame and chain h select_mutated 1xuu, * """ if ( sele2 == None ): sele2 = obj2 objects = cmd.get_names("objects") for o in objects: if o.startswith(obj2): obj2 = o break one_letter ={'VAL':'V', 'ILE':'I', 'LEU':'L', 'GLU':'E', 'GLN':'Q','ASP':'D', 'ASN':'N', 'HIS':'H', 'TRP':'W', 'PHE':'F', 'TYR':'Y', \ 'ARG':'R', 'LYS':'K', 'SER':'S', 'THR':'T', 'MET':'M', 'ALA':'A','GLY':'G', 'PRO':'P', 'CYS':'C', 'MSE':'M', 'ASX':'N' } print "select_mutated called with object 1: " + obj1 + " and object 2: " + obj2 # use PyMOL to get a sequence alignment of the two objects (don't do any refinement to get a better fit - just align the sequences) cmd.align( obj2, obj1, object="alignment", cycles=0 ) # after doing the sequence alignment, use super to do a sequence-independent, structure-based alignment. supposedly much better than align. cmd.super( obj2, obj1 ) # alignment is an "object" which somehow contains both objects that were used for the alignment. we'll iterate over this alignment object # and save the chain, resi, and resn for each aligned position. making the big assumption here that the order of elements in the alignment # object is the same for both actual aligned objects, which seems to be the case. stored.obj1_resi = [] stored.obj2_resi = [] stored.obj1_resn = [] stored.obj2_resn = [] stored.obj1_chain = [] stored.obj2_chain = [] cmd.iterate( obj1 + " and n. CA and alignment", "stored.obj1_resi.append( resi )" ) cmd.iterate( obj2 + " and n. CA and alignment", "stored.obj2_resi.append( resi )" ) cmd.iterate( obj1 + " and n. CA and alignment", "stored.obj1_resn.append( resn )" ) cmd.iterate( obj2 + " and n. CA and alignment", "stored.obj2_resn.append( resn )" ) cmd.iterate( obj1 + " and n. CA and alignment", "stored.obj1_chain.append( chain )" ) cmd.iterate( obj2 + " and n. CA and alignment", "stored.obj2_chain.append( chain )" ) sele_mutations_list = [] sele_insert_list = [] wt_list = [] mut_list = [] mutations = [] # loop over the aligned residues for resn1, resn2, resi1, resi2, ch1, ch2 in zip( stored.obj1_resn, stored.obj2_resn, stored.obj1_resi, stored.obj2_resi, stored.obj1_chain, stored.obj2_chain ): # take care of 'empty' chain names if ch1 == '': ch1 = '""' if ch2 == '': ch2 = '""' if resn1 != resn2: #print "%s/%s-%s => %s/%s-%s" % ( ch1, resn1, resi1, ch2, resn2, resi2 ) sele_exp = '/' + '/'.join([ obj2, '', ch2, resi2 ]) sele_mutations_list.append( sele_exp ) wt_list.append( one_letter[resn1] ) mut_list.append( one_letter[resn2] ) mutations.append( "%s:%s%s%s" % ( ch2, one_letter[resn1], resi2, one_letter[resn2]) ) if not mutations: print "No mutations found." return selename = "mutated-" + obj2 #print "+".join(sele_mutations_list) cmd.select(selename, " + ".join(sele_mutations_list)) print "Mutations found: '%s'" % (mutations) cmd.show("sticks", selename) hideexp = "(mutated-" + obj2 + " and hydro)" cmd.hide(hideexp) cmd.color( "yellow", selename + " and not (name N+CA+C+O)" ) util.cnc(selename) cmd.disable(selename) for i in range(0,len(sele_mutations_list)): labelexp = '''"''' + wt_list[i] + '''%s''' + mut_list[i] + '''"''' + ''' % (resi)''' cmd.label( sele_mutations_list[i] + " and n. ca", labelexp ) #labelexp = '''(name ca+C1*+C1' and (byres(mutated-''' + obj2 + ''')))''' #cmd.label(labelexp,'''"%s-%s"%(resn,resi)''') # identify insertions also, by using the mutated selection and alignment object # this will be the intersection of everything that's in object2 that's not in the alignment object (will included mutated positions and inserts) and # not anything that's in the mutated selection selename = "inserts-" + obj2 cmd.select( selename, "(" + obj2 + " and not hydro and !(" + obj2 + " in alignment)) and !(mutated-" + obj2 + ")" ) cmd.color( "orange", selename ) util.cnc(selename) cmd.disable(selename) # clean up after ourselves cmd.delete("alignment")
def testSelectByAtomType(self): cmd.load(self.datafile('1oky.pdb.gz')) cmd.remove("alt 'B'") cmd.label('resn STU', 'text_type') cmd.select('foo', "resn STU and text_type 'C.3'") self.assertEquals(cmd.count_atoms('foo'), 8)
def muta(): ''' DESCRIPTION Creates an alignment of two proteins and superimposes them. Aligned residues that are different in the two (i.e. mutations) are highlighted and colored according to their difference in the BLOSUM90 matrix. Is meant to be used for similar proteins, e.g. close homologs or point mutants, to visualize their differences. USAGE color_by_mutation selection1, selection2 [,waters [,labels ]] ARGUMENTS obj1: object or selection obj2: object or selection waters: bool (0 or 1). If 1, waters are included in the view, colored differently for the both input structures. default = 0 labels: bool (0 or 1). If 1, the possibly mutated sidechains are labeled by their chain, name and id default = 0 EXAMPLE color_by_mutation protein1, protein2 SEE ALSO super ''' from pymol import stored, CmdException obj1 = "native_na" obj2 = "design_na" waters = 0 labels = 0 if cmd.count_atoms(obj1) == 0: print '%s is empty' % obj1 return if cmd.count_atoms(obj2) == 0: print '%s is empty' % obj2 return waters = int(waters) labels = int(labels) # align the two proteins aln = '__aln' # first, an alignment with 0 cycles (no atoms are rejected, which maximized the number of aligned residues) # for some mutations in the same protein this works fine). This is essentially done to get a # sequence alignment cmd.super(obj2, obj1, object=aln, cycles=0) # superimpose the the object using the default parameters to get a slightly better superimposition, # i.e. get the best structural alignment cmd.super(obj2, obj1) stored.resn1, stored.resn2 = [], [] stored.resi1, stored.resi2 = [], [] stored.chain1, stored.chain2 = [], [] # store residue ids, residue names and chains of aligned residues cmd.iterate(obj1 + ' and name CA and ' + aln, 'stored.resn1.append(resn)') cmd.iterate(obj2 + ' and name CA and ' + aln, 'stored.resn2.append(resn)') cmd.iterate(obj1 + ' and name CA and ' + aln, 'stored.resi1.append(resi)') cmd.iterate(obj2 + ' and name CA and ' + aln, 'stored.resi2.append(resi)') cmd.iterate(obj1 + ' and name CA and ' + aln, 'stored.chain1.append(chain)') cmd.iterate(obj2 + ' and name CA and ' + aln, 'stored.chain2.append(chain)') mutant_selection = '' non_mutant_selection = 'none or ' colors = [] # loop over the aligned residues for n1, n2, i1, i2, c1, c2 in zip(stored.resn1, stored.resn2, stored.resi1, stored.resi2, stored.chain1, stored.chain2): # take care of 'empty' chain names if c1 == '': c1 = '""' if c2 == '': c2 = '""' if n1 == n2: non_mutant_selection += '((%s and resi %s and chain %s) or (%s and resi %s and chain %s)) or ' % ( obj1, i1, c1, obj2, i2, c2) else: mutant_selection += '((%s and resi %s and chain %s) or (%s and resi %s and chain %s)) or ' % ( obj1, i1, c1, obj2, i2, c2) # get the similarity (according to the blosum matrix) of the two residues and c = getBlosum90ColorName(n1, n2) colors.append( (c, '%s and resi %s and chain %s and elem C' % (obj2, i2, c2))) if mutant_selection == '': print ' Error: No mutations found' raise CmdException # create selections cmd.select('mutations', mutant_selection[:-4]) cmd.select('non_mutations', non_mutant_selection[:-4]) cmd.select( 'not_aligned', '(%s or %s) and not mutations and not non_mutations' % (obj1, obj2)) # create the view and coloring cmd.hide('everything', '%s or %s' % (obj1, obj1)) cmd.show('cartoon', '%s or %s' % (obj2, obj1)) cmd.show( 'lines', '(%s or %s) and ((non_mutations or not_aligned) and not name c+o+n)' % (obj2, obj1)) cmd.show('sticks', '(%s or %s) and mutations and not name c+o+n' % (obj2, obj1)) cmd.color('white', 'elem C and non_mutations') cmd.color('cyan', 'elem C and mutations and %s' % obj1) cmd.color('gray', 'elem C and not_aligned') cmd.color('limon', 'chainA') cmd.util.cnc("all") for (col, sel) in colors: cmd.color(col, sel) cmd.hide('everything', '(hydro) and (%s or %s)' % (obj2, obj1)) cmd.center('%s or %s' % (obj2, obj1)) if labels: cmd.label('mutations and name CA', '"(%s-%s-%s)"%(chain, resi, resn)') if waters: cmd.set('sphere_scale', '0.1') cmd.show('spheres', 'resn HOH and (%s or %s)' % (obj2, obj1)) cmd.color('red', 'resn HOH and %s' % obj1) cmd.color('salmon', 'resn HOH and %s' % obj2) print ''' Mutations are highlighted in blue and red. All mutated sidechains of %s are colored blue, the corresponding ones from %s are colored on a spectrum from blue to red according to how similar the two amino acids are (as measured by the BLOSUM90 substitution matrix). Aligned regions without mutations are colored white. Regions not used for the alignment are gray. NOTE: There could be mutations in the gray regions that were not detected.''' % ( obj2, obj1) cmd.delete(aln) cmd.deselect() cmd.zoom("interface")
def show_AtomsName(self): cmd.label(self.LigDisplay, "\"%s\" % name") cmd.refresh()
cmd.load("$TUT/1hpv.pdb") # color by chain (aesthetics) util.cbc() # store the links as atom text_types cmd.alter("name CA",r"custom='http://delsci.info/cgi-bin/click.cgi?residue=%s%s%s'%(resn,resi,chain)") # put the mouse into single-atom selection mode cmd.set('mouse_selection_mode',0) # just show ribbon (means we can only select labelled C-alphas) cmd.show_as("cartoon") # set up the labels cmd.label("name CA","'Link'") # color the labels white cmd.set("label_color", 'white') # activate the wizard cmd.set_wizard(Clickurl())
def color_by_mutation(obj1, obj2, waters=0, labels=0): ''' DESCRIPTION Creates an alignment of two proteins and superimposes them. Aligned residues that are different in the two (i.e. mutations) are highlighted and colored according to their difference in the BLOSUM90 matrix. Is meant to be used for similar proteins, e.g. close homologs or point mutants, to visualize their differences. USAGE color_by_mutation selection1, selection2 [,waters [,labels ]] ARGUMENTS obj1: object or selection obj2: object or selection waters: bool (0 or 1). If 1, waters are included in the view, colored differently for the both input structures. default = 0 labels: bool (0 or 1). If 1, the possibly mutated sidechains are labeled by their chain, name and id default = 0 EXAMPLE color_by_mutation protein1, protein2 SEE ALSO super ''' from pymol import stored, CmdException if cmd.count_atoms(obj1) == 0: print '%s is empty'%obj1 return if cmd.count_atoms(obj2) == 0: print '%s is empty'%obj2 return waters = int(waters) labels = int(labels) # align the two proteins aln = '__aln' # first, an alignment with 0 cycles (no atoms are rejected, which maximized the number of aligned residues) # for some mutations in the same protein this works fine). This is essentially done to get a # sequence alignment cmd.super(obj1, obj2, object=aln, cycles=0) # superimpose the the object using the default parameters to get a slightly better superimposition, # i.e. get the best structural alignment cmd.super(obj1, obj2) stored.resn1, stored.resn2 = [], [] stored.resi1, stored.resi2 = [], [] stored.chain1, stored.chain2 = [], [] # store residue ids, residue names and chains of aligned residues cmd.iterate(obj1 + ' and name CA and ' + aln, 'stored.resn1.append(resn)') cmd.iterate(obj2 + ' and name CA and ' + aln, 'stored.resn2.append(resn)') cmd.iterate(obj1 + ' and name CA and ' + aln, 'stored.resi1.append(resi)') cmd.iterate(obj2 + ' and name CA and ' + aln, 'stored.resi2.append(resi)') cmd.iterate(obj1 + ' and name CA and ' + aln, 'stored.chain1.append(chain)') cmd.iterate(obj2 + ' and name CA and ' + aln, 'stored.chain2.append(chain)') mutant_selection = '' non_mutant_selection = 'none or ' colors = [] # loop over the aligned residues for n1, n2, i1, i2, c1, c2 in zip(stored.resn1, stored.resn2, stored.resi1, stored.resi2, stored.chain1, stored.chain2): # take care of 'empty' chain names if c1 == '': c1 = '""' if c2 == '': c2 = '""' if n1 == n2: non_mutant_selection += '((%s and resi %s and chain %s) or (%s and resi %s and chain %s)) or '%(obj1, i1, c1, obj2, i2, c2 ) else: mutant_selection += '((%s and resi %s and chain %s) or (%s and resi %s and chain %s)) or '%(obj1, i1, c1, obj2, i2, c2 ) # get the similarity (according to the blosum matrix) of the two residues and c = getBlosum90ColorName(n1, n2) colors.append((c, '%s and resi %s and chain %s and elem C'%(obj2, i2, c2))) if mutant_selection == '': print ' Error: No mutations found' raise CmdException # create selections cmd.select('mutations', mutant_selection[:-4]) cmd.select('non_mutations', non_mutant_selection[:-4]) cmd.select('not_aligned', '(%s or %s) and not mutations and not non_mutations'%(obj1, obj2)) # create the view and coloring cmd.hide('everything', '%s or %s'%(obj1, obj2)) cmd.show('cartoon', '%s or %s'%(obj1, obj2)) cmd.show('lines', '(%s or %s) and ((non_mutations or not_aligned) and not name c+o+n)'%(obj1, obj2)) cmd.show('sticks', '(%s or %s) and mutations and not name c+o+n'%(obj1, obj2)) cmd.color('gray', 'elem C and not_aligned') cmd.color('white', 'elem C and non_mutations') cmd.color('blue', 'elem C and mutations and %s'%obj1) for (col, sel) in colors: cmd.color(col, sel) cmd.hide('everything', '(hydro) and (%s or %s)'%(obj1, obj2)) cmd.center('%s or %s'%(obj1, obj2)) if labels: cmd.label('mutations and name CA','"(%s-%s-%s)"%(chain, resi, resn)') if waters: cmd.set('sphere_scale', '0.1') cmd.show('spheres', 'resn HOH and (%s or %s)'%(obj1, obj2)) cmd.color('red', 'resn HOH and %s'%obj1) cmd.color('salmon', 'resn HOH and %s'%obj2) print ''' Mutations are highlighted in blue and red. All mutated sidechains of %s are colored blue, the corresponding ones from %s are colored on a spectrum from blue to red according to how similar the two amino acids are (as measured by the BLOSUM90 substitution matrix). Aligned regions without mutations are colored white. Regions not used for the alignment are gray. NOTE: There could be mutations in the gray regions that were not detected.'''%(obj1, obj2) cmd.delete(aln) cmd.deselect()
from pymol import cmd cmd.bg_color('white') cmd.select('drg', 'all') cmd.set('valence', '1') cmd.set_bond('stick_radius', '0.14', 'drg', 'drg') cmd.set('sphere_scale', '0.25', 'drg') cmd.show('sticks', 'drg') cmd.show('spheres', 'drg') cmd.set_view ([0.987891138, -0.139472052, -0.067891687, 0.152521998, 0.793636620, 0.588958621, -0.028259384, -0.592185259, 0.805302858, 0.000017954, 0.000006792, -52.386489868, -1.638074398, -1.409737468, -0.143483341, -34.060420990, 138.833740234, 20.000000000]) charges = ["-0.103" ," 0.115" ," 0.016" ,"-0.082" ," 0.068" ,"-0.022" ,"-0.017" ," 0.017" ,"-0.001" ,"-0.051" ," 0.120" ,"-0.186" ," 0.163" ,"-0.115" ," 0.216" ,"-0.142" ," 0.130" ,"-0.294" ," 0.114" ,"-0.004" ," 0.102" ,"-0.098" ,"-0.004" ," 0.102" ,"-0.294" ," 0.114" ," 0.882" ,"-0.582" ,"-0.582" ,"-0.582"] cmd.set('label_size', '22') cmd.set('label_position', (0, 2, 2)) for i, charge in zip(range(1, 31), charges): cmd.label('id %s' % i, charge) # output cmd.set('antialias', '2') cmd.set('direct', '0.6') cmd.set('orthoscopic', 'on') cmd.set('ray_trace_frames', '1') #cmd.ray(renderer=-1) #cmd.png('~/Downloads/charge.png', dpi=600)
cmd.load("$TUT/1hpv.pdb") # color by chain (aesthetics) util.cbc() # store the links as atom text_types cmd.alter("name ca",r"custom='http://delsci.info/cgi-bin/click.cgi?residue=%s%s%s'%(resn,resi,chain)") # put the mouse into single-atom selection mode cmd.set('mouse_selection_mode',0) # just show ribbon (means we can only select labelled C-alphas) cmd.show_as("cartoon") # set up the labels cmd.label("name ca","'Link'") # color the labels white cmd.set("label_color", 'white') # activate the wizard cmd.set_wizard(Clickurl())
dirpath = tempfile.mkdtemp() zip_dir = 'hotspot_boundaries.zip' with zipfile.ZipFile(zip_dir) as hs_zip: hs_zip.extractall(dirpath) cmd.load(join(dirpath,"protein.pdb"), "protein") cmd.show("cartoon", "protein") if dirpath: f = join(dirpath, "0/label_threshold_12.9.mol2") else: f = "0/label_threshold_12.9.mol2" cmd.load(f, 'label_threshold_12.9') cmd.hide('everything', 'label_threshold_12.9') cmd.label("label_threshold_12.9", "name") cmd.set("label_font_id", 7) cmd.set("label_size", -0.4) colour_dict = {'acceptor':'red', 'donor':'blue', 'apolar':'yellow', 'negative':'purple', 'positive':'cyan'} threshold_list = [12.9] gfiles = ['0/donor.grd', '0/apolar.grd', '0/acceptor.grd'] grids = ['donor', 'apolar', 'acceptor'] num = 0 surf_transparency = 0.2 if dirpath: gfiles = [join(dirpath, g) for g in gfiles]
A = AggregatTransferFromFile(fname) cmd.set_view ([ -0.480811268, 0.603387773, 0.636203885, 0.675508440, 0.717507422, -0.169974893, -0.559037924, 0.348030269, -0.752567112, -0.000127681, 0.000030167, -122.974456787, 13.921709061, -7.469791889, -4.264435768, -1086.176879883, 1332.132446289, -20.000000000]) # select only a few sample points indices = [0, 250, 500, 1000, 1999] t = np.linspace(0, A._tLength, A._tSteps)[indices] # Get values ordered by time in first index values = np.swapaxes(A.get(), 0, 1)[indices] selections = ['lab{}'.format(i + 1) for i in range(8)] for lab in selections: cmd.label(lab, '') selections = ['bcl{}'.format(i + 1) for i in range(7)] for i, val in enumerate(values): alpha = p_to_alpha(val) for n, bcl in enumerate(selections): cmd.set_bond('stick_transparency', alpha[n], bcl) cmd.refresh() cmd.ray(width, height) print('Belongs to time {}'.format(t[i] * 5.20883746)) cmd.png('../fmo_transfer_{}.png'.format(i), dpi=DPI, ray=1)
SPHERE, 1.0+math.cos(a/10.0), 1.0+math.sin(a/20.0), 1.0+math.cos(a/10.0), 0.2+math.cos(a/5.0)/10.0, COLOR, 1.0, 0.2, 0.2, SPHERE, 2.0-math.cos(a/10.0), 1.0+math.sin(0.5+a/10.0), 1.0+math.cos(a/10.0), 0.2+math.cos(a/5.0)/10.0, ] obj = axes + balls cmd.load_cgo(obj,'cgo01',c) c = c + 1 # counter label pdb_list = [ "HETATM%5d C UNK 1 %8.3f%8.3f%8.3f 1.00 10.00\n"%(c,2.0,0,2.0), ] cmd.read_pdbstr(''.join(pdb_list),'lab1',c,discrete=1) cmd.label("(lab1 and id %d)"%c,"'frame %d %6.3f'"%(c,math.sin(a/10.0))) cmd.hide("nonbonded","lab1") # axes labels pdb_list = [ "HETATM 1 X UNK 1 %8.3f%8.3f%8.3f 1.00 10.00\n"%(3.2,0,0), "HETATM 2 Y UNK 2 %8.3f%8.3f%8.3f 1.00 10.00\n"%(0,3.2,0), "HETATM 3 Z UNK 3 %8.3f%8.3f%8.3f 1.00 10.00\n"%(0,0,3.2),] cmd.read_pdbstr(''.join(pdb_list),'lab2') cmd.hide('(lab2)') cmd.label('lab2','name') cmd.color('white','lab2')
c=0 for a in xrange(0,100): cluster.MD_step() balls = [] for i in xrange(0,cluster.N): balls.extend([COLOR, 1.0, 1.0, 1.0, SPHERE, cluster.particles[i].x, cluster.particles[i].y, cluster.particles[i].z, 0.5,]) obj = axes + balls cmd.load_cgo(obj,'cgo01',c) c = c + 1 pdb_list = [ "HETATM 1 X UNK 1 %8.3f%8.3f%8.3f 1.00 10.00\n"%(3.2,0,0), "HETATM 2 Y UNK 2 %8.3f%8.3f%8.3f 1.00 10.00\n"%(0,3.2,0), "HETATM 3 Z UNK 3 %8.3f%8.3f%8.3f 1.00 10.00\n"%(0,0,3.2), ] cmd.read_pdbstr(string.join(pdb_list,''),'lab2') cmd.hide('(lab2)') cmd.label('lab2','name') cmd.color('white','lab2') #cmd.zoom('cgo01') cmd.clip('far',-5)
else : cmd.color('blue','dist'+ch+str(n)) cmd.hide('labels','dist'+ch+str(n)) cmd.show('spheres','3H4E//'+ch+'/'+e[0]+'/CA') cmd.show('spheres','3H4E//'+ch+'/'+e[1]+'/CA') cmd.color('yellow','3H4E//'+ch+'/'+e[0]+'/CA') cmd.color('yellow','3H4E//'+ch+'/'+e[1]+'/CA') # Create a set of residues set_res = [] for e_tup in edges : set_res.extend(e_tup) set_res = set(set_res) for ch,resi in itertools.product(chains,set_res) : cmd.label('3H4E//'+ch+'/'+resi+'/CA','"%s%s"%(resn,resi)') cmd.set('dash_radius','0.2'); cmd.set('dash_gap','0.0'); cmd.set('sphere_scale','0.3') #cmd.set('sphere_scale','0.8','retinal'); #cmd.ray() outfp = os.path.join(DATA_DIR,os.path.splitext(edgef)[0]+'_hex_top.png') print('*'*5+'Image:%s'%os.path.abspath(outfp)+'*'*5) cmd.png(os.path.abspath(outfp)) print('-----Finished drawing from top -----') # Set the view from the bottom cmd.set_view (\ '-0.062551118, 0.668488383, -0.741087615,\ 0.326947540, -0.687838376, -0.648059845,\
def snp_common(record, selection, label, name, quiet): ''' Common part of snp_uniprot and snp_ncbi. Argument `record' must be a Bio.SwissProt.Record object with `sequence', `entry_name' and `features' fields defined. ''' from . import one_letter from .seqalign import needle_alignment, alignment_mapping label = int(label) quiet = int(quiet) pdbids = cmd.get_object_list(selection) chains = cmd.get_chains(selection) if len(pdbids) != 1: print('please select one object') return snpi = set() snpi_str = [] labels = dict() for chain in chains: print('chain ' + chain) res_list = [] cmd.iterate('(%s) and chain %s and name CA' % (selection, chain), 'res_list.append((resn,resv))', space=locals()) seq = ''.join([one_letter.get(res[0], 'X') for res in res_list]) align = needle_alignment(record.sequence, seq) if not quiet: align._records[0].id = record.entry_name align._records[1].id = pdbids[0] + '_' + chain print(align.format('clustal')) map1 = dict(alignment_mapping(*align)) for feature in record.features: if feature[0] != 'VARIANT' or feature[1] != feature[2]: continue i = feature[1] if (i-1) not in map1: if not quiet: print('not mapped', feature) continue resi = res_list[map1[i-1]][1] snpi.add(resi) if not quiet: print('%s`%d' % res_list[map1[i-1]], feature[2:4]) if label: labels.setdefault((chain, resi), []).append(feature[3].split(' (')[0]) if len(snpi) > 0: snpi_str.append('(chain %s and resi %s)' % (chain, '+'.join(map(str, snpi)))) for chain, resi in labels: lab = ', '.join(labels[(chain, resi)]) cmd.label('(%s) and chain %s and resi %d and name CA' % (selection, chain, resi), repr(lab)) if len(snpi_str) == 0: print('no missense variants') return if name == '': name = cmd.get_unused_name('nsSNPs') cmd.select(name, '(%s) and (%s)' % (selection, ' or '.join(snpi_str)))