Пример #1
0
 def testIdentify(self):
     cmd.fragment('gly', 'm1')
     cmd.select('s1', 'ID 3+4')
     r = cmd.identify('s1')
     self.assertItemsEqual(r, [3, 4])
     r = cmd.identify('s1', 1)
     self.assertItemsEqual(r, [('m1', 3), ('m1', 4)])
Пример #2
0
def cap(object):
    from pymol import cmd
    
    model = cmd.get_model(object)
    # guarantee identical ordering
    cmd.delete(object)
    cmd.load_model(model,object)
    n_list = cmd.identify("(n;n &!(n;c a;2.0))")
    c_list = cmd.identify("(n;c &!(n;n a;2.0))")
    print n_list
    print c_list
    for a in n_list:
        newat = copy.deepcopy(model.atom[a])
        newat.coord = [
            newat.coord[0] + random.random(),
            newat.coord[1] + random.random(),
            newat.coord[2] + random.random(),
            ]
        newat.symbol = 'H'
        newat.name = 'HN'
        newat.numeric_type = 43
        bond = Bond()
        bond.order = 1
        bond.stereo = 0
        bond.index = [ a, model.nAtom ]
        print "adding",newat.name,bond.index
        model.add_atom(newat)
        model.add_bond(bond)
    for a in c_list:
        newat = copy.deepcopy(model.atom[a])
        newat.coord = [
            newat.coord[0] + random.random(),
            newat.coord[1] + random.random(),
            newat.coord[2] + random.random(),
            ]
        newat.symbol = 'H'
        newat.name = 'HC'
        newat.numeric_type = 41
        bond = Bond()
        bond.order = 1
        bond.stereo = 0
        bond.index = [ a, model.nAtom ]
        print "adding",newat.name,bond.index
        model.add_atom(newat)
        model.add_bond(bond)
    # reload
    cmd.delete(object)
    cmd.load_model(model,object)
    cmd.sort(object)
Пример #3
0
def print_names(selection):
    print('\n\nSelection:\n\n\n\n\n')
    selection_string = 'select sel_name, id '
    for x in cmd.identify(selection, 0):
        print(x)
        selection_string += string.strip(str(x) + '+')
    print(selection_string[:-1])
Пример #4
0
def print_names(selection):
  print '\n\nSelection:\n\n\n\n\n'
  selection_string = 'select sel_name, id '
  for x in cmd.identify(selection,0):
    print x
    selection_string += string.strip(str(x) + '+')
  print selection_string[:-1]
Пример #5
0
def measure_all_torsions(sele,prot_dict):
   id_list = cmd.identify("((%s) and name ca)"%sele)
   for a in id_list:
      res_sele = "(alt '' and (byres id %d) and (%s))"%(a,sele)
      lst = find_torsions(res_sele)
      if len(lst):
         cmd.iterate("(%s and n;ca)"%res_sele,"stored.resn=resn")
         resn = pymol.stored.resn
         print(resn)
         name_list = []
         for a in lst:
            pymol.stored.names = []
            for b in a:
               cmd.iterate("(%s and id %d)"%(res_sele,b),"stored.names.append(name)")
            name_list.append(tuple(pymol.stored.names))
         res_dict = {}
         for a in name_list:
            dihe = cmd.get_dihedral("(%s and name %s)"%(res_sele,a[0]),
                                    "(%s and name %s)"%(res_sele,a[1]),
                                    "(%s and name %s)"%(res_sele,a[2]),
                                    "(%s and name %s)"%(res_sele,a[3]))
            res_dict[a]=dihe
         if resn not in prot_dict:
            prot_dict[resn]=[]
         prot_dict[resn].append(res_dict)
Пример #6
0
def measure_all_torsions(sele,prot_dict):
   id_list = cmd.identify("((%s) and name ca)"%sele)
   for a in id_list:
      res_sele = "(alt '' and (byres id %d) and (%s))"%(a,sele)
      lst = find_torsions(res_sele)
      if len(lst):
         cmd.iterate("(%s and n;ca)"%res_sele,"stored.resn=resn")
         resn = pymol.stored.resn
         print resn
         name_list = []
         for a in lst:
            pymol.stored.names = []
            for b in a:
               cmd.iterate("(%s and id %d)"%(res_sele,b),"stored.names.append(name)")
            name_list.append(tuple(pymol.stored.names))
         res_dict = {}
         for a in name_list:
            dihe = cmd.get_dihedral("(%s and name %s)"%(res_sele,a[0]),
                                    "(%s and name %s)"%(res_sele,a[1]),
                                    "(%s and name %s)"%(res_sele,a[2]),
                                    "(%s and name %s)"%(res_sele,a[3]))
            res_dict[a]=dihe
         if not prot_dict.has_key(resn):
            prot_dict[resn]=[]
         prot_dict[resn].append(res_dict)
Пример #7
0
def YXShowZINC():
    objName = cmd.identify("sele",1)[0][0]
    lastName = ""
    
    for objTuple in cmd.identify("sele", 1):
        objName = objTuple[0]
        if objName == lastName:
            continue
        lastName = objName
        fileName, molRank = parseObjName(objName)

        if fileName in os.listdir(os.getcwd()):
            zincID, outputName = getAndWriteZincID(fileName, molRank)
            openZincWebpage(zincID)
            moveAndWriteMolecule(outputName, zincID, fileName, molRank)
        else:
            print "Make sure to cd to the right directory"
Пример #8
0
    def get_prompt(self):

        # returns prompt for the viewer window (optional)

        if self.sele_name in cmd.get_names('selections'):
            n_atom = cmd.count_atoms("sele")
        else:
            n_atom = 0
        if n_atom:
            list = cmd.identify("sele")
            return ["%d atoms selected..." % n_atom, str(list)]
        else:
            return ["Please select some atoms..."]
Пример #9
0
   def get_prompt(self):

      # returns prompt for the viewer window (optional)
      
      if sele_name in cmd.get_names('selections'):
         n_atom = cmd.count_atoms(sele_name)
      else:
         n_atom = 0
      if n_atom:
         list = cmd.identify(sele_name)
         return ["%d atoms selected..."%n_atom,str(list)]
      else:
         return ["Please select some atoms..."]
Пример #10
0
 def getObjectName(self, selection="(all)"):
     pairs = cmd.identify(selection, 1)
     name = None
     names = set([])
     for p in pairs:
         names.add(p[0])
     if len(names) == 0:
         self.pop_error("Selection is empty")
     elif len(names) == 1:
         name = names.pop()
     else:
         s = "Active site selection needs to be limited to one object!"
         for n in names:
             s += n + " "
         self.pop_error(s)
     return name
Пример #11
0
    def do_pick(self, bondFlag):
        self.obj_name = None

        #      if 'pk1' in cmd.get_names('selections'):
        if cmd.count_atoms('pk1', 1):
            self.obj_name = cmd.identify('pk1', 1)[0][0]

        model = cmd.get_model("(pk1)")
        self.atom = model.atom.pop()
        if not self.labeling:
            cmd.label("(pk1)", '""')
        elif self.atom.name == 'CA':
            cmd.label("(pk1)", '" %s %s" % (resn,resi)')
        else:
            cmd.label("(pk1)", '" %s %s" % (name,resi)')
        cmd.unpick()
        cmd.refresh_wizard()
Пример #12
0
    def do_pick(self,bondFlag):
        self.obj_name = None

#      if 'pk1' in cmd.get_names('selections'):
        if cmd.count_atoms('pk1',1):
            self.obj_name = cmd.identify('pk1',1)[0][0]

        model = cmd.get_model("(pk1)")
        self.atom = model.atom.pop()
        if not self.labeling:
            cmd.label("(pk1)", '""')
        elif self.atom.name == 'CA':
            cmd.label("(pk1)", '" %s %s" % (resn,resi)')
        else:
            cmd.label("(pk1)", '" %s %s" % (name,resi)')
        cmd.unpick()
        cmd.refresh_wizard()
Пример #13
0
def get_chain_bb(selection):
    """
    returns nested dictionary with format {object: {chain: list-of-bb-atoms}}
    """
    bb_name = "BB"
    bb_beads = {}

    # get list of objects in selection
    objects = cmd.get_names(selection=selection)

    for obj in objects:
        chains = cmd.get_chains(obj)
        bb_beads[obj] = {}
        for c in chains:
            # if chain is empty string, put it in the "*" bin
            if not c:
                c = "*"
            id_list = cmd.identify(f"{obj} and chain {c} and name {bb_name}")
            bb_beads[obj][c] = id_list
    return bb_beads
