Exemple #1
0
 def do_select(self, name):
     # "edit" only this atom, and not others with the object prefix
     try:
         cmd.edit("%s and not %s*" % (name, self.object_prefix))
         self.do_pick(0)
     except pymol.CmdException as pmce:
         print(pmce)
 def do_select(self, name):
     # "edit" only this atom, and not others with the object prefix
     try:
         cmd.edit("%s and not %s*" % (name, self.object_prefix))
         self.do_pick(0)
     except pymol.CmdException, pmce:
         print pmce
Exemple #3
0
 def test_attach(self):
     cmd.pseudoatom()
     cmd.edit('first all')
     cmd.attach('C', 1, 1)
     self.assertEqual(2, cmd.count_atoms())
     cmd.attach('C', 1, 1)
     self.assertEqual(3, cmd.count_atoms())
     self.assertEqual(['C01', 'C02', 'PS1'], sorted(get_atom_names()))
Exemple #4
0
    def testAutoMeasure(self):
        cmd.fragment("gly")

        for (N, prefix) in enumerate(["dist", "angle", "dihedral"], 2):
            cmd.set("dist_counter", 0)
            cmd.edit(*["index %d" % (i + 1) for i in range(N)])
            cmd.auto_measure()
            self.assertTrue(prefix + "01" in cmd.get_names(), prefix)
Exemple #5
0
 def test_attach(self):
     cmd.pseudoatom()
     cmd.edit('first all')
     cmd.attach('C', 1, 1)
     self.assertEqual(2, cmd.count_atoms())
     cmd.attach('C', 1, 1)
     self.assertEqual(3, cmd.count_atoms())
     self.assertEqual(['C01', 'C02', 'PS1'], sorted(get_atom_names()))
Exemple #6
0
 def test_invert(self):
     cmd.fragment('ala')
     xyzfix = get_coord_list('ID 1-7')
     xyzmov = get_coord_list('ID 0+8+9')
     cmd.edit('ID 1', 'ID 2', 'ID 3')
     cmd.invert()
     self.assertEqual(xyzfix, get_coord_list('ID 1-7'))
     self.assertNotEqual(xyzmov, get_coord_list('ID 0+8+9'))
Exemple #7
0
 def do_select(self, name):
     # "edit" only this atom, and not others with the object prefix
     try:
         cmd.edit("{:s} and not {:s}*".format(name, self.object_prefix))
         self.do_pick(0)
     except CmdException:
         showerror(self.parent, "Error", "Selection Error!")
         self.reset()
Exemple #8
0
 def test_invert(self):
     cmd.fragment('ala')
     xyzfix = get_coord_list('ID 1-7')
     xyzmov = get_coord_list('ID 0+8+9')
     cmd.edit('ID 1', 'ID 2', 'ID 3')
     cmd.invert()
     self.assertEqual(xyzfix, get_coord_list('ID 1-7'))
     self.assertNotEqual(xyzmov, get_coord_list('ID 0+8+9'))
Exemple #9
0
 def test_torsion(self):
     cmd.fragment('ala')
     delta = 10
     atoms = ('ID 7', 'ID 2', 'ID 1', 'ID 9')
     d1 = cmd.get_dihedral(*atoms)
     cmd.edit(*atoms[1:3])
     cmd.torsion(delta)
     d2 = cmd.get_dihedral(*atoms)
     self.assertAlmostEqual(d1 + delta, d2, 4)
Exemple #10
0
 def do_select(self,name): # map selects into picks
     cmd.unpick()
     try:
         cmd.edit(name + " and not " + sele_prefix + "*") # note, using new object name wildcards
         cmd.delete(name)
         self.do_pick(0)
     except pymol.CmdException:
         traceback.print_exc()
         pass
Exemple #11
0
 def test_torsion(self):
     cmd.fragment('ala')
     delta = 10
     atoms = ('ID 7', 'ID 2', 'ID 1', 'ID 9')
     d1 = cmd.get_dihedral(*atoms)
     cmd.edit(*atoms[1:3])
     cmd.torsion(delta)
     d2 = cmd.get_dihedral(*atoms)
     self.assertAlmostEqual(d1 + delta, d2, 4)
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()
Exemple #13
0
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 do_select(self, name):  # map selects into picks
     cmd.unpick()
     try:
         cmd.edit(name + " and not " + sele_prefix +
                  "*")  # note, using new object name wildcards
         cmd.delete(name)
         self.do_pick(0)
     except pymol.CmdException:
         traceback.print_exc()
         pass
