File: count_molecules.py

package info (click to toggle)
pymol 1.7.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 42,668 kB
  • ctags: 25,775
  • sloc: ansic: 494,779; python: 75,446; cpp: 20,088; makefile: 351; sh: 172; 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)