<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.pymol.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Cmalisi</id>
	<title>PyMOL Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pymol.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Cmalisi"/>
	<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php/Special:Contributions/Cmalisi"/>
	<updated>2026-05-28T13:27:07Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.1</generator>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Color_By_Mutations&amp;diff=5201</id>
		<title>Color By Mutations</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Color_By_Mutations&amp;diff=5201"/>
		<updated>2011-04-20T13:58:10Z</updated>

		<summary type="html">&lt;p&gt;Cmalisi: Created page with &amp;quot;This script creates an alignment of two proteins and superimposes them. Aligned residues that are different in the two (i.e. mutations) are highlighted and colored according to t...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This script creates an alignment of two proteins and superimposes them. Aligned residues that are different in the two (i.e. mutations) are highlighted and colored according to their difference in the BLOSUM90 matrix. It is meant to be used for similar proteins, e.g. close homologs or point mutants, to visualize their differences.&lt;br /&gt;
&lt;br /&gt;
Example&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
color_by_mutation protein1, protein2&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: rat trypsin and cow trypsin colored by color_by_mutation.&lt;br /&gt;
&lt;br /&gt;
[[File:color_by_mutation.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
created by Christoph Malisi.&lt;br /&gt;
&lt;br /&gt;
Creates an alignment of two proteins and superimposes them. &lt;br /&gt;
Aligned residues that are different in the two (i.e. mutations) are highlighted and &lt;br /&gt;
colored according to their difference in the BLOSUM90 matrix. &lt;br /&gt;
Is meant to be used for similar proteins, e.g. close homologs or point mutants, &lt;br /&gt;
to visualize their differences.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
&lt;br /&gt;
aa_3l = {'ALA':0, 'ARG':1, 'ASN':2, 'ASP':3, 'CYS':4, 'GLN':5, 'GLU':6, 'GLY':7, 'HIS':8, 'ILE':9, 'LEU':10, 'LYS':11,&lt;br /&gt;
        'MET':12, 'PHE':13, 'PRO':14, 'SER':15, 'THR':16, 'TRP':17, 'TYR':18, 'VAL':19, 'B':20, 'Z':21, 'X':22, '*':23}&lt;br /&gt;
&lt;br /&gt;
#            A   R   N   D   C   Q   E   G   H   I   L   K   M   F   P   S   T   W   Y   V   B   Z   X   *&lt;br /&gt;
blosum90 = [[ 5, -2, -2, -3, -1, -1, -1,  0, -2, -2, -2, -1, -2, -3, -1,  1,  0, -4, -3, -1, -2, -1, -1, -6], &lt;br /&gt;
            [-2,  6, -1, -3, -5,  1, -1, -3,  0, -4, -3,  2, -2, -4, -3, -1, -2, -4, -3, -3, -2,  0, -2, -6], &lt;br /&gt;
            [-2, -1,  7,  1, -4,  0, -1, -1,  0, -4, -4,  0, -3, -4, -3,  0,  0, -5, -3, -4,  4, -1, -2, -6], &lt;br /&gt;
            [-3, -3,  1,  7, -5, -1,  1, -2, -2, -5, -5, -1, -4, -5, -3, -1, -2, -6, -4, -5,  4,  0, -2, -6], &lt;br /&gt;
            [-1, -5, -4, -5,  9, -4, -6, -4, -5, -2, -2, -4, -2, -3, -4, -2, -2, -4, -4, -2, -4, -5, -3, -6], &lt;br /&gt;
            [-1,  1,  0, -1, -4,  7,  2, -3,  1, -4, -3,  1,  0, -4, -2, -1, -1, -3, -3, -3, -1,  4, -1, -6], &lt;br /&gt;
            [-1, -1, -1,  1, -6,  2,  6, -3, -1, -4, -4,  0, -3, -5, -2, -1, -1, -5, -4, -3,  0,  4, -2, -6], &lt;br /&gt;
            [ 0, -3, -1, -2, -4, -3, -3,  6, -3, -5, -5, -2, -4, -5, -3, -1, -3, -4, -5, -5, -2, -3, -2, -6], &lt;br /&gt;
            [-2,  0,  0, -2, -5,  1, -1, -3,  8, -4, -4, -1, -3, -2, -3, -2, -2, -3,  1, -4, -1,  0, -2, -6], &lt;br /&gt;
            [-2, -4, -4, -5, -2, -4, -4, -5, -4,  5,  1, -4,  1, -1, -4, -3, -1, -4, -2,  3, -5, -4, -2, -6], &lt;br /&gt;
            [-2, -3, -4, -5, -2, -3, -4, -5, -4,  1,  5, -3,  2,  0, -4, -3, -2, -3, -2,  0, -5, -4, -2, -6], &lt;br /&gt;
            [-1,  2,  0, -1, -4,  1,  0, -2, -1, -4, -3,  6, -2, -4, -2, -1, -1, -5, -3, -3, -1,  1, -1, -6], &lt;br /&gt;
            [-2, -2, -3, -4, -2,  0, -3, -4, -3,  1,  2, -2,  7, -1, -3, -2, -1, -2, -2,  0, -4, -2, -1, -6], &lt;br /&gt;
            [-3, -4, -4, -5, -3, -4, -5, -5, -2, -1,  0, -4, -1,  7, -4, -3, -3,  0,  3, -2, -4, -4, -2, -6], &lt;br /&gt;
            [-1, -3, -3, -3, -4, -2, -2, -3, -3, -4, -4, -2, -3, -4,  8, -2, -2, -5, -4, -3, -3, -2, -2, -6], &lt;br /&gt;
            [ 1, -1,  0, -1, -2, -1, -1, -1, -2, -3, -3, -1, -2, -3, -2,  5,  1, -4, -3, -2,  0, -1, -1, -6], &lt;br /&gt;
            [ 0, -2,  0, -2, -2, -1, -1, -3, -2, -1, -2, -1, -1, -3, -2,  1,  6, -4, -2, -1, -1, -1, -1, -6], &lt;br /&gt;
            [-4, -4, -5, -6, -4, -3, -5, -4, -3, -4, -3, -5, -2,  0, -5, -4, -4, 11,  2, -3, -6, -4, -3, -6], &lt;br /&gt;
            [-3, -3, -3, -4, -4, -3, -4, -5,  1, -2, -2, -3, -2,  3, -4, -3, -2,  2,  8, -3, -4, -3, -2, -6], &lt;br /&gt;
            [-1, -3, -4, -5, -2, -3, -3, -5, -4,  3,  0, -3,  0, -2, -3, -2, -1, -3, -3,  5, -4, -3, -2, -6], &lt;br /&gt;
            [-2, -2,  4,  4, -4, -1,  0, -2, -1, -5, -5, -1, -4, -4, -3,  0, -1, -6, -4, -4,  4,  0, -2, -6], &lt;br /&gt;
            [-1,  0, -1,  0, -5,  4,  4, -3,  0, -4, -4,  1, -2, -4, -2, -1, -1, -4, -3, -3,  0,  4, -1, -6], &lt;br /&gt;
            [-1, -2, -2, -2, -3, -1, -2, -2, -2, -2, -2, -1, -1, -2, -2, -1, -1, -3, -2, -2, -2, -1, -2, -6], &lt;br /&gt;
            [-6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6,  1]] &lt;br /&gt;
&lt;br /&gt;
def getBlosum90ColorName(aa1, aa2):&lt;br /&gt;
    '''returns a rgb color name of a color that represents the similarity of the two residues according to&lt;br /&gt;
       the BLOSUM90 matrix. the color is on a spectrum from blue to red, where blue is very similar, and &lt;br /&gt;
       red very disimilar.'''&lt;br /&gt;
    # return red for residues that are not part of the 20 amino acids&lt;br /&gt;
    if aa1 not in aa_3l or aa2 not in aa_3l:&lt;br /&gt;
	return 'red'&lt;br /&gt;
    &lt;br /&gt;
    # if the two are the same, return blue&lt;br /&gt;
    if aa1 == aa2:&lt;br /&gt;
	return 'blue'&lt;br /&gt;
    i1 = aa_3l[aa1]&lt;br /&gt;
    i2 = aa_3l[aa2]&lt;br /&gt;
    b = blosum90[i1][i2]&lt;br /&gt;
&lt;br /&gt;
    # 3 is the highest score for non-identical substitutions, so substract 4 to get into range [-10, -1]&lt;br /&gt;
    b = abs(b - 4)&lt;br /&gt;
&lt;br /&gt;
    # map to (0, 1]:&lt;br /&gt;
    b = 1. - (b / 10.0)&lt;br /&gt;
&lt;br /&gt;
    # red = [1.0, 0.0, 0.0], blue = [0.0, 0.0, 1.0]&lt;br /&gt;
    colvec = [(0., 0., 1.), (1.,0.,0.)]&lt;br /&gt;
    bcolor = (1.-b, 0., b)&lt;br /&gt;
    col_name = '0x%02x%02x%02x'%(bcolor[0]*255, bcolor[1]*255, bcolor[2]*255)&lt;br /&gt;
    return col_name&lt;br /&gt;
&lt;br /&gt;
def color_by_mutation(obj1, obj2, waters=0, labels=0):&lt;br /&gt;
    '''&lt;br /&gt;
    DESCRIPTION&lt;br /&gt;
    &lt;br /&gt;
        Creates an alignment of two proteins and superimposes them. &lt;br /&gt;
        Aligned residues that are different in the two (i.e. mutations) are highlighted and &lt;br /&gt;
        colored according to their difference in the BLOSUM90 matrix. &lt;br /&gt;
        Is meant to be used for similar proteins, e.g. close homologs or point mutants, &lt;br /&gt;
        to visualize their differences.      &lt;br /&gt;
    &lt;br /&gt;
    USAGE&lt;br /&gt;
    &lt;br /&gt;
        color_by_mutation selection1, selection2 [,waters [,labels ]]&lt;br /&gt;
        &lt;br /&gt;
    ARGUMENTS&lt;br /&gt;
    &lt;br /&gt;
        obj1: object or selection&lt;br /&gt;
        &lt;br /&gt;
        obj2: object or selection    &lt;br /&gt;
        &lt;br /&gt;
        waters: bool (0 or 1). If 1, waters are included in the view, colored&lt;br /&gt;
                differently for the both input structures.&lt;br /&gt;
                default = 0&lt;br /&gt;
&lt;br /&gt;
        labels: bool (0 or 1). If 1, the possibly mutated sidechains are &lt;br /&gt;
                labeled by their chain, name and id&lt;br /&gt;
                default = 0&lt;br /&gt;
        &lt;br /&gt;
    EXAMPLE&lt;br /&gt;
        &lt;br /&gt;
        color_by_mutation protein1, protein2&lt;br /&gt;
        &lt;br /&gt;
    SEE ALSO&lt;br /&gt;
&lt;br /&gt;
        super&lt;br /&gt;
    '''&lt;br /&gt;
    if cmd.count_atoms(obj1) == 0:&lt;br /&gt;
        print '%s is empty'%obj1&lt;br /&gt;
        return&lt;br /&gt;
    if cmd.count_atoms(obj2) == 0:&lt;br /&gt;
        print '%s is empty'%obj2&lt;br /&gt;
        return&lt;br /&gt;
    waters = int(waters)&lt;br /&gt;
    labels = int(labels)&lt;br /&gt;
    &lt;br /&gt;
    # align the two proteins&lt;br /&gt;
    aln = '__aln'&lt;br /&gt;
    &lt;br /&gt;
    # first, an alignment with 0 cycles (no atoms are rejected, which maximized the number of aligned residues)&lt;br /&gt;
    # for some mutations in the same protein this works fine). This is essentially done to get a&lt;br /&gt;
    # sequence alignment&lt;br /&gt;
    cmd.super(obj1, obj2, object=aln, cycles=0)&lt;br /&gt;
    &lt;br /&gt;
    # superimpose the the object using the default parameters to get a slightly better superimposition,&lt;br /&gt;
    # i.e. get the best structural alignment    &lt;br /&gt;
    cmd.super(obj1, obj2)&lt;br /&gt;
&lt;br /&gt;
    stored.resn1, stored.resn2 = [], []&lt;br /&gt;
    stored.resi1, stored.resi2 = [], []&lt;br /&gt;
    stored.chain1, stored.chain2 = [], []&lt;br /&gt;
    &lt;br /&gt;
    # store residue ids, residue names and chains of aligned residues&lt;br /&gt;
    cmd.iterate(obj1 + ' and name CA and ' + aln, 'stored.resn1.append(resn)')&lt;br /&gt;
    cmd.iterate(obj2 + ' and name CA and ' + aln, 'stored.resn2.append(resn)')&lt;br /&gt;
&lt;br /&gt;
    cmd.iterate(obj1 + ' and name CA and ' + aln, 'stored.resi1.append(resi)')&lt;br /&gt;
    cmd.iterate(obj2 + ' and name CA and ' + aln, 'stored.resi2.append(resi)')&lt;br /&gt;
&lt;br /&gt;
    cmd.iterate(obj1 + ' and name CA and ' + aln, 'stored.chain1.append(chain)')&lt;br /&gt;
    cmd.iterate(obj2 + ' and name CA and ' + aln, 'stored.chain2.append(chain)')&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    mutant_selection = '' &lt;br /&gt;
    non_mutant_selection = ''&lt;br /&gt;
    colors = []&lt;br /&gt;
&lt;br /&gt;
    # loop over the aligned residues&lt;br /&gt;
    for n1, n2, i1, i2, c1, c2 in zip(stored.resn1, stored.resn2,&lt;br /&gt;
                                      stored.resi1, stored.resi2,&lt;br /&gt;
                                      stored.chain1, stored.chain2):&lt;br /&gt;
        # take care of 'empty' chain names&lt;br /&gt;
        if c1 == '':&lt;br /&gt;
            c1 = '&amp;quot;&amp;quot;'&lt;br /&gt;
        if c2 == '':&lt;br /&gt;
            c2 = '&amp;quot;&amp;quot;'&lt;br /&gt;
        if n1 == n2:&lt;br /&gt;
            non_mutant_selection += '((%s and resi %s and chain %s) or (%s and resi %s and chain %s)) or '%(obj1, i1, c1, obj2, i2, c2 )            &lt;br /&gt;
        else:&lt;br /&gt;
            mutant_selection += '((%s and resi %s and chain %s) or (%s and resi %s and chain %s)) or '%(obj1, i1, c1, obj2, i2, c2 )&lt;br /&gt;
            # get the similarity (according to the blosum matrix) of the two residues and&lt;br /&gt;
            c = getBlosum90ColorName(n1, n2)&lt;br /&gt;
            colors.append((c, '%s and resi %s and chain %s and elem C'%(obj2, i2, c2)))&lt;br /&gt;
&lt;br /&gt;
    # create selections        &lt;br /&gt;
    cmd.select('mutations', mutant_selection[:-4])&lt;br /&gt;
    cmd.select('non_mutations', non_mutant_selection[:-4])&lt;br /&gt;
    cmd.select('not_aligned', '(%s or %s) and not mutations and not non_mutations'%(obj1, obj2))&lt;br /&gt;
    &lt;br /&gt;
    # create the view and coloring&lt;br /&gt;
    cmd.hide('everything', '%s or %s'%(obj1, obj2))&lt;br /&gt;
    cmd.show('cartoon', '%s or %s'%(obj1, obj2))&lt;br /&gt;
    cmd.show('lines', '(%s or %s) and ((non_mutations or not_aligned) and not name c+o+n)'%(obj1, obj2))&lt;br /&gt;
    cmd.show('sticks', '(%s or %s) and mutations and not name c+o+n'%(obj1, obj2))&lt;br /&gt;
    cmd.color('gray', 'elem C and not_aligned')&lt;br /&gt;
    cmd.color('white', 'elem C and non_mutations')&lt;br /&gt;
    cmd.color('blue', 'elem C and mutations and %s'%obj1)&lt;br /&gt;
    for (col, sel) in colors:&lt;br /&gt;
        cmd.color(col, sel)&lt;br /&gt;
&lt;br /&gt;
    cmd.hide('everything', '(hydro) and (%s or %s)'%(obj1, obj2))        &lt;br /&gt;
    cmd.center('%s or %s'%(obj1, obj2))&lt;br /&gt;
    if labels:&lt;br /&gt;
        cmd.label('mutations and name CA','&amp;quot;(%s-%s-%s)&amp;quot;%(chain, resi, resn)')    &lt;br /&gt;
    if waters:&lt;br /&gt;
        cmd.set('sphere_scale', '0.1')&lt;br /&gt;
        cmd.show('spheres', 'resn HOH and (%s or %s)'%(obj1, obj2))&lt;br /&gt;
        cmd.color('red', 'resn HOH and %s'%obj1)&lt;br /&gt;
        cmd.color('salmon', 'resn HOH and %s'%obj2)&lt;br /&gt;
    print '''&lt;br /&gt;
             Mutations are highlighted in blue and red.&lt;br /&gt;
             All mutated sidechains of %s are colored blue, the corresponding ones from %s are&lt;br /&gt;
             colored on a spectrum from blue to red according to how similar the two amino acids are&lt;br /&gt;
             (as measured by the BLOSUM90 substitution matrix).&lt;br /&gt;
             Aligned regions without mutations are colored white.&lt;br /&gt;
             Regions not used for the alignment are gray.&lt;br /&gt;
             NOTE: There could be mutations in the gray regions that were not detected.'''%(obj1, obj2)&lt;br /&gt;
    cmd.delete(aln)&lt;br /&gt;
    cmd.deselect()&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
cmd.extend(&amp;quot;color_by_mutation&amp;quot;, color_by_mutation)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[Category:Script_Library|Color By Mutation]]&lt;br /&gt;
[[Category:Script_Library]] [[Category:Structural_Biology_Scripts]]&lt;/div&gt;</summary>
		<author><name>Cmalisi</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=File:Color_by_mutation.png&amp;diff=1722</id>
		<title>File:Color by mutation.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=File:Color_by_mutation.png&amp;diff=1722"/>
		<updated>2011-04-20T13:54:54Z</updated>

		<summary type="html">&lt;p&gt;Cmalisi: uploaded a new version of &amp;amp;quot;File:Color by mutation.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;example for script color_by_mutation&lt;/div&gt;</summary>
		<author><name>Cmalisi</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=File:Color_by_mutation.png&amp;diff=1721</id>
		<title>File:Color by mutation.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=File:Color_by_mutation.png&amp;diff=1721"/>
		<updated>2011-04-20T13:53:14Z</updated>

		<summary type="html">&lt;p&gt;Cmalisi: uploaded a new version of &amp;amp;quot;File:Color by mutation.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;example for script color_by_mutation&lt;/div&gt;</summary>
		<author><name>Cmalisi</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=File:Color_by_mutation.png&amp;diff=1720</id>
		<title>File:Color by mutation.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=File:Color_by_mutation.png&amp;diff=1720"/>
		<updated>2011-04-20T13:50:32Z</updated>

		<summary type="html">&lt;p&gt;Cmalisi: example for script color_by_mutation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;example for script color_by_mutation&lt;/div&gt;</summary>
		<author><name>Cmalisi</name></author>
	</entry>
</feed>