Exemple #1
0
def color_structure(pdb_file):
    '''
	this function colors each nucleotide in pymol
	>>>print (data[1][0])
	2886_2897

	2QBG must match the name of pdb file which is open
	data[i][1] = color
	data[i][0] = range of nucleotide
	data[i][2] = chain

	'''
    pdb_file = pdb_file.upper()

    url = 'https://raw.githubusercontent.com/BGSU-RNA/3D-structure-coloring/master/csv_files/%s.csv' % pdb_file
    response = urllib2.urlopen(url)
    reader = csv.reader(response, delimiter=",")

    data = nt_ranges(reader)
    for i in range(0, len(data)):
        if (data[i][2]) != '':
            cmd.color(
                data[i][1], "%s and resi %s in chain %s" %
                (pdb_file, data[i][0], data[i][2]))
        elif (data[i][2]) == '':
            cmd.color(data[i][1], "%s and resi %s " % (pdb_file, data[i][0]))
def cmd_color(data):
	'''
	this function colors each nucleotide in pymol
	#print (data[1][0]) = 2886_2897	

	4QS1 must match the name of pdb file which is open 
	'''
	for i in range(0,len(data)-1):
		cmd.color(data[i][1], "%s and resi %s" % ( pdb_file , data[i][0]))
Exemple #3
0
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))
Exemple #4
0
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))
Exemple #5
0
def default(selection="(all)",_self=cmd):
    cmd=_self
    s = tmp_sele
    cmd.select(s,selection)
    _prepare(s,_self=cmd)
    cmd.show("lines",s)
    cmd.show("nonbonded",s)
    color=cmd.get_object_color_index(selection)
    if color<0:
        util.cbag(selection,_self=cmd)
    else:
        util.cnc(selection,_self=cmd)
        cmd.color(str(color),"("+s+") and elem c")
Exemple #6
0
def default(selection="(all)", _self=cmd):
    cmd = _self
    s = tmp_sele
    cmd.select(s, selection)
    _prepare(s, _self=cmd)
    cmd.show("lines", s)
    cmd.show("nonbonded", s)
    color = cmd.get_object_color_index(selection)
    if color < 0:
        util.cbag(selection, _self=cmd)
    else:
        util.cnc(selection, _self=cmd)
        cmd.color(str(color), "(" + s + ") and elem c")
Exemple #7
0
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()
Exemple #8
0
def color_objs(selection='(all)',quiet=1,_self=cmd):
    pymol=_self._pymol
    cmd=_self 
    '''
    Color all chains a different color
    '''
    c = 0
    for a in cmd.get_names('public_nongroup_objects',selection=selection):
	if (selection!='all') and (selection!='(all)'):
            cmd.color(_color_cycle[c],"(?%s and (%s))"%(a,selection),quiet=quiet)
        else:
            cmd.color(_color_cycle[c],"(?%s)"%(a),quiet=quiet)
        c = (c + 1) % _color_cycle_len
Exemple #9
0
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 color_structure(pdb_file):
	'''
	this function colors each nucleotide in pymol
	>>>print (data[1][0])
	2886_2897	

	2QBG must match the name of pdb file which is open 
	data[i][1] = color
	data[i][0] = range of nucleotide
	data[i][2] = chain

	'''
	data = nt_ranges(reader)
	for i in range(0,len(data)):
		if (data[i][2]) != '':
			cmd.color(data[i][1], "%s and resi %s in chain %s" % ( pdb_file, data[i][0], data[i][2]))
		elif(data[i][2]) == '':
			cmd.color(data[i][1], "%s and resi %s " % ( pdb_file, data[i][0]))
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]))
Exemple #13
0
def cba(color,selection="(all)",quiet=1,_self=cmd):
    pymol=_self._pymol
    cmd=_self
    s = str(selection)
    cmd.color("atomic","(("+s+") and not elem C)",quiet=quiet)
    cmd.color(color,"(elem C and ("+s+"))",quiet=quiet)
    cmd.color(color,s,flags=1,quiet=quiet)