Exemple #15
0
 def test_replace(self):
     # NOTES:
     # - doc says "Immature functionality"
     # - will not preserve ID
     # - will not re-add hydrogens with h_fill=1
     cmd.fragment('ala')
     cmd.edit('elem O')
     cmd.replace('S', 0, 0, 0)
     self.assertEqual(0, cmd.count_atoms('elem O'))
     self.assertEqual(1, cmd.count_atoms('elem S'))
    def test(self):
        if cmd.get_setting_int('suspend_undo'):
            self.skipTest("need suspend_undo=0")

        cmd.fragment('gly', 'm1')
        cmd.create('m2', 'm1')
        cmd.edit('m1 & name N')
        cmd.replace('I', 1, 1)
        self.assertEqual(cmd.count_atoms('m1 in m2'), 5)
        cmd.undo()
        self.assertEqual(cmd.count_atoms('m1 in m2'), 7)
Exemple #17
0
    def test(self):
        if cmd.get_setting_int('suspend_undo'):
            self.skipTest("need suspend_undo=0")

        cmd.fragment('gly', 'm1')
        cmd.create('m2', 'm1')
        cmd.edit('m1 & name N')
        cmd.replace('I', 1, 1)
        self.assertEqual(cmd.count_atoms('m1 in m2'), 5)
        cmd.undo()
        self.assertEqual(cmd.count_atoms('m1 in m2'), 7)
Exemple #18
0
    def test_cycle_valence(self):
        cmd.fragment('gly')
        cmd.edit('ID 0', 'ID 1')

        cmd.cycle_valence()
        self.assertEqual(4, cmd.get_model('pkbond').bond[0].order)

        cmd.cycle_valence()
        self.assertEqual(2, cmd.get_model('pkbond').bond[0].order)

        cmd.cycle_valence()
        self.assertEqual(3, cmd.get_model('pkbond').bond[0].order)
Exemple #19
0
    def test_cycle_valence(self):
        cmd.fragment('gly')
        cmd.edit('ID 0', 'ID 1')

        cmd.cycle_valence()
        self.assertEqual(4, cmd.get_model('pkbond').bond[0].order)

        cmd.cycle_valence()
        self.assertEqual(2, cmd.get_model('pkbond').bond[0].order)

        cmd.cycle_valence()
        self.assertEqual(3, cmd.get_model('pkbond').bond[0].order)
Exemple #20
0
 def test_replace(self):
     # NOTES:
     # - doc says "Immature functionality"
     # - will not preserve ID
     # - will not re-add hydrogens with h_fill=1
     cmd.fragment('ala')
     cmd.edit('elem O')
     cmd.replace('S', 0, 0, 0)
     self.assertEqual(0, cmd.count_atoms('elem O'))
     self.assertEqual(1, cmd.count_atoms('elem S'))
     self.assertEqual(1, cmd.count_atoms('name S01'))
     self.assertEqual(0, cmd.count_atoms('name S02'))
     cmd.edit('elem N')
     cmd.replace('S', 0, 0, 0)
     self.assertEqual(2, cmd.count_atoms('elem S'))
     self.assertEqual(1, cmd.count_atoms('name S02'))
Exemple #21
0
def missing_c_termini(selection="(all)",quiet=0,_self=cmd):
    cmd=_self
    # assumes that hydogens are not present!
    
    sele_list = []
    ch=Champ()
    model = cmd.get_model(selection)
    model_pat = ch.insert_model(model)
    assn_pat = ch.insert_pattern_string("[N+0+1]C[C;D2]<0>(=O)")
    ch.pattern_clear_tags(model_pat)
    if ch.match_1v1_n(assn_pat,model_pat,10000,2)>0:
        result = ch.pattern_get_ext_indices_with_tags(model_pat)
        for atom_tag in result[0]: # just iterate over atom tags
            if len(atom_tag[1])==1: # one and only one match
                if atom_tag[1][0]==0:
                    sele_list.append(atom_tag[0])
    cmd.select_list(tmp_sele1,selection,sele_list, mode='index')
    while cmd.pop(tmp_sele2,tmp_sele1)>0: # complete the carboxy terminus
        cmd.edit(tmp_sele2)
        cmd.attach("O",1,1,"OXT",quiet=1)
        cmd.unpick()
    cmd.delete(tmp_sele1)
