Aa codes: Difference between revisions

From PyMOLWiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 1: Line 1:
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.
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 =
= The Code Part I=
<source lang="python">
<source lang="python">
# one_letter["SER"] will now return "S"
# one_letter["SER"] will now return "S"
Line 11: Line 11:
# three_letter["S"] will now return "SER"
# three_letter["S"] will now return "SER"
three_letter = dict([[v,k] for k,v in one_letter.items()])
three_letter = dict([[v,k] for k,v in one_letter.items()])
</source>
= The Code Part II =
Here's another way to accomplish this
<source lang="python">
# 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 ]
</source>
= The Code Part II -- BioPython =
If you have BioPython you can use the following
<source lang="python">
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
</source>
</source>



Revision as of 08:06, 13 September 2010

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