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 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012,2013, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
38 /* This file is completely threadsafe - keep it that way! */
48 #include "hackblock.h"
50 #include "gmx_fatal.h"
52 static void clear_atom_list(int i0, atom_id a[])
56 for (i=i0; i < MAXATOMLIST; i++)
60 static void clear_force_param(int i0, real c[])
64 for (i=i0; i < MAXFORCEPARAM; i++)
68 void add_param(t_params *ps,int ai,int aj, real *c, char *s)
72 if ((ai < 0) || (aj < 0))
73 gmx_fatal(FARGS,"Trying to add impossible atoms: ai=%d, aj=%d",ai,aj);
75 ps->param[ps->nr].AI=ai;
76 ps->param[ps->nr].AJ=aj;
77 clear_atom_list(2, ps->param[ps->nr].a);
79 clear_force_param(0, ps->param[ps->nr].c);
81 for(i=0; (i < MAXFORCEPARAM); i++)
82 ps->param[ps->nr].c[i]=c[i];
83 set_p_string(&(ps->param[ps->nr]),s);
87 void add_imp_param(t_params *ps,int ai,int aj,int ak,int al,real c0, real c1,
91 ps->param[ps->nr].AI=ai;
92 ps->param[ps->nr].AJ=aj;
93 ps->param[ps->nr].AK=ak;
94 ps->param[ps->nr].AL=al;
95 clear_atom_list (4, ps->param[ps->nr].a);
96 ps->param[ps->nr].C0=c0;
97 ps->param[ps->nr].C1=c1;
98 clear_force_param(2, ps->param[ps->nr].c);
99 set_p_string(&(ps->param[ps->nr]),s);
103 void add_dih_param(t_params *ps,int ai,int aj,int ak,int al,real c0, real c1,
107 ps->param[ps->nr].AI=ai;
108 ps->param[ps->nr].AJ=aj;
109 ps->param[ps->nr].AK=ak;
110 ps->param[ps->nr].AL=al;
111 clear_atom_list (4, ps->param[ps->nr].a);
112 ps->param[ps->nr].C0=c0;
113 ps->param[ps->nr].C1=c1;
114 ps->param[ps->nr].C2=c2;
115 clear_force_param(3, ps->param[ps->nr].c);
116 set_p_string(&(ps->param[ps->nr]),s);
120 void add_cmap_param(t_params *ps, int ai, int aj, int ak, int al, int am, char *s)
123 ps->param[ps->nr].AI=ai;
124 ps->param[ps->nr].AJ=aj;
125 ps->param[ps->nr].AK=ak;
126 ps->param[ps->nr].AL=al;
127 ps->param[ps->nr].AM=am;
128 clear_atom_list(5,ps->param[ps->nr].a);
129 clear_force_param(0,ps->param[ps->nr].c);
130 set_p_string(&(ps->param[ps->nr]),s);
134 void add_vsite2_atoms(t_params *ps,int ai,int aj,int ak)
137 ps->param[ps->nr].AI=ai;
138 ps->param[ps->nr].AJ=aj;
139 ps->param[ps->nr].AK=ak;
140 clear_atom_list (3, ps->param[ps->nr].a);
141 clear_force_param(0, ps->param[ps->nr].c);
142 set_p_string(&(ps->param[ps->nr]),"");
146 void add_vsite2_param(t_params *ps,int ai,int aj,int ak,real c0)
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 ps->param[ps->nr].C0=c0;
154 clear_force_param(1, ps->param[ps->nr].c);
155 set_p_string(&(ps->param[ps->nr]),"");
159 void add_vsite3_param(t_params *ps,int ai,int aj,int ak,int al,
163 ps->param[ps->nr].AI=ai;
164 ps->param[ps->nr].AJ=aj;
165 ps->param[ps->nr].AK=ak;
166 ps->param[ps->nr].AL=al;
167 clear_atom_list (4, ps->param[ps->nr].a);
168 ps->param[ps->nr].C0=c0;
169 ps->param[ps->nr].C1=c1;
170 clear_force_param(2, ps->param[ps->nr].c);
171 set_p_string(&(ps->param[ps->nr]),"");
175 void add_vsite3_atoms(t_params *ps,int ai,int aj,int ak,int al, gmx_bool bSwapParity)
178 ps->param[ps->nr].AI=ai;
179 ps->param[ps->nr].AJ=aj;
180 ps->param[ps->nr].AK=ak;
181 ps->param[ps->nr].AL=al;
182 clear_atom_list (4, ps->param[ps->nr].a);
183 clear_force_param(0, ps->param[ps->nr].c);
185 ps->param[ps->nr].C1=-1;
186 set_p_string(&(ps->param[ps->nr]),"");
190 void add_vsite4_atoms(t_params *ps,int ai,int aj,int ak,int al,int am)
193 ps->param[ps->nr].AI=ai;
194 ps->param[ps->nr].AJ=aj;
195 ps->param[ps->nr].AK=ak;
196 ps->param[ps->nr].AL=al;
197 ps->param[ps->nr].AM=am;
198 clear_atom_list (5, ps->param[ps->nr].a);
199 clear_force_param(0, ps->param[ps->nr].c);
200 set_p_string(&(ps->param[ps->nr]),"");
204 int search_jtype(t_restp *rtp,char *name,gmx_bool bNterm)
206 int niter,iter,j,k,kmax,jmax,minstrlen;
207 char *rtpname,searchname[12];
209 strcpy(searchname,name);
211 /* Do a best match comparison */
212 /* for protein N-terminus, allow renaming of H1, H2 and H3 to H */
213 if ( bNterm && (strlen(searchname)==2) && (searchname[0] == 'H') &&
214 ( (searchname[1] == '1') || (searchname[1] == '2') ||
215 (searchname[1] == '3') ) ) {
222 for(iter=0; (iter<niter && jmax==-1); iter++) {
224 /* Try without the hydrogen number in the N-terminus */
225 searchname[1] = '\0';
227 for(j=0; (j<rtp->natom); j++) {
228 rtpname=*(rtp->atomname[j]);
229 if (gmx_strcasecmp(searchname,rtpname) == 0) {
231 kmax=strlen(searchname);
234 if (iter == niter - 1) {
235 minstrlen = min(strlen(searchname), strlen(rtpname));
236 for(k=0; k < minstrlen; k++)
237 if (searchname[k] != rtpname[k])
247 gmx_fatal(FARGS,"Atom %s not found in rtp database in residue %s",
248 searchname,rtp->resname);
249 if (kmax != strlen(searchname))
250 gmx_fatal(FARGS,"Atom %s not found in rtp database in residue %s, "
251 "it looks a bit like %s",
252 searchname,rtp->resname,*(rtp->atomname[jmax]));