This is a read-only mirror of pymolwiki.org

Difference between revisions of "Cluster Count"

From PyMOL Wiki
Jump to navigation Jump to search
(New script to get statistics on b-factors ~~~~)
 
m (1 revision)
 
(No difference)

Latest revision as of 01:49, 28 March 2014

Overview

This script calculates statistics on the B-values for all atoms in the selected object, prints the information on screen and appends it to a file called "cluster_count.txt".


Usage

cluster_count object


Example

cluster_count 1ubq

#output on screen:

Number of atoms in ' 1ubq ':  602
Minimum and Maximum B-values:  2.0 42.75
Average B-value:  13.4131063029
Standard deviation of the B-values:  8.70767140923
This data will be appended to cluster_count.txt

#output in file cluster_count.txt; the format is:
#objectname N minB maxB aveB stdevB
1ubq            602    2.000   42.750   13.413    8.708


The Code

# Script: cluster_count.py
# Copyleft 2010 Martin Christen

from pymol import cmd,stored
def cluster_count(selection):

        """
 AUTHOR
 
 Martin Christen
 
 DESCRIPTION
 
 This script calculates statistics on the B-values for all atoms in
 the selected object, prints the information on screen and appends
 it to the file "cluster_count.txt".
 
 Output format on screen:
 ------------------------
 Number of atoms in 'selection': 0
 Minimum and Maximum B-values:  0.0
 Average B-value :  0.0
 Standard deviation of the B-values (best): 0.0 (0.0)
 This data will be appended to cluster_count.txt

 Output format in cluster_count.txt:
 -----------------------------------
 selection N minB maxB aveB stdevB

 EXAMPLE

 cluster_count 1ubq

 Number of atoms in ' 1ubq ':  602
 Minimum and Maximum B-values:  2.0 42.75
 Average B-value:  13.4131063029
 Standard deviation of the B-values:  8.70767140923
 This data will be appended to cluster_count.txt

 (in cluster_count.txt:)
 1ubq            602    2.000   42.750   13.413    8.708

 USAGE

 cluster_count selection

        """
	
# get list of B-factors from selection
	m = cmd.get_model(selection)
	sel = []
	b_list = []
	dummy = []
	for i in range(len(m.atom)):
		b_list.append(m.atom[i].b)

#determine min and max
	try: max_b = max(b_list)
	except ValueError: max_b=0
	try: min_b = min(b_list)
	except ValueError: min_b=0

#determine average
	try: average_b= float(sum(b_list)) / len(b_list)
	except ZeroDivisionError: average_b=0

#determine standard deviation
	for i in range(len(m.atom)):
		if m.atom[i]>average_b:
			dummy.append((m.atom[i].b-average_b)**2)
		if m.atom[i]<average_b:
			dummy.append((average_b-m.atom[i].b)**2)
	try: stdev_b= (sum(dummy) / (len(m.atom)-1))**(1/2.0)
	except ZeroDivisionError: stdev_b=0

#print values on screen
	print "Number of atoms in '", selection,"': ", len(b_list)
	print "Minimum and Maximum B-values: ", min_b, max_b
	print "Average B-value: ", average_b
	print "Standard deviation of the B-values: ", stdev_b
	print "This data will be appended to cluster_count.txt"

#write information to cluster_count.txt
	f=open('cluster_count.txt','a')
	print >>f, '%-10s %8d %8.3f %8.3f %8.3f %8.3f' % (selection, len(m.atom), min_b, max_b, average_b, stdev_b)
	f.close()
cmd.extend("cluster_count",cluster_count)