Merge branch 'origin/release-2020' into master
[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/cstringutil.h"
58 #include "gromacs/utility/fatalerror.h"
59 #include "gromacs/utility/futil.h"
60 #include "gromacs/utility/smalloc.h"
61
62
63 static void string2dvec(const char buf[], dvec nums)
64 {
65     double dum;
66
67     if (sscanf(buf, "%lf%lf%lf%lf", &nums[0], &nums[1], &nums[2], &dum) != 3)
68     {
69         gmx_fatal(FARGS, "Expected three numbers at input line %s", buf);
70     }
71 }
72
73 static void init_pull_group(t_pull_group* pg, const char* wbuf)
74 {
75     double d;
76     int    n;
77
78     pg->nweight = 0;
79     while (sscanf(wbuf, "%lf %n", &d, &n) == 1)
80     {
81         if (pg->nweight % 100 == 0)
82         {
83             srenew(pg->weight, pg->nweight + 100);
84         }
85         pg->weight[pg->nweight++] = d;
86         wbuf += n;
87     }
88 }
89
90 static void process_pull_dim(char* dim_buf, ivec dim, const t_pull_coord* pcrd)
91 {
92     int   ndim, d, nchar;
93     char *ptr, pulldim1[STRLEN];
94
95     ptr  = dim_buf;
96     ndim = 0;
97     for (d = 0; d < DIM; d++)
98     {
99         if (sscanf(ptr, "%s%n", pulldim1, &nchar) != 1)
100         {
101             gmx_fatal(FARGS, "Less than 3 pull dimensions given in pull_dim: '%s'", dim_buf);
102         }
103
104         if (gmx::equalCaseInsensitive(pulldim1, "N", 1))
105         {
106             dim[d] = 0;
107         }
108         else if (gmx::equalCaseInsensitive(pulldim1, "Y", 1))
109         {
110             dim[d] = 1;
111             ndim++;
112         }
113         else
114         {
115             gmx_fatal(FARGS, "Please use Y(ES) or N(O) for pull_dim only (not %s)", pulldim1);
116         }
117         ptr += nchar;
118     }
119     if (ndim == 0)
120     {
121         gmx_fatal(FARGS, "All entries in pull dim are N");
122     }
123     if ((pcrd->eGeom == epullgDIHEDRAL) && (ndim < 3))
124     {
125         gmx_fatal(FARGS, "Pull geometry dihedral is only useful with pull-dim = Y Y Y");
126     }
127     if ((pcrd->eGeom == epullgANGLE || pcrd->eGeom == epullgANGLEAXIS) && (ndim < 2))
128     {
129         gmx_fatal(FARGS,
130                   "Pull geometry %s is only useful with pull-dim = Y for at least 2 dimensions",
131                   EPULLGEOM(pcrd->eGeom));
132     }
133 }
134
135 static void init_pull_coord(t_pull_coord* pcrd,
136                             int           coord_index_for_output,
137                             char*         dim_buf,
138                             const char*   origin_buf,
139                             const char*   vec_buf,
140                             warninp_t     wi)
141 {
142     int  m;
143     dvec origin, vec;
144     char buf[STRLEN];
145
146     if (pcrd->eType == epullCONSTRAINT
147         && (pcrd->eGeom == epullgCYL || pcrd->eGeom == epullgDIRRELATIVE || pcrd->eGeom == epullgANGLE
148             || pcrd->eGeom == epullgANGLEAXIS || pcrd->eGeom == epullgDIHEDRAL))
149     {
150         gmx_fatal(FARGS,
151                   "Pulling of type %s can not be combined with geometry %s. Consider using pull "
152                   "type %s.",
153                   epull_names[pcrd->eType], epullg_names[pcrd->eGeom], epull_names[epullUMBRELLA]);
154     }
155
156     if (pcrd->eType == epullEXTERNAL)
157     {
158         if (pcrd->externalPotentialProvider[0] == '\0')
159         {
160             sprintf(buf,
161                     "The use of pull type '%s' for pull coordinate %d requires that the name of "
162                     "the module providing the potential external is set with the option %s%d%s",
163                     epull_names[pcrd->eType], coord_index_for_output, "pull-coord",
164                     coord_index_for_output, "-potential-provider");
165             warning_error(wi, buf);
166         }
167
168         if (pcrd->rate != 0)
169         {
170             sprintf(buf,
171                     "The use of pull type '%s' for pull coordinate %d requires that the pull rate "
172                     "is zero",
173                     epull_names[pcrd->eType], coord_index_for_output);
174             warning_error(wi, buf);
175         }
176
177         if (pcrd->eGeom == epullgCYL)
178         {
179             /* Warn the user of a PBC restriction, caused by the fact that
180              * there is no reference value with an external pull potential.
181              */
182             sprintf(buf,
183                     "With pull type '%s' and geometry '%s', the distance component along the "
184                     "cylinder axis between atoms in the cylinder group and the COM of the pull "
185                     "group should be smaller than half the box length",
186                     epull_names[pcrd->eType], epullg_names[pcrd->eGeom]);
187             warning_note(wi, buf);
188         }
189     }
190
191     process_pull_dim(dim_buf, pcrd->dim, pcrd);
192
193     string2dvec(origin_buf, origin);
194     if (pcrd->group[0] != 0 && dnorm(origin) > 0)
195     {
196         gmx_fatal(FARGS, "The pull origin can only be set with an absolute reference");
197     }
198
199     /* Check the given initial reference value and warn for dangerous values */
200     if (pcrd->eGeom == epullgDIST)
201     {
202         if (pcrd->bStart && pcrd->init < 0)
203         {
204             sprintf(buf,
205                     "The initial reference distance set by pull-coord-init is set to a negative "
206                     "value (%g) with geometry %s while distances need to be non-negative. "
207                     "This may work, since you have set pull-coord-start to 'yes' which modifies "
208                     "this value, but only for certain starting distances. "
209                     "If this is a mistake you may want to use geometry %s instead.",
210                     pcrd->init, EPULLGEOM(pcrd->eGeom), EPULLGEOM(epullgDIR));
211             warning(wi, buf);
212         }
213     }
214     else if (pcrd->eGeom == epullgANGLE || pcrd->eGeom == epullgANGLEAXIS)
215     {
216         if (pcrd->bStart && (pcrd->init < 0 || pcrd->init > 180))
217         {
218             /* This value of pcrd->init may be ok depending on pcrd->bStart which modifies pcrd->init later on */
219             sprintf(buf,
220                     "The initial reference angle set by pull-coord-init (%g) is outside of the "
221                     "allowed range [0, 180] degrees for geometry (%s). "
222                     "This may work, since you have set pull-coord-start to 'yes' which modifies "
223                     "this value, but only for certain starting angles.",
224                     pcrd->init, EPULLGEOM(pcrd->eGeom));
225             warning(wi, buf);
226         }
227     }
228     else if (pcrd->eGeom == epullgDIHEDRAL)
229     {
230         if (pcrd->bStart && (pcrd->init < -180 || pcrd->init > 180))
231         {
232             sprintf(buf,
233                     "The initial reference angle set by pull-coord-init (%g) is outside of the "
234                     "allowed range [-180, 180] degrees for geometry (%s). "
235                     "This may work, since you have set pull-coord-start to 'yes' which modifies "
236                     "this value, but only for certain starting angles.",
237                     pcrd->init, EPULLGEOM(pcrd->eGeom));
238             warning(wi, buf);
239         }
240     }
241
242     /* Check and set the pull vector */
243     clear_dvec(vec);
244     string2dvec(vec_buf, vec);
245
246     if (pcrd->eGeom == epullgDIR || pcrd->eGeom == epullgCYL || pcrd->eGeom == epullgDIRPBC
247         || pcrd->eGeom == epullgANGLEAXIS)
248     {
249         if (dnorm2(vec) == 0)
250         {
251             gmx_fatal(FARGS, "With pull geometry %s the pull vector can not be 0,0,0",
252                       epullg_names[pcrd->eGeom]);
253         }
254         for (int d = 0; d < DIM; d++)
255         {
256             if (vec[d] != 0 && pcrd->dim[d] == 0)
257             {
258                 gmx_fatal(FARGS,
259                           "pull-coord-vec has non-zero %c-component while pull_dim for the "
260                           "%c-dimension is set to N",
261                           'x' + d, 'x' + d);
262             }
263         }
264
265         /* Normalize the direction vector */
266         dsvmul(1 / dnorm(vec), vec, vec);
267     }
268     else /* This case is for are all the geometries where the pull vector is not used */
269     {
270         if (dnorm2(vec) > 0)
271         {
272             sprintf(buf,
273                     "A pull vector is given (%g  %g  %g) but will not be used with geometry %s. If "
274                     "you really want to use this "
275                     "vector, consider using geometry %s instead.",
276                     vec[0], vec[1], vec[2], EPULLGEOM(pcrd->eGeom),
277                     pcrd->eGeom == epullgANGLE ? EPULLGEOM(epullgANGLEAXIS) : EPULLGEOM(epullgDIR));
278             warning(wi, buf);
279         }
280     }
281     for (m = 0; m < DIM; m++)
282     {
283         pcrd->origin[m] = origin[m];
284         pcrd->vec[m]    = vec[m];
285     }
286 }
287
288 char** read_pullparams(std::vector<t_inpfile>* inp, pull_params_t* pull, warninp_t wi)
289 {
290     int    nscan, idum;
291     char** grpbuf;
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     snew(grpbuf, pull->ngroup);
337     /* Group 0 is the absolute reference, we don't read anything for 0 */
338     for (int groupNum = 1; groupNum < pull->ngroup; groupNum++)
339     {
340         pgrp = &pull->group[groupNum];
341         snew(grpbuf[groupNum], STRLEN);
342         sprintf(buf, "pull-group%d-name", groupNum);
343         setStringEntry(inp, buf, grpbuf[groupNum], "");
344         sprintf(buf, "pull-group%d-weights", groupNum);
345         setStringEntry(inp, buf, wbuf, "");
346         sprintf(buf, "pull-group%d-pbcatom", groupNum);
347         pgrp->pbcatom = get_eint(inp, buf, 0, wi);
348
349         /* Initialize the pull group */
350         init_pull_group(pgrp, wbuf);
351     }
352
353     /* Read the pull coordinates */
354     for (int coordNum = 1; coordNum < pull->ncoord + 1; coordNum++)
355     {
356         pcrd = &pull->coord[coordNum - 1];
357         sprintf(buf, "pull-coord%d-type", coordNum);
358         pcrd->eType = get_eeenum(inp, buf, epull_names, wi);
359         sprintf(buf, "pull-coord%d-potential-provider", coordNum);
360         setStringEntry(inp, buf, provider, "");
361         pcrd->externalPotentialProvider = gmx_strdup(provider);
362         sprintf(buf, "pull-coord%d-geometry", coordNum);
363         pcrd->eGeom = get_eeenum(inp, buf, epullg_names, wi);
364         sprintf(buf, "pull-coord%d-groups", coordNum);
365         setStringEntry(inp, buf, groups, "");
366
367         switch (pcrd->eGeom)
368         {
369             case epullgDIHEDRAL: pcrd->ngroup = 6; break;
370             case epullgDIRRELATIVE:
371             case epullgANGLE: pcrd->ngroup = 4; break;
372             default: pcrd->ngroup = 2; break;
373         }
374
375         nscan = sscanf(groups, "%d %d %d %d %d %d %d", &pcrd->group[0], &pcrd->group[1],
376                        &pcrd->group[2], &pcrd->group[3], &pcrd->group[4], &pcrd->group[5], &idum);
377         if (nscan != pcrd->ngroup)
378         {
379             auto message =
380                     gmx::formatString("%s should contain %d pull group indices with geometry %s",
381                                       buf, pcrd->ngroup, epullg_names[pcrd->eGeom]);
382             set_warning_line(wi, nullptr, -1);
383             warning_error(wi, message);
384         }
385         for (int g = 0; g < pcrd->ngroup; g++)
386         {
387             if (pcrd->group[g] < 0 || pcrd->group[g] >= pull->ngroup)
388             {
389                 /* Quit with a fatal error to avoid invalid memory access */
390                 gmx_fatal(FARGS,
391                           "%s contains an invalid pull group %d, you should have %d <= group <= %d",
392                           buf, pcrd->group[g], 0, pull->ngroup - 1);
393             }
394         }
395
396         sprintf(buf, "pull-coord%d-dim", coordNum);
397         setStringEntry(inp, buf, dim_buf, "Y Y Y");
398         sprintf(buf, "pull-coord%d-origin", coordNum);
399         setStringEntry(inp, buf, origin_buf, "0.0 0.0 0.0");
400         sprintf(buf, "pull-coord%d-vec", coordNum);
401         setStringEntry(inp, buf, vec_buf, "0.0 0.0 0.0");
402         sprintf(buf, "pull-coord%d-start", coordNum);
403         pcrd->bStart = (get_eeenum(inp, buf, yesno_names, wi) != 0);
404         sprintf(buf, "pull-coord%d-init", coordNum);
405         pcrd->init = get_ereal(inp, buf, 0.0, wi);
406         sprintf(buf, "pull-coord%d-rate", coordNum);
407         pcrd->rate = get_ereal(inp, buf, 0.0, wi);
408         sprintf(buf, "pull-coord%d-k", coordNum);
409         pcrd->k = get_ereal(inp, buf, 0.0, wi);
410         sprintf(buf, "pull-coord%d-kB", coordNum);
411         pcrd->kB = get_ereal(inp, buf, pcrd->k, wi);
412
413         /* Initialize the pull coordinate */
414         init_pull_coord(pcrd, coordNum, dim_buf, origin_buf, vec_buf, wi);
415     }
416
417     return grpbuf;
418 }
419
420 void make_pull_groups(pull_params_t* pull, char** pgnames, const t_blocka* grps, char** gnames)
421 {
422     int           g, ig = -1, i;
423     t_pull_group* pgrp;
424
425     /* Absolute reference group (might not be used) is special */
426     pgrp                = &pull->group[0];
427     pgrp->nat           = 0;
428     pgrp->pbcatom       = -1;
429     pgrp->pbcatom_input = -1;
430
431     for (g = 1; g < pull->ngroup; g++)
432     {
433         pgrp                = &pull->group[g];
434         pgrp->pbcatom_input = pgrp->pbcatom;
435
436         if (strcmp(pgnames[g], "") == 0)
437         {
438             gmx_fatal(FARGS, "Pull option pull_group%d required by grompp has not been set.", g);
439         }
440
441         ig        = search_string(pgnames[g], grps->nr, gnames);
442         pgrp->nat = grps->index[ig + 1] - grps->index[ig];
443
444         fprintf(stderr, "Pull group %d '%s' has %d atoms\n", g, pgnames[g], pgrp->nat);
445
446         if (pgrp->nat == 0)
447         {
448             gmx_fatal(FARGS, "Pull group %d '%s' is empty", g, pgnames[g]);
449         }
450
451         snew(pgrp->ind, pgrp->nat);
452         for (i = 0; i < pgrp->nat; i++)
453         {
454             pgrp->ind[i] = grps->a[grps->index[ig] + i];
455         }
456
457         if (pgrp->nweight > 0 && pgrp->nweight != pgrp->nat)
458         {
459             gmx_fatal(FARGS,
460                       "Number of weights (%d) for pull group %d '%s' does not match the number of "
461                       "atoms (%d)",
462                       pgrp->nweight, g, pgnames[g], pgrp->nat);
463         }
464
465         if (pgrp->nat == 1)
466         {
467             /* No pbc is required for this group */
468             pgrp->pbcatom = -1;
469         }
470         else
471         {
472             if (pgrp->pbcatom > 0)
473             {
474                 pgrp->pbcatom -= 1;
475             }
476             else if (pgrp->pbcatom == 0)
477             {
478                 pgrp->pbcatom = pgrp->ind[(pgrp->nat - 1) / 2];
479             }
480             else
481             {
482                 /* Use cosine weighting */
483                 pgrp->pbcatom = -1;
484             }
485         }
486     }
487 }
488
489 void make_pull_coords(pull_params_t* pull)
490 {
491     int           c;
492     t_pull_coord* pcrd;
493
494     for (c = 0; c < pull->ncoord; c++)
495     {
496         pcrd = &pull->coord[c];
497
498         if (pcrd->group[0] < 0 || pcrd->group[0] >= pull->ngroup || pcrd->group[1] < 0
499             || pcrd->group[1] >= pull->ngroup)
500         {
501             gmx_fatal(FARGS,
502                       "Pull group index in pull-coord%d-groups out of range, should be between %d "
503                       "and %d",
504                       c + 1, 0, pull->ngroup + 1);
505         }
506
507         if (pcrd->group[0] == pcrd->group[1])
508         {
509             gmx_fatal(FARGS, "Identical pull group indices in pull-coord%d-groups", c + 1);
510         }
511
512         if (pcrd->eGeom == epullgCYL)
513         {
514             if (pull->group[pcrd->group[0]].nweight > 0)
515             {
516                 gmx_fatal(
517                         FARGS,
518                         "Weights are not supported for the reference group with cylinder pulling");
519             }
520         }
521     }
522 }
523
524 pull_t* set_pull_init(t_inputrec* ir, const gmx_mtop_t* mtop, rvec* x, matrix box, real lambda, warninp_t wi)
525 {
526     pull_params_t* pull;
527     pull_t*        pull_work;
528     t_pbc          pbc;
529     int            c;
530     double         t_start;
531
532     pull = ir->pull;
533     gmx::LocalAtomSetManager atomSets;
534     pull_work    = init_pull(nullptr, pull, ir, mtop, nullptr, &atomSets, lambda);
535     auto mdAtoms = gmx::makeMDAtoms(nullptr, *mtop, *ir, false);
536     auto md      = mdAtoms->mdatoms();
537     atoms2md(mtop, ir, -1, nullptr, mtop->natoms, mdAtoms.get());
538     if (ir->efep)
539     {
540         update_mdatoms(md, lambda);
541     }
542
543     set_pbc(&pbc, ir->pbcType, box);
544
545     t_start = ir->init_t + ir->init_step * ir->delta_t;
546
547     if (pull->bSetPbcRefToPrevStepCOM)
548     {
549         initPullComFromPrevStep(nullptr, pull_work, md, &pbc, x);
550     }
551     pull_calc_coms(nullptr, pull_work, md, &pbc, t_start, x, nullptr);
552
553     for (int g = 0; g < pull->ngroup; g++)
554     {
555         bool groupObeysPbc = pullCheckPbcWithinGroup(
556                 *pull_work, gmx::arrayRefFromArray(reinterpret_cast<gmx::RVec*>(x), mtop->natoms),
557                 pbc, g, c_pullGroupSmallGroupThreshold);
558         if (!groupObeysPbc)
559         {
560             char buf[STRLEN];
561             if (pull->group[g].pbcatom_input == 0)
562             {
563                 sprintf(buf,
564                         "When the maximum distance from a pull group reference atom to other atoms "
565                         "in the "
566                         "group is larger than %g times half the box size a centrally placed "
567                         "atom should be chosen as pbcatom. Pull group %d is larger than that and "
568                         "does not have "
569                         "a specific atom selected as reference atom.",
570                         c_pullGroupSmallGroupThreshold, g);
571                 warning_error(wi, buf);
572             }
573             else if (!pull->bSetPbcRefToPrevStepCOM)
574             {
575                 sprintf(buf,
576                         "The maximum distance from the chosen PBC atom (%d) of pull group %d to "
577                         "other "
578                         "atoms in the group is larger than %g times half the box size. "
579                         "Set the pull-pbc-ref-prev-step-com option to yes.",
580                         pull->group[g].pbcatom + 1, g, c_pullGroupSmallGroupThreshold);
581                 warning_error(wi, buf);
582             }
583         }
584         if (groupObeysPbc)
585         {
586             groupObeysPbc = pullCheckPbcWithinGroup(
587                     *pull_work, gmx::arrayRefFromArray(reinterpret_cast<gmx::RVec*>(x), mtop->natoms),
588                     pbc, g, c_pullGroupPbcMargin);
589             if (!groupObeysPbc)
590             {
591                 char buf[STRLEN];
592                 sprintf(buf,
593                         "Pull group %d has atoms at a distance larger than %g times half the box "
594                         "size from the PBC atom (%d). "
595                         "If atoms are or will more beyond half the box size from the PBC atom, the "
596                         "COM will be ill defined.",
597                         g, c_pullGroupPbcMargin, pull->group[g].pbcatom + 1);
598                 set_warning_line(wi, nullptr, -1);
599                 warning(wi, buf);
600             }
601         }
602     }
603
604     fprintf(stderr, "Pull group  natoms  pbc atom  distance at start  reference at t=0\n");
605     for (c = 0; c < pull->ncoord; c++)
606     {
607         t_pull_coord* pcrd;
608         t_pull_group *pgrp0, *pgrp1;
609         double        value;
610         real          init = 0;
611
612         pcrd = &pull->coord[c];
613
614         pgrp0 = &pull->group[pcrd->group[0]];
615         pgrp1 = &pull->group[pcrd->group[1]];
616         fprintf(stderr, "%8d  %8d  %8d\n", pcrd->group[0], pgrp0->nat, pgrp0->pbcatom + 1);
617         fprintf(stderr, "%8d  %8d  %8d ", pcrd->group[1], pgrp1->nat, pgrp1->pbcatom + 1);
618
619         if (pcrd->bStart)
620         {
621             init       = pcrd->init;
622             pcrd->init = 0;
623         }
624
625         value = get_pull_coord_value(pull_work, c, &pbc);
626
627         value *= pull_conversion_factor_internal2userinput(pcrd);
628         fprintf(stderr, " %10.3f %s", value, pull_coordinate_units(pcrd));
629
630         if (pcrd->bStart)
631         {
632             pcrd->init = value + init;
633         }
634
635         if (pcrd->eGeom == epullgDIST)
636         {
637             if (pcrd->init < 0)
638             {
639                 gmx_fatal(FARGS,
640                           "The initial pull distance (%g) needs to be non-negative with geometry "
641                           "%s. If you want a signed distance, use geometry %s instead.",
642                           pcrd->init, EPULLGEOM(pcrd->eGeom), EPULLGEOM(epullgDIR));
643             }
644
645             /* TODO: With a positive init but a negative rate things could still
646              * go wrong, but it might be fine if you don't pull too far.
647              * We should give a warning or note when there is only one pull dim
648              * active, since that is usually the problematic case when you should
649              * be using direction. We will do this later, since an already planned
650              * generalization of the pull code makes pull dim available here.
651              */
652         }
653         else if (pcrd->eGeom == epullgANGLE || pcrd->eGeom == epullgANGLEAXIS)
654         {
655             if (pcrd->init < 0 || pcrd->init > 180)
656             {
657                 gmx_fatal(FARGS,
658                           "The initial pull reference angle (%g) is outside of the allowed range "
659                           "[0, 180] degrees.",
660                           pcrd->init);
661             }
662         }
663         else if (pcrd->eGeom == epullgDIHEDRAL)
664         {
665             if (pcrd->init < -180 || pcrd->init > 180)
666             {
667                 gmx_fatal(FARGS,
668                           "The initial pull reference angle (%g) is outside of the allowed range "
669                           "[-180, 180] degrees.",
670                           pcrd->init);
671             }
672         }
673
674
675         fprintf(stderr, "     %10.3f %s\n", pcrd->init, pull_coordinate_units(pcrd));
676     }
677
678     return pull_work;
679 }