IMP logo
IMP Reference Guide  2.16.0
The Integrative Modeling Platform
alphabets.py
1 """@namespace IMP.pmi.alphabets
2  Mapping between FASTA one-letter codes and residue types.
3 """
4 
5 from __future__ import print_function
6 import IMP.atom
7 
8 
9 class ResidueAlphabet(object):
10  """Map between FASTA codes and residue types.
11  Typically one would use the `amino_acid`, `rna`, or `dna` objects."""
12  def __init__(self, charmm_to_one):
13  self._one_to_charmm = {}
14  for k, v in charmm_to_one.items():
15  self._one_to_charmm[v] = k
16  self.charmm_to_one = charmm_to_one
17 
19  """Given a one-letter code, return an IMP.atom.ResidueType"""
20  return IMP.atom.ResidueType(self._one_to_charmm[code])
21 
23  """Given a residue type, return a one-letter code"""
24  # Technically this is the CHARMM type, not PDB (but they are the
25  # same for amino acids)
26  return self.charmm_to_one.get(rt, 'X')
27 
28 
29 """Mapping between FASTA one-letter codes and residue types for amino acids"""
30 amino_acid = ResidueAlphabet(
31  {'ALA': 'A', 'ARG': 'R', 'ASN': 'N', 'ASP': 'D',
32  'CYS': 'C', 'GLU': 'E', 'GLN': 'Q', 'GLY': 'G',
33  'HIS': 'H', 'ILE': 'I', 'LEU': 'L', 'LYS': 'K',
34  'MET': 'M', 'PHE': 'F', 'PRO': 'P', 'SER': 'S',
35  'THR': 'T', 'TRP': 'W', 'TYR': 'Y', 'VAL': 'V',
36  'UNK': 'X'})
37 
38 
39 """Mapping between FASTA one-letter codes and residue types for DNA"""
40 dna = ResidueAlphabet(
41  {'DADE': 'A', 'DURA': 'U', 'DCYT': 'C', 'DGUA': 'G',
42  'DTHY': 'T', 'UNK': 'X'})
43 
44 
45 """Mapping between FASTA one-letter codes and residue types for RNA"""
46 rna = ResidueAlphabet(
47  {'ADE': 'A', 'URA': 'U', 'CYT': 'C', 'GUA': 'G',
48  'THY': 'T', 'UNK': 'X'})
def get_one_letter_code_from_residue_type
Given a residue type, return a one-letter code.
Definition: alphabets.py:22
Map between FASTA codes and residue types.
Definition: alphabets.py:9
def get_residue_type_from_one_letter_code
Given a one-letter code, return an IMP.atom.ResidueType.
Definition: alphabets.py:18
The type for a residue.
Functionality for loading, creating, manipulating and scoring atomic structures.