Skip to content

Instantly share code, notes, and snippets.

@JoaoRodrigues
Created October 25, 2016 01:46
Show Gist options
  • Save JoaoRodrigues/6c1e09e45e6460451f02b009f19462c3 to your computer and use it in GitHub Desktop.
Save JoaoRodrigues/6c1e09e45e6460451f02b009f19462c3 to your computer and use it in GitHub Desktop.
PyMOL script to highlight mutated residues between two proteins
"""
(c) 2016 Joao Rodrigues
"""
from __future__ import print_function
from pymol import cmd
# Autocomplete
def _autocomplete():
return cmd.Shortcut(cmd.get_names())
cmd.auto_arg[0]['diffseq'] = [_autocomplete, 'object name', '']
cmd.auto_arg[1]['diffseq'] = [_autocomplete, 'object name', '']
def diffseq(objectA, objectB):
"""
DESCRIPTION
Highlight sequence differences between two proteins.
USAGE
diffseq protA, protB
"""
# Color white
cmd.color('white', '{} or {}'.format(objectA, objectB))
# Align
cmd.align(objectA, objectB, object='_aln')
# Map
def _id_to_resn(selection):
obj, at_id = selection
_s = {'_r': []}
cmd.iterate('{} and id {}'.format(obj, at_id),
'_r.append(resn)', space=_s)
return _s['_r'][0]
raw_aln = cmd.get_raw_alignment('_aln')
for resA, resB in raw_aln:
resn_A = _id_to_resn(resA)
resn_B = _id_to_resn(resB)
if resn_A != resn_B:
cmd.show('spheres', '{} and id {}'.format(*resA))
cmd.color('orange', '{} and id {}'.format(*resA))
cmd.show('spheres', '{} and id {}'.format(*resB))
cmd.color('orange', '{} and id {}'.format(*resB))
cmd.delete('_aln')
cmd.extend('diffseq', diffseq)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment