1
2
3
4
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
44
45
46
48 """StripWater worker class."""
49
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
79
80 _fitvalues = ("xy", "all", None)
81 parameters = {}
82 parameters['fit'] = kwargs.pop('fit',None)
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)
86 parameters['resn'] = kwargs.pop('resn', 'SOL')
87 parameters['dt'] = kwargs.pop('dt', None)
88 parameters['force'] = kwargs.pop('force', None)
89
90
91
92 super(_StripWater, self).__init__(**kwargs)
93
94
95 self.parameters.filenames = AttributeDict()
96 self.parameters.update(parameters)
97
98
99
100
101
102 if not self.simulation is None:
103 self._register_hook()
104
106 """Run when registering; requires simulation."""
107
108 super(_StripWater, self)._register_hook(**kwargs)
109 assert not self.simulation is None
110
111 self.transformer = gromacs.cbook.Transformer(
112 s=self.simulation.tpr, f=self.simulation.xtc, n=self.simulation.ndx)
113
114
115
116 - def run(self, **kwargs):
117 """Write new trajectory with water index group stripped.
118
119 kwargs are passed to
120 :meth:`gromacs.cbook.Transformer.strip_water`. Important
121 parameters:
122
123 :Keywords:
124 *force*
125 ``True`` will always regenerate trajectories even if they
126 already exist, ``False`` raises an exception, ``None``
127 does the sensible thing in most cases (i.e. notify and
128 then move on).
129 *dt* : float or list of floats
130 only write every dt timestep (in ps); if a list of floats is
131 supplied, write multiple trajectories, one for each dt.
132 *compact* : bool
133 write a compact representation
134 *fit*
135 Create an additional trajectory from the stripped one in which
136 the Protein group is rms-fitted to the initial structure. See
137 :meth:`gromacs.cbook.Transformer.fit` for details. Useful
138 values:
139 - "xy" : perform a rot+trans fit in the x-y plane
140 - "all": rot+trans
141 - ``None``: no fitting
142 If *fit* is not supplied then the constructore-default is used
143 (:attr:`_StripWater.parameters.fit`).
144 *resn*
145 name of the residues that are stripped (typically it is
146 safe to leave this at the default 'SOL')
147
148 .. Note:: If set, *dt* is only applied to a fit step; the
149 no-water trajectory is always generated for all time
150 steps of the input.
151 """
152 dt = kwargs.pop('dt', self.parameters.dt)
153 fit = kwargs.pop('fit', self.parameters.fit)
154
155 kwargs.setdefault('compact', self.parameters.compact)
156 kwargs.setdefault('resn', self.parameters.resn)
157 kwargs.setdefault('force', self.parameters.force)
158
159 newfiles = self.transformer.strip_water(**kwargs)
160 self.parameters.filenames.update(newfiles)
161
162 if fit != None:
163 if self.parameters.fit == "xy":
164 xy = True
165 else:
166 xy = False
167 transformer_nowater = self.transformer.nowater.values()[0]
168 for delta_t in asiterable(dt):
169 transformer_nowater.fit(xy=xy, dt=delta_t, force=kwargs['force'])
170
172 """No postprocessing."""
173 pass
174
175
176 - def plot(self, **kwargs):
177 """No plotting."""
178 pass
179
180
181
182
183
185 """*StripWater* plugin.
186
187 Write a new trajectory which has the water index group removed.
188
189 .. class:: StripWater([selection[, name[, simulation]]])
190
191 :Arguments:
192 *selection*
193 optional selection for the water instead of "SOL"
194 *name* : string
195 plugin name (used to access it)
196 *simulation* : instance
197 The :class:`gromacs.analysis.Simulation` instance that owns the plugin.
198
199 """
200 worker_class = _StripWater
201