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, 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.
47 #include "gromacs/fileio/futil.h"
52 #include "gmx_fatal.h"
60 #include "gromacs/pulling/pull.h"
63 static char pulldim[STRLEN];
65 static void string2dvec(const char buf[], dvec nums)
69 if (sscanf(buf, "%lf%lf%lf%lf", &nums[0], &nums[1], &nums[2], &dum) != 3)
71 gmx_fatal(FARGS, "Expected three numbers at input line %s", buf);
75 static void init_pull_group(t_pull_group *pg,
82 while (sscanf(wbuf, "%lf %n", &d, &n) == 1)
84 if (pg->nweight % 100 == 0)
86 srenew(pg->weight, pg->nweight+100);
88 pg->weight[pg->nweight++] = d;
93 static void init_pull_coord(t_pull_coord *pcrd, int eGeom,
94 const char *origin_buf, const char *vec_buf)
99 string2dvec(origin_buf, origin);
100 if (pcrd->group[0] != 0 && dnorm(origin) > 0)
102 gmx_fatal(FARGS, "The pull origin can only be set with an absolute reference");
105 if (eGeom == epullgDIST)
111 string2dvec(vec_buf, vec);
112 if (eGeom == epullgDIR || eGeom == epullgCYL)
114 /* Normalize the direction vector */
115 dsvmul(1/dnorm(vec), vec, vec);
118 for (m = 0; m < DIM; m++)
120 pcrd->origin[m] = origin[m];
121 pcrd->vec[m] = vec[m];
125 char **read_pullparams(int *ninp_p, t_inpfile **inp_p,
126 t_pull *pull, gmx_bool *bStart,
129 int ninp, nerror = 0, i, nchar, nscan, m, idum;
133 char dummy[STRLEN], buf[STRLEN], groups[STRLEN], init[STRLEN];
134 const char *init_def1 = "0.0", *init_def3 = "0.0 0.0 0.0";
135 char wbuf[STRLEN], origin_buf[STRLEN], vec_buf[STRLEN];
143 /* read pull parameters */
144 CTYPE("Pull geometry: distance, direction, direction-periodic or cylinder");
145 EETYPE("pull-geometry", pull->eGeom, epullg_names);
146 CTYPE("Select components for the pull vector. default: Y Y Y");
147 STYPE("pull-dim", pulldim, "Y Y Y");
148 CTYPE("Cylinder radius for dynamic reaction force groups (nm)");
149 RTYPE("pull-r1", pull->cyl_r1, 1.0);
150 CTYPE("Switch from r1 to r0 in case of dynamic reaction force");
151 RTYPE("pull-r0", pull->cyl_r0, 1.5);
152 RTYPE("pull_constr_tol", pull->constr_tol, 1E-6);
153 EETYPE("pull-start", *bStart, yesno_names);
154 EETYPE("pull-print-reference", pull->bPrintRef, yesno_names);
155 ITYPE("pull-nstxout", pull->nstxout, 10);
156 ITYPE("pull-nstfout", pull->nstfout, 1);
157 CTYPE("Number of pull groups");
158 ITYPE("pull-ngroups", pull->ngroup, 1);
159 CTYPE("Number of pull coordinates");
160 ITYPE("pull-ncoords", pull->ncoord, 1);
162 if (pull->cyl_r1 > pull->cyl_r0)
164 warning_error(wi, "pull-r1 > pull_r0");
167 if (pull->ngroup < 1)
169 gmx_fatal(FARGS, "pull-ngroups should be >= 1");
171 /* We always add an absolute reference group (index 0), even if not used */
174 if (pull->ncoord < 1)
176 gmx_fatal(FARGS, "pull-ncoords should be >= 1");
179 snew(pull->group, pull->ngroup);
181 snew(pull->coord, pull->ncoord);
183 /* pull group options */
184 CTYPE("Group name, weight (default all 1), vector, init, rate (nm/ps), kJ/(mol*nm^2)");
186 /* Read the pull groups */
187 snew(grpbuf, pull->ngroup);
188 /* Group 0 is the absolute reference, we don't read anything for 0 */
189 for (i = 1; i < pull->ngroup; i++)
191 pgrp = &pull->group[i];
192 snew(grpbuf[i], STRLEN);
193 sprintf(buf, "pull-group%d-name", i);
194 STYPE(buf, grpbuf[i], "");
195 sprintf(buf, "pull-group%d-weights", i);
196 STYPE(buf, wbuf, "");
197 sprintf(buf, "pull-group%d-pbcatom", i);
198 ITYPE(buf, pgrp->pbcatom, 0);
200 /* Initialize the pull group */
201 init_pull_group(pgrp, wbuf);
204 /* Read the pull coordinates */
205 for (i = 1; i < pull->ncoord + 1; i++)
207 pcrd = &pull->coord[i-1];
208 sprintf(buf, "pull-coord%d-groups", i);
209 STYPE(buf, groups, "");
210 nscan = sscanf(groups, "%d %d %d", &pcrd->group[0], &pcrd->group[1], &idum);
213 fprintf(stderr, "ERROR: %s should have %d components\n", buf, 2);
216 sprintf(buf, "pull-coord%d-origin", i);
217 STYPE(buf, origin_buf, "0.0 0.0 0.0");
218 sprintf(buf, "pull-coord%d-vec", i);
219 STYPE(buf, vec_buf, "0.0 0.0 0.0");
220 sprintf(buf, "pull-coord%d-init", i);
221 RTYPE(buf, pcrd->init, 0.0);
222 sprintf(buf, "pull-coord%d-rate", i);
223 RTYPE(buf, pcrd->rate, 0.0);
224 sprintf(buf, "pull-coord%d-k", i);
225 RTYPE(buf, pcrd->k, 0.0);
226 sprintf(buf, "pull-coord%d-kB", i);
227 RTYPE(buf, pcrd->kB, pcrd->k);
229 /* Initialize the pull coordinate */
230 init_pull_coord(pcrd, pull->eGeom, origin_buf, vec_buf);
239 void make_pull_groups(t_pull *pull,
241 const t_blocka *grps, char **gnames)
246 /* Absolute reference group (might not be used) is special */
247 pgrp = &pull->group[0];
251 for (g = 1; g < pull->ngroup; g++)
253 pgrp = &pull->group[g];
255 ig = search_string(pgnames[g], grps->nr, gnames);
256 pgrp->nat = grps->index[ig+1] - grps->index[ig];
258 fprintf(stderr, "Pull group %d '%s' has %d atoms\n",
259 g, pgnames[g], pgrp->nat);
263 gmx_fatal(FARGS, "Pull group %d '%s' is empty", g, pgnames[g]);
266 snew(pgrp->ind, pgrp->nat);
267 for (i = 0; i < pgrp->nat; i++)
269 pgrp->ind[i] = grps->a[grps->index[ig]+i];
272 if (pull->eGeom == epullgCYL && g == 1 && pgrp->nweight > 0)
274 gmx_fatal(FARGS, "Weights are not supported for the reference group with cylinder pulling");
276 if (pgrp->nweight > 0 && pgrp->nweight != pgrp->nat)
278 gmx_fatal(FARGS, "Number of weights (%d) for pull group %d '%s' does not match the number of atoms (%d)",
279 pgrp->nweight, g, pgnames[g], pgrp->nat);
284 /* No pbc is required for this group */
289 if (pgrp->pbcatom > 0)
293 else if (pgrp->pbcatom == 0)
295 pgrp->pbcatom = pgrp->ind[(pgrp->nat-1)/2];
299 /* Use cosine weighting */
306 void make_pull_coords(t_pull *pull)
308 int ndim, d, nchar, c;
309 char *ptr, pulldim1[STRLEN];
314 for (d = 0; d < DIM; d++)
316 if (sscanf(ptr, "%s%n", pulldim1, &nchar) != 1)
318 gmx_fatal(FARGS, "Less than 3 pull dimensions given in pull_dim: '%s'",
322 if (gmx_strncasecmp(pulldim1, "N", 1) == 0)
326 else if (gmx_strncasecmp(pulldim1, "Y", 1) == 0)
333 gmx_fatal(FARGS, "Please use Y(ES) or N(O) for pull_dim only (not %s)",
340 gmx_fatal(FARGS, "All entries in pull_dim are N");
343 for (c = 0; c < pull->ncoord; c++)
345 pcrd = &pull->coord[c];
347 if (pcrd->group[0] < 0 || pcrd->group[0] >= pull->ngroup ||
348 pcrd->group[1] < 0 || pcrd->group[1] >= pull->ngroup)
350 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);
353 if (pcrd->group[0] == pcrd->group[1])
355 gmx_fatal(FARGS, "Identical pull group indices in pull-coord%d-groups", c+1);
358 if (pull->eGeom == epullgCYL && pcrd->group[0] != 1)
360 gmx_fatal(FARGS, "With pull geometry %s, the first pull group should always be 1", EPULLGEOM(pull->eGeom));
363 if (pull->eGeom != epullgDIST)
365 for (d = 0; d < DIM; d++)
367 if (pcrd->vec[d] != 0 && pull->dim[d] == 0)
369 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);
374 if ((pull->eGeom == epullgDIR || pull->eGeom == epullgCYL) &&
375 norm2(pcrd->vec) == 0)
377 gmx_fatal(FARGS, "pull-group%d-vec can not be zero with geometry %s",
378 c+1, EPULLGEOM(pull->eGeom));
383 void set_pull_init(t_inputrec *ir, gmx_mtop_t *mtop, rvec *x, matrix box, real lambda,
384 const output_env_t oenv, gmx_bool bStart)
389 t_pull_group *pgrp0, *pgrp1;
392 double t_start, tinvrate;
397 init_pull(NULL, ir, 0, NULL, mtop, NULL, oenv, lambda, FALSE, 0);
398 md = init_mdatoms(NULL, mtop, ir->efep);
399 atoms2md(mtop, ir, 0, NULL, mtop->natoms, md);
402 update_mdatoms(md, lambda);
406 set_pbc(&pbc, ir->ePBC, box);
408 t_start = ir->init_t + ir->init_step*ir->delta_t;
410 pull_calc_coms(NULL, pull, md, &pbc, t_start, x, NULL);
412 fprintf(stderr, "Pull group natoms pbc atom distance at start reference at t=0\n");
413 for (c = 0; c < pull->ncoord; c++)
415 pcrd = &pull->coord[c];
417 pgrp0 = &pull->group[pcrd->group[0]];
418 pgrp1 = &pull->group[pcrd->group[1]];
419 fprintf(stderr, "%8d %8d %8d\n",
420 pcrd->group[0], pgrp0->nat, pgrp0->pbcatom+1);
421 fprintf(stderr, "%8d %8d %8d ",
422 pcrd->group[1], pgrp1->nat, pgrp1->pbcatom+1);
433 tinvrate = t_start/pcrd->rate;
435 get_pull_coord_distance(pull, c, &pbc, 0, dr, &dev);
436 fprintf(stderr, " %6.3f ", dev);
440 pcrd->init = init + dev - tinvrate;
446 fprintf(stderr, " %6.3f\n", pcrd->init);