def color_structure(pdb_file):
	'''
	this function colors each nucleotide in pymol
	>>>print (data[1][0])
	2886_2897	

	2QBG must match the name of pdb file which is open 
	data[i][1] = color
	data[i][0] = range of nucleotide
	data[i][2] = chain

	'''
	url = 'https://raw.githubusercontent.com/hmaryam/pymol/master/%s_coloring_info.csv' % pdb_file
	response = urllib2.urlopen(url)
	reader = csv.reader(response, delimiter=",")

	data = nt_ranges(reader)
	for i in range(0,len(data)):
		if (data[i][2]) != '':
			cmd.color(data[i][1], "%s and resi %s in chain %s" % ( pdb_file, data[i][0], data[i][2]))
		elif(data[i][2]) == '':
			cmd.color(data[i][1], "%s and resi %s " % ( pdb_file, data[i][0]))
Exemple #15
0
def cbss(selection="(all)",helix_color="red",sheet_color="yellow",loop_color="green",quiet=1,_self=cmd):
    pymol=_self._pymol
    cmd=_self
    sel = str(selection)
    h = str(helix_color)
    s = str(sheet_color)
    l = str(loop_color)
    cmd.color(h,"(ss H and ("+sel+"))",quiet=quiet)
    cmd.color(s,"(ss S and ("+sel+"))",quiet=quiet)
    cmd.color(l,"((not (ss S+H)) and ("+sel+"))",quiet=quiet)
import cmd
import csv
import urllib2
import sys
import cmd
import csv
import urllib2

cmd.color('red', "4QS1 and resi 111-500 in chain A " ) 

z
'''
cmd.color('yellow', "2QBG and resi 100-200 in chain B") 
cmd.color('red', "2QBG and resi '' in chain B") 

cmd.color('green', "2QBG and resi 100-200 in chain ''") 
cmd.color('white', "2QBG and resi 1-100 in chain A")

#cmd.color("white", objSel)
#4QS1 and resi %s" %data[i][0])

'''

#color_structure 2QBG
Exemple #17
0
# 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)
    
