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.
35 #ifndef GMX_MDLIB_ENERGYOUTPUT_H
36 #define GMX_MDLIB_ENERGYOUTPUT_H
40 #include "gromacs/mdtypes/enerdata.h"
42 class energyhistory_t;
44 struct gmx_ekindata_t;
45 struct gmx_enerdata_t;
48 struct gmx_output_env_t;
63 extern const char *egrp_nm[egNR+1];
65 /* delta_h block type enum: the kinds of energies written out. */
68 dhbtDH = 0, /* delta H BAR energy difference*/
69 dhbtDHDL = 1, /* dH/dlambda derivative */
70 dhbtEN, /* System energy */
72 dhbtEXPANDED, /* expanded ensemble statistics */
79 // TODO remove use of detail namespace when removing t_mdebin in
80 // favour of an Impl class.
86 /* The functions & data structures here determine the content for outputting
87 the .edr file; the file format and actual writing is done with functions
94 /*! \brief Initiate MD energy bin
96 * This second phase of construction is needed until we have
97 * modules that understand how to request output from
100 * \todo Refactor to separate a function to write the energy
101 * file header. Perhaps transform the remainder into a factory
104 void prepare(ener_file *fp_ene,
105 const gmx_mtop_t *mtop,
106 const t_inputrec *ir,
108 bool isRerun = false);
110 /*! \brief Update the averaging structures.
112 * Called every step on which the energies are evaluated. */
113 void addDataAtEnergyStep(bool bDoDHDL,
117 gmx_enerdata_t *enerd,
126 gmx_ekindata_t *ekind,
128 const gmx::Constraints *constr);
129 /*! \brief Updated the averaging structures
131 * Called every step on which the energies are not evaluated.
133 * \todo This schedule is known in advance, and should be made
134 * an intrinsic behaviour of EnergyOutput, rather than being
135 * wastefully called every step. */
136 void recordNonEnergyStep();
138 /*! \brief Help write quantites to the energy file
140 * \todo Perhaps this responsibility should involve some other
141 * object visiting all the contributing objects. */
142 void printStepToEnergyFile(ener_file *fp_ene, bool bEne, bool bDR, bool bOR,
144 int64_t step, double time,
147 gmx_groups_t *groups, t_grpopts *opts,
149 /*! \brief Get the number of energy terms recorded.
151 * \todo Refactor this to return the expected output size,
152 * rather than exposing the implementation details about
154 int numEnergyTerms() const;
155 /*! \brief Getter used for testing t_ebin
157 * \todo Find a better approach for this. */
160 /* Between .edr writes, the averages are history dependent,
161 and that history needs to be retained in checkpoints.
162 These functions set/read the energyhistory_t class
163 that is written to checkpoints in checkpoint.c */
165 //! Fill the energyhistory_t data.
166 void fillEnergyHistory(energyhistory_t * enerhist) const;
167 //! Restore from energyhistory_t data.
168 void restoreFromEnergyHistory(const energyhistory_t &enerhist);
171 // TODO transform this into an impl class.
172 detail::t_mdebin *mdebin = nullptr;
177 //! Open the dhdl file for output
178 FILE *open_dhdl(const char *filename, const t_inputrec *ir,
179 const gmx_output_env_t *oenv);
184 //! Print an energy-output header to the log file
185 void print_ebin_header(FILE *log, int64_t steps, double time);