Package gromacs :: Package analysis :: Package plugins :: Module ls
[hide private]
[frames] | no frames]

Source Code for Module gromacs.analysis.plugins.ls

  1  # GromacsWrapper plugin: ls.py 
  2  # Copyright (c) 2010 Oliver Beckstein <orbeckst@gmail.com> 
  3  # Released under the GNU Public License 3 (or higher, your choice) 
  4  # See the file COPYING for details. 
  5   
  6  """ 
  7  ls plugin 
  8  ========= 
  9   
 10  This simply lists the files on disk. It is useful for testing the 
 11  plugin architecture. 
 12   
 13   
 14  Plugin class 
 15  ------------ 
 16   
 17  .. autoclass:: Ls 
 18     :members: worker_class 
 19     :undoc-members: 
 20   
 21  Worker class 
 22  ------------ 
 23   
 24  The worker class performs the analysis. 
 25   
 26  .. autoclass:: _Ls 
 27     :members: 
 28   
 29   
 30  """ 
 31  from __future__ import with_statement 
 32   
 33  __docformat__ = "restructuredtext en" 
 34   
 35  import os.path 
 36  import warnings 
 37   
 38  import gromacs 
 39  from gromacs.utilities import AttributeDict 
 40  from gromacs.analysis.core import Worker, Plugin 
 41   
 42  import logging 
 43  logger = logging.getLogger('gromacs.analysis.plugins.ls') 
44 45 # Worker classes that are registered via Plugins (see below) 46 # ---------------------------------------------------------- 47 # These must be defined before the plugins. 48 49 -class _Ls(Worker):
50 """ls worker class.""" 51
52 - def __init__(self,**kwargs):
53 """ 54 :Arguments: 55 *kwargs* 56 same as ls ?? 57 """ 58 # super class init: do this before doing anything else 59 # (also sets up self.parameters and self.results) 60 super(_Ls, self).__init__(**kwargs) 61 62 # process specific parameters now and set instance variables 63 # .... 64 # self.parameters.filenames = { 'xxx': 'yyy', ....} 65 # .... 66 67 # self.simulation might have been set by the super class 68 # already; just leave this snippet at the end. Do all 69 # initialization that requires the simulation class in the 70 # _register_hook() method. 71 if not self.simulation is None: 72 self._register_hook()
73
74 - def _register_hook(self, **kwargs):
75 """Run when registering; requires simulation.""" 76 77 super(_Ls, self)._register_hook(**kwargs) 78 assert not self.simulation is None
79 80 81 # override 'API' methods of base class 82
83 - def run(self, *args, **kwargs):
84 """List the contents of the simulation directory. 85 """ 86 87 from subprocess import call 88 lscmd = ['ls', '-la'] + list(args) 89 cmd = lscmd + [self.simulation.tpr, self.simulation.xtc] 90 with rulify("TPR and XTC"): 91 rc = call(cmd) # just print to screen 92 93 adir = self.simulation.analysis_dir 94 cmd = lscmd + [adir] 95 with rulify("Analysis dir %(adir)s" % vars()): 96 rc = call(cmd) # just print to screen
97
98 - def analyze(self,**kwargs):
99 pass
100
101 - def plot(self, **kwargs):
102 pass
103 104 from contextlib import contextmanager
105 106 @contextmanager 107 -def rulify(header, ncol=79):
108 toprule = ncol * '=' 109 midrule = ncol * '-' 110 botrule = toprule 111 print toprule 112 print header 113 print midrule 114 try: 115 yield None 116 finally: 117 print botrule 118 print
119
120 # Public classes that register the worker classes 121 #------------------------------------------------ 122 123 -class Ls(Plugin):
124 """*ls* plugin. 125 126 This simply lists the files on disk. It is useful for testing the 127 plugin architecture. 128 129 .. class:: Ls([name[, simulation]]) 130 131 :Arguments: 132 *name* : string 133 plugin name (used to access it) 134 *simulation* : instance 135 The :class:`gromacs.analysis.Simulation` instance that owns the plugin. 136 137 """ 138 worker_class = _Ls
139