Exemple #18
0
def color_carbon(color,selection="(all)",_self=cmd):
    pymol=_self._pymol
    cmd=_self
    selection = str(selection)
    cmd.color(color,"(%s) and elem c"%selection)
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)
Exemple #20
0
def colorByRMSD(objSel1, objSel2, doAlign="True", doPretty=None):
    """
    colorByRMSD -- align two structures and show the structural deviations
                   in color to more easily see variable regions.
 
    PARAMS
 
        objSel1 (valid PyMOL object or selection)
            The first object to align.  
 
        objSel2 (valid PyMOL object or selection)
            The second object to align
 
        doAlign (boolean, either True or False)
            Should this script align your proteins or just leave them as is?
            If doAlign=True then your original proteins are aligned.
            If False, then they are not. Regardless, the B-factors are changed.
            DEFAULT: True
 
        doPretty (boolean, either True or False)
            If doPretty=True then a simple representation is created to
            highlight the differences.  If False, then no changes are made.
            DEFAULT: False
 
    RETURNS
        None.
 
    SIDE-EFFECTS
        Modifies the B-factor columns in your original structures.
 
    """
    # First create backup copies; names starting with __ (underscores) are
    # normally hidden by PyMOL
    tObj1, tObj2, aln = "__tempObj1", "__tempObj2", "__aln"
 
    if strTrue(doAlign):
        # perform the alignment
        cmd.create( tObj1, objSel1 )
        cmd.create( tObj2, objSel2 )
        cmd.super( tObj1, tObj2, object=aln )
        cmd.matrix_copy(tObj1, objSel1)
    else:
        # perform the alignment
        cmd.create( tObj1, objSel1 )
        cmd.create( tObj2, objSel2 )
        cmd.super( tObj1, tObj2, object=aln )
 
    # Modify the B-factor columns of the original objects,
    # in order to identify the residues NOT used for alignment, later on
    cmd.alter( objSel1 + " or " + objSel2, "b=-10")
    cmd.alter( tObj1 + " or " + tObj2, "chain='A'")
    cmd.alter( tObj1 + " or " + tObj2, "segi='A'")
 
    # Update pymol internal representations; one of these should do the trick
    cmd.refresh(); cmd.rebuild(); cmd.sort(tObj1); cmd.sort(tObj2)
 
    #  Create lists for storage
    stored.alnAres, stored.alnBres = [], []
 
    #  Get the residue identifiers from the alignment object "aln"
    cmd.iterate(tObj1 + " and n. CA and " + aln, "stored.alnAres.append(resi)")
    cmd.iterate(tObj2 + " and n. CA and " + aln, "stored.alnBres.append(resi)")
 
    # Change the B-factors for EACH object
    rmsUpdateB(tObj1,stored.alnAres,tObj2,stored.alnBres)
 
    # Store the NEW B-factors
    stored.alnAnb, stored.alnBnb = [], []
    cmd.iterate(tObj1 + " and n. CA and " + aln, "stored.alnAnb.append(b)" )
    cmd.iterate(tObj2 + " and n. CA and " + aln, "stored.alnBnb.append(b)" )
 
    # Get rid of all intermediate objects and clean up
    cmd.delete(tObj1)
    cmd.delete(tObj2)
    cmd.delete(aln)
 
    # Assign the just stored NEW B-factors to the original objects
    for x in range(len(stored.alnAres)):
        cmd.alter(objSel1 + " and n. CA and i. " + str(stored.alnAres[x]), "b = " + str(stored.alnAnb[x]))
    for x in range(len(stored.alnBres)):
        cmd.alter(objSel2 + " and n. CA and i. " + str(stored.alnBres[x]), "b = " + str(stored.alnBnb[x]))
    cmd.rebuild(); cmd.refresh(); cmd.sort(objSel1); cmd.sort(objSel2)
 
    # Provide some useful information
    stored.allRMSDval = []
    stored.allRMSDval = stored.alnAnb + stored.alnBnb
    print "\nColorByRMSD completed successfully."
    print "The MINIMUM RMSD value is: "+str(min(stored.allRMSDval))
    print "The MAXIMUM RMSD value is: "+str(max(stored.allRMSDval))
 
    if doPretty!=None:
        # Showcase what we did
        cmd.orient()
        cmd.hide("all")
        cmd.show_as("cartoon", objSel1 + " or " + objSel2)
        # Select the residues not used for alignment; they still have their B-factors as "-10"
        cmd.select("notUsedForAln", "b < 0")
        # White-wash the residues not used for alignment
        cmd.color("white", "notUsedForAln")
        # Color the residues used for alignment according to their B-factors (RMSD values)
        cmd.spectrum("b", 'rainbow',  "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not notUsedForAln")
        # Delete the selection of atoms not used for alignment
        # If you would like to keep this selection intact,
        # just comment "cmd.delete" line and
        # uncomment the "cmd.disable" line below.
        cmd.delete("notUsedForAln")
        # cmd.disable("notUsedForAln") 
 
        print "\nObjects are now colored by C-alpha RMS deviation."
        print "All residues with RMSD values greater than the maximum are colored white..."
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] )

