4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
34 * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
53 #include "gmx_fatal.h"
54 #include "gpp_atomtype.h"
55 #include "gpp_bond_atomtype.h"
57 void generate_nbparams(int comb,int ftype,t_params *plist,t_atomtype atype)
61 real c,bi,bj,ci,cj,ci0,ci1,ci2,cj0,cj1,cj2;
64 /* Lean mean shortcuts */
65 nr = get_atomtype_ntypes(atype);
67 snew(plist->param,nr*nr);
70 /* Fill the matrix with force parameters */
76 for(i=k=0; (i<nr); i++) {
77 for(j=0; (j<nr); j++,k++) {
78 for(nf=0; (nf<nrfp); nf++) {
79 ci = get_atomtype_nbparam(i,nf,atype);
80 cj = get_atomtype_nbparam(j,nf,atype);
82 plist->param[k].c[nf] = c;
88 case eCOMB_ARITHMETIC:
89 /* c0 and c1 are epsilon and sigma */
90 for (i=k=0; (i < nr); i++)
91 for (j=0; (j < nr); j++,k++) {
92 ci0 = get_atomtype_nbparam(i,0,atype);
93 cj0 = get_atomtype_nbparam(j,0,atype);
94 ci1 = get_atomtype_nbparam(i,1,atype);
95 cj1 = get_atomtype_nbparam(j,1,atype);
96 plist->param[k].c[0] = (ci0+cj0)*0.5;
97 plist->param[k].c[1] = sqrt(ci1*cj1);
101 case eCOMB_GEOM_SIG_EPS:
102 /* c0 and c1 are epsilon and sigma */
103 for (i=k=0; (i < nr); i++)
104 for (j=0; (j < nr); j++,k++) {
105 ci0 = get_atomtype_nbparam(i,0,atype);
106 cj0 = get_atomtype_nbparam(j,0,atype);
107 ci1 = get_atomtype_nbparam(i,1,atype);
108 cj1 = get_atomtype_nbparam(j,1,atype);
109 plist->param[k].c[0] = sqrt(ci0*cj0);
110 plist->param[k].c[1] = sqrt(ci1*cj1);
115 gmx_fatal(FARGS,"No such combination rule %d",comb);
118 gmx_incons("Topology processing, generate nb parameters");
122 /* Buckingham rules */
123 for(i=k=0; (i<nr); i++)
124 for(j=0; (j<nr); j++,k++) {
125 ci0 = get_atomtype_nbparam(i,0,atype);
126 cj0 = get_atomtype_nbparam(j,0,atype);
127 ci2 = get_atomtype_nbparam(i,2,atype);
128 cj2 = get_atomtype_nbparam(j,2,atype);
129 bi = get_atomtype_nbparam(i,1,atype);
130 bj = get_atomtype_nbparam(j,1,atype);
131 plist->param[k].c[0] = sqrt(ci0 * cj0);
132 if ((bi == 0) || (bj == 0))
133 plist->param[k].c[1] = 0;
135 plist->param[k].c[1] = 2.0/(1/bi+1/bj);
136 plist->param[k].c[2] = sqrt(ci2 * cj2);
141 sprintf(errbuf,"Invalid nonbonded type %s",
142 interaction_function[ftype].longname);
143 warning_error(errbuf);
147 static void realloc_nb_params(t_atomtype at,
148 t_nbparam ***nbparam,t_nbparam ***pair)
150 /* Add space in the non-bonded parameters matrix */
151 int atnr = get_atomtype_ntypes(at);
152 srenew(*nbparam,atnr);
153 snew((*nbparam)[atnr-1],atnr);
156 snew((*pair)[atnr-1],atnr);
160 static void copy_B_from_A(int ftype,double *c)
164 nrfpA = NRFPA(ftype);
165 nrfpB = NRFPB(ftype);
167 /* Copy the B parameters from the first nrfpB A parameters */
168 for(i=0; (i<nrfpB); i++) {
173 void push_at (t_symtab *symtab, t_atomtype at, t_bond_atomtype bat,
174 char *line,int nb_funct,
175 t_nbparam ***nbparam,t_nbparam ***pair)
181 t_xlate xl[eptNR] = {
189 int nr,i,nfields,j,pt,nfp0=-1;
191 char type[STRLEN],btype[STRLEN],ptype[STRLEN];
193 double c[MAXFORCEPARAM];
194 double radius,vol,surftens,gb_radius,S_hct;
195 char tmpfield[12][100]; /* Max 12 fields of width 100 */
200 bool have_atomic_number;
201 bool have_bonded_type;
206 /* First assign input line to temporary array */
207 nfields=sscanf(line,"%s%s%s%s%s%s%s%s%s%s%s%s",
208 tmpfield[0],tmpfield[1],tmpfield[2],tmpfield[3],tmpfield[4],tmpfield[5],
209 tmpfield[6],tmpfield[7],tmpfield[8],tmpfield[9],tmpfield[10],tmpfield[11]);
211 /* Comments on optional fields in the atomtypes section:
213 * The force field format is getting a bit old. For OPLS-AA we needed
214 * to add a special bonded atomtype, and for Gerrit Groenhofs QM/MM stuff
215 * we also needed the atomic numbers.
216 * To avoid making all old or user-generated force fields unusable we
217 * have introduced both these quantities as optional columns, and do some
218 * acrobatics to check whether they are present or not.
219 * This will all look much nicer when we switch to XML... sigh.
221 * Field 0 (mandatory) is the nonbonded type name. (string)
222 * Field 1 (optional) is the bonded type (string)
223 * Field 2 (optional) is the atomic number (int)
224 * Field 3 (mandatory) is the mass (numerical)
225 * Field 4 (mandatory) is the charge (numerical)
226 * Field 5 (mandatory) is the particle type (single character)
227 * This is followed by a number of nonbonded parameters.
229 * The safest way to identify the format is the particle type field.
231 * So, here is what we do:
233 * A. Read in the first six fields as strings
234 * B. If field 3 (starting from 0) is a single char, we have neither
235 * bonded_type or atomic numbers.
236 * C. If field 5 is a single char we have both.
237 * D. If field 4 is a single char we check field 1. If this begins with
238 * an alphabetical character we have bonded types, otherwise atomic numbers.
247 if( (strlen(tmpfield[5])==1) && isalpha(tmpfield[5][0]) )
249 have_bonded_type = TRUE;
250 have_atomic_number = TRUE;
252 else if( (strlen(tmpfield[3])==1) && isalpha(tmpfield[3][0]) )
254 have_bonded_type = FALSE;
255 have_atomic_number = FALSE;
259 have_bonded_type = ( isalpha(tmpfield[1][0]) != 0 );
260 have_atomic_number = !have_bonded_type;
263 /* optional fields */
276 if( have_atomic_number )
278 if ( have_bonded_type )
280 nread = sscanf(line,"%s%s%d%lf%lf%s%lf%lf%lf%lf%lf%lf",
281 type,btype,&atomnr,&m,&q,ptype,&c[0],&c[1],
282 &radius,&vol,&surftens,&gb_radius);
291 /* have_atomic_number && !have_bonded_type */
292 nread = sscanf(line,"%s%d%lf%lf%s%lf%lf%lf%lf%lf%lf",
293 type,&atomnr,&m,&q,ptype,&c[0],&c[1],
294 &radius,&vol,&surftens,&gb_radius);
304 if ( have_bonded_type )
306 /* !have_atomic_number && have_bonded_type */
307 nread = sscanf(line,"%s%s%lf%lf%s%lf%lf%lf%lf%lf%lf",
308 type,btype,&m,&q,ptype,&c[0],&c[1],
309 &radius,&vol,&surftens,&gb_radius);
318 /* !have_atomic_number && !have_bonded_type */
319 nread = sscanf(line,"%s%lf%lf%s%lf%lf%lf%lf%lf%lf",
320 type,&m,&q,ptype,&c[0],&c[1],
321 &radius,&vol,&surftens,&gb_radius);
330 if( !have_bonded_type )
335 if( !have_atomic_number )
345 if( have_atomic_number )
347 if ( have_bonded_type )
349 nread = sscanf(line,"%s%s%d%lf%lf%s%lf%lf%lf%lf%lf%lf%lf",
350 type,btype,&atomnr,&m,&q,ptype,&c[0],&c[1],&c[2],
351 &radius,&vol,&surftens,&gb_radius);
360 /* have_atomic_number && !have_bonded_type */
361 nread = sscanf(line,"%s%d%lf%lf%s%lf%lf%lf%lf%lf%lf%lf",
362 type,&atomnr,&m,&q,ptype,&c[0],&c[1],&c[2],
363 &radius,&vol,&surftens,&gb_radius);
373 if ( have_bonded_type )
375 /* !have_atomic_number && have_bonded_type */
376 nread = sscanf(line,"%s%s%lf%lf%s%lf%lf%lf%lf%lf%lf%lf",
377 type,btype,&m,&q,ptype,&c[0],&c[1],&c[2],
378 &radius,&vol,&surftens,&gb_radius);
387 /* !have_atomic_number && !have_bonded_type */
388 nread = sscanf(line,"%s%lf%lf%s%lf%lf%lf%lf%lf%lf%lf",
389 type,&m,&q,ptype,&c[0],&c[1],&c[2],
390 &radius,&vol,&surftens,&gb_radius);
399 if( !have_bonded_type )
404 if( !have_atomic_number )
412 gmx_fatal(FARGS,"Invalid function type %d in push_at %s %d",nb_funct,
415 for(j=nfp0; (j<MAXFORCEPARAM); j++)
418 if(strlen(type)==1 && isdigit(type[0]))
419 gmx_fatal(FARGS,"Atom type names can't be single digits.");
421 if(strlen(btype)==1 && isdigit(btype[0]))
422 gmx_fatal(FARGS,"Bond atom type names can't be single digits.");
424 /* Hack to read old topologies */
425 if (strcasecmp(ptype,"D") == 0)
427 for(j=0; (j<eptNR); j++)
428 if (strcasecmp(ptype,xl[j].entry) == 0)
431 gmx_fatal(FARGS,"Invalid particle type %s on line %s",
435 fprintf(debug,"ptype: %s\n",ptype_str[pt]);
440 for (i=0; (i<MAXFORCEPARAM); i++)
443 if ((batype_nr = get_bond_atomtype_type(btype,bat)) == NOTSET)
444 add_bond_atomtype(bat,symtab,btype);
445 batype_nr = get_bond_atomtype_type(btype,bat);
447 if ((nr = get_atomtype_type(type,at)) != NOTSET) {
448 sprintf(errbuf,"Overriding atomtype %s",type);
450 if ((nr = set_atomtype(nr,at,symtab,atom,type,param,batype_nr,
451 radius,vol,surftens,atomnr,gb_radius,S_hct)) == NOTSET)
452 gmx_fatal(FARGS,"Replacing atomtype %s failed",type);
454 else if ((nr = add_atomtype(at,symtab,atom,type,param,
455 batype_nr,radius,vol,
456 surftens,atomnr,gb_radius,S_hct)) == NOTSET)
457 gmx_fatal(FARGS,"Adding atomtype %s failed",type);
459 /* Add space in the non-bonded parameters matrix */
460 realloc_nb_params(at,nbparam,pair);
466 static void push_bondtype(t_params * bt,
474 bool bTest,bFound,bCont,bId;
476 int nrfp = NRFP(ftype);
479 /* If bAllowRepeat is TRUE, we allow multiple entries as long as they
480 are on directly _adjacent_ lines.
483 /* First check if our atomtypes are _identical_ (not reversed) to the previous
484 entry. If they are not identical we search for earlier duplicates. If they are
485 we can skip it, since we already searched for the first line
492 if(bAllowRepeat && nr>1)
494 for (j=0,bCont=TRUE; (j < nral); j++)
496 bCont=bCont && (b->a[j] == bt->param[nr-2].a[j]);
500 /* Search for earlier duplicates if this entry was not a continuation
501 from the previous line.
506 for (i=0; (i < nr); i++) {
508 for (j=0; (j < nral); j++)
509 bTest=(bTest && (b->a[j] == bt->param[i].a[j]));
512 for(j=0; (j<nral); j++)
513 bTest=(bTest && (b->a[nral-1-j] == bt->param[i].a[j]));
518 for (j=0; (j < nrfp); j++)
519 bId = bId && (bt->param[i].c[j] == b->c[j]);
521 sprintf(errbuf,"Overriding %s parameters.%s",
522 interaction_function[ftype].longname,
523 (ftype==F_PDIHS) ? "\nUse dihedraltype 4 to allow several multiplicity terms." : "");
525 fprintf(stderr," old:");
526 for (j=0; (j < nrfp); j++)
527 fprintf(stderr," %g",bt->param[i].c[j]);
528 fprintf(stderr," \n new: %s\n\n",line);
532 for (j=0; (j < nrfp); j++)
533 bt->param[i].c[j] = b->c[j];
542 /* fill the arrays up and down */
543 memcpy(bt->param[bt->nr].c, b->c,sizeof(b->c));
544 memcpy(bt->param[bt->nr].a, b->a,sizeof(b->a));
545 memcpy(bt->param[bt->nr+1].c,b->c,sizeof(b->c));
547 for (j=0; (j < nral); j++)
548 bt->param[bt->nr+1].a[j] = b->a[nral-1-j];
554 void push_bt(directive d,t_params bt[],int nral,
556 t_bond_atomtype bat,char *line)
558 const char *formal[MAXATOMLIST+1] = {
566 const char *formnl[MAXATOMLIST+1] = {
574 const char *formlf = "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf";
575 int i,ft,ftype,nn,nrfp,nrfpA,nrfpB;
577 char alc[MAXATOMLIST+1][20];
578 /* One force parameter more, so we can check if we read too many */
579 double c[MAXFORCEPARAM+1];
583 if ((bat && at) || (!bat && !at))
584 gmx_incons("You should pass either bat or at to push_bt");
586 /* Make format string (nral ints+functype) */
587 if ((nn=sscanf(line,formal[nral],
588 alc[0],alc[1],alc[2],alc[3],alc[4],alc[5])) != nral+1) {
589 sprintf(errbuf,"Not enough atomtypes (%d instead of %d)",nn-1,nral);
590 warning_error(errbuf);
594 ft = atoi(alc[nral]);
595 ftype = ifunc_index(d,ft);
597 nrfpA = interaction_function[ftype].nrfpA;
598 nrfpB = interaction_function[ftype].nrfpB;
599 strcpy(f1,formnl[nral]);
601 if ((nn=sscanf(line,f1,&c[0],&c[1],&c[2],&c[3],&c[4],&c[5],&c[6],&c[7],&c[8],&c[9],&c[10],&c[11],&c[12]))
604 /* Copy the B-state from the A-state */
605 copy_B_from_A(ftype,c);
608 warning_error("Not enough parameters");
609 } else if (nn > nrfpA && nn < nrfp) {
610 warning_error("Too many parameters or not enough parameters for topology B");
611 } else if (nn > nrfp) {
612 warning_error("Too many parameters");
614 for(i=nn; (i<nrfp); i++)
618 for(i=0; (i<nral); i++) {
619 if (at && ((p.a[i]=get_atomtype_type(alc[i],at)) == NOTSET))
620 gmx_fatal(FARGS,"Unknown atomtype %s\n",alc[i]);
621 else if (bat && ((p.a[i]=get_bond_atomtype_type(alc[i],bat)) == NOTSET))
622 gmx_fatal(FARGS,"Unknown bond_atomtype %s\n",alc[i]);
624 for(i=0; (i<nrfp); i++)
626 push_bondtype (&(bt[ftype]),&p,nral,ftype,FALSE,line);
630 void push_dihedraltype(directive d,t_params bt[],
631 t_bond_atomtype bat,char *line)
633 const char *formal[MAXATOMLIST+1] = {
641 const char *formnl[MAXATOMLIST+1] = {
649 const char *formlf[MAXFORCEPARAM] = {
655 "%lf%lf%lf%lf%lf%lf",
656 "%lf%lf%lf%lf%lf%lf%lf",
657 "%lf%lf%lf%lf%lf%lf%lf%lf",
658 "%lf%lf%lf%lf%lf%lf%lf%lf%lf",
659 "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
660 "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
661 "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
663 int i,ft,ftype,nn,nrfp,nrfpA,nrfpB,nral;
665 char alc[MAXATOMLIST+1][20];
666 double c[MAXFORCEPARAM];
671 /* This routine accepts dihedraltypes defined from either 2 or 4 atoms.
673 * We first check for 2 atoms with the 3th column being an integer
674 * defining the type. If this isn't the case, we try it with 4 atoms
675 * and the 5th column defining the dihedral type.
677 nn=sscanf(line,formal[4],alc[0],alc[1],alc[2],alc[3],alc[4]);
678 if(nn>=3 && strlen(alc[2])==1 && isdigit(alc[2][0])) {
680 ft = atoi(alc[nral]);
681 /* Move atom types around a bit and use 'X' for wildcard atoms
682 * to create a 4-atom dihedral definition with arbitrary atoms in
686 /* improper - the two atomtypes are 1,4. Use wildcards for 2,3 */
687 strcpy(alc[3],alc[1]);
690 /* alc[0] stays put */
692 /* proper - the two atomtypes are 2,3. Use wildcards for 1,4 */
694 strcpy(alc[2],alc[1]);
695 strcpy(alc[1],alc[0]);
698 } else if(nn==5 && strlen(alc[4])==1 && isdigit(alc[4][0])) {
700 ft = atoi(alc[nral]);
702 sprintf(errbuf,"Incorrect number of atomtypes for dihedral (%d instead of 2 or 4)",nn-1);
703 warning_error(errbuf);
709 /* Previously, we have always overwritten parameters if e.g. a torsion
710 with the same atomtypes occurs on multiple lines. However, CHARMM and
711 some other force fields specify multiple dihedrals over some bonds,
712 including cosines with multiplicity 6 and somethimes even higher.
713 Thus, they cannot be represented with Ryckaert-Bellemans terms.
714 To add support for these force fields, Dihedral type 4 is identical to
715 normal proper dihedrals, but repeated entries are allowed.
722 bAllowRepeat = FALSE;
726 ftype = ifunc_index(d,ft);
728 nrfpA = interaction_function[ftype].nrfpA;
729 nrfpB = interaction_function[ftype].nrfpB;
731 strcpy(f1,formnl[nral]);
732 strcat(f1,formlf[nrfp-1]);
734 /* Check number of parameters given */
735 if ((nn=sscanf(line,f1,&c[0],&c[1],&c[2],&c[3],&c[4],&c[5],&c[6],&c[7],&c[8],&c[9],&c[10],&c[11]))
738 /* Copy the B-state from the A-state */
739 copy_B_from_A(ftype,c);
742 warning_error("Not enough parameters");
743 } else if (nn > nrfpA && nn < nrfp) {
744 warning_error("Too many parameters or not enough parameters for topology B");
745 } else if (nn > nrfp) {
746 warning_error("Too many parameters");
748 for(i=nn; (i<nrfp); i++)
753 for(i=0; (i<4); i++) {
754 if(!strcmp(alc[i],"X"))
757 if ((p.a[i]=get_bond_atomtype_type(alc[i],bat)) == NOTSET)
758 gmx_fatal(FARGS,"Unknown bond_atomtype %s",alc[i]);
761 for(i=0; (i<nrfp); i++)
763 /* Always use 4 atoms here, since we created two wildcard atoms
764 * if there wasn't of them 4 already.
766 push_bondtype (&(bt[ftype]),&p,4,ftype,bAllowRepeat,line);
770 void push_nbt(directive d,t_nbparam **nbt,t_atomtype atype,
771 char *pline,int nb_funct)
774 const char *form2="%*s%*s%*s%lf%lf";
775 const char *form3="%*s%*s%*s%lf%lf%lf";
776 const char *form4="%*s%*s%*s%lf%lf%lf%lf";
778 int i,f,n,ftype,atnr,nrfp;
786 if (sscanf (pline,"%s%s%d",a0,a1,&f) != 3) {
791 ftype=ifunc_index(d,f);
793 if (ftype != nb_funct) {
794 sprintf(errbuf,"Trying to add %s while the default nonbond type is %s",
795 interaction_function[ftype].longname,
796 interaction_function[nb_funct].longname);
797 warning_error(errbuf);
801 /* Get the force parameters */
803 if (ftype == F_LJ14) {
804 n = sscanf(pline,form4,&c[0],&c[1],&c[2],&c[3]);
809 /* When the B topology parameters are not set,
810 * copy them from topology A
812 for(i=n; i<nrfp; i++)
815 else if (ftype == F_LJC14_Q) {
816 n = sscanf(pline,form4,&c[0],&c[1],&c[2],&c[3]);
822 else if (nrfp == 2) {
823 if (sscanf(pline,form2,&c[0],&c[1]) != 2) {
828 else if (nrfp == 3) {
829 if (sscanf(pline,form3,&c[0],&c[1],&c[2]) != 3) {
835 gmx_fatal(FARGS,"Number of force parameters for nonbonded interactions is %d"
836 " in file %s, line %d",nrfp,__FILE__,__LINE__);
838 for(i=0; (i<nrfp); i++)
841 /* Put the parameters in the matrix */
842 if ((ai = get_atomtype_type (a0,atype)) == NOTSET)
843 gmx_fatal(FARGS,"Atomtype %s not found",a0);
844 if ((aj = get_atomtype_type (a1,atype)) == NOTSET)
845 gmx_fatal(FARGS,"Atomtype %s not found",a1);
846 nbp = &(nbt[max(ai,aj)][min(ai,aj)]);
850 for (i=0; i<nrfp; i++)
851 bId = bId && (nbp->c[i] == cr[i]);
853 sprintf(errbuf,"Overriding non-bonded parameters,");
855 fprintf(stderr," old:");
856 for (i=0; i<nrfp; i++)
857 fprintf(stderr," %g",nbp->c[i]);
858 fprintf(stderr," new\n%s\n",pline);
862 for (i=0; i<nrfp; i++)
867 push_gb_params (t_atomtype at, char *line)
870 int i,n,k,found,gfound;
871 double radius,vol,surftens,gb_radius,S_hct;
872 char atypename[STRLEN];
875 if( (nfield = sscanf(line,"%s%lf%lf%lf%lf%lf",atypename,&radius,&vol,&surftens,&gb_radius,&S_hct)) != 6)
877 sprintf(errbuf,"Too few gb parameters for type %s\n",atypename);
881 /* Search for atomtype */
882 //printf("gb params for atomtype '%s'\n",atypename);
885 for(i=0;i<get_atomtype_ntypes(at) && !found;i++)
887 if(gmx_strncasecmp(atypename,get_atomtype_name(i,at),STRLEN-1)==0)
889 //printf("Found matching atomtype in topology: %s\n",get_atomtype_name(i,at));
892 //printf("found=%d\n",found);
898 printf("Couldn't find topology match for atomtype %s\n",atypename);
902 set_atomtype_gbparam(at,found,radius,vol,surftens,gb_radius,S_hct);
905 static void push_atom_now(t_symtab *symtab,t_atoms *at,int atomnr,
907 int type,char *ctype,int ptype,
908 char *resnumberic,int cgnumber,
909 char *resname,char *name,real m0,real q0,
910 int typeB,char *ctypeB,real mB,real qB)
916 if (((nr==0) && (atomnr != 1)) || (nr && (atomnr != at->nr+1)))
917 gmx_fatal(FARGS,"Atoms in the .top are not numbered consecutively from 1 (rather, atomnr = %d, while at->nr = %d)",atomnr,at->nr);
919 j = strlen(resnumberic) - 1;
920 if (isdigit(resnumberic[j])) {
923 ric = resnumberic[j];
924 if (j == 0 || !isdigit(resnumberic[j-1])) {
925 gmx_fatal(FARGS,"Invalid residue number '%s' for atom %d",
929 resnr = atoi(resnumberic);
932 resind = at->atom[nr-1].resind;
934 if (nr == 0 || strcmp(resname,*at->resinfo[resind].name) != 0 ||
935 resnr != at->resinfo[resind].nr ||
936 ric != at->resinfo[resind].ic) {
942 at->nres = resind + 1;
943 srenew(at->resinfo,at->nres);
944 at->resinfo[resind].name = put_symtab(symtab,resname);
945 at->resinfo[resind].nr = resnr;
946 at->resinfo[resind].ic = ric;
948 resind = at->atom[at->nr-1].resind;
952 * get new space for arrays
954 srenew(at->atom,nr+1);
955 srenew(at->atomname,nr+1);
956 srenew(at->atomtype,nr+1);
957 srenew(at->atomtypeB,nr+1);
960 at->atom[nr].type = type;
961 at->atom[nr].ptype = ptype;
964 at->atom[nr].typeB = typeB;
965 at->atom[nr].qB = qB;
966 at->atom[nr].mB = mB;
968 at->atom[nr].resind = resind;
969 at->atom[nr].atomnumber = atomicnumber;
970 at->atomname[nr] = put_symtab(symtab,name);
971 at->atomtype[nr] = put_symtab(symtab,ctype);
972 at->atomtypeB[nr] = put_symtab(symtab,ctypeB);
976 void push_cg(t_block *block, int *lastindex, int index, int a)
979 fprintf (debug,"Index %d, Atom %d\n",index,a);
981 if (((block->nr) && (*lastindex != index)) || (!block->nr)) {
982 /* add a new block */
984 srenew(block->index,block->nr+1);
986 block->index[block->nr] = a + 1;
990 void push_atom(t_symtab *symtab,t_block *cgs,
991 t_atoms *at,t_atomtype atype,char *line,int *lastcg)
994 int cgnumber,atomnr,type,typeB,nscan;
995 char id[STRLEN],ctype[STRLEN],ctypeB[STRLEN],
996 resnumberic[STRLEN],resname[STRLEN],name[STRLEN],check[STRLEN];
1000 /* Make a shortcut for writing in this molecule */
1003 /* Fixed parameters */
1004 if (sscanf(line,"%s%s%s%s%s%d",
1005 id,ctype,resnumberic,resname,name,&cgnumber) != 6) {
1009 sscanf(id,"%d",&atomnr);
1010 if ((type = get_atomtype_type(ctype,atype)) == NOTSET)
1011 gmx_fatal(FARGS,"Atomtype %s not found",ctype);
1012 ptype = get_atomtype_ptype(type,atype);
1014 /* Set default from type */
1015 q0 = get_atomtype_qA(type,atype);
1016 m0 = get_atomtype_massA(type,atype);
1021 /* Optional parameters */
1022 nscan = sscanf(line,"%*s%*s%*s%*s%*s%*s%lf%lf%s%lf%lf%s",
1023 &q,&m,ctypeB,&qb,&mb,check);
1025 /* Nasty switch that falls thru all the way down! */
1031 typeB=get_atomtype_type(ctypeB,atype);
1032 qB = get_atomtype_qA(typeB,atype);
1033 mB = get_atomtype_massA(typeB,atype);
1039 warning_error("Too many parameters");
1046 fprintf(debug,"mB=%g, qB=%g, typeB=%d\n",mB,qB,typeB);
1048 push_cg(cgs,lastcg,cgnumber,nr);
1050 push_atom_now(symtab,at,atomnr,get_atomtype_atomnumber(type,atype),
1051 type,ctype,ptype,resnumberic,cgnumber,
1052 resname,name,m0,q0,typeB,
1053 typeB==type ? ctype : ctypeB,mB,qB);
1056 void push_molt(t_symtab *symtab,int *nmol,t_molinfo **mol,char *line)
1062 if ((sscanf(line,"%s%d",type,&nrexcl)) != 2) {
1063 warning_error("Expected a molecule type name and nrexcl");
1066 /* Test if this atomtype overwrites another */
1069 if (strcasecmp(*((*mol)[i].name),type) == 0)
1070 gmx_fatal(FARGS,"moleculetype %s is redefined",type);
1076 newmol = &((*mol)[*nmol-1]);
1077 init_molinfo(newmol);
1079 /* Fill in the values */
1080 newmol->name = put_symtab(symtab,type);
1081 newmol->nrexcl = nrexcl;
1082 newmol->excl_set = FALSE;
1085 static bool default_nb_params(int ftype,t_params bt[],t_atoms *at,
1086 t_param *p,int c_start,bool bB,bool bGenPairs)
1088 int i,j,ti,tj,ntype;
1091 int nr = bt[ftype].nr;
1092 int nral = NRAL(ftype);
1093 int nrfp = interaction_function[ftype].nrfpA;
1094 int nrfpB= interaction_function[ftype].nrfpB;
1096 if ((!bB && nrfp == 0) || (bB && nrfpB == 0))
1101 /* First test the generated-pair position to save
1102 * time when we have 1000*1000 entries for e.g. OPLS...
1106 ti=at->atom[p->a[0]].typeB;
1107 tj=at->atom[p->a[1]].typeB;
1109 ti=at->atom[p->a[0]].type;
1110 tj=at->atom[p->a[1]].type;
1112 pi=&(bt[ftype].param[ntype*ti+tj]);
1113 bFound=((ti == pi->a[0]) && (tj == pi->a[1]));
1116 /* Search explicitly if we didnt find it */
1118 for (i=0; ((i < nr) && !bFound); i++) {
1119 pi=&(bt[ftype].param[i]);
1121 for (j=0; ((j < nral) &&
1122 (at->atom[p->a[j]].typeB == pi->a[j])); j++);
1124 for (j=0; ((j < nral) &&
1125 (at->atom[p->a[j]].type == pi->a[j])); j++);
1132 if (nrfp+nrfpB > MAXFORCEPARAM) {
1133 gmx_incons("Too many force parameters");
1135 for (j=c_start; (j < nrfpB); j++)
1136 p->c[nrfp+j] = pi->c[j];
1139 for (j=c_start; (j < nrfp); j++)
1143 for (j=c_start; (j < nrfp); j++)
1150 static bool default_params(int ftype,t_params bt[],
1151 t_atoms *at,t_atomtype atype,
1153 t_param **param_def,
1156 int i,j,nparam_found;
1160 int nr = bt[ftype].nr;
1161 int nral = NRAL(ftype);
1162 int nrfpA= interaction_function[ftype].nrfpA;
1163 int nrfpB= interaction_function[ftype].nrfpB;
1165 if ((!bB && nrfpA == 0) || (bB && nrfpB == 0))
1169 /* We allow wildcards now. The first type (with or without wildcards) that
1170 * fits is used, so you should probably put the wildcarded bondtypes
1171 * at the end of each section.
1175 /* OPLS uses 1000s of dihedraltypes, so in order to speed up the scanning we have a
1176 * special case for this. Check for B state outside loop to speed it up.
1178 if( ftype==F_PDIHS || ftype == F_RBDIHS || ftype == F_IDIHS)
1182 for (i=0; ((i < nr) && !bFound); i++)
1184 pi=&(bt[ftype].param[i]);
1187 ((pi->AI==-1) || (get_atomtype_batype(at->atom[p->AI].typeB,atype)==pi->AI)) &&
1188 ((pi->AJ==-1) || (get_atomtype_batype(at->atom[p->AJ].typeB,atype)==pi->AJ)) &&
1189 ((pi->AK==-1) || (get_atomtype_batype(at->atom[p->AK].typeB,atype)==pi->AK)) &&
1190 ((pi->AL==-1) || (get_atomtype_batype(at->atom[p->AL].typeB,atype)==pi->AL))
1197 for (i=0; ((i < nr) && !bFound); i++)
1199 pi=&(bt[ftype].param[i]);
1202 ((pi->AI==-1) || (get_atomtype_batype(at->atom[p->AI].type,atype)==pi->AI)) &&
1203 ((pi->AJ==-1) || (get_atomtype_batype(at->atom[p->AJ].type,atype)==pi->AJ)) &&
1204 ((pi->AK==-1) || (get_atomtype_batype(at->atom[p->AK].type,atype)==pi->AK)) &&
1205 ((pi->AL==-1) || (get_atomtype_batype(at->atom[p->AL].type,atype)==pi->AL))
1209 /* Find additional matches for this dihedral - necessary for ftype==9 which is used e.g. for charmm.
1210 * The rules in that case is that additional matches HAVE to be on adjacent lines!
1216 /* Continue from current i value */
1217 for(j=i+1 ; j<nr && bSame ; j+=2)
1219 pj=&(bt[ftype].param[j]);
1220 bSame = (pi->AI == pj->AI && pi->AJ == pj->AJ && pi->AK == pj->AK && pi->AL == pj->AL);
1223 /* nparam_found will be increased as long as the numbers match */
1226 } else { /* Not a dihedral */
1227 for (i=0; ((i < nr) && !bFound); i++) {
1228 pi=&(bt[ftype].param[i]);
1230 for (j=0; ((j < nral) &&
1231 (get_atomtype_batype(at->atom[p->a[j]].typeB,atype)==pi->a[j])); j++)
1234 for (j=0; ((j < nral) &&
1235 (get_atomtype_batype(at->atom[p->a[j]].type,atype)==pi->a[j])); j++)
1244 *nparam_def = nparam_found;
1251 void push_bond(directive d,t_params bondtype[],t_params bond[],
1252 t_atoms *at,t_atomtype atype,char *line,
1253 bool bBonded,bool bGenPairs,real fudgeQQ,
1254 bool bZero,bool *bWarn_copy_A_B)
1256 const char *aaformat[MAXATOMLIST]= {
1263 const char *asformat[MAXATOMLIST]= {
1268 "%*s%*s%*s%*s%*s%*s"
1270 const char *ccformat="%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf";
1271 int nr,i,j,nral,nread,ftype;
1272 char format[STRLEN];
1273 /* One force parameter more, so we can check if we read too many */
1274 double cc[MAXFORCEPARAM+1];
1275 int aa[MAXATOMLIST+1];
1276 t_param param,paramB,*param_defA,*param_defB;
1277 bool bFoundA=FALSE,bFoundB=FALSE,bDef,bPert,bSwapParity=FALSE;
1278 int nparam_defA,nparam_defB;
1281 nparam_defA=nparam_defB=0;
1283 ftype = ifunc_index(d,1);
1285 for(j=0; j<MAXATOMLIST; j++)
1287 bDef = (NRFP(ftype) > 0);
1289 nread = sscanf(line,aaformat[nral-1],
1290 &aa[0],&aa[1],&aa[2],&aa[3],&aa[4],&aa[5]);
1294 } else if (nread == nral)
1295 ftype = ifunc_index(d,1);
1297 /* this is a hack to allow for virtual sites with swapped parity */
1298 bSwapParity = (aa[nral]<0);
1300 aa[nral] = -aa[nral];
1301 ftype = ifunc_index(d,aa[nral]);
1308 gmx_fatal(FARGS,"Negative function types only allowed for %s and %s",
1309 interaction_function[F_VSITE3FAD].longname,
1310 interaction_function[F_VSITE3OUT].longname);
1314 /* Check for double atoms and atoms out of bounds */
1315 for(i=0; (i<nral); i++) {
1316 if ( aa[i] < 1 || aa[i] > at->nr )
1317 gmx_fatal(FARGS,"[ file %s, line %d ]:\n"
1318 "Atom index (%d) in %s out of bounds (1-%d).\n"
1319 "This probably means that you have inserted topology section \"%s\"\n"
1320 "in a part belonging to a different molecule than you intended to.\n"
1321 "In that case move the \"%s\" section to the right molecule.",
1322 get_warning_file(),get_warning_line(),
1323 aa[i],dir2str(d),at->nr,dir2str(d),dir2str(d));
1324 for(j=i+1; (j<nral); j++)
1325 if (aa[i] == aa[j]) {
1326 sprintf(errbuf,"Duplicate atom index (%d) in %s",aa[i],dir2str(d));
1330 if (ftype == F_SETTLE)
1331 if (aa[0]+2 > at->nr)
1332 gmx_fatal(FARGS,"[ file %s, line %d ]:\n"
1333 " Atom index (%d) in %s out of bounds (1-%d)\n"
1334 " Settle works on atoms %d, %d and %d",
1335 get_warning_file(),get_warning_line(),
1336 aa[0],dir2str(d),at->nr,
1337 aa[0],aa[0]+1,aa[0]+2);
1339 /* default force parameters */
1340 for(j=0; (j<MAXATOMLIST); j++)
1341 param.a[j] = aa[j]-1;
1342 for(j=0; (j<MAXFORCEPARAM); j++)
1345 /* Get force params for normal and free energy perturbation
1346 * studies, as determined by types!
1349 bFoundA = default_params(ftype,bondtype,at,atype,¶m,FALSE,¶m_defA,&nparam_defA);
1351 /* Copy the A-state and B-state default parameters */
1352 for(j=0; (j<NRFPA(ftype)+NRFPB(ftype)); j++)
1353 param.c[j] = param_defA->c[j];
1355 bFoundB = default_params(ftype,bondtype,at,atype,¶m,TRUE,¶m_defB,&nparam_defB);
1357 /* Copy only the B-state default parameters */
1358 for(j=NRFPA(ftype); (j<NRFP(ftype)); j++)
1359 param.c[j] = param_defB->c[j];
1361 } else if (ftype == F_LJ14) {
1362 bFoundA = default_nb_params(ftype, bondtype,at,¶m,0,FALSE,bGenPairs);
1363 bFoundB = default_nb_params(ftype, bondtype,at,¶m,0,TRUE, bGenPairs);
1364 } else if (ftype == F_LJC14_Q) {
1365 param.c[0] = fudgeQQ;
1366 /* Fill in the A-state charges as default parameters */
1367 param.c[1] = at->atom[param.a[0]].q;
1368 param.c[2] = at->atom[param.a[1]].q;
1369 /* The default LJ parameters are the standard 1-4 parameters */
1370 bFoundA = default_nb_params(F_LJ14,bondtype,at,¶m,3,FALSE,bGenPairs);
1372 } else if (ftype == F_LJC_PAIRS_NB) {
1373 /* Defaults are not supported here */
1377 gmx_incons("Unknown function type in push_bond");
1381 /* Manually specified parameters - in this case we discard multiple torsion info! */
1383 strcpy(format,asformat[nral-1]);
1384 strcat(format,ccformat);
1386 nread = sscanf(line,format,&cc[0],&cc[1],&cc[2],&cc[3],&cc[4],&cc[5],
1387 &cc[6],&cc[7],&cc[8],&cc[9],&cc[10],&cc[11],&cc[12]);
1389 if ((nread == NRFPA(ftype)) && (NRFPB(ftype) != 0))
1391 /* We only have to issue a warning if these atoms are perturbed! */
1393 for(j=0; (j<nral); j++)
1394 bPert = bPert || PERTURBED(at->atom[param.a[j]]);
1396 if (bPert && *bWarn_copy_A_B)
1399 "Some parameters for bonded interaction involving perturbed atoms are specified explicitly in state A, but not B - copying A to B");
1401 *bWarn_copy_A_B = FALSE;
1404 /* If only the A parameters were specified, copy them to the B state */
1405 /* The B-state parameters correspond to the first nrfpB
1406 * A-state parameters.
1408 for(j=0; (j<NRFPB(ftype)); j++)
1409 cc[nread++] = cc[j];
1412 /* If nread was 0 or EOF, no parameters were read => use defaults.
1413 * If nread was nrfpA we copied above so nread=nrfp.
1414 * If nread was nrfp we are cool.
1415 * For F_LJC14_Q we allow supplying fudgeQQ only.
1416 * Anything else is an error!
1418 if ((nread != 0) && (nread != EOF) && (nread != NRFP(ftype)) &&
1419 !(ftype == F_LJC14_Q && nread == 1))
1421 gmx_fatal(FARGS,"Incorrect number of parameters - found %d, expected %d or %d for %s.",
1422 nread,NRFPA(ftype),NRFP(ftype),
1423 interaction_function[ftype].longname);
1426 for(j=0; (j<nread); j++)
1429 /* Check whether we have to use the defaults */
1430 if (nread == NRFP(ftype))
1437 /* nread now holds the number of force parameters read! */
1445 /* When we have multiple terms it would be very dangerous to allow perturbations to a different atom type! */
1448 if ((nparam_defA != nparam_defB) || ((nparam_defA>1 || nparam_defB>1) && (param_defA!=param_defB)))
1451 "Cannot automatically perturb a torsion with multiple terms to different form.\n"
1452 "Please specify perturbed parameters manually for this torsion in your topology!");
1453 warning_error(errbuf);
1457 if (nread > 0 && nread < NRFPA(ftype))
1459 /* Issue an error, do not use defaults */
1460 sprintf(errbuf,"Not enough parameters, there should be at least %d (or 0 for defaults)",NRFPA(ftype));
1461 warning_error(errbuf);
1464 if (nread == 0 || nread == EOF)
1468 if (interaction_function[ftype].flags & IF_VSITE)
1470 /* set them to NOTSET, will be calculated later */
1471 for(j=0; (j<MAXFORCEPARAM); j++)
1472 param.c[j] = NOTSET;
1475 param.C1 = -1; /* flag to swap parity of vsite construction */
1481 fprintf(stderr,"NOTE: No default %s types, using zeroes\n",
1482 interaction_function[ftype].longname);
1486 sprintf(errbuf,"No default %s types",interaction_function[ftype].longname);
1487 warning_error(errbuf);
1498 param.C0 = 360 - param.C0;
1501 param.C2 = -param.C2;
1508 /* We only have to issue a warning if these atoms are perturbed! */
1510 for(j=0; (j<nral); j++)
1511 bPert = bPert || PERTURBED(at->atom[param.a[j]]);
1515 sprintf(errbuf,"No default %s types for perturbed atoms, "
1516 "using normal values",interaction_function[ftype].longname);
1523 if ((ftype==F_PDIHS || ftype==F_ANGRES || ftype==F_ANGRESZ)
1524 && param.c[5]!=param.c[2])
1525 gmx_fatal(FARGS,"[ file %s, line %d ]:\n"
1526 " %s multiplicity can not be perturbed %f!=%f",
1527 get_warning_file(),get_warning_line(),
1528 interaction_function[ftype].longname,
1529 param.c[2],param.c[5]);
1531 if (IS_TABULATED(ftype) && param.c[2]!=param.c[0])
1532 gmx_fatal(FARGS,"[ file %s, line %d ]:\n"
1533 " %s table number can not be perturbed %d!=%d",
1534 get_warning_file(),get_warning_line(),
1535 interaction_function[ftype].longname,
1536 (int)(param.c[0]+0.5),(int)(param.c[2]+0.5));
1538 /* Dont add R-B dihedrals where all parameters are zero (no interaction) */
1539 if (ftype==F_RBDIHS) {
1541 for(i=0;i<NRFP(ftype);i++) {
1549 /* Put the values in the appropriate arrays */
1550 add_param_to_list (&bond[ftype],¶m);
1552 /* Push additional torsions from FF for ftype==9 if we have them.
1553 * We have already checked that the A/B states do not differ in this case,
1554 * so we do not have to double-check that again, or the vsite stuff.
1555 * In addition, those torsions cannot be automatically perturbed.
1557 if(bDef && ftype==F_PDIHS)
1559 for(i=1;i<nparam_defA;i++)
1561 /* Advance pointer! */
1563 for(j=0; (j<NRFPA(ftype)+NRFPB(ftype)); j++)
1564 param.c[j] = param_defA->c[j];
1565 /* And push the next term for this torsion */
1566 add_param_to_list (&bond[ftype],¶m);
1573 void push_vsitesn(directive d,t_params bondtype[],t_params bond[],
1574 t_atoms *at,t_atomtype atype,char *line)
1577 int type,ftype,j,n,ret,nj,a;
1579 double *weight=NULL,weight_tot;
1582 /* default force parameters */
1583 for(j=0; (j<MAXATOMLIST); j++)
1584 param.a[j] = NOTSET;
1585 for(j=0; (j<MAXFORCEPARAM); j++)
1589 ret = sscanf(ptr,"%d%n",&a,&n);
1592 gmx_fatal(FARGS,"[ file %s, line %d ]:\n"
1593 " Expected an atom index in section \"%s\"",
1594 get_warning_file(),get_warning_line(),
1599 ret = sscanf(ptr,"%d%n",&type,&n);
1601 ftype = ifunc_index(d,type);
1606 ret = sscanf(ptr,"%d%n",&a,&n);
1611 srenew(weight,nj+20);
1619 /* Here we use the A-state mass as a parameter.
1620 * Note that the B-state mass has no influence.
1622 weight[nj] = at->atom[atc[nj]].m;
1626 ret = sscanf(ptr,"%lf%n",&(weight[nj]),&n);
1629 gmx_fatal(FARGS,"[ file %s, line %d ]:\n"
1630 " No weight or negative weight found for vsiten constructing atom %d (atom index %d)",
1631 get_warning_file(),get_warning_line(),
1635 gmx_fatal(FARGS,"Unknown vsiten type %d",type);
1637 weight_tot += weight[nj];
1643 gmx_fatal(FARGS,"[ file %s, line %d ]:\n"
1644 " Expected more than one atom index in section \"%s\"",
1645 get_warning_file(),get_warning_line(),
1648 if (weight_tot == 0)
1649 gmx_fatal(FARGS,"[ file %s, line %d ]:\n"
1650 " The total mass of the construting atoms is zero",
1651 get_warning_file(),get_warning_line());
1653 for(j=0; j<nj; j++) {
1654 param.a[1] = atc[j];
1656 param.c[1] = weight[j]/weight_tot;
1657 /* Put the values in the appropriate arrays */
1658 add_param_to_list (&bond[ftype],¶m);
1665 void push_mol(int nrmols,t_molinfo mols[],char *pline,int *whichmol,
1672 if (sscanf(pline,"%s%d",type,&copies) != 2) {
1677 /* search moleculename */
1678 for (i=0; ((i<nrmols) && strcasecmp(type,*(mols[i].name))); i++)
1685 gmx_fatal(FARGS,"No such moleculetype %s",type);
1688 void init_block2(t_block2 *b2, int natom)
1693 snew(b2->nra,b2->nr);
1695 for(i=0; (i<b2->nr); i++)
1699 void done_block2(t_block2 *b2)
1704 for(i=0; (i<b2->nr); i++)
1712 void push_excl(char *line, t_block2 *b2)
1716 char base[STRLEN],format[STRLEN];
1718 if (sscanf(line,"%d",&i)==0)
1721 if ((1 <= i) && (i <= b2->nr))
1725 fprintf(debug,"Unbound atom %d\n",i-1);
1730 strcpy(format,base);
1731 strcat(format,"%d");
1732 n=sscanf(line,format,&j);
1734 if ((1 <= j) && (j <= b2->nr)) {
1736 srenew(b2->a[i],++(b2->nra[i]));
1737 b2->a[i][b2->nra[i]-1]=j;
1738 /* also add the reverse exclusion! */
1739 srenew(b2->a[j],++(b2->nra[j]));
1740 b2->a[j][b2->nra[j]-1]=i;
1744 gmx_fatal(FARGS,"Invalid Atomnr j: %d, b2->nr: %d\n",j,b2->nr);
1749 void b_to_b2(t_blocka *b, t_block2 *b2)
1754 for(i=0; (i<b->nr); i++)
1755 for(j=b->index[i]; (j<b->index[i+1]); j++) {
1757 srenew(b2->a[i],++b2->nra[i]);
1758 b2->a[i][b2->nra[i]-1]=a;
1762 void b2_to_b(t_block2 *b2, t_blocka *b)
1768 for(i=0; (i<b2->nr); i++) {
1770 for(j=0; (j<b2->nra[i]); j++)
1771 b->a[nra+j]=b2->a[i][j];
1774 /* terminate list */
1778 static int icomp(const void *v1, const void *v2)
1780 return (*((atom_id *) v1))-(*((atom_id *) v2));
1783 void merge_excl(t_blocka *excl, t_block2 *b2)
1791 else if (b2->nr != excl->nr) {
1792 gmx_fatal(FARGS,"DEATH HORROR: b2->nr = %d, while excl->nr = %d",
1796 fprintf(debug,"Entering merge_excl\n");
1798 /* First copy all entries from excl to b2 */
1801 /* Count and sort the exclusions */
1803 for(i=0; (i<b2->nr); i++) {
1804 if (b2->nra[i] > 0) {
1805 /* remove double entries */
1806 qsort(b2->a[i],(size_t)b2->nra[i],(size_t)sizeof(b2->a[i][0]),icomp);
1808 for(j=1; (j<b2->nra[i]); j++)
1809 if (b2->a[i][j]!=b2->a[i][k-1]) {
1810 b2->a[i][k]=b2->a[i][j];
1818 srenew(excl->a,excl->nra);
1823 int add_atomtype_decoupled(t_symtab *symtab,t_atomtype at,
1824 t_nbparam ***nbparam,t_nbparam ***pair)
1830 /* Define an atom type with all parameters set to zero (no interactions) */
1833 /* Type for decoupled atoms could be anything,
1834 * this should be changed automatically later when required.
1836 atom.ptype = eptAtom;
1837 for (i=0; (i<MAXFORCEPARAM); i++)
1840 nr = add_atomtype(at,symtab,&atom,"decoupled",¶m,-1,0.0,0.0,0.0,0,0,0);
1842 /* Add space in the non-bonded parameters matrix */
1843 realloc_nb_params(at,nbparam,pair);
1848 static void convert_pairs_to_pairsQ(t_params *plist,
1849 real fudgeQQ,t_atoms *atoms)
1855 /* Copy the pair list to the pairQ list */
1856 plist[F_LJC14_Q] = plist[F_LJ14];
1857 /* Empty the pair list */
1858 plist[F_LJ14].nr = 0;
1859 plist[F_LJ14].param = NULL;
1860 param = plist[F_LJC14_Q].param;
1861 for(i=0; i<plist[F_LJC14_Q].nr; i++) {
1864 param[i].c[0] = fudgeQQ;
1865 param[i].c[1] = atoms->atom[param[i].a[0]].q;
1866 param[i].c[2] = atoms->atom[param[i].a[1]].q;
1872 static void generate_LJCpairsNB(t_molinfo *mol,int nb_funct,t_params *nbp)
1881 atom = mol->atoms.atom;
1883 ntype = sqrt(nbp->nr);
1885 for (i=0; i<MAXATOMLIST; i++)
1886 param.a[i] = NOTSET;
1887 for (i=0; i<MAXFORCEPARAM; i++)
1888 param.c[i] = NOTSET;
1890 /* Add a pair interaction for all non-excluded atom pairs */
1892 for(i=0; i<n; i++) {
1893 for(j=i+1; j<n; j++) {
1895 for(k=excl->index[i]; k<excl->index[i+1]; k++) {
1896 if (excl->a[k] == j)
1900 if (nb_funct != F_LJ)
1901 gmx_fatal(FARGS,"Can only generate non-bonded pair interactions for Van der Waals type Lennard-Jones");
1904 param.c[0] = atom[i].q;
1905 param.c[1] = atom[j].q;
1906 param.c[2] = nbp->param[ntype*atom[i].type+atom[j].type].c[0];
1907 param.c[3] = nbp->param[ntype*atom[i].type+atom[j].type].c[1];
1908 add_param_to_list(&mol->plist[F_LJC_PAIRS_NB],¶m);
1914 static void set_excl_all(t_blocka *excl)
1918 /* Get rid of the current exclusions and exclude all atom pairs */
1920 excl->nra = nat*nat;
1921 srenew(excl->a,excl->nra);
1923 for(i=0; i<nat; i++) {
1925 for(j=0; j<nat; j++)
1928 excl->index[nat] = k;
1931 static void decouple_atoms(t_atoms *atoms,int atomtype_decouple,
1932 int couple_lam0,int couple_lam1)
1936 for(i=0; i<atoms->nr; i++) {
1937 if (couple_lam0 != ecouplamVDWQ)
1938 atoms->atom[i].q = 0.0;
1939 if (couple_lam0 == ecouplamNONE)
1940 atoms->atom[i].type = atomtype_decouple;
1941 if (couple_lam1 != ecouplamVDWQ)
1942 atoms->atom[i].qB = 0.0;
1943 if (couple_lam1 == ecouplamNONE)
1944 atoms->atom[i].typeB = atomtype_decouple;
1948 void convert_moltype_couple(t_molinfo *mol,int atomtype_decouple,real fudgeQQ,
1949 int couple_lam0,int couple_lam1,
1950 bool bCoupleIntra,int nb_funct,t_params *nbp)
1952 convert_pairs_to_pairsQ(mol->plist,fudgeQQ,&mol->atoms);
1953 if (!bCoupleIntra) {
1954 generate_LJCpairsNB(mol,nb_funct,nbp);
1955 set_excl_all(&mol->excls);
1957 decouple_atoms(&mol->atoms,atomtype_decouple,couple_lam0,couple_lam1);