Exemple #22
0
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)
Exemple #23
0
def missing_c_termini(selection="(all)", quiet=0, _self=cmd):
    cmd = _self
    # assumes that hydogens are not present!

    sele_list = []
    ch = Champ()
    model = cmd.get_model(selection)
    model_pat = ch.insert_model(model)
    assn_pat = ch.insert_pattern_string("[N+0+1]C[C;D2]<0>(=O)")
    ch.pattern_clear_tags(model_pat)
    if ch.match_1v1_n(assn_pat, model_pat, 10000, 2) > 0:
        result = ch.pattern_get_ext_indices_with_tags(model_pat)
        for atom_tag in result[0]:  # just iterate over atom tags
            if len(atom_tag[1]) == 1:  # one and only one match
                if atom_tag[1][0] == 0:
                    sele_list.append(atom_tag[0])
    cmd.select_list(tmp_sele1, selection, sele_list, mode='index')
    while cmd.pop(tmp_sele2, tmp_sele1) > 0:  # complete the carboxy terminus
        cmd.edit(tmp_sele2)
        cmd.attach("O", 1, 1, "OXT", quiet=1)
        cmd.unpick()
    cmd.delete(tmp_sele1)
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)
Exemple #25
0
def find_torsions(res_sele):
   # this routine gets a list of atom ids which correspond to the
   # free torsions in the sidechain
   res_sele = "("+res_sele+")"
   if cmd.count_atoms("(%s and n;N,CA)"%res_sele,quiet=1)<2:
      return []
   result = []
   done = 0
   # set up the starting trunk
   cmd.select("trunk","(%s and n;N,CA,C,O)"%res_sele)
   first_id = cmd.identify("(%s and n;N)"%res_sele)[0]
   second_id = cmd.identify("(%s and n;CA)"%res_sele)[0]
   to_do_list = [(first_id,second_id)]
   while len(to_do_list):
      (first_id,second_id) = to_do_list.pop(0)
      # find candidates for the 3rd atom in the dihedral
      cmd.select("candi","(%s and (neighbor trunk))"%res_sele)
      pymol.stored.list = []
      cmd.iterate("candi","stored.list.append((name,ID))")
      candi_list = pymol.stored.list
      if len(candi_list):
         # we may have a dihedral
         dihe_list = []
         for a in candi_list:
            if cmd.select("termi","(%s and (not trunk) and (neighbor id %d))"%
                          (res_sele,a[1]))>0:
               # apparently we do, but is it acyclic
               # (i.e., can edit split the molecule?)
               cmd.edit("(%s and trunk and (neighbor id %d))"%(res_sele,a[1]),
                        "(%s and id %d)"%(res_sele,a[1]))
               if 'pkfrag2' in cmd.get_names('selections'):
                  # yes, so this is a valid dihedral
                  dihe_list.append(a)
               else:
                  # no, so add the third atom to the trunk
                  cmd.select("trunk","(trunk or (%s and id %d))"%(res_sele,a[1]))                  
            else:
               # no fourth atom, so add this atom to the trunk
               cmd.select("trunk","(trunk or (%s and id %d))"%(res_sele,a[1]))
         if len(dihe_list):
            # choose 3rd atom using alphanumeric order
            dihe_list.sort()
            third_id = dihe_list[0][1]
            # if there is another third atom, then repeat later      
            if len(dihe_list)>1: 
               to_do_list.insert(0,(first_id,second_id))
            # now choose the 4th atom, which we know exists, using a similar criterion
            cmd.select("termi","(%s and (not trunk) and (neighbor id %d))"%
                       (res_sele,third_id))
            pymol.stored.list=[]
            cmd.iterate("termi","stored.list.append((name,ID))")
            termi_list = pymol.stored.list
            termi_list.sort()
            fourth_id = termi_list[0][1]
            # at this point, we should have a complete dihedral
            # add the third atom into the trunk, and store the second and third for
            # outward extension later on
            to_do_list.append((second_id,third_id))
            cmd.select("trunk","(trunk or (%s and id %d))"%(res_sele,third_id))      
#            cmd.show('sticks','(%s and (id %d,%d,%d,%d))'%
#                     (res_sele,first_id,second_id,third_id,fourth_id))
            result.append((first_id,second_id,third_id,fourth_id))
   return result
