Added option to gmx nmeig to print ZPE.
[gromacs.git] / src / gromacs / trajectoryanalysis / topologyinformation.h
blob5748029dbccccb1b88726ea9fe297b2f3f9e2b67
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2018, 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.
35 /*! \file
36 * \brief
37 * Declares gmx::TopologyInformation.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \author Mark Abraham <mark.j.abraham@gmail.com>
41 * \inlibraryapi
42 * \ingroup module_trajectoryanalysis
44 #ifndef GMX_TRAJECTORYANALYSIS_TOPOLOGYINFORMATION_H
45 #define GMX_TRAJECTORYANALYSIS_TOPOLOGYINFORMATION_H
47 #include <memory>
48 #include <string>
49 #include <vector>
51 #include "gromacs/math/vectypes.h"
52 #include "gromacs/topology/atoms.h"
53 #include "gromacs/topology/topology.h"
54 #include "gromacs/utility/classhelpers.h"
56 //! Forward declaration
57 typedef struct gmx_rmpbc *gmx_rmpbc_t;
59 namespace gmx
62 template<typename T> class ArrayRef;
64 class TopologyInformation;
65 class TrajectoryAnalysisRunnerCommon;
67 /*! \libinternal
68 * \brief Topology information available to a trajectory analysis module.
70 * This class is used to provide topology information to trajectory
71 * analysis modules and to manage memory for them. Having a single
72 * wrapper object instead of passing each item separately makes
73 * TrajectoryAnalysisModule interface simpler, and also reduces the
74 * need to change existing code if additional information is added.
76 * It is intended that eventually most clients of this class will be
77 * analysis tools ported to the new analysis framework, but we will
78 * use this infrastructure also from the legacy analysis tools during
79 * the transition period. That will make it easier to put those tools
80 * under tests, and eventually port them.
82 * Methods in this class do not throw if not explicitly stated.
84 * The main data content is constant once loaded, but some content is
85 * constructed only when required (e.g. atoms_ and
86 * expandedTopology_). Their data members are mutable, so that the
87 * lazy construction idiom works properly. Some clients wish to modify
88 * the t_atoms, so there is an efficient mechanism for them to get a
89 * copy they can modify without disturbing this class. (The
90 * implementation releases the cached lazily constructed atoms_, but
91 * from the point of view of the caller, that is a copy.) The getters
92 * and copy functions are const for callers, which correctly expresses
93 * that the topology information is not being changed, merely copied
94 * and presented in a different form.
96 * \ingroup module_trajectoryanalysis
98 class TopologyInformation
100 public:
101 //! Returns true if a topology file was loaded.
102 bool hasTopology() const { return hasLoadedMtop_; }
103 //! Returns true if a full topology file was loaded.
104 bool hasFullTopology() const { return bTop_; }
105 /*! \brief Builder function to fill the contents of
106 * TopologyInformation in \c topInfo from \c filename.
108 * Different tools require, might need, would benefit from, or
109 * do not need topology information. This functions implements
110 * the two-phase construction that is currently needed to
111 * support that.
113 * Any coordinate or run input file format will work, but the
114 * kind of data available from the getter methods afterwards
115 * will vary. For example, the mtop() available after reading
116 * a plain structure file will have a single molecule block and
117 * molecule type, regardless of contents.
119 * After reading, this object can return many kinds of primary
120 * and derived data structures to its caller.
122 * \todo This should throw upon error but currently does
123 * not. */
124 void fillFromInputFile(const std::string &filename);
125 /*! \brief Returns the loaded topology, or nullptr if not loaded. */
126 gmx_mtop_t *mtop() const { return mtop_.get(); }
127 //! Returns the loaded topology fully expanded, or nullptr if no topology is available.
128 const gmx_localtop_t *expandedTopology() const;
129 /*! \brief Returns a read-only handle to the fully expanded
130 * atom data arrays, which might be valid but empty if no
131 * topology is available. */
132 const t_atoms *atoms() const;
133 /*! \brief Copies the fully expanded atom data arrays, which
134 * might be valid but empty if no topology is available. */
135 AtomsDataPtr copyAtoms() const;
136 //! Returns the ePBC field from the topology.
137 int ePBC() const { return ePBC_; }
138 /*! \brief
139 * Gets the configuration positions from the topology file.
141 * If TrajectoryAnalysisSettings::efUseTopX has not been specified,
142 * this method should not be called.
144 * \throws APIError if topology position coordinates are not available
146 ArrayRef<const RVec> x() const;
147 /*! \brief
148 * Gets the configuration velocities from the topology file.
150 * If TrajectoryAnalysisSettings::efUseTopV has not been specified,
151 * this method should not be called.
153 * \throws APIError if topology velocity coordinates are not available
155 ArrayRef<const RVec> v() const;
156 /*! \brief
157 * Gets the configuration box from the topology file.
159 * \param[out] box Box size from the topology file, must not be nullptr.
161 void getBox(matrix box) const;
162 /*! \brief Returns a name for the topology.
164 * If a full topology was read from a a file, returns the name
165 * it contained, otherwise the empty string. */
166 const char *name() const;
168 TopologyInformation();
169 ~TopologyInformation();
171 private:
172 //! The topology structure, or nullptr if no topology loaded.
173 std::unique_ptr<gmx_mtop_t> mtop_;
174 //! Whether a topology has been loaded.
175 bool hasLoadedMtop_;
176 //! The fully expanded topology structure, nullptr if not yet constructed.
177 mutable ExpandedTopologyPtr expandedTopology_;
178 //! The fully expanded atoms data structure, nullptr if not yet constructed.
179 mutable AtomsDataPtr atoms_;
180 //! true if full tpx file was loaded, false otherwise.
181 bool bTop_;
182 //! Position coordinates from the topology (can be nullptr).
183 std::vector<RVec> xtop_;
184 //! Velocity coordinates from the topology (can be nullptr).
185 std::vector<RVec> vtop_;
186 //! The box loaded from the topology file.
187 matrix boxtop_ {};
188 //! The ePBC field loaded from the topology file.
189 int ePBC_;
191 // TODO This type is probably movable if we need that.
192 GMX_DISALLOW_COPY_AND_ASSIGN(TopologyInformation);
194 /*! \brief
195 * Needed to initialize the data.
197 friend class TrajectoryAnalysisRunnerCommon;
200 //! Convenience overload useful for implementing legacy tools.
201 gmx_rmpbc_t gmx_rmpbc_init(const gmx::TopologyInformation &topInfo);
203 } // namespace gmx
205 #endif