Radius of gyration: Difference between revisions
Jump to navigation
Jump to search
(example) |
mNo edit summary |
||
Line 40: | Line 40: | ||
[[File:Radius_of_gyration_Example.png|300px|thumb|right]] | [[File:Radius_of_gyration_Example.png|300px|thumb|right]] | ||
This example | This example uses the radius of gyration and the [[Center_Of_Mass|center of mass]] to display a semitransparent sphere. | ||
<source lang="python"> | <source lang="python"> | ||
from pymol import cmd, stored, util | from pymol import cmd, stored, util | ||
import centerOfMass, | import centerOfMass, radiusOfGyration | ||
cmd.set('sphere_transparency', 0.5) | cmd.set('sphere_transparency', 0.5) | ||
Line 52: | Line 52: | ||
cmd.show('cartoon', 'chain A') | cmd.show('cartoon', 'chain A') | ||
stored.gyradius = | stored.gyradius = radiusOfGyration.rgyrate('chain A and polymer') | ||
centerOfMass.com('chain A and polymer', object='com') | centerOfMass.com('chain A and polymer', object='com') | ||
cmd.alter('last com', 'vdw=stored.gyradius') | cmd.alter('last com', 'vdw=stored.gyradius') |
Revision as of 13:58, 31 March 2011
This script does calcualate the radius of gyration of a molecule.
Thanks to Tsjerk Wassenaar for posting this script on the pymol-users mailing list!
from pymol import cmd
from itertools import izip
import math
def rgyrate(selection='(all)', quiet=1):
'''
DESCRIPTION
Radius of gyration
USAGE
rgyrate [ selection ]
'''
quiet = int(quiet)
model = cmd.get_model(selection).atom
x = [i.coord for i in model]
mass = [i.get_mass() for i in model]
xm = [(m*i,m*j,m*k) for (i,j,k),m in izip(x,mass)]
tmass = sum(mass)
rr = sum(mi*i+mj*j+mk*k for (i,j,k),(mi,mj,mk) in izip(x,xm))
mm = sum((sum(i)/tmass)**2 for i in izip(*xm))
rg = math.sqrt(rr/tmass - mm)
if not quiet:
print "Radius of gyration: %.2f" % (rg)
return rg
cmd.extend("rgyrate", rgyrate)
# vi:expandtab
Example
This example uses the radius of gyration and the center of mass to display a semitransparent sphere.
from pymol import cmd, stored, util
import centerOfMass, radiusOfGyration
cmd.set('sphere_transparency', 0.5)
cmd.fetch('2xwu')
cmd.hide('everything')
cmd.show('cartoon', 'chain A')
stored.gyradius = radiusOfGyration.rgyrate('chain A and polymer')
centerOfMass.com('chain A and polymer', object='com')
cmd.alter('last com', 'vdw=stored.gyradius')
util.cbc()