ColorByGroup: Difference between revisions

From PyMOLWiki
Jump to navigation Jump to search
(Created page with "{{Infobox script-repo |type = script |author = Zhenting Gao }} == Introduction == Color the objects by their groups. == Usage == *Open PyMOL *Load PD...")
 
 
(One intermediate revision by the same user not shown)
Line 23: Line 23:
== The Code ==
== The Code ==
<source>
<source>
def colorByGroup():
def colorByGroup(palette="rainbow"):
#Based on: https://pymolwiki.org/index.php/Get_Names#ARGUMENTS
#Based on: https://pymolwiki.org/index.php/Get_Names#ARGUMENTS
#Author: Zhenting Gao (zhentgpicasa@gmail.com)
#Author: Zhenting Gao (zhentgpicasa@gmail.com)
#Update: 11/12/2018
#Update: 11/12/2018
#Aim: Color atoms of a binding site based on their distance from a point
#Aim: Color the objects by their groups.
# returns the length of the distance between atom A and atom B
# returns the length of the distance between atom A and atom B
groups=cmd.get_names("group_objects")
groups=cmd.get_names("group_objects")
Line 33: Line 33:
import math
import math
for x in range(numClusters):
for x in range(numClusters):
colorCode=x*int(math.floor(255/numClusters))
cmd.alter(groups[x],"b="+str(x))
util.cba(colorCode,groups[x])
cmd.spectrum( "b", palette, " ".join(groups))
print(colorCode,groups[x])
#https://pymolwiki.org/index.php/Spectrum
cmd.extend('colorByGroup', colorByGroup)
cmd.extend('colorByGroup', colorByGroup)
</source>
</source>

Latest revision as of 04:54, 12 November 2018

Type Python Script
Download
Author(s) Zhenting Gao
License

Introduction

Color the objects by their groups.

Usage

  • Open PyMOL
  • Load PDB files, create groups
  • run this Python script inside PyMOL
  • call the function
    • colorByGroup

Required Arguments

Text

Optional Arguments

Text

Examples

Text

The Code

def colorByGroup(palette="rainbow"):
	#Based on: https://pymolwiki.org/index.php/Get_Names#ARGUMENTS
	#Author: Zhenting Gao (zhentgpicasa@gmail.com)
	#Update: 11/12/2018
	#Aim: Color the objects by their groups.
	# returns the length of the distance between atom A and atom B
	groups=cmd.get_names("group_objects")
	numClusters=len(groups)
	import math
	for x in range(numClusters):
		cmd.alter(groups[x],"b="+str(x))
	cmd.spectrum( "b", palette, " ".join(groups))
	#https://pymolwiki.org/index.php/Spectrum
cmd.extend('colorByGroup', colorByGroup)