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.
39 #include "gpp_atomtype.h"
44 #include "gromacs/gmxpreprocess/topdirs.h"
45 #include "gromacs/gmxpreprocess/toputil.h"
46 #include "gromacs/legacyheaders/txtdump.h"
47 #include "gromacs/topology/symtab.h"
48 #include "gromacs/utility/fatalerror.h"
49 #include "gromacs/utility/smalloc.h"
51 typedef struct gpp_atomtype {
52 int nr; /* The number of atomtypes */
53 t_atom *atom; /* Array of atoms */
54 char ***atomname; /* Names of the atomtypes */
55 t_param *nb; /* Nonbonded force default params */
56 int *bondatomtype; /* The bond_atomtype for each atomtype */
57 real *radius; /* Radius for GBSA stuff */
58 real *vol; /* Effective volume for GBSA */
59 real *surftens; /* Surface tension with water, for GBSA */
60 real *gb_radius; /* Radius for Still model */
61 real *S_hct; /* Overlap factor for HCT model */
62 int *atomnumber; /* Atomic number, used for QM/MM */
65 int get_atomtype_type(const char *str, gpp_atomtype_t ga)
69 /* Atom types are always case sensitive */
70 for (i = 0; (i < ga->nr); i++)
72 if (strcmp(str, *(ga->atomname[i])) == 0)
81 int get_atomtype_ntypes(gpp_atomtype_t ga)
86 char *get_atomtype_name(int nt, gpp_atomtype_t ga)
88 if ((nt < 0) || (nt >= ga->nr))
93 return *(ga->atomname[nt]);
96 real get_atomtype_massA(int nt, gpp_atomtype_t ga)
98 if ((nt < 0) || (nt >= ga->nr))
103 return ga->atom[nt].m;
106 real get_atomtype_massB(int nt, gpp_atomtype_t ga)
108 if ((nt < 0) || (nt >= ga->nr))
113 return ga->atom[nt].mB;
116 real get_atomtype_qA(int nt, gpp_atomtype_t ga)
118 if ((nt < 0) || (nt >= ga->nr))
123 return ga->atom[nt].q;
126 real get_atomtype_qB(int nt, gpp_atomtype_t ga)
128 if ((nt < 0) || (nt >= ga->nr))
133 return ga->atom[nt].qB;
136 int get_atomtype_ptype(int nt, gpp_atomtype_t ga)
138 if ((nt < 0) || (nt >= ga->nr))
143 return ga->atom[nt].ptype;
146 int get_atomtype_batype(int nt, gpp_atomtype_t ga)
148 if ((nt < 0) || (nt >= ga->nr))
153 return ga->bondatomtype[nt];
156 int get_atomtype_atomnumber(int nt, gpp_atomtype_t ga)
158 if ((nt < 0) || (nt >= ga->nr))
163 return ga->atomnumber[nt];
166 real get_atomtype_radius(int nt, gpp_atomtype_t ga)
168 if ((nt < 0) || (nt >= ga->nr))
173 return ga->radius[nt];
176 real get_atomtype_vol(int nt, gpp_atomtype_t ga)
178 if ((nt < 0) || (nt >= ga->nr))
186 real get_atomtype_surftens(int nt, gpp_atomtype_t ga)
188 if ((nt < 0) || (nt >= ga->nr))
193 return ga->surftens[nt];
196 real get_atomtype_gb_radius(int nt, gpp_atomtype_t ga)
198 if ((nt < 0) || (nt >= ga->nr))
203 return ga->gb_radius[nt];
206 real get_atomtype_S_hct(int nt, gpp_atomtype_t ga)
208 if ((nt < 0) || (nt >= ga->nr))
213 return ga->S_hct[nt];
216 real get_atomtype_nbparam(int nt, int param, gpp_atomtype_t ga)
218 if ((nt < 0) || (nt >= ga->nr))
222 if ((param < 0) || (param >= MAXFORCEPARAM))
226 return ga->nb[nt].c[param];
229 gpp_atomtype_t init_atomtype(void)
239 ga->bondatomtype = NULL;
243 ga->atomnumber = NULL;
244 ga->gb_radius = NULL;
251 set_atomtype_gbparam(gpp_atomtype_t ga, int i,
252 real radius, real vol, real surftens,
253 real gb_radius, real S_hct)
255 if ( (i < 0) || (i >= ga->nr))
260 ga->radius[i] = radius;
262 ga->surftens[i] = surftens;
263 ga->gb_radius[i] = gb_radius;
264 ga->S_hct[i] = S_hct;
270 int set_atomtype(int nt, gpp_atomtype_t ga, t_symtab *tab,
271 t_atom *a, const char *name, t_param *nb,
273 real radius, real vol, real surftens, int atomnumber,
274 real gb_radius, real S_hct)
276 if ((nt < 0) || (nt >= ga->nr))
282 ga->atomname[nt] = put_symtab(tab, name);
284 ga->bondatomtype[nt] = bondatomtype;
285 ga->radius[nt] = radius;
287 ga->surftens[nt] = surftens;
288 ga->atomnumber[nt] = atomnumber;
289 ga->gb_radius[nt] = gb_radius;
290 ga->S_hct[nt] = S_hct;
295 int add_atomtype(gpp_atomtype_t ga, t_symtab *tab,
296 t_atom *a, const char *name, t_param *nb,
298 real radius, real vol, real surftens, real atomnumber,
299 real gb_radius, real S_hct)
303 for (i = 0; (i < ga->nr); i++)
305 if (strcmp(*ga->atomname[i], name) == 0)
309 fprintf(debug, "Trying to add atomtype %s again. Skipping it.\n", name);
317 srenew(ga->atom, ga->nr);
318 srenew(ga->atomname, ga->nr);
319 srenew(ga->nb, ga->nr);
320 srenew(ga->bondatomtype, ga->nr);
321 srenew(ga->radius, ga->nr);
322 srenew(ga->vol, ga->nr);
323 srenew(ga->surftens, ga->nr);
324 srenew(ga->atomnumber, ga->nr);
325 srenew(ga->gb_radius, ga->nr);
326 srenew(ga->S_hct, ga->nr);
328 return set_atomtype(ga->nr-1, ga, tab, a, name, nb, bondatomtype, radius,
329 vol, surftens, atomnumber, gb_radius, S_hct);
337 void print_at (FILE * out, gpp_atomtype_t ga)
340 t_atom *atom = ga->atom;
341 t_param *nb = ga->nb;
343 fprintf (out, "[ %s ]\n", dir2str(d_atomtypes));
344 fprintf (out, "; %6s %8s %8s %8s %12s %12s\n",
345 "type", "mass", "charge", "particle", "c6", "c12");
346 for (i = 0; (i < ga->nr); i++)
348 fprintf(out, "%8s %8.3f %8.3f %8s %12e %12e\n",
349 *(ga->atomname[i]), atom[i].m, atom[i].q, "A",
356 void done_atomtype(gpp_atomtype_t ga)
361 sfree(ga->bondatomtype);
364 sfree(ga->gb_radius);
367 sfree(ga->atomnumber);
372 static int search_atomtypes(gpp_atomtype_t ga, int *n, int typelist[],
374 t_param param[], int ftype)
376 int i, nn, nrfp, j, k, ntype, tli;
377 gmx_bool bFound = FALSE;
381 ntype = get_atomtype_ntypes(ga);
383 for (i = 0; (i < nn); i++)
385 if (typelist[i] == thistype)
387 /* This type number has already been added */
391 /* Otherwise, check if the parameters are identical to any previously added type */
394 for (j = 0; j < ntype && bFound; j++)
396 /* Check nonbonded parameters */
397 for (k = 0; k < nrfp && bFound; k++)
399 bFound = (param[ntype*typelist[i]+j].c[k] == param[ntype*thistype+j].c[k]);
402 /* Check radius, volume, surftens */
405 (get_atomtype_radius(tli, ga) == get_atomtype_radius(thistype, ga)) &&
406 (get_atomtype_vol(tli, ga) == get_atomtype_vol(thistype, ga)) &&
407 (get_atomtype_surftens(tli, ga) == get_atomtype_surftens(thistype, ga)) &&
408 (get_atomtype_atomnumber(tli, ga) == get_atomtype_atomnumber(thistype, ga)) &&
409 (get_atomtype_gb_radius(tli, ga) == get_atomtype_gb_radius(thistype, ga)) &&
410 (get_atomtype_S_hct(tli, ga) == get_atomtype_S_hct(thistype, ga));
422 fprintf(debug, "Renumbering atomtype %d to %d\n", thistype, nn);
426 gmx_fatal(FARGS, "Atomtype horror n = %d, %s, %d", nn, __FILE__, __LINE__);
428 typelist[nn] = thistype;
436 void renum_atype(t_params plist[], gmx_mtop_t *mtop,
438 gpp_atomtype_t ga, gmx_bool bVerbose)
440 int i, j, k, l, molt, mi, mj, nat, nrfp, ftype, ntype;
450 char ***new_atomname;
452 ntype = get_atomtype_ntypes(ga);
453 snew(typelist, ntype);
457 fprintf(stderr, "renumbering atomtypes...\n");
460 /* Since the bonded interactions have been assigned now,
461 * we want to reduce the number of atom types by merging
462 * ones with identical nonbonded interactions, in addition
463 * to removing unused ones.
465 * With Generalized-Born electrostatics, or implicit solvent
466 * we also check that the atomtype radius, effective_volume
467 * and surface tension match.
469 * With QM/MM we also check that the atom numbers match
472 /* Get nonbonded interaction type */
473 if (plist[F_LJ].nr > 0)
482 /* Renumber atomtypes by first making a list of which ones are actually used.
483 * We provide the list of nonbonded parameters so search_atomtypes
484 * can determine if two types should be merged.
487 for (molt = 0; molt < mtop->nmoltype; molt++)
489 atoms = &mtop->moltype[molt].atoms;
490 for (i = 0; (i < atoms->nr); i++)
492 atoms->atom[i].type =
493 search_atomtypes(ga, &nat, typelist, atoms->atom[i].type,
494 plist[ftype].param, ftype);
495 atoms->atom[i].typeB =
496 search_atomtypes(ga, &nat, typelist, atoms->atom[i].typeB,
497 plist[ftype].param, ftype);
501 for (i = 0; i < 2; i++)
503 if (wall_atomtype[i] >= 0)
505 wall_atomtype[i] = search_atomtypes(ga, &nat, typelist, wall_atomtype[i],
506 plist[ftype].param, ftype);
510 snew(new_radius, nat);
512 snew(new_surftens, nat);
513 snew(new_atomnumber, nat);
514 snew(new_gb_radius, nat);
515 snew(new_S_hct, nat);
516 snew(new_atomname, nat);
518 /* We now have a list of unique atomtypes in typelist */
522 pr_ivec(debug, 0, "typelist", typelist, nat, TRUE);
527 snew(nbsnew, plist[ftype].nr);
531 for (i = k = 0; (i < nat); i++)
534 for (j = 0; (j < nat); j++, k++)
537 for (l = 0; (l < nrfp); l++)
539 nbsnew[k].c[l] = plist[ftype].param[ntype*mi+mj].c[l];
542 new_radius[i] = get_atomtype_radius(mi, ga);
543 new_vol[i] = get_atomtype_vol(mi, ga);
544 new_surftens[i] = get_atomtype_surftens(mi, ga);
545 new_atomnumber[i] = get_atomtype_atomnumber(mi, ga);
546 new_gb_radius[i] = get_atomtype_gb_radius(mi, ga);
547 new_S_hct[i] = get_atomtype_S_hct(mi, ga);
548 new_atomname[i] = ga->atomname[mi];
551 for (i = 0; (i < nat*nat); i++)
553 for (l = 0; (l < nrfp); l++)
555 plist[ftype].param[i].c[l] = nbsnew[i].c[l];
559 mtop->ffparams.atnr = nat;
564 sfree(ga->atomnumber);
565 sfree(ga->gb_radius);
567 /* Dangling atomname pointers ? */
570 ga->radius = new_radius;
572 ga->surftens = new_surftens;
573 ga->atomnumber = new_atomnumber;
574 ga->gb_radius = new_gb_radius;
575 ga->S_hct = new_S_hct;
576 ga->atomname = new_atomname;
584 void copy_atomtype_atomtypes(gpp_atomtype_t ga, t_atomtypes *atomtypes)
588 /* Copy the atomtype data to the topology atomtype list */
589 ntype = get_atomtype_ntypes(ga);
590 atomtypes->nr = ntype;
591 snew(atomtypes->radius, ntype);
592 snew(atomtypes->vol, ntype);
593 snew(atomtypes->surftens, ntype);
594 snew(atomtypes->atomnumber, ntype);
595 snew(atomtypes->gb_radius, ntype);
596 snew(atomtypes->S_hct, ntype);
598 for (i = 0; i < ntype; i++)
600 atomtypes->radius[i] = ga->radius[i];
601 atomtypes->vol[i] = ga->vol[i];
602 atomtypes->surftens[i] = ga->surftens[i];
603 atomtypes->atomnumber[i] = ga->atomnumber[i];
604 atomtypes->gb_radius[i] = ga->gb_radius[i];
605 atomtypes->S_hct[i] = ga->S_hct[i];