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/] , 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


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())


        return tuple(np.average(xyz, 0))

def GetListOfFiles (filename):

    l = []

    for line in fileinput.input( filename ):

        tokens = line.split( )


    return l

def Calculate_COM (list):

    for i in range (len(list)):

        print list[i][0]


        if (X<101):

            os.system("cp ./dockout/F"+ str(X).zfill(2)+ " ./lig.pdb")

            for pdb in glob.glob("lig.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")




listofFiles = GetListOfFiles ("./out")

print listofFiles


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