Exemple #26
0
import sys
from pymol import cmd

protein = sys.argv[1]  # PDB file
outfile = sys.argv[2]  # Outfile

cmd.load(protein, 'Protein')
chains = cmd.get_chains('Protein')
N_res = len(cmd.get_fastastr("chain A").split('\n')[1])

for n in range(len(chains)):
    cmd.select('AA', '/Protein//' + chains[n] + '/1/N')
    cmd.edit('AA')
    cmd.editor.attach_amino_acid("pk1", 'ace')
    cmd.unpick()
    cmd.select('AA', '/Protein//' + chains[n] + '/' + str(N_res) + '/C')
    cmd.edit('AA')
    cmd.editor.attach_amino_acid("pk1", 'nhh')
    cmd.unpick()

# Rename NHH to NH2 (GROMACS format)
cmd.select("NH2s", "resn NHH")
cmd.alter("NH2s", "resn='NH2'")
cmd.delete("NH2s")

cmd.save(outfile, 'Protein')
Exemple #27
0
 def test_remove_picked(self, hydro, count):
     cmd.fragment('ala')
     cmd.edit('ID 1', 'ID 2', 'ID 3')
     cmd.remove_picked(hydro)
     self.assertEqual(count, cmd.count_atoms())
Exemple #28
0
def find_torsions(res_sele):
   # this routine gets a list of atom ids which correspond to the
   # free torsions in the sidechain
   res_sele = "("+res_sele+")"
   if cmd.count_atoms("(%s and n;N,CA)"%res_sele,quiet=1)<2:
      return []
   result = []
   done = 0
   # set up the starting trunk
   cmd.select("trunk","(%s and n;N,CA,C,O)"%res_sele)
   first_id = cmd.identify("(%s and n;N)"%res_sele)[0]
   second_id = cmd.identify("(%s and n;CA)"%res_sele)[0]
   to_do_list = [(first_id,second_id)]
   while len(to_do_list):
      (first_id,second_id) = to_do_list.pop(0)
      # find candidates for the 3rd atom in the dihedral
      cmd.select("candi","(%s and (neighbor trunk))"%res_sele)
      pymol.stored.list = []
      cmd.iterate("candi","stored.list.append((name,ID))")
      candi_list = pymol.stored.list
      if len(candi_list):
         # we may have a dihedral
         dihe_list = []
         for a in candi_list:
            if cmd.select("termi","(%s and (not trunk) and (neighbor id %d))"%
                          (res_sele,a[1]))>0:
               # apparently we do, but is it acyclic
               # (i.e., can edit split the molecule?)
               cmd.edit("(%s and trunk and (neighbor id %d))"%(res_sele,a[1]),
                        "(%s and id %d)"%(res_sele,a[1]))
               if 'pkfrag2' in cmd.get_names('selections'):
                  # yes, so this is a valid dihedral
                  dihe_list.append(a)
               else:
                  # no, so add the third atom to the trunk
                  cmd.select("trunk","(trunk or (%s and id %d))"%(res_sele,a[1]))                  
            else:
               # no fourth atom, so add this atom to the trunk
               cmd.select("trunk","(trunk or (%s and id %d))"%(res_sele,a[1]))
         if len(dihe_list):
            # choose 3rd atom using alphanumeric order
            dihe_list.sort()
            third_id = dihe_list[0][1]
            # if there is another third atom, then repeat later      
            if len(dihe_list)>1: 
               to_do_list.insert(0,(first_id,second_id))
            # now choose the 4th atom, which we know exists, using a similar criterion
            cmd.select("termi","(%s and (not trunk) and (neighbor id %d))"%
                       (res_sele,third_id))
            pymol.stored.list=[]
            cmd.iterate("termi","stored.list.append((name,ID))")
            termi_list = pymol.stored.list
            termi_list.sort()
            fourth_id = termi_list[0][1]
            # at this point, we should have a complete dihedral
            # add the third atom into the trunk, and store the second and third for
            # outward extension later on
            to_do_list.append((second_id,third_id))
            cmd.select("trunk","(trunk or (%s and id %d))"%(res_sele,third_id))      
#            cmd.show('sticks','(%s and (id %d,%d,%d,%d))'%
#                     (res_sele,first_id,second_id,third_id,fourth_id))
            result.append((first_id,second_id,third_id,fourth_id))
   return result
