More const correctness
[gromacs.git] / src / gromacs / pulling / pull.h
blob525ad5858d13a3d96083be32c22cacba47054819
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
38 /*! \libinternal \file
41 * \brief
42 * This file contains datatypes and function declarations necessary
43 for mdrun to interface with the pull code.
45 * \author Berk Hess
47 * \inlibraryapi
50 #ifndef GMX_PULLING_PULL_H
51 #define GMX_PULLING_PULL_H
53 #include <cstdio>
55 #include "gromacs/math/vectypes.h"
56 #include "gromacs/mdtypes/pull-params.h"
57 #include "gromacs/pulling/pull_internal.h"
58 #include "gromacs/utility/basedefinitions.h"
59 #include "gromacs/utility/real.h"
61 struct ContinuationOptions;
62 struct gmx_mtop_t;
63 struct gmx_output_env_t;
64 struct pull_params_t;
65 struct t_commrec;
66 struct t_filenm;
67 struct t_inputrec;
68 struct t_mdatoms;
69 struct t_pbc;
71 namespace gmx
73 class ForceWithVirial;
76 /*! \brief Returns if the pull coordinate is an angle
78 * \param[in] pcrd The pull coordinate to query the type for.
79 * \returns a boolean telling if the coordinate is of angle type.
81 bool pull_coordinate_is_angletype(const t_pull_coord *pcrd);
83 /*! \brief Returns the units of the pull coordinate.
85 * \param[in] pcrd The pull coordinate to query the units for.
86 * \returns a string with the units of the coordinate.
88 const char *pull_coordinate_units(const t_pull_coord *pcrd);
90 /*! \brief Returns the conversion factor from the pull coord init/rate unit to internal value unit.
92 * \param[in] pcrd The pull coordinate to get the conversion factor for.
93 * \returns the conversion factor.
95 double pull_conversion_factor_userinput2internal(const t_pull_coord *pcrd);
97 /*! \brief Returns the conversion factor from the pull coord internal value unit to the init/rate unit.
99 * \param[in] pcrd The pull coordinate to get the conversion factor for.
100 * \returns the conversion factor.
102 double pull_conversion_factor_internal2userinput(const t_pull_coord *pcrd);
104 /*! \brief Get the value for pull coord coord_ind.
106 * \param[in,out] pull The pull struct.
107 * \param[in] coord_ind Number of the pull coordinate.
108 * \param[in] pbc Information structure about periodicity.
109 * \returns the value of the pull coordinate.
111 double get_pull_coord_value(struct pull_t *pull,
112 int coord_ind,
113 const struct t_pbc *pbc);
115 /*! \brief Registers the provider of an external potential for a coordinate.
117 * This function is only used for checking the consistency of the pull setup.
118 * For each pull coordinate of type external-potential, selected by the user
119 * in the mdp file, there has to be a module that provides this potential.
120 * The module registers itself as the provider by calling this function.
121 * The passed \p provider string has to match the string that the user
122 * passed with the potential-provider pull coordinate mdp option.
123 * This function should be called after init_pull has been called and before
124 * pull_potential is called for the first time.
125 * This function does many consistency checks and when it returns and the
126 * first call to do_potential passes, the pull setup is guaranteed to be
127 * correct (unless the module doesn't call apply_external_pull_coord_force
128 * every step or calls it with incorrect forces). This registering function
129 * will exit with a (release) assertion failure when used incorrely or
130 * with a fatal error when the user (mdp) input in inconsistent.
132 * Thread-safe for simultaneous registration from multiple threads.
134 * \param[in,out] pull The pull struct.
135 * \param[in] coord_index The pull coordinate index to register the external potential for.
136 * \param[in] provider Provider string, should match the potential-provider pull coordinate mdp option.
138 void register_external_pull_potential(struct pull_t *pull,
139 int coord_index,
140 const char *provider);
143 /*! \brief Apply forces of an external potential to a pull coordinate.
145 * This function applies the external scalar force \p coord_force to
146 * the pull coordinate, distributing it over the atoms in the groups
147 * involved in the pull coordinate. The corresponding potential energy
148 * value should be added to the pull or the module's potential energy term
149 * separately by the module itself.
150 * This function should be called after pull_potential has been called and,
151 * obviously, before the coordinates are updated uses the forces.
153 * \param[in,out] pull The pull struct.
154 * \param[in] coord_index The pull coordinate index to set the force for.
155 * \param[in] coord_force The scalar force for the pull coordinate.
156 * \param[in] mdatoms Atom properties, only masses are used.
157 * \param[in,out] forceWithVirial Force and virial buffers.
159 void apply_external_pull_coord_force(struct pull_t *pull,
160 int coord_index,
161 double coord_force,
162 const t_mdatoms *mdatoms,
163 gmx::ForceWithVirial *forceWithVirial);
166 /*! \brief Set the all the pull forces to zero.
168 * \param pull The pull group.
170 void clear_pull_forces(struct pull_t *pull);
173 /*! \brief Determine the COM pull forces and add them to f, return the potential
175 * \param[in,out] pull The pull struct.
176 * \param[in] md All atoms.
177 * \param[in] pbc Information struct about periodicity.
178 * \param[in] cr Struct for communication info.
179 * \param[in] t Time.
180 * \param[in] lambda The value of lambda in FEP calculations.
181 * \param[in] x Positions.
182 * \param[in,out] force Forces and virial.
183 * \param[out] dvdlambda Pull contribution to dV/d(lambda).
185 * \returns The pull potential energy.
187 real pull_potential(struct pull_t *pull, const t_mdatoms *md, struct t_pbc *pbc,
188 const t_commrec *cr, double t, real lambda,
189 const rvec *x, gmx::ForceWithVirial *force, real *dvdlambda);
192 /*! \brief Constrain the coordinates xp in the directions in x
193 * and also constrain v when v != NULL.
195 * \param[in,out] pull The pull data.
196 * \param[in] md All atoms.
197 * \param[in] pbc Information struct about periodicity.
198 * \param[in] cr Struct for communication info.
199 * \param[in] dt The time step length.
200 * \param[in] t The time.
201 * \param[in] x Positions.
202 * \param[in,out] xp Updated x, can be NULL.
203 * \param[in,out] v Velocities, which may get a pull correction.
204 * \param[in,out] vir The virial, which, if != NULL, gets a pull correction.
206 void pull_constraint(struct pull_t *pull, const t_mdatoms *md, struct t_pbc *pbc,
207 const t_commrec *cr, double dt, double t,
208 rvec *x, rvec *xp, rvec *v, tensor vir);
211 /*! \brief Make a selection of the home atoms for all pull groups.
212 * Should be called at every domain decomposition.
214 * \param cr Structure for communication info.
215 * \param pull The pull group.
216 * \param md All atoms.
218 void dd_make_local_pull_groups(const t_commrec *cr,
219 struct pull_t *pull, t_mdatoms *md);
222 /*! \brief Allocate, initialize and return a pull work struct.
224 * \param fplog General output file, normally md.log.
225 * \param pull_params The pull input parameters containing all pull settings.
226 * \param ir The inputrec.
227 * \param mtop The topology of the whole system.
228 * \param cr Struct for communication info.
229 * \param lambda FEP lambda.
231 struct pull_t *init_pull(FILE *fplog,
232 const pull_params_t *pull_params,
233 const t_inputrec *ir,
234 const gmx_mtop_t *mtop,
235 const t_commrec *cr,
236 real lambda);
238 /*! \brief Set up and open the pull output files, when requested.
240 * NOTE: This should only be called on the master rank and only when
241 * doing dynamics (e.g. not with energy minimization).
243 * \param pull The pull work data struct
244 * \param nfile Number of files.
245 * \param fnm Standard filename struct.
246 * \param oenv Output options.
247 * \param continuationOptions Options for continuing from checkpoint file
249 void init_pull_output_files(pull_t *pull,
250 int nfile,
251 const t_filenm fnm[],
252 const gmx_output_env_t *oenv,
253 const ContinuationOptions &continuationOptions);
255 /*! \brief Close the pull output files.
257 * \param pull The pull group.
259 void finish_pull(struct pull_t *pull);
262 /*! \brief Print the pull output (x and/or f)
264 * \param pull The pull data structure.
265 * \param step Time step number.
266 * \param time Time.
268 void pull_print_output(struct pull_t *pull, gmx_int64_t step, double time);
271 /*! \brief Calculates centers of mass all pull groups.
273 * \param[in] cr Struct for communication info.
274 * \param[in] pull The pull data structure.
275 * \param[in] md All atoms.
276 * \param[in] pbc Information struct about periodicity.
277 * \param[in] t Time, only used for cylinder ref.
278 * \param[in] x The local positions.
279 * \param[in,out] xp Updated x, can be NULL.
282 void pull_calc_coms(const t_commrec *cr,
283 pull_t *pull,
284 const t_mdatoms *md,
285 t_pbc *pbc,
286 double t,
287 const rvec x[],
288 rvec *xp);
291 /*! \brief Returns if we have pull coordinates with potential pulling.
293 * \param[in] pull The pull data structure.
295 gmx_bool pull_have_potential(const struct pull_t *pull);
298 /*! \brief Returns if we have pull coordinates with constraint pulling.
300 * \param[in] pull The pull data structure.
302 gmx_bool pull_have_constraint(const struct pull_t *pull);
304 /*! \brief Returns the maxing distance for pulling
306 * For distance geometries, only dimensions with pcrd->params[dim]=1
307 * are included in the distance calculation.
308 * For directional geometries, only dimensions with pcrd->vec[dim]!=0
309 * are included in the distance calculation.
311 * \param[in] pcrd Pulling data structure
312 * \param[in] pbc Information on periodic boundary conditions
313 * \returns The maximume distance
315 real max_pull_distance2(const pull_coord_work_t *pcrd,
316 const t_pbc *pbc);
318 #endif