3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
49 #include "gmx_fatal.h"
51 #include "gpp_atomtype.h"
53 typedef struct gpp_atomtype {
54 int nr; /* The number of atomtypes */
55 t_atom *atom; /* Array of atoms */
56 char ***atomname; /* Names of the atomtypes */
57 t_param *nb; /* Nonbonded force default params */
58 int *bondatomtype; /* The bond_atomtype for each atomtype */
59 real *radius; /* Radius for GBSA stuff */
60 real *vol; /* Effective volume for GBSA */
61 real *surftens; /* Surface tension with water, for GBSA */
62 real *gb_radius; /* Radius for Still model */
63 real *S_hct; /* Overlap factor for HCT model */
64 int *atomnumber; /* Atomic number, used for QM/MM */
67 int get_atomtype_type(const char *str, gpp_atomtype_t ga)
71 /* Atom types are always case sensitive */
72 for (i = 0; (i < ga->nr); i++)
74 if (strcmp(str, *(ga->atomname[i])) == 0)
83 int get_atomtype_ntypes(gpp_atomtype_t ga)
88 char *get_atomtype_name(int nt, gpp_atomtype_t ga)
90 if ((nt < 0) || (nt >= ga->nr))
95 return *(ga->atomname[nt]);
98 real get_atomtype_massA(int nt, gpp_atomtype_t ga)
100 if ((nt < 0) || (nt >= ga->nr))
105 return ga->atom[nt].m;
108 real get_atomtype_massB(int nt, gpp_atomtype_t ga)
110 if ((nt < 0) || (nt >= ga->nr))
115 return ga->atom[nt].mB;
118 real get_atomtype_qA(int nt, gpp_atomtype_t ga)
120 if ((nt < 0) || (nt >= ga->nr))
125 return ga->atom[nt].q;
128 real get_atomtype_qB(int nt, gpp_atomtype_t ga)
130 if ((nt < 0) || (nt >= ga->nr))
135 return ga->atom[nt].qB;
138 int get_atomtype_ptype(int nt, gpp_atomtype_t ga)
140 if ((nt < 0) || (nt >= ga->nr))
145 return ga->atom[nt].ptype;
148 int get_atomtype_batype(int nt, gpp_atomtype_t ga)
150 if ((nt < 0) || (nt >= ga->nr))
155 return ga->bondatomtype[nt];
158 int get_atomtype_atomnumber(int nt, gpp_atomtype_t ga)
160 if ((nt < 0) || (nt >= ga->nr))
165 return ga->atomnumber[nt];
168 real get_atomtype_radius(int nt, gpp_atomtype_t ga)
170 if ((nt < 0) || (nt >= ga->nr))
175 return ga->radius[nt];
178 real get_atomtype_vol(int nt, gpp_atomtype_t ga)
180 if ((nt < 0) || (nt >= ga->nr))
188 real get_atomtype_surftens(int nt, gpp_atomtype_t ga)
190 if ((nt < 0) || (nt >= ga->nr))
195 return ga->surftens[nt];
198 real get_atomtype_gb_radius(int nt, gpp_atomtype_t ga)
200 if ((nt < 0) || (nt >= ga->nr))
205 return ga->gb_radius[nt];
208 real get_atomtype_S_hct(int nt, gpp_atomtype_t ga)
210 if ((nt < 0) || (nt >= ga->nr))
215 return ga->S_hct[nt];
218 real get_atomtype_nbparam(int nt, int param, gpp_atomtype_t ga)
220 if ((nt < 0) || (nt >= ga->nr))
224 if ((param < 0) || (param >= MAXFORCEPARAM))
228 return ga->nb[nt].c[param];
231 gpp_atomtype_t init_atomtype(void)
241 ga->bondatomtype = NULL;
245 ga->atomnumber = NULL;
246 ga->gb_radius = NULL;
253 set_atomtype_gbparam(gpp_atomtype_t ga, int i,
254 real radius, real vol, real surftens,
255 real gb_radius, real S_hct)
257 if ( (i < 0) || (i >= ga->nr))
262 ga->radius[i] = radius;
264 ga->surftens[i] = surftens;
265 ga->gb_radius[i] = gb_radius;
266 ga->S_hct[i] = S_hct;
272 int set_atomtype(int nt, gpp_atomtype_t ga, t_symtab *tab,
273 t_atom *a, const char *name, t_param *nb,
275 real radius, real vol, real surftens, int atomnumber,
276 real gb_radius, real S_hct)
278 if ((nt < 0) || (nt >= ga->nr))
284 ga->atomname[nt] = put_symtab(tab, name);
286 ga->bondatomtype[nt] = bondatomtype;
287 ga->radius[nt] = radius;
289 ga->surftens[nt] = surftens;
290 ga->atomnumber[nt] = atomnumber;
291 ga->gb_radius[nt] = gb_radius;
292 ga->S_hct[nt] = S_hct;
297 int add_atomtype(gpp_atomtype_t ga, t_symtab *tab,
298 t_atom *a, const char *name, t_param *nb,
300 real radius, real vol, real surftens, real atomnumber,
301 real gb_radius, real S_hct)
305 for (i = 0; (i < ga->nr); i++)
307 if (strcmp(*ga->atomname[i], name) == 0)
311 fprintf(debug, "Trying to add atomtype %s again. Skipping it.\n", name);
319 srenew(ga->atom, ga->nr);
320 srenew(ga->atomname, ga->nr);
321 srenew(ga->nb, ga->nr);
322 srenew(ga->bondatomtype, ga->nr);
323 srenew(ga->radius, ga->nr);
324 srenew(ga->vol, ga->nr);
325 srenew(ga->surftens, ga->nr);
326 srenew(ga->atomnumber, ga->nr);
327 srenew(ga->gb_radius, ga->nr);
328 srenew(ga->S_hct, ga->nr);
330 return set_atomtype(ga->nr-1, ga, tab, a, name, nb, bondatomtype, radius,
331 vol, surftens, atomnumber, gb_radius, S_hct);
339 void print_at (FILE * out, gpp_atomtype_t ga)
342 t_atom *atom = ga->atom;
343 t_param *nb = ga->nb;
345 fprintf (out, "[ %s ]\n", dir2str(d_atomtypes));
346 fprintf (out, "; %6s %8s %8s %8s %12s %12s\n",
347 "type", "mass", "charge", "particle", "c6", "c12");
348 for (i = 0; (i < ga->nr); i++)
350 fprintf(out, "%8s %8.3f %8.3f %8s %12e %12e\n",
351 *(ga->atomname[i]), atom[i].m, atom[i].q, "A",
358 void done_atomtype(gpp_atomtype_t ga)
363 sfree(ga->bondatomtype);
366 sfree(ga->gb_radius);
369 sfree(ga->atomnumber);
375 static int search_atomtypes(gpp_atomtype_t ga, int *n, int typelist[],
377 t_param param[], int ftype)
379 int i, nn, nrfp, j, k, ntype, tli;
380 gmx_bool bFound = FALSE;
384 ntype = get_atomtype_ntypes(ga);
386 for (i = 0; (i < nn); i++)
388 if (typelist[i] == thistype)
390 /* This type number has already been added */
394 /* Otherwise, check if the parameters are identical to any previously added type */
397 for (j = 0; j < ntype && bFound; j++)
399 /* Check nonbonded parameters */
400 for (k = 0; k < nrfp && bFound; k++)
402 bFound = (param[ntype*typelist[i]+j].c[k] == param[ntype*thistype+j].c[k]);
405 /* Check radius, volume, surftens */
408 (get_atomtype_radius(tli, ga) == get_atomtype_radius(thistype, ga)) &&
409 (get_atomtype_vol(tli, ga) == get_atomtype_vol(thistype, ga)) &&
410 (get_atomtype_surftens(tli, ga) == get_atomtype_surftens(thistype, ga)) &&
411 (get_atomtype_atomnumber(tli, ga) == get_atomtype_atomnumber(thistype, ga)) &&
412 (get_atomtype_gb_radius(tli, ga) == get_atomtype_gb_radius(thistype, ga)) &&
413 (get_atomtype_S_hct(tli, ga) == get_atomtype_S_hct(thistype, ga));
425 fprintf(debug, "Renumbering atomtype %d to %d\n", thistype, nn);
429 gmx_fatal(FARGS, "Atomtype horror n = %d, %s, %d", nn, __FILE__, __LINE__);
431 typelist[nn] = thistype;
439 void renum_atype(t_params plist[], gmx_mtop_t *mtop,
441 gpp_atomtype_t ga, gmx_bool bVerbose)
443 int i, j, k, l, molt, mi, mj, nat, nrfp, ftype, ntype;
453 char ***new_atomname;
455 ntype = get_atomtype_ntypes(ga);
456 snew(typelist, ntype);
460 fprintf(stderr, "renumbering atomtypes...\n");
463 /* Since the bonded interactions have been assigned now,
464 * we want to reduce the number of atom types by merging
465 * ones with identical nonbonded interactions, in addition
466 * to removing unused ones.
468 * With Generalized-Born electrostatics, or implicit solvent
469 * we also check that the atomtype radius, effective_volume
470 * and surface tension match.
472 * With QM/MM we also check that the atom numbers match
475 /* Get nonbonded interaction type */
476 if (plist[F_LJ].nr > 0)
485 /* Renumber atomtypes by first making a list of which ones are actually used.
486 * We provide the list of nonbonded parameters so search_atomtypes
487 * can determine if two types should be merged.
490 for (molt = 0; molt < mtop->nmoltype; molt++)
492 atoms = &mtop->moltype[molt].atoms;
493 for (i = 0; (i < atoms->nr); i++)
495 atoms->atom[i].type =
496 search_atomtypes(ga, &nat, typelist, atoms->atom[i].type,
497 plist[ftype].param, ftype);
498 atoms->atom[i].typeB =
499 search_atomtypes(ga, &nat, typelist, atoms->atom[i].typeB,
500 plist[ftype].param, ftype);
504 for (i = 0; i < 2; i++)
506 if (wall_atomtype[i] >= 0)
508 wall_atomtype[i] = search_atomtypes(ga, &nat, typelist, wall_atomtype[i],
509 plist[ftype].param, ftype);
513 snew(new_radius, nat);
515 snew(new_surftens, nat);
516 snew(new_atomnumber, nat);
517 snew(new_gb_radius, nat);
518 snew(new_S_hct, nat);
519 snew(new_atomname, nat);
521 /* We now have a list of unique atomtypes in typelist */
525 pr_ivec(debug, 0, "typelist", typelist, nat, TRUE);
530 snew(nbsnew, plist[ftype].nr);
534 for (i = k = 0; (i < nat); i++)
537 for (j = 0; (j < nat); j++, k++)
540 for (l = 0; (l < nrfp); l++)
542 nbsnew[k].c[l] = plist[ftype].param[ntype*mi+mj].c[l];
545 new_radius[i] = get_atomtype_radius(mi, ga);
546 new_vol[i] = get_atomtype_vol(mi, ga);
547 new_surftens[i] = get_atomtype_surftens(mi, ga);
548 new_atomnumber[i] = get_atomtype_atomnumber(mi, ga);
549 new_gb_radius[i] = get_atomtype_gb_radius(mi, ga);
550 new_S_hct[i] = get_atomtype_S_hct(mi, ga);
551 new_atomname[i] = ga->atomname[mi];
554 for (i = 0; (i < nat*nat); i++)
556 for (l = 0; (l < nrfp); l++)
558 plist[ftype].param[i].c[l] = nbsnew[i].c[l];
562 mtop->ffparams.atnr = nat;
567 sfree(ga->atomnumber);
568 sfree(ga->gb_radius);
570 /* Dangling atomname pointers ? */
573 ga->radius = new_radius;
575 ga->surftens = new_surftens;
576 ga->atomnumber = new_atomnumber;
577 ga->gb_radius = new_gb_radius;
578 ga->S_hct = new_S_hct;
579 ga->atomname = new_atomname;
587 void copy_atomtype_atomtypes(gpp_atomtype_t ga, t_atomtypes *atomtypes)
591 /* Copy the atomtype data to the topology atomtype list */
592 ntype = get_atomtype_ntypes(ga);
593 atomtypes->nr = ntype;
594 snew(atomtypes->radius, ntype);
595 snew(atomtypes->vol, ntype);
596 snew(atomtypes->surftens, ntype);
597 snew(atomtypes->atomnumber, ntype);
598 snew(atomtypes->gb_radius, ntype);
599 snew(atomtypes->S_hct, ntype);
601 for (i = 0; i < ntype; i++)
603 atomtypes->radius[i] = ga->radius[i];
604 atomtypes->vol[i] = ga->vol[i];
605 atomtypes->surftens[i] = ga->surftens[i];
606 atomtypes->atomnumber[i] = ga->atomnumber[i];
607 atomtypes->gb_radius[i] = ga->gb_radius[i];
608 atomtypes->S_hct[i] = ga->S_hct[i];