Пример #14
0
def saveflex_from_mol2(Filename, userSelection):
    # saves bonds within selection in .flex format

    # get atoms indexes / IDs from pymol selection

    # IF PROBLEMS CHECK IF MOL2 WAS GENERATED USING INDEX AS KEY
    # index = numpy.array( cmd.index( userSelection ) )
    # index_list = [ int(index[k, 1]) for k in range( len(index) ) ]

    index_list = numpy.array(cmd.identify(userSelection))

    # open needed files
    molFilename = Filename + ".mol2"
    flexFilename = Filename + ".flex"
    mol2 = open(molFilename, "r")
    flex = open(flexFilename, "w")

    print(index_list)

    # gets bond list from mol2 and prints selected flexible bonds ( index - 1 )
    bondsection = 0
    line = mol2.readlines()
    for i in line:

        currentLine = i.split()

        if len(currentLine) > 0:

            if currentLine[0] == "@<TRIPOS>BOND":
                bondsection = 1
            elif currentLine[0] == "@<TRIPOS>SUBSTRUCTURE":
                bondsection = 0
                break

            elif bondsection:
                if int(currentLine[1]) in index_list and int(
                        currentLine[2]) in index_list:
                    print >> flex, int(currentLine[1]) - 1, int(
                        currentLine[2]) - 1
                    # prints in pymol console
                    print(int(currentLine[1]) - 1, int(currentLine[2]) - 1)
Пример #15
0
def optAlign( sel1, sel2 ):
	"""
	optAlign performs the Kabsch alignment algorithm upon the alpha-carbons of two selections.
	Example:   optAlign MOL1 and i. 20-40, MOL2 and i. 102-122
	Example 2: optAlign 1GGZ and i. 4-146 and n. CA, 1CLL and i. 4-146 and n. CA
	
	Two RMSDs are returned.  One comes from the Kabsch algorithm and the other from
	PyMol based upon your selections.

	By default, this program will optimally align the ALPHA CARBONS of the selections provided.
	To turn off this feature remove the lines between the commented "REMOVE ALPHA CARBONS" below.
	
	@param sel1: First PyMol selection with N-atoms
	@param sel2: Second PyMol selection with N-atoms
	"""
	cmd.reset()

	# make the lists for holding coordinates
	# partial lists
	stored.sel1 = []
	stored.sel2 = []
	# full lists
	stored.mol1 = []
	stored.mol2 = []

	# now put the coordinates into a list
	# partials

	# -- REMOVE ALPHA CARBONS
	sel1 = sel1 + " and N. CA"
	sel2 = sel2 + " and N. CA"
	# -- REMOVE ALPHA CARBONS

	cmd.iterate_state(1, selector.process(sel1), "stored.sel1.append([x,y,z])")
	cmd.iterate_state(1, selector.process(sel2), "stored.sel2.append([x,y,z])")
	# full molecule
	mol1 = cmd.identify(sel1,1)[0][0]
	mol2 = cmd.identify(sel2,1)[0][0]
	cmd.iterate_state(1, mol1, "stored.mol1.append([x,y,z])")
	cmd.iterate_state(1, mol2, "stored.mol2.append([x,y,z])")

	K = kabsch()
	U, T1, T2, RMSD, c1, c2 = K.align(stored.sel1, stored.sel2, [])

	stored.mol2 = map(lambda v:[T2[0]+((v[0]*U[0][0])+(v[1]*U[1][0])+(v[2]*U[2][0])),T2[1]+((v[0]*U[0][1])+(v[1]*U[1][1])+(v[2]*U[2][1])),T2[2]+((v[0]*U[0][2])+(v[1]*U[1][2])+(v[2]*U[2][2]))],stored.mol2)
	#stored.mol1 = map(lambda v:[ v[0]+T1[0], v[1]+T1[1], v[2]+T1[2] ], stored.mol1)
	stored.mol1 = map(lambda v:[ v[0]+T1[0], v[1]+T1[1], v[2]+T1[2] ], stored.mol1)

	cmd.alter_state(1,mol1,"(x,y,z)=stored.mol1.pop(0)")
	cmd.alter_state(1,mol2,"(x,y,z)=stored.mol2.pop(0)")
	cmd.alter( 'all',"segi=''")
	cmd.alter('all', "chain=''")
	print "RMSD=%f" % cmd.rms_cur(sel1, sel2)
	print "MY RMSD=%f" % RMSD
	cmd.hide('everything')
	cmd.show('ribbon', sel1 + ' or ' + sel2)
	cmd.color('gray70', mol1 )
	cmd.color('paleyellow', mol2 )
	cmd.color('red', 'visible')
	cmd.show('ribbon', 'not visible')
	cmd.center('visible')
	cmd.orient()
	cmd.zoom('visible')
def Mutagenesis(filename,mutation_type,start_mutation,finish_mutation):
    #2.Load your PDB file. Use V2R INACTIVE as an example or any pdb file. You can also 
    ##use cmd.fetch() to get an online pdb (search for the documentation typing 'pymol API' in Google).
    cmd.load(filename)
    #3.Get all loaded PDB object names in pymol
    PDBs = cmd.get_names()
    #4. We need to be able to get the chain and residue information
    ##a. Create empty list
    ProtChainResiList = []
    for PDB in PDBs:
        #print PDB
        ###### Get the ID numbers of c-alpha (CA) atoms of all residues
        CAindex = cmd.identify("%s and name CA"%PDB)
        print(CAindex)
        for CAid in CAindex:
            #Using CA ID to get Chain and Residue information   
             pdbstr = cmd.get_pdbstr("%s and id %s"%(PDB,CAid))
             pdbstr_lines = pdbstr.splitlines()
             chain = pdbstr_lines[0].split()[4]
             resi = pdbstr_lines[0].split()[5]
             ProtChainResiList.append([PDB,chain,resi])
             #b.check the output of the list
        for output in ProtChainResiList:
                 print (output)
     #5.Divide PDBid,Chain, and Residue (p,c,r) present in list to do a proper selection for the PyMOL wizard.
    for p,c,r in ProtChainResiList[start_mutation:finish_mutation]:
        #If you want to select a range of residues you will have to add above,for example, ProtChainResiList[0:100] to select the
        ##first residue and the 99th one.
        cmd.wizard("mutagenesis")
        print(p,c,r)
        cmd.refresh_wizard()
        #Selection to which type of residue you want to change
        cmd.get_wizard().set_mode(mutation_type)
        ############################################################
        ##Possible mutation_type could be:##########################
        ##'VAL' for ALA TO VAL######################################
        ###'ALA' for any/not ALA to ALA#############################
        ###'GLY' for ALA to GLY#####################################
        ############################################################
        # #'selection' will select each residue that you have selected 
        # #on ProtChainResiList above using the PDBid,chain,and residue 
        # #present on your pdb file.If you didn't select a range on 
        # #ProteinChainResiList, it will do the mutation on all the residues
        #  #present in your protein.
        selection="/%s//%s/%s"%(p,c,r)
       #Print selection to check the output
        print(selection)
        #Selects where to place the mutation
        cmd.get_wizard().do_select(selection)
        ##Applies mutation
        cmd.get_wizard().apply()
        #Save each mutation and reinitialize the session before the next mutation
        ##to have pdb files only with the residue-specific single-point mutation you were
        ##interested.
        for PDB in PDBs:
            cmd.set_wizard("done")
           #Saving your mutated residue in a single pdb file. Use directory in
           ##os.path.basename("(directory)%s"%selection)to add where you want your pdb file
           ##to be saved. 
           ##This will save the residue-specific mutation with the respective file name according to
           ##mutation.
            cmd.save((os.path.basename("%s"%selection)+"-mutation.pdb"),"%s"%PDB)
           ##Reinitialize PyMOL to default settings.
            cmd.reinitialize('everything')
            #Load your original (non-mutated) PDB file.
            cmd.load(filename)
