AlphaToAll: Difference between revisions

From PyMOLWiki
Jump to navigation Jump to search
No edit summary
(make multi-chain safe and support multiple properties)
Line 30: Line 30:
= The Code =
= The Code =
<source lang="python">
<source lang="python">
import pymol
from pymol import cmd, CmdException
from pymol import stored
 


def alphaToAll(sel, col="b",forceRebuild=False):
def alphaToAll(sel, col="b",forceRebuild=False):
Line 64: Line 62:
"""
"""
if sel=="*":
col = '(' + ','.join(col.split()) + ')'
names=cmd.get_names("objects")
space = {'props': dict()}
else:
cmd.iterate('byca (%s)' % (sel), 'props[model,segi,chain,resi] = ' + col, space=space)
names=[sel]
cmd.alter(sel, col + ' = props.get((model,segi,chain,resi), ' + col + ')', space=space)
 
if forceRebuild != False:
for sel in names:
cmd.rebuild(sel)
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)
cmd.extend("alphaToAll", alphaToAll)

Revision as of 07:39, 3 November 2011

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

from pymol import cmd, CmdException

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.
			
	"""
	col = '(' + ','.join(col.split()) + ')'
	space = {'props': dict()}
	cmd.iterate('byca (%s)' % (sel), 'props[model,segi,chain,resi] = ' + col, space=space)
	cmd.alter(sel, col + ' = props.get((model,segi,chain,resi), ' + col + ')', space=space)
	if forceRebuild != False:
		cmd.rebuild(sel)

cmd.extend("alphaToAll", alphaToAll)