From: Subha K <sub...@gm...> - 2016-10-12 19:56:20
|
Thanks David and Tsjerk for the kind reply and suggestion. I Figured a solution by combining both of your suggestions 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)) with open("./out") as f: for line in f: in_pdb_file = line.strip() print in_pdb_file cmd.load(in_pdb_file, 'tmp') COM = center('resn UNK') cmd.pseudoatom('ligCOM', pos=COM) cmd.save(in_pdb_file[:-4] + "_dummy.pdb", "all") cmd.delete('ligCOM') cmd.delete('tmp') @Tsjerk: Don't know why I got an error: Selector-Error: Invalid selection name "pseudo". pseudo<-- Thanks again for the support. Best Regards, Subha On Wed, Oct 12, 2016 at 12:53 PM, Tsjerk Wassenaar <ts...@gm...> wrote: > > Hi Subha, > > Probably this will get close: > > for pdb in open('./out').readlines(): > pdb = pdb.strip() > cmd.load(pdb,'tmp') > cmd.pseudoatom('tmp',name='pseudo') > cmd.save(pdb[:-4]+'-pseudo.pdb','pseudo') > cmd.delete('tmp') > cmd.delete('pseudo') > > ... Just a bit too much for a oneliner ;) > > Hope it helps, > > Tsjerk > > > On Wed, Oct 12, 2016 at 8:16 PM, Subha K <sub...@gm...> 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/] , 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 (PyM...@li...) >> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users >> Archives: http://www.mail-archive.com/pym...@li... >> > > > > -- > Tsjerk A. Wassenaar, Ph.D. > > |