Пример #17
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
Пример #18
0
def fSumWSC(molecule, SGNameAngle, chain, residue, DieElecSC, SCchargeASP, SCchargeGLU, SCchargeOXT, SCchargeARG, SCchargeHIS, SCchargeLYS, SCchargeMET1, printSC):
    SumWSC = 0.0
    SGnameselect = "/" + SGNameAngle + "//" + "/" + "/SG"
    # Sidechain ASP
    nameselect = "/" + molecule + " and resn ASP and name CG and not resi " + residue
    cmd.select("SC", nameselect)
    SClist = cmd.identify("SC")
    for i in range(len(SClist)):
        ResDist = cmd.dist(residue + 'distASP', SGnameselect, molecule + " and id " + str(SClist[i]))
        WSC = fWSC(SCchargeASP, DieElecSC, ResDist)
        SumWSC = SumWSC + WSC
        if printSC == 'yes':
            print("SC ASP ", str(SClist[i]), " ", SCchargeASP, " ", DieElecSC, " ", ResDist, " ", WSC)
    cmd.delete(residue + 'distASP')
    # Sidechain GLU
    nameselect = "/" + molecule + " and resn GLU and name CD and not resi " + residue
    cmd.select("SC", nameselect)
    SClist = cmd.identify("SC")
    for i in range(len(SClist)):
        ResDist = cmd.dist(residue + 'distGLU', SGnameselect, molecule + " and id " + str(SClist[i]))
        WSC = fWSC(SCchargeGLU, DieElecSC, ResDist)
        SumWSC = SumWSC + WSC
        if printSC == 'yes':
            print("SC GLU ", str(SClist[i]), " ", SCchargeGLU, " ", DieElecSC, " ", ResDist, " ", WSC)
    cmd.delete(residue + 'distGLU')
    # print "GLU", cmd.count_atoms("SC"), SumWSC
    # Sidechain OXT
    nameselect = "/" + molecule + " and byres name OXT and not resi " + residue
    cmd.select("SC", nameselect)
    cmd.select("SC", "SC and name C")
    SClist = cmd.identify("SC")
    for i in range(len(SClist)):
        ResDist = cmd.dist(residue + 'distOXT', SGnameselect, molecule + " and id " + str(SClist[i]))
        WSC = fWSC(SCchargeOXT, DieElecSC, ResDist)
        SumWSC = SumWSC + WSC
        if printSC == 'yes':
            print("SC OXT ", str(SClist[i]), " ", SCchargeOXT, " ", DieElecSC, " ", ResDist, " ", WSC)
    cmd.delete(residue + 'distOXT')
    # print "OXT", cmd.count_atoms("SC"), SumWSC
    # Sidechain ARG
    nameselect = "/" + molecule + " and resn ARG and name CZ and not resi " + residue
    cmd.select("SC", nameselect)
    SClist = cmd.identify("SC")
    for i in range(len(SClist)):
        ResDist = cmd.dist(residue + 'distARG', SGnameselect, molecule + " and id " + str(SClist[i]))
        WSC = fWSC(SCchargeARG, DieElecSC, ResDist)
        SumWSC = SumWSC + WSC
        if printSC == 'yes':
            print("SC ARG ", str(SClist[i]), " ", SCchargeARG, " ", DieElecSC, " ", ResDist, " ", WSC)
    cmd.delete(residue + 'distARG')
    # print "ARG", cmd.count_atoms("SC"), SumWSC
    # Sidechain HIS
    nameselect = "/" + molecule + " and resn HIS and name CD2 and not resi " + residue
    cmd.select("SC", nameselect)
    SClist = cmd.identify("SC")
    for i in range(len(SClist)):
        ResDist = cmd.dist(residue + 'distHIS', SGnameselect, molecule + " and id " + str(SClist[i]))
        WSC = fWSC(SCchargeHIS, DieElecSC, ResDist)
        SumWSC = SumWSC + WSC
        if printSC == 'yes':
            print("SC HIS ", str(SClist[i]), " ", SCchargeHIS, " ", DieElecSC, " ", ResDist, " ", WSC)
    cmd.delete(residue + 'distHIS')
    # print "HIS", cmd.count_atoms("SC"), SumWSC
    # Sidechain LYS
    nameselect = "/" + molecule + " and resn LYS and name NZ and not resi " + residue
    cmd.select("SC", nameselect)
    SClist = cmd.identify("SC")
    for i in range(len(SClist)):
        ResDist = cmd.dist(residue + 'distLYS', SGnameselect, molecule + " and id " + str(SClist[i]))
        WSC = fWSC(SCchargeLYS, DieElecSC, ResDist)
        SumWSC = SumWSC + WSC
        if printSC == 'yes':
            print("SC LYS ", str(SClist[i]), " ", SCchargeLYS, " ", DieElecSC, " ", ResDist, " ", WSC)
    cmd.delete(residue + 'distLYS')
    # print "LYS", cmd.count_atoms("SC"), SumWSC
    # Sidechain MET1
    nameselect = "/" + molecule + " and resn MET and res 1 and not resi " + residue
    cmd.select("SC", nameselect)
    cmd.select("SC", "SC and name N")
    SClist = cmd.identify("SC")
    for i in range(len(SClist)):
        ResDist = cmd.dist(residue + 'distMET1', SGnameselect, molecule + " and id " + str(SClist[i]))
        WSC = fWSC(SCchargeMET1, DieElecSC, ResDist)
        SumWSC = SumWSC + WSC
        if printSC == 'yes':
            print("SC MET1 ", str(SClist[i]), " ", SCchargeMET1, " ", DieElecSC, " ", ResDist, " ", WSC)
    cmd.delete(residue + 'distMET1')
    # print "MET1", cmd.count_atoms("SC"), SumWSC
    cmd.delete("SC")
    return SumWSC
