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) 2011,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.
37 /* This file is completely threadsafe - keep it that way! */
44 #include "gromacs/utility/smalloc.h"
45 #include "grompp-impl.h"
48 #include "hackblock.h"
49 #include "gromacs/utility/cstringutil.h"
50 #include "gromacs/utility/fatalerror.h"
52 static void clear_atom_list(int i0, atom_id a[])
56 for (i = i0; i < MAXATOMLIST; i++)
62 static void clear_force_param(int i0, real c[])
66 for (i = i0; i < MAXFORCEPARAM; i++)
72 void add_param(t_params *ps, int ai, int aj, real *c, char *s)
76 if ((ai < 0) || (aj < 0))
78 gmx_fatal(FARGS, "Trying to add impossible atoms: ai=%d, aj=%d", ai, aj);
81 ps->param[ps->nr].AI = ai;
82 ps->param[ps->nr].AJ = aj;
83 clear_atom_list(2, ps->param[ps->nr].a);
86 clear_force_param(0, ps->param[ps->nr].c);
90 for (i = 0; (i < MAXFORCEPARAM); i++)
92 ps->param[ps->nr].c[i] = c[i];
95 set_p_string(&(ps->param[ps->nr]), s);
99 void add_imp_param(t_params *ps, int ai, int aj, int ak, int al, real c0, real c1,
103 ps->param[ps->nr].AI = ai;
104 ps->param[ps->nr].AJ = aj;
105 ps->param[ps->nr].AK = ak;
106 ps->param[ps->nr].AL = al;
107 clear_atom_list (4, ps->param[ps->nr].a);
108 ps->param[ps->nr].C0 = c0;
109 ps->param[ps->nr].C1 = c1;
110 clear_force_param(2, ps->param[ps->nr].c);
111 set_p_string(&(ps->param[ps->nr]), s);
115 void add_dih_param(t_params *ps, int ai, int aj, int ak, int al, real c0, real c1,
119 ps->param[ps->nr].AI = ai;
120 ps->param[ps->nr].AJ = aj;
121 ps->param[ps->nr].AK = ak;
122 ps->param[ps->nr].AL = al;
123 clear_atom_list (4, ps->param[ps->nr].a);
124 ps->param[ps->nr].C0 = c0;
125 ps->param[ps->nr].C1 = c1;
126 ps->param[ps->nr].C2 = c2;
127 clear_force_param(3, ps->param[ps->nr].c);
128 set_p_string(&(ps->param[ps->nr]), s);
132 void add_cmap_param(t_params *ps, int ai, int aj, int ak, int al, int am, char *s)
135 ps->param[ps->nr].AI = ai;
136 ps->param[ps->nr].AJ = aj;
137 ps->param[ps->nr].AK = ak;
138 ps->param[ps->nr].AL = al;
139 ps->param[ps->nr].AM = am;
140 clear_atom_list(5, ps->param[ps->nr].a);
141 clear_force_param(0, ps->param[ps->nr].c);
142 set_p_string(&(ps->param[ps->nr]), s);
146 void add_vsite2_atoms(t_params *ps, int ai, int aj, int ak)
149 ps->param[ps->nr].AI = ai;
150 ps->param[ps->nr].AJ = aj;
151 ps->param[ps->nr].AK = ak;
152 clear_atom_list (3, ps->param[ps->nr].a);
153 clear_force_param(0, ps->param[ps->nr].c);
154 set_p_string(&(ps->param[ps->nr]), "");
158 void add_vsite2_param(t_params *ps, int ai, int aj, int ak, real c0)
161 ps->param[ps->nr].AI = ai;
162 ps->param[ps->nr].AJ = aj;
163 ps->param[ps->nr].AK = ak;
164 clear_atom_list (3, ps->param[ps->nr].a);
165 ps->param[ps->nr].C0 = c0;
166 clear_force_param(1, ps->param[ps->nr].c);
167 set_p_string(&(ps->param[ps->nr]), "");
171 void add_vsite3_param(t_params *ps, int ai, int aj, int ak, int al,
175 ps->param[ps->nr].AI = ai;
176 ps->param[ps->nr].AJ = aj;
177 ps->param[ps->nr].AK = ak;
178 ps->param[ps->nr].AL = al;
179 clear_atom_list (4, ps->param[ps->nr].a);
180 ps->param[ps->nr].C0 = c0;
181 ps->param[ps->nr].C1 = c1;
182 clear_force_param(2, ps->param[ps->nr].c);
183 set_p_string(&(ps->param[ps->nr]), "");
187 void add_vsite3_atoms(t_params *ps, int ai, int aj, int ak, int al, gmx_bool bSwapParity)
190 ps->param[ps->nr].AI = ai;
191 ps->param[ps->nr].AJ = aj;
192 ps->param[ps->nr].AK = ak;
193 ps->param[ps->nr].AL = al;
194 clear_atom_list (4, ps->param[ps->nr].a);
195 clear_force_param(0, ps->param[ps->nr].c);
198 ps->param[ps->nr].C1 = -1;
200 set_p_string(&(ps->param[ps->nr]), "");
204 void add_vsite4_atoms(t_params *ps, int ai, int aj, int ak, int al, int am)
207 ps->param[ps->nr].AI = ai;
208 ps->param[ps->nr].AJ = aj;
209 ps->param[ps->nr].AK = ak;
210 ps->param[ps->nr].AL = al;
211 ps->param[ps->nr].AM = am;
212 clear_atom_list (5, ps->param[ps->nr].a);
213 clear_force_param(0, ps->param[ps->nr].c);
214 set_p_string(&(ps->param[ps->nr]), "");
218 int search_jtype(t_restp *rtp, char *name, gmx_bool bNterm)
220 int niter, iter, j, k, kmax, jmax, minstrlen;
221 char *rtpname, searchname[12];
223 strcpy(searchname, name);
225 /* Do a best match comparison */
226 /* for protein N-terminus, allow renaming of H1, H2 and H3 to H */
227 if (bNterm && (strlen(searchname) == 2) && (searchname[0] == 'H') &&
228 ( (searchname[1] == '1') || (searchname[1] == '2') ||
229 (searchname[1] == '3') ) )
239 for (iter = 0; (iter < niter && jmax == -1); iter++)
243 /* Try without the hydrogen number in the N-terminus */
244 searchname[1] = '\0';
246 for (j = 0; (j < rtp->natom); j++)
248 rtpname = *(rtp->atomname[j]);
249 if (gmx_strcasecmp(searchname, rtpname) == 0)
252 kmax = strlen(searchname);
255 if (iter == niter - 1)
257 minstrlen = min(strlen(searchname), strlen(rtpname));
258 for (k = 0; k < minstrlen; k++)
260 if (searchname[k] != rtpname[k])
275 gmx_fatal(FARGS, "Atom %s not found in rtp database in residue %s",
276 searchname, rtp->resname);
278 if (kmax != strlen(searchname))
280 gmx_fatal(FARGS, "Atom %s not found in rtp database in residue %s, "
281 "it looks a bit like %s",
282 searchname, rtp->resname, *(rtp->atomname[jmax]));