def colorbyB(selection="spheres",first=7,last=3): # Author: Scott Dixon cols = [(0.,0.,1.),(.5,.5,1.),(.8,.8,1.),(1.,1.,1.), (1.,.9,.9),(1.,.6,.6),(1.,0.,0.)] nbins = len(cols) incr = float(first-last)/nbins for i in range(nbins): cname = "_spcol%03d"%i cmd.set_color(cname,cols[i]) b = first - i*incr cmd.color(cname,"((%s) and not(b > %f) and b > %f)"%(selection,b,b-incr))
def colorbyB(selection="spheres", first=7, last=3): # Author: Scott Dixon cols = [(0., 0., 1.), (.5, .5, 1.), (.8, .8, 1.), (1., 1., 1.), (1., .9, .9), (1., .6, .6), (1., 0., 0.)] nbins = len(cols) incr = float(first - last) / nbins for i in range(nbins): cname = "_spcol%03d" % i cmd.set_color(cname, cols[i]) b = first - i * incr cmd.color( cname, "((%s) and not(b > %f) and b > %f)" % (selection, b, b - incr))
def rainbow(selection="(name ca and alt '',A)",reverse=0,_self=cmd): pymol=_self._pymol cmd=_self # NOT THREAD SAFE cmd.feedback("push") cmd.feedback("disable","executive","actions") # your basic rainbow... list = [ (0,0,255), (0,0,255), (0,128,255), (0,255,255), (0,255,128), (0,255,0), (128,255,0), (255,255,0), (255,128,0), (255,0,0), (255,0,0) ] if reverse: list.reverse() # last = list.pop(0) cmd.set_color("_000",[last[0]/255.0,last[1]/255.0,last[2]/255.0]) c = 1 for a in list: for b in range(1,21): b0 = b/20.0 b1 = 1.0-b0 cname = "_%03d"%c r = last[0]*b1+a[0]*b0 g = last[1]*b1+a[1]*b0 b = last[2]*b1+a[2]*b0 cmd.set_color(cname,[r/255.0,g/255.0,b/255.0]) c = c + 1 last = a cas = cmd.index("((byres ("+selection+")) and name ca and not het)") l = len(cas) if not len(cas): return c = 0 for a in cas: col = int((200*c)/l) cmd.color("_%03d"%col,"((%s) and (byres %s`%d))"%(selection,a[0],a[1])) c = c + 1 cmd.feedback("pop")
def apply_gradient(selection, start_color='blue', end_color='yellow'): """ This function applies a gradient to the selection. It works with either a string color name which exists in the PyMOL color index, or custom RGB values. """ deltas = [] for r, d in selection: deltas.append(d) #Get the dynamic range of the deltas delta_min = min(deltas) delta_dynrange = max(deltas) - delta_min #Create a dictionary of colors from PyMOL color_dict = {} for col, num in cmd.get_color_indices(): color_dict[col] = cmd.get_color_tuple(num) #Get the RGB values of the start color try: int(start_color[0]) except ValueError: start_rgb = color_dict[start_color] else: start_rgb = start_color #Get the RGB values of the end color try: int(end_color[0]) except ValueError: end_rgb = color_dict[end_color] else: end_rgb = end_color #Get the dynamic range for RGB values rgb_dynrange = [] for i in range(3): rgb_dynrange.append(end_rgb[i]-start_rgb[i]) print(rgb_dynrange) #Apply the coloring to each residue in the selection tick = 0 for r, d in selection: cmd.select(name='gradient', selection='resi {0}'.format(r)) change = (d - delta_min) / delta_dynrange res_red = start_rgb[0] + change * rgb_dynrange[0] res_gre = start_rgb[1] + change * rgb_dynrange[1] res_blu = start_rgb[2] + change * rgb_dynrange[2] cmd.set_color('grad{0}'.format(tick), [res_red, res_gre, res_blu]) cmd.color('grad{0}'.format(tick), 'gradient') tick += 1
def rot_color(vals): nbins = 10 vals.sort(key=lambda x:x[1]) # print "End sort: "+str(len(vals))+" : "+str(nbins) # Coloring scheme... j = 0 rgb = [0.0,0.0,0.0] sel_str = "" for i in range(len(vals)): if int(len(vals)/nbins) == 0 or i % int(len(vals)/nbins) == 0: hsv = (colorsys.TWO_THIRD - colorsys.TWO_THIRD * float(j) / (nbins-1), 1.0, 1.0) #convert to rgb and append to color list rgb = colorsys.hsv_to_rgb(hsv[0],hsv[1],hsv[2]) if j < nbins-1: j += 1 cmd.set_color("RotProbColor"+str(i), rgb) cmd.color("RotProbColor"+str(i), str(vals[i][0]))
def convert_color_RGB(colorr): ''' RGB colores are not defined in pymol. convert_color_RBG function defines RGB colors Input : '#3300FF' Output : "RGB_blue" ( which we have defined to be [51 , 0 , 255] ) ''' cmd.set_color( 'RGB_blue' , [51 , 0 , 255] ) cmd.set_color( 'RGB_green' , [51 , 153 , 51] ) cmd.set_color( 'RGB_Lblue' , [51 , 153 , 255] ) cmd.set_color( 'RGB_grey' , [128 , 128 , 128] ) cmd.set_color( 'RGB_brown' , [139 , 69 , 19] ) cmd.set_color( 'RGB_purple' , [153 , 30 , 255] ) cmd.set_color( 'RGB_gold' , [205 , 173 , 0] ) cmd.set_color( 'RGB_red' , [255 , 0 , 51] ) cmd.set_color( 'RGB_orange' , [255 , 102 , 0] ) if colorr == "#3300FF": return "RGB_blue" elif colorr == "#339933": return "RGB_green" elif colorr == "#3399FF": return "RGB_Lblue" elif colorr == "#808080": return "RGB_grey" elif colorr == "#8B4513": return "RGB_brown" elif colorr == "#991EFF": return "RGB_purple" elif colorr == "#CDAD00": return "RGB_gold" elif colorr == "#FF0033": return "RGB_red" elif colorr == "#FF6600": return 'RGB_orange' else: return ''
import cmd import csv #f = open("coloring.csv", "rb") #reader = csv.reader(f, delimiter=",") #cmd.set_color(a, [0.00 , 0.53 , 0.22]) #cmd.set_color dblue= [0.05 , 0.19 , 0.57] cmd.color( 'gren' , "4QS1 and resi 71-280") cmd.set_color( 'gren' , [51 , 70 , 255] )
# Default representations cmd.hide("everything","all") cmd.show("ribbon","all") cmd.show("spheres","resn N06 or resn N15 or resn E40 or resn EST") # Create a list of unique trajectories loaded by parsing the command line unique = [arg[:-4] for arg in sys.argv if arg.endswith(".pdb")] # Go through each trajecotry models = cmd.get_names("all") for i, u in enumerate(unique): traj = [m for m in models if "_".join(m.split("_")[:-1]) == u] # Go through each step in the trajectory num_steps = float(len(traj)) for j, t in enumerate(traj): # Determine rgb of new color fx = j/num_steps color_list = color_gradients[i](fx) # Create a new color color_name = "col%s%i" % (u,j) cmd.set_color(color_name,color_list) # Apply the color to step j of trajectory u cmd.color(color_name,t)
def convert_color_RGB(colorr): ''' RGB colors are not defined in pymol. convert_color_RBG function defines RGB colors Input : '#3300FF' Output : "RGB_blue" ( which we have defined to be [51 , 0 , 255] ) ''' cmd.set_color('RGB_blue', [51, 0, 255]) cmd.set_color('RGB_green', [51, 153, 51]) cmd.set_color('RGB_Lblue', [51, 153, 255]) cmd.set_color('RGB_grey', [128, 128, 128]) cmd.set_color('RGB_brown', [139, 69, 19]) cmd.set_color('RGB_purple', [153, 30, 255]) cmd.set_color('RGB_gold', [205, 173, 0]) cmd.set_color('RGB_red', [255, 0, 51]) cmd.set_color('RGB_orange', [255, 102, 0]) if colorr == "#3300FF": return "RGB_blue" elif colorr == "#339933": return "RGB_green" elif colorr == "#3399FF": return "RGB_Lblue" elif colorr == "#808080": return "RGB_grey" elif colorr == "#8B4513": return "RGB_brown" elif colorr == "#991EFF": return "RGB_purple" elif colorr == "#CDAD00": return "RGB_gold" elif colorr == "#FF0033": return "RGB_red" elif colorr == "#FF6600": return 'RGB_orange' else: return 'white'
color_gradients = [a, b, c] # Default representations cmd.hide("everything", "all") cmd.show("ribbon", "all") cmd.show("spheres", "resn N06 or resn N15 or resn E40 or resn EST") # Create a list of unique trajectories loaded by parsing the command line unique = [arg[:-4] for arg in sys.argv if arg.endswith(".pdb")] # Go through each trajecotry models = cmd.get_names("all") for i, u in enumerate(unique): traj = [m for m in models if "_".join(m.split("_")[:-1]) == u] # Go through each step in the trajectory num_steps = float(len(traj)) for j, t in enumerate(traj): # Determine rgb of new color fx = j / num_steps color_list = color_gradients[i](fx) # Create a new color color_name = "col%s%i" % (u, j) cmd.set_color(color_name, color_list) # Apply the color to step j of trajectory u cmd.color(color_name, t)
def colors(scheme="",_self=cmd): pymol=_self._pymol cmd=_self if scheme=="jmol": cmd.set("auto_color",0) cmd.set_color("hydrogen",[1.000,1.000,1.000]) cmd.set_color("carbon",[0.567,0.567,0.567]) cmd.set_color("nitrogen",[0.189,0.315,0.976]) cmd.set_color("oxygen",[1.000,0.051,0.051]) cmd.set_color("fluorine",[0.567,0.882,0.314]) cmd.set_color("sulfur",[1.000,1.000,0.189]) cmd.color("carbon","elem c") cmd.recolor()