Пример #19
0
def writepymolcmd(newmolecule,pkafile,verbose,makebonds):
	list_results,ligands_results = importpropkaresult(pkafile)
	### Now find the available bonding partners that pymol knows of
	bonding_partners = []
	bonding_partners_str = cmd.get_pdbstr("%s and resn * and not resn ASP+GLU+ARG+LYS+HIS+CYS+TYR+GLN+ASN+SER+THR+GLY+PHE+LEU+ALA+ILE+TRP+MET+PRO+VAL+HOH"%(newmolecule))
	for i in range(len(bonding_partners_str.splitlines())-1):
		bonding_partners_split = bonding_partners_str.splitlines()[i].split()
		if bonding_partners_split[0] == "HETATM" or bonding_partners_split[0] == "ATOM" :
			bonding_partners_single = bonding_partners_split[3]
			bonding_partners.append(bonding_partners_single)
	bonding_partners=uniqifi(bonding_partners)
	if verbose == 'yes': print("And other possible bonding partners is: %s"%(bonding_partners))
	### Read in the bond file, if it exists
	writebonds="no"
	if os.path.isfile(pkafile[:-4]+".bonds") and makebonds == "yes": bonds = importpropkabonds(pkafile); writebonds="yes"
	### Open the pymol command file for writing
	files_pka_pymol = openpymolfiles(pkafile)
	result_pka_pymol=files_pka_pymol[0];result_pka_pymol_name=files_pka_pymol[1]
	### Make some dictionary for propka->pymol name conversion
	dictio = {'ASP':'CG', 'GLU':'CD', 'ARG':'CZ', 'LYS':'NZ', 'HIS':'CG', 'CYS':'SG', 'TYR':'OH', 'C-':'C', 'N+':'N','NTR':'N','CTR':'C','GLN':'CD','ASN':'CG','SER':'OG','THR':'OG1','GLY':'CA','PHE':'CZ','LEU':'CG','ALA':'CB','ILE':'CD1','TRP':'NE1','MET':'SD','PRO':'CG','VAL':'CB'}
	dictio2 = {'ASP':'D', 'GLU':'E', 'ARG':'R', 'LYS':'K', 'HIS':'H', 'CYS':'C', 'TYR':'Y', 'C-':'C-', 'N+':'N+'}
	### This list is from: http://en.wikipedia.org/wiki/Protein_pKa_calculations
	pkaaminoacid=['ASP','GLU','ARG','LYS','HIS','CYS','TYR']
	pkadictio = {'ASP':3.9, 'GLU':4.3, 'ARG':12.0, 'LYS':10.5, 'HIS':6.0, 'CYS':8.3, 'TYR':10.1}
	### Now start write to the file.
	### Try to make silent
	##result_pka_pymol.write("cmd.feedback('disable','all','actions')\n")
	##result_pka_pymol.write("cmd.feedback('disable','all','results')\n")
	### Change the GUI width, to make the long names possible.
	result_pka_pymol.write("cmd.set('internal_gui_width','360')\n")
	### Set fonts
	result_pka_pymol.write("cmd.set('label_font_id','12')\n")
	result_pka_pymol.write("cmd.set('label_size','-0.5')\n")
	result_pka_pymol.write("cmd.set('label_color','grey')\n")
	### No auto zoom the new objects
	result_pka_pymol.write("cmd.set('auto_zoom','off')\n")
	### The name for the molecules are defined here
	pkamolecule="%spKa"%(newmolecule)
	pkalabelmolecule="%sLab"%(newmolecule)
	### Create the groups now, so they come in order. They will be empty
	result_pka_pymol.write("cmd.group('%sResi','Res*')\n"%(newmolecule))
	result_pka_pymol.write("cmd.group('%sLigands','Lig*')\n"%(newmolecule))
	if writebonds=="yes": result_pka_pymol.write("cmd.group('%sBonds','%sBond*')\n"%(newmolecule,newmolecule))
	### Create new empty pymol pka molecules. For pka atoms and its label. This is a "bucket" we where we will put in the atoms together.
	result_pka_pymol.write("cmd.create('%s','None')\n"%(pkamolecule))
	result_pka_pymol.write("cmd.create('%s','None')\n"%(pkalabelmolecule))
	### Now make the pka atoms and alter, color and such
	for l in list_results:
		name=dictio[l[0]];resn=dictio2[l[0]];resi=l[1];chain=l[2];pka=l[3];buried=l[4]
		if "*" in pka: pka = pka.replace("*",""); comment="*Coupled residue"
		else: comment=""
		if l[0] in pkaaminoacid:
			pkadiff =(float(pka)-pkadictio[l[0]])
			pkadiff = "(%s)"%pkadiff
			if pka=="99.99": pkadiff=""
		else: pkadiff=""
		### Make the selection for which atom to copy
		newselection = ("/%s//%s/%s/%s"%(newmolecule,chain,resi,name))
		protselect = ("%sRes_%s%s%s"%(newmolecule,chain,resn,resi))
		result_pka_pymol.write("cmd.select('%s','byres %s')\n"%(protselect,newselection))
		result_pka_pymol.write("cmd.show('sticks','byres %s')\n"%(protselect))
		### The temporary name
		tempname = ("%s%s%s%s"%(pkamolecule,chain,resi,name))
		tempnamelabel = ("%s%s%s%s"%(pkalabelmolecule,chain,resi,name))
		tempselect= ("/%s//%s/%s"%(tempname,chain,resi))
		tempselectlabel= ("/%s//%s/%s"%(tempnamelabel,chain,resi))
		### Copy the atom, call it by the residue name
		result_pka_pymol.write("cmd.create('%s','%s',quiet=1)\n"%(tempname,newselection))
		### Alter the name and the b value of the newly created atom
		result_pka_pymol.write("cmd.alter('%s','b=%s')\n"%(tempselect,pka))
		result_pka_pymol.write("cmd.alter('%s','vdw=0.5')\n"%(tempselect))
		result_pka_pymol.write("cmd.alter('%s','name=%s%s%s')\n"%(tempselect,'"',pka,'"'))
		### Now create a fake label atom, and translate it
		result_pka_pymol.write("cmd.create('%s','%s',quiet=1)\n"%(tempnamelabel,tempname))
		movelabelxyz = (1.5,0,0)
		result_pka_pymol.write("cmd.translate('[%s,%s,%s]','%s',camera=0)\n"%(movelabelxyz[0],movelabelxyz[1],movelabelxyz[2],tempnamelabel))
		### Labelling alternate positions are not allowed, so we delete that attribute for the label atoms.
		result_pka_pymol.write("cmd.alter('%s','alt=%s%s')\n"%(tempselectlabel,'"','"'))
		result_pka_pymol.write("cmd.label('%s','text_type=%spka=%s%s Bu:%s%s%s%s')\n"%(tempselectlabel,'"',pka,pkadiff,buried,'%',comment,'"'))
		### Now put the atoms into a bucket of atoms
		result_pka_pymol.write("cmd.create('%s','%s or (%s)',quiet=1)\n"%(pkamolecule,pkamolecule,tempselect))
		result_pka_pymol.write("cmd.create('%s','%s or (%s)',quiet=1)\n"%(pkalabelmolecule,pkalabelmolecule,tempselectlabel))
		### Remove the temporary atoms
		result_pka_pymol.write("cmd.remove('%s')\n"%(tempname))
		result_pka_pymol.write("cmd.remove('%s')\n"%(tempnamelabel))
		### Delete the temporary molecule/selection
		result_pka_pymol.write("cmd.delete('%s')\n"%(tempname))
		result_pka_pymol.write("cmd.delete('%s')\n"%(tempnamelabel))
	### Group the resi together
	result_pka_pymol.write("cmd.group('%sResi','%sRes*')\n"%(newmolecule,newmolecule))
	for l in ligands_results:
		resn=l[0];atom=l[1];chain=l[2];pka=l[3];buried=l[4]
		if verbose == 'yes': print("Ligand. resn:%s atom:%s chain:%s pka:%s buried:%s"%(resn,atom,chain,pka,buried))
		if Check_bonding_partners(bonding_partners, resn)[0]:
			if "*" in pka: pka = pka.replace("*",""); comment="*Coupled residue"
			else: comment=""
			### Make the selection for which atom to copy
			ligselection = ("/%s and chain %s and resn %s and name %s"%(newmolecule,chain,resn,atom))
			ligselect = ("%sLig_%s%s%s"%(newmolecule,chain,resn,atom))
			result_pka_pymol.write("cmd.select('%s','%s')\n"%(ligselect,ligselection))
			result_pka_pymol.write("cmd.show('sticks','byres %s')\n"%(ligselect))
			result_pka_pymol.write("cmd.util.cbap('byres %s')\n"%(ligselect))
			### The temporary name
			tempname = ("%s%s%s%s"%(pkamolecule,chain,resn,atom))
			tempnamelabel = ("%s%s%s%s"%(pkalabelmolecule,chain,resn,atom))
			tempselect= ("/%s and chain %s and resn %s"%(tempname,chain,resn))
			tempselectlabel= ("/%s and chain %s and resn %s"%(tempnamelabel,chain,resn))
			### Copy the atom, call it by the residue name
			result_pka_pymol.write("cmd.create('%s','%s',quiet=1)\n"%(tempname,ligselection))
			### Alter the name and the b value of the newly created atom
			result_pka_pymol.write("cmd.alter('%s','b=%s')\n"%(tempselect,pka))
			result_pka_pymol.write("cmd.alter('%s','vdw=0.5')\n"%(tempselect))
			result_pka_pymol.write("cmd.alter('%s','name=%s%s%s')\n"%(tempselect,'"',pka,'"'))
			### Now create a fake label atom, and translate it
			result_pka_pymol.write("cmd.create('%s','%s',quiet=1)\n"%(tempnamelabel,tempname))
			movelabelxyz = (1.5,0,0)
			result_pka_pymol.write("cmd.translate('[%s,%s,%s]','%s',camera=0)\n"%(movelabelxyz[0],movelabelxyz[1],movelabelxyz[2],tempnamelabel))
			### Labelling alternate positions are not allowed, so we delete that attribute for the label atoms.
			result_pka_pymol.write("cmd.alter('%s','alt=%s%s')\n"%(tempselectlabel,'"','"'))
			result_pka_pymol.write("cmd.label('%s','text_type=%spka=%s Bu:%s%s%s%s')\n"%(tempselectlabel,'"',pka,buried,'%',comment,'"'))
			### Now put the atoms into a bucket of atoms
			result_pka_pymol.write("cmd.create('%s','%s or (%s)',quiet=1)\n"%(pkamolecule,pkamolecule,tempselect))
			result_pka_pymol.write("cmd.create('%s','%s or (%s)',quiet=1)\n"%(pkalabelmolecule,pkalabelmolecule,tempselectlabel))
			### Remove the temporary atoms
			result_pka_pymol.write("cmd.remove('%s')\n"%(tempname))
			result_pka_pymol.write("cmd.remove('%s')\n"%(tempnamelabel))
			### Delete the temporary molecule/selection
			result_pka_pymol.write("cmd.delete('%s')\n"%(tempname))
			result_pka_pymol.write("cmd.delete('%s')\n"%(tempnamelabel))
	### Group the resi together
	result_pka_pymol.write("cmd.group('%sLigands','%sLig*')\n"%(newmolecule,newmolecule))
	### Finish the pka atoms, and show spheres
	result_pka_pymol.write("cmd.show('spheres','%s')\n"%(pkamolecule))
	result_pka_pymol.write("cmd.spectrum('b','red_white_blue',selection='%s',minimum='0',maximum='14')\n"%(pkamolecule))
	result_pka_pymol.write("cmd.alter('%s and name 99.9','vdw=0.8')\n"%(pkamolecule))
	result_pka_pymol.write("cmd.show('spheres','%s and name 99.9')\n"%(pkamolecule))
	result_pka_pymol.write("cmd.color('sulfur','%s and name 99.9')\n"%(pkamolecule))
	### Now we make the bonds
	if writebonds=="yes":
		Bondgroups=[]
		naturalaminoacids = ['ASP','GLU','ARG','LYS','HIS','CYS','TYR','NTR','N+','CTR','C-','GLN','ASN','SER','THR','GLY','PHE','LEU','ALA','ILE','TRP','MET','PRO','VAL']
		for l in bonds:
			if l[0] in naturalaminoacids:
				name=dictio[l[0]];resi=l[1];chain=l[2];desolvation=l[6][12:];pkachange=l[11];NBresi=l[8][3:];NBchain=l[9];NBbond=l[-1][:2]
				if l[8][:3] in naturalaminoacids:
					NBname,cutoff=BondTypeName(dictio[l[8][:3]],NBbond)
					fromselection = ("/%s//%s/%s/%s"%(newmolecule,chain,resi,name))
					toselection = ("/%s//%s/%s/%s"%(newmolecule,NBchain,NBresi,NBname))
					if l[8][:3]=='NTR':
						extind=cmd.identify("chain %s and name N"%(NBchain))[0]
						toselection = ("/%s and id %s and name N"%(newmolecule,extind))
						NBresi="N+"
					if l[8][:3]=='CTR':
						extind=cmd.identify("chain %s and name C"%(NBchain))[-1]
						toselection = ("/%s and id %s and name C"%(newmolecule,extind))
						NBresi="C-"
					distname = ("%s_%s%s%s%s_%s_%s"%(newmolecule,chain,resi,NBchain,NBresi,NBbond,pkachange))
					result_pka_pymol.write("cmd.distance('%s','%s','%s'%s)\n"%(distname,fromselection,toselection,cutoff))
					result_pka_pymol.write("cmd.color('%s','%s')\n"%(SetDashColor(NBbond),distname))
					##result_pka_pymol.write("cmd.disable('%s')\n"%(distname))
					Bondgroups.append("%s%s"%(chain,resi))
				if l[8][:3] not in naturalaminoacids and Check_bonding_partners(bonding_partners, l[8])[0]:
					cutoff=""; NBresn = Check_bonding_partners(bonding_partners, l[8])[1]; NBname=l[8][len(NBresn):]+"*"
					fromselection = ("/%s//%s/%s/%s"%(newmolecule,chain,resi,name))
					toselection = ("/%s and chain %s and resn %s and name %s"%(newmolecule,NBchain,NBresn,NBname))
					if verbose == 'yes': print("Res->Ligand: (%s) -> (%s)"%(fromselection, toselection))
					result_pka_pymol.write("cmd.show('sticks','%s')\n"%(toselection))
					distname = ("%s_%s%s%s_%s_%s"%(newmolecule,chain,resi,NBresn,NBbond,pkachange))
					result_pka_pymol.write("cmd.distance('%s','%s','%s'%s)\n"%(distname,fromselection,toselection,cutoff))
					result_pka_pymol.write("cmd.color('%s','%s')\n"%(SetDashColor(NBbond),distname))
					##result_pka_pymol.write("cmd.disable('%s')\n"%(distname))
					Bondgroups.append("%s%s"%(chain,resi))
			if l[0] in bonding_partners:
				resn=l[0];atom=l[1];chain=l[2];desolvation=l[6][12:];pkachange=l[11];NBresi=l[8][3:];NBchain=l[9];NBbond=l[-1][:2]
				if not Check_bonding_partners(bonding_partners, l[8])[0]:
					NBname,cutoff=BondTypeName(dictio[l[8][:3]],NBbond)
					fromselection = ("/%s and chain %s and resn %s and name %s"%(newmolecule,chain,resn,atom))
					toselection = ("/%s//%s/%s/%s"%(newmolecule,NBchain,NBresi,NBname))
					if l[8][:3]=='NTR':
						extind=cmd.identify("chain %s and name N"%(NBchain))[0]
						toselection = ("/%s and id %s and name N"%(newmolecule,extind))
						NBresi="N+"
					if l[8][:3]=='CTR':
						extind=cmd.identify("chain %s and name C"%(NBchain))[-1]
						toselection = ("/%s and id %s and name C"%(newmolecule,extind))
						NBresi="C-"
					distname = ("%s_%s%s%s%s%s_%s_%s"%(newmolecule,chain,resn,atom,NBchain,NBresi,NBbond,pkachange))
					result_pka_pymol.write("cmd.distance('%s','%s','%s'%s)\n"%(distname,fromselection,toselection,cutoff))
					result_pka_pymol.write("cmd.color('%s','%s')\n"%(SetDashColor(NBbond),distname))
					Bondgroups.append("%s%s%s"%(chain,resn,atom))
					##result_pka_pymol.write("cmd.disable('%s')\n"%(distname))
				if Check_bonding_partners(bonding_partners, l[8])[0]:
					cutoff=""; NBresn = Check_bonding_partners(bonding_partners, l[8])[1]; NBname=l[8][len(NBresn):]+"*"
					fromselection = ("/%s and chain %s and resn %s and name %s"%(newmolecule,chain,resn,atom))
					toselection = ("/%s and chain %s and resn %s and name %s"%(newmolecule,NBchain,NBresn,NBname))
					if verbose == 'yes': print("Ligand->Ligand: (%s) -> (%s)"%(fromselection, toselection))
					result_pka_pymol.write("cmd.show('sticks','%s')\n"%(toselection))
					distname = ("%s_%s%s%s%s_%s_%s"%(newmolecule,chain,resn,atom,NBresn,NBbond,pkachange))
					result_pka_pymol.write("cmd.distance('%s','%s','%s'%s)\n"%(distname,fromselection,toselection,cutoff))
					result_pka_pymol.write("cmd.color('%s','%s')\n"%(SetDashColor(NBbond),distname))
					##result_pka_pymol.write("cmd.disable('%s')\n"%(distname))
					Bondgroups.append("%s%s%s"%(chain,resn,atom))
		Bondgroups=uniqifi(Bondgroups)
		for l in Bondgroups:
			result_pka_pymol.write("cmd.group('%sBonds_%s','%s_%s*')\n"%(newmolecule,l,newmolecule,l))
			result_pka_pymol.write("cmd.disable('%sBonds_%s')\n"%(newmolecule,l))
		result_pka_pymol.write("cmd.group('%sBonds','%sBonds_*')\n"%(newmolecule,newmolecule))
	result_pka_pymol.write("cmd.set('auto_zoom','on')\n")
	##result_pka_pymol.write("cmd.feedback('enable','all','actions')\n")
	##result_pka_pymol.write("cmd.feedback('enable','all','results')\n")
	result_pka_pymol.close()
	return(result_pka_pymol_name)
