def build(object_name, sequence, first_residue="1"): if len(sequence): code = sequence[0] cmd.fragment(aa_dict[code], object_name) cmd.alter(object_name, 'resi="%s"' % first_residue) cmd.edit(object_name + " and name C") for code in sequence[1:]: editor.attach_amino_acid("pk1", aa_dict[code]) cmd.edit()
def build(object_name, sequence, first_residue = "1"): if len(sequence): code = sequence[0] cmd.fragment(aa_dict[code],object_name) cmd.alter(object_name,'resi="%s"'%first_residue) cmd.edit(object_name+" and name C") for code in sequence[1:]: editor.attach_amino_acid("pk1",aa_dict[code]) cmd.edit()
def create_new(self): names = self.cmd.get_names("objects") num = 1 while 1: name = "obj%02d"%num if name not in names: break num = num + 1 editor.attach_amino_acid("pk1", self.aminoAcid, object=name, _self=self.cmd) if not self.getRepeating(): self.actionWizardDone()
def build_epz1_h(): """Build epz1_h (epz1 with XL domains in alpha-helix)""" cmd._alt('B'.lower()) # N-terminal actyl group build_HP(0) build_XL(1) build_HP(0) build_XL(1) build_HP(0) editor.attach_amino_acid('pk1', 'nhh') cmd.save('/home/zyxue/labwork/pdb_backup/lele/epz1_h.pdb')
def attach(self, aa): picked = collectPicked(self.cmd) if len(picked)==1: try: with undocontext(self.cmd, "bymol %s" % picked[0]): editor.attach_amino_acid(picked[0], aa, _self=self.cmd) except: fin = -1 self.doZoom() else: self.cmd.unpick() AminoAcidWizard(_self=self.cmd).toggle(aa)
def attach(self, aa): picked = collectPicked(self.cmd) if len(picked)==1: try: with undocontext(self.cmd, "bymol %s" % picked[0]): editor.attach_amino_acid(picked[0], aa, ss=self.ss_cbox.currentIndex() + 1, _self=self.cmd) except: fin = -1 self.doZoom() else: self.cmd.unpick() AminoAcidWizard(_self=self.cmd).toggle(aa)
def do_pick(self, bondFlag): # since this function can change any position of atoms in a related # molecule, bymol is used if self.mode == 0: self.cmd.select(active_sele, "bymol pk1") try: with undocontext(self.cmd, "bymol ?pk1"): editor.attach_amino_acid("pk1", self.aminoAcid, _self=self.cmd) except QuietException: fin = -1 elif self.mode == 1: self.cmd.select(active_sele, "bymol pk1") editor.combine_fragment("pk1", self.aminoAcid, 0, 1, _self=self.cmd) self.mode = 0 self.cmd.refresh_wizard() self.cmd.unpick() if not self.getRepeating(): self.actionWizardDone()
def createPeptide(seqInfo): cmd.delete("all") # Creates residue TWO editor.attach_amino_acid('pk1', seqInfo[1][0]) # Creates residue ONE createSS('resi 2', sequence=seqInfo[0][0], terminal='N') print "found sequence info for number of residues: ", len(seqInfo) for i in range(2, len(seqInfo)): # resn is the residue number of the new residue resn = i + 1 print "Adding residue: ", resn, seqInfo[i][0] # Note that the previous residue is numbered i. resi = 'resi ' + repr(i) createSS(resi, sequence=seqInfo[i][0]) # j=0 #unused parameter to test pydev extension abilities for i in range(len(seqInfo)): resi = 'resi ' + repr(i + 1) # print "Setting backbone angles for residue: ", (i+1), seqInfo[i][0],seqInfo[i][1],seqInfo[i][2] set_phipsi(resi, seqInfo[i][1], seqInfo[i][2])
def createPeptide(seqInfo): cmd.delete("all") # Creates residue TWO editor.attach_amino_acid('pk1',seqInfo[1][0]) # Creates residue ONE createSS('resi 2', sequence=seqInfo[0][0],terminal='N') print "found sequence info for number of residues: ", len(seqInfo) for i in range(2,len(seqInfo) ): # resn is the residue number of the new residue resn = i + 1 print "Adding residue: ", resn, seqInfo[i][0] # Note that the previous residue is numbered i. resi = 'resi '+repr(i) createSS(resi, sequence=seqInfo[i][0]) # j=0 #unused parameter to test pydev extension abilities for i in range( len(seqInfo) ): resi = 'resi '+repr(i+1) # print "Setting backbone angles for residue: ", (i+1), seqInfo[i][0],seqInfo[i][1],seqInfo[i][2] set_phipsi(resi,seqInfo[i][1],seqInfo[i][2])
def createSS(sel, sequence='ALA', repeat=1, terminal='C'): # Set selection selection = "%s and name %s" % (sel, terminal) # Pick atom for editing - interestingly only need to do this for the first addition cmd.edit(selection, None, None, None, pkresi=0, pkbond=0) # Array of residues seq = string.split(sequence, ",") # Get residue numbering .. potential bug here if number is inconsistent.. (Only works at c-terminal) # resi = int(cmd.get_model(sel).atom[0].resi) + 1 # Loop and build new residues for i in range(1, repeat + 1): for s in seq: print "residue[%i]: %s %s" % (i, s, terminal) editor.attach_amino_acid('pk1', s) # Remove extra OXT carboxylate atom (OXT1, OXT2 ?) .. fix as needed if terminal == 'C': cmd.remove("%s and name OXT" % sel)
def createSS(sel, sequence='ALA',repeat=1,terminal='C'): # Set selection selection = "%s and name %s" % (sel,terminal) # Pick atom for editing - interestingly only need to do this for the first addition cmd.edit(selection,None,None,None,pkresi=0,pkbond=0) # Array of residues seq = string.split(sequence,",") # Get residue numbering .. potential bug here if number is inconsistent.. (Only works at c-terminal) # resi = int(cmd.get_model(sel).atom[0].resi) + 1 # Loop and build new residues for i in range(1,repeat+1): for s in seq: print "residue[%i]: %s %s" % (i,s,terminal) editor.attach_amino_acid('pk1',s) # Remove extra OXT carboxylate atom (OXT1, OXT2 ?) .. fix as needed if terminal == 'C': cmd.remove("%s and name OXT" % sel)
def do_library(self): cmd=self.cmd pymol=cmd._pymol if not ((cmd.count_atoms("(%s) and name N"%src_sele)==1) and (cmd.count_atoms("(%s) and name C"%src_sele)==1) and (cmd.count_atoms("(%s) and name O"%src_sele)==1)): self.clear() return 1 cmd.feedback("push") cmd.feedback("disable","selector","everythin") cmd.feedback("disable","editor","actions") self.prompt = [ 'Loading rotamers...'] self.bump_scores = [] state_best = 0 pymol.stored.name = 'residue' cmd.iterate("first (%s)"%src_sele,'stored.name=model+"/"+segi+"/"+chain+"/"+resn+"`"+resi') self.res_text = pymol.stored.name cmd.select("_seeker_hilight",src_sele) auto_zoom = cmd.get_setting_text('auto_zoom') cmd.set('auto_zoom',"0",quiet=1) cmd.frame(0) cmd.delete(frag_name) if self.auto_center: cmd.center(src_sele,animate=-1) self.lib_mode = self.mode if self.lib_mode=="current": pymol.stored.resn="" cmd.iterate("(%s & name CA)"%src_sele,"stored.resn=resn") rot_type = _rot_type_xref.get(pymol.stored.resn,pymol.stored.resn) if (self.c_cap!='none') or (self.n_cap!='none') or (self.hyd != 'auto'): self.lib_mode = rot_type # force fragment-based load else: cmd.create(frag_name,src_sele,1,1) if self.c_cap=='open': cmd.remove("%s and name OXT"%frag_name) if self.lib_mode!='current': rot_type = self.lib_mode frag_type = self.lib_mode if (self.n_cap == 'posi') and (frag_type[0:3]!='NT_'): if not ( cmd.count_atoms( "elem C & !(%s) & (bto. (name N & (%s))) &! resn ACE"% (src_sele,src_sele))): # use N-terminal fragment frag_type ="NT_"+frag_type if (self.c_cap == 'nega') and (frag_type[0:3]!='CT_'): if not ( cmd.count_atoms("elem N & !(%s) & (bto. (name C & (%s))) & !resn NME+NHH"% (src_sele,src_sele))): # use C-terminal fragment frag_type ="CT_"+frag_type if rot_type[0:3] in [ 'NT_', 'CT_' ]: rot_type = rot_type[3:] rot_type = _rot_type_xref.get(rot_type, rot_type) cmd.fragment(frag_type.lower(), frag_name, origin=0) # trim off hydrogens if (self.hyd == 'none'): cmd.remove("("+frag_name+" and hydro)") elif (self.hyd == 'auto'): if cmd.count_atoms("("+src_sele+") and hydro")==0: cmd.remove("("+frag_name+" and hydro)") # copy identifying information cmd.alter("?%s & name CA" % src_sele, "stored.identifiers = (segi, chain, resi, ss, color)", space=self.space) cmd.alter("?%s" % frag_name, "(segi, chain, resi, ss) = stored.identifiers[:4]", space=self.space) # move the fragment if ((cmd.count_atoms("(%s & name CB)"%frag_name)==1) and (cmd.count_atoms("(%s & name CB)"%src_sele)==1)): cmd.pair_fit("(%s & name CA)"%frag_name, "(%s & name CA)"%src_sele, "(%s & name CB)"%frag_name, "(%s & name CB)"%src_sele, "(%s & name C)"%frag_name, "(%s & name C)"%src_sele, "(%s & name N)"%frag_name, "(%s & name N)"%src_sele) else: cmd.pair_fit("(%s & name CA)"%frag_name, "(%s & name CA)"%src_sele, "(%s & name C)"%frag_name, "(%s & name C)"%src_sele, "(%s & name N)"%frag_name, "(%s & name N)"%src_sele) # fix the carbonyl position... cmd.iterate_state(1,"(%s & name O)"%src_sele,"stored.list=[x,y,z]") cmd.alter_state(1,"(%s & name O)"%frag_name,"(x,y,z)=stored.list") if cmd.count_atoms("(%s & name OXT)"%src_sele): cmd.iterate_state(1,"(%s & name OXT)"%src_sele,"stored.list=[x,y,z]") cmd.alter_state(1,"(%s & name OXT)"%frag_name,"(x,y,z)=stored.list") elif cmd.count_atoms("(%s & name OXT)"%frag_name): # place OXT if no template exists angle = cmd.get_dihedral("(%s & name N)"%frag_name, "(%s & name CA)"%frag_name, "(%s & name C)"%frag_name, "(%s & name O)"%frag_name) cmd.protect("(%s & name O)"%frag_name) cmd.set_dihedral("(%s & name N)"%frag_name, "(%s & name CA)"%frag_name, "(%s & name C)"%frag_name, "(%s & name OXT)"%frag_name,180.0+angle) cmd.deprotect(frag_name) # fix the hydrogen position (if any) if cmd.count_atoms("(hydro and bound_to (name N & (%s)))"%frag_name)==1: if cmd.count_atoms("(hydro and bound_to (name N & (%s)))"%src_sele)==1: cmd.iterate_state(1,"(hydro and bound_to (name N & (%s)))"%src_sele, "stored.list=[x,y,z]") cmd.alter_state(1,"(hydro and bound_to (name N & (%s)))"%frag_name, "(x,y,z)=stored.list") elif cmd.select(tmp_sele1,"(name C & bound_to (%s and elem N))"%src_sele)==1: # position hydro based on location of the carbonyl angle = cmd.get_dihedral("(%s & name C)"%frag_name, "(%s & name CA)"%frag_name, "(%s & name N)"%frag_name, tmp_sele1) cmd.set_dihedral("(%s & name C)"%frag_name, "(%s & name CA)"%frag_name, "(%s & name N)"%frag_name, "(%s & name H)"%frag_name,180.0+angle) cmd.delete(tmp_sele1) # add c-cap (if appropriate) if self.c_cap in [ 'amin', 'nmet' ]: if not cmd.count_atoms("elem N & !(%s) & (bto. (name C & (%s))) & !resn NME+NHH"% (src_sele,src_sele)): if cmd.count_atoms("name C & (%s)"%(frag_name))==1: if self.c_cap == 'amin': editor.attach_amino_acid("name C & (%s)"%(frag_name), 'nhh') elif self.c_cap == 'nmet': editor.attach_amino_acid("name C & (%s)"%(frag_name), 'nme') if cmd.count_atoms("hydro & bound_to (name N & bound_to (name C & (%s)))"%frag_name): cmd.h_fix("name N & bound_to (name C & (%s))"%frag_name) # trim hydrogens if (self.hyd == 'none'): cmd.remove("("+frag_name+" and hydro)") elif (self.hyd == 'auto'): if cmd.count_atoms("("+src_sele+") and hydro")==0: cmd.remove("("+frag_name+" and hydro)") # add n-cap (if appropriate) if self.n_cap in [ 'acet' ]: if not cmd.count_atoms("elem C & !(%s) & (bto. (name N & (%s))) & !resn ACE "% (src_sele,src_sele)): if cmd.count_atoms("name N & (%s)"%(frag_name))==1: if self.n_cap == 'acet': editor.attach_amino_acid("name N & (%s)"%(frag_name), 'ace') if cmd.count_atoms("hydro & bound_to (name N & bound_to (name C & (%s)))"%frag_name): cmd.h_fix("name N & (%s)"%frag_name) # trim hydrogens if (self.hyd == 'none'): cmd.remove("("+frag_name+" and hydro)") elif (self.hyd == 'auto'): if cmd.count_atoms("("+src_sele+") and hydro")==0: cmd.remove("("+frag_name+" and hydro)") cartoon = (cmd.count_atoms("(%s & name CA & rep cartoon)"%src_sele)>0) sticks = (cmd.count_atoms("(%s & name CA & rep sticks)"%src_sele)>0) cmd.delete(obj_name) key = rot_type lib = None if self.dep == 'dep': try: result = cmd.phi_psi("%s"%src_sele) if len(result)==1: (phi,psi) = list(result.values())[0] (phi,psi) = (int(10*round(phi/10)),int(10*(round(psi/10)))) key = (rot_type,phi,psi) if key not in self.dep_library: (phi,psi) = (int(20*round(phi/20)),int(20*(round(psi/20)))) key = (rot_type,phi,psi) if key not in self.dep_library: (phi,psi) = (int(60*round(phi/60)),int(60*(round(psi/60)))) key = (rot_type,phi,psi) lib = self.dep_library.get(key,None) except: pass if lib is None: key = rot_type lib = self.ind_library.get(key,None) if (lib is not None) and self.dep == 'dep': print(' Mutagenesis: no phi/psi, using backbone-independent rotamers.') if lib is not None: state = 1 for a in lib: cmd.create(obj_name,frag_name,1,state) if state == 1: cmd.select(mut_sele,"(byres (%s like %s))"%(obj_name,src_sele)) if rot_type=='PRO': cmd.unbond("(%s & name N)"%mut_sele,"(%s & name CD)"%mut_sele) for b in a.keys(): if b!='FREQ': cmd.set_dihedral("(%s & n;%s)"%(mut_sele,b[0]), "(%s & n;%s)"%(mut_sele,b[1]), "(%s & n;%s)"%(mut_sele,b[2]), "(%s & n;%s)"%(mut_sele,b[3]), a[b],state=state) else: cmd.set_title(obj_name,state,"%1.1f%%"%(a[b]*100)) if rot_type=='PRO': cmd.bond("(%s & name N)"%mut_sele,"(%s & name CD)"%mut_sele) state = state + 1 cmd.delete(frag_name) print(" Mutagenesis: %d rotamers loaded."%len(lib)) if self.bump_check: cmd.delete(bump_name) cmd.create(bump_name, "(((byobj %s) within 6 of (%s and not name N+C+CA+O+H+HA)) and (not (%s)))|(%s)"% (src_sele,mut_sele,src_sele,mut_sele),singletons=1) cmd.color("gray50",bump_name+" and elem C") cmd.set("seq_view",0,bump_name,quiet=1) cmd.hide("everything",bump_name) if ((cmd.select(tmp_sele1, "(name N & (%s in (neighbor %s)))"% (bump_name,src_sele)) == 1) and (cmd.select(tmp_sele2, "(name C & (%s in %s))"% (bump_name,mut_sele)) == 1)): cmd.bond(tmp_sele1,tmp_sele2) if ((cmd.select(tmp_sele1,"(name C & (%s in (neighbor %s)))"% (bump_name,src_sele)) == 1) and (cmd.select(tmp_sele2,"(name N & (%s in %s))"% (bump_name,mut_sele)) == 1)): cmd.bond(tmp_sele1,tmp_sele2) cmd.delete(tmp_sele1) cmd.delete(tmp_sele2) cmd.protect("%s and not (%s in (%s and not name N+C+CA+O+H+HA))"% (bump_name,bump_name,mut_sele)) cmd.sculpt_activate(bump_name) cmd.show("cgo",bump_name) # draw the bumps cmd.set("sculpt_vdw_vis_mode",1,bump_name) state = 1 score_best = 1e6 for a in lib: score = cmd.sculpt_iterate(bump_name, state, 1) self.bump_scores.append(score) if score < score_best: state_best = state score_best = score state = state + 1 cmd.delete(mut_sele) else: cmd.create(obj_name,frag_name,1,1) print(" Mutagenesis: no rotamers found in library.") cmd.set("seq_view",0,obj_name,quiet=1) pymol.util.cbaw(obj_name) cmd.hide("("+obj_name+")") cmd.show(self.rep,obj_name) cmd.show('lines',obj_name) #neighbor always show lines if cartoon: cmd.show("cartoon",obj_name) if sticks: cmd.show("sticks",obj_name) cmd.set('auto_zoom',auto_zoom,quiet=1) cmd.delete(frag_name) cmd.frame(state_best) cmd.unpick() cmd.feedback("pop")
def do_library(self): cmd=self.cmd pymol=cmd._pymol if not ((cmd.count_atoms("(%s) and name N"%src_sele)==1) and (cmd.count_atoms("(%s) and name C"%src_sele)==1) and (cmd.count_atoms("(%s) and name O"%src_sele)==1)): self.clear() return 1 cmd.feedback("push") cmd.feedback("disable","selector","everythin") cmd.feedback("disable","editor","actions") self.prompt = [ 'Loading rotamers...'] self.bump_scores = [] state_best = 0 pymol.stored.name = 'residue' cmd.iterate("first (%s)"%src_sele,'stored.name=model+"/"+segi+"/"+chain+"/"+resn+"`"+resi') self.res_text = pymol.stored.name cmd.select("_seeker_hilight",src_sele) auto_zoom = cmd.get_setting_text('auto_zoom') cmd.set('auto_zoom',"0",quiet=1) cmd.frame(0) cmd.delete(frag_name) if self.auto_center: cmd.center(src_sele,animate=-1) self.lib_mode = self.mode if self.lib_mode=="current": pymol.stored.resn="" cmd.iterate("(%s & name CA)"%src_sele,"stored.resn=resn") rot_type = _rot_type_xref.get(pymol.stored.resn,pymol.stored.resn) if (self.c_cap!='none') or (self.n_cap!='none') or (self.hyd != 'auto'): self.lib_mode = rot_type # force fragment-based load else: cmd.create(frag_name,src_sele,1,1) if self.c_cap=='open': cmd.remove("%s and name OXT"%frag_name) if self.lib_mode!='current': rot_type = self.lib_mode frag_type = self.lib_mode if (self.n_cap == 'posi') and (frag_type[0:3]!='NT_'): if not ( cmd.count_atoms( "elem C & !(%s) & (bto. (name N & (%s))) &! resn ACE"% (src_sele,src_sele))): # use N-terminal fragment frag_type ="NT_"+frag_type if (self.c_cap == 'nega') and (frag_type[0:3]!='CT_'): if not ( cmd.count_atoms("elem N & !(%s) & (bto. (name C & (%s))) & !resn NME+NHH"% (src_sele,src_sele))): # use C-terminal fragment frag_type ="CT_"+frag_type if rot_type[0:3] in [ 'NT_', 'CT_' ]: rot_type = rot_type[3:] rot_type = _rot_type_xref.get(rot_type, rot_type) cmd.fragment(frag_type.lower(), frag_name, origin=0) # trim off hydrogens if (self.hyd == 'none'): cmd.remove("("+frag_name+" and hydro)") elif (self.hyd == 'auto'): if cmd.count_atoms("("+src_sele+") and hydro")==0: cmd.remove("("+frag_name+" and hydro)") # copy identifying information cmd.alter("?%s & name CA" % src_sele, "stored.identifiers = (segi, chain, resi, ss, color)", space=self.space) cmd.alter("?%s" % frag_name, "(segi, chain, resi, ss) = stored.identifiers[:4]", space=self.space) # move the fragment if ((cmd.count_atoms("(%s & name CB)"%frag_name)==1) and (cmd.count_atoms("(%s & name CB)"%src_sele)==1)): cmd.pair_fit("(%s & name CA)"%frag_name, "(%s & name CA)"%src_sele, "(%s & name CB)"%frag_name, "(%s & name CB)"%src_sele, "(%s & name C)"%frag_name, "(%s & name C)"%src_sele, "(%s & name N)"%frag_name, "(%s & name N)"%src_sele) else: cmd.pair_fit("(%s & name CA)"%frag_name, "(%s & name CA)"%src_sele, "(%s & name C)"%frag_name, "(%s & name C)"%src_sele, "(%s & name N)"%frag_name, "(%s & name N)"%src_sele) # fix the carbonyl position... cmd.iterate_state(1,"(%s & name O)"%src_sele,"stored.list=[x,y,z]") cmd.alter_state(1,"(%s & name O)"%frag_name,"(x,y,z)=stored.list") if cmd.count_atoms("(%s & name OXT)"%src_sele): cmd.iterate_state(1,"(%s & name OXT)"%src_sele,"stored.list=[x,y,z]") cmd.alter_state(1,"(%s & name OXT)"%frag_name,"(x,y,z)=stored.list") elif cmd.count_atoms("(%s & name OXT)"%frag_name): # place OXT if no template exists angle = cmd.get_dihedral("(%s & name N)"%frag_name, "(%s & name CA)"%frag_name, "(%s & name C)"%frag_name, "(%s & name O)"%frag_name) cmd.protect("(%s & name O)"%frag_name) cmd.set_dihedral("(%s & name N)"%frag_name, "(%s & name CA)"%frag_name, "(%s & name C)"%frag_name, "(%s & name OXT)"%frag_name,180.0+angle) cmd.deprotect(frag_name) # fix the hydrogen position (if any) if cmd.count_atoms("(hydro and bound_to (name N & (%s)))"%frag_name)==1: if cmd.count_atoms("(hydro and bound_to (name N & (%s)))"%src_sele)==1: cmd.iterate_state(1,"(hydro and bound_to (name N & (%s)))"%src_sele, "stored.list=[x,y,z]") cmd.alter_state(1,"(hydro and bound_to (name N & (%s)))"%frag_name, "(x,y,z)=stored.list") elif cmd.select(tmp_sele1,"(name C & bound_to (%s and elem N))"%src_sele)==1: # position hydro based on location of the carbonyl angle = cmd.get_dihedral("(%s & name C)"%frag_name, "(%s & name CA)"%frag_name, "(%s & name N)"%frag_name, tmp_sele1) cmd.set_dihedral("(%s & name C)"%frag_name, "(%s & name CA)"%frag_name, "(%s & name N)"%frag_name, "(%s & name H)"%frag_name,180.0+angle) cmd.delete(tmp_sele1) # add c-cap (if appropriate) if self.c_cap in [ 'amin', 'nmet' ]: if not cmd.count_atoms("elem N & !(%s) & (bto. (name C & (%s))) & !resn NME+NHH"% (src_sele,src_sele)): if cmd.count_atoms("name C & (%s)"%(frag_name))==1: if self.c_cap == 'amin': editor.attach_amino_acid("name C & (%s)"%(frag_name), 'nhh') elif self.c_cap == 'nmet': editor.attach_amino_acid("name C & (%s)"%(frag_name), 'nme') if cmd.count_atoms("hydro & bound_to (name N & bound_to (name C & (%s)))"%frag_name): cmd.h_fix("name N & bound_to (name C & (%s))"%frag_name) # trim hydrogens if (self.hyd == 'none'): cmd.remove("("+frag_name+" and hydro)") elif (self.hyd == 'auto'): if cmd.count_atoms("("+src_sele+") and hydro")==0: cmd.remove("("+frag_name+" and hydro)") # add n-cap (if appropriate) if self.n_cap in [ 'acet' ]: if not cmd.count_atoms("elem C & !(%s) & (bto. (name N & (%s))) & !resn ACE "% (src_sele,src_sele)): if cmd.count_atoms("name N & (%s)"%(frag_name))==1: if self.n_cap == 'acet': editor.attach_amino_acid("name N & (%s)"%(frag_name), 'ace') if cmd.count_atoms("hydro & bound_to (name N & bound_to (name C & (%s)))"%frag_name): cmd.h_fix("name N & (%s)"%frag_name) # trim hydrogens if (self.hyd == 'none'): cmd.remove("("+frag_name+" and hydro)") elif (self.hyd == 'auto'): if cmd.count_atoms("("+src_sele+") and hydro")==0: cmd.remove("("+frag_name+" and hydro)") cartoon = (cmd.count_atoms("(%s & name CA & rep cartoon)"%src_sele)>0) sticks = (cmd.count_atoms("(%s & name CA & rep sticks)"%src_sele)>0) cmd.delete(obj_name) key = rot_type lib = None if self.dep == 'dep': try: result = cmd.phi_psi("%s"%src_sele) if len(result)==1: (phi,psi) = list(result.values())[0] (phi,psi) = (int(10*round(phi/10)),int(10*(round(psi/10)))) key = (rot_type,phi,psi) if key not in self.dep_library: (phi,psi) = (int(20*round(phi/20)),int(20*(round(psi/20)))) key = (rot_type,phi,psi) if key not in self.dep_library: (phi,psi) = (int(60*round(phi/60)),int(60*(round(psi/60)))) key = (rot_type,phi,psi) lib = self.dep_library.get(key,None) except: pass if lib == None: key = rot_type lib = self.ind_library.get(key,None) if (lib!= None) and self.dep == 'dep': print(' Mutagenesis: no phi/psi, using backbone-independent rotamers.') if lib != None: state = 1 for a in lib: cmd.create(obj_name,frag_name,1,state) if state == 1: cmd.select(mut_sele,"(byres (%s like %s))"%(obj_name,src_sele)) if rot_type=='PRO': cmd.unbond("(%s & name N)"%mut_sele,"(%s & name CD)"%mut_sele) for b in a.keys(): if b!='FREQ': cmd.set_dihedral("(%s & n;%s)"%(mut_sele,b[0]), "(%s & n;%s)"%(mut_sele,b[1]), "(%s & n;%s)"%(mut_sele,b[2]), "(%s & n;%s)"%(mut_sele,b[3]), a[b],state=state) else: cmd.set_title(obj_name,state,"%1.1f%%"%(a[b]*100)) if rot_type=='PRO': cmd.bond("(%s & name N)"%mut_sele,"(%s & name CD)"%mut_sele) state = state + 1 cmd.delete(frag_name) print(" Mutagenesis: %d rotamers loaded."%len(lib)) if self.bump_check: cmd.delete(bump_name) cmd.create(bump_name, "(((byobj %s) within 6 of (%s and not name N+C+CA+O+H+HA)) and (not (%s)))|(%s)"% (src_sele,mut_sele,src_sele,mut_sele),singletons=1) cmd.color("gray50",bump_name+" and elem C") cmd.set("seq_view",0,bump_name,quiet=1) cmd.hide("everything",bump_name) if ((cmd.select(tmp_sele1, "(name N & (%s in (neighbor %s)))"% (bump_name,src_sele)) == 1) and (cmd.select(tmp_sele2, "(name C & (%s in %s))"% (bump_name,mut_sele)) == 1)): cmd.bond(tmp_sele1,tmp_sele2) if ((cmd.select(tmp_sele1,"(name C & (%s in (neighbor %s)))"% (bump_name,src_sele)) == 1) and (cmd.select(tmp_sele2,"(name N & (%s in %s))"% (bump_name,mut_sele)) == 1)): cmd.bond(tmp_sele1,tmp_sele2) cmd.delete(tmp_sele1) cmd.delete(tmp_sele2) cmd.protect("%s and not (%s in (%s and not name N+C+CA+O+H+HA))"% (bump_name,bump_name,mut_sele)) cmd.sculpt_activate(bump_name) cmd.show("cgo",bump_name) # draw the bumps cmd.set("sculpt_vdw_vis_mode",1,bump_name) state = 1 score_best = 1e6 for a in lib: score = cmd.sculpt_iterate(bump_name, state, 1) self.bump_scores.append(score) if score < score_best: state_best = state score_best = score state = state + 1 cmd.delete(mut_sele) else: cmd.create(obj_name,frag_name,1,1) print(" Mutagenesis: no rotamers found in library.") cmd.set("seq_view",0,obj_name,quiet=1) pymol.util.cbaw(obj_name) cmd.hide("("+obj_name+")") cmd.show(self.rep,obj_name) cmd.show('lines',obj_name) #neighbor always show lines if cartoon: cmd.show("cartoon",obj_name) if sticks: cmd.show("sticks",obj_name) cmd.set('auto_zoom',auto_zoom,quiet=1) cmd.delete(frag_name) cmd.frame(state_best) cmd.unpick() cmd.feedback("pop")
def attach_monomer(self, objectname=""): editor.attach_amino_acid("?pk1", self.aminoAcid, object=objectname, ss=self._secondary_structure, _self=self.cmd)
def do_library(self): cmd = self.cmd pymol = cmd._pymol if not ( (cmd.count_atoms("(%s) and name n" % src_sele) == 1) and (cmd.count_atoms("(%s) and name c" % src_sele) == 1) and (cmd.count_atoms("(%s) and name o" % src_sele) == 1) ): self.clear() return 1 cmd.feedback("push") cmd.feedback("disable", "selector", "everythin") cmd.feedback("disable", "editor", "actions") self.prompt = ["Loading rotamers..."] pymol.stored.name = "residue" cmd.iterate("first (%s)" % src_sele, 'stored.name=model+"/"+segi+"/"+chain+"/"+resn+"`"+resi') self.res_text = pymol.stored.name cmd.select("_seeker_hilight", src_sele) auto_zoom = cmd.get_setting_text("auto_zoom") cmd.set("auto_zoom", "0", quiet=1) cmd.frame(0) cmd.delete(frag_name) if self.auto_center: cmd.center(src_sele, animate=-1) self.lib_mode = self.mode if self.lib_mode == "current": pymol.stored.resn = "" cmd.iterate("(%s and n;ca)" % src_sele, "stored.resn=resn") rot_type = _rot_type_xref.get(pymol.stored.resn, pymol.stored.resn) if (self.c_cap != "none") or (self.n_cap != "none") or (self.hyd != "auto"): self.lib_mode = rot_type # force fragment-based load else: cmd.create(frag_name, src_sele, 1, 1) if self.c_cap == "open": cmd.remove("%s and name OXT" % frag_name) if self.lib_mode != "current": rot_type = self.lib_mode frag_type = self.lib_mode if (self.n_cap == "posi") and (frag_type[0:3] != "NT_"): if not (cmd.count_atoms("elem c & !(%s) & (bto. (n;n & (%s))) &! r. ace" % (src_sele, src_sele))): # use N-terminal fragment frag_type = "NT_" + frag_type if (self.c_cap == "nega") and (frag_type[0:3] != "CT_"): if not (cmd.count_atoms("elem n & !(%s) & (bto. (n;c & (%s))) & !r. nme+nhh" % (src_sele, src_sele))): # use C-terminal fragment frag_type = "CT_" + frag_type if rot_type[0:3] in ["NT_", "CT_"]: rot_type = rot_type[3:] rot_type = _rot_type_xref.get(rot_type, rot_type) cmd.fragment(string.lower(frag_type), frag_name) # trim off hydrogens if self.hyd == "none": cmd.remove("(" + frag_name + " and hydro)") elif self.hyd == "auto": if cmd.count_atoms("(" + src_sele + ") and hydro") == 0: cmd.remove("(" + frag_name + " and hydro)") # copy identifying information cmd.iterate("(%s and n;ca)" % src_sele, "stored.chain=chain") cmd.alter("(%s)" % frag_name, "chain=stored.chain") cmd.iterate("(%s and n;ca)" % src_sele, "stored.resi=resi") cmd.alter("(%s)" % frag_name, "resi=stored.resi") cmd.iterate("(%s and n;ca)" % src_sele, "stored.segi=segi") cmd.alter("(%s)" % frag_name, "segi=stored.segi") cmd.iterate("(%s and n;ca)" % src_sele, "stored.ss=ss") cmd.alter("(%s)" % frag_name, "ss=stored.ss") # move the fragment if (cmd.count_atoms("(%s and n;cb)" % frag_name) == 1) and ( cmd.count_atoms("(%s and n;cb)" % src_sele) == 1 ): cmd.pair_fit( "(%s and n;ca)" % frag_name, "(%s and n;ca)" % src_sele, "(%s and n;cb)" % frag_name, "(%s and n;cb)" % src_sele, "(%s and n;c)" % frag_name, "(%s and n;c)" % src_sele, "(%s and n;n)" % frag_name, "(%s and n;n)" % src_sele, ) else: cmd.pair_fit( "(%s and n;ca)" % frag_name, "(%s and n;ca)" % src_sele, "(%s and n;c)" % frag_name, "(%s and n;c)" % src_sele, "(%s and n;n)" % frag_name, "(%s and n;n)" % src_sele, ) # fix the carbonyl position... cmd.iterate_state(1, "(%s and n;o)" % src_sele, "stored.list=[x,y,z]") cmd.alter_state(1, "(%s and n;o)" % frag_name, "(x,y,z)=stored.list") if cmd.count_atoms("(%s and n;oxt)" % src_sele): cmd.iterate_state(1, "(%s and n;oxt)" % src_sele, "stored.list=[x,y,z]") cmd.alter_state(1, "(%s and n;oxt)" % frag_name, "(x,y,z)=stored.list") elif cmd.count_atoms("(%s and n;oxt)" % frag_name): # place OXT if no template exists angle = cmd.get_dihedral( "(%s and n;n)" % frag_name, "(%s and n;ca)" % frag_name, "(%s and n;c)" % frag_name, "(%s and n;o)" % frag_name, ) cmd.protect("(%s and n;o)" % frag_name) cmd.set_dihedral( "(%s and n;n)" % frag_name, "(%s and n;ca)" % frag_name, "(%s and n;c)" % frag_name, "(%s and n;oxt)" % frag_name, 180.0 + angle, ) cmd.deprotect(frag_name) # fix the hydrogen position (if any) if cmd.count_atoms("(elem h and bound_to (n;n and (%s)))" % frag_name) == 1: if cmd.count_atoms("(elem h and bound_to (n;n and (%s)))" % src_sele) == 1: cmd.iterate_state(1, "(elem h and bound_to (n;n and (%s)))" % src_sele, "stored.list=[x,y,z]") cmd.alter_state(1, "(elem h and bound_to (n;n and (%s)))" % frag_name, "(x,y,z)=stored.list") elif cmd.select(tmp_sele1, "(n;c and bound_to (%s and e;n))" % src_sele) == 1: # position hydro based on location of the carbonyl angle = cmd.get_dihedral( "(%s and n;c)" % frag_name, "(%s and n;ca)" % frag_name, "(%s and n;n)" % frag_name, tmp_sele1 ) cmd.set_dihedral( "(%s and n;c)" % frag_name, "(%s and n;ca)" % frag_name, "(%s and n;n)" % frag_name, "(%s and n;h)" % frag_name, 180.0 + angle, ) cmd.delete(tmp_sele1) # add c-cap (if appropriate) if self.c_cap in ["amin", "nmet"]: if not cmd.count_atoms("elem n & !(%s) & (bto. (n;c & (%s))) & !r. nme+nhh" % (src_sele, src_sele)): if cmd.count_atoms("n;c & (%s)" % (frag_name)) == 1: if self.c_cap == "amin": editor.attach_amino_acid("n;c & (%s)" % (frag_name), "nhh") elif self.c_cap == "nmet": editor.attach_amino_acid("n;c & (%s)" % (frag_name), "nme") if cmd.count_atoms("hydro & bound_to (n;n & bound_to (n;c & (%s)))" % frag_name): cmd.h_fix("n;n & bound_to (n;c & (%s))" % frag_name) # trim hydrogens if self.hyd == "none": cmd.remove("(" + frag_name + " and hydro)") elif self.hyd == "auto": if cmd.count_atoms("(" + src_sele + ") and hydro") == 0: cmd.remove("(" + frag_name + " and hydro)") # add n-cap (if appropriate) if self.n_cap in ["acet"]: if not cmd.count_atoms("elem c & !(%s) & (bto. (n;n & (%s))) & !r. ace " % (src_sele, src_sele)): if cmd.count_atoms("n;n & (%s)" % (frag_name)) == 1: if self.n_cap == "acet": editor.attach_amino_acid("n;n & (%s)" % (frag_name), "ace") if cmd.count_atoms("hydro & bound_to (n;n & bound_to (n;c & (%s)))" % frag_name): cmd.h_fix("n;n & (%s)" % frag_name) # trim hydrogens if self.hyd == "none": cmd.remove("(" + frag_name + " and hydro)") elif self.hyd == "auto": if cmd.count_atoms("(" + src_sele + ") and hydro") == 0: cmd.remove("(" + frag_name + " and hydro)") cartoon = cmd.count_atoms("(%s and n;ca and rep cartoon)" % src_sele) > 0 sticks = cmd.count_atoms("(%s and n;ca and rep sticks)" % src_sele) > 0 cmd.delete(obj_name) key = rot_type lib = None if self.dep == "dep": try: result = cmd.phi_psi("%s" % src_sele) if len(result) == 1: (phi, psi) = result[result.keys()[0]] (phi, psi) = (int(10 * round(phi / 10)), int(10 * (round(psi / 10)))) key = (rot_type, phi, psi) if not self.dep_library.has_key(key): (phi, psi) = (int(20 * round(phi / 20)), int(20 * (round(psi / 20)))) key = (rot_type, phi, psi) if not self.dep_library.has_key(key): (phi, psi) = (int(60 * round(phi / 60)), int(60 * (round(psi / 60)))) key = (rot_type, phi, psi) lib = self.dep_library.get(key, None) except: pass if lib == None: key = rot_type lib = self.ind_library.get(key, None) if (lib != None) and self.dep == "dep": print " Mutagenesis: no phi/psi, using backbone-independent rotamers." if lib != None: state = 1 for a in lib: cmd.create(obj_name, frag_name, 1, state) if state == 1: cmd.select(mut_sele, "(byres (%s like %s))" % (obj_name, src_sele)) if rot_type == "PRO": cmd.unbond("(%s & name N)" % mut_sele, "(%s & name CD)" % mut_sele) for b in a.keys(): if b != "FREQ": cmd.set_dihedral( "(%s & n;%s)" % (mut_sele, b[0]), "(%s & n;%s)" % (mut_sele, b[1]), "(%s & n;%s)" % (mut_sele, b[2]), "(%s & n;%s)" % (mut_sele, b[3]), a[b], state=state, ) else: cmd.set_title(obj_name, state, "%1.1f%%" % (a[b] * 100)) if rot_type == "PRO": cmd.bond("(%s & name N)" % mut_sele, "(%s & name CD)" % mut_sele) state = state + 1 cmd.delete(frag_name) print " Mutagenesis: %d rotamers loaded." % len(lib) if self.bump_check: cmd.delete(bump_name) cmd.create( bump_name, "(((byobj %s) within 6 of (%s and not name n+c+ca+o+h+ha)) and (not (%s)))|(%s)" % (src_sele, mut_sele, src_sele, mut_sele), singletons=1, ) cmd.color("gray50", bump_name + " and elem c") cmd.set("seq_view", 0, bump_name, quiet=1) cmd.hide("everything", bump_name) if (cmd.select(tmp_sele1, "(n;N and (%s in (neighbor %s)))" % (bump_name, src_sele)) == 1) and ( cmd.select(tmp_sele2, "(n;C and (%s in %s))" % (bump_name, mut_sele)) == 1 ): cmd.bond(tmp_sele1, tmp_sele2) if (cmd.select(tmp_sele1, "(n;C and (%s in (neighbor %s)))" % (bump_name, src_sele)) == 1) and ( cmd.select(tmp_sele2, "(n;N and (%s in %s))" % (bump_name, mut_sele)) == 1 ): cmd.bond(tmp_sele1, tmp_sele2) cmd.delete(tmp_sele1) cmd.delete(tmp_sele2) cmd.protect("%s and not (%s in (%s and not name n+c+ca+o+h+ha))" % (bump_name, bump_name, mut_sele)) cmd.sculpt_activate(bump_name) cmd.show("cgo", bump_name) # draw the bumps cmd.set("sculpt_vdw_vis_mode", 1, bump_name) state = 1 for a in lib: cmd.sculpt_iterate(bump_name, state=state) state = state + 1 cmd.delete(mut_sele) else: cmd.create(obj_name, frag_name, 1, 1) print " Mutagenesis: no rotamers found in library." cmd.set("seq_view", 0, obj_name, quiet=1) pymol.util.cbaw(obj_name) cmd.hide("(" + obj_name + ")") cmd.show(self.rep, obj_name) cmd.show("lines", obj_name) # neighbor always show lines if cartoon: cmd.show("cartoon", obj_name) if sticks: cmd.show("sticks", obj_name) cmd.set("auto_zoom", auto_zoom, quiet=1) cmd.delete(frag_name) cmd.frame(0) cmd.unpick() cmd.feedback("pop")
#!/usr/bin/env python from pymol import editor, cmd cmd.load('singlechain.pdb') editor.attach_amino_acid("last name C", 'nme') editor.attach_amino_acid("first name N", 'ace') cmd.set('pdb_use_ter_records',0) cmd.save('cappedchain.pdb')