91abefcc451616d5f6f33b11f3a84eb3ab421eba
[alexxy/gromacs.git] / src / gromacs / gmxpreprocess / readpull.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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 by the GROMACS development team.
7  * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
8  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9  * and including many others, as listed in the AUTHORS file in the
10  * top-level source directory and at http://www.gromacs.org.
11  *
12  * GROMACS is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 2.1
15  * of the License, or (at your option) any later version.
16  *
17  * GROMACS is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with GROMACS; if not, see
24  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
26  *
27  * If you want to redistribute modifications to GROMACS, please
28  * consider that scientific software is very special. Version
29  * control is crucial - bugs must be traceable. We will be happy to
30  * consider code for inclusion in the official distribution, but
31  * derived work must not be called official GROMACS. Details are found
32  * in the README & COPYING files - if they are missing, get the
33  * official version at http://www.gromacs.org.
34  *
35  * To help us fund GROMACS development, we humbly ask that you cite
36  * the research papers on the package. Check out http://www.gromacs.org.
37  */
38 #include "gmxpre.h"
39
40 #include <cassert>
41 #include <cstdlib>
42 #include <cstring>
43
44 #include "gromacs/domdec/localatomsetmanager.h"
45 #include "gromacs/fileio/readinp.h"
46 #include "gromacs/fileio/warninp.h"
47 #include "gromacs/gmxpreprocess/readir.h"
48 #include "gromacs/math/vec.h"
49 #include "gromacs/mdlib/mdatoms.h"
50 #include "gromacs/mdtypes/inputrec.h"
51 #include "gromacs/mdtypes/md_enums.h"
52 #include "gromacs/mdtypes/mdatom.h"
53 #include "gromacs/mdtypes/pull_params.h"
54 #include "gromacs/pbcutil/pbc.h"
55 #include "gromacs/pulling/pull.h"
56 #include "gromacs/topology/topology.h"
57 #include "gromacs/utility/arrayref.h"
58 #include "gromacs/utility/cstringutil.h"
59 #include "gromacs/utility/fatalerror.h"
60 #include "gromacs/utility/futil.h"
61 #include "gromacs/utility/smalloc.h"
62
63
64 static void string2dvec(const char buf[], dvec nums)
65 {
66     double dum;
67
68     if (sscanf(buf, "%lf%lf%lf%lf", &nums[0], &nums[1], &nums[2], &dum) != 3)
69     {
70         gmx_fatal(FARGS, "Expected three numbers at input line %s", buf);
71     }
72 }
73
74 static void init_pull_group(t_pull_group* pg, const char* wbuf)
75 {
76     double d;
77     int    n;
78
79     pg->nweight = 0;
80     while (sscanf(wbuf, "%lf %n", &d, &n) == 1)
81     {
82         if (pg->nweight % 100 == 0)
83         {
84             srenew(pg->weight, pg->nweight + 100);
85         }
86         pg->weight[pg->nweight++] = d;
87         wbuf += n;
88     }
89 }
90
91 static void process_pull_dim(char* dim_buf, ivec dim, const t_pull_coord* pcrd)
92 {
93     int   ndim, d, nchar;
94     char *ptr, pulldim1[STRLEN];
95
96     ptr  = dim_buf;
97     ndim = 0;
98     for (d = 0; d < DIM; d++)
99     {
100         if (sscanf(ptr, "%s%n", pulldim1, &nchar) != 1)
101         {
102             gmx_fatal(FARGS, "Less than 3 pull dimensions given in pull_dim: '%s'", dim_buf);
103         }
104
105         if (gmx::equalCaseInsensitive(pulldim1, "N", 1))
106         {
107             dim[d] = 0;
108         }
109         else if (gmx::equalCaseInsensitive(pulldim1, "Y", 1))
110         {
111             dim[d] = 1;
112             ndim++;
113         }
114         else
115         {
116             gmx_fatal(FARGS, "Please use Y(ES) or N(O) for pull_dim only (not %s)", pulldim1);
117         }
118         ptr += nchar;
119     }
120     if (ndim == 0)
121     {
122         gmx_fatal(FARGS, "All entries in pull dim are N");
123     }
124     if ((pcrd->eGeom == epullgDIHEDRAL) && (ndim < 3))
125     {
126         gmx_fatal(FARGS, "Pull geometry dihedral is only useful with pull-dim = Y Y Y");
127     }
128     if ((pcrd->eGeom == epullgANGLE || pcrd->eGeom == epullgANGLEAXIS) && (ndim < 2))
129     {
130         gmx_fatal(FARGS,
131                   "Pull geometry %s is only useful with pull-dim = Y for at least 2 dimensions",
132                   EPULLGEOM(pcrd->eGeom));
133     }
134 }
135
136 static void init_pull_coord(t_pull_coord* pcrd,
137                             int           coord_index_for_output,
138                             char*         dim_buf,
139                             const char*   origin_buf,
140                             const char*   vec_buf,
141                             warninp_t     wi)
142 {
143     int  m;
144     dvec origin, vec;
145     char buf[STRLEN];
146
147     if (pcrd->eType == epullCONSTRAINT
148         && (pcrd->eGeom == epullgCYL || pcrd->eGeom == epullgDIRRELATIVE || pcrd->eGeom == epullgANGLE
149             || pcrd->eGeom == epullgANGLEAXIS || pcrd->eGeom == epullgDIHEDRAL))
150     {
151         gmx_fatal(FARGS,
152                   "Pulling of type %s can not be combined with geometry %s. Consider using pull "
153                   "type %s.",
154                   epull_names[pcrd->eType], epullg_names[pcrd->eGeom], epull_names[epullUMBRELLA]);
155     }
156
157     if (pcrd->eType == epullEXTERNAL)
158     {
159         if (pcrd->externalPotentialProvider[0] == '\0')
160         {
161             sprintf(buf,
162                     "The use of pull type '%s' for pull coordinate %d requires that the name of "
163                     "the module providing the potential external is set with the option %s%d%s",
164                     epull_names[pcrd->eType], coord_index_for_output, "pull-coord",
165                     coord_index_for_output, "-potential-provider");
166             warning_error(wi, buf);
167         }
168
169         if (pcrd->rate != 0)
170         {
171             sprintf(buf,
172                     "The use of pull type '%s' for pull coordinate %d requires that the pull rate "
173                     "is zero",
174                     epull_names[pcrd->eType], coord_index_for_output);
175             warning_error(wi, buf);
176         }
177
178         if (pcrd->eGeom == epullgCYL)
179         {
180             /* Warn the user of a PBC restriction, caused by the fact that
181              * there is no reference value with an external pull potential.
182              */
183             sprintf(buf,
184                     "With pull type '%s' and geometry '%s', the distance component along the "
185                     "cylinder axis between atoms in the cylinder group and the COM of the pull "
186                     "group should be smaller than half the box length",
187                     epull_names[pcrd->eType], epullg_names[pcrd->eGeom]);
188             warning_note(wi, buf);
189         }
190     }
191
192     process_pull_dim(dim_buf, pcrd->dim, pcrd);
193
194     string2dvec(origin_buf, origin);
195     if (pcrd->group[0] != 0 && dnorm(origin) > 0)
196     {
197         gmx_fatal(FARGS, "The pull origin can only be set with an absolute reference");
198     }
199
200     /* Check the given initial reference value and warn for dangerous values */
201     if (pcrd->eGeom == epullgDIST)
202     {
203         if (pcrd->bStart && pcrd->init < 0)
204         {
205             sprintf(buf,
206                     "The initial reference distance set by pull-coord-init is set to a negative "
207                     "value (%g) with geometry %s while distances need to be non-negative. "
208                     "This may work, since you have set pull-coord-start to 'yes' which modifies "
209                     "this value, but only for certain starting distances. "
210                     "If this is a mistake you may want to use geometry %s instead.",
211                     pcrd->init, EPULLGEOM(pcrd->eGeom), EPULLGEOM(epullgDIR));
212             warning(wi, buf);
213         }
214     }
215     else if (pcrd->eGeom == epullgANGLE || pcrd->eGeom == epullgANGLEAXIS)
216     {
217         if (pcrd->bStart && (pcrd->init < 0 || pcrd->init > 180))
218         {
219             /* This value of pcrd->init may be ok depending on pcrd->bStart which modifies pcrd->init later on */
220             sprintf(buf,
221                     "The initial reference angle set by pull-coord-init (%g) is outside of the "
222                     "allowed range [0, 180] degrees for geometry (%s). "
223                     "This may work, since you have set pull-coord-start to 'yes' which modifies "
224                     "this value, but only for certain starting angles.",
225                     pcrd->init, EPULLGEOM(pcrd->eGeom));
226             warning(wi, buf);
227         }
228     }
229     else if (pcrd->eGeom == epullgDIHEDRAL)
230     {
231         if (pcrd->bStart && (pcrd->init < -180 || pcrd->init > 180))
232         {
233             sprintf(buf,
234                     "The initial reference angle set by pull-coord-init (%g) is outside of the "
235                     "allowed range [-180, 180] degrees for geometry (%s). "
236                     "This may work, since you have set pull-coord-start to 'yes' which modifies "
237                     "this value, but only for certain starting angles.",
238                     pcrd->init, EPULLGEOM(pcrd->eGeom));
239             warning(wi, buf);
240         }
241     }
242
243     /* Check and set the pull vector */
244     clear_dvec(vec);
245     string2dvec(vec_buf, vec);
246
247     if (pcrd->eGeom == epullgDIR || pcrd->eGeom == epullgCYL || pcrd->eGeom == epullgDIRPBC
248         || pcrd->eGeom == epullgANGLEAXIS)
249     {
250         if (dnorm2(vec) == 0)
251         {
252             gmx_fatal(FARGS, "With pull geometry %s the pull vector can not be 0,0,0",
253                       epullg_names[pcrd->eGeom]);
254         }
255         for (int d = 0; d < DIM; d++)
256         {
257             if (vec[d] != 0 && pcrd->dim[d] == 0)
258             {
259                 gmx_fatal(FARGS,
260                           "pull-coord-vec has non-zero %c-component while pull_dim for the "
261                           "%c-dimension is set to N",
262                           'x' + d, 'x' + d);
263             }
264         }
265
266         /* Normalize the direction vector */
267         dsvmul(1 / dnorm(vec), vec, vec);
268     }
269     else /* This case is for are all the geometries where the pull vector is not used */
270     {
271         if (dnorm2(vec) > 0)
272         {
273             sprintf(buf,
274                     "A pull vector is given (%g  %g  %g) but will not be used with geometry %s. If "
275                     "you really want to use this "
276                     "vector, consider using geometry %s instead.",
277                     vec[0], vec[1], vec[2], EPULLGEOM(pcrd->eGeom),
278                     pcrd->eGeom == epullgANGLE ? EPULLGEOM(epullgANGLEAXIS) : EPULLGEOM(epullgDIR));
279             warning(wi, buf);
280         }
281     }
282     for (m = 0; m < DIM; m++)
283     {
284         pcrd->origin[m] = origin[m];
285         pcrd->vec[m]    = vec[m];
286     }
287 }
288
289 std::vector<std::string> read_pullparams(std::vector<t_inpfile>* inp, pull_params_t* pull, warninp_t wi)
290 {
291     int  nscan, idum;
292     char buf[STRLEN];
293     char provider[STRLEN], groups[STRLEN], dim_buf[STRLEN];
294     char wbuf[STRLEN], origin_buf[STRLEN], vec_buf[STRLEN];
295
296     t_pull_group* pgrp;
297     t_pull_coord* pcrd;
298
299     /* read pull parameters */
300     printStringNoNewline(inp, "Cylinder radius for dynamic reaction force groups (nm)");
301     pull->cylinder_r     = get_ereal(inp, "pull-cylinder-r", 1.5, wi);
302     pull->constr_tol     = get_ereal(inp, "pull-constr-tol", 1E-6, wi);
303     pull->bPrintCOM      = (get_eeenum(inp, "pull-print-com", yesno_names, wi) != 0);
304     pull->bPrintRefValue = (get_eeenum(inp, "pull-print-ref-value", yesno_names, wi) != 0);
305     pull->bPrintComp     = (get_eeenum(inp, "pull-print-components", yesno_names, wi) != 0);
306     pull->nstxout        = get_eint(inp, "pull-nstxout", 50, wi);
307     pull->nstfout        = get_eint(inp, "pull-nstfout", 50, wi);
308     pull->bSetPbcRefToPrevStepCOM = (get_eeenum(inp, "pull-pbc-ref-prev-step-com", yesno_names, wi) != 0);
309     pull->bXOutAverage            = (get_eeenum(inp, "pull-xout-average", yesno_names, wi) != 0);
310     pull->bFOutAverage            = (get_eeenum(inp, "pull-fout-average", yesno_names, wi) != 0);
311     printStringNoNewline(inp, "Number of pull groups");
312     pull->ngroup = get_eint(inp, "pull-ngroups", 1, wi);
313     printStringNoNewline(inp, "Number of pull coordinates");
314     pull->ncoord = get_eint(inp, "pull-ncoords", 1, wi);
315
316     if (pull->ngroup < 1)
317     {
318         gmx_fatal(FARGS, "pull-ngroups should be >= 1");
319     }
320     /* We always add an absolute reference group (index 0), even if not used */
321     pull->ngroup += 1;
322
323     if (pull->ncoord < 1)
324     {
325         gmx_fatal(FARGS, "pull-ncoords should be >= 1");
326     }
327
328     snew(pull->group, pull->ngroup);
329
330     snew(pull->coord, pull->ncoord);
331
332     /* pull group options */
333     printStringNoNewline(inp, "Group and coordinate parameters");
334
335     /* Read the pull groups */
336     std::vector<std::string> pullGroups(pull->ngroup);
337     char                     readBuffer[STRLEN];
338     /* Group 0 is the absolute reference, we don't read anything for 0 */
339     for (int groupNum = 1; groupNum < pull->ngroup; groupNum++)
340     {
341         pgrp = &pull->group[groupNum];
342         sprintf(buf, "pull-group%d-name", groupNum);
343         setStringEntry(inp, buf, readBuffer, "");
344         pullGroups[groupNum] = readBuffer;
345         sprintf(buf, "pull-group%d-weights", groupNum);
346         setStringEntry(inp, buf, wbuf, "");
347         sprintf(buf, "pull-group%d-pbcatom", groupNum);
348         pgrp->pbcatom = get_eint(inp, buf, 0, wi);
349
350         /* Initialize the pull group */
351         init_pull_group(pgrp, wbuf);
352     }
353
354     /* Read the pull coordinates */
355     for (int coordNum = 1; coordNum < pull->ncoord + 1; coordNum++)
356     {
357         pcrd = &pull->coord[coordNum - 1];
358         sprintf(buf, "pull-coord%d-type", coordNum);
359         pcrd->eType = get_eeenum(inp, buf, epull_names, wi);
360         sprintf(buf, "pull-coord%d-potential-provider", coordNum);
361         setStringEntry(inp, buf, provider, "");
362         pcrd->externalPotentialProvider = gmx_strdup(provider);
363         sprintf(buf, "pull-coord%d-geometry", coordNum);
364         pcrd->eGeom = get_eeenum(inp, buf, epullg_names, wi);
365         sprintf(buf, "pull-coord%d-groups", coordNum);
366         setStringEntry(inp, buf, groups, "");
367
368         switch (pcrd->eGeom)
369         {
370             case epullgDIHEDRAL: pcrd->ngroup = 6; break;
371             case epullgDIRRELATIVE:
372             case epullgANGLE: pcrd->ngroup = 4; break;
373             default: pcrd->ngroup = 2; break;
374         }
375
376         nscan = sscanf(groups, "%d %d %d %d %d %d %d", &pcrd->group[0], &pcrd->group[1],
377                        &pcrd->group[2], &pcrd->group[3], &pcrd->group[4], &pcrd->group[5], &idum);
378         if (nscan != pcrd->ngroup)
379         {
380             auto message =
381                     gmx::formatString("%s should contain %d pull group indices with geometry %s",
382                                       buf, pcrd->ngroup, epullg_names[pcrd->eGeom]);
383             set_warning_line(wi, nullptr, -1);
384             warning_error(wi, message);
385         }
386         for (int g = 0; g < pcrd->ngroup; g++)
387         {
388             if (pcrd->group[g] < 0 || pcrd->group[g] >= pull->ngroup)
389             {
390                 /* Quit with a fatal error to avoid invalid memory access */
391                 gmx_fatal(FARGS,
392                           "%s contains an invalid pull group %d, you should have %d <= group <= %d",
393                           buf, pcrd->group[g], 0, pull->ngroup - 1);
394             }
395         }
396
397         sprintf(buf, "pull-coord%d-dim", coordNum);
398         setStringEntry(inp, buf, dim_buf, "Y Y Y");
399         sprintf(buf, "pull-coord%d-origin", coordNum);
400         setStringEntry(inp, buf, origin_buf, "0.0 0.0 0.0");
401         sprintf(buf, "pull-coord%d-vec", coordNum);
402         setStringEntry(inp, buf, vec_buf, "0.0 0.0 0.0");
403         sprintf(buf, "pull-coord%d-start", coordNum);
404         pcrd->bStart = (get_eeenum(inp, buf, yesno_names, wi) != 0);
405         sprintf(buf, "pull-coord%d-init", coordNum);
406         pcrd->init = get_ereal(inp, buf, 0.0, wi);
407         sprintf(buf, "pull-coord%d-rate", coordNum);
408         pcrd->rate = get_ereal(inp, buf, 0.0, wi);
409         sprintf(buf, "pull-coord%d-k", coordNum);
410         pcrd->k = get_ereal(inp, buf, 0.0, wi);
411         sprintf(buf, "pull-coord%d-kB", coordNum);
412         pcrd->kB = get_ereal(inp, buf, pcrd->k, wi);
413
414         /* Initialize the pull coordinate */
415         init_pull_coord(pcrd, coordNum, dim_buf, origin_buf, vec_buf, wi);
416     }
417
418     return pullGroups;
419 }
420
421 void make_pull_groups(pull_params_t*                   pull,
422                       gmx::ArrayRef<const std::string> pullGroupNames,
423                       const t_blocka*                  grps,
424                       char**                           gnames)
425 {
426     int           g, ig = -1, i;
427     t_pull_group* pgrp;
428
429     /* Absolute reference group (might not be used) is special */
430     pgrp                = &pull->group[0];
431     pgrp->nat           = 0;
432     pgrp->pbcatom       = -1;
433     pgrp->pbcatom_input = -1;
434
435     for (g = 1; g < pull->ngroup; g++)
436     {
437         pgrp                = &pull->group[g];
438         pgrp->pbcatom_input = pgrp->pbcatom;
439
440         if (pullGroupNames[g].empty())
441         {
442             gmx_fatal(FARGS, "Pull option pull_group%d required by grompp has not been set.", g);
443         }
444
445         ig        = search_string(pullGroupNames[g].c_str(), grps->nr, gnames);
446         pgrp->nat = grps->index[ig + 1] - grps->index[ig];
447
448         fprintf(stderr, "Pull group %d '%s' has %d atoms\n", g, pullGroupNames[g].c_str(), pgrp->nat);
449
450         if (pgrp->nat == 0)
451         {
452             gmx_fatal(FARGS, "Pull group %d '%s' is empty", g, pullGroupNames[g].c_str());
453         }
454
455         snew(pgrp->ind, pgrp->nat);
456         for (i = 0; i < pgrp->nat; i++)
457         {
458             pgrp->ind[i] = grps->a[grps->index[ig] + i];
459         }
460
461         if (pgrp->nweight > 0 && pgrp->nweight != pgrp->nat)
462         {
463             gmx_fatal(FARGS,
464                       "Number of weights (%d) for pull group %d '%s' does not match the number of "
465                       "atoms (%d)",
466                       pgrp->nweight, g, pullGroupNames[g].c_str(), pgrp->nat);
467         }
468
469         if (pgrp->nat == 1)
470         {
471             /* No pbc is required for this group */
472             pgrp->pbcatom = -1;
473         }
474         else
475         {
476             if (pgrp->pbcatom > 0)
477             {
478                 pgrp->pbcatom -= 1;
479             }
480             else if (pgrp->pbcatom == 0)
481             {
482                 pgrp->pbcatom = pgrp->ind[(pgrp->nat - 1) / 2];
483             }
484             else
485             {
486                 /* Use cosine weighting */
487                 pgrp->pbcatom = -1;
488             }
489         }
490     }
491 }
492
493 void make_pull_coords(pull_params_t* pull)
494 {
495     int           c;
496     t_pull_coord* pcrd;
497
498     for (c = 0; c < pull->ncoord; c++)
499     {
500         pcrd = &pull->coord[c];
501
502         if (pcrd->group[0] < 0 || pcrd->group[0] >= pull->ngroup || pcrd->group[1] < 0
503             || pcrd->group[1] >= pull->ngroup)
504         {
505             gmx_fatal(FARGS,
506                       "Pull group index in pull-coord%d-groups out of range, should be between %d "
507                       "and %d",
508                       c + 1, 0, pull->ngroup + 1);
509         }
510
511         if (pcrd->group[0] == pcrd->group[1])
512         {
513             gmx_fatal(FARGS, "Identical pull group indices in pull-coord%d-groups", c + 1);
514         }
515
516         if (pcrd->eGeom == epullgCYL)
517         {
518             if (pull->group[pcrd->group[0]].nweight > 0)
519             {
520                 gmx_fatal(
521                         FARGS,
522                         "Weights are not supported for the reference group with cylinder pulling");
523             }
524         }
525     }
526 }
527
528 pull_t* set_pull_init(t_inputrec* ir, const gmx_mtop_t* mtop, rvec* x, matrix box, real lambda, warninp_t wi)
529 {
530     pull_params_t* pull;
531     pull_t*        pull_work;
532     t_pbc          pbc;
533     int            c;
534     double         t_start;
535
536     pull = ir->pull;
537     gmx::LocalAtomSetManager atomSets;
538     pull_work    = init_pull(nullptr, pull, ir, mtop, nullptr, &atomSets, lambda);
539     auto mdAtoms = gmx::makeMDAtoms(nullptr, *mtop, *ir, false);
540     auto md      = mdAtoms->mdatoms();
541     atoms2md(mtop, ir, -1, {}, mtop->natoms, mdAtoms.get());
542     if (ir->efep)
543     {
544         update_mdatoms(md, lambda);
545     }
546
547     set_pbc(&pbc, ir->pbcType, box);
548
549     t_start = ir->init_t + ir->init_step * ir->delta_t;
550
551     if (pull->bSetPbcRefToPrevStepCOM)
552     {
553         initPullComFromPrevStep(nullptr, pull_work, md->massT, &pbc, x);
554     }
555     pull_calc_coms(nullptr, pull_work, md->massT, &pbc, t_start, x, nullptr);
556
557     for (int g = 0; g < pull->ngroup; g++)
558     {
559         bool groupObeysPbc = pullCheckPbcWithinGroup(
560                 *pull_work, gmx::arrayRefFromArray(reinterpret_cast<gmx::RVec*>(x), mtop->natoms),
561                 pbc, g, c_pullGroupSmallGroupThreshold);
562         if (!groupObeysPbc)
563         {
564             char buf[STRLEN];
565             if (pull->group[g].pbcatom_input == 0)
566             {
567                 sprintf(buf,
568                         "When the maximum distance from a pull group reference atom to other atoms "
569                         "in the "
570                         "group is larger than %g times half the box size a centrally placed "
571                         "atom should be chosen as pbcatom. Pull group %d is larger than that and "
572                         "does not have "
573                         "a specific atom selected as reference atom.",
574                         c_pullGroupSmallGroupThreshold, g);
575                 warning_error(wi, buf);
576             }
577             else if (!pull->bSetPbcRefToPrevStepCOM)
578             {
579                 sprintf(buf,
580                         "The maximum distance from the chosen PBC atom (%d) of pull group %d to "
581                         "other "
582                         "atoms in the group is larger than %g times half the box size. "
583                         "Set the pull-pbc-ref-prev-step-com option to yes.",
584                         pull->group[g].pbcatom + 1, g, c_pullGroupSmallGroupThreshold);
585                 warning_error(wi, buf);
586             }
587         }
588         if (groupObeysPbc)
589         {
590             groupObeysPbc = pullCheckPbcWithinGroup(
591                     *pull_work, gmx::arrayRefFromArray(reinterpret_cast<gmx::RVec*>(x), mtop->natoms),
592                     pbc, g, c_pullGroupPbcMargin);
593             if (!groupObeysPbc)
594             {
595                 char buf[STRLEN];
596                 sprintf(buf,
597                         "Pull group %d has atoms at a distance larger than %g times half the box "
598                         "size from the PBC atom (%d). "
599                         "If atoms are or will more beyond half the box size from the PBC atom, the "
600                         "COM will be ill defined.",
601                         g, c_pullGroupPbcMargin, pull->group[g].pbcatom + 1);
602                 set_warning_line(wi, nullptr, -1);
603                 warning(wi, buf);
604             }
605         }
606     }
607
608     fprintf(stderr, "Pull group  natoms  pbc atom  distance at start  reference at t=0\n");
609     for (c = 0; c < pull->ncoord; c++)
610     {
611         t_pull_coord* pcrd;
612         t_pull_group *pgrp0, *pgrp1;
613         double        value;
614         real          init = 0;
615
616         pcrd = &pull->coord[c];
617
618         pgrp0 = &pull->group[pcrd->group[0]];
619         pgrp1 = &pull->group[pcrd->group[1]];
620         fprintf(stderr, "%8d  %8d  %8d\n", pcrd->group[0], pgrp0->nat, pgrp0->pbcatom + 1);
621         fprintf(stderr, "%8d  %8d  %8d ", pcrd->group[1], pgrp1->nat, pgrp1->pbcatom + 1);
622
623         if (pcrd->bStart)
624         {
625             init       = pcrd->init;
626             pcrd->init = 0;
627         }
628
629         value = get_pull_coord_value(pull_work, c, &pbc);
630
631         value *= pull_conversion_factor_internal2userinput(pcrd);
632         fprintf(stderr, " %10.3f %s", value, pull_coordinate_units(pcrd));
633
634         if (pcrd->bStart)
635         {
636             pcrd->init = value + init;
637         }
638
639         if (pcrd->eGeom == epullgDIST)
640         {
641             if (pcrd->init < 0)
642             {
643                 gmx_fatal(FARGS,
644                           "The initial pull distance (%g) needs to be non-negative with geometry "
645                           "%s. If you want a signed distance, use geometry %s instead.",
646                           pcrd->init, EPULLGEOM(pcrd->eGeom), EPULLGEOM(epullgDIR));
647             }
648
649             /* TODO: With a positive init but a negative rate things could still
650              * go wrong, but it might be fine if you don't pull too far.
651              * We should give a warning or note when there is only one pull dim
652              * active, since that is usually the problematic case when you should
653              * be using direction. We will do this later, since an already planned
654              * generalization of the pull code makes pull dim available here.
655              */
656         }
657         else if (pcrd->eGeom == epullgANGLE || pcrd->eGeom == epullgANGLEAXIS)
658         {
659             if (pcrd->init < 0 || pcrd->init > 180)
660             {
661                 gmx_fatal(FARGS,
662                           "The initial pull reference angle (%g) is outside of the allowed range "
663                           "[0, 180] degrees.",
664                           pcrd->init);
665             }
666         }
667         else if (pcrd->eGeom == epullgDIHEDRAL)
668         {
669             if (pcrd->init < -180 || pcrd->init > 180)
670             {
671                 gmx_fatal(FARGS,
672                           "The initial pull reference angle (%g) is outside of the allowed range "
673                           "[-180, 180] degrees.",
674                           pcrd->init);
675             }
676         }
677
678
679         fprintf(stderr, "     %10.3f %s\n", pcrd->init, pull_coordinate_units(pcrd));
680     }
681
682     return pull_work;
683 }