Back to index

python-biopython  1.60
Model.py
Go to the documentation of this file.
00001 # Copyright (C) 2002, Thomas Hamelryck (thamelry@binf.ku.dk)
00002 # This code is part of the Biopython distribution and governed by its
00003 # license.  Please see the LICENSE file that should have been included
00004 # as part of this package.  
00005 
00006 """Model class, used in Structure objects."""
00007 
00008 from Bio.PDB.Entity import Entity
00009 
00010 
00011 class Model(Entity):
00012     """
00013     The object representing a model in a structure. In a structure
00014     derived from an X-ray crystallography experiment, only a single 
00015     model will be present (with some exceptions). NMR structures 
00016     normally contain many different models. 
00017     """
00018 
00019     def __init__(self, id, serial_num = None):
00020         """
00021         Arguments:
00022         o id - int
00023         o serial_num - int
00024         """
00025         self.level="M"
00026         if serial_num is None:
00027             self.serial_num=id
00028         else:
00029             self.serial_num=serial_num
00030 
00031         Entity.__init__(self, id)
00032 
00033     # Private methods
00034 
00035     def _sort(self, c1, c2):
00036         """Sort the Chains instances in the Model instance.
00037 
00038         Chain instances are sorted alphabetically according to
00039         their chain id. Blank chains come last, as they often consist
00040         of waters.
00041 
00042         Arguments:
00043         o c1, c2 - Chain objects
00044         """
00045         id1=c1.get_id()
00046         id2= c2.get_id()
00047         # make sure blank chains come last (often waters)
00048         if id1==" " and not id2==" ":
00049             return 1
00050         elif id2==" " and not id1==" ":
00051             return -1
00052         return cmp(id1, id2)
00053 
00054     # Special methods
00055 
00056     def __repr__(self):
00057         return "<Model id=%s>" % self.get_id()
00058 
00059     # Public
00060 
00061     def get_residues(self):
00062         for c in self:
00063             for r in c:
00064                 yield r
00065 
00066     def get_atoms(self):
00067         for r in self.get_residues():
00068             for a in r:
00069                 yield a
00070