This is a read-only mirror of pymolwiki.org

Difference between revisions of "ColorByDistance"

From PyMOL Wiki
Jump to navigation Jump to search
Line 28: Line 28:
 
#Update: 11/12/2018
 
#Update: 11/12/2018
 
#Aim: Color atoms of a binding site based on their distance from a point
 
#Aim: Color atoms of a binding site based on their distance from a point
 +
#May also refer to https://pymolwiki.org/index.php/Ramp_New#Ramp_.2B_Distance_Measure
 
# returns the length of the distance between atom A and atom B
 
# returns the length of the distance between atom A and atom B
  
Line 42: Line 43:
 
# create the pseudoatom at the origin
 
# create the pseudoatom at the origin
  
#pseudoatom pOrig, pos=(0,0,0), label=origin
+
cmd.pseudoatom("pOrig", anchor, label="origin")
  
 
# these are special PyMOL variables that will hold # the coordinates of  
 
# these are special PyMOL variables that will hold # the coordinates of  
Line 52: Line 53:
 
# copy the coordinates into those special variables  
 
# copy the coordinates into those special variables  
  
cmd.iterate_state(1, anchor, 'stored.origCoord.append((x,y,z))')
+
cmd.iterate_state(1, "pOrig", 'stored.origCoord.append((x,y,z))')
 
cmd.iterate_state(1, site, 'stored.distCoord.append((x,y,z))')
 
cmd.iterate_state(1, site, 'stored.distCoord.append((x,y,z))')
  
Line 62: Line 63:
  
 
stored.newB = map(lambda x,y: diff_len(x,y), stored.distCoord, stored.origCoord)
 
stored.newB = map(lambda x,y: diff_len(x,y), stored.distCoord, stored.origCoord)
print(stored.newB)
+
#print(stored.newB)
 
# put them into the b-factor of the protein
 
# put them into the b-factor of the protein
  
cmd.alter( "site", "b=stored.newB.pop(0)")
+
cmd.alter( site, "b=stored.newB.pop(0)")
  
 
# color by rainbow_rev or any other
 
# color by rainbow_rev or any other
Line 73: Line 74:
 
cmd.set("surface_color","-1",site) #color the surface of the binding site by corresponding atom colors
 
cmd.set("surface_color","-1",site) #color the surface of the binding site by corresponding atom colors
 
cmd.extend('colorByDistance', colorByDistance)
 
cmd.extend('colorByDistance', colorByDistance)
 
 
</source>
 
</source>

Revision as of 10:08, 12 November 2018

Type Python Script
Download
Author(s) Zhenting Gao
License

Introduction

Color the surface of a binding site by the distance to a specific atom.

Usage

  • Open PyMOL
  • Load PDB files
  • run this Python script inside PyMOL
  • call the function
    • colorByDistance anchor, bindingSite

Required Arguments

Text

Optional Arguments

Text

Examples

Text

The Code

def colorByDistance(anchor='anchor', site='site'):
	#Based on: https://pymolwiki.org/index.php/Spectrum#Intermediate
	#Author: Zhenting Gao (zhentgpicasa@gmail.com)
	#Update: 11/12/2018
	#Aim: Color atoms of a binding site based on their distance from a point
	#May also refer to https://pymolwiki.org/index.php/Ramp_New#Ramp_.2B_Distance_Measure
	# returns the length of the distance between atom A and atom B

	diff_len = lambda x,y : math.sqrt((x[0]-y[0])*(x[0]-y[0]) + (x[1]-y[1])*(x[1]-y[1]) + (x[2]-y[2])*(x[2]-y[2]))

	# fetch site from the PDB

	#fetch site, async=0

	# show it as surface

	#as surface

	# create the pseudoatom at the origin

	cmd.pseudoatom("pOrig", anchor, label="origin")

	# these are special PyMOL variables that will hold # the coordinates of 
	# the atoms and the  pseudoatom

	stored.origCoord = []
	stored.distCoord = []

	# copy the coordinates into those special variables 

	cmd.iterate_state(1, "pOrig", 'stored.origCoord.append((x,y,z))')
	cmd.iterate_state(1, site, 'stored.distCoord.append((x,y,z))')

	# extend origCoord to be the same length as the other

	stored.origCoord *= len(stored.distCoord)

	# calculate the distances

	stored.newB = map(lambda x,y: diff_len(x,y), stored.distCoord, stored.origCoord)
	#print(stored.newB)
	# put them into the b-factor of the protein

	cmd.alter( site, "b=stored.newB.pop(0)")

	# color by rainbow_rev or any other
	# palette listed in "help spectrum"

	cmd.spectrum(expression="b", palette="rainbow", selection=site)
	cmd.set("surface_color","-1",site) #color the surface of the binding site by corresponding atom colors
cmd.extend('colorByDistance', colorByDistance)