OpenStructure
repository.py
Go to the documentation of this file.
1 import os.path
2 import string
3 import os
4 
5 from ost import io
6 
8  """
9  Model repository. A model repository abstracts the way that PDB files are
10  loaded. Instead of explicitly specifying the PDB filename, only the PDB
11  id (and optionally a chain) needs to be specified. The actual files are then
12  resolved by the repository.
13 
14  Usage
15  -----
16  The usage pattern of the model repository is simple. After construction,
17  models may be loaded by passing in a model id and optionally a number of
18  chain names (see documentation for io.LoadPDB).
19 
20  Example:
21  import string
22  repos=repository.ModelRepository('path_to_pdbs',
23  file_pattern='pdb%(id)s.ent.gz',
24  transform=string.lower)
25  # load 1ake (note that the name is transformed by string.lower)
26  m=repos.Load('1AKE')
27  """
28  def __init__(self, directory=None,
29  file_pattern='%(id)s.pdb',transform=str):
30  """
31  Construct new model repository
32  """
33  if directory==None:
34  self.directory_directory_=os.getenv('PDB_PATH', '')
35  else:
36  self.directory_directory_=directory;
37  self.file_pattern_file_pattern_=file_pattern
38  self.transform_transform_=transform or string.__init__
39  def FilenameForModel(self, pdb_id, chain):
40  pdb_id=self.transform_transform_(pdb_id)
41  basename=self.file_pattern_file_pattern_ % {'id' : pdb_id, 'chain' :chain, 'dir' : pdb_id[1:3]}
42  return os.path.join(self.directory_directory_, basename)
43 
44  def Load(self, pdb_id, chains='', calpha_only=False, fault_tolerant=False):
45  return io.LoadPDB(self.FilenameForModelFilenameForModel(pdb_id, chains),
46  chains, calpha_only=calpha_only,
47  fault_tolerant=fault_tolerant)
48 
49  def LoadMulti(self, pdb_id, chains=""):
50  return io.LoadMultiPDB(self.FilenameForModelFilenameForModel(pdb_id, chains))
51 
def FilenameForModel(self, pdb_id, chain)
Definition: repository.py:39
def __init__(self, directory=None, file_pattern='%(id) s.pdb', transform=str)
Definition: repository.py:29
def LoadMulti(self, pdb_id, chains="")
Definition: repository.py:49
def Load(self, pdb_id, chains='', calpha_only=False, fault_tolerant=False)
Definition: repository.py:44