Package Bio :: Package PDB :: Module Model
[hide private]
[frames] | no frames]

Source Code for Module Bio.PDB.Model

 1  # Copyright (C) 2002, Thomas Hamelryck (thamelry@binf.ku.dk) 
 2  # This code is part of the Biopython distribution and governed by its 
 3  # license.  Please see the LICENSE file that should have been included 
 4  # as part of this package. 
 5   
 6  """Model class, used in Structure objects.""" 
 7   
 8  from Bio.PDB.Entity import Entity 
 9   
10   
11 -class Model(Entity):
12 """The object representing a model in a structure. In a structure 13 derived from an X-ray crystallography experiment, only a single 14 model will be present (with some exceptions). NMR structures 15 normally contain many different models. 16 """ 17
18 - def __init__(self, id, serial_num=None):
19 """Initialize. 20 21 Arguments: 22 - id - int 23 - serial_num - int 24 25 """ 26 self.level = "M" 27 if serial_num is None: 28 self.serial_num = id 29 else: 30 self.serial_num = serial_num 31 32 Entity.__init__(self, id)
33 34 # Private methods 35
36 - def _sort(self, c1, c2):
37 """Sort the Chains instances in the Model instance. 38 39 Chain instances are sorted alphabetically according to 40 their chain id. Blank chains come last, as they often consist 41 of waters. 42 43 Arguments: 44 - c1, c2 - Chain objects 45 46 """ 47 id1 = c1.get_id() 48 id2 = c2.get_id() 49 # make sure blank chains come last (often waters) 50 if id1 == " " and not id2 == " ": 51 return 1 52 elif id2 == " " and not id1 == " ": 53 return -1 54 return cmp(id1, id2)
55 56 # Special methods 57
58 - def __repr__(self):
59 return "<Model id=%s>" % self.get_id()
60 61 # Public 62
63 - def get_chains(self):
64 for c in self: 65 yield c
66
67 - def get_residues(self):
68 for c in self.get_chains(): 69 for r in c: 70 yield r
71
72 - def get_atoms(self):
73 for r in self.get_residues(): 74 for a in r: 75 yield a
76