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

Source Code for Module gromacs.analysis.plugins.stripwater

  1  # plugin for GromacsWrapper: stripwater.py 
  2  # Copyright (c) 2009 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  StripWater 
  8  ========== 
  9   
 10  Write a trajectory with all water removed. This uses 
 11  :meth:`gromacs.cbook.Transformer.strip_water`. 
 12   
 13  Plugin class 
 14  ------------ 
 15   
 16  .. autoclass:: Stripwater 
 17     :members: worker_class 
 18     :undoc-members: 
 19   
 20  Worker class 
 21  ------------ 
 22   
 23  The worker class performs the analysis. 
 24   
 25  .. autoclass:: _StripWater 
 26     :members: 
 27   
 28   
 29  """ 
 30  from __future__ import with_statement 
 31   
 32  __docformat__ = "restructuredtext en" 
 33   
 34  import os.path 
 35  import warnings 
 36   
 37  import gromacs 
 38  import gromacs.cbook 
 39  from gromacs.utilities import AttributeDict, asiterable 
 40  from gromacs.analysis.core import Worker, Plugin 
 41   
 42   
 43  # Worker classes that are registered via Plugins (see below) 
 44  # ---------------------------------------------------------- 
 45  # These must be defined before the plugins. 
 46   
47 -class _StripWater(Worker):
48 """StripWater worker class.""" 49
50 - def __init__(self,**kwargs):
51 """Set up StripWater 52 53 :Arguments: 54 *force* 55 ``True`` will always regenerate trajectories even if they 56 already exist, ``False`` raises an exception, ``None`` 57 does the sensible thing in most cases (i.e. notify and 58 then move on). 59 *dt* : float or list of floats 60 only write every dt timestep (in ps); if a list of floats is 61 supplied, write multiple trajectories, one for each dt. 62 *compact* : bool 63 write a compact representation 64 *fit* 65 Create an additional trajectory from the stripped one in which 66 the Protein group is rms-fitted to the initial structure. See 67 :meth:`gromacs.cbook.Transformer.fit` for details. Useful 68 values: 69 - "xy" : perform a rot+trans fit in the x-y plane 70 - "all": rot+trans 71 - ``None``: no fitting 72 If *fit* is not supplied then the constructore-default is used 73 (:attr:`_StripWater.parameters.fit`). 74 *resn* 75 name of the residues that are stripped (typically it is 76 safe to leave this at the default 'SOL') 77 """ 78 # specific arguments: take them before calling the super class that 79 # does not know what to do with them 80 _fitvalues = ("xy", "all", None) 81 parameters = {} 82 parameters['fit'] = kwargs.pop('fit',None) # fitting algorithm 83 if not parameters['fit'] in _fitvalues: 84 raise ValueError("StripWater: *fit* must be one of %(_fitvalues)r, not %(fit)r." % vars()) 85 parameters['compact'] = kwargs.pop('compact', False) # compact+centered ? 86 parameters['resn'] = kwargs.pop('resn', 'SOL') # residue name to be stripped 87 parameters['dt'] = kwargs.pop('dt', None) 88 parameters['force'] = kwargs.pop('force', None) 89 90 # super class init: do this before doing anything else 91 # (also sets up self.parameters and self.results) 92 super(_StripWater, self).__init__(**kwargs) 93 94 # self.parameters is set up by the base Worker class... 95 self.parameters.filenames = AttributeDict() 96 self.parameters.update(parameters) 97 98 # self.simulation might have been set by the super class 99 # already; just leave this snippet at the end. Do all 100 # initialization that requires the simulation class in the 101 # _register_hook() method. 102 if not self.simulation is None: 103 self._register_hook()
104
105 - def _register_hook(self, **kwargs):
106 """Run when registering; requires simulation.""" 107 108 super(_StripWater, self)._register_hook(**kwargs) 109 assert not self.simulation is None 110 111 trjdir = os.path.dirname(self.simulation.tpr) 112 self.transformer = gromacs.cbook.Transformer(dirname=trjdir, 113 s=self.simulation.tpr, f=self.simulation.xtc, n=self.simulation.ndx)
114 115 # override 'API' methods of base class 116
117 - def run(self, **kwargs):
118 """Write new trajectory with water index group stripped. 119 120 kwargs are passed to 121 :meth:`gromacs.cbook.Transformer.strip_water`. Important 122 parameters: 123 124 :Keywords: 125 *force* 126 ``True`` will always regenerate trajectories even if they 127 already exist, ``False`` raises an exception, ``None`` 128 does the sensible thing in most cases (i.e. notify and 129 then move on). 130 *dt* : float or list of floats 131 only write every dt timestep (in ps); if a list of floats is 132 supplied, write multiple trajectories, one for each dt. 133 *compact* : bool 134 write a compact representation 135 *fit* 136 Create an additional trajectory from the stripped one in which 137 the Protein group is rms-fitted to the initial structure. See 138 :meth:`gromacs.cbook.Transformer.fit` for details. Useful 139 values: 140 - "xy" : perform a rot+trans fit in the x-y plane 141 - "all": rot+trans 142 - ``None``: no fitting 143 If *fit* is not supplied then the constructore-default is used 144 (:attr:`_StripWater.parameters.fit`). 145 *resn* 146 name of the residues that are stripped (typically it is 147 safe to leave this at the default 'SOL') 148 149 .. Note:: If set, *dt* is only applied to a fit step; the 150 no-water trajectory is always generated for all time 151 steps of the input. 152 """ 153 dt = kwargs.pop('dt', self.parameters.dt) 154 fit = kwargs.pop('fit', self.parameters.fit) 155 156 kwargs.setdefault('compact', self.parameters.compact) 157 kwargs.setdefault('resn', self.parameters.resn) 158 kwargs.setdefault('force', self.parameters.force) 159 160 newfiles = self.transformer.strip_water(**kwargs) 161 self.parameters.filenames.update(newfiles) 162 163 if fit != None: 164 if self.parameters.fit == "xy": 165 xy = True 166 else: 167 xy = False 168 transformer_nowater = self.transformer.nowater.values()[0] 169 for delta_t in asiterable(dt): 170 transformer_nowater.fit(xy=xy, dt=delta_t, force=kwargs['force'])
171
172 - def analyze(self,**kwargs):
173 """No postprocessing.""" 174 pass
175 176
177 - def plot(self, **kwargs):
178 """No plotting.""" 179 pass
180 181 182 # Public classes that register the worker classes 183 #------------------------------------------------ 184
185 -class StripWater(Plugin):
186 """*StripWater* plugin. 187 188 Write a new trajectory which has the water index group removed. 189 190 .. class:: StripWater([selection[, name[, simulation]]]) 191 192 :Arguments: 193 *selection* 194 optional selection for the water instead of "SOL" 195 *name* : string 196 plugin name (used to access it) 197 *simulation* : instance 198 The :class:`gromacs.analysis.Simulation` instance that owns the plugin. 199 200 """ 201 worker_class = _StripWater
202