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

allpy

view lib/monomer.py @ 129:a6d287f9c901

broken: lib::block::geometrical_cores returns list of blocks added new parameters to geometrical_core test passed
author boris <bnagaev@gmail.com>
date Sun, 24 Oct 2010 00:26:18 +0400
parents 7a87d55efc17
children db9d116e979f
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 """
13 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 """
49 type -- link to MonomerType object
50 pdb_residues -- dictionary like {Bio.PDB.Chain: Bio.PDB.Residue}
51 """
52 def __init__(self, monomer_type):
53 self.type = monomer_type
54 self.pdb_residues = {}
56 def pdb_residue_add(self, chain, residue):
57 self.pdb_residues[chain] = residue
59 def __eq__(self, other):
60 return self.type == other.type
62 def __ne__(self, other):
63 return not (self == other)
65 class AminoAcidType(MonomerType):
66 def __init__(self, name, code1, code3, is_modified=False):
67 MonomerType.__init__(self, name, code1, code3, is_modified)
68 if not is_modified:
69 index_code1_protein[self.code1] = self
71 @staticmethod
72 def from_code1(code1):
73 return index_code1_protein[code1.upper()]
74 def instance(self):
75 return AminoAcid(self)
78 class AminoAcid(Monomer):
79 """
80 Amino acid
81 """
82 pass
85 # prepare all aminoacids
87 for code3, data in AAdict.items():
88 code1, m_type, is_modified, none, name = data
89 if m_type == 'p':
90 aat = AminoAcidType(name, code1, code3, is_modified)