2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2019, 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.
37 * Implements gmx::analysismodules::ConvertTrj.
39 * \author Paul Bauer <paul.bauer.q@gmail.com>
40 * \ingroup module_trajectoryanalysis
45 #include "convert_trj.h"
49 #include "gromacs/coordinateio/coordinatefile.h"
50 #include "gromacs/coordinateio/requirements.h"
51 #include "gromacs/options/filenameoption.h"
52 #include "gromacs/options/ioptionscontainer.h"
53 #include "gromacs/selection/selectionoption.h"
54 #include "gromacs/trajectoryanalysis/analysissettings.h"
55 #include "gromacs/trajectoryanalysis/topologyinformation.h"
60 namespace analysismodules
70 class ConvertTrj
: public TrajectoryAnalysisModule
75 void initOptions(IOptionsContainer
*options
,
76 TrajectoryAnalysisSettings
*settings
) override
;
77 void optionsFinished(TrajectoryAnalysisSettings
*settings
) override
;
78 void initAnalysis(const TrajectoryAnalysisSettings
&settings
,
79 const TopologyInformation
&top
) override
;
80 void analyzeFrame(int frnr
, const t_trxframe
&fr
, t_pbc
*pbc
,
81 TrajectoryAnalysisModuleData
*pdata
) override
;
83 void finishAnalysis(int nframes
) override
;
84 void writeOutput() override
;
87 TrajectoryFrameWriterPointer output_
;
90 OutputRequirementOptionDirector requirementsBuilder_
;
93 ConvertTrj::ConvertTrj()
99 ConvertTrj::initOptions(IOptionsContainer
*options
, TrajectoryAnalysisSettings
*settings
)
101 static const char *const desc
[] = {
102 "[THISMODULE] converts trajectory files between different formats.",
103 "The module supports writing all GROMACS supported file formats from",
104 "the supported input formats.",
106 "Included is also a selection of possible options to modify individual",
107 "trajectory frames, including options to produce slimmer",
108 "output files. It is also possible to replace the particle information stored",
109 "in the input trajectory with those from a structure file",
111 "The module can also generate subsets of trajectories based on user supplied",
115 options
->addOption(SelectionOption("select")
118 .description("Selection of particles to write to the file"));
120 options
->addOption(FileNameOption("o")
121 .filetype(eftTrajectory
)
123 .store(&name_
).defaultBasename("trajout")
125 .description("Output trajectory"));
127 requirementsBuilder_
.initOptions(options
);
129 settings
->setHelpText(desc
);
133 ConvertTrj::optionsFinished(TrajectoryAnalysisSettings
* settings
)
135 int frameFlags
= TRX_NEED_X
;
137 frameFlags
|= TRX_READ_V
;
138 frameFlags
|= TRX_READ_F
;
140 settings
->setFrameFlags(frameFlags
);
145 ConvertTrj::initAnalysis(const TrajectoryAnalysisSettings
& /*settings*/,
146 const TopologyInformation
&top
)
148 output_
= createTrajectoryFrameWriter(top
.mtop(),
151 top
.hasTopology() ? top
.copyAtoms() : nullptr,
152 requirementsBuilder_
.process());
156 ConvertTrj::analyzeFrame(int frnr
, const t_trxframe
&fr
, t_pbc
* /* pbc */,
157 TrajectoryAnalysisModuleData
* /*pdata*/)
159 output_
->prepareAndWriteFrame(frnr
, fr
);
163 ConvertTrj::finishAnalysis(int /*nframes*/)
170 ConvertTrj::writeOutput()
176 const char ConvertTrjInfo::name
[] = "convert-trj";
177 const char ConvertTrjInfo::shortDescription
[] =
178 "Converts between different trajectory types";
180 TrajectoryAnalysisModulePointer
ConvertTrjInfo::create()
182 return TrajectoryAnalysisModulePointer(new ConvertTrj
);
185 } // namespace analysismodules