This is a read-only mirror of pymolwiki.org

Difference between revisions of "Center of mass"

From PyMOL Wiki
Jump to navigation Jump to search
Line 1: Line 1:
Here is a script that calculates the center of mass from a selection. It gets hold of the coordinates with cmd.get_model.
+
Here is a script that calculates the center of mass from a selection.  
 +
It gets hold of the coordinates with cmd.get_model.
 
Make sure the atoms in the selection are of equal weight.  
 
Make sure the atoms in the selection are of equal weight.  
  
 +
For a sample application, see: [http://yggdrasil.biotec.tu-dresden.de/abac/b.47.1.2___b.16.1.1___g.4.1.1.html "Convergent Evolution Examples"]
  
 +
<source lang="python">
 +
## Author: Andreas Henschel 2006
  
<source lang="python">
 
 
from pymol import cmd
 
from pymol import cmd
 
from pymol.cgo import *
 
from pymol.cgo import *

Revision as of 17:47, 20 April 2007

Here is a script that calculates the center of mass from a selection. It gets hold of the coordinates with cmd.get_model. Make sure the atoms in the selection are of equal weight.

For a sample application, see: "Convergent Evolution Examples"

## Author: Andreas Henschel 2006

from pymol import cmd
from pymol.cgo import *

def centerOfMass(selection):
   ## assumes equal weights (best called with "and name ca" suffix)
   model = cmd.get_model(selection)
   x,y,z=0,0,0
   for a in model.atom:
       x+= a.coord[0]
       y+= a.coord[1]
       z+= a.coord[2]
   return (x/len(model.atom), y/len(model.atom), z/len(model.atom))

cmd.load("/group/bioinf/Data/PDBLinks/1c7c.pdb")
cmd.select("domain", "/1c7c//A/143-283/ and name ca") ## selecting a domain

domainCenter=centerOfMass("domain")

print "Center of mass: (%.1f,%.1f,%.1f)"% domainCenter
cmd.as("cartoon", "all")
cmd.show("spheres", "domain")

## Creating a sphere CGO
com = [COLOR, 1.0, 1.0, 1.0, SPHERE]+list(domainCenter) + [3.0] ## white sphere with 3A radius
cmd.load_cgo(com, "CoM")

cmd.zoom("1c7c", 1.0)
cmd.center("domain")

#ah@bioinfws19:~/Projects/PyMOL$ pymol -qc centerOfMass4.py
#Center of mass: (-1.0,24.5,48.2)
#ah@bioinfws19:~/Projects/PyMOL$