1
2
3
4
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
50
51
52
54 """Trajctories worker class."""
55
57 """Set up Trajectories
58
59 :Arguments:
60 None at the moment, everything is hard coded.
61 """
62
63
64 dt = kwargs.pop('dt', 100)
65
66
67
68 super(_Trajectories, self).__init__(**kwargs)
69
70
71 self.parameters.dt = dt
72
73
74
75
76
77 if not self.simulation is None:
78 self._register_hook()
79
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
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
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
141 """No postprocessing."""
142 pass
143
144
145 - def plot(self, **kwargs):
146 """No plotting."""
147 pass
148
149
150
151
152
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