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, 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.
42 #include "gromacs/gmxpreprocess/readir.h"
43 #include "gromacs/legacyheaders/macros.h"
44 #include "gromacs/legacyheaders/mdatoms.h"
45 #include "gromacs/legacyheaders/names.h"
46 #include "gromacs/legacyheaders/readinp.h"
47 #include "gromacs/legacyheaders/typedefs.h"
48 #include "gromacs/math/vec.h"
49 #include "gromacs/pbcutil/pbc.h"
50 #include "gromacs/pulling/pull.h"
51 #include "gromacs/utility/cstringutil.h"
52 #include "gromacs/utility/fatalerror.h"
53 #include "gromacs/utility/futil.h"
54 #include "gromacs/utility/smalloc.h"
57 static void string2dvec(const char buf[], dvec nums)
61 if (sscanf(buf, "%lf%lf%lf%lf", &nums[0], &nums[1], &nums[2], &dum) != 3)
63 gmx_fatal(FARGS, "Expected three numbers at input line %s", buf);
67 static void init_pull_group(t_pull_group *pg,
74 while (sscanf(wbuf, "%lf %n", &d, &n) == 1)
76 if (pg->nweight % 100 == 0)
78 srenew(pg->weight, pg->nweight+100);
80 pg->weight[pg->nweight++] = d;
85 static void process_pull_dim(char *dim_buf, ivec dim)
87 int ndim, d, nchar, c;
88 char *ptr, pulldim1[STRLEN];
93 for (d = 0; d < DIM; d++)
95 if (sscanf(ptr, "%s%n", pulldim1, &nchar) != 1)
97 gmx_fatal(FARGS, "Less than 3 pull dimensions given in pull_dim: '%s'",
101 if (gmx_strncasecmp(pulldim1, "N", 1) == 0)
105 else if (gmx_strncasecmp(pulldim1, "Y", 1) == 0)
112 gmx_fatal(FARGS, "Please use Y(ES) or N(O) for pull_dim only (not %s)",
119 gmx_fatal(FARGS, "All entries in pull dim are N");
123 static void init_pull_coord(t_pull_coord *pcrd,
125 const char *origin_buf, const char *vec_buf,
132 if (pcrd->eType == epullCONSTRAINT && pcrd->eGeom == epullgCYL)
134 gmx_fatal(FARGS, "Pulling of type %s can not be combined with geometry %s. Consider using pull type %s.",
135 epull_names[pcrd->eType],
136 epullg_names[pcrd->eGeom],
137 epull_names[epullUMBRELLA]);
140 process_pull_dim(dim_buf, pcrd->dim);
142 string2dvec(origin_buf, origin);
143 if (pcrd->group[0] != 0 && dnorm(origin) > 0)
145 gmx_fatal(FARGS, "The pull origin can only be set with an absolute reference");
148 if (pcrd->eGeom == epullgDIST)
152 sprintf(buf, "The initial pull distance is negative with geometry %s, while a distance can not be negative. Use geometry %s instead.",
153 EPULLGEOM(pcrd->eGeom), EPULLGEOM(epullgDIR));
154 warning_error(wi, buf);
156 /* TODO: With a positive init but a negative rate things could still
157 * go wrong, but it might be fine if you don't pull too far.
158 * We should give a warning or note when there is only one pull dim
159 * active, since that is usually the problematic case when you should
160 * be using direction. We will do this later, since an already planned
161 * generalization of the pull code makes pull dim available here.
168 string2dvec(vec_buf, vec);
169 if (dnorm2(vec) == 0)
171 gmx_fatal(FARGS, "With pull geometry %s the pull vector can not be 0,0,0",
172 epullg_names[pcrd->eGeom]);
174 if (pcrd->eGeom == epullgDIR || pcrd->eGeom == epullgCYL)
176 /* Normalize the direction vector */
177 dsvmul(1/dnorm(vec), vec, vec);
180 for (m = 0; m < DIM; m++)
182 pcrd->origin[m] = origin[m];
183 pcrd->vec[m] = vec[m];
187 char **read_pullparams(int *ninp_p, t_inpfile **inp_p,
191 int ninp, nerror = 0, i, nchar, nscan, m, idum;
195 char dummy[STRLEN], buf[STRLEN], groups[STRLEN], dim_buf[STRLEN];
197 const char *init_def1 = "0.0", *init_def3 = "0.0 0.0 0.0";
198 char wbuf[STRLEN], origin_buf[STRLEN], vec_buf[STRLEN];
206 /* read pull parameters */
207 CTYPE("Cylinder radius for dynamic reaction force groups (nm)");
208 RTYPE("pull-cylinder-r", pull->cylinder_r, 1.5);
209 RTYPE("pull-constr-tol", pull->constr_tol, 1E-6);
210 EETYPE("pull-print-com1", pull->bPrintCOM1, yesno_names);
211 EETYPE("pull-print-com2", pull->bPrintCOM2, yesno_names);
212 EETYPE("pull-print-ref-value", pull->bPrintRefValue, yesno_names);
213 EETYPE("pull-print-components", pull->bPrintComp, yesno_names);
214 ITYPE("pull-nstxout", pull->nstxout, 50);
215 ITYPE("pull-nstfout", pull->nstfout, 50);
216 CTYPE("Number of pull groups");
217 ITYPE("pull-ngroups", pull->ngroup, 1);
218 CTYPE("Number of pull coordinates");
219 ITYPE("pull-ncoords", pull->ncoord, 1);
221 if (pull->ngroup < 1)
223 gmx_fatal(FARGS, "pull-ngroups should be >= 1");
225 /* We always add an absolute reference group (index 0), even if not used */
228 if (pull->ncoord < 1)
230 gmx_fatal(FARGS, "pull-ncoords should be >= 1");
233 snew(pull->group, pull->ngroup);
235 snew(pull->coord, pull->ncoord);
237 /* pull group options */
238 CTYPE("Group name, weight (default all 1), vector, init, rate (nm/ps), kJ/(mol*nm^2)");
240 /* Read the pull groups */
241 snew(grpbuf, pull->ngroup);
242 /* Group 0 is the absolute reference, we don't read anything for 0 */
243 for (i = 1; i < pull->ngroup; i++)
245 pgrp = &pull->group[i];
246 snew(grpbuf[i], STRLEN);
247 sprintf(buf, "pull-group%d-name", i);
248 STYPE(buf, grpbuf[i], "");
249 sprintf(buf, "pull-group%d-weights", i);
250 STYPE(buf, wbuf, "");
251 sprintf(buf, "pull-group%d-pbcatom", i);
252 ITYPE(buf, pgrp->pbcatom, 0);
254 /* Initialize the pull group */
255 init_pull_group(pgrp, wbuf);
258 /* Read the pull coordinates */
259 for (i = 1; i < pull->ncoord + 1; i++)
261 pcrd = &pull->coord[i-1];
262 sprintf(buf, "pull-coord%d-groups", i);
263 STYPE(buf, groups, "");
264 nscan = sscanf(groups, "%d %d %d", &pcrd->group[0], &pcrd->group[1], &idum);
267 fprintf(stderr, "ERROR: %s should contain %d pull group indices\n",
271 sprintf(buf, "pull-coord%d-type", i);
272 EETYPE(buf, pcrd->eType, epull_names);
273 sprintf(buf, "pull-coord%d-geometry", i);
274 EETYPE(buf, pcrd->eGeom, epullg_names);
275 sprintf(buf, "pull-coord%d-dim", i);
276 STYPE(buf, dim_buf, "Y Y Y");
277 sprintf(buf, "pull-coord%d-origin", i);
278 STYPE(buf, origin_buf, "0.0 0.0 0.0");
279 sprintf(buf, "pull-coord%d-vec", i);
280 STYPE(buf, vec_buf, "0.0 0.0 0.0");
281 sprintf(buf, "pull-coord%d-start", i);
282 EETYPE(buf, pcrd->bStart, yesno_names);
283 sprintf(buf, "pull-coord%d-init", i);
284 RTYPE(buf, pcrd->init, 0.0);
285 sprintf(buf, "pull-coord%d-rate", i);
286 RTYPE(buf, pcrd->rate, 0.0);
287 sprintf(buf, "pull-coord%d-k", i);
288 RTYPE(buf, pcrd->k, 0.0);
289 sprintf(buf, "pull-coord%d-kB", i);
290 RTYPE(buf, pcrd->kB, pcrd->k);
292 /* Initialize the pull coordinate */
293 init_pull_coord(pcrd, dim_buf, origin_buf, vec_buf, wi);
302 void make_pull_groups(t_pull *pull,
304 const t_blocka *grps, char **gnames)
309 /* Absolute reference group (might not be used) is special */
310 pgrp = &pull->group[0];
314 for (g = 1; g < pull->ngroup; g++)
316 pgrp = &pull->group[g];
318 if (strcmp(pgnames[g], "") == 0)
320 gmx_fatal(FARGS, "Pull option pull_group%d required by grompp has not been set.", g);
323 ig = search_string(pgnames[g], grps->nr, gnames);
324 pgrp->nat = grps->index[ig+1] - grps->index[ig];
326 fprintf(stderr, "Pull group %d '%s' has %d atoms\n",
327 g, pgnames[g], pgrp->nat);
331 gmx_fatal(FARGS, "Pull group %d '%s' is empty", g, pgnames[g]);
334 snew(pgrp->ind, pgrp->nat);
335 for (i = 0; i < pgrp->nat; i++)
337 pgrp->ind[i] = grps->a[grps->index[ig]+i];
340 if (pgrp->nweight > 0 && pgrp->nweight != pgrp->nat)
342 gmx_fatal(FARGS, "Number of weights (%d) for pull group %d '%s' does not match the number of atoms (%d)",
343 pgrp->nweight, g, pgnames[g], pgrp->nat);
348 /* No pbc is required for this group */
353 if (pgrp->pbcatom > 0)
357 else if (pgrp->pbcatom == 0)
359 pgrp->pbcatom = pgrp->ind[(pgrp->nat-1)/2];
363 /* Use cosine weighting */
370 void make_pull_coords(t_pull *pull)
375 for (c = 0; c < pull->ncoord; c++)
377 pcrd = &pull->coord[c];
379 if (pcrd->group[0] < 0 || pcrd->group[0] >= pull->ngroup ||
380 pcrd->group[1] < 0 || pcrd->group[1] >= pull->ngroup)
382 gmx_fatal(FARGS, "Pull group index in pull-coord%d-groups out of range, should be between %d and %d", c+1, 0, pull->ngroup+1);
385 if (pcrd->group[0] == pcrd->group[1])
387 gmx_fatal(FARGS, "Identical pull group indices in pull-coord%d-groups", c+1);
390 if (pcrd->eGeom == epullgCYL)
392 if (pull->group[pcrd->group[0]].nweight > 0)
394 gmx_fatal(FARGS, "Weights are not supported for the reference group with cylinder pulling");
398 if (pcrd->eGeom != epullgDIST)
400 for (d = 0; d < DIM; d++)
402 if (pcrd->vec[d] != 0 && pcrd->dim[d] == 0)
404 gmx_fatal(FARGS, "ERROR: pull-group%d-vec has non-zero %c-component while pull_dim for the %c-dimension is N\n", c+1, 'x'+d, 'x'+d);
409 if ((pcrd->eGeom == epullgDIR || pcrd->eGeom == epullgCYL) &&
410 norm2(pcrd->vec) == 0)
412 gmx_fatal(FARGS, "pull-group%d-vec can not be zero with geometry %s",
413 c+1, EPULLGEOM(pcrd->eGeom));
418 void set_pull_init(t_inputrec *ir, gmx_mtop_t *mtop, rvec *x, matrix box, real lambda,
419 const output_env_t oenv)
424 t_pull_group *pgrp0, *pgrp1;
432 init_pull(NULL, ir, 0, NULL, mtop, NULL, oenv, lambda, FALSE, 0);
433 md = init_mdatoms(NULL, mtop, ir->efep);
434 atoms2md(mtop, ir, 0, NULL, mtop->natoms, md);
437 update_mdatoms(md, lambda);
441 set_pbc(&pbc, ir->ePBC, box);
443 t_start = ir->init_t + ir->init_step*ir->delta_t;
445 pull_calc_coms(NULL, pull, md, &pbc, t_start, x, NULL);
447 fprintf(stderr, "Pull group natoms pbc atom distance at start reference at t=0\n");
448 for (c = 0; c < pull->ncoord; c++)
450 pcrd = &pull->coord[c];
452 pgrp0 = &pull->group[pcrd->group[0]];
453 pgrp1 = &pull->group[pcrd->group[1]];
454 fprintf(stderr, "%8d %8d %8d\n",
455 pcrd->group[0], pgrp0->nat, pgrp0->pbcatom+1);
456 fprintf(stderr, "%8d %8d %8d ",
457 pcrd->group[1], pgrp1->nat, pgrp1->pbcatom+1);
465 get_pull_coord_distance(pull, c, &pbc, t_start, dr, &dev);
466 /* Calculate the value of the coordinate at t_start */
467 value = pcrd->init + t_start*pcrd->rate + dev;
468 fprintf(stderr, " %10.3f nm", value);
472 pcrd->init = value + init;
474 fprintf(stderr, " %10.3f nm\n", pcrd->init);