1
2
3
4
5
6 """
7 ProteinOnly
8 ===========
9
10 Write a trajectory with only the protein retained, using
11 :meth:`gromacs.cbook.Transformer.keep_protein_only`.
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:: _ProteinOnly
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 """ProteinOnly worker class."""
49
51 """Set up ProteinOnly
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:`_ProteinOnly.parameters.fit`).
74 *keepalso*
75 List of literal ``make_ndx`` selections that select additional
76 groups of atoms that should also be kept in addition to the
77 protein. For example *keepalso*=['"POPC"', 'resname DRUG'].
78 """
79
80
81 _fitvalues = ("xy", "all", None)
82 parameters = {}
83 parameters['fit'] = kwargs.pop('fit',None)
84 if not parameters['fit'] in _fitvalues:
85 raise ValueError("ProteinOnly: *fit* must be one of %(_fitvalues)r, not %(fit)r." % vars())
86 parameters['compact'] = kwargs.pop('compact', False)
87 parameters['dt'] = kwargs.pop('dt', None)
88 parameters['force'] = kwargs.pop('force', None)
89 parameters['keepalso'] = kwargs.pop('keepalso', None)
90
91
92
93 super(_ProteinOnly, self).__init__(**kwargs)
94
95
96 self.parameters.filenames = AttributeDict()
97 self.parameters.update(parameters)
98
99
100
101
102
103 if not self.simulation is None:
104 self._register_hook()
105
107 """Run when registering; requires simulation."""
108
109 super(_ProteinOnly, self)._register_hook(**kwargs)
110 assert not self.simulation is None
111
112 trjdir = os.path.dirname(self.simulation.tpr)
113 self.transformer = gromacs.cbook.Transformer(dirname=trjdir,
114 s=self.simulation.tpr, f=self.simulation.xtc, n=self.simulation.ndx)
115
116
117
118 - def run(self, **kwargs):
119 """Write new trajectory with water index group stripped.
120
121 kwargs are passed to
122 :meth:`gromacs.cbook.Transformer.strip_water`. Important
123 parameters:
124
125 :Keywords:
126 *force*
127 ``True`` will always regenerate trajectories even if they
128 already exist, ``False`` raises an exception, ``None``
129 does the sensible thing in most cases (i.e. notify and
130 then move on).
131 *dt* : float or list of floats
132 only write every dt timestep (in ps); if a list of floats is
133 supplied, write multiple trajectories, one for each dt.
134 *compact* : bool
135 write a compact representation
136 *fit*
137 Create an additional trajectory from the stripped one in which
138 the Protein group is rms-fitted to the initial structure. See
139 :meth:`gromacs.cbook.Transformer.fit` for details. Useful
140 values:
141 - "xy" : perform a rot+trans fit in the x-y plane
142 - "all": rot+trans
143 - ``None``: no fitting
144 If *fit* is not supplied then the constructore-default is used
145 (:attr:`_ProteinOnly.parameters.fit`).
146 *keepalso*
147 List of ``make_ndx`` selections that should also be kept.
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('force', self.parameters.force)
158 kwargs.setdefault('keepalso', self.parameters.keepalso)
159
160 newfiles = self.transformer.keep_protein_only(**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_proteinonly = self.transformer.proteinonly.values()[0]
169 for delta_t in asiterable(dt):
170 transformer_proteinonly.fit(xy=xy, dt=delta_t, force=kwargs['force'])
171
173 """No postprocessing."""
174 pass
175
176 - def plot(self, **kwargs):
177 """No plotting."""
178 pass
179
180
181
182
183
185 """*ProteinOnly* plugin.
186
187 Write a new trajectory which has the water index group removed.
188
189 .. class:: ProteinOnly([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 *force*
199 ``True`` will always regenerate trajectories even if they
200 already exist, ``False`` raises an exception, ``None``
201 does the sensible thing in most cases (i.e. notify and
202 then move on).
203 *dt* : float or list of floats
204 only write every dt timestep (in ps); if a list of floats is
205 supplied, write multiple trajectories, one for each dt.
206 *compact* : bool
207 write a compact representation
208 *fit*
209 Create an additional trajectory from the stripped one in which
210 the Protein group is rms-fitted to the initial structure. See
211 :meth:`gromacs.cbook.Transformer.fit` for details. Useful
212 values:
213 - "xy" : perform a rot+trans fit in the x-y plane
214 - "all": rot+trans
215 - ``None``: no fitting
216 If *fit* is not supplied then the constructore-default is used
217 (:attr:`_ProteinOnly.parameters.fit`).
218 *keepalso*
219 List of literal ``make_ndx`` selections that select additional
220 groups of atoms that should also be kept in addition to the
221 protein. For example *keepalso*=['"POPC"', 'resname DRUG'].
222
223 """
224 worker_class = _ProteinOnly
225