Exemple #29
0
def attach_amino_acid(selection,amino_acid,phi,psi):
  if not selection in cmd.get_names("selections"):
    if amino_acid in cmd.get_names("objects"):
      print " Error: an object with than name already exists"
      raise QuietException
    cmd.fragment(amino_acid)
    if cmd.get_setting_legacy("auto_remove_hydrogens"):
      cmd.remove("(hydro and %s)"%amino_acid)
    if cmd.count_atoms("((%s) and name c)"%amino_acid,quiet=1):
      cmd.edit("((%s) and name c)"%amino_acid)
  else:
    cmd.fragment(amino_acid,tmp_editor)
    if cmd.count_atoms("((%s) and elem n)"%selection,quiet=1):
      cmd.select(tmp_ed_save,"(%s)"%selection)
      cmd.iterate("(%s)"%selection,"stored.resv=resv")
      stored.resi = str(stored.resv-1)
      cmd.alter(tmp_editor,"resi=stored.resi")
      cmd.fuse("(%s and name C)"%(tmp_editor),"(pk1)",2)
      if cmd.get_setting_legacy("auto_remove_hydrogens"):
        cmd.remove("(pkmol and hydro)")
      cmd.set_dihedral("(name ca and neighbor pk2)",
                            "(pk2)","(pk1)","(name ca,ch3 and neighbor pk1)",180.0)
      cmd.set_geometry("pk2",3,3) # make nitrogen planer
#      if ss:
      cmd.select(tpk1,"pk2")
      cmd.select(tpk2,"pk1")
      if amino_acid[0:3]!='pro':
        cmd.set_dihedral( # PHI
            "(name c and neighbor (name ca and neighbor "+tpk1+"))", # C
            "(name ca and neighbor "+tpk1+")", # CA 
            tpk1, # N
            tpk2, # C
            phi)
      cmd.set_dihedral( # PSI (n-1)
          tpk1, # N
          tpk2, # C
          "(name ca and neighbor "+tpk2+")", # CA
          "(name n and neighbor (name ca and neighbor "+tpk2+"))", # C
          psi)
      cmd.delete(tpk1)
      cmd.delete(tpk2)
      sele = ("(name N and (byres neighbor %s) and not (byres %s))"%
                (tmp_ed_save,tmp_ed_save))
      if cmd.count_atoms(sele,quiet=1):
        cmd.edit(sele)
      cmd.delete(tmp_ed_save)

    elif cmd.count_atoms("((%s) and elem c)"%selection,quiet=1):
      cmd.select(tmp_ed_save,"(%s)"%selection)
      cmd.iterate("(%s)"%selection,"stored.resv=resv")
      stored.resi = str(stored.resv+1)
      cmd.alter(tmp_editor,"resi=stored.resi")
      cmd.fuse("(%s and name N)"%(tmp_editor),"(pk1)",2)
      if cmd.get_setting_legacy("auto_remove_hydrogens"):
        cmd.remove("(pkmol and hydro)")
      cmd.set_dihedral("(name ca and neighbor pk2)",
                            "(pk2)","(pk1)","(name ca,ch3 and neighbor pk1)",180.0)
      cmd.set_geometry("pk1",3,3) # make nitrogen planer
#      if ss:
      cmd.select(tpk1,"pk1")
      cmd.select(tpk2,"pk2")
      if amino_acid[0:3]!='pro':
        cmd.set_dihedral( # PHI
            tpk2, # C
            tpk1, # N
            "(name ca and neighbor "+tpk1+")", # CA 
            "(name c and neighbor (name ca and neighbor "+tpk1+"))", # C
            phi)
      cmd.set_dihedral( # PSI (n-1)
          "(name n and neighbor (name ca and neighbor "+tpk2+"))", # C
          "(name ca and neighbor "+tpk2+")", # CA
          tpk2, # C
          tpk1, # N
          psi)
      cmd.delete(tpk1)
      cmd.delete(tpk2)
      sele = ("(name C and (byres neighbor %s) and not (byres %s))"%
                (tmp_ed_save,tmp_ed_save))
      if cmd.count_atoms(sele,quiet=1):
        cmd.edit(sele)
      cmd.delete(tmp_ed_save)
    elif cmd.count_atoms("((%s) and elem h)"%selection,quiet=1):
      print " Error: please pick a nitrogen or carbonyl carbon to grow from."
      cmd.delete(tmp_editor)
      raise QuietException

  cmd.delete(tmp_editor)