Пример #20
0
def optAlign(sel1, sel2):
    """
	optAlign performs the Kabsch alignment algorithm upon the alpha-carbons of two selections.
	Example:   optAlign MOL1 and i. 20-40, MOL2 and i. 102-122
	Example 2: optAlign 1GGZ and i. 4-146 and n. CA, 1CLL and i. 4-146 and n. CA
	
	Two RMSDs are returned.  One comes from the Kabsch algorithm and the other from
	PyMol based upon your selections.

	By default, this program will optimally align the ALPHA CARBONS of the selections provided.
	To turn off this feature remove the lines between the commented "REMOVE ALPHA CARBONS" below.
	
	@param sel1: First PyMol selection with N-atoms
	@param sel2: Second PyMol selection with N-atoms
	"""
    cmd.reset()

    # make the lists for holding coordinates
    # partial lists
    stored.sel1 = []
    stored.sel2 = []
    # full lists
    stored.mol1 = []
    stored.mol2 = []

    # now put the coordinates into a list
    # partials

    # -- REMOVE ALPHA CARBONS
    sel1 = sel1 + " and N. CA"
    sel2 = sel2 + " and N. CA"
    # -- REMOVE ALPHA CARBONS

    cmd.iterate_state(1, selector.process(sel1), "stored.sel1.append([x,y,z])")
    cmd.iterate_state(1, selector.process(sel2), "stored.sel2.append([x,y,z])")
    # full molecule
    mol1 = cmd.identify(sel1, 1)[0][0]
    mol2 = cmd.identify(sel2, 1)[0][0]
    cmd.iterate_state(1, mol1, "stored.mol1.append([x,y,z])")
    cmd.iterate_state(1, mol2, "stored.mol2.append([x,y,z])")

    K = kabsch()
    U, T1, T2, RMSD, c1, c2 = K.align(stored.sel1, stored.sel2, [])

    stored.mol2 = map(
        lambda v: [
            T2[0] + ((v[0] * U[0][0]) + (v[1] * U[1][0]) +
                     (v[2] * U[2][0])), T2[1] +
            ((v[0] * U[0][1]) + (v[1] * U[1][1]) + (v[2] * U[2][1])), T2[2] + (
                (v[0] * U[0][2]) + (v[1] * U[1][2]) + (v[2] * U[2][2]))
        ], stored.mol2)
    #stored.mol1 = map(lambda v:[ v[0]+T1[0], v[1]+T1[1], v[2]+T1[2] ], stored.mol1)
    stored.mol1 = map(lambda v: [v[0] + T1[0], v[1] + T1[1], v[2] + T1[2]],
                      stored.mol1)

    cmd.alter_state(1, mol1, "(x,y,z)=stored.mol1.pop(0)")
    cmd.alter_state(1, mol2, "(x,y,z)=stored.mol2.pop(0)")
    cmd.alter('all', "segi=''")
    cmd.alter('all', "chain=''")
    print "RMSD=%f" % cmd.rms_cur(sel1, sel2)
    print "MY RMSD=%f" % RMSD
    cmd.hide('everything')
    cmd.show('ribbon', sel1 + ' or ' + sel2)
    cmd.color('gray70', mol1)
    cmd.color('paleyellow', mol2)
    cmd.color('red', 'visible')
    cmd.show('ribbon', 'not visible')
    cmd.center('visible')
    cmd.orient()
    cmd.zoom('visible')
