Every time you loop through the list of files, you set X=1 ; you do your X=X+1 
in a loop that will only run once ( because glob.glob(“lig.pdb”) is only going 
to return a list of length 1 that has lig.pdb) , so you set X=1 , then X=2, 
then back to X=1 before you process the next entry. That is why you are only 
processing the first file, probably doing so 100 times.

you probably want something like

with open(“out") as f:
    for line in f:
          in_pdb_file = line.strip()
          // code for processing in_pdb_file here

or

for X in range(1,101):
    in_pdb_file = “dockout/F"+ str(X).zfill(2)
   // code for processing in_pdb_file here


Generally, I would recommend strongly against using os.system for performing 
file operations. You should look into shutil.copy , shutil.move , and os.remove 


> On Oct 12, 2016, at 2:16 PM, Subha K <subhal...@gmail.com> wrote:
> 
> Hi There,
> 
> I am looking to automate the calculation of centre of mass and placing a 
> pseudo atom on the COM and save it as a pdb file . Going through the forum 
> [https://sourceforge.net/p/pymol/mailman/message/34458943/ 
> <https://sourceforge.net/p/pymol/mailman/message/34458943/>] , I found some 
> useful scripts for this, but, I am having trouble getting it done for all 
> files in a directory. My script does what I need for the first file alone. 
> Some looping or other is not correct. Or there could be an easy and better 
> way to do it. I couldn't figure that out.  So, could some one please help me 
> solve this?
> 
> I have 100 files F01, F02, F100 ... in the directory dockout. I would like to 
> calculate the COM and place a pseudo atom on the COM and save it as a pdb for 
> all the 100 files. 
> 'out' in the script corresponds to the list of all the 100 files.
> 
> import pymol
> from pymol import cmd
> pymol.finish_launching()
> import numpy as np
> import glob
> import fileinput
> def center(selection, com=True):
>     model = cmd.get_model(selection)
>     xyz = np.array(model.get_coord_list())
>     mass = [i.get_mass() for i in model.atom]
>     xyz_m = xyz * np.array([mass]).T
>     if com:
>         return tuple(np.sum(xyz_m, 0)/model.get_mass())
>     else:
>         return tuple(np.average(xyz, 0))
> 
> def GetListOfFiles (filename):
>     l = []
>     for line in fileinput.input( filename ):
>         tokens = line.split( )
>         l.append(tokens)
>     return l
> 
> def Calculate_COM (list):
>     for i in range (len(list)):
>         print list[i][0]
>         X=1
>         if (X<101):
>             os.system("cp ./dockout/F"+ str(X).zfill(2)+ " ./lig.pdb")
>             for pdb in glob.glob("lig.pdb"):
>                 cmd.load(pdb)
>                 COM = center('resn UNK')
>                 cmd.pseudoatom('ligCOM', pos=COM)
>                 cmd.save("complex_dummy.pdb", "all")
>                 os.system("mv complex_dummy.pdb complex_" + str(X).zfill(2) + 
> "_dummy.pdb")
>                 os.system("rm lig.pdb")
>                 X=X+1
>         else:
>             break
> listofFiles = GetListOfFiles ("./out")
> print listofFiles
> Calculate_COM(listofFiles)
> 
> 
> Thanks,
> Subha 
> 
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most 
> engaging tech sites, SlashDot.org! 
> http://sdm.link/slashdot_______________________________________________
> PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
> Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

Reply via email to