Aa codes

From PyMOLWiki
Revision as of 09:06, 13 September 2010 by Inchoate (talk | contribs)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Just a quick little script to allow you to convert from 1-to-3 letter codes and 3-to-1 letter codes in PyMOL. Copy the code below and drop it into your .pymolrc file. Then, each time you load PyMOL, "one_letter" and "three_letter" will be defined.

The Code Part I

# one_letter["SER"] will now return "S"
one_letter ={'VAL':'V', 'ILE':'I', 'LEU':'L', 'GLU':'E', 'GLN':'Q', \
'ASP':'D', 'ASN':'N', 'HIS':'H', 'TRP':'W', 'PHE':'F', 'TYR':'Y',    \
'ARG':'R', 'LYS':'K', 'SER':'S', 'THR':'T', 'MET':'M', 'ALA':'A',    \
'GLY':'G', 'PRO':'P', 'CYS':'C'}

# three_letter["S"] will now return "SER"
three_letter = dict([[v,k] for k,v in one_letter.items()])

The Code Part II

Here's another way to accomplish this

# The real convenience in there is that you can easily construct any
# kind of hash by just adding a matching list, and zipping.
aa1 = list("ACDEFGHIKLMNPQRSTVWY")
aa3 = "ALA CYS ASP GLU PHE GLY HIS ILE LYS MET ASN PRO GLN ARG SER THR VAL TRP TYR".split()
aa123 = dict(zip(aa1,aa3))
aa321 = dict(zip(aa3,aa1))

# Then to extract a sequence, I tend to go for a construction like:
sequence = [ aa321[i.resn] for i in cmd.get_model(selection + " and n. ca").atom ]

The Code Part II -- BioPython

If you have BioPython you can use the following

from Bio.PDB import to_one_letter_code as one_letter
from pymol.exporting import _resn_to_aa as one_letter

#Alternative to get three letter code:
print cmd.get_model('myselection').atom[0].resn

Example Usage

# we used to have to do the following to get the amino acid name
from pymol import stored
stored.aa = ""
cmd.iterate("myselection", "stored.aa=resn")

# now we can just call
three_letter[string.split(cmd.get_fastastr("myselection"),'\n')[1]]