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.
44 #include "gromacs/utility/smalloc.h"
45 #include "gromacs/legacyheaders/macros.h"
46 #include "gromacs/utility/cstringutil.h"
47 #include "gromacs/utility/fatalerror.h"
50 /* Must correspond to the directive enum in grompp-impl.h */
51 static const char *directive_names[d_maxdir+1] = {
60 "implicit_genborn_params",
61 "implicit_surface_params",
63 /* All the directives above can not appear after moleculetype */
83 "position_restraints",
86 "distance_restraints",
87 "orientation_restraints",
88 "dihedral_restraints",
93 int ifunc_index(directive d, int type)
122 gmx_fatal(FARGS, "Invalid bond type %d", type);
135 return F_CROSS_BOND_BONDS;
137 return F_CROSS_BOND_ANGLES;
139 return F_UREY_BRADLEY;
141 return F_QUARTIC_ANGLES;
145 return F_LINEAR_ANGLES;
147 return F_RESTRANGLES;
149 gmx_fatal(FARGS, "Invalid angle type %d", type);
155 if (type == 1 || (d == d_pairtypes && type == 2))
165 gmx_fatal(FARGS, "Invalid pairs type %d", type);
169 return F_LJC_PAIRS_NB;
171 case d_dihedraltypes:
187 return F_PDIHS; /* proper dihedrals where we allow multiple terms over single bond */
193 gmx_fatal(FARGS, "Invalid dihedral type %d", type);
200 case d_nonbond_params:
223 gmx_fatal(FARGS, "Invalid vsites3 type %d", type);
234 gmx_fatal(FARGS, "Invalid vsites4 type %d", type);
240 case d_constrainttypes:
248 gmx_fatal(FARGS, "Invalid constraints type %d", type);
253 case d_position_restraints:
262 gmx_fatal(FARGS, "Invalid position restraint type %d", type);
269 return F_POLARIZATION;
273 gmx_fatal(FARGS, "Invalid polarization type %d", type);
276 case d_thole_polarization:
278 case d_water_polarization:
280 case d_angle_restraints:
282 case d_angle_restraints_z:
284 case d_distance_restraints:
286 case d_orientation_restraints:
288 case d_dihedral_restraints:
291 gmx_fatal(FARGS, "invalid directive %s in ifunc_index (%s:%s)",
292 dir2str(d), __FILE__, __LINE__);
297 const char *dir2str (directive d)
301 return directive_names[d];
305 return directive_names[d_maxdir];
309 directive str2dir (char *dstr)
312 char buf[STRLEN], *ptr;
314 /* Hack to be able to read old topologies */
315 if (gmx_strncasecmp_min(dstr, "dummies", 7) == 0)
317 sprintf(buf, "virtual_sites%s", dstr+7);
325 for (d = 0; (d < d_maxdir); d++)
327 if (gmx_strcasecmp_min(ptr, dir2str((directive)d)) == 0)
336 static directive **necessary = NULL;
338 static void set_nec(directive **n, ...)
339 /* Must always have at least one extra argument */
348 d = (directive)va_arg(ap, int);
356 void DS_Init(DirStack **DS)
358 if (necessary == NULL)
362 snew(necessary, d_maxdir);
363 set_nec(&(necessary[d_defaults]), d_none);
364 set_nec(&(necessary[d_atomtypes]), d_defaults, d_none);
365 set_nec(&(necessary[d_bondtypes]), d_atomtypes, d_none);
366 set_nec(&(necessary[d_constrainttypes]), d_atomtypes, d_none);
367 set_nec(&(necessary[d_pairtypes]), d_atomtypes, d_none);
368 set_nec(&(necessary[d_angletypes]), d_atomtypes, d_none);
369 set_nec(&(necessary[d_dihedraltypes]), d_atomtypes, d_none);
370 set_nec(&(necessary[d_nonbond_params]), d_atomtypes, d_none);
371 set_nec(&(necessary[d_implicit_genborn_params]), d_atomtypes, d_none);
372 set_nec(&(necessary[d_implicit_surface_params]), d_atomtypes, d_none);
373 set_nec(&(necessary[d_cmaptypes]), d_atomtypes, d_none);
374 set_nec(&(necessary[d_moleculetype]), d_atomtypes, d_none);
375 set_nec(&(necessary[d_atoms]), d_moleculetype, d_none);
376 set_nec(&(necessary[d_vsites2]), d_atoms, d_none);
377 set_nec(&(necessary[d_vsites3]), d_atoms, d_none);
378 set_nec(&(necessary[d_vsites4]), d_atoms, d_none);
379 set_nec(&(necessary[d_vsitesn]), d_atoms, d_none);
380 set_nec(&(necessary[d_bonds]), d_atoms, d_none);
381 set_nec(&(necessary[d_exclusions]), d_bonds, d_constraints, d_settles, d_none);
382 set_nec(&(necessary[d_pairs]), d_atoms, d_none);
383 set_nec(&(necessary[d_pairs_nb]), d_atoms, d_none);
384 set_nec(&(necessary[d_angles]), d_atoms, d_none);
385 set_nec(&(necessary[d_polarization]), d_atoms, d_none);
386 set_nec(&(necessary[d_water_polarization]), d_atoms, d_none);
387 set_nec(&(necessary[d_thole_polarization]), d_atoms, d_none);
388 set_nec(&(necessary[d_dihedrals]), d_atoms, d_none);
389 set_nec(&(necessary[d_constraints]), d_atoms, d_none);
390 set_nec(&(necessary[d_settles]), d_atoms, d_none);
391 set_nec(&(necessary[d_system]), d_moleculetype, d_none);
392 set_nec(&(necessary[d_molecules]), d_system, d_none);
393 set_nec(&(necessary[d_position_restraints]), d_atoms, d_none);
394 set_nec(&(necessary[d_angle_restraints]), d_atoms, d_none);
395 set_nec(&(necessary[d_angle_restraints_z]), d_atoms, d_none);
396 set_nec(&(necessary[d_distance_restraints]), d_atoms, d_none);
397 set_nec(&(necessary[d_orientation_restraints]), d_atoms, d_none);
398 set_nec(&(necessary[d_dihedral_restraints]), d_atoms, d_none);
399 set_nec(&(necessary[d_cmap]), d_atoms, d_none);
401 for (i = 0; (i < d_maxdir); i++)
405 fprintf(debug, "%20s: ", dir2str((directive)i));
413 d = necessary[i][j++];
416 fprintf(debug, "%20s ", dir2str(d));
423 fprintf(debug, "\n");
431 void DS_Done (DirStack **DS)
443 void DS_Push (DirStack **DS, directive d)
453 int DS_Search(DirStack *DS, directive d)
458 while ((D != NULL) && (D->d != d))
466 int DS_Check_Order(DirStack *DS, directive d)
471 /* Check if parameter definitions appear after a moleculetype directive */
472 if (d < d_moleculetype && DS_Search(DS, d_moleculetype))
477 /* Check if all the necessary directives have appeared before directive d */
478 if (necessary[d][0] == d_none)
486 d0 = necessary[d][i++];
487 if (DS_Search(DS, d0))
492 while (d0 != d_none);