Пример #21
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
def optAlignRNA( sel1, sel2 ):
	"""
	optAlignRNA performs the Kabsch alignment algorithm upon the C1' carbons of two selections.
	Example: optAlignRNA 1JU7 and i. 1-16 and n. C1', 1CLL and i. 4-146 and n. C1'
 
	Two RMSDs are returned.  One comes from the Kabsch algorithm and the other from
	PyMOL based upon your selections.
	
	This function can be run in a for loop to fit multiple structures  with a common prefix name:
	
	for x in cmd.get_names(): optAlignRNA(x, "1JU7_0001")
	 
	or get the rmsds for all combinations, do the following:
	 
	[[optAlignRNA(x, y) for x in cmd.get_names()] for y in cmd.get_names()]

	"""
	cmd.reset()
 
	# make the lists for holding coordinates
	# partial lists
	stored.sel1 = []
	stored.sel2 = []
	# full lists
	stored.mol1 = []
	stored.mol2 = []
 
	# -- CUT HERE
	sel1 += " and N. C1'"
	sel2 += " and N. C1'"
	# -- CUT HERE
 
	# Get the selected coordinates.  We
	# align these coords.
	cmd.iterate_state(1, selector.process(sel1), "stored.sel1.append([x,y,z])")
	cmd.iterate_state(1, selector.process(sel2), "stored.sel2.append([x,y,z])")
 
	# get molecule name
	mol1 = cmd.identify(sel1,1)[0][0]
	mol2 = cmd.identify(sel2,1)[0][0]
 
	# Get all molecule coords.  We do this because
	# we have to rotate the whole molcule, not just
	# the aligned selection
	cmd.iterate_state(1, mol1, "stored.mol1.append([x,y,z])")
	cmd.iterate_state(1, mol2, "stored.mol2.append([x,y,z])")
 
	# check for consistency
	assert len(stored.sel1) == len(stored.sel2)
	L = len(stored.sel1)
	assert L > 0
 
	# must alway center the two proteins to avoid
	# affine transformations.  Center the two proteins
	# to their selections.
	COM1 = numpy.sum(stored.sel1,axis=0) / float(L)
	COM2 = numpy.sum(stored.sel2,axis=0) / float(L)
	stored.sel1 -= COM1
	stored.sel2 -= COM2
 
	# Initial residual, see Kabsch.
	E0 = numpy.sum( numpy.sum(stored.sel1 * stored.sel1,axis=0),axis=0) + numpy.sum( numpy.sum(stored.sel2 * stored.sel2,axis=0),axis=0)
 
	#
	# This beautiful step provides the answer.  V and Wt are the orthonormal
	# bases that when multiplied by each other give us the rotation matrix, U.
	# S, (Sigma, from SVD) provides us with the error!  Isn't SVD great!
	V, S, Wt = numpy.linalg.svd( numpy.dot( numpy.transpose(stored.sel2), stored.sel1))
 
	# we already have our solution, in the results from SVD.
	# we just need to check for reflections and then produce
	# the rotation.  V and Wt are orthonormal, so their det's
	# are +/-1.
	reflect = float(str(float(numpy.linalg.det(V) * numpy.linalg.det(Wt))))
 
	if reflect == -1.0:
		S[-1] = -S[-1]
		V[:,-1] = -V[:,-1]
 
	RMSD = E0 - (2.0 * sum(S))
	RMSD = numpy.sqrt(abs(RMSD / L))
 
	#U is simply V*Wt
	U = numpy.dot(V, Wt)
 
	# rotate and translate the molecule
	stored.sel2 = numpy.dot((stored.mol2 - COM2), U)
	stored.sel2 = stored.sel2.tolist()
	# center the molecule
	stored.sel1 = stored.mol1 - COM1
	stored.sel1 = stored.sel1.tolist()
 
	# let PyMol know about the changes to the coordinates
	cmd.alter_state(1,mol1,"(x,y,z)=stored.sel1.pop(0)")
	cmd.alter_state(1,mol2,"(x,y,z)=stored.sel2.pop(0)")
 
	#print("Moved: %s Reference: %s RMSD = %f" % mol1, mol2, RMSD)
	print("% s, % s,% 5.3f" % (mol1, mol2, RMSD))
 
	# make the alignment OBVIOUS
	cmd.hide("everything")
	cmd.show("ribbon", sel1 + " or " + sel2)
	cmd.color("gray70", mol1 )
	cmd.color("magenta", mol2 )
	cmd.color("red", "visible")
	cmd.show("ribbon", "not visible")
	cmd.center("visible")
	cmd.orient()
	cmd.zoom("visible")
Пример #23
0
def optAlign( sel1, sel2 ):
	"""
	optAlign performs the Kabsch alignment algorithm upon the alpha-carbons of two selections.
	Example:   optAlign MOL1 and i. 20-40, MOL2 and i. 102-122
	Example 2: optAlign 1GGZ and i. 4-146 and n. CA, 1CLL and i. 4-146 and n. CA
 
	Two RMSDs are returned.  One comes from the Kabsch algorithm and the other from
	PyMol based upon your selections.
 
	By default, this program will optimally align the ALPHA CARBONS of the selections provided.
	To turn off this feature remove the lines between the commented "REMOVE ALPHA CARBONS" below.
 
	@param sel1: First PyMol selection with N-atoms
	@param sel2: Second PyMol selection with N-atoms
	"""
	cmd.reset()
 
	# make the lists for holding coordinates
	# partial lists
	stored.sel1 = []
	stored.sel2 = []
	# full lists
	stored.mol1 = []
	stored.mol2 = []
 
	# -- CUT HERE
	sel1 += " and N. CA"
	sel2 += " and N. CA"
	# -- CUT HERE
 
	# Get the selected coordinates.  We
	# align these coords.
	cmd.iterate_state(1, selector.process(sel1), "stored.sel1.append([x,y,z])")
	cmd.iterate_state(1, selector.process(sel2), "stored.sel2.append([x,y,z])")
 
	# get molecule name
	mol1 = cmd.identify(sel1,1)[0][0]
	mol2 = cmd.identify(sel2,1)[0][0]
 
	# Get all molecule coords.  We do this because
	# we have to rotate the whole molcule, not just
	# the aligned selection
	cmd.iterate_state(1, mol1, "stored.mol1.append([x,y,z])")
	cmd.iterate_state(1, mol2, "stored.mol2.append([x,y,z])")
 
	# check for consistency
	assert len(stored.sel1) == len(stored.sel2)
	L = len(stored.sel1)
	assert L > 0
 
	# must alway center the two proteins to avoid
	# affine transformations.  Center the two proteins
	# to their selections.
	COM1 = numpy.sum(stored.sel1,axis=0) / float(L)
	COM2 = numpy.sum(stored.sel2,axis=0) / float(L)
	stored.sel1 -= COM1
	stored.sel2 -= COM2
 
	# Initial residual, see Kabsch.
	E0 = numpy.sum( numpy.sum(stored.sel1 * stored.sel1,axis=0),axis=0) + numpy.sum( numpy.sum(stored.sel2 * stored.sel2,axis=0),axis=0)
 
	#
	# This beautiful step provides the answer.  V and Wt are the orthonormal
	# bases that when multiplied by each other give us the rotation matrix, U.
	# S, (Sigma, from SVD) provides us with the error!  Isn't SVD great!
	V, S, Wt = numpy.linalg.svd( numpy.dot( numpy.transpose(stored.sel2), stored.sel1))
 
	# we already have our solution, in the results from SVD.
	# we just need to check for reflections and then produce
	# the rotation.  V and Wt are orthonormal, so their det's
	# are +/-1.
	reflect = float(str(float(numpy.linalg.det(V) * numpy.linalg.det(Wt))))
 
	if reflect == -1.0:
		S[-1] = -S[-1]
		V[:,-1] = -V[:,-1]
 
	RMSD = E0 - (2.0 * sum(S))
	RMSD = numpy.sqrt(abs(RMSD / L))
 
	#U is simply V*Wt
	U = numpy.dot(V, Wt)
 
	# rotate and translate the molecule
	stored.sel2 = numpy.dot((stored.mol2 - COM2), U)
	stored.sel2 = stored.sel2.tolist()
	# center the molecule
	stored.sel1 = stored.mol1 - COM1
	stored.sel1 = stored.sel1.tolist()
 
	# let PyMol know about the changes to the coordinates
	cmd.alter_state(1,mol1,"(x,y,z)=stored.sel1.pop(0)")
	cmd.alter_state(1,mol2,"(x,y,z)=stored.sel2.pop(0)")
 
	print "RMSD=%f" % RMSD
 
	# make the alignment OBVIOUS
	cmd.hide('everything')
	cmd.show('ribbon', sel1 + ' or ' + sel2)
	cmd.color('gray70', mol1 )
	cmd.color('paleyellow', mol2 )
	cmd.color('red', 'visible')
	cmd.show('ribbon', 'not visible')
	cmd.center('visible')
	cmd.orient()
	cmd.zoom('visible')
Пример #24
0
def rpcIdentify(what='all', mode=0):
  """ returns the results of cmd.identify(what,mode) """
  return cmd.identify(what, mode=mode)
