Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/file/3de50226f993/lib/monomer.py
Дата изменения: Unknown
Дата индексирования: Sun Feb 3 23:24:44 2013
Кодировка:
allpy: 3de50226f993 lib/monomer.py

allpy

view lib/monomer.py @ 163:3de50226f993

start to change geometrical_core tool on single-pdb-usage scheme
author boris <bnagaev@gmail.com>
date Sun, 31 Oct 2010 13:08:17 +0300
parents 0c7f6117481b
children 137057949976
line source
1 #!/usr/bin/python
3 from allpy_data.AAdict import AAdict
4 import Bio.PDB
6 index_code3 = {}
7 index_code1_protein = {}
8 index_name = {}
11 class MonomerType(object):
12 """ Monomer type
14 name -- string like "Valine"
15 code1 -- one-letter code (in upper case)
16 code3 -- three-letter code (in upper case)
17 is_modified -- True of False
18 """
19 def __init__(self, name, code1, code3, is_modified=False):
20 self.name = name.capitalize()
21 self.code1 = code1.upper()
22 self.code3 = code3.upper()
23 self.is_modified = bool(is_modified) # ugly
25 index_name[self.name] = self
26 index_code3[self.code3] = self
28 @staticmethod
29 def from_code3(code3):
30 return index_code3[code3.upper()]
31 @staticmethod
32 def from_name(name):
33 return index_name[name.capitalize()]
35 @staticmethod
36 def from_pdb_residue(pdb_residue):
37 return MonomerType.from_code3(pdb_residue.get_resname())
39 # TO DISCUSS
40 def __eq__(self, other):
41 return self.code1 == other.code1
43 def __ne__(self, other):
44 return not (self == other)
47 class Monomer(object):
48 """ Monomer
50 type -- link to MonomerType object
51 """
52 def __init__(self, monomer_type):
53 self.type = monomer_type
55 def __eq__(self, other):
56 return self.type == other.type
58 def __ne__(self, other):
59 return not (self == other)
61 class AminoAcidType(MonomerType):
62 def __init__(self, name, code1, code3, is_modified=False):
63 MonomerType.__init__(self, name, code1, code3, is_modified)
64 if not is_modified:
65 index_code1_protein[self.code1] = self
67 @staticmethod
68 def from_code1(code1):
69 return index_code1_protein[code1.upper()]
70 def instance(self):
71 """ Returns new AminoAcid object of this type """
72 return AminoAcid(self)
75 class AminoAcid(Monomer):
76 """ Amino acid """
77 pass
80 # prepare all aminoacids
82 for code3, data in AAdict.items():
83 code1, m_type, is_modified, none, name = data
84 if m_type == 'p':
85 AminoAcidType(name, code1, code3, is_modified)
87 del code3, data, code1, m_type, is_modified, none, name