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...')
 
m (core command)
 
(3 intermediate revisions by 2 users not shown)
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.
Line 9: Line 11:
 
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 =
Line 30: Line 32:
 
= 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 64:
 
 
 
"""
 
"""
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)

Latest revision as of 06: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)