Exemple #30
0
 def test_edit(self):
     cmd.fragment('gly')
     cmd.edit('ID 0', 'ID 1', 'ID 2', 'ID 3')
     names = cmd.get_names('public_selections')
     self.assertEqual(names, ['pk1', 'pk2', 'pk3', 'pk4', 'pkset', 'pkmol'])
Exemple #31
0
 def test_unpick(self):
     cmd.pseudoatom('m1')
     cmd.edit('m1')
     cmd.unpick()
     self.assertTrue('pk1' not in cmd.get_names('selections'))
Exemple #32
0
def attach_amino_acid(selection,amino_acid,phi,psi):
  if not selection in cmd.get_names("selections"):
    if amino_acid in cmd.get_names("objects"):
      print " Error: an object with than name already exists"
      raise QuietException
    cmd.fragment(amino_acid)
    if cmd.get_setting_legacy("auto_remove_hydrogens"):
      cmd.remove("(hydro and %s)"%amino_acid)
    if cmd.count_atoms("((%s) and name c)"%amino_acid,quiet=1):
      cmd.edit("((%s) and name c)"%amino_acid)
  else:
    cmd.fragment(amino_acid,tmp_editor)
    if cmd.count_atoms("((%s) and elem n)"%selection,quiet=1):
      cmd.select(tmp_ed_save,"(%s)"%selection)
      cmd.iterate("(%s)"%selection,"stored.resv=resv")
      stored.resi = str(stored.resv-1)
      cmd.alter(tmp_editor,"resi=stored.resi")
      cmd.fuse("(%s and name C)"%(tmp_editor),"(pk1)",2)
      if cmd.get_setting_legacy("auto_remove_hydrogens"):
        cmd.remove("(pkmol and hydro)")
      cmd.set_dihedral("(name ca and neighbor pk2)",
                            "(pk2)","(pk1)","(name ca,ch3 and neighbor pk1)",180.0)
      cmd.set_geometry("pk2",3,3) # make nitrogen planer
      cmd.select(tpk1,"pk2")
      cmd.select(tpk2,"pk1")
      if amino_acid[0:3]!='pro':
        cmd.set_dihedral( # PHI
            "(name c and neighbor (name ca and neighbor "+tpk1+"))", # C
            "(name ca and neighbor "+tpk1+")", # CA 
            tpk1, # N
            tpk2, # C
            phi)
      cmd.set_dihedral( # PSI (n-1)
          tpk1, # N
          tpk2, # C
          "(name ca and neighbor "+tpk2+")", # CA
          "(name n and neighbor (name ca and neighbor "+tpk2+"))", # C
          psi)
      cmd.delete(tpk1)
      cmd.delete(tpk2)
      sele = ("(name N and (byres neighbor %s) and not (byres %s))"%
                (tmp_ed_save,tmp_ed_save))
      if cmd.count_atoms(sele,quiet=1):
        cmd.edit(sele)
      cmd.delete(tmp_ed_save)
                
    elif cmd.count_atoms("((%s) and elem c)"%selection,quiet=1):
      cmd.select(tmp_ed_save,"(%s)"%selection)
      cmd.iterate("(%s)"%selection,"stored.resv=resv")
      stored.resi = str(stored.resv+1)
      cmd.alter(tmp_editor,"resi=stored.resi")
      cmd.fuse("(%s and name N)"%(tmp_editor),"(pk1)",2)
      if cmd.get_setting_legacy("auto_remove_hydrogens"):
        cmd.remove("(pkmol and hydro)")
      cmd.set_dihedral("(name ca and neighbor pk2)",
                            "(pk2)","(pk1)","(name ca,ch3 and neighbor pk1)",180.0)
      cmd.set_geometry("pk1",3,3) # make nitrogen planar
      cmd.select(tpk1,"pk1")
      cmd.select(tpk2,"pk2")
      if amino_acid[0:3]!='pro':
        cmd.set_dihedral( # PHI
            tpk2, # C
            tpk1, # N
            "(name ca and neighbor "+tpk1+")", # CA 
            "(name c and neighbor (name ca and neighbor "+tpk1+"))", # C
            phi)
      cmd.set_dihedral( # PSI (n-1)
          "(name n and neighbor (name ca and neighbor "+tpk2+"))", # C
          "(name ca and neighbor "+tpk2+")", # CA
          tpk2, # C
          tpk1, # N
          psi)
      cmd.delete(tpk1)
      cmd.delete(tpk2)
      sele = ("(name C and (byres neighbor %s) and not (byres %s))"%
                (tmp_ed_save,tmp_ed_save))
      if cmd.count_atoms(sele,quiet=1):
        cmd.edit(sele)
      cmd.delete(tmp_ed_save)
    elif cmd.count_atoms("((%s) and elem h)"%selection,quiet=1):
      print " Error: please pick a nitrogen or carbonyl carbon to grow from."
      cmd.delete(tmp_editor)
      raise QuietException
  
  cmd.delete(tmp_editor)
