2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2019,2020, 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/fileio/trxio.h"
52 #include "gromacs/options/filenameoption.h"
53 #include "gromacs/options/ioptionscontainer.h"
54 #include "gromacs/selection/selectionoption.h"
55 #include "gromacs/trajectoryanalysis/analysissettings.h"
56 #include "gromacs/trajectoryanalysis/topologyinformation.h"
61 namespace analysismodules
71 class ConvertTrj : public TrajectoryAnalysisModule
76 void initOptions(IOptionsContainer* options, TrajectoryAnalysisSettings* settings) override;
77 void optionsFinished(TrajectoryAnalysisSettings* settings) override;
78 void initAnalysis(const TrajectoryAnalysisSettings& settings, const TopologyInformation& top) override;
79 void analyzeFrame(int frnr, const t_trxframe& fr, t_pbc* pbc, TrajectoryAnalysisModuleData* pdata) override;
81 void finishAnalysis(int nframes) override;
82 void writeOutput() override;
85 TrajectoryFrameWriterPointer output_;
88 OutputRequirementOptionDirector requirementsBuilder_;
91 ConvertTrj::ConvertTrj() {}
94 void ConvertTrj::initOptions(IOptionsContainer* options, TrajectoryAnalysisSettings* settings)
96 static const char* const desc[] = {
97 "[THISMODULE] converts trajectory files between different formats.",
98 "The module supports writing all GROMACS supported file formats from",
99 "the supported input formats.",
101 "Included is also a selection of possible options to modify individual",
102 "trajectory frames, including options to produce slimmer",
103 "output files. It is also possible to replace the particle information stored",
104 "in the input trajectory with those from a structure file",
106 "The module can also generate subsets of trajectories based on user supplied",
110 options->addOption(SelectionOption("select").store(&sel_).onlyAtoms().description(
111 "Selection of particles to write to the file"));
113 options->addOption(FileNameOption("o")
114 .filetype(eftTrajectory)
117 .defaultBasename("trajout")
119 .description("Output trajectory"));
121 requirementsBuilder_.initOptions(options);
123 settings->setHelpText(desc);
126 void ConvertTrj::optionsFinished(TrajectoryAnalysisSettings* settings)
128 int frameFlags = TRX_NEED_X;
130 frameFlags |= TRX_READ_V;
131 frameFlags |= TRX_READ_F;
133 settings->setFrameFlags(frameFlags);
137 void ConvertTrj::initAnalysis(const TrajectoryAnalysisSettings& /*settings*/, const TopologyInformation& top)
139 output_ = createTrajectoryFrameWriter(top.mtop(), sel_, name_,
140 top.hasTopology() ? top.copyAtoms() : nullptr,
141 requirementsBuilder_.process());
144 void ConvertTrj::analyzeFrame(int frnr, const t_trxframe& fr, t_pbc* /* pbc */, TrajectoryAnalysisModuleData* /*pdata*/)
146 output_->prepareAndWriteFrame(frnr, fr);
149 void ConvertTrj::finishAnalysis(int /*nframes*/) {}
152 void ConvertTrj::writeOutput() {}
156 const char ConvertTrjInfo::name[] = "convert-trj";
157 const char ConvertTrjInfo::shortDescription[] = "Converts between different trajectory types";
159 TrajectoryAnalysisModulePointer ConvertTrjInfo::create()
161 return TrajectoryAnalysisModulePointer(new ConvertTrj);
164 } // namespace analysismodules