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

Source Code for Module gromacs.analysis.plugins.rmsf

  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  RMSF calculation 
  8  ================ 
  9   
 10  Calculation of the root mean square fluctuations from a trajectory. 
 11   
 12  Plugin class 
 13  ------------ 
 14   
 15  .. autoclass:: RMSF 
 16     :members: worker_class 
 17     :undoc-members: 
 18   
 19  Worker class 
 20  ------------ 
 21   
 22  The worker class performs the analysis. 
 23   
 24  .. autoclass:: _RMSF 
 25     :members: 
 26   
 27   
 28  """ 
 29  from __future__ import with_statement 
 30   
 31  __docformat__ = "restructuredtext en" 
 32   
 33  import os.path 
 34  import warnings 
 35   
 36  import gromacs 
 37  from gromacs.utilities import AttributeDict 
 38  from gromacs.analysis.core import Worker, Plugin 
 39   
 40  import logging 
 41  logger = logging.getLogger('gromacs.analysis.plugins.rmsf') 
 42   
 43  # Worker classes that are registered via Plugins (see below) 
 44  # ---------------------------------------------------------- 
 45  # These must be defined before the plugins. 
 46   
47 -class _RMSF(Worker):
48 """RMSF worker class.""" 49
50 - def __init__(self,**kwargs):
51 """Set up RMSF analysis. 52 53 This is the worker class; this is where all the real analysis is done. 54 55 """ 56 super(_RMSF, self).__init__(**kwargs) 57 if not self.simulation is None: 58 self._register_hook()
59
60 - def _register_hook(self, **kwargs):
61 """Run when registering; requires simulation.""" 62 63 super(_RMSF, self)._register_hook(**kwargs) 64 assert not self.simulation is None 65 66 self.parameters.filenames = { 67 'RMSF': self.plugindir('rmsf.xvg'), 68 'RMSD': self.plugindir('rmsdev.xvg'), 69 } 70 # default filename for the plot 71 self.parameters.figname = self.figdir('rmsf')
72
73 - def run(self, force=False, group='C-alpha', **gmxargs):
74 """Analyze trajectory and write RMSF files. 75 76 The run method typically processes trajectories and writes data files. 77 78 :Arguments: 79 - *group*: index group (eg C-alpha or Protein) 80 - *force*: do analysis and overwrite existing files 81 - *gmxargs*: additional keyword arguments for :func:`gromacs.g_rmsf` (e.g. res=True) 82 """ 83 if not self.check_file_exists(self.parameters.filenames['RMSF'], resolve='warning') or force: 84 logger.info("Analyzing RMSF...") 85 gromacs.g_rmsf(s=self.simulation.tpr, f=self.simulation.xtc, fit=True, 86 o=self.parameters.filenames['RMSF'], 87 od=self.parameters.filenames['RMSD'], 88 input=[group], **gmxargs)
89
90 - def analyze(self,**kwargs):
91 """Collect output xvg files as :class:`gromacs.formats.XVG` objects. 92 93 :Returns: a dictionary of the results and also sets ``self.results``. 94 """ 95 from gromacs.formats import XVG 96 97 logger.info("Preparing RMSF graphs as XVG objects.") 98 results = AttributeDict(RMSF=XVG(self.parameters.filenames['RMSF']), 99 RMSD=XVG(self.parameters.filenames['RMSD'])) 100 self.results = results 101 return results
102
103 - def plot(self, **kwargs):
104 """Plot all results in one graph, labelled by the result keys. 105 106 :Keywords: 107 figure 108 - ``True``: save figures in the given formats 109 - "name.ext": save figure under this filename (``ext`` -> format) 110 - ``False``: only show on screen 111 formats : sequence 112 sequence of all formats that should be saved [('png', 'pdf')] 113 plotargs 114 keyword arguments for pylab.plot() 115 """ 116 117 import pylab 118 figure = kwargs.pop('figure', False) 119 extensions = kwargs.pop('formats', ('pdf','png')) 120 for name,result in self.results.items(): 121 kwargs['label'] = name 122 try: 123 result.plot(**kwargs) # This requires result classes with a plot() method!! 124 except AttributeError: 125 warnings.warn("Sorry, plotting of result %(name)r is not implemented" % vars(), 126 category=UserWarning) 127 pylab.legend(loc='best') 128 if figure is True: 129 for ext in extensions: 130 self.savefig(ext=ext) 131 elif figure: 132 self.savefig(filename=figure)
133 134 135 136 137 # Public classes that register the worker classes 138 #------------------------------------------------ 139
140 -class RMSF(Plugin):
141 """*RMSF* plugin. 142 143 Compute the root mean square fluctuations (RMSF) of the C-alpha 144 atoms. The trajectory is always fitted to the reference structure 145 in the tpr file. 146 147 .. class:: RMSF([name[, simulation]]) 148 149 :Arguments: 150 *name* : string 151 plugin name (used to access it) 152 *simulation* : instance 153 The :class:`gromacs.analysis.Simulation` instance that owns the plugin. 154 155 """ 156 worker_class = _RMSF
157