https://pymolwiki.org/index.php?title=Cluster_Count&feed=atom&action=historyCluster Count - Revision history2024-03-28T12:55:26ZRevision history for this page on the wikiMediaWiki 1.35.7https://pymolwiki.org/index.php?title=Cluster_Count&diff=10986&oldid=prevMartinChristen: New script to get statistics on b-factors ~~~~2013-02-14T11:30:54Z<p>New script to get statistics on b-factors ~~~~</p>
<p><b>New page</b></p><div>= Overview =<br />
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".<br />
<br />
<br />
= Usage =<br />
<source lang="python"><br />
cluster_count object<br />
</source><br />
<br />
<br />
= Example =<br />
<source lang="python"><br />
cluster_count 1ubq<br />
<br />
#output on screen:<br />
<br />
Number of atoms in ' 1ubq ': 602<br />
Minimum and Maximum B-values: 2.0 42.75<br />
Average B-value: 13.4131063029<br />
Standard deviation of the B-values: 8.70767140923<br />
This data will be appended to cluster_count.txt<br />
<br />
#output in file cluster_count.txt; the format is:<br />
#objectname N minB maxB aveB stdevB<br />
1ubq 602 2.000 42.750 13.413 8.708<br />
</source><br />
<br />
<br />
= The Code =<br />
<source lang="python"><br />
<br />
# Script: cluster_count.py<br />
# Copyleft 2010 Martin Christen<br />
<br />
from pymol import cmd,stored<br />
def cluster_count(selection):<br />
<br />
"""<br />
AUTHOR<br />
<br />
Martin Christen<br />
<br />
DESCRIPTION<br />
<br />
This script calculates statistics on the B-values for all atoms in<br />
the selected object, prints the information on screen and appends<br />
it to the file "cluster_count.txt".<br />
<br />
Output format on screen:<br />
------------------------<br />
Number of atoms in 'selection': 0<br />
Minimum and Maximum B-values: 0.0<br />
Average B-value : 0.0<br />
Standard deviation of the B-values (best): 0.0 (0.0)<br />
This data will be appended to cluster_count.txt<br />
<br />
Output format in cluster_count.txt:<br />
-----------------------------------<br />
selection N minB maxB aveB stdevB<br />
<br />
EXAMPLE<br />
<br />
cluster_count 1ubq<br />
<br />
Number of atoms in ' 1ubq ': 602<br />
Minimum and Maximum B-values: 2.0 42.75<br />
Average B-value: 13.4131063029<br />
Standard deviation of the B-values: 8.70767140923<br />
This data will be appended to cluster_count.txt<br />
<br />
(in cluster_count.txt:)<br />
1ubq 602 2.000 42.750 13.413 8.708<br />
<br />
USAGE<br />
<br />
cluster_count selection<br />
<br />
"""<br />
<br />
# get list of B-factors from selection<br />
m = cmd.get_model(selection)<br />
sel = []<br />
b_list = []<br />
dummy = []<br />
for i in range(len(m.atom)):<br />
b_list.append(m.atom[i].b)<br />
<br />
#determine min and max<br />
try: max_b = max(b_list)<br />
except ValueError: max_b=0<br />
try: min_b = min(b_list)<br />
except ValueError: min_b=0<br />
<br />
#determine average<br />
try: average_b= float(sum(b_list)) / len(b_list)<br />
except ZeroDivisionError: average_b=0<br />
<br />
#determine standard deviation<br />
for i in range(len(m.atom)):<br />
if m.atom[i]>average_b:<br />
dummy.append((m.atom[i].b-average_b)**2)<br />
if m.atom[i]<average_b:<br />
dummy.append((average_b-m.atom[i].b)**2)<br />
try: stdev_b= (sum(dummy) / (len(m.atom)-1))**(1/2.0)<br />
except ZeroDivisionError: stdev_b=0<br />
<br />
#print values on screen<br />
print "Number of atoms in '", selection,"': ", len(b_list)<br />
print "Minimum and Maximum B-values: ", min_b, max_b<br />
print "Average B-value: ", average_b<br />
print "Standard deviation of the B-values: ", stdev_b<br />
print "This data will be appended to cluster_count.txt"<br />
<br />
#write information to cluster_count.txt<br />
f=open('cluster_count.txt','a')<br />
print >>f, '%-10s %8d %8.3f %8.3f %8.3f %8.3f' % (selection, len(m.atom), min_b, max_b, average_b, stdev_b)<br />
f.close()<br />
cmd.extend("cluster_count",cluster_count)<br />
</source><br />
<br />
[[Category:Script_Library]]<br />
[[Category:ObjSel_Scripts]]</div>MartinChristen