Aa codes

From PyMOLWiki
Jump to navigation Jump to search

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

Simple

# 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()])

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

Simple and Clever

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 LEU 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 ]

Using BioPython

If you have BioPython you can use the following, which includes also many three-letter codes of modified amino acids:

from Bio.PDB import to_one_letter_code as one_letter
from Bio.Data.SCOPData import protein_letters_3to1 as one_letter

Using PyMOL

from pymol.exporting import _resn_to_aa as one_letter

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]]