Пример #25
0
def cealign(sel1, sel2):
    """
	Rough CE Structure-based Alignment of two protein structures

	Overview:
	cealign will try its best to align the alpha-carbon atoms provided
	in both selections sel1 and sel2.  The algorithm follows the paper
	written by Shindyalov and Bourne.  A few modifications to the algo-
	rithm are introduced, partly due to lazyness, and partly due to 
	improving speed and accuracy while not conflicting with the lazyness
	requirement.  :-)

	Params:
	\@param sel1: (string) valid PyMol selection string of protein 1 to align	
	\@param sel2: (string) valid PyMol selection string of protein 2 to align

	Returns:
	\@return: (string) the CE-score and the RMSD of the alignment

	Side-Effects:
	\@note: rotates and translates the objects (proteins) provided in the
	selections, sel1 and sel2, to represent the alignment.  Probably will
	also change their representation to more clearly show the aligned
	segments.

	Requires:
	Requires the Kabsch algorithm for protein optimal superposition.  Don't
	worry, I already wrote this as a foray into the academic: you may download
	and install it from the PyMol wiki at:
		http://www.pymolwiki.org/index.php/Kabsch

	Bugs: Many, I'm sure.  Please forward bugs/comments to [email protected]
	"""

    #########################################################################
    # CE specific defines.  Don't change these unless you know
    # what you're doing.  See the documentation.
    #########################################################################
    # WINDOW SIZE
    # make sure you set this variable in cealign.py, as well!
    winSize = 8
    # FOR AVERAGING
    winSum = (winSize - 1) * (winSize - 2) / 2
    # max gap size
    gapMax = 30

    # make the lists for holding coordinates
    # partial lists
    stored.sel1 = []
    stored.sel2 = []
    # full lists
    stored.mol1 = []
    stored.mol2 = []

    # now put the coordinates into a list
    # partials

    # -- REMOVE ALPHA CARBONS
    sel1 = sel1 + " and n. CA"
    sel2 = sel2 + " and n. CA"
    # -- REMOVE ALPHA CARBONS

    cmd.iterate_state(1, selector.process(sel1), "stored.sel1.append([x,y,z])")
    cmd.iterate_state(1, selector.process(sel2), "stored.sel2.append([x,y,z])")

    # full molecule
    mol1 = cmd.identify(sel1, 1)[0][0]
    mol2 = cmd.identify(sel2, 1)[0][0]

    # put all atoms from MOL1 & MOL2 into stored.mol1
    cmd.iterate_state(1, mol1, "stored.mol1.append([x,y,z])")
    cmd.iterate_state(1, mol2, "stored.mol2.append([x,y,z])")

    if (len(stored.mol1) == 0):
        print "ERROR: Your first selection was empty."
        return
    if (len(stored.mol2) == 0):
        print "ERROR: Your second selection was empty."
        return

    # call the C function
    alignString = ccealign((stored.sel1, stored.sel2))

    if (len(alignString) == 1):
        if (len(alignString[0]) == 0):
            print "\n\nERROR: There was a problem with CEAlign's C Module.  The return value was blank."
            print "ERROR: This is obviously bad.  Please inform a CEAlign developer.\n\n"
            return

    bestPathID = -1
    bestPathScore = 100000
    bestStr1 = ""
    bestStr2 = ""

    # for each of the 20 possible alignments returned
    # we check each one for the best CE-Score and keep
    # that one.  The return val of ccealign is a list
    # of lists of pairs.
    for curAlignment in alignString:
        seqCount = len(curAlignment)
        matA = None
        matB = None

        if (seqCount == 0):
            continue

        for AFP in curAlignment:
            first, second = AFP
            if (matA == None and matB == None):
                matA = [stored.sel1[first - 1]]
                matB = [stored.sel2[second - 1]]
            else:
                matA.append(stored.sel1[first - 1])
                matB.append(stored.sel2[second - 1])

        curScore = simpAlign(matA,
                             matB,
                             mol1,
                             mol2,
                             stored.mol1,
                             stored.mol2,
                             align=0,
                             L=len(matA))

        #########################################################################
        # if you want the best RMSD, not CE Score uncomment here down
        #########################################################################
        #if ( curScore < bestPathScore ):
        #bestPathScore = curScore
        #bestMatA = matA
        #bestMatB = matB
        #########################################################################
        # if you want the best RMSD, not CE Score uncomment here up
        #########################################################################

        #########################################################################
        # if you want a proven, "better" alignment use the CE-score instead
        # Uncomment here down for CE-Score
        #########################################################################
        internalGaps = 0.0
        for g in range(0, seqCount - 1):
            if (not curAlignment[g][0] + 1 == curAlignment[g + 1][0]):
                internalGaps += curAlignment[g + 1][0]
            if (not curAlignment[g][1] + 1 == curAlignment[g + 1][1]):
                internalGaps += curAlignment[g + 1][1]

            aliLen = float(len(curAlignment))
            numGap = internalGaps
            curScore = float((curScore / aliLen) * (1.0 + (numGap / aliLen)))

        if (curScore < bestPathScore):
            bestPathScore = curScore
            bestMatA = matA
            bestMatB = matB
        #########################################################################
        # if you want a proven, "better" alignment use the CE-score instead
        # Uncomment here UP for CE-Score
        #########################################################################

    # align the best one string
    simpAlign(bestMatA,
              bestMatB,
              mol1,
              mol2,
              stored.mol1,
              stored.mol2,
              align=1,
              L=len(bestMatA))
Пример #26
0
def fSumWSC(molecule, SGNameAngle, chain, residue, DieElecSC, SCchargeASP,
            SCchargeGLU, SCchargeOXT, SCchargeARG, SCchargeHIS, SCchargeLYS,
            SCchargeMET1, printSC):
    SumWSC = 0.0
    SGnameselect = "/" + SGNameAngle + "//" + "/" + "/SG"
    # Sidechain ASP
    nameselect = "/" + molecule + " and resn ASP and name CG and not resi " + residue
    cmd.select("SC", nameselect)
    SClist = cmd.identify("SC")
    for i in range(len(SClist)):
        ResDist = cmd.dist(residue + 'distASP', SGnameselect,
                           molecule + " and id " + str(SClist[i]))
        WSC = fWSC(SCchargeASP, DieElecSC, ResDist)
        SumWSC = SumWSC + WSC
        if printSC == 'yes':
            print("SC ASP ", str(SClist[i]), " ", SCchargeASP, " ", DieElecSC,
                  " ", ResDist, " ", WSC)
    cmd.delete(residue + 'distASP')
    # Sidechain GLU
    nameselect = "/" + molecule + " and resn GLU and name CD and not resi " + residue
    cmd.select("SC", nameselect)
    SClist = cmd.identify("SC")
    for i in range(len(SClist)):
        ResDist = cmd.dist(residue + 'distGLU', SGnameselect,
                           molecule + " and id " + str(SClist[i]))
        WSC = fWSC(SCchargeGLU, DieElecSC, ResDist)
        SumWSC = SumWSC + WSC
        if printSC == 'yes':
            print("SC GLU ", str(SClist[i]), " ", SCchargeGLU, " ", DieElecSC,
                  " ", ResDist, " ", WSC)
    cmd.delete(residue + 'distGLU')
    # print "GLU", cmd.count_atoms("SC"), SumWSC
    # Sidechain OXT
    nameselect = "/" + molecule + " and byres name OXT and not resi " + residue
    cmd.select("SC", nameselect)
    cmd.select("SC", "SC and name C")
    SClist = cmd.identify("SC")
    for i in range(len(SClist)):
        ResDist = cmd.dist(residue + 'distOXT', SGnameselect,
                           molecule + " and id " + str(SClist[i]))
        WSC = fWSC(SCchargeOXT, DieElecSC, ResDist)
        SumWSC = SumWSC + WSC
        if printSC == 'yes':
            print("SC OXT ", str(SClist[i]), " ", SCchargeOXT, " ", DieElecSC,
                  " ", ResDist, " ", WSC)
    cmd.delete(residue + 'distOXT')
    # print "OXT", cmd.count_atoms("SC"), SumWSC
    # Sidechain ARG
    nameselect = "/" + molecule + " and resn ARG and name CZ and not resi " + residue
    cmd.select("SC", nameselect)
    SClist = cmd.identify("SC")
    for i in range(len(SClist)):
        ResDist = cmd.dist(residue + 'distARG', SGnameselect,
                           molecule + " and id " + str(SClist[i]))
        WSC = fWSC(SCchargeARG, DieElecSC, ResDist)
        SumWSC = SumWSC + WSC
        if printSC == 'yes':
            print("SC ARG ", str(SClist[i]), " ", SCchargeARG, " ", DieElecSC,
                  " ", ResDist, " ", WSC)
    cmd.delete(residue + 'distARG')
    # print "ARG", cmd.count_atoms("SC"), SumWSC
    # Sidechain HIS
    nameselect = "/" + molecule + " and resn HIS and name CD2 and not resi " + residue
    cmd.select("SC", nameselect)
    SClist = cmd.identify("SC")
    for i in range(len(SClist)):
        ResDist = cmd.dist(residue + 'distHIS', SGnameselect,
                           molecule + " and id " + str(SClist[i]))
        WSC = fWSC(SCchargeHIS, DieElecSC, ResDist)
        SumWSC = SumWSC + WSC
        if printSC == 'yes':
            print("SC HIS ", str(SClist[i]), " ", SCchargeHIS, " ", DieElecSC,
                  " ", ResDist, " ", WSC)
    cmd.delete(residue + 'distHIS')
    # print "HIS", cmd.count_atoms("SC"), SumWSC
    # Sidechain LYS
    nameselect = "/" + molecule + " and resn LYS and name NZ and not resi " + residue
    cmd.select("SC", nameselect)
    SClist = cmd.identify("SC")
    for i in range(len(SClist)):
        ResDist = cmd.dist(residue + 'distLYS', SGnameselect,
                           molecule + " and id " + str(SClist[i]))
        WSC = fWSC(SCchargeLYS, DieElecSC, ResDist)
        SumWSC = SumWSC + WSC
        if printSC == 'yes':
            print("SC LYS ", str(SClist[i]), " ", SCchargeLYS, " ", DieElecSC,
                  " ", ResDist, " ", WSC)
    cmd.delete(residue + 'distLYS')
    # print "LYS", cmd.count_atoms("SC"), SumWSC
    # Sidechain MET1
    nameselect = "/" + molecule + " and resn MET and res 1 and not resi " + residue
    cmd.select("SC", nameselect)
    cmd.select("SC", "SC and name N")
    SClist = cmd.identify("SC")
    for i in range(len(SClist)):
        ResDist = cmd.dist(residue + 'distMET1', SGnameselect,
                           molecule + " and id " + str(SClist[i]))
        WSC = fWSC(SCchargeMET1, DieElecSC, ResDist)
        SumWSC = SumWSC + WSC
        if printSC == 'yes':
            print("SC MET1 ", str(SClist[i]), " ", SCchargeMET1, " ",
                  DieElecSC, " ", ResDist, " ", WSC)
    cmd.delete(residue + 'distMET1')
    # print "MET1", cmd.count_atoms("SC"), SumWSC
    cmd.delete("SC")
    return SumWSC