Exemple #22
0
def colorByRMSD(objSel1, objSel2, doAlign="True", doPretty=None):
    """
    colorByRMSD -- align two structures and show the structural deviations
                   in color to more easily see variable regions.
 
    PARAMS
 
        objSel1 (valid PyMOL object or selection)
            The first object to align.  
 
        objSel2 (valid PyMOL object or selection)
            The second object to align
 
        doAlign (boolean, either True or False)
            Should this script align your proteins or just leave them as is?
            If doAlign=True then your original proteins are aligned.
            If False, then they are not. Regardless, the B-factors are changed.
            DEFAULT: True
 
        doPretty (boolean, either True or False)
            If doPretty=True then a simple representation is created to
            highlight the differences.  If False, then no changes are made.
            DEFAULT: False
 
    RETURNS
        None.
 
    SIDE-EFFECTS
        Modifies the B-factor columns in your original structures.
 
    """
    # First create backup copies; names starting with __ (underscores) are
    # normally hidden by PyMOL
    tObj1, tObj2, aln = "__tempObj1", "__tempObj2", "__aln"
 
    if strTrue(doAlign):
        # perform the alignment
        cmd.create( tObj1, objSel1 )
        cmd.create( tObj2, objSel2 )
        cmd.super( tObj1, tObj2, object=aln )
        cmd.matrix_copy(tObj1, objSel1)
    else:
        # perform the alignment
        cmd.create( tObj1, objSel1 )
        cmd.create( tObj2, objSel2 )
        cmd.super( tObj1, tObj2, object=aln )
 
    # Modify the B-factor columns of the original objects,
    # in order to identify the residues NOT used for alignment, later on
    cmd.alter( objSel1 + " or " + objSel2, "b=-10")
    cmd.alter( tObj1 + " or " + tObj2, "chain='A'")
    cmd.alter( tObj1 + " or " + tObj2, "segi='A'")
 
    # Update pymol internal representations; one of these should do the trick
    cmd.refresh(); cmd.rebuild(); cmd.sort(tObj1); cmd.sort(tObj2)
 
    #  Create lists for storage
    stored.alnAres, stored.alnBres = [], []
 
    #  Get the residue identifiers from the alignment object "aln"
    cmd.iterate(tObj1 + " and n. CA and " + aln, "stored.alnAres.append(resi)")
    cmd.iterate(tObj2 + " and n. CA and " + aln, "stored.alnBres.append(resi)")
 
    # Change the B-factors for EACH object
    rmsUpdateB(tObj1,stored.alnAres,tObj2,stored.alnBres)
 
    # Store the NEW B-factors
    stored.alnAnb, stored.alnBnb = [], []
    cmd.iterate(tObj1 + " and n. CA and " + aln, "stored.alnAnb.append(b)" )
    cmd.iterate(tObj2 + " and n. CA and " + aln, "stored.alnBnb.append(b)" )
 
    # Get rid of all intermediate objects and clean up
    cmd.delete(tObj1)
    cmd.delete(tObj2)
    cmd.delete(aln)
 
    # Assign the just stored NEW B-factors to the original objects
    for x in range(len(stored.alnAres)):
        cmd.alter(objSel1 + " and n. CA and i. " + str(stored.alnAres[x]), "b = " + str(stored.alnAnb[x]))
    for x in range(len(stored.alnBres)):
        cmd.alter(objSel2 + " and n. CA and i. " + str(stored.alnBres[x]), "b = " + str(stored.alnBnb[x]))
    cmd.rebuild(); cmd.refresh(); cmd.sort(objSel1); cmd.sort(objSel2)
 
    # Provide some useful information
    stored.allRMSDval = []
    stored.allRMSDval = stored.alnAnb + stored.alnBnb
    print "\nColorByRMSD completed successfully."
    print "The MINIMUM RMSD value is: "+str(min(stored.allRMSDval))
    print "The MAXIMUM RMSD value is: "+str(max(stored.allRMSDval))
 
    if doPretty!=None:
        # Showcase what we did
        cmd.orient()
        cmd.hide("all")
        cmd.show_as("cartoon", objSel1 + " or " + objSel2)
        # Select the residues not used for alignment; they still have their B-factors as "-10"
        cmd.select("notUsedForAln", "b < 0")
        # White-wash the residues not used for alignment
        cmd.color("white", "notUsedForAln")
        # Color the residues used for alignment according to their B-factors (RMSD values)
        cmd.spectrum("b", 'rainbow',  "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not notUsedForAln")
        # Delete the selection of atoms not used for alignment
        # If you would like to keep this selection intact,
        # just comment "cmd.delete" line and
        # uncomment the "cmd.disable" line below.
        cmd.delete("notUsedForAln")
        # cmd.disable("notUsedForAln") 
 
        print "\nObjects are now colored by C-alpha RMS deviation."
        print "All residues with RMSD values greater than the maximum are colored white..."
Exemple #23
0
def cnc(selection="(all)",quiet=1,_self=cmd):
    pymol=_self._pymol
    cmd=_self
    s = str(selection)
    cmd.color("atomic","(("+s+") and not elem C)",quiet=quiet)
Exemple #24
0
def cbao(selection="(all)",quiet=1,_self=cmd):
    pymol=_self._pymol
    cmd=_self
    s = str(selection)   
    cmd.color("atomic","(("+s+") and not elem C)",quiet=quiet)
    cmd.color("brightorange","(elem C and ("+s+"))",quiet=quiet)
Exemple #25
0
def cbaw(selection="(all)",quiet=1,_self=cmd):
    pymol=_self._pymol
    cmd=_self
    s = str(selection)   
    cmd.color("atomic","(("+s+") and not elem C)",quiet=quiet)
    cmd.color("hydrogen","(elem C and ("+s+"))",quiet=quiet)
import cmd
import csv

