Average b

From PyMOLWiki
Revision as of 13:32, 6 November 2013 by Jaredsampson (talk | contribs) (code: adjusted string outputs to use string formatting instead of concatenation; adjusted whitespace around operators)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


  • calculate the average B-factor of a selection.


  • copy code to text file and save as average_b.py. Install via Plugin>Install plugin from within PyMOL.
  • restart PyMOL and then type "average_b (selection)"


Gregor Hagelueken


from pymol import cmd,stored
def average_b(selection):
	stored.tempfactor = 0
	stored.atomnumber = 0
	cmd.iterate(selection, "stored.tempfactor = stored.tempfactor + b")
	cmd.iterate(selection, "stored.atomnumber = stored.atomnumber + 1")
	print "Your selection: %s" % selection
	print "sum of B factors: %s" % stored.tempfactor
	print "number of atoms: %s" % stored.atomnumber
	averagetempfactor = stored.tempfactor / stored.atomnumber
	print "average B of '%s': %s" % (selection, averagetempfactor)
cmd.extend("average_b", average_b)