Пример #27
0
def getrange(sel):
    minid = min(cmd.identify(sel, 0))
    maxid = max(cmd.identify(sel, 0))
    print(str(minid) + '-' + str(maxid))
Пример #28
0
 def getAtoms(self, selection="(all)"):
     return cmd.identify(selection, 0)
Пример #29
0
def rpcIdentify(what='all', mode=0):
    """ returns the results of cmd.identify(what,mode) """
    return cmd.identify(what, mode=mode)
Пример #30
0
def print_dihedrals(selection='sele',
                    state=1,
                    quiet=1,
                    ss='',
                    fc=10.0,
                    chi=0,
                    label='ID'):
    '''
DESCRIPTION

    "print_dihedrals" return the phi, psi, and chi1 angles for a protein atom
    selection.

ARGUMENTS

    state = integer: object state {default: 1}

    selection = string: atom selection {default: all}

    amber = integer: generate AMBER rst file {default: 1;ON}

    label = string: label type ('ID' or 'index') {default: ID}

    fc = float: force constant for the dihedral angles {default: 10.0}

    chi = 0: Do not print chi angles (default)
    chi = 1: print chi1 dihedral angle (if exists)
    chi = 2: print chi1 and chi2 dihedral angles (if exists) (not implemented yet)

SEE ALSO

    phipsi
    '''
    # selectionからCalpha原子のIDリストを取得
    chi = int(chi)
    caindex = []
    cmd.iterate('bycalpha (%s)' % selection,
                'caindex.append(ID)',
                space=locals())
    # Calpha原子が属する残基ごとに処理を行う
    for ca in caindex:
        # resinameに残基名のみ取得
        n_sele = "((byres ID %s) & name N)" % ca
        c_sele = "((byres ID %s) & name C)" % ca
        ca_sele = "((byres ID %s) & name CA)" % ca
        cb_sele = "((byres ID %s) & name CB)" % ca

        resiname_sele = []
        cmd.iterate(ca_sele, "resiname_sele.append(resn)", space=locals())
        resiname = str(resiname_sele[0])

        if resiname == 'ILE' or resiname == 'VAL':
            cg_sele = "((byres ID %s) & name CG1)" % ca
        elif resiname == 'THR':
            cg_sele = "((byres ID %s) & name OG1)" % ca
        elif resiname == 'CYS' or resiname == 'CYX':
            cg_sele = "((byres ID %s) & name SG)" % ca
        else:
            cg_sele = "((byres ID %s) & name CG)" % ca

        cm_sele = "((neighbor (%s)) and not (byres (%s)))" % (n_sele, n_sele
                                                              )  #前の残基のC
        np_sele = "((neighbor (%s)) and not (byres (%s)))" % (c_sele, c_sele
                                                              )  #次の残基のN
        cmd.feedback("push")
        cmd.feedback("disable", "selector", "everything")
        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)
        cb_cnt = cmd.select("_pp_cb", cb_sele)
        cg_cnt = cmd.select("_pp_cg", cg_sele)
        np_cnt = cmd.select("_pp_np", np_sele)

        # 残基名+残基番号取得(ASP704みたいな)
        rname = []
        cmd.iterate(ca_sele, "rname.append(resn+resi)", space=locals())

        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
        if (n_cnt and ca_cnt and cb_cnt and cg_cnt):
            chi1 = cmd.get_dihedral("_pp_cg", "_pp_cb", "_pp_ca", "_pp_n")
        else:
            chi1 = None

        atomdict = {}
        strings = [
            "_pp_cm", "_pp_n", "_pp_c", "_pp_ca", "_pp_cb", "_pp_np", "_pp_cg"
        ]
        for i in strings:
            temp = cmd.identify(i)
            # tempが空リストでなければatomdictに追加
            if temp:
                atomdict[i] = temp[0]

        # phi, psi用に制限を設ける
        # 引数でssが指定されている場合、その範囲になるよう設定
        def phir2limit(x, sigma, ss):
            if ss == '':
                val = x - sigma
                if val <= -180.0:
                    val = -180.0
                return val
            elif ss == 'alpha':
                val = -80.0
                return val
            elif ss == 'beta':
                val = -155.0
                return val

        def phir3limit(x, sigma, ss):
            if ss == '':
                val = x + sigma
                if val >= 180.0:
                    val = 180.0
                return val
            elif ss == 'alpha':
                val = -50.0
                return val
            elif ss == 'beta':
                val = -125.0
                return val

        def psir2limit(x, sigma, ss):
            if ss == '':
                val = x - sigma
                if val <= -180.0:
                    val = -180.0
                return val
            elif ss == 'alpha':
                val = -55.0
                return val
            elif ss == 'beta':
                val = 115.0
                return val

        def psir3limit(x, sigma, ss):
            if ss == '':
                val = x + sigma
                if val >= 180.0:
                    val = 180.0
                return val
            elif ss == 'alpha':
                val = -25.0
                return val
            elif ss == 'beta':
                val = 145.0
                return val

        def r2limit(x, sigma):
            val = x - sigma
            if val <= -180.0:
                val = -180.0
            return val

        def r3limit(x, sigma):
            val = x + sigma
            if val >= 180.0:
                val = 180.0
            return val

        if phi is not None:
            print('''# {6} phi
&rst iat=  {0},  {1},  {2},  {3},
r1=-180.0, r2={4:.2f}, r3={5:.2f}, r4= 180.0,
rk2= {7}, rk3= {7},\n/'''.format(int(atomdict['_pp_c']),
                                 int(atomdict['_pp_ca']),
                                 int(atomdict['_pp_n']),
                                 int(atomdict['_pp_cm']),
                                 phir2limit(phi, 10.0, ss),
                                 phir3limit(phi, 10.0, ss), str(rname[0]),
                                 float(fc)))
        if psi is not None:
            print('''# {6} psi
&rst iat=  {0},  {1},  {2},  {3},
r1=-180.0, r2={4:.2f}, r3={5:.2f}, r4= 180.0,
rk2= {7}, rk3= {7},\n/'''.format(int(atomdict['_pp_np']),
                                 int(atomdict['_pp_c']),
                                 int(atomdict['_pp_ca']),
                                 int(atomdict['_pp_n']),
                                 psir2limit(psi, 10.0, ss),
                                 psir3limit(psi, 10.0, ss), str(rname[0]),
                                 float(fc)))
        if (chi > 0) and (chi1 is not None):
            print('''# {6} chi1
&rst iat=  {0},  {1},  {2},  {3},
r1=-180.0, r2={4:.2f}, r3={5:.2f}, r4= 180.0,
rk2= {7}, rk3= {7},\n/'''.format(int(atomdict['_pp_cg']),
                                 int(atomdict['_pp_cb']),
                                 int(atomdict['_pp_ca']),
                                 int(atomdict['_pp_n']), r2limit(chi1, 10.0),
                                 r3limit(chi1,
                                         10.0), str(rname[0]), float(fc)))