Difference between revisions of "AlphaToAll"

From PyMOLWiki
Jump to navigation Jump to search
(Created page with '= Overview = AlphaToAll will expand the alpha-carbon property that you specify to all atoms in the residues. For example, if you set the b-factor column to some different va...')
 
Line 9: Line 9:
 
Image:Alphac1.png|This script will fix that, expanding the color attribute to the rest of the atoms.
 
Image:Alphac1.png|This script will fix that, expanding the color attribute to the rest of the atoms.
 
</gallery>
 
</gallery>
</center>?
+
</center>
  
 
= Usage =
 
= Usage =

Revision as of 15:41, 29 June 2009

Overview

AlphaToAll will expand the alpha-carbon property that you specify to all atoms in the residues. For example, if you set the b-factor column to some different value for all alpha carbons, this script will propagate those values into all the atoms as well.

In the example below, notice the color of the sticks.

Usage

# expand propertyName in objName on all the alpha carbons
# to every atom, for each residue
alphaToAll objName, propertyName

# Example #1
# For all objects, for each residue, set every atom's b-column value
# to match that residue's alpha carbon's b-column value.
alphaToAll *, b

# Example #2
# For selection 1qox and c. A expand the alpha carbon
# colors to all atoms in the selection
alphaToAll 1qox and c. A, color

The Code

import pymol
from pymol import stored


def alphaToAll(sel, col="b",forceRebuild=False):
	"""
	alphaToAll -- expand any property of the alpha carbons to all atoms in the residue
	
	PARAMS
		sel
			The selection or object (include "*" for all objects) to operate on.  This will
			read the alpha carbon's "COL" property and expand that down to all atoms in the
			given residues in sel.
			
		col
			Any valid PyMOL property.  For example, 'b' or 'q' or 'color', etc.
			DEFAULT: b, for B-factor as we most often overwrite that column
			
		forceRebuild
			If a color changes, this will rebuild the objects for us.  For speed, we
			DEFAULT this to False.
			
	RETURNS
		None, just epxands the properties as dicsussed above.
		
	NOTES
		This script is useful for instances where we update the b-factor column for the
		alpha carbons and then want to expand that color to all atoms for smoother looking
		images.
		
	AUTHOR:
		Jason Vertrees, 2009.
			
	"""
	if sel=="*":
		names=cmd.get_names("objects")
	else:
		names=sel

	for sel in names:
		stored.x = []
		cmd.iterate(sel + " and n. CA", 'stored.x.append( [resi,%s] )' % col )
		for r,t in stored.x:
			cmd.alter( sel + " and i. %s" % r, "%s=%s" % (col,t))

		if forceRebuild != False:
			cmd.rebuild(sel)

cmd.extend("alphaToAll", alphaToAll)