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
42 * This file contains datatypes and function declarations necessary
43 for mdrun to interface with the pull code.
50 #ifndef GMX_PULLING_PULL_H
51 #define GMX_PULLING_PULL_H
55 #include "gromacs/math/vectypes.h"
56 #include "gromacs/mdlib/mdrun.h"
57 #include "gromacs/mdtypes/pull-params.h"
58 #include "gromacs/utility/arrayref.h"
59 #include "gromacs/utility/basedefinitions.h"
60 #include "gromacs/utility/real.h"
62 struct ContinuationOptions;
64 struct gmx_output_env_t;
65 struct pull_coord_work_t;
76 class ForceWithVirial;
77 class LocalAtomSetManager;
80 /*! \brief Returns if the pull coordinate is an angle
82 * \param[in] pcrd The pull coordinate to query the type for.
83 * \returns a boolean telling if the coordinate is of angle type.
85 bool pull_coordinate_is_angletype(const t_pull_coord *pcrd);
87 /*! \brief Returns the units of the pull coordinate.
89 * \param[in] pcrd The pull coordinate to query the units for.
90 * \returns a string with the units of the coordinate.
92 const char *pull_coordinate_units(const t_pull_coord *pcrd);
94 /*! \brief Returns the conversion factor from the pull coord init/rate unit to internal value unit.
96 * \param[in] pcrd The pull coordinate to get the conversion factor for.
97 * \returns the conversion factor.
99 double pull_conversion_factor_userinput2internal(const t_pull_coord *pcrd);
101 /*! \brief Returns the conversion factor from the pull coord internal value unit to the init/rate unit.
103 * \param[in] pcrd The pull coordinate to get the conversion factor for.
104 * \returns the conversion factor.
106 double pull_conversion_factor_internal2userinput(const t_pull_coord *pcrd);
108 /*! \brief Get the value for pull coord coord_ind.
110 * \param[in,out] pull The pull struct.
111 * \param[in] coord_ind Number of the pull coordinate.
112 * \param[in] pbc Information structure about periodicity.
113 * \returns the value of the pull coordinate.
115 double get_pull_coord_value(struct pull_t *pull,
117 const struct t_pbc *pbc);
119 /*! \brief Registers the provider of an external potential for a coordinate.
121 * This function is only used for checking the consistency of the pull setup.
122 * For each pull coordinate of type external-potential, selected by the user
123 * in the mdp file, there has to be a module that provides this potential.
124 * The module registers itself as the provider by calling this function.
125 * The passed \p provider string has to match the string that the user
126 * passed with the potential-provider pull coordinate mdp option.
127 * This function should be called after init_pull has been called and before
128 * pull_potential is called for the first time.
129 * This function does many consistency checks and when it returns and the
130 * first call to do_potential passes, the pull setup is guaranteed to be
131 * correct (unless the module doesn't call apply_external_pull_coord_force
132 * every step or calls it with incorrect forces). This registering function
133 * will exit with a (release) assertion failure when used incorrely or
134 * with a fatal error when the user (mdp) input in inconsistent.
136 * Thread-safe for simultaneous registration from multiple threads.
138 * \param[in,out] pull The pull struct.
139 * \param[in] coord_index The pull coordinate index to register the external potential for.
140 * \param[in] provider Provider string, should match the potential-provider pull coordinate mdp option.
142 void register_external_pull_potential(struct pull_t *pull,
144 const char *provider);
147 /*! \brief Apply forces of an external potential to a pull coordinate.
149 * This function applies the external scalar force \p coord_force to
150 * the pull coordinate, distributing it over the atoms in the groups
151 * involved in the pull coordinate. The corresponding potential energy
152 * value should be added to the pull or the module's potential energy term
153 * separately by the module itself.
154 * This function should be called after pull_potential has been called and,
155 * obviously, before the coordinates are updated uses the forces.
157 * \param[in,out] pull The pull struct.
158 * \param[in] coord_index The pull coordinate index to set the force for.
159 * \param[in] coord_force The scalar force for the pull coordinate.
160 * \param[in] mdatoms Atom properties, only masses are used.
161 * \param[in,out] forceWithVirial Force and virial buffers.
163 void apply_external_pull_coord_force(struct pull_t *pull,
166 const t_mdatoms *mdatoms,
167 gmx::ForceWithVirial *forceWithVirial);
170 /*! \brief Set the all the pull forces to zero.
172 * \param pull The pull group.
174 void clear_pull_forces(struct pull_t *pull);
177 /*! \brief Determine the COM pull forces and add them to f, return the potential
179 * \param[in,out] pull The pull struct.
180 * \param[in] md All atoms.
181 * \param[in] pbc Information struct about periodicity.
182 * \param[in] cr Struct for communication info.
184 * \param[in] lambda The value of lambda in FEP calculations.
185 * \param[in] x Positions.
186 * \param[in,out] force Forces and virial.
187 * \param[out] dvdlambda Pull contribution to dV/d(lambda).
189 * \returns The pull potential energy.
191 real pull_potential(struct pull_t *pull, const t_mdatoms *md, struct t_pbc *pbc,
192 const t_commrec *cr, double t, real lambda,
193 const rvec *x, gmx::ForceWithVirial *force, real *dvdlambda);
196 /*! \brief Constrain the coordinates xp in the directions in x
197 * and also constrain v when v != NULL.
199 * \param[in,out] pull The pull data.
200 * \param[in] md All atoms.
201 * \param[in] pbc Information struct about periodicity.
202 * \param[in] cr Struct for communication info.
203 * \param[in] dt The time step length.
204 * \param[in] t The time.
205 * \param[in] x Positions.
206 * \param[in,out] xp Updated x, can be NULL.
207 * \param[in,out] v Velocities, which may get a pull correction.
208 * \param[in,out] vir The virial, which, if != NULL, gets a pull correction.
210 void pull_constraint(struct pull_t *pull, const t_mdatoms *md, struct t_pbc *pbc,
211 const t_commrec *cr, double dt, double t,
212 rvec *x, rvec *xp, rvec *v, tensor vir);
215 /*! \brief Make a selection of the home atoms for all pull groups.
216 * Should be called at every domain decomposition.
218 * \param cr Structure for communication info.
219 * \param pull The pull group.
221 void dd_make_local_pull_groups(const t_commrec *cr, struct pull_t *pull);
224 /*! \brief Allocate, initialize and return a pull work struct.
226 * \param fplog General output file, normally md.log.
227 * \param pull_params The pull input parameters containing all pull settings.
228 * \param ir The inputrec.
229 * \param mtop The topology of the whole system.
230 * \param cr Struct for communication info.
231 * \param atomSets The manager that handles the pull atom sets
232 * \param lambda FEP lambda.
234 struct pull_t *init_pull(FILE *fplog,
235 const pull_params_t *pull_params,
236 const t_inputrec *ir,
237 const gmx_mtop_t *mtop,
239 gmx::LocalAtomSetManager *atomSets,
243 /*! \brief Close the pull output files and delete pull.
245 * \param pull The pull data structure.
247 void finish_pull(struct pull_t *pull);
250 /*! \brief Calculates centers of mass all pull groups.
252 * \param[in] cr Struct for communication info.
253 * \param[in] pull The pull data structure.
254 * \param[in] md All atoms.
255 * \param[in] pbc Information struct about periodicity.
256 * \param[in] t Time, only used for cylinder ref.
257 * \param[in] x The local positions.
258 * \param[in,out] xp Updated x, can be NULL.
261 void pull_calc_coms(const t_commrec *cr,
269 /*! \brief Margin for checking pull group PBC distances compared to half the box size */
270 static constexpr real c_pullGroupPbcMargin = 0.9;
271 /*! \brief Threshold (as a factor of half the box size) for accepting pull groups without explicitly set refatom */
272 static constexpr real c_pullGroupSmallGroupThreshold = 0.5;
274 /*! \brief Checks whether all groups that use a reference atom are within PBC restrictions
276 * Groups that use a reference atom for determining PBC should have all their
277 * atoms within half the box size from the PBC atom. The box size is used
278 * per dimension for rectangular boxes, but can be a combination of
279 * dimensions for triclinic boxes, depending on which dimensions are
280 * involved in the pull coordinates a group is involved in. A margin is specified
281 * to ensure that atoms are not too close to the maximum distance.
283 * Should be called without MPI parallelization and after pull_calc_coms()
284 * has been called at least once.
286 * \param[in] pull The pull data structure
287 * \param[in] x The coordinates
288 * \param[in] pbc Information struct about periodicity
289 * \param[in] pbcMargin The minimum margin (as a fraction) to half the box size
290 * \returns -1 when all groups obey PBC or the first group index that fails PBC
292 int pullCheckPbcWithinGroups(const pull_t &pull,
297 /*! \brief Checks whether a specific group that uses a reference atom is within PBC restrictions
299 * Groups that use a reference atom for determining PBC should have all their
300 * atoms within half the box size from the PBC atom. The box size is used
301 * per dimension for rectangular boxes, but can be a combination of
302 * dimensions for triclinic boxes, depending on which dimensions are
303 * involved in the pull coordinates a group is involved in. A margin is specified
304 * to ensure that atoms are not too close to the maximum distance. Only one group is
307 * Should be called without MPI parallelization and after pull_calc_coms()
308 * has been called at least once.
310 * \param[in] pull The pull data structure
311 * \param[in] x The coordinates
312 * \param[in] pbc Information struct about periodicity
313 * \param[in] groupNr The index of the group (in pull.group[]) to check
314 * \param[in] pbcMargin The minimum margin (as a fraction) to half the box size
315 * \returns true if the group obeys PBC otherwise false
317 bool pullCheckPbcWithinGroup(const pull_t &pull,
318 gmx::ArrayRef<const gmx::RVec> x,
323 /*! \brief Returns if we have pull coordinates with potential pulling.
325 * \param[in] pull The pull data structure.
327 gmx_bool pull_have_potential(const struct pull_t *pull);
330 /*! \brief Returns if we have pull coordinates with constraint pulling.
332 * \param[in] pull The pull data structure.
334 gmx_bool pull_have_constraint(const struct pull_t *pull);
336 /*! \brief Returns the maxing distance for pulling
338 * For distance geometries, only dimensions with pcrd->params[dim]=1
339 * are included in the distance calculation.
340 * For directional geometries, only dimensions with pcrd->vec[dim]!=0
341 * are included in the distance calculation.
343 * \param[in] pcrd Pulling data structure
344 * \param[in] pbc Information on periodic boundary conditions
345 * \returns The maximume distance
347 real max_pull_distance2(const pull_coord_work_t *pcrd,
350 /*! \brief Copies the COM from the previous step of all pull groups to the checkpoint state container
352 * \param[in] pull The COM pull force calculation data structure
353 * \param[in] state The global state container
355 void setStatePrevStepPullCom(const struct pull_t *pull, t_state *state);
357 /*! \brief Copies the pull group COM of the previous step from the checkpoint state to the pull state
359 * \param[in] pull The COM pull force calculation data structure
360 * \param[in] state The global state container
362 void setPrevStepPullComFromState(struct pull_t *pull, const t_state *state);
364 /*! \brief Sets the previous step COM to the current COM
366 * \param[in] pull The COM pull force calculation data structure
368 void updatePrevStepCom(struct pull_t *pull);
370 /*! \brief Resizes the vector, in the state container, containing the COMs from the previous step
372 * \param[in] state The global state container
373 * \param[in] pull The COM pull force calculation data structure
375 void allocStatePrevStepPullCom(t_state *state, pull_t *pull);
377 /*! \brief Initializes the COM of the previous step (set to initial COM)
379 * \param[in] cr Struct for communication info.
380 * \param[in] pull The pull data structure.
381 * \param[in] md All atoms.
382 * \param[in] pbc Information struct about periodicity.
383 * \param[in] x The local positions.
385 void initPullComFromPrevStep(const t_commrec *cr,