Exemple #33
0
 def do_select(self,name): # map selects into picks
     cmd.unpick()
     cmd.edit(name)
     cmd.delete(name)
     self.do_pick(0)
Exemple #34
0
 def test_remove_picked(self, hydro, count):
     cmd.fragment('ala')
     cmd.edit('ID 1', 'ID 2', 'ID 3')
     cmd.remove_picked(hydro)
     self.assertEqual(count, cmd.count_atoms())
Exemple #35
0
def frag(state=state, obj=obj):

    pwd, mutations, orig_sequence = setup(obj)

    # Add and retain hydrogens
    cmd.get_wizard().set_hyd("keep")

    # Run over all sites where to mutate
    for site in mutations.keys():

        variants = mutations[site]

        # Run over all variants.
        for variant in variants:

            cmd.load(obj)

            cmd.do("wizard mutagenesis")
            cmd.do("refresh_wizard")
            cmd.get_wizard().set_mode(variant)
            cmd.get_wizard().do_select(site + "/")

            # Get the number of available rotamers at that site
            # Introduce a condition here to check if
            # rotamers are requested.
            # <<OPTION>>
            # nRots = getRots(site, variant)
            # if nRots > 3:
            #    nRots = 3
            nRots = 1

            cmd.rewind()
            for i in range(1, nRots + 1):

                cmd.get_wizard().do_select("(" + site + "/)")
                cmd.frame(i)
                cmd.get_wizard().apply()

                # Optimize the mutated sidechain
                # <<OPTION>>
                # print "Sculpting."
                # localSculpt(obj, site)

                # Protonation of the N.
                cmd.do("select n%d, name n and %d/" % (int(site), int(site)))
                cmd.edit("n%d" % int(site), None, None, None, pkresi=0, pkbond=0)
                cmd.do("h_fill")

                # Protonation of the C.
                cmd.do("select c%d, name c and %d/" % (int(site), int(site)))
                cmd.edit("c%d" % int(site), None, None, None, pkresi=0, pkbond=0)
                cmd.do("h_fill")

                # Definition of saveString
                # saveString  = '%s/' % pwd
                # saveString += 'frag-' + getOne(orig_sequence[site]).lower() +\
                #               site + getOne(variant).lower() + '-%s.pdb, ' % state +\
                #               '((%s/))' % site
                saveStringRot = "%s/" % pwd
                saveStringRot += (
                    "frag-"
                    + getOne(orig_sequence[site]).lower()
                    + site
                    + getOne(variant).lower()
                    + "-%02d-%s.pdb, " % (i, state)
                    + "((%s/))" % site
                )
                # print saveString
                # cmd.do('save %s' % saveString.lower())
                cmd.do("save %s" % saveStringRot.lower())
            cmd.do("delete all")
            cmd.set_wizard("done")
Exemple #36
0
 def test_h_fill(self):
     cmd.fragment('gly')
     cmd.edit('elem N')
     cmd.h_fill()
     self.assertEqual(4, cmd.count_atoms('hydro'))
