2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2015, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
36 from gromacs import Options
37 from gromacs import TrajectoryAnalysis
39 class M(TrajectoryAnalysis.TrajectoryAnalysisModule):
41 super(M, self).__init__("a", "a")
43 def initOptions(self, options, settings):
44 print('python: initOptions')
46 settings.setHelpText('A stupid test module')
48 self.optionsHolder = Options.PyOptionsHolder()
50 options.addOption(self.optionsHolder.selectionOption('sel').required())
51 options.addOption(self.optionsHolder.fileNameOption('file').defaultBasename('test').description('filename from python to rule them all').outputFile().required().filetype(Options.eftGenericData))
52 settings.setFlag(TrajectoryAnalysis.TrajectoryAnalysisSettings.efRequireTop)
54 self.angle = TrajectoryAnalysis.AngleInfo.create()
56 print('python: inited')
59 print('python: getBatch')
63 print('python: getArgv')
65 #First element of list should be module name -- gets discarded by parser anyway
66 return ["gangle", "-group1", "Backbone", "-oav", "angles.xvg"]
68 def initAnalysis(self, settings, top):
69 print('python: initAnalysis')
70 print('There are {} atoms'.format(top.topology().atoms.nr))
71 print('Topology name: {}'.format(top.topology().name))
73 #Tell GROMACS to keep last frame in storage, required in analyzeFrame()
74 self.angle.datasetFromIndex(1).requestStorage(1)
76 def analyzeFrame(self, frnr, frame, pbc, data):
77 sel = self.optionsHolder['sel']
79 dataset = self.angle.datasetFromIndex(1)
81 print('frame =', frnr, ', columnCount =', dataset.columnCount(), ', y =', dataset.getDataFrame(frnr).y(0))
83 def finishAnalysis(self, nframes):
84 print('python: Analyzed {} frames'.format(nframes))
86 def writeOutput(self):
87 print('python: writeOutput')
88 print('file = {}'.format(self.optionsHolder['file']))
90 fo = open(self.optionsHolder['file'], 'w')
91 fo.write('Test output\n')
93 TrajectoryAnalysis.runAsMain(M(), sys.argv)