def simple_no_solv(selection="(all)",_self=cmd): cmd=_self simple(selection,_self=_self) s = tmp_sele cmd.select(s,selection) cmd.hide("nonbonded","("+solv_sele+" and "+s+")") cmd.delete(s)
def publication(selection="(all)",_self=cmd): cmd=_self pub_solv(selection,_self) s = tmp_sele cmd.select(s,selection) cmd.hide("nb_spheres","(("+lig_sele+"|resn hoh+wat+h2o) and "+s+")") cmd.delete(s)
def pretty(selection,_self=cmd): cmd=_self pretty_solv(selection,_self) s = tmp_sele cmd.select(s,selection) cmd.hide("nb_spheres","("+s+" and "+lig_sele+"|resn hoh+wat+h2o)") cmd.delete(s)
def phipsi(selection="(pk1)",_self=cmd): pymol=_self._pymol cmd=_self # NOT THREAD SAFE n_sele = "((byres (%s)) & name n)"%selection c_sele = "((byres (%s)) & name c)"%selection ca_sele = "((byres (%s)) & name ca)"%selection cm_sele = "((neighbor (%s)) and not (byres (%s)))"%(n_sele,n_sele) np_sele = "((neighbor (%s)) and not (byres (%s)))"%(c_sele,c_sele) cmd.feedback("push") cmd.feedback("disable","selector","everythin") cm_cnt = cmd.select("_pp_cm",cm_sele) n_cnt = cmd.select("_pp_n",n_sele) c_cnt = cmd.select("_pp_c",c_sele) ca_cnt = cmd.select("_pp_ca",ca_sele) np_cnt = cmd.select("_pp_np",np_sele) if(cm_cnt and n_cnt and ca_cnt and c_cnt): phi = cmd.get_dihedral("_pp_c","_pp_ca","_pp_n","_pp_cm") else: phi = None if(n_cnt and ca_cnt and c_cnt and np_cnt): psi = cmd.get_dihedral("_pp_np","_pp_c","_pp_ca","_pp_n") else: psi = None cmd.feedback("pop") cmd.delete("_pp_cm") cmd.delete("_pp_n") cmd.delete("_pp_c") cmd.delete("_pp_ca") cmd.delete("_pp_np") return (phi,psi)
def simple(selection="(all)", _self=cmd): cmd = _self s = tmp_sele cmd.select(s, selection) _prepare(s, _self=cmd) util.cbc(s, _self=cmd) cmd.show("ribbon", s) cmd.show( "lines", "(byres ((" + s + " & r. CYS+CYX & n. SG) & bound_to (" + s + " & r. CYS+CYX & n. SG))) & n. CA+CB+SG") # try to show what covalent ligands are connected to... cmd.show("sticks", "(" + lig_sele + " and (" + s + ")) extend 2") cmd.show( "sticks", "byres ((" + lig_sele + " and (" + s + ") and not resn ACE+NAC+NME+NH2) extend 1)") cmd.hide("sticks", "(" + s + ") and ((not rep sticks) extend 1)") cmd.show("sticks", "(" + lig_sele + " and (" + s + ")) extend 2") # color by atom if lines or sticks are shown util.cnc("(( rep lines or rep sticks or (" + lig_and_solv_sele + ")) and (" + s + "))", _self=cmd) cmd.show("nonbonded", "(" + lig_and_solv_sele + " and (" + s + "))") cmd.show("lines", "(" + lig_and_solv_sele + " and (" + s + "))") if cmd.count_atoms(s): cmd.zoom(s) cmd.delete(s)
def _prepare(selection, polar_contacts=None, _self=cmd): cmd = _self # this function should undo everything that is done by any preset function in this module # (except for coloring) s = tmp_sele cmd.select(s, selection) cmd.cartoon("auto", s) cmd.hide("everything", s) cmd.set("two_sided_lighting", 0) # global cmd.unset("transparency", s) cmd.unset("dot_normals", s) cmd.unset("mesh_normals", s) cmd.unset("surface_quality", s) cmd.unset("surface_type", selection) cmd.unset("sphere_scale", selection) cmd.unset_bond("stick_radius", s, s) cmd.unset_bond("stick_color", s, s) cmd.unset("cartoon_highlight_color", selection) cmd.unset("cartoon_fancy_helices", selection) cmd.unset("cartoon_smooth_loops", selection) cmd.unset("cartoon_flat_sheets", selection) cmd.unset("cartoon_side_chain_helper", selection) cmd.unset("mesh_normals", s) cmd.unset("dot_normals", s) if polar_contacts == None: polar_contacts = _get_polar_contacts_name(s, _self) if polar_contacts in cmd.get_names('objects'): cmd.delete(polar_contacts)
def _prepare(selection,polar_contacts=None,_self=cmd): cmd=_self # this function should undo everything that is done by any preset function in this module # (except for coloring) s = tmp_sele cmd.select(s,selection) cmd.cartoon("auto",s) cmd.hide("everything",s) cmd.set("two_sided_lighting",0) # global cmd.unset("transparency",s) cmd.unset("dot_normals",s) cmd.unset("mesh_normals",s) cmd.unset("surface_quality",s) cmd.unset("surface_type",selection) cmd.unset("sphere_scale",selection) cmd.unset_bond("stick_radius",s,s) cmd.unset_bond("stick_color",s,s) cmd.unset("cartoon_highlight_color",selection) cmd.unset("cartoon_fancy_helices",selection) cmd.unset("cartoon_smooth_loops",selection) cmd.unset("cartoon_flat_sheets",selection) cmd.unset("cartoon_side_chain_helper",selection) cmd.unset("mesh_normals",s) cmd.unset("dot_normals",s) if polar_contacts == None: polar_contacts = _get_polar_contacts_name(s,_self) if polar_contacts in cmd.get_names('objects'): cmd.delete(polar_contacts)
def ligand_sites_hq(selection="(all)",_self=cmd): cmd=_self ligand_sites(selection,_self) s = tmp_sele cmd.select(s,selection) cmd.set("surface_quality","1",selection) cmd.set("surface_type",0,selection) cmd.delete(s)
def ligand_cartoon(selection="(all)",_self=cmd): cmd=_self ligand_sites(selection,_self) s = tmp_sele cmd.select(s,selection) cmd.set("cartoon_side_chain_helper",1,selection) cmd.show("cartoon","rep ribbon") cmd.hide("ribbon") cmd.hide("surface") cmd.delete(s)
def ligand_sites_dots(selection="(all)",_self=cmd): cmd=_self ligand_sites(selection,_self) s = tmp_sele cmd.select(s,selection) cmd.show("sticks",s+" and rep lines") cmd.hide("lines",s+" and rep lines") cmd.set("surface_type","1",selection) cmd.set("surface_quality","1",selection) cmd.set("dot_normals",0,s) cmd.delete(s)
def ligand_sites_trans_hq(selection="(all)",_self=cmd): cmd=_self ligand_sites(selection,_self) s = tmp_sele cmd.select(s,selection) cmd.show("sticks",s+" and rep lines") cmd.hide("lines",s+" and rep lines") cmd.set("transparency","0.33",s) cmd.set("surface_type",0,selection) cmd.set("surface_quality",1,selection) cmd.delete(s)
def b_factor_putty(selection="(name ca or name p)",_self=cmd): cmd=_self s = tmp_sele cmd.select(s,selection) _prepare(s,_self=cmd) cmd.select(s,"(name ca or name p) and ("+selection+")") cmd.show("cartoon",s) cmd.set("cartoon_flat_sheets",0,selection) cmd.cartoon("putty",s) cmd.spectrum("b",selection=s) cmd.delete(s)
def ligands(selection="(all)", _self=cmd): cmd = _self try: s = tmp_sele cmd.select(s, selection) polar_contacts = _get_polar_contacts_name(s, _self) _prepare(s, polar_contacts, _self=cmd) host = "_preset_host" solvent = "_preset_solvent" near_solvent = "_preset_solvent" lig = "_preset_lig" cmd.select(host, s + " and " + prot_and_dna_sele) cmd.select(solvent, s + " and " + solv_sele) cmd.select(lig, s + " and " + lig_sele) cmd.select(near_solvent, s + " and (" + solvent + " within 4 of " + lig + ")") util.chainbow(host, _self=cmd) util.cbc(lig, _self=cmd) util.cbac("((" + s + ") and not elem c)", _self=cmd) cmd.hide("everything", s) cmd.show("ribbon", host) cmd.show( "lines", "(" + s + " and byres (" + host + " within 5 of " + lig + "))") cmd.show("sticks", lig) cmd.show("sticks", solvent + " and neighbor " + lig) cmd.show("lines", "(" + s + " and (rep lines extend 1) and " + lig + ")") if cmd.count_atoms(lig): cmd.dist(polar_contacts, host + "|" + near_solvent, lig + "|" + near_solvent, mode=2, quiet=1, label=0, reset=1) # hbonds if polar_contacts in cmd.get_names(): cmd.enable(polar_contacts) cmd.hide("labels", polar_contacts) cmd.show("dashes", polar_contacts) else: cmd.delete(polar_contacts) cmd.show("nonbonded", lig + "|" + host + "|" + near_solvent) if cmd.count_atoms(lig): cmd.zoom(lig, 3) cmd.delete(host) cmd.delete(solvent) cmd.delete(near_solvent) cmd.delete(lig) except: traceback.print_exc()
def pub_solv(selection="(all)",_self=cmd): cmd=_self pretty_solv(selection,_self) s = tmp_sele cmd.select(s,selection) cmd.set("cartoon_smooth_loops",1,selection) cmd.set("cartoon_highlight_color","grey50",selection) cmd.set("cartoon_fancy_helices",1,selection) cmd.set("cartoon_flat_sheets",1,selection) cmd.set("cartoon_side_chain_helper",0,selection) if cmd.count_atoms(s): cmd.zoom(s) cmd.delete(s)
def ligand_sites(selection="(all)",_self=cmd): cmd=_self try: s = tmp_sele cmd.select(s,selection) polar_contacts = _get_polar_contacts_name(s,_self) _prepare(s,polar_contacts,_self=cmd) host = "_preset_host" solvent = "_preset_solvent" near_solvent = "_preset_solvent" lig = "_preset_lig" cmd.select(host,s+" and "+prot_and_dna_sele) cmd.select(solvent,s+" and "+solv_sele) cmd.select(lig,s+" and "+lig_sele) cmd.select(near_solvent,s+" and ("+solvent+" within 4 of "+lig+")") cmd.flag("ignore",host,"clear") cmd.flag("ignore",lig+"|"+solvent,"set") util.chainbow(host,_self=cmd) util.cbc(lig,_self=cmd) util.cbac("(("+s+") and not elem c)",_self=cmd) cmd.hide("everything",s) cmd.show("ribbon",host) cmd.show("lines","("+s+" and byres ("+host+" within 5 of "+lig+"))") cmd.show("surface","("+s+" and ((rep lines expand 4) within 6 of "+lig+"))") cmd.set("two_sided_lighting",1) # global setting cmd.set("transparency",0,s) cmd.set("surface_quality",0,s) cmd.show("sticks",lig) cmd.show("sticks",solvent+" and neighbor "+lig) cmd.show("lines","("+s+" and (rep lines extend 1) and "+lig+")") if cmd.count_atoms(lig): cmd.dist(polar_contacts,host+"|"+near_solvent,lig+"|"+near_solvent,mode=2,quiet=1,label=0,reset=1) # hbonds if polar_contacts in cmd.get_names(): cmd.enable(polar_contacts) cmd.hide("labels",polar_contacts) cmd.show("dashes",polar_contacts) else: cmd.delete(polar_contacts) cmd.show("nb_spheres",lig+"|"+host+"|"+near_solvent) if cmd.count_atoms(lig): cmd.zoom(lig,3) cmd.delete(host) cmd.delete(solvent) cmd.delete(near_solvent) cmd.delete(lig) except: traceback.print_exc()
def default(selection="(all)",_self=cmd): cmd=_self s = tmp_sele cmd.select(s,selection) _prepare(s,_self=cmd) cmd.show("lines",s) cmd.show("nonbonded",s) color=cmd.get_object_color_index(selection) if color<0: util.cbag(selection,_self=cmd) else: util.cnc(selection,_self=cmd) cmd.color(str(color),"("+s+") and elem c") cmd.delete(s)
def mass_align(target,enabled_only=0,max_gap=50,_self=cmd): pymol=_self._pymol cmd=_self list = cmd.get_names("public_objects",int(enabled_only)) filter(lambda x:cmd.get_type(x)!="object:molecule",list) if enabled_only: aln_object = 'aln_enabled_to'+target else: aln_object = 'aln_all_to_'+target cmd.delete(aln_object) for name in list: if name!=target: if cmd.count_atoms("(%s) and (%s)"%(target,name))==0: cmd.align('polymer and name ca and (%s)'%name, 'polymer and name ca and (%s)'%target,max_gap=max_gap,quiet=0, object=aln_object)
def displacementUpdateB(objA, alnAri, objB, alnBri): ### If residue is unassigned in one of the pdb files, we reset its value for x in range(len(alnAri)): s1 = objA + " and name CA and resi " + alnAri[x] cmd.alter( s1, "b = " + str(-0.01)) for x in range(len(alnBri)): s2 = objB + " and name CA and resi " + alnBri[x] cmd.alter( s2, "b = " + str(-0.01)) cmd.sort(objA); cmd.sort(objB) for x in range(len(alnAri)): s1 = objA + " and name CA and resi " + alnAri[x] s2 = objB + " and name CA and resi " + alnAri[x] ### Names starting with __ (underscores) are normally hidden by PyMOL tempObject = "__tempObject" Displacement = cmd.distance(tempObject, s1, s2) cmd.alter( s1, "b = " + str(Displacement)) cmd.alter( s2, "b = " + str(Displacement)) cmd.delete(tempObject) cmd.sort(objA); cmd.sort(objB)
def displacementUpdateBAll(objA, alnAri, objB, alnBri): print "This will take a while to go through the for loops. Give me around 3-5 minutes..." ### If residue is unassigned in one of the pdb files, we reset its value for x in range(len(alnAri)): s1 = objA + " and resi " + alnAri[x][0] + " and name " + str(alnAri[x][1]) cmd.alter( s1, "b = " + str(-0.01)) for x in range(len(alnBri)): s2 = objB + " and resi " + alnBri[x][0] + " and name " + alnBri[x][1] cmd.alter( s2, "b = " + str(-0.01)) cmd.sort(objA); cmd.sort(objB) for x in range(len(alnAri)): s1 = objA + " and resi " + alnAri[x][0] + " and name " + alnAri[x][1] s2 = objB + " and resi " + alnAri[x][0] + " and name " + alnAri[x][1] ### Names starting with __ (underscores) are normally hidden by PyMOL tempObject = "__tempObject" Displacement = cmd.distance(tempObject, s1, s2) cmd.alter( s1, "b = " + str(Displacement)) cmd.alter( s2, "b = " + str(Displacement)) cmd.delete(tempObject) cmd.sort(objA); cmd.sort(objB)
def find_interfaces(self): interfaces=dict() chainkeys=self.chains.keys() for chain1key in chainkeys: chain1=self.chains[chain1key] for chain2key in chainkeys: if chain1key==chain2key: continue chain2=self.chains[chain2key] interface1=cmd.select(self.name+'_'+chain1key+'_interface_'+chain1key+chain2key, 'byres '+self.name+' and chain '+chain1key+' within 4.0 of chain '+chain2key) interface2=cmd.select(self.name+'_'+chain2key+'_interface_'+chain1key+chain2key, 'byres '+self.name+' and chain '+chain2key+' within 4.0 of chain '+chain1key) newinterface=cmd.select(self.name+'_interface_'+chain1key+chain2key, '('+self.name+'_'+chain1key+'_interface_'+chain1key+chain2key+',' +self.name+'_'+chain2key+'_interface_'+chain1key+chain2key+')') interfaces[chain1key+chain2key]=newinterface cmd.delete(self.name+'_'+chain1key+'_interface_'+chain1key+chain2key) cmd.delete(self.name+'_'+chain2key+'_interface_'+chain1key+chain2key) self.interfaces=interfaces
def simple(selection="(all)",_self=cmd): cmd=_self s = tmp_sele cmd.select(s,selection) _prepare(s,_self=cmd) util.cbc(s,_self=cmd) cmd.show("ribbon",s) cmd.show("lines","(byres (("+s+" & r. CYS+CYX & n. SG) & bound_to ("+s+" & r. CYS+CYX & n. SG))) & n. CA+CB+SG") # try to show what covalent ligands are connected to... cmd.show("sticks","("+lig_sele+" and ("+s+")) extend 2") cmd.show("sticks","byres (("+lig_sele+" and ("+s+") and not resn ACE+NAC+NME+NH2) extend 1)") cmd.hide("sticks","("+s+") and ((not rep sticks) extend 1)") cmd.show("sticks","("+lig_sele+" and ("+s+")) extend 2") # color by atom if lines or sticks are shown util.cnc("(( rep lines or rep sticks or ("+lig_and_solv_sele+")) and ("+s+"))",_self=cmd) cmd.show("nonbonded","("+lig_and_solv_sele+" and ("+s+"))") cmd.show("lines","("+lig_and_solv_sele+" and ("+s+"))") if cmd.count_atoms(s): cmd.zoom(s) cmd.delete(s)
def ball_and_stick(selection="(all)",mode=1,_self=cmd): cmd=_self s = tmp_sele cmd.select(s,selection) _prepare(s,_self=cmd) if mode == 1: cmd.hide("everything",s) cmd.set_bond("stick_color","white",s,s) cmd.set_bond("stick_radius","0.14",s,s) cmd.set("sphere_scale","0.25",s) cmd.show("sticks",s) cmd.show("spheres",s) elif mode == 2: cmd.hide("everything",s) cmd.set_bond("stick_color","white",s,s) cmd.set_bond("stick_radius","-0.14",s,s) cmd.set("stick_ball","1") cmd.set("stick_ball_ratio",-1.0) cmd.set("stick_ball_color","atomic") cmd.show("sticks",s) cmd.delete(s)
def technical(selection="(all)",_self=cmd): cmd=_self s = tmp_sele cmd.select(s,selection) polar_contacts = _get_polar_contacts_name(s,_self) _prepare(s,polar_contacts,_self=cmd) util.chainbow(s,_self=cmd) util.cbc("("+lig_sele+" and ("+s+"))",_self=cmd) util.cbac("(("+s+") and not elem c)",_self=cmd) cmd.show("nonbonded",s) cmd.show("lines","((("+s+") and not "+lig_sele+") extend 1)") cmd.show("sticks","("+lig_sele+" and ("+s+"))") cmd.show("ribbon",s) cmd.dist(polar_contacts,s,s,mode=2,label=0,reset=1) # hbonds if polar_contacts in cmd.get_names(): cmd.enable(polar_contacts) cmd.set("dash_width",1.5,polar_contacts) cmd.hide("labels",polar_contacts) cmd.show("dashes",polar_contacts) cmd.show("nonbonded","(("+lig_sele+"|resn hoh+wat+h2o) and ("+s+"))") cmd.delete(s)
def pretty_solv(selection="(all)",_self=cmd): cmd=_self s = tmp_sele cmd.select(s,selection) polar_contacts = _get_polar_contacts_name(s,_self) _prepare(s,polar_contacts,_self=cmd) cmd.dss(s,preserve=1) cmd.cartoon("auto",s) cmd.show("cartoon",s) cmd.show("sticks","("+lig_sele+" and ("+s+"))") cmd.show("nb_spheres","(("+lig_sele+"|resn hoh+wat+h2o) and ("+s+"))") util.cbc("("+lig_sele+" and ("+s+"))",_self=cmd) util.cbac("("+lig_sele+" and ("+s+") and not elem c)",_self=cmd) cmd.spectrum("count",selection="(elem c and ("+s+") and not "+lig_sele+")") cmd.set("cartoon_highlight_color",-1,selection) cmd.set("cartoon_fancy_helices",0,selection) cmd.set("cartoon_smooth_loops",0,selection) cmd.set("cartoon_flat_sheets",1,selection) cmd.set("cartoon_side_chain_helper",0,selection) if polar_contacts in cmd.get_names(): cmd.disable(polar_contacts) if cmd.count_atoms(s): cmd.zoom(s) cmd.delete(s)
def set_rotamer(sel, chi1, chi2=0,chi3=0,chi4=0): at = cmd.get_model("byres ("+sel+")").atom[0] list = [chi1,chi2,chi3,chi4] for i in range(len(CHIS[at.resn])): print "Setting Chi"+str(i+1)+" to "+str(list[i]) editing.set_dihedral(sel + ' and name '+CHIS[at.resn][i][0], sel + ' and name '+CHIS[at.resn][i][1], sel + ' and name '+CHIS[at.resn][i][2], sel + ' and name '+CHIS[at.resn][i][3], str(list[i])) # Remove some objects that got created cmd.delete("pk1") cmd.delete("pk2") cmd.delete("pkmol")
def protein_vacuum_esp(selection, mode=2, border=10.0, quiet = 1, _self=cmd): pymol=_self._pymol cmd=_self if ((string.split(selection)!=[selection]) or selection not in cmd.get_names('objects')): print " Error: must provide an object name" raise cmd.QuietException obj_name = selection + "_e_chg" map_name = selection + "_e_map" pot_name = selection + "_e_pot" cmd.disable(selection) cmd.delete(obj_name) cmd.delete(map_name) cmd.delete(pot_name) cmd.create(obj_name,"((polymer and ("+selection+ ") and (not resn A+C+T+G+U)) or ((bymol (polymer and ("+ selection+"))) and resn NME+NHE+ACE)) and (not hydro)") # try to just get protein... protein_assign_charges_and_radii(obj_name,_self=_self) ext = cmd.get_extent(obj_name) max_length = max(abs(ext[0][0] - ext[1][0]),abs(ext[0][1] - ext[1][1]),abs(ext[0][2]-ext[1][2])) + 2*border # compute an grid with a maximum dimension of 50, with 10 A borders around molecule, and a 1.0 A minimum grid sep = max_length/50.0 if sep<1.0: sep = 1.0 print " Util: Calculating electrostatic potential..." if mode==0: # absolute, no cutoff cmd.map_new(map_name,"coulomb",sep,obj_name,border) elif mode==1: # neutral, no cutoff cmd.map_new(map_name,"coulomb_neutral",sep,obj_name,border) else: # local, with cutoff cmd.map_new(map_name,"coulomb_local",sep,obj_name,border) cmd.ramp_new(pot_name, map_name, selection=obj_name,zero=1) cmd.hide("everything",obj_name) cmd.show("surface",obj_name) cmd.set("surface_color",pot_name,obj_name) cmd.set("surface_ramp_above_mode",1,obj_name)
def colorByRMSD(objSel1, objSel2, doAlign="True", doPretty=None): """ colorByRMSD -- align two structures and show the structural deviations in color to more easily see variable regions. PARAMS objSel1 (valid PyMOL object or selection) The first object to align. objSel2 (valid PyMOL object or selection) The second object to align doAlign (boolean, either True or False) Should this script align your proteins or just leave them as is? If doAlign=True then your original proteins are aligned. If False, then they are not. Regardless, the B-factors are changed. DEFAULT: True doPretty (boolean, either True or False) If doPretty=True then a simple representation is created to highlight the differences. If False, then no changes are made. DEFAULT: False RETURNS None. SIDE-EFFECTS Modifies the B-factor columns in your original structures. """ # First create backup copies; names starting with __ (underscores) are # normally hidden by PyMOL tObj1, tObj2, aln = "__tempObj1", "__tempObj2", "__aln" if strTrue(doAlign): # perform the alignment cmd.create( tObj1, objSel1 ) cmd.create( tObj2, objSel2 ) cmd.super( tObj1, tObj2, object=aln ) cmd.matrix_copy(tObj1, objSel1) else: # perform the alignment cmd.create( tObj1, objSel1 ) cmd.create( tObj2, objSel2 ) cmd.super( tObj1, tObj2, object=aln ) # Modify the B-factor columns of the original objects, # in order to identify the residues NOT used for alignment, later on cmd.alter( objSel1 + " or " + objSel2, "b=-10") cmd.alter( tObj1 + " or " + tObj2, "chain='A'") cmd.alter( tObj1 + " or " + tObj2, "segi='A'") # Update pymol internal representations; one of these should do the trick cmd.refresh(); cmd.rebuild(); cmd.sort(tObj1); cmd.sort(tObj2) # Create lists for storage stored.alnAres, stored.alnBres = [], [] # Get the residue identifiers from the alignment object "aln" cmd.iterate(tObj1 + " and n. CA and " + aln, "stored.alnAres.append(resi)") cmd.iterate(tObj2 + " and n. CA and " + aln, "stored.alnBres.append(resi)") # Change the B-factors for EACH object rmsUpdateB(tObj1,stored.alnAres,tObj2,stored.alnBres) # Store the NEW B-factors stored.alnAnb, stored.alnBnb = [], [] cmd.iterate(tObj1 + " and n. CA and " + aln, "stored.alnAnb.append(b)" ) cmd.iterate(tObj2 + " and n. CA and " + aln, "stored.alnBnb.append(b)" ) # Get rid of all intermediate objects and clean up cmd.delete(tObj1) cmd.delete(tObj2) cmd.delete(aln) # Assign the just stored NEW B-factors to the original objects for x in range(len(stored.alnAres)): cmd.alter(objSel1 + " and n. CA and i. " + str(stored.alnAres[x]), "b = " + str(stored.alnAnb[x])) for x in range(len(stored.alnBres)): cmd.alter(objSel2 + " and n. CA and i. " + str(stored.alnBres[x]), "b = " + str(stored.alnBnb[x])) cmd.rebuild(); cmd.refresh(); cmd.sort(objSel1); cmd.sort(objSel2) # Provide some useful information stored.allRMSDval = [] stored.allRMSDval = stored.alnAnb + stored.alnBnb print "\nColorByRMSD completed successfully." print "The MINIMUM RMSD value is: "+str(min(stored.allRMSDval)) print "The MAXIMUM RMSD value is: "+str(max(stored.allRMSDval)) if doPretty!=None: # Showcase what we did cmd.orient() cmd.hide("all") cmd.show_as("cartoon", objSel1 + " or " + objSel2) # Select the residues not used for alignment; they still have their B-factors as "-10" cmd.select("notUsedForAln", "b < 0") # White-wash the residues not used for alignment cmd.color("white", "notUsedForAln") # Color the residues used for alignment according to their B-factors (RMSD values) cmd.spectrum("b", 'rainbow', "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not notUsedForAln") # Delete the selection of atoms not used for alignment # If you would like to keep this selection intact, # just comment "cmd.delete" line and # uncomment the "cmd.disable" line below. cmd.delete("notUsedForAln") # cmd.disable("notUsedForAln") print "\nObjects are now colored by C-alpha RMS deviation." print "All residues with RMSD values greater than the maximum are colored white..."
def ss(selection="(name ca and alt '',A)",state=1,_self=cmd): pymol=_self._pymol cmd=_self # NOT THREAD SAFE print ' util.ss: WARNING: This is not a "correct" secondary structure' print ' util.ss: assignment algorithm! Please use only as a last resort.' cmd.feedback("push") cmd.feedback("disable","executive","actions") ss_pref = "_sss" sss1 = ss_pref+"1" cnt = cmd.select(sss1,"((byres ("+selection+")) and name ca and not het)") print " util.ss: initiating secondary structure assignment on %d residues."%cnt cas = cmd.index(sss1) if not len(cas): return # set cartoon mode to auto over the selection cmd.cartoon("auto",sss1) print " util.ss: extracting sequence and relationships..." # get CA list res_list = [] pymol._ss = pymol.Scratch_Storage() pymol._ss.res_list = res_list cmd.iterate(sss1,'_ss.res_list.append((model,index))') # generate atom-to-residue conversion dictionaries ca_dict = {} n_dict = {} o_dict = {} scr_dict = {} # scr = segment,chain,resi pymol._ss.n_dict = n_dict pymol._ss.o_dict = o_dict pymol._ss.scr_dict = scr_dict pymol._ss.ca_dict = ca_dict cmd.iterate(sss1, '_ss.scr_dict[(model,index)]=(segi,chain,resi)') # CA's cmd.iterate("((byres "+sss1+") and n;n)" ,'_ss.scr_dict[(model,index)]=(segi,chain,resi)') # N's cmd.iterate("((byres "+sss1+") and n;o)", '_ss.scr_dict[(model,index)]=(segi,chain,resi)') # O's cmd.iterate(sss1, '_ss.ca_dict[(segi,chain,resi)] = (model,index)') cmd.iterate("((byres "+sss1+") and n;n)", '_ss.n_dict[(segi,chain,resi)] = (model,index)') cmd.iterate("((byres "+sss1+") and n;o)", '_ss.o_dict[(segi,chain,resi)] = (model,index)') scr_dict[None]=None o_dict[None]=None n_dict[None]=None ca_dict[None]=None # create special version of cas with gaps gap = [None,None,None,None] # gap large enough to distinguish i+4 interations from gaps last = None for a in res_list: if last!=None: if(cmd.count_atoms( "((neighbor(neighbor(neighbor (%s`%d)))) and (%s`%d))"% (last[0],last[1],a[0],a[1]),quiet=1)==0): gap.extend([None,None,None,None]) gap.append(a) last = a gap.extend([None,None,None,None]) print " util.ss: analyzing phi/psi angles (slow)..." # generate reverse-lookup for gap indices ss = {} c = 0 gap_idx = {} for a in gap: gap_idx[a] = c c = c + 1 # secondary structure database... ss = {} ss[None]=None # make decisions based on phi/psi for a in cas: ss[a] = 'L' # default phipsi = cmd.get_phipsi(sss1,state) for a in phipsi.keys(): (phi,psi) = phipsi[a] # print scr_dict[a],(phi,psi) if (phi!=None) and (psi!=None): if ((phi<-45) and (phi>-160) and (psi<-170) or (psi>10)): # beta? ss[a] = 's' elif ((phi<-45) and (phi>-160) and (psi>-80) and (psi<-25)): # helix? ss[a] = 'H' print " util.ss: finding hydrogen bonds..." # find all pairwise hydrogen bonds and make note of them in dict hb = cmd.find_pairs("((byres "+sss1+") and n;n)", "((byres "+sss1+") and n;o)",mode=1, cutoff=3.7,angle=55, state1=state,state2=state) hb_dict = {} # [((N-atom) (O-atom))] = 1 n_hb_dict = {} # [(N-atom)] = [(O-atom),...] o_hb_dict = {} # [(O-atom)] = [(N-atom),...] for a in hb: # cmd.dist("(%s`%d)"%a[0],"(%s`%d)"%a[1]) hb_dict[a] = 1 n = a[0] o = a[1] if not n_hb_dict.has_key(n): n_hb_dict[n]=[] if not o_hb_dict.has_key(o): o_hb_dict[o]=[] n_hb_dict[n].append(o) o_hb_dict[o].append(n) # check to insure that all helical residues have at least an i +/- 4 # hydrogen bond for c in xrange(4,len(gap)-4): a = gap[c] if ss[a]=='H': aN = n_dict[scr_dict[a]] aO = o_dict[scr_dict[a]] am4O = o_dict[scr_dict[gap[c-4]]] ap4N = n_dict[scr_dict[gap[c+4]]] if not hb_dict.has_key((aN,am4O)): if not hb_dict.has_key((ap4N,aO)): ss[a]='L' print " util.ss: verifying beta sheets..." # check to insure that all beta residues have proper interactions rep_dict = {} repeat = 1 while repeat: repeat = 0 c = 4 cc = len(gap)-4 while c<cc: a1 = gap[c] if (ss[a1] in ['s','S']) and not rep_dict.has_key(a1): rep_dict[a1] = 1 valid = 0 scr_a1 = scr_dict[a1] # look for antiparallel 2:2 H-bonds (NH-O=C + C=O-HN) n_a1_atom = n_dict[scr_a1] o_a1_atom = o_dict[scr_a1] if (n_hb_dict.has_key(n_a1_atom) and o_hb_dict.has_key(o_a1_atom)): for n_hb_atom in n_hb_dict[n_a1_atom]: for o_hb_atom in o_hb_dict[o_a1_atom]: n_hb_scr = scr_dict[n_hb_atom] o_hb_scr = scr_dict[o_hb_atom] if o_hb_scr == n_hb_scr: b1 = ca_dict[o_hb_scr] if abs(c-gap_idx[b1])>2: ss[b1] = 'S' ss[a1] = 'S' valid = 1 # look for antiparallel offset HB (i,i+2,j,j-2) a3 = gap[c+2] if (a3!=None): scr_a3 = scr_dict[a3] o_a1_atom = o_dict[scr_a1] n_a3_atom = n_dict[scr_a3] if (n_hb_dict.has_key(n_a3_atom) and o_hb_dict.has_key(o_a1_atom)): for n_hb_atom in n_hb_dict[n_a3_atom]: for o_hb_atom in o_hb_dict[o_a1_atom]: n_hb_scr = scr_dict[n_hb_atom] o_hb_scr = scr_dict[o_hb_atom] b1 = ca_dict[o_hb_scr] if b1!=None: b1_i = gap_idx[b1] if abs(c-b1_i)>2: # no turns! b3 = gap[b1_i-2] if b3!=None: b3_scr = scr_dict[b3] if b3_scr == n_hb_scr: a2 = gap[c+1] b2 = gap[gap_idx[b1]-1] ss[b1] = 'S' ss[b3] = 'S' ss[a1] = 'S' ss[a3] = 'S' if ss[a2]=='L': ss[a2] = 's' if ss[b2]=='L': ss[b2] = 's' valid = 1 # look for antiparallel offset HB (i,i-2,j,j+2) a3 = gap[c-2] if (a3!=None): scr_a3 = scr_dict[a3] n_a1_atom = n_dict[scr_a1] o_a3_atom = o_dict[scr_a3] if (n_hb_dict.has_key(n_a1_atom) and o_hb_dict.has_key(o_a3_atom)): for n_hb_atom in n_hb_dict[n_a1_atom]: for o_hb_atom in o_hb_dict[o_a3_atom]: n_hb_scr = scr_dict[n_hb_atom] o_hb_scr = scr_dict[o_hb_atom] b1 = ca_dict[o_hb_scr] if b1!=None: b1_i = gap_idx[b1] if abs(c-b1_i)>2: # no turns! b3 = gap[b1_i-2] if b3!=None: b3_scr = scr_dict[b3] if b3_scr == n_hb_scr: a2 = gap[c-1] b2 = gap[gap_idx[b1]-1] ss[b1] = 'S' ss[b3] = 'S' ss[a1] = 'S' ss[a3] = 'S' if ss[a2]=='L': ss[a2] = 's' if ss[b2]=='L': ss[b2] = 's' valid = 1 # look for parallel 1:3 HB (i,j-1,j+1) n_a1_atom = n_dict[scr_a1] o_a1_atom = o_dict[scr_a1] if (n_hb_dict.has_key(n_a1_atom) and o_hb_dict.has_key(o_a1_atom)): for n_hb_atom in n_hb_dict[n_a1_atom]: for o_hb_atom in o_hb_dict[o_a1_atom]: n_hb_scr = scr_dict[n_hb_atom] o_hb_scr = scr_dict[o_hb_atom] b0 = ca_dict[n_hb_scr] if b0!=None: b2 = gap[gap_idx[b0]+2] if b2!=None: b2_scr = scr_dict[b2] if b2_scr == o_hb_scr: b1 = gap[gap_idx[b0]+1] ss[a1] = 'S' ss[b0] = 'S' if ss[b1]=='L': ss[b1]='s' ss[b2] = 'S' valid = 1 repeat = 1 if not valid: ss[a1] = 'L' c = c + 1 # automatically fill 1 residue gaps in helices and well-defined sheets c = 4 cc = len(gap)-6 while c<cc: a1 = gap[c] a3 = gap[c+2] ss_a1 = ss[a1] ss_a3 = ss[a3] if (ss_a1==ss_a3) and (ss_a1 in ['S','H']): a2 = gap[c+1] ss[a2] = ss_a1 c = c + 1 # remove singleton sheet residues c = 4 cc = len(gap)-4 while c<cc: a0 = gap[c-1] a1 = gap[c] a2 = gap[c+1] if ss[a1] in ['s','S']: if ((not ss[a0] in ['s','S']) and (not ss[a2] in ['s','S'])): ss[a1] = 'L' c = c + 1 # remove sheet residues which aren't next to another sheet c = 4 cc = len(gap)-4 while c<cc: a1 = gap[c] if ss[a1]=='S': a1 = gap[c] scr_a1 = scr_dict[a1] # look for hydrogen bonds to another sheet n_a1_atom = n_dict[scr_a1] o_a1_atom = o_dict[scr_a1] certain = 0 if n_hb_dict.has_key(n_a1_atom): for n_hb_atom in n_hb_dict[n_a1_atom]: n_hb_ca_atom=ca_dict[scr_dict[n_hb_atom]] if ss[n_hb_ca_atom]=='S': certain = 1 break if o_hb_dict.has_key(o_a1_atom): for o_hb_atom in o_hb_dict[o_a1_atom]: o_hb_ca_atom=ca_dict[scr_dict[o_hb_atom]] if ss[o_hb_ca_atom]=='S': certain = 1 break if not certain: ss[a1] = 's' c = c + 1 # remove questionable sheet residues c = 4 cc = len(gap)-4 while c<cc: a0 = gap[c-1] a1 = gap[c] a2 = gap[c+1] if ss[a1]=='s': if (not ((ss[a0]=='S') and (ss[a2]=='S'))): ss[a1] = 'L' c = c + 1 # extend helices if hydrogen bonding requirements are met rep_dict = {} repeat = 1 while repeat: repeat = 0 c = 4 cc = len(gap)-4 while c<cc: a = gap[c] if not rep_dict.has_key(a): if ss[gap[c+1]]=='H': rep_dict[a] = 1 if ss[a]!='H': # N-terminal end aO = o_dict[scr_dict[a]] ap4N = n_dict[scr_dict[gap[c+4]]] ap3N = n_dict[scr_dict[gap[c+3]]] if hb_dict.has_key((ap4N,aO)) or hb_dict.has_key((ap3N,aO)): ss[a]='H' repeat = 1 c = c - 5 if c<4: c=4 if ss[gap[c-1]]=='H': a = gap[c] if ss[a]!='H': # C-terminal end rep_dict[a] = 1 aN = n_dict[scr_dict[a]] am4O = o_dict[scr_dict[gap[c-4]]] am3O = o_dict[scr_dict[gap[c-3]]] if hb_dict.has_key((aN,am4O)) or hb_dict.has_key((aN,am3O)): ss[a]='H' repeat = 1 c = c - 5 if c<4: c=4 c = c + 1 # remove doubleton helices c = 4 cc = len(gap)-5 while c<cc: a0 = gap[c-1] a1 = gap[c] a2 = gap[c+1] a3 = gap[c+2] ss_a0 = ss[gap[c-1]] ss_a1 = ss[gap[c]] ss_a2 = ss[gap[c+1]] ss_a3 = ss[gap[c+2]] if ss_a1=='H': if (ss_a2==ss_a1) and (ss_a0!=ss_a2) and (ss_a2!=ss_a3): ss[a1] = 'L' ss[a2] = 'L' c = c + 1 # remove totally unreasonable helix and sheet residues c = 4 cc = len(gap)-5 while c<cc: a1 = gap[c] ss_a1 = ss[gap[c]] if ss_a1=='H': if phipsi.has_key(a1): (phi,psi) = phipsi[a1] if (phi>0) and (phi<150): ss[a1] = 'L' elif((psi<-120) or (psi>140)): ss[a1] = 'L' elif ss_a1 in ['S','s']: if phipsi.has_key(a1): (phi,psi) = phipsi[a1] if (phi>45) and (phi<160): ss[a1] = 'L' # if (psi<-30) and (psi>-150): if (psi<-65) and (psi>-150): ss[a1] = 'L' c = c + 1 for x in range(1,3): # remove singleton sheet residues c = 4 cc = len(gap)-4 while c<cc: a0 = gap[c-1] a1 = gap[c] a2 = gap[c+1] if ss[a1] in ['s','S']: if ((not ss[a0] in ['s','S']) and (not ss[a2] in ['s','S'])): ss[a1] = 'L' c = c + 1 # remove sheet residues which aren't next to another sheet c = 4 cc = len(gap)-4 while c<cc: a1 = gap[c] if ss[a1]=='S': a1 = gap[c] scr_a1 = scr_dict[a1] # look for hydrogen bonds to another sheet n_a1_atom = n_dict[scr_a1] o_a1_atom = o_dict[scr_a1] certain = 0 if n_hb_dict.has_key(n_a1_atom): for n_hb_atom in n_hb_dict[n_a1_atom]: n_hb_ca_atom=ca_dict[scr_dict[n_hb_atom]] if ss[n_hb_ca_atom]=='S': certain = 1 break if o_hb_dict.has_key(o_a1_atom): for o_hb_atom in o_hb_dict[o_a1_atom]: o_hb_ca_atom=ca_dict[scr_dict[o_hb_atom]] if ss[o_hb_ca_atom]=='S': certain = 1 break if not certain: ss[a1] = 's' c = c + 1 # remove questionable sheet residues c = 4 cc = len(gap)-4 while c<cc: a0 = gap[c-1] a1 = gap[c] a2 = gap[c+1] if ss[a1]=='s': if (not ((ss[a0]=='S') and (ss[a2]=='S'))): ss[a1] = 'L' c = c + 1 # lst = ss.keys() # lst.sort() # for a in lst: print scr_dict[a],ss[a] # assign protein for a in cas: if ss[a]=='s': ss[a]='S' cmd.alter(sss1,"ss ='L'") for a in cas: if ss[a]!='L': cmd.alter("(%s`%d)"%a,"ss='%s'"%ss[a]) cmd.feedback("pop") del pymol._ss # IMPORTANT cmd.delete(sss1) cmd.rebuild(selection,'cartoon') # # print conn_hash.keys() print " util.ss: assignment complete."
def ColorByDisplacementCA(objSel1, objSel2, super1='all', super2='all', doColor="True", doAlign="True", AlignedWhite='yes'): ### First create backup copies; names starting with __ (underscores) are normally hidden by PyMOL tObj1, tObj2, aln = "__tempObj1", "__tempObj2", "__aln" if strTrue(doAlign): ### Create temp objects cmd.create( tObj1, objSel1 ) cmd.create( tObj2, objSel2 ) ### Align and make create an object aln which indicates which atoms were paired between the two structures ### Super is must faster than align http://www.pymolwiki.org/index.php/Super cmd.super(tObj1 + ' and ' + str(super1), tObj2 + ' and ' + str(super2), object=aln) ### Modify the original matrix of object1 from the alignment cmd.matrix_copy(tObj1, objSel1) else: ### Create temp objects cmd.create( tObj1, objSel1 ) cmd.create( tObj2, objSel2 ) ### Align and make create an object aln which indicates which atoms were paired between the two structures ### Super is must faster than align http://www.pymolwiki.org/index.php/Super cmd.super(tObj1 + ' and ' + str(super1), tObj2 + ' and ' + str(super2), object=aln) ### Modify the B-factor columns of the original objects, ### in order to identify the residues NOT used for alignment, later on cmd.alter( objSel1 + " or " + objSel2, "b=-0.2") cmd.alter( tObj1 + " or " + tObj2, "chain='A'") cmd.alter( tObj1 + " or " + tObj2, "segi='A'") ### Update pymol internal representations; one of these should do the trick cmd.refresh(); cmd.rebuild(); cmd.sort(tObj1); cmd.sort(tObj2) ### Create lists for storage stored.alnAres, stored.alnBres = [], [] ### Iterate over objects if AlignedWhite=='yes': cmd.iterate(tObj1 + " and n. CA and not " + aln, "stored.alnAres.append(resi)") cmd.iterate(tObj2 + " and n. CA and not " + aln, "stored.alnBres.append(resi)") else: cmd.iterate(tObj1 + " and n. CA", "stored.alnAres.append(resi)") cmd.iterate(tObj2 + " and n. CA", "stored.alnBres.append(resi)") ### Change the B-factors for EACH object displacementUpdateB(tObj1,stored.alnAres,tObj2,stored.alnBres) ### Store the NEW B-factors stored.alnAnb, stored.alnBnb = [], [] ### Iterate over objects and get b if AlignedWhite=='yes': ### Iterate over objects which is not aligned cmd.iterate(tObj1 + " and n. CA and not " + aln, "stored.alnAnb.append(b)" ) cmd.iterate(tObj2 + " and n. CA and not " + aln, "stored.alnBnb.append(b)" ) else: ### Or Iterate over all objects with CA cmd.iterate(tObj1 + " and n. CA", "stored.alnAnb.append(b)" ) cmd.iterate(tObj2 + " and n. CA", "stored.alnBnb.append(b)" ) ### Get rid of all intermediate objects and clean up cmd.delete(tObj1) cmd.delete(tObj2) cmd.delete(aln) ### Assign the just stored NEW B-factors to the original objects for x in range(len(stored.alnAres)): cmd.alter(objSel1 + " and n. CA and i. " + str(stored.alnAres[x]), "b = " + str(stored.alnAnb[x])) for x in range(len(stored.alnBres)): cmd.alter(objSel2 + " and n. CA and i. " + str(stored.alnBres[x]), "b = " + str(stored.alnBnb[x])) cmd.rebuild(); cmd.refresh(); cmd.sort(objSel1); cmd.sort(objSel2) ### Provide some useful information stored.allRMSDval = [] stored.allRMSDval = stored.alnAnb + stored.alnBnb print "\nColorByDisplacementCA completed successfully." print "The MAXIMUM Displacement is: "+str(max(stored.allRMSDval)) +" residue "+str(stored.alnAres[int(stored.allRMSDval.index(max(stored.allRMSDval)))]) if strTrue(doColor): ### Showcase what we did #cmd.orient() #cmd.hide("all") cmd.show("cartoon", objSel1 + " or " + objSel2) ### Select the residues not used for alignment; they still have their B-factors as "-0.2" cmd.select("notUsedForAln", "b = -0.2") ### White-wash the residues not used for alignment cmd.color("white", "notUsedForAln") ### Select the residues not in both pdb files; they have their B-factors as "-0. 01" cmd.select("ResNotInBothPDB", "b = -0.01") ### White-wash the residues not used for alignment cmd.color("black", "ResNotInBothPDB") ### Color the residues used for alignment according to their B-factors (Displacment values) # cmd.spectrum("b", 'rainbow', "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not notUsedForAln+ResNotInBothPDB") cmd.spectrum("b", 'rainbow', "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not (notUsedForAln or ResNotInBothPDB)") ### Delete the selection of atoms not used for alignment ### If you would like to keep this selection intact, ### just comment "cmd.delete" line and ### uncomment the "cmd.disable" line abowe. cmd.disable("notUsedForAln") cmd.delete("notUsedForAln") cmd.disable("ResNotInBothPDB") cmd.delete("ResNotInBothPDB") print "\nObjects are now colored by C-alpha displacement deviation." print "Blue is minimum and red is maximum..." print "White is those residues used in the alignment algorithm. Can be turned off in top of algorithm." print "Black is residues that does not exist in both files..."
'cmd.load("dat/nonexistent.pkl")' , 'cmd.get_names()' , 'cmd.delete("all")' , 'cmd.get_names()' , 'cmd.get_model("nonexistent")' , 'cmd.space("cmyk")', 'cmd.space("unknown")', 'cmd.space("rgb")', 'cmd.space()', ]) cmd.delete("all") cmd.load("dat/pept.pdb") mdl = cmd.get_model("pept") print mdl.__class__ print len(mdl.atom) mdl = cmd.get_model("none") print mdl.__class__ print len(mdl.atom) map( x, [ 'cmd.get_model("nonexistent")', 'cmd.create("test","none",quiet=0)', 'cmd.create("test2","nonexistent")', 'cmd.create("test3","?allowed",quiet=0)', 'cmd.fragment("arg")',