Back to index

python-biopython  1.60
Structure.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 """The structure class, representing a macromolecular structure."""
00007 
00008 from Bio.PDB.Entity import Entity
00009 
00010 
00011 class Structure(Entity):
00012     """
00013     The Structure class contains a collection of Model instances.
00014     """
00015     def __init__(self, id):
00016         self.level="S"
00017         Entity.__init__(self, id)
00018 
00019     # Special methods
00020 
00021     def __repr__(self):
00022         return "<Structure id=%s>" % self.get_id()
00023 
00024     # Private methods
00025 
00026     def _sort(self, m1, m2):
00027         """Sort models.
00028 
00029         This sorting function sorts the Model instances in the Structure instance.
00030         The sorting is done based on the model id, which is a simple int that 
00031         reflects the order of the models in the PDB file.
00032 
00033         Arguments:
00034         o m1, m2 - Model instances
00035         """
00036         return cmp(m1.get_id(), m2.get_id())
00037 
00038     # Public 
00039 
00040     def get_chains(self):
00041         for m in self:
00042             for c in m:
00043                 yield c
00044 
00045     def get_residues(self):
00046         for c in self.get_chains():
00047             for r in c:
00048                 yield r
00049 
00050     def get_atoms(self):
00051         for r in self.get_residues():
00052             for a in r:
00053                 yield a
00054         
00055