This is a read-only mirror of pymolwiki.org

Difference between revisions of "AlphaToAll"

From PyMOL Wiki
Jump to navigation Jump to search
m (4 revisions)
m (core command)
Line 1: Line 1:
 +
'' '''alphatoall''' (all lower case) is a core command since PyMOL 1.7.2''
 +
 
= Overview =
 
= 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.
 
[[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.

Revision as of 10:45, 25 February 2019

alphatoall (all lower case) is a core command since PyMOL 1.7.2

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)