From 2ba0249ec10d3f1c40af8efb9edb9740c7f1bbea Mon Sep 17 00:00:00 2001
From: marco <marco@5a81b35b-ba03-0410-adc8-b2c5c5119f08>
Date: Fri, 9 Apr 2010 12:46:42 +0000
Subject: [PATCH] add repository class
git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@1955 5a81b35b-ba03-0410-adc8-b2c5c5119f08
---
modules/io/pymod/CMakeLists.txt | 1 +
modules/io/pymod/repository.py | 50 +++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+)
create mode 100644 modules/io/pymod/repository.py
diff --git a/modules/io/pymod/CMakeLists.txt b/modules/io/pymod/CMakeLists.txt
index 55ea4a5f3..902089f7f 100644
--- a/modules/io/pymod/CMakeLists.txt
+++ b/modules/io/pymod/CMakeLists.txt
@@ -10,6 +10,7 @@ endif()
set(OST_IO_PYMOD_MODULES
__init__.py
hhsearch.py
+ repository.py
)
diff --git a/modules/io/pymod/repository.py b/modules/io/pymod/repository.py
new file mode 100644
index 000000000..ac6c1d1c2
--- /dev/null
+++ b/modules/io/pymod/repository.py
@@ -0,0 +1,50 @@
+import os.path
+import string
+import os
+
+from ost import io
+
+class ModelRepository:
+ """
+ Model repository. A model repository abstracts the way that PDB files are
+ loaded. Instead of explicitly specifying the PDB filename, only the PDB
+ id (and optionally a chain) needs to be specified. The actual files are then
+ resolved by the repository.
+
+ Usage
+ -----
+ The usage pattern of the model repository is simple. After construction,
+ models may be loaded by passing in a model id and optionally a number of
+ chain names (see documentation for io.LoadPDB).
+
+ Example:
+ import string
+ repos=repository.ModelRepository('path_to_pdbs',
+ file_pattern='pdb%(id)s.ent.gz',
+ transform=string.lower)
+ # load 1ake (note that the name is transformed by string.lower)
+ m=repos.Load('1AKE')
+ """
+ def __init__(self, directory=None,
+ file_pattern='%(id)s.pdb',transform=str):
+ """
+ Construct new model repository
+ """
+ if directory==None:
+ self.directory_=os.getenv('PDB_PATH', '')
+ else:
+ self.directory_=directory;
+ self.file_pattern_=file_pattern
+ self.transform_=transform or string.__init__
+ def FilenameForModel(self, pdb_id, chain):
+ pdb_id=self.transform_(pdb_id)
+ basename=self.file_pattern_ % {'id' : pdb_id, 'chain' :chain, 'dir' : pdb_id[1:3]}
+ return os.path.join(self.directory_, basename)
+
+ def Load(self, pdb_id, chains=""):
+ return io.LoadPDB(self.FilenameForModel(pdb_id, chains),
+ chains)
+
+ def LoadMulti(self, pdb_id, chains=""):
+ return io.LoadMultiPDB(self.FilenameForModel(pdb_id, chains))
+
--
GitLab