00001 import os.path 00002 import string 00003 import os 00004 00005 from ost import io 00006 00007 class ModelRepository: 00008 """ 00009 Model repository. A model repository abstracts the way that PDB files are 00010 loaded. Instead of explicitly specifying the PDB filename, only the PDB 00011 id (and optionally a chain) needs to be specified. The actual files are then 00012 resolved by the repository. 00013 00014 Usage 00015 ----- 00016 The usage pattern of the model repository is simple. After construction, 00017 models may be loaded by passing in a model id and optionally a number of 00018 chain names (see documentation for io.LoadPDB). 00019 00020 Example: 00021 import string 00022 repos=repository.ModelRepository('path_to_pdbs', 00023 file_pattern='pdb%(id)s.ent.gz', 00024 transform=string.lower) 00025 # load 1ake (note that the name is transformed by string.lower) 00026 m=repos.Load('1AKE') 00027 """ 00028 def __init__(self, directory=None, 00029 file_pattern='%(id)s.pdb',transform=str): 00030 """ 00031 Construct new model repository 00032 """ 00033 if directory==None: 00034 self.directory_=os.getenv('PDB_PATH', '') 00035 else: 00036 self.directory_=directory; 00037 self.file_pattern_=file_pattern 00038 self.transform_=transform or string.__init__ 00039 def FilenameForModel(self, pdb_id, chain): 00040 pdb_id=self.transform_(pdb_id) 00041 basename=self.file_pattern_ % {'id' : pdb_id, 'chain' :chain, 'dir' : pdb_id[1:3]} 00042 return os.path.join(self.directory_, basename) 00043 00044 def Load(self, pdb_id, chains='', calpha_only=False, fault_tolerant=False): 00045 return io.LoadPDB(self.FilenameForModel(pdb_id, chains), 00046 chains, calpha_only=calpha_only, 00047 fault_tolerant=fault_tolerant) 00048 00049 def LoadMulti(self, pdb_id, chains=""): 00050 return io.LoadMultiPDB(self.FilenameForModel(pdb_id, chains)) 00051