Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/file/ff68a1bef5eb/lib/monomer.py
Дата изменения: Unknown
Дата индексирования: Sat Mar 1 19:26:21 2014
Кодировка:
allpy: ff68a1bef5eb lib/monomer.py

allpy

view lib/monomer.py @ 152:ff68a1bef5eb

idea to prevent lack of memory
author boris (netbook) <bnagaev@gmail.com>
date Tue, 26 Oct 2010 13:32:19 +0400
parents 675b402094be
children 0c7f6117481b
line source
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
4 from allpy_data.AAdict import AAdict
5 import Bio.PDB
7 index_code3 = {}
8 index_code1_protein = {}
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 pdb_residues -- dictionary like {Bio.PDB.Chain: Bio.PDB.Residue}
53 pdb_secstr -- dictionary like {Bio.PDB.Chain: 'Secondary structure'}
54 Code Secondary structure
55 H ??-helix
56 B Isolated ??-bridge residue
57 E Strand
58 G 3-10 helix
59 I ??-helix
60 T Turn
61 S Bend
62 - Other
64 Idea: move pdb_residues and pdb_secstr to Sequence object
65 """
66 def __init__(self, monomer_type):
67 self.type = monomer_type
68 self.pdb_residues = {}
69 self.pdb_secstr = {}
71 def pdb_residue_add(self, chain, residue):
72 self.pdb_residues[chain] = residue
74 def __eq__(self, other):
75 return self.type == other.type
77 def __ne__(self, other):
78 return not (self == other)
80 class AminoAcidType(MonomerType):
81 def __init__(self, name, code1, code3, is_modified=False):
82 MonomerType.__init__(self, name, code1, code3, is_modified)
83 if not is_modified:
84 index_code1_protein[self.code1] = self
86 @staticmethod
87 def from_code1(code1):
88 return index_code1_protein[code1.upper()]
89 def instance(self):
90 """ Returns new AminoAcid object of this type """
91 return AminoAcid(self)
94 class AminoAcid(Monomer):
95 """ Amino acid """
96 pass
99 # prepare all aminoacids
101 for code3, data in AAdict.items():
102 code1, m_type, is_modified, none, name = data
103 if m_type == 'p':
104 AminoAcidType(name, code1, code3, is_modified)
106 del code3, data, code1, m_type, is_modified, none, name