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