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.
52 #include "gmx_fatal.h"
54 #include "gpp_atomtype.h"
56 typedef struct gpp_atomtype {
57 int nr; /* The number of atomtypes */
58 t_atom *atom; /* Array of atoms */
59 char ***atomname; /* Names of the atomtypes */
60 t_param *nb; /* Nonbonded force default params */
61 int *bondatomtype; /* The bond_atomtype for each atomtype */
62 real *radius; /* Radius for GBSA stuff */
63 real *vol; /* Effective volume for GBSA */
64 real *surftens; /* Surface tension with water, for GBSA */
65 real *gb_radius; /* Radius for Still model */
66 real *S_hct; /* Overlap factor for HCT model */
67 int *atomnumber; /* Atomic number, used for QM/MM */
70 int get_atomtype_type(const char *str,gpp_atomtype_t ga)
74 /* Atom types are always case sensitive */
75 for (i=0; (i<ga->nr); i++)
76 if (strcmp(str,*(ga->atomname[i])) == 0)
82 int get_atomtype_ntypes(gpp_atomtype_t ga)
87 char *get_atomtype_name(int nt, gpp_atomtype_t ga)
89 if ((nt < 0) || (nt >= ga->nr))
92 return *(ga->atomname[nt]);
95 real get_atomtype_massA(int nt,gpp_atomtype_t ga)
97 if ((nt < 0) || (nt >= ga->nr))
100 return ga->atom[nt].m;
103 real get_atomtype_massB(int nt,gpp_atomtype_t ga)
105 if ((nt < 0) || (nt >= ga->nr))
108 return ga->atom[nt].mB;
111 real get_atomtype_qA(int nt,gpp_atomtype_t ga)
113 if ((nt < 0) || (nt >= ga->nr))
116 return ga->atom[nt].q;
119 real get_atomtype_qB(int nt,gpp_atomtype_t ga)
121 if ((nt < 0) || (nt >= ga->nr))
124 return ga->atom[nt].qB;
127 int get_atomtype_ptype(int nt,gpp_atomtype_t ga)
129 if ((nt < 0) || (nt >= ga->nr))
132 return ga->atom[nt].ptype;
135 int get_atomtype_batype(int nt,gpp_atomtype_t ga)
137 if ((nt < 0) || (nt >= ga->nr))
140 return ga->bondatomtype[nt];
143 int get_atomtype_atomnumber(int nt,gpp_atomtype_t ga)
145 if ((nt < 0) || (nt >= ga->nr))
148 return ga->atomnumber[nt];
151 real get_atomtype_radius(int nt,gpp_atomtype_t ga)
153 if ((nt < 0) || (nt >= ga->nr))
156 return ga->radius[nt];
159 real get_atomtype_vol(int nt,gpp_atomtype_t ga)
161 if ((nt < 0) || (nt >= ga->nr))
167 real get_atomtype_surftens(int nt,gpp_atomtype_t ga)
169 if ((nt < 0) || (nt >= ga->nr))
172 return ga->surftens[nt];
175 real get_atomtype_gb_radius(int nt,gpp_atomtype_t ga)
177 if ((nt < 0) || (nt >= ga->nr))
180 return ga->gb_radius[nt];
183 real get_atomtype_S_hct(int nt,gpp_atomtype_t ga)
185 if ((nt < 0) || (nt >= ga->nr))
188 return ga->S_hct[nt];
191 real get_atomtype_nbparam(int nt,int param,gpp_atomtype_t ga)
193 if ((nt < 0) || (nt >= ga->nr))
195 if ((param < 0) || (param >= MAXFORCEPARAM))
197 return ga->nb[nt].c[param];
200 gpp_atomtype_t init_atomtype(void)
210 ga->bondatomtype = NULL;
214 ga->atomnumber = NULL;
215 ga->gb_radius = NULL;
222 set_atomtype_gbparam(gpp_atomtype_t ga, int i,
223 real radius,real vol,real surftens,
224 real gb_radius, real S_hct)
226 if ( (i < 0) || (i>= ga->nr))
229 ga->radius[i] = radius;
231 ga->surftens[i] = surftens;
232 ga->gb_radius[i] = gb_radius;
233 ga->S_hct[i] = S_hct;
239 int set_atomtype(int nt,gpp_atomtype_t ga,t_symtab *tab,
240 t_atom *a,const char *name,t_param *nb,
242 real radius,real vol,real surftens,int atomnumber,
243 real gb_radius, real S_hct)
245 if ((nt < 0) || (nt >= ga->nr))
249 ga->atomname[nt] = put_symtab(tab,name);
251 ga->bondatomtype[nt] = bondatomtype;
252 ga->radius[nt] = radius;
254 ga->surftens[nt] = surftens;
255 ga->atomnumber[nt] = atomnumber;
256 ga->gb_radius[nt] = gb_radius;
257 ga->S_hct[nt] = S_hct;
262 int add_atomtype(gpp_atomtype_t ga,t_symtab *tab,
263 t_atom *a,const char *name,t_param *nb,
265 real radius,real vol,real surftens,real atomnumber,
266 real gb_radius, real S_hct)
270 for(i=0; (i<ga->nr); i++) {
271 if (strcmp(*ga->atomname[i],name) == 0) {
273 fprintf(debug,"Trying to add atomtype %s again. Skipping it.\n",name);
279 srenew(ga->atom,ga->nr);
280 srenew(ga->atomname,ga->nr);
281 srenew(ga->nb,ga->nr);
282 srenew(ga->bondatomtype,ga->nr);
283 srenew(ga->radius,ga->nr);
284 srenew(ga->vol,ga->nr);
285 srenew(ga->surftens,ga->nr);
286 srenew(ga->atomnumber,ga->nr);
287 srenew(ga->gb_radius,ga->nr);
288 srenew(ga->S_hct,ga->nr);
290 return set_atomtype(ga->nr-1,ga,tab,a,name,nb,bondatomtype,radius,
291 vol,surftens,atomnumber,gb_radius,S_hct);
297 void print_at (FILE * out, gpp_atomtype_t ga)
300 t_atom *atom = ga->atom;
301 t_param *nb = ga->nb;
303 fprintf (out,"[ %s ]\n",dir2str(d_atomtypes));
304 fprintf (out,"; %6s %8s %8s %8s %12s %12s\n",
305 "type","mass","charge","particle","c6","c12");
306 for (i=0; (i<ga->nr); i++)
307 fprintf(out,"%8s %8.3f %8.3f %8s %12e %12e\n",
308 *(ga->atomname[i]),atom[i].m,atom[i].q,"A",
314 void done_atomtype(gpp_atomtype_t ga)
319 sfree(ga->bondatomtype);
322 sfree(ga->gb_radius);
325 sfree(ga->atomnumber);
331 static int search_atomtypes(gpp_atomtype_t ga,int *n,int typelist[],
333 t_param param[],int ftype)
335 int i,nn,nrfp,j,k,ntype,tli;
336 gmx_bool bFound=FALSE;
340 ntype = get_atomtype_ntypes(ga);
342 for(i=0; (i<nn); i++)
344 if (typelist[i] == thistype)
346 /* This type number has already been added */
350 /* Otherwise, check if the parameters are identical to any previously added type */
353 for(j=0;j<ntype && bFound;j++)
355 /* Check nonbonded parameters */
356 for(k=0;k<nrfp && bFound;k++)
358 bFound=(param[ntype*typelist[i]+j].c[k]==param[ntype*thistype+j].c[k]);
361 /* Check radius, volume, surftens */
364 (get_atomtype_radius(tli,ga) == get_atomtype_radius(thistype,ga)) &&
365 (get_atomtype_vol(tli,ga) == get_atomtype_vol(thistype,ga)) &&
366 (get_atomtype_surftens(tli,ga) == get_atomtype_surftens(thistype,ga)) &&
367 (get_atomtype_atomnumber(tli,ga) == get_atomtype_atomnumber(thistype,ga)) &&
368 (get_atomtype_gb_radius(tli,ga) == get_atomtype_gb_radius(thistype,ga)) &&
369 (get_atomtype_S_hct(tli,ga) == get_atomtype_S_hct(thistype,ga));
379 fprintf(debug,"Renumbering atomtype %d to %d\n",thistype,nn);
381 gmx_fatal(FARGS,"Atomtype horror n = %d, %s, %d",nn,__FILE__,__LINE__);
382 typelist[nn]=thistype;
390 void renum_atype(t_params plist[],gmx_mtop_t *mtop,
392 gpp_atomtype_t ga,gmx_bool bVerbose)
394 int i,j,k,l,molt,mi,mj,nat,nrfp,ftype,ntype;
404 char ***new_atomname;
406 ntype = get_atomtype_ntypes(ga);
407 snew(typelist,ntype);
410 fprintf(stderr,"renumbering atomtypes...\n");
412 /* Since the bonded interactions have been assigned now,
413 * we want to reduce the number of atom types by merging
414 * ones with identical nonbonded interactions, in addition
415 * to removing unused ones.
417 * With Generalized-Born electrostatics, or implicit solvent
418 * we also check that the atomtype radius, effective_volume
419 * and surface tension match.
421 * With QM/MM we also check that the atom numbers match
424 /* Get nonbonded interaction type */
425 if (plist[F_LJ].nr > 0)
430 /* Renumber atomtypes by first making a list of which ones are actually used.
431 * We provide the list of nonbonded parameters so search_atomtypes
432 * can determine if two types should be merged.
435 for(molt=0; molt<mtop->nmoltype; molt++) {
436 atoms = &mtop->moltype[molt].atoms;
437 for(i=0; (i<atoms->nr); i++) {
438 atoms->atom[i].type =
439 search_atomtypes(ga,&nat,typelist,atoms->atom[i].type,
440 plist[ftype].param,ftype);
441 atoms->atom[i].typeB=
442 search_atomtypes(ga,&nat,typelist,atoms->atom[i].typeB,
443 plist[ftype].param,ftype);
448 if (wall_atomtype[i] >= 0)
449 wall_atomtype[i] = search_atomtypes(ga,&nat,typelist,wall_atomtype[i],
450 plist[ftype].param,ftype);
453 snew(new_radius,nat);
455 snew(new_surftens,nat);
456 snew(new_atomnumber,nat);
457 snew(new_gb_radius,nat);
459 snew(new_atomname,nat);
461 /* We now have a list of unique atomtypes in typelist */
464 pr_ivec(debug,0,"typelist",typelist,nat,TRUE);
468 snew(nbsnew,plist[ftype].nr);
472 for(i=k=0; (i<nat); i++)
475 for(j=0; (j<nat); j++,k++)
478 for(l=0; (l<nrfp); l++)
480 nbsnew[k].c[l]=plist[ftype].param[ntype*mi+mj].c[l];
483 new_radius[i] = get_atomtype_radius(mi,ga);
484 new_vol[i] = get_atomtype_vol(mi,ga);
485 new_surftens[i] = get_atomtype_surftens(mi,ga);
486 new_atomnumber[i] = get_atomtype_atomnumber(mi,ga);
487 new_gb_radius[i] = get_atomtype_gb_radius(mi,ga);
488 new_S_hct[i] = get_atomtype_S_hct(mi,ga);
489 new_atomname[i] = ga->atomname[mi];
492 for(i=0; (i<nat*nat); i++) {
493 for(l=0; (l<nrfp); l++)
494 plist[ftype].param[i].c[l]=nbsnew[i].c[l];
497 mtop->ffparams.atnr = nat;
502 sfree(ga->atomnumber);
503 sfree(ga->gb_radius);
505 /* Dangling atomname pointers ? */
508 ga->radius = new_radius;
510 ga->surftens = new_surftens;
511 ga->atomnumber = new_atomnumber;
512 ga->gb_radius = new_gb_radius;
513 ga->S_hct = new_S_hct;
514 ga->atomname = new_atomname;
522 void copy_atomtype_atomtypes(gpp_atomtype_t ga,t_atomtypes *atomtypes)
526 /* Copy the atomtype data to the topology atomtype list */
527 ntype = get_atomtype_ntypes(ga);
529 snew(atomtypes->radius,ntype);
530 snew(atomtypes->vol,ntype);
531 snew(atomtypes->surftens,ntype);
532 snew(atomtypes->atomnumber,ntype);
533 snew(atomtypes->gb_radius,ntype);
534 snew(atomtypes->S_hct,ntype);
536 for(i=0; i<ntype; i++) {
537 atomtypes->radius[i] = ga->radius[i];
538 atomtypes->vol[i] = ga->vol[i];
539 atomtypes->surftens[i] = ga->surftens[i];
540 atomtypes->atomnumber[i] = ga->atomnumber[i];
541 atomtypes->gb_radius[i] = ga->gb_radius[i];
542 atomtypes->S_hct[i] = ga->S_hct[i];