Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/file/50633fcbbdc4/allpy/monomer.py
Дата изменения: Unknown
Дата индексирования: Mon Feb 4 04:28:53 2013
Кодировка:
allpy: 50633fcbbdc4 allpy/monomer.py

allpy

view allpy/monomer.py @ 192:50633fcbbdc4

Removed old implementation of geometrical_core. The proper place for obsolete implementations is either in history in the repository, or in separate branches, not in subdirectories within the current branch in the repository.
author Daniil Alexeyevsky <me.dendik@gmail.com>
date Thu, 18 Nov 2010 21:42:16 +0300
parents be4773230e65
children 346a6cd4fc1d
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_code1_nucleotide = {}
9 index_name = {}
12 class MonomerType(object):
13 """ Monomer type
15 name -- string like "Valine"
16 code1 -- one-letter code (in upper case)
17 code3 -- three-letter code (in upper case)
18 is_modified -- True of False
19 """
20 def __init__(self, name, code1, code3, is_modified=False):
21 self.name = name.capitalize()
22 self.code1 = code1.upper()
23 self.code3 = code3.upper()
24 self.is_modified = bool(is_modified) # ugly
26 index_name[self.name] = self
27 index_code3[self.code3] = self
29 @staticmethod
30 def from_code3(code3):
31 return index_code3[code3.upper()]
32 @staticmethod
33 def from_name(name):
34 return index_name[name.capitalize()]
36 @staticmethod
37 def from_pdb_residue(pdb_residue):
38 return MonomerType.from_code3(pdb_residue.get_resname())
40 # TO DISCUSS
41 def __eq__(self, other):
42 return self.code1 == other.code1
44 def __ne__(self, other):
45 return not (self == other)
48 class Monomer(object):
49 """ Monomer
51 type -- link to MonomerType object
52 """
53 def __init__(self, monomer_type):
54 self.type = monomer_type
56 def __eq__(self, other):
57 return self.type == other.type
59 def __ne__(self, other):
60 return not (self == other)
62 class AminoAcidType(MonomerType):
63 def __init__(self, name, code1, code3, is_modified=False):
64 MonomerType.__init__(self, name, code1, code3, is_modified)
65 if not is_modified:
66 index_code1_protein[self.code1] = self
68 @staticmethod
69 def from_code1(code1):
70 return index_code1_protein[code1.upper()]
71 def instance(self):
72 """ Returns new AminoAcid object of this type """
73 return AminoAcid(self)
75 class DNAType(MonomerType):
76 def __init__(self, name, code1, code3, is_modified=False):
77 MonomerType.__init__(self, name, code1, code3, is_modified)
78 if not is_modified:
79 index_code1_nucleotide[self.code1] = self
81 @staticmethod
82 def from_code1(code1):
83 return index_code1_nucleotide[code1.upper()]
84 def instance(self):
85 """ Returns new AminoAcid object of this type """
86 return DNA(self)
88 class AminoAcid(Monomer):
89 """ Amino acid """
90 pass
92 class DNA(Monomer):
93 """ Deoxyribonucleic acid """
94 pass
96 # prepare all aminoacids
98 for code3, data in AAdict.items():
99 code1, m_type, is_modified, none, name = data
100 if m_type == 'p':
101 AminoAcidType(name, code1, code3, is_modified)
102 if m_type == 'd':
103 DNAType(name, code1, code3, is_modified)
104 del code3, data, code1, m_type, is_modified, none, name