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

allpy

view lib/monomer.py @ 101:5091fef2ad88

lib::MonomerType operator== consider only one letter code align -- additional check of monomer equality fix bug with missing __ne__ where __eq__ present
author boris <bnagaev@gmail.com>
date Thu, 21 Oct 2010 00:39:57 +0400
parents 581c1f71c4ea
children 6479950a9ee3
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 # TO DISCUSS
36 def __eq__(self, other):
37 return self.code1 == other.code1
39 def __ne__(self, other):
40 return not self == other
43 class Monomer(object):
44 """
45 monomer_type -- link to monomer_type
46 pdb_residues -- dictionary like {Bio.PDB.Chain: Bio.PDB.Residue}
47 """
48 def __init__(self, monomer_type):
49 self.monomer_type = monomer_type
50 self.pdb_residue = []
52 def pdb_residue_add(self, pdb_chain, pdb_residue):
53 self.pdb_residue[pdb_chain] = pdb_residue
55 def __eq__(self, other):
56 return self.monomer_type == other.monomer_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 return AminoAcid(self)
74 class AminoAcid(Monomer):
75 """
76 Amino acid
77 """
78 pass
81 # prepare all aminoacids
83 for code3, data in AAdict.items():
84 code1, m_type, is_modified, none, name = data
85 if m_type == 'p':
86 aat = AminoAcidType(name, code1, code3, is_modified)