l=[]
with open("coloring.csv", "rb") as f:
    reader = csv.reader(f, delimiter=",")
    for i, line in enumerate(reader):
    #	l.append(line)
		print line 


def SplitOneRange(range):
	split1= range.split('/')
	split2= '\n'.join(split1)
	nt_number = ''.join(split2.split('--'))
	a=  nt_number.split()
	it = iter(a)
	d= zip(it, it)
	print d
# ('31', '32'), ('473', '474')]
#def color_convert(color):
#	'#8B4513'=,,,,
#for i in x"
cmd.color("purpleblue", "4QS1 and resi" +'9')
Exemple #27
0
def cmd_color(data):
	for i in data:
		cmd.color(convert_color(data[i][1]), "4QS1 and resi " +str(data[i][0]))
Exemple #28
0
def cbc(selection='(all)',first_color=7,quiet=1,legacy=0,_self=cmd):
    pymol=_self._pymol
    cmd=_self 
    '''
    Color all chains a different color
    '''
    if int(legacy):
        c = first_color
        for a in cmd.get_chains(selection):
            if len(string.strip(a)):
                if not quiet: print (" util.cbc: color %d,(chain %s)"%(c,a))
                cmd.color("%d"%c,"(chain %s and (%s))"%(a,selection),quiet=quiet)
                c = c + 1
            elif len(a): # note, PyMOL's selection language can't handle this right now
                if not quiet: print (" util.cbc: color %d,(chain ' ')"%(c))
                cmd.color("%d"%c,"(chain '' and (%s))"%selection,quiet=quiet)
                c = c + 1
            else:
                if not quiet: print (" util.cbc: color %d,(chain '')"%(c))
                cmd.color("%d"%c,"(chain '' and (%s))"%selection,quiet=quiet)
                c = c + 1
    else:
        c = 0
        for a in cmd.get_chains(selection):
            if len(string.strip(a)):
                if not quiet: print (" util.cbc: color %d,(chain %s)"%(_color_cycle[c],a))
                cmd.color(_color_cycle[c],"(chain %s and (%s))"%(a,selection),quiet=quiet)
            elif len(a): # note, PyMOL's selection language can't handle this right now
                if not quiet: print (" util.cbc: color %d,(chain ' ')"%(_color_cycle[c]))
                cmd.color(_color_cycle[c],"(chain '' and (%s))"%selection,quiet=quiet)
            else:
                if not quiet: print (" util.cbc: color %d,(chain '')"%(_color_cycle[c]))
                cmd.color(_color_cycle[c],"(chain '' and (%s))"%selection,quiet=quiet)
            c = (c + 1) % _color_cycle_len
