Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help
Special pages
SBGrid Resources
SBGrid Consortium
SBGrid Data Bank
Software Webinars
PyMOL Webinar
PyMOL Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
ColorByDistance
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== The Code == <source> 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) </source>
Summary:
Please note that all contributions to PyMOL Wiki are considered to be released under the GNU Free Documentation License 1.2 (see
PyMOL Wiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
ColorByDistance
(section)
Add topic