File: count_molecules.py

package info (click to toggle)
pymol 1.2r2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 38,716 kB
  • ctags: 23,006
  • sloc: ansic: 480,417; python: 70,953; cpp: 12,928; sh: 10,266; makefile: 530; csh: 21
file content (27 lines) | stat: -rw-r--r-- 713 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# This script illustrates how you can use PyMOL to count the
# number of molecules in a selection

cmd.load("$PYMOL_PATH/test/dat/1tii.pdb")

input_sele = "1tii and polymer"

prefix = "tmp_cnt_"

iter_sele = prefix + "iter"
mole_sele = prefix + "mole"

mole_cnt = 0

if cmd.select(iter_sele, input_sele)>0:
    while 1:
        atom_cnt = cmd.select(mole_sele, "bymol (first "+iter_sele+")")
        togo_cnt = cmd.select(iter_sele, iter_sele+" and not "+mole_sele)
        if atom_cnt>0:
            mole_cnt = mole_cnt + 1
            print "molecule %d contains %d atoms"%(mole_cnt,atom_cnt)
        if togo_cnt<=0:
            break
        

print "(%s) contains %d molecules total."%(input_sele, mole_cnt)