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

Source Code for Module gromacs.analysis.plugins.trajectories

  1  # $Id$ 
  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  Trajectories 
  8  ============ 
  9   
 10  Write centered trajectories. Trajectories will be stored under the 
 11  base dir / trj.   
 12   
 13  - full fitxy  
 14  - fitxy at 100 ps intervals 
 15   
 16   
 17  Plugin class 
 18  ------------ 
 19   
 20  .. autoclass:: Trajectories 
 21     :members: worker_class 
 22     :undoc-members: 
 23   
 24  Worker class 
 25  ------------ 
 26   
 27  The worker class performs the analysis. 
 28   
 29  .. autoclass:: _Trajectories 
 30     :members: 
 31   
 32   
 33  """ 
 34  from __future__ import with_statement 
 35   
 36  __docformat__ = "restructuredtext en" 
 37   
 38  import os 
 39  import errno 
 40  import warnings 
 41   
 42  import gromacs 
 43  from gromacs.utilities import AttributeDict 
 44  from gromacs.analysis.core import Worker, Plugin 
 45   
 46  import logging 
 47  logger = logging.getLogger('gromacs.analysis.plugins.trajectories') 
 48   
 49  # Worker classes that are registered via Plugins (see below) 
 50  # ---------------------------------------------------------- 
 51  # These must be defined before the plugins. 
 52   
53 -class _Trajectories(Worker):
54 """Trajctories worker class.""" 55
56 - def __init__(self,**kwargs):
57 """Set up Trajectories 58 59 :Arguments: 60 None at the moment, everything is hard coded. 61 """ 62 # specific arguments: take them before calling the super class that 63 # does not know what to do with them 64 dt = kwargs.pop('dt', 100) # reduced xtc: write steps every dt ps 65 66 # super class init: do this before doing anything else 67 # (also sets up self.parameters and self.results) 68 super(_Trajectories, self).__init__(**kwargs) 69 70 # process specific parameters now and set instance variables 71 self.parameters.dt = dt 72 73 # self.simulation might have been set by the super class 74 # already; just leave this snippet at the end. Do all 75 # initialization that requires the simulation class in the 76 # _register_hook() method. 77 if not self.simulation is None: 78 self._register_hook()
79
80 - def _register_hook(self, **kwargs):
81 """Run when registering; requires simulation.""" 82 83 super(_Trajectories, self)._register_hook(**kwargs) 84 assert not self.simulation is None 85 86 xtcdir,xtcname = os.path.split(self.simulation.xtc) 87 xtcbasename, xtcext = os.path.splitext(xtcname) 88 trjdir = os.path.join(xtcdir, 'trj') 89 fitxy_gro = os.path.join(trjdir, xtcbasename+'_fitxy'+'.gro') 90 fitxy_pdb = os.path.join(trjdir, xtcbasename+'_fitxy'+'.pdb') 91 fitxy_xtc = os.path.join(trjdir, xtcbasename+'_fitxy'+xtcext) 92 fitxydt_xtc = os.path.join(trjdir, (xtcbasename+'_fitxy_dt%dps'+xtcext) % self.parameters.dt) 93 94 # make sure trjdir exists 95 try: 96 os.makedirs(trjdir) 97 except OSError, err: 98 if err.errno == errno.EEXIST: 99 pass 100 101 self.parameters.trjdir = trjdir 102 self.parameters.filenames = { 103 'gro': fitxy_gro, 104 'pdb': fitxy_pdb, 105 'fitxy': fitxy_xtc, 106 'fitxydt': fitxydt_xtc, 107 }
108 109 # override 'API' methods of base class 110
111 - def run(self, force=False, **gmxargs):
112 """Write new trajectories""" 113 114 filename = self.parameters.filenames['gro'] 115 if not self.check_file_exists(filename, resolve='warning') or force: 116 logger.info("Writing fitted GRO file...") 117 gromacs.cbook.trj_fitandcenter(xy=True, s=self.simulation.tpr, f=self.simulation.xtc, 118 o=filename, dump=0) 119 120 filename = self.parameters.filenames['pdb'] 121 if not self.check_file_exists(filename, resolve='warning') or force: 122 logger.info("Writing fitted PDB file...") 123 gromacs.cbook.trj_fitandcenter(xy=True, s=self.simulation.tpr, f=self.simulation.xtc, 124 o=filename, dump=0) 125 126 filename = self.parameters.filenames['fitxydt'] 127 if not self.check_file_exists(filename, resolve='warning') or force: 128 logger.info("Writing fitted xtc file (frame every %d ps)..." % self.parameters.dt) 129 gromacs.cbook.trj_fitandcenter(xy=True, s=self.simulation.tpr, f=self.simulation.xtc, 130 o=filename, dt=self.parameters.dt) 131 132 filename = self.parameters.filenames['fitxy'] 133 if not self.check_file_exists(filename, resolve='warning') or force: 134 logger.info("Writing fitted xtc file (all frames)...") 135 gromacs.cbook.trj_fitandcenter(xy=True, s=self.simulation.tpr, f=self.simulation.xtc, 136 o=filename) 137 138 logger.info("New trajectories can be found in %r." % self.parameters.trjdir)
139
140 - def analyze(self,**kwargs):
141 """No postprocessing.""" 142 pass
143 144
145 - def plot(self, **kwargs):
146 """No plotting.""" 147 pass
148 149 150 # Public classes that register the worker classes 151 #------------------------------------------------ 152
153 -class Trajectories(Plugin):
154 """*Trajectories* plugin. 155 156 Write new xy-fitted trajectories (see :func:`gromacs.cbook.trj_fitandcenter`), 157 158 .. class:: Trajectories([name[, simulation]]) 159 160 :Arguments: 161 *name* : string 162 plugin name (used to access it) 163 *simulation* : instance 164 The :class:`gromacs.analysis.Simulation` instance that owns the plugin. 165 166 """ 167 worker_class = _Trajectories
168