Remove all unnecessary HAVE_CONFIG_H
[gromacs.git] / src / gromacs / gmxpreprocess / add_par.c
blob8bcab7fc827f36bb27d9e67e9489ba03ded03056
1 /*
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! */
38 #include "config.h"
40 #include <string.h>
41 #include "typedefs.h"
42 #include "gromacs/utility/smalloc.h"
43 #include "grompp-impl.h"
44 #include "macros.h"
45 #include "toputil.h"
46 #include "hackblock.h"
47 #include "gromacs/utility/cstringutil.h"
48 #include "gromacs/utility/fatalerror.h"
50 static void clear_atom_list(int i0, atom_id a[])
52 int i;
54 for (i = i0; i < MAXATOMLIST; i++)
56 a[i] = -1;
60 static void clear_force_param(int i0, real c[])
62 int i;
64 for (i = i0; i < MAXFORCEPARAM; i++)
66 c[i] = NOTSET;
70 void add_param(t_params *ps, int ai, int aj, real *c, char *s)
72 int i;
74 if ((ai < 0) || (aj < 0))
76 gmx_fatal(FARGS, "Trying to add impossible atoms: ai=%d, aj=%d", ai, aj);
78 pr_alloc(1, ps);
79 ps->param[ps->nr].AI = ai;
80 ps->param[ps->nr].AJ = aj;
81 clear_atom_list(2, ps->param[ps->nr].a);
82 if (c == NULL)
84 clear_force_param(0, ps->param[ps->nr].c);
86 else
88 for (i = 0; (i < MAXFORCEPARAM); i++)
90 ps->param[ps->nr].c[i] = c[i];
93 set_p_string(&(ps->param[ps->nr]), s);
94 ps->nr++;
97 void add_imp_param(t_params *ps, int ai, int aj, int ak, int al, real c0, real c1,
98 char *s)
100 pr_alloc(1, ps);
101 ps->param[ps->nr].AI = ai;
102 ps->param[ps->nr].AJ = aj;
103 ps->param[ps->nr].AK = ak;
104 ps->param[ps->nr].AL = al;
105 clear_atom_list (4, ps->param[ps->nr].a);
106 ps->param[ps->nr].C0 = c0;
107 ps->param[ps->nr].C1 = c1;
108 clear_force_param(2, ps->param[ps->nr].c);
109 set_p_string(&(ps->param[ps->nr]), s);
110 ps->nr++;
113 void add_dih_param(t_params *ps, int ai, int aj, int ak, int al, real c0, real c1,
114 real c2, char *s)
116 pr_alloc(1, ps);
117 ps->param[ps->nr].AI = ai;
118 ps->param[ps->nr].AJ = aj;
119 ps->param[ps->nr].AK = ak;
120 ps->param[ps->nr].AL = al;
121 clear_atom_list (4, ps->param[ps->nr].a);
122 ps->param[ps->nr].C0 = c0;
123 ps->param[ps->nr].C1 = c1;
124 ps->param[ps->nr].C2 = c2;
125 clear_force_param(3, ps->param[ps->nr].c);
126 set_p_string(&(ps->param[ps->nr]), s);
127 ps->nr++;
130 void add_cmap_param(t_params *ps, int ai, int aj, int ak, int al, int am, char *s)
132 pr_alloc(1, ps);
133 ps->param[ps->nr].AI = ai;
134 ps->param[ps->nr].AJ = aj;
135 ps->param[ps->nr].AK = ak;
136 ps->param[ps->nr].AL = al;
137 ps->param[ps->nr].AM = am;
138 clear_atom_list(5, ps->param[ps->nr].a);
139 clear_force_param(0, ps->param[ps->nr].c);
140 set_p_string(&(ps->param[ps->nr]), s);
141 ps->nr++;
144 void add_vsite2_atoms(t_params *ps, int ai, int aj, int ak)
146 pr_alloc(1, ps);
147 ps->param[ps->nr].AI = ai;
148 ps->param[ps->nr].AJ = aj;
149 ps->param[ps->nr].AK = ak;
150 clear_atom_list (3, ps->param[ps->nr].a);
151 clear_force_param(0, ps->param[ps->nr].c);
152 set_p_string(&(ps->param[ps->nr]), "");
153 ps->nr++;
156 void add_vsite2_param(t_params *ps, int ai, int aj, int ak, real c0)
158 pr_alloc(1, ps);
159 ps->param[ps->nr].AI = ai;
160 ps->param[ps->nr].AJ = aj;
161 ps->param[ps->nr].AK = ak;
162 clear_atom_list (3, ps->param[ps->nr].a);
163 ps->param[ps->nr].C0 = c0;
164 clear_force_param(1, ps->param[ps->nr].c);
165 set_p_string(&(ps->param[ps->nr]), "");
166 ps->nr++;
169 void add_vsite3_param(t_params *ps, int ai, int aj, int ak, int al,
170 real c0, real c1)
172 pr_alloc(1, ps);
173 ps->param[ps->nr].AI = ai;
174 ps->param[ps->nr].AJ = aj;
175 ps->param[ps->nr].AK = ak;
176 ps->param[ps->nr].AL = al;
177 clear_atom_list (4, ps->param[ps->nr].a);
178 ps->param[ps->nr].C0 = c0;
179 ps->param[ps->nr].C1 = c1;
180 clear_force_param(2, ps->param[ps->nr].c);
181 set_p_string(&(ps->param[ps->nr]), "");
182 ps->nr++;
185 void add_vsite3_atoms(t_params *ps, int ai, int aj, int ak, int al, gmx_bool bSwapParity)
187 pr_alloc(1, ps);
188 ps->param[ps->nr].AI = ai;
189 ps->param[ps->nr].AJ = aj;
190 ps->param[ps->nr].AK = ak;
191 ps->param[ps->nr].AL = al;
192 clear_atom_list (4, ps->param[ps->nr].a);
193 clear_force_param(0, ps->param[ps->nr].c);
194 if (bSwapParity)
196 ps->param[ps->nr].C1 = -1;
198 set_p_string(&(ps->param[ps->nr]), "");
199 ps->nr++;
202 void add_vsite4_atoms(t_params *ps, int ai, int aj, int ak, int al, int am)
204 pr_alloc(1, ps);
205 ps->param[ps->nr].AI = ai;
206 ps->param[ps->nr].AJ = aj;
207 ps->param[ps->nr].AK = ak;
208 ps->param[ps->nr].AL = al;
209 ps->param[ps->nr].AM = am;
210 clear_atom_list (5, ps->param[ps->nr].a);
211 clear_force_param(0, ps->param[ps->nr].c);
212 set_p_string(&(ps->param[ps->nr]), "");
213 ps->nr++;
216 int search_jtype(t_restp *rtp, char *name, gmx_bool bNterm)
218 int niter, iter, j, k, kmax, jmax, minstrlen;
219 char *rtpname, searchname[12];
221 strcpy(searchname, name);
223 /* Do a best match comparison */
224 /* for protein N-terminus, allow renaming of H1, H2 and H3 to H */
225 if (bNterm && (strlen(searchname) == 2) && (searchname[0] == 'H') &&
226 ( (searchname[1] == '1') || (searchname[1] == '2') ||
227 (searchname[1] == '3') ) )
229 niter = 2;
231 else
233 niter = 1;
235 kmax = 0;
236 jmax = -1;
237 for (iter = 0; (iter < niter && jmax == -1); iter++)
239 if (iter == 1)
241 /* Try without the hydrogen number in the N-terminus */
242 searchname[1] = '\0';
244 for (j = 0; (j < rtp->natom); j++)
246 rtpname = *(rtp->atomname[j]);
247 if (gmx_strcasecmp(searchname, rtpname) == 0)
249 jmax = j;
250 kmax = strlen(searchname);
251 break;
253 if (iter == niter - 1)
255 minstrlen = min(strlen(searchname), strlen(rtpname));
256 for (k = 0; k < minstrlen; k++)
258 if (searchname[k] != rtpname[k])
260 break;
263 if (k > kmax)
265 kmax = k;
266 jmax = j;
271 if (jmax == -1)
273 gmx_fatal(FARGS, "Atom %s not found in rtp database in residue %s",
274 searchname, rtp->resname);
276 if (kmax != strlen(searchname))
278 gmx_fatal(FARGS, "Atom %s not found in rtp database in residue %s, "
279 "it looks a bit like %s",
280 searchname, rtp->resname, *(rtp->atomname[jmax]));
282 return jmax;