def ColorByDisplacementCA(objSel1, objSel2, super1='all', super2='all', doColor="True", doAlign="True", AlignedWhite='yes'):
    ### First create backup copies; names starting with __ (underscores) are normally hidden by PyMOL
    tObj1, tObj2, aln = "__tempObj1", "__tempObj2", "__aln"
 
    if strTrue(doAlign):
        ### Create temp objects
        cmd.create( tObj1, objSel1 )
        cmd.create( tObj2, objSel2 )
	### Align and make create an object aln which indicates which atoms were paired between the two structures
	### Super is must faster than align http://www.pymolwiki.org/index.php/Super
        cmd.super(tObj1 + ' and ' + str(super1), tObj2 + ' and ' + str(super2), object=aln)
	### Modify the original matrix of object1 from the alignment
        cmd.matrix_copy(tObj1, objSel1)
    else:
        ### Create temp objects
        cmd.create( tObj1, objSel1 )
        cmd.create( tObj2, objSel2 )
	### Align and make create an object aln which indicates which atoms were paired between the two structures
	### Super is must faster than align http://www.pymolwiki.org/index.php/Super
        cmd.super(tObj1 + ' and ' + str(super1), tObj2 + ' and ' + str(super2), object=aln)
 
    ### Modify the B-factor columns of the original objects,
    ### in order to identify the residues NOT used for alignment, later on
    cmd.alter( objSel1 + " or " + objSel2, "b=-0.2")
    cmd.alter( tObj1 + " or " + tObj2, "chain='A'")
    cmd.alter( tObj1 + " or " + tObj2, "segi='A'")
 
    ### Update pymol internal representations; one of these should do the trick
    cmd.refresh(); cmd.rebuild(); cmd.sort(tObj1); cmd.sort(tObj2)
 
    ###  Create lists for storage
    stored.alnAres, stored.alnBres = [], []
 
    ### Iterate over objects
    if AlignedWhite=='yes':
        cmd.iterate(tObj1 + " and n. CA and not " + aln, "stored.alnAres.append(resi)")
	cmd.iterate(tObj2 + " and n. CA and not " + aln, "stored.alnBres.append(resi)")
    else:
	cmd.iterate(tObj1 + " and n. CA", "stored.alnAres.append(resi)")
        cmd.iterate(tObj2 + " and n. CA", "stored.alnBres.append(resi)")
 
    ### Change the B-factors for EACH object
    displacementUpdateB(tObj1,stored.alnAres,tObj2,stored.alnBres)
 
    ### Store the NEW B-factors
    stored.alnAnb, stored.alnBnb = [], []
    ### Iterate over objects and get b
    if AlignedWhite=='yes':
	### Iterate over objects which is not aligned
    	cmd.iterate(tObj1 + " and n. CA and not " + aln, "stored.alnAnb.append(b)" )
	cmd.iterate(tObj2 + " and n. CA and not " + aln, "stored.alnBnb.append(b)" )
    else:
	### Or Iterate over all objects with CA
    	cmd.iterate(tObj1 + " and n. CA", "stored.alnAnb.append(b)" )
    	cmd.iterate(tObj2 + " and n. CA", "stored.alnBnb.append(b)" )
 
    ### Get rid of all intermediate objects and clean up
    cmd.delete(tObj1)
    cmd.delete(tObj2)
    cmd.delete(aln)
 
    ### Assign the just stored NEW B-factors to the original objects
    for x in range(len(stored.alnAres)):
        cmd.alter(objSel1 + " and n. CA and i. " + str(stored.alnAres[x]), "b = " + str(stored.alnAnb[x]))
    for x in range(len(stored.alnBres)):
        cmd.alter(objSel2 + " and n. CA and i. " + str(stored.alnBres[x]), "b = " + str(stored.alnBnb[x]))
    cmd.rebuild(); cmd.refresh(); cmd.sort(objSel1); cmd.sort(objSel2)
 
    ### Provide some useful information
    stored.allRMSDval = []
    stored.allRMSDval = stored.alnAnb + stored.alnBnb
    print "\nColorByDisplacementCA completed successfully."
    print "The MAXIMUM Displacement is: "+str(max(stored.allRMSDval)) +" residue "+str(stored.alnAres[int(stored.allRMSDval.index(max(stored.allRMSDval)))])
 
    if strTrue(doColor):
        ### Showcase what we did
        #cmd.orient()
        #cmd.hide("all")
        cmd.show("cartoon", objSel1 + " or " + objSel2)
        ### Select the residues not used for alignment; they still have their B-factors as "-0.2"
        cmd.select("notUsedForAln", "b = -0.2")
        ### White-wash the residues not used for alignment
        cmd.color("white", "notUsedForAln")
        ### Select the residues not in both pdb files; they have their B-factors as "-0. 01"
        cmd.select("ResNotInBothPDB", "b = -0.01")
        ### White-wash the residues not used for alignment
        cmd.color("black", "ResNotInBothPDB")
        ### Color the residues used for alignment according to their B-factors (Displacment values)
#        cmd.spectrum("b", 'rainbow',  "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not notUsedForAln+ResNotInBothPDB")
        cmd.spectrum("b", 'rainbow',  "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not (notUsedForAln or ResNotInBothPDB)")
        ### Delete the selection of atoms not used for alignment
        ### If you would like to keep this selection intact,
        ### just comment "cmd.delete" line and
        ### uncomment the "cmd.disable" line abowe.
        cmd.disable("notUsedForAln")
        cmd.delete("notUsedForAln")
        cmd.disable("ResNotInBothPDB")
        cmd.delete("ResNotInBothPDB")
 
        print "\nObjects are now colored by C-alpha displacement deviation."
        print "Blue is minimum and red is maximum..."
        print "White is those residues used in the alignment algorithm. Can be turned off in top of algorithm."
	print "Black is residues that does not exist in both files..."