Exemple #37
0
    # Set Phi dihedral angle of ARG-32 to alpha-helix
    res0 = 32
    atom1 = "/MyProtein//" + chn + "/" + str(res0 - 1) + "/C"
    atom2 = "/MyProtein//" + chn + "/" + str(res0) + "/N"
    atom3 = "/MyProtein//" + chn + "/" + str(res0) + "/CA"
    atom4 = "/MyProtein//" + chn + "/" + str(res0) + "/C"

    cmd.set_dihedral(atom1, atom2, atom3, atom4, -60)

    # Add missing residues to C-termini on ARG-376
    # NOTE: Amidate C-termini by default. For the last residue, we need a N to set Psi
    # So, this is why we cap peptides from the beginning

    cmd.select("MyAA", "/MyProtein//" + chn + "/THR`32/C")
    cmd.edit("MyAA")

    for aa in to_build:
        cmd.editor.attach_amino_acid("pk1", aa)
    cmd.unpick()

    # Set dihedral angles fo new residues to alpha-helix
    for res0 in range(32, 35):
        atom1 = "/MyProtein//" + chn + "/" + str(res0 - 1) + "/C"
        atom2 = "/MyProtein//" + chn + "/" + str(res0) + "/N"
        atom3 = "/MyProtein//" + chn + "/" + str(res0) + "/CA"
        atom4 = "/MyProtein//" + chn + "/" + str(res0) + "/C"
        atom5 = "/MyProtein//" + chn + "/" + str(res0 + 1) + "/N"
        # 	# Set (Phi,Psi) dihedral angles per residue, respectively
        cmd.set_dihedral(atom1, atom2, atom3, atom4, -60)
        cmd.set_dihedral(atom2, atom3, atom4, atom5, -45)
Exemple #38
0
 def test_h_fill(self):
     cmd.fragment('gly')
     cmd.edit('elem N')
     cmd.h_fill()
     self.assertEqual(4, cmd.count_atoms('hydro'))
Exemple #39
0
 def test_unpick(self):
     cmd.pseudoatom('m1')
     cmd.edit('m1')
     cmd.unpick()
     self.assertTrue('pk1' not in cmd.get_names('selections'))
Exemple #40
0
 def test_edit(self):
     cmd.fragment('gly')
     cmd.edit('ID 0', 'ID 1', 'ID 2','ID 3')
     names = cmd.get_names('public_selections')
     self.assertEqual(names, ['pk1', 'pk2', 'pk3', 'pk4', 'pkset', 'pkmol'])
 def do_select(self, name):  # map selects into picks
     cmd.unpick()
     cmd.edit(name)
     cmd.delete(name)
     self.do_pick(0)
def frag(state=state, obj=obj3): 
    pwd, orig_sequence = setup(obj)
    stored.rotamerDict = {}
    # Add and retain hydrogens
    cmd.get_wizard().set_hyd("keep") 

    # Run over all sites where to mutate
    for site in mutations.keys():

        variants = mutations[site]

        # Run over all variants.
        for variant in variants:
            cmd.load(obj) 

            cmd.do('wizard mutagenesis')
            cmd.do('refresh_wizard')
            cmd.get_wizard().do_select("(%s/)" % site)
            cmd.do("cmd.get_wizard().set_mode('%s')"%variant)

            # Get the number of available rotamers at that site
            # Introduce a condition here to check if 
            # rotamers are requested. 
            # <<OPTION>>
            print variant, "variant"
            nRots = getRots(site, variant)
            nRots = 2
            stored.rotamerDict[str(site)+getOne(variant)] = nRots

            cmd.rewind()
            for i in range(1, nRots + 1): 
                
                cmd.get_wizard().do_select("(" + site + "/)")
                cmd.frame(i)
                cmd.get_wizard().apply()

                # Optimize the mutated sidechain
                #<<OPTION>>
                print "Sculpting."
                localSculpt(obj, site)

                # Protonation of the N.
                cmd.do("select n%d, name n and %d/" % (int(site), int(site)))
                cmd.edit("n%d" % int(site), None, None, None, pkresi=0, pkbond=0)
                cmd.do("h_fill")

                # Protonation of the C.
                cmd.do("select c%d, name c and %d/" % (int(site), int(site)))
                cmd.edit("c%d" % int(site), None, None, None, pkresi=0, pkbond=0)
                cmd.do("h_fill") 

                # Definition of saveString
                saveString  = '%s/' % pwd
                saveString += 'frag-' + getOne(orig_sequence[site]).lower() +\
                               site + getOne(variant).lower() + '-rot%i-%s.pdb, ' \
                               % (i,state) +'((%s/))' % site
                #print saveString 
                cmd.do('save %s' % saveString)
            cmd.do('delete all') 
            cmd.set_wizard('done')
    print "Frag is all done"
Exemple #43
0
 def test_attach(self):
     cmd.pseudoatom()
     cmd.edit('first all')
     cmd.attach('C', 1, 1)
     self.assertEqual(2, cmd.count_atoms())