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;
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 */
274 if( have_atomic_number )
276 if ( have_bonded_type )
278 nread = sscanf(line,"%s%s%d%lf%lf%s%lf%lf%lf%lf%lf",
279 type,btype,&atomnr,&m,&q,ptype,&c[0],&c[1],
280 &radius,&vol,&surftens);
289 /* have_atomic_number && !have_bonded_type */
290 nread = sscanf(line,"%s%d%lf%lf%s%lf%lf%lf%lf%lf",
291 type,&atomnr,&m,&q,ptype,&c[0],&c[1],
292 &radius,&vol,&surftens);
302 if ( have_bonded_type )
304 /* !have_atomic_number && have_bonded_type */
305 nread = sscanf(line,"%s%s%lf%lf%s%lf%lf%lf%lf%lf",
306 type,btype,&m,&q,ptype,&c[0],&c[1],
307 &radius,&vol,&surftens);
316 /* !have_atomic_number && !have_bonded_type */
317 nread = sscanf(line,"%s%lf%lf%s%lf%lf%lf%lf%lf",
318 type,&m,&q,ptype,&c[0],&c[1],
319 &radius,&vol,&surftens);
328 if( !have_bonded_type )
333 if( !have_atomic_number )
343 if( have_atomic_number )
345 if ( have_bonded_type )
347 nread = sscanf(line,"%s%s%d%lf%lf%s%lf%lf%lf%lf%lf%lf",
348 type,btype,&atomnr,&m,&q,ptype,&c[0],&c[1],&c[2],
349 &radius,&vol,&surftens);
358 /* have_atomic_number && !have_bonded_type */
359 nread = sscanf(line,"%s%d%lf%lf%s%lf%lf%lf%lf%lf%lf",
360 type,&atomnr,&m,&q,ptype,&c[0],&c[1],&c[2],
361 &radius,&vol,&surftens);
371 if ( have_bonded_type )
373 /* !have_atomic_number && have_bonded_type */
374 nread = sscanf(line,"%s%s%lf%lf%s%lf%lf%lf%lf%lf%lf",
375 type,btype,&m,&q,ptype,&c[0],&c[1],&c[2],
376 &radius,&vol,&surftens);
385 /* !have_atomic_number && !have_bonded_type */
386 nread = sscanf(line,"%s%lf%lf%s%lf%lf%lf%lf%lf%lf",
387 type,&m,&q,ptype,&c[0],&c[1],&c[2],
388 &radius,&vol,&surftens);
397 if( !have_bonded_type )
402 if( !have_atomic_number )
410 gmx_fatal(FARGS,"Invalid function type %d in push_at %s %d",nb_funct,
413 for(j=nfp0; (j<MAXFORCEPARAM); j++)
416 if(strlen(type)==1 && isdigit(type[0]))
417 gmx_fatal(FARGS,"Atom type names can't be single digits.");
419 if(strlen(btype)==1 && isdigit(btype[0]))
420 gmx_fatal(FARGS,"Bond atom type names can't be single digits.");
422 /* Hack to read old topologies */
423 if (strcasecmp(ptype,"D") == 0)
425 for(j=0; (j<eptNR); j++)
426 if (strcasecmp(ptype,xl[j].entry) == 0)
429 gmx_fatal(FARGS,"Invalid particle type %s on line %s",
433 fprintf(debug,"ptype: %s\n",ptype_str[pt]);
438 for (i=0; (i<MAXFORCEPARAM); i++)
441 if ((batype_nr = get_bond_atomtype_type(btype,bat)) == NOTSET)
442 add_bond_atomtype(bat,symtab,btype);
443 batype_nr = get_bond_atomtype_type(btype,bat);
445 if ((nr = get_atomtype_type(type,at)) != NOTSET) {
446 sprintf(errbuf,"Overriding atomtype %s",type);
448 if ((nr = set_atomtype(nr,at,symtab,atom,type,param,batype_nr,
449 radius,vol,surftens,atomnr)) == NOTSET)
450 gmx_fatal(FARGS,"Replacing atomtype %s failed",type);
452 else if ((nr = add_atomtype(at,symtab,atom,type,param,
453 batype_nr,radius,vol,
454 surftens,atomnr)) == NOTSET)
455 gmx_fatal(FARGS,"Adding atomtype %s failed",type);
457 /* Add space in the non-bonded parameters matrix */
458 realloc_nb_params(at,nbparam,pair);
464 static void push_bondtype(t_params * bt,
472 bool bTest,bFound,bCont,bId;
474 int nrfp = NRFP(ftype);
477 /* If bAllowRepeat is TRUE, we allow multiple entries as long as they
478 are on directly _adjacent_ lines.
481 /* First check if our atomtypes are _identical_ (not reversed) to the previous
482 entry. If they are not identical we search for earlier duplicates. If they are
483 we can skip it, since we already searched for the first line
490 if(bAllowRepeat && nr>1)
492 for (j=0,bCont=TRUE; (j < nral); j++)
494 bCont=bCont && (b->a[j] == bt->param[nr-2].a[j]);
498 /* Search for earlier duplicates if this entry was not a continuation
499 from the previous line.
504 for (i=0; (i < nr); i++) {
506 for (j=0; (j < nral); j++)
507 bTest=(bTest && (b->a[j] == bt->param[i].a[j]));
510 for(j=0; (j<nral); j++)
511 bTest=(bTest && (b->a[nral-1-j] == bt->param[i].a[j]));
516 for (j=0; (j < nrfp); j++)
517 bId = bId && (bt->param[i].c[j] == b->c[j]);
519 sprintf(errbuf,"Overriding %s parameters.%s",
520 interaction_function[ftype].longname,
521 (ftype==F_PDIHS) ? "\nUse dihedraltype 4 to allow several multiplicity terms." : "");
523 fprintf(stderr," old:");
524 for (j=0; (j < nrfp); j++)
525 fprintf(stderr," %g",bt->param[i].c[j]);
526 fprintf(stderr," \n new: %s\n\n",line);
530 for (j=0; (j < nrfp); j++)
531 bt->param[i].c[j] = b->c[j];
539 /* fill the arrays up and down */
540 memcpy(bt->param[bt->nr].c, b->c,sizeof(b->c));
541 memcpy(bt->param[bt->nr].a, b->a,sizeof(b->a));
542 memcpy(bt->param[bt->nr+1].c,b->c,sizeof(b->c));
544 for (j=0; (j < nral); j++)
545 bt->param[bt->nr+1].a[j] = b->a[nral-1-j];
552 void push_bt(directive d,t_params bt[],int nral,
554 t_bond_atomtype bat,char *line)
556 const char *formal[MAXATOMLIST+1] = {
564 const char *formnl[MAXATOMLIST+1] = {
572 const char *formlf = "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf";
573 int i,ft,ftype,nn,nrfp,nrfpA,nrfpB;
575 char alc[MAXATOMLIST+1][20];
576 /* One force parameter more, so we can check if we read too many */
577 double c[MAXFORCEPARAM+1];
581 if ((bat && at) || (!bat && !at))
582 gmx_incons("You should pass either bat or at to push_bt");
584 /* Make format string (nral ints+functype) */
585 if ((nn=sscanf(line,formal[nral],
586 alc[0],alc[1],alc[2],alc[3],alc[4],alc[5])) != nral+1) {
587 sprintf(errbuf,"Not enough atomtypes (%d instead of %d)",nn-1,nral);
588 warning_error(errbuf);
592 ft = atoi(alc[nral]);
593 ftype = ifunc_index(d,ft);
595 nrfpA = interaction_function[ftype].nrfpA;
596 nrfpB = interaction_function[ftype].nrfpB;
597 strcpy(f1,formnl[nral]);
599 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]))
602 /* Copy the B-state from the A-state */
603 copy_B_from_A(ftype,c);
606 warning_error("Not enough parameters");
607 } else if (nn > nrfpA && nn < nrfp) {
608 warning_error("Too many parameters or not enough parameters for topology B");
609 } else if (nn > nrfp) {
610 warning_error("Too many parameters");
612 for(i=nn; (i<nrfp); i++)
616 for(i=0; (i<nral); i++) {
617 if (at && ((p.a[i]=get_atomtype_type(alc[i],at)) == NOTSET))
618 gmx_fatal(FARGS,"Unknown atomtype %s\n",alc[i]);
619 else if (bat && ((p.a[i]=get_bond_atomtype_type(alc[i],bat)) == NOTSET))
620 gmx_fatal(FARGS,"Unknown bond_atomtype %s\n",alc[i]);
622 for(i=0; (i<nrfp); i++)
624 push_bondtype (&(bt[ftype]),&p,nral,ftype,FALSE,line);
628 void push_dihedraltype(directive d,t_params bt[],
629 t_bond_atomtype bat,char *line)
631 const char *formal[MAXATOMLIST+1] = {
639 const char *formnl[MAXATOMLIST+1] = {
647 const char *formlf[MAXFORCEPARAM] = {
653 "%lf%lf%lf%lf%lf%lf",
654 "%lf%lf%lf%lf%lf%lf%lf",
655 "%lf%lf%lf%lf%lf%lf%lf%lf",
656 "%lf%lf%lf%lf%lf%lf%lf%lf%lf",
657 "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
658 "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
659 "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
661 int i,ft,ftype,nn,nrfp,nrfpA,nrfpB,nral;
663 char alc[MAXATOMLIST+1][20];
664 double c[MAXFORCEPARAM];
669 /* This routine accepts dihedraltypes defined from either 2 or 4 atoms.
671 * We first check for 2 atoms with the 3th column being an integer
672 * defining the type. If this isn't the case, we try it with 4 atoms
673 * and the 5th column defining the dihedral type.
675 nn=sscanf(line,formal[4],alc[0],alc[1],alc[2],alc[3],alc[4]);
676 if(nn>=3 && strlen(alc[2])==1 && isdigit(alc[2][0])) {
678 ft = atoi(alc[nral]);
679 /* Move atom types around a bit and use 'X' for wildcard atoms
680 * to create a 4-atom dihedral definition with arbitrary atoms in
684 /* improper - the two atomtypes are 1,4. Use wildcards for 2,3 */
685 strcpy(alc[3],alc[1]);
688 /* alc[0] stays put */
690 /* proper - the two atomtypes are 2,3. Use wildcards for 1,4 */
692 strcpy(alc[2],alc[1]);
693 strcpy(alc[1],alc[0]);
696 } else if(nn==5 && strlen(alc[4])==1 && isdigit(alc[4][0])) {
698 ft = atoi(alc[nral]);
700 sprintf(errbuf,"Incorrect number of atomtypes for dihedral (%d instead of 2 or 4)",nn-1);
701 warning_error(errbuf);
707 /* Previously, we have always overwritten parameters if e.g. a torsion
708 with the same atomtypes occurs on multiple lines. However, CHARMM and
709 some other force fields specify multiple dihedrals over some bonds,
710 including cosines with multiplicity 6 and somethimes even higher.
711 Thus, they cannot be represented with Ryckaert-Bellemans terms.
712 To add support for these force fields, Dihedral type 4 is identical to
713 normal proper dihedrals, but repeated entries are allowed.
720 bAllowRepeat = FALSE;
724 ftype = ifunc_index(d,ft);
726 nrfpA = interaction_function[ftype].nrfpA;
727 nrfpB = interaction_function[ftype].nrfpB;
729 strcpy(f1,formnl[nral]);
730 strcat(f1,formlf[nrfp-1]);
732 /* Check number of parameters given */
733 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]))
736 /* Copy the B-state from the A-state */
737 copy_B_from_A(ftype,c);
740 warning_error("Not enough parameters");
741 } else if (nn > nrfpA && nn < nrfp) {
742 warning_error("Too many parameters or not enough parameters for topology B");
743 } else if (nn > nrfp) {
744 warning_error("Too many parameters");
746 for(i=nn; (i<nrfp); i++)
751 for(i=0; (i<4); i++) {
752 if(!strcmp(alc[i],"X"))
755 if ((p.a[i]=get_bond_atomtype_type(alc[i],bat)) == NOTSET)
756 gmx_fatal(FARGS,"Unknown bond_atomtype %s",alc[i]);
759 for(i=0; (i<nrfp); i++)
761 /* Always use 4 atoms here, since we created two wildcard atoms
762 * if there wasn't of them 4 already.
764 push_bondtype (&(bt[ftype]),&p,4,ftype,bAllowRepeat,line);
768 void push_nbt(directive d,t_nbparam **nbt,t_atomtype atype,
769 char *pline,int nb_funct)
772 const char *form2="%*s%*s%*s%lf%lf";
773 const char *form3="%*s%*s%*s%lf%lf%lf";
774 const char *form4="%*s%*s%*s%lf%lf%lf%lf";
776 int i,f,n,ftype,atnr,nrfp;
784 if (sscanf (pline,"%s%s%d",a0,a1,&f) != 3) {
789 ftype=ifunc_index(d,f);
791 if (ftype != nb_funct) {
792 sprintf(errbuf,"Trying to add %s while the default nonbond type is %s",
793 interaction_function[ftype].longname,
794 interaction_function[nb_funct].longname);
795 warning_error(errbuf);
799 /* Get the force parameters */
801 if (ftype == F_LJ14) {
802 n = sscanf(pline,form4,&c[0],&c[1],&c[2],&c[3]);
807 /* When the B topology parameters are not set,
808 * copy them from topology A
810 for(i=n; i<nrfp; i++)
813 else if (ftype == F_LJC14_Q) {
814 n = sscanf(pline,form4,&c[0],&c[1],&c[2],&c[3]);
820 else if (nrfp == 2) {
821 if (sscanf(pline,form2,&c[0],&c[1]) != 2) {
826 else if (nrfp == 3) {
827 if (sscanf(pline,form3,&c[0],&c[1],&c[2]) != 3) {
833 gmx_fatal(FARGS,"Number of force parameters for nonbonded interactions is %d"
834 " in file %s, line %d",nrfp,__FILE__,__LINE__);
836 for(i=0; (i<nrfp); i++)
839 /* Put the parameters in the matrix */
840 if ((ai = get_atomtype_type (a0,atype)) == NOTSET)
841 gmx_fatal(FARGS,"Atomtype %s not found",a0);
842 if ((aj = get_atomtype_type (a1,atype)) == NOTSET)
843 gmx_fatal(FARGS,"Atomtype %s not found",a1);
844 nbp = &(nbt[max(ai,aj)][min(ai,aj)]);
848 for (i=0; i<nrfp; i++)
849 bId = bId && (nbp->c[i] == cr[i]);
851 sprintf(errbuf,"Overriding non-bonded parameters,");
853 fprintf(stderr," old:");
854 for (i=0; i<nrfp; i++)
855 fprintf(stderr," %g",nbp->c[i]);
856 fprintf(stderr," new\n%s\n",pline);
860 for (i=0; i<nrfp; i++)
864 static void push_atom_now(t_symtab *symtab,t_atoms *at,int atomnr,
866 int type,char *ctype,int ptype,
867 int resnumber,int cgnumber,
868 char *resname,char *name,real m0,real q0,
869 int typeB,char *ctypeB,real mB,real qB)
874 if (((nr==0) && (atomnr != 1)) || (nr && (atomnr != at->nr+1)))
875 gmx_fatal(FARGS,"Atoms in the .top are not numbered consecutively from 1 (rather, atomnr = %d, while at->nr = %d)",atomnr,at->nr);
877 resnr_diff = resnumber - (at->atom[at->nr-1].resnr+1);
878 if (((nr==0) && (resnumber != 1)) ||
879 (nr && (resnr_diff != 0) && (resnr_diff != 1)))
880 gmx_fatal(FARGS,"Residue numbers in the .top are not numbered consecutively from 1 (rather, resnumber = %d and resnr_diff = %d)",resnumber,resnr_diff);
883 * get new space for arrays
885 srenew(at->atom,nr+1);
886 srenew(at->atomname,nr+1);
887 srenew(at->atomtype,nr+1);
888 srenew(at->atomtypeB,nr+1);
890 if (resnumber > at->nres) {
892 srenew(at->resname,resnumber);
893 at->resname[resnumber-1] = put_symtab(symtab,resname);
896 at->atom[nr].type = type;
897 at->atom[nr].ptype = ptype;
900 at->atom[nr].typeB = typeB;
901 at->atom[nr].qB = qB;
902 at->atom[nr].mB = mB;
904 at->atom[nr].resnr = resnumber-1;
905 at->atom[nr].atomnumber = atomicnumber;
906 at->atomname[nr] = put_symtab(symtab,name);
907 at->atomtype[nr] = put_symtab(symtab,ctype);
908 at->atomtypeB[nr] = put_symtab(symtab,ctypeB);
912 void push_cg(t_block *block, int *lastindex, int index, int a)
915 fprintf (debug,"Index %d, Atom %d\n",index,a);
917 if (((block->nr) && (*lastindex != index)) || (!block->nr)) {
918 /* add a new block */
920 srenew(block->index,block->nr+1);
922 block->index[block->nr] = a + 1;
926 void push_atom(t_symtab *symtab,t_block *cgs,
927 t_atoms *at,t_atomtype atype,char *line,int *lastcg)
930 int resnumber,cgnumber,atomnr,type,typeB,nscan;
931 char id[STRLEN],ctype[STRLEN],ctypeB[STRLEN],
932 resname[STRLEN],name[STRLEN],check[STRLEN];
936 /* Make a shortcut for writing in this molecule */
939 /* Fixed parameters */
940 if (sscanf(line,"%s%s%d%s%s%d",
941 id,ctype,&resnumber,resname,name,&cgnumber) != 6) {
945 sscanf(id,"%d",&atomnr);
946 if ((type = get_atomtype_type(ctype,atype)) == NOTSET)
947 gmx_fatal(FARGS,"Atomtype %s not found",ctype);
948 ptype = get_atomtype_ptype(type,atype);
950 /* Set default from type */
951 q0 = get_atomtype_qA(type,atype);
952 m0 = get_atomtype_massA(type,atype);
957 /* Optional parameters */
958 nscan = sscanf(line,"%*s%*s%*s%*s%*s%*s%lf%lf%s%lf%lf%s",
959 &q,&m,ctypeB,&qb,&mb,check);
961 /* Nasty switch that falls thru all the way down! */
967 typeB=get_atomtype_type(ctypeB,atype);
968 qB = get_atomtype_qA(typeB,atype);
969 mB = get_atomtype_massA(typeB,atype);
975 warning_error("Too many parameters");
982 fprintf(debug,"mB=%g, qB=%g, typeB=%d\n",mB,qB,typeB);
984 push_cg(cgs,lastcg,cgnumber,nr);
986 push_atom_now(symtab,at,atomnr,get_atomtype_atomnumber(type,atype),
987 type,ctype,ptype,resnumber,cgnumber,
988 resname,name,m0,q0,typeB,
989 typeB==type ? ctype : ctypeB,mB,qB);
992 void push_molt(t_symtab *symtab,int *nmol,t_molinfo **mol,char *line)
998 if ((sscanf(line,"%s%d",type,&nrexcl)) != 2) {
999 warning_error("Expected a molecule type name and nrexcl");
1002 /* Test if this atomtype overwrites another */
1005 if (strcasecmp(*((*mol)[i].name),type) == 0)
1006 gmx_fatal(FARGS,"moleculetype %s is redefined",type);
1012 newmol = &((*mol)[*nmol-1]);
1013 init_molinfo(newmol);
1015 /* Fill in the values */
1016 newmol->name = put_symtab(symtab,type);
1017 newmol->nrexcl = nrexcl;
1018 newmol->excl_set = FALSE;
1021 static bool default_nb_params(int ftype,t_params bt[],t_atoms *at,
1022 t_param *p,int c_start,bool bB,bool bGenPairs)
1024 int i,j,ti,tj,ntype;
1027 int nr = bt[ftype].nr;
1028 int nral = NRAL(ftype);
1029 int nrfp = interaction_function[ftype].nrfpA;
1030 int nrfpB= interaction_function[ftype].nrfpB;
1032 if ((!bB && nrfp == 0) || (bB && nrfpB == 0))
1037 /* First test the generated-pair position to save
1038 * time when we have 1000*1000 entries for e.g. OPLS...
1042 ti=at->atom[p->a[0]].typeB;
1043 tj=at->atom[p->a[1]].typeB;
1045 ti=at->atom[p->a[0]].type;
1046 tj=at->atom[p->a[1]].type;
1048 pi=&(bt[ftype].param[ntype*ti+tj]);
1049 bFound=((ti == pi->a[0]) && (tj == pi->a[1]));
1052 /* Search explicitly if we didnt find it */
1054 for (i=0; ((i < nr) && !bFound); i++) {
1055 pi=&(bt[ftype].param[i]);
1057 for (j=0; ((j < nral) &&
1058 (at->atom[p->a[j]].typeB == pi->a[j])); j++);
1060 for (j=0; ((j < nral) &&
1061 (at->atom[p->a[j]].type == pi->a[j])); j++);
1068 if (nrfp+nrfpB > MAXFORCEPARAM) {
1069 gmx_incons("Too many force parameters");
1071 for (j=c_start; (j < nrfpB); j++)
1072 p->c[nrfp+j] = pi->c[j];
1075 for (j=c_start; (j < nrfp); j++)
1079 for (j=c_start; (j < nrfp); j++)
1086 static bool default_params(int ftype,t_params bt[],
1087 t_atoms *at,t_atomtype atype,
1089 t_param **param_def,
1092 int i,j,nparam_found;
1096 int nr = bt[ftype].nr;
1097 int nral = NRAL(ftype);
1098 int nrfpA= interaction_function[ftype].nrfpA;
1099 int nrfpB= interaction_function[ftype].nrfpB;
1101 if ((!bB && nrfpA == 0) || (bB && nrfpB == 0))
1105 /* We allow wildcards now. The first type (with or without wildcards) that
1106 * fits is used, so you should probably put the wildcarded bondtypes
1107 * at the end of each section.
1111 /* OPLS uses 1000s of dihedraltypes, so in order to speed up the scanning we have a
1112 * special case for this. Check for B state outside loop to speed it up.
1114 if( ftype==F_PDIHS || ftype == F_RBDIHS || ftype == F_IDIHS)
1118 for (i=0; ((i < nr) && !bFound); i++)
1120 pi=&(bt[ftype].param[i]);
1123 ((pi->AI==-1) || (get_atomtype_batype(at->atom[p->AI].typeB,atype)==pi->AI)) &&
1124 ((pi->AJ==-1) || (get_atomtype_batype(at->atom[p->AJ].typeB,atype)==pi->AJ)) &&
1125 ((pi->AK==-1) || (get_atomtype_batype(at->atom[p->AK].typeB,atype)==pi->AK)) &&
1126 ((pi->AL==-1) || (get_atomtype_batype(at->atom[p->AL].typeB,atype)==pi->AL))
1133 for (i=0; ((i < nr) && !bFound); i++)
1135 pi=&(bt[ftype].param[i]);
1138 ((pi->AI==-1) || (get_atomtype_batype(at->atom[p->AI].type,atype)==pi->AI)) &&
1139 ((pi->AJ==-1) || (get_atomtype_batype(at->atom[p->AJ].type,atype)==pi->AJ)) &&
1140 ((pi->AK==-1) || (get_atomtype_batype(at->atom[p->AK].type,atype)==pi->AK)) &&
1141 ((pi->AL==-1) || (get_atomtype_batype(at->atom[p->AL].type,atype)==pi->AL))
1145 /* Find additional matches for this dihedral - necessary for ftype==9 which is used e.g. for charmm.
1146 * The rules in that case is that additional matches HAVE to be on adjacent lines!
1152 /* Continue from current i value */
1153 for(j=i ; j<nr && bSame ; j++)
1155 pj=&(bt[ftype].param[j]);
1156 bSame = (pi->AI == pj->AI && pi->AJ == pj->AJ && pi->AK == pj->AK && pi->AL == pj->AL);
1159 /* nparam_found will be increased as long as the numbers match */
1162 } else { /* Not a dihedral */
1163 for (i=0; ((i < nr) && !bFound); i++) {
1164 pi=&(bt[ftype].param[i]);
1166 for (j=0; ((j < nral) &&
1167 (get_atomtype_batype(at->atom[p->a[j]].typeB,atype)==pi->a[j])); j++)
1170 for (j=0; ((j < nral) &&
1171 (get_atomtype_batype(at->atom[p->a[j]].type,atype)==pi->a[j])); j++)
1180 *nparam_def = nparam_found;
1187 void push_bond(directive d,t_params bondtype[],t_params bond[],
1188 t_atoms *at,t_atomtype atype,char *line,
1189 bool bBonded,bool bGenPairs,real fudgeQQ,
1190 bool bZero,bool *bWarn_copy_A_B)
1192 const char *aaformat[MAXATOMLIST]= {
1199 const char *asformat[MAXATOMLIST]= {
1204 "%*s%*s%*s%*s%*s%*s"
1206 const char *ccformat="%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf";
1207 int nr,i,j,nral,nread,ftype;
1208 char format[STRLEN];
1209 /* One force parameter more, so we can check if we read too many */
1210 double cc[MAXFORCEPARAM+1];
1211 int aa[MAXATOMLIST+1];
1212 t_param param,paramB,*param_defA,*param_defB;
1213 bool bFoundA=FALSE,bFoundB=FALSE,bDef,bPert,bSwapParity=FALSE;
1214 int nparam_defA,nparam_defB;
1217 nparam_defA=nparam_defB=0;
1219 ftype = ifunc_index(d,1);
1221 for(j=0; j<MAXATOMLIST; j++)
1223 bDef = (NRFP(ftype) > 0);
1225 nread = sscanf(line,aaformat[nral-1],
1226 &aa[0],&aa[1],&aa[2],&aa[3],&aa[4],&aa[5]);
1230 } else if (nread == nral)
1231 ftype = ifunc_index(d,1);
1233 /* this is a hack to allow for virtual sites with swapped parity */
1234 bSwapParity = (aa[nral]<0);
1236 aa[nral] = -aa[nral];
1237 ftype = ifunc_index(d,aa[nral]);
1244 gmx_fatal(FARGS,"Negative function types only allowed for %s and %s",
1245 interaction_function[F_VSITE3FAD].longname,
1246 interaction_function[F_VSITE3OUT].longname);
1250 /* Check for double atoms and atoms out of bounds */
1251 for(i=0; (i<nral); i++) {
1252 if ( aa[i] < 1 || aa[i] > at->nr )
1253 gmx_fatal(FARGS,"[ file %s, line %d ]:\n"
1254 "Atom index (%d) in %s out of bounds (1-%d).\n"
1255 "This probably means that you have inserted topology section \"%s\"\n"
1256 "in a part belonging to a different molecule than you intended to.\n"
1257 "In that case move the \"%s\" section to the right molecule.",
1258 get_warning_file(),get_warning_line(),
1259 aa[i],dir2str(d),at->nr,dir2str(d),dir2str(d));
1260 for(j=i+1; (j<nral); j++)
1261 if (aa[i] == aa[j]) {
1262 sprintf(errbuf,"Duplicate atom index (%d) in %s",aa[i],dir2str(d));
1266 if (ftype == F_SETTLE)
1267 if (aa[0]+2 > at->nr)
1268 gmx_fatal(FARGS,"[ file %s, line %d ]:\n"
1269 " Atom index (%d) in %s out of bounds (1-%d)\n"
1270 " Settle works on atoms %d, %d and %d",
1271 get_warning_file(),get_warning_line(),
1272 aa[0],dir2str(d),at->nr,
1273 aa[0],aa[0]+1,aa[0]+2);
1275 /* default force parameters */
1276 for(j=0; (j<MAXATOMLIST); j++)
1277 param.a[j] = aa[j]-1;
1278 for(j=0; (j<MAXFORCEPARAM); j++)
1281 /* Get force params for normal and free energy perturbation
1282 * studies, as determined by types!
1285 bFoundA = default_params(ftype,bondtype,at,atype,¶m,FALSE,¶m_defA,&nparam_defA);
1287 /* Copy the A-state and B-state default parameters */
1288 for(j=0; (j<NRFPA(ftype)+NRFPB(ftype)); j++)
1289 param.c[j] = param_defA->c[j];
1291 bFoundB = default_params(ftype,bondtype,at,atype,¶m,TRUE,¶m_defB,&nparam_defB);
1293 /* Copy only the B-state default parameters */
1294 for(j=NRFPA(ftype); (j<NRFP(ftype)); j++)
1295 param.c[j] = param_defB->c[j];
1297 } else if (ftype == F_LJ14) {
1298 bFoundA = default_nb_params(ftype, bondtype,at,¶m,0,FALSE,bGenPairs);
1299 bFoundB = default_nb_params(ftype, bondtype,at,¶m,0,TRUE, bGenPairs);
1300 } else if (ftype == F_LJC14_Q) {
1301 param.c[0] = fudgeQQ;
1302 /* Fill in the A-state charges as default parameters */
1303 param.c[1] = at->atom[param.a[0]].q;
1304 param.c[2] = at->atom[param.a[1]].q;
1305 /* The default LJ parameters are the standard 1-4 parameters */
1306 bFoundA = default_nb_params(F_LJ14,bondtype,at,¶m,3,FALSE,bGenPairs);
1308 } else if (ftype == F_LJC_PAIRS_NB) {
1309 /* Defaults are not supported here */
1313 gmx_incons("Unknown function type in push_bond");
1317 /* Manually specified parameters - in this case we discard multiple torsion info! */
1319 strcpy(format,asformat[nral-1]);
1320 strcat(format,ccformat);
1322 nread = sscanf(line,format,&cc[0],&cc[1],&cc[2],&cc[3],&cc[4],&cc[5],
1323 &cc[6],&cc[7],&cc[8],&cc[9],&cc[10],&cc[11],&cc[12]);
1325 if ((nread == NRFPA(ftype)) && (NRFPB(ftype) != 0))
1327 /* We only have to issue a warning if these atoms are perturbed! */
1329 for(j=0; (j<nral); j++)
1330 bPert = bPert || PERTURBED(at->atom[param.a[j]]);
1332 if (bPert && *bWarn_copy_A_B)
1335 "Some parameters for bonded interaction involving perturbed atoms are specified explicitly in state A, but not B - copying A to B");
1337 *bWarn_copy_A_B = FALSE;
1340 /* If only the A parameters were specified, copy them to the B state */
1341 /* The B-state parameters correspond to the first nrfpB
1342 * A-state parameters.
1344 for(j=0; (j<NRFPB(ftype)); j++)
1345 cc[nread++] = cc[j];
1348 /* If nread was 0 or EOF, no parameters were read => use defaults.
1349 * If nread was nrfpA we copied above so nread=nrfp.
1350 * If nread was nrfp we are cool.
1351 * For F_LJC14_Q we allow supplying fudgeQQ only.
1352 * Anything else is an error!
1354 if ((nread != 0) && (nread != EOF) && (nread != NRFP(ftype)) &&
1355 !(ftype == F_LJC14_Q && nread == 1))
1357 gmx_fatal(FARGS,"Incorrect number of parameters - found %d, expected %d or %d for %s.",
1358 nread,NRFPA(ftype),NRFP(ftype),
1359 interaction_function[ftype].longname);
1362 for(j=0; (j<nread); j++)
1365 /* Check whether we have to use the defaults */
1366 if (nread == NRFP(ftype))
1373 /* nread now holds the number of force parameters read! */
1381 /* When we have multiple terms it would be very dangerous to allow perturbations to a different atom type! */
1384 if ((nparam_defA != nparam_defB) || ((nparam_defA>1 || nparam_defB>1) && (param_defA!=param_defB)))
1387 "Cannot automatically perturb a torsion with multiple terms to different form.\n"
1388 "Please specify perturbed parameters manually for this torsion in your topology!");
1389 warning_error(errbuf);
1393 if (nread > 0 && nread < NRFPA(ftype))
1395 /* Issue an error, do not use defaults */
1396 sprintf(errbuf,"Not enough parameters, there should be at least %d (or 0 for defaults)",NRFPA(ftype));
1397 warning_error(errbuf);
1400 if (nread == 0 || nread == EOF)
1404 if (interaction_function[ftype].flags & IF_VSITE)
1406 /* set them to NOTSET, will be calculated later */
1407 for(j=0; (j<MAXFORCEPARAM); j++)
1408 param.c[j] = NOTSET;
1411 param.C1 = -1; /* flag to swap parity of vsite construction */
1417 fprintf(stderr,"NOTE: No default %s types, using zeroes\n",
1418 interaction_function[ftype].longname);
1422 sprintf(errbuf,"No default %s types",interaction_function[ftype].longname);
1423 warning_error(errbuf);
1434 param.C0 = 360 - param.C0;
1437 param.C2 = -param.C2;
1444 /* We only have to issue a warning if these atoms are perturbed! */
1446 for(j=0; (j<nral); j++)
1447 bPert = bPert || PERTURBED(at->atom[param.a[j]]);
1451 sprintf(errbuf,"No default %s types for perturbed atoms, "
1452 "using normal values",interaction_function[ftype].longname);
1459 if ((ftype==F_PDIHS || ftype==F_ANGRES || ftype==F_ANGRESZ)
1460 && param.c[5]!=param.c[2])
1461 gmx_fatal(FARGS,"[ file %s, line %d ]:\n"
1462 " %s multiplicity can not be perturbed %f!=%f",
1463 get_warning_file(),get_warning_line(),
1464 interaction_function[ftype].longname,
1465 param.c[2],param.c[5]);
1467 if (IS_TABULATED(ftype) && param.c[2]!=param.c[0])
1468 gmx_fatal(FARGS,"[ file %s, line %d ]:\n"
1469 " %s table number can not be perturbed %d!=%d",
1470 get_warning_file(),get_warning_line(),
1471 interaction_function[ftype].longname,
1472 (int)(param.c[0]+0.5),(int)(param.c[2]+0.5));
1474 /* Dont add R-B dihedrals where all parameters are zero (no interaction) */
1475 if (ftype==F_RBDIHS) {
1477 for(i=0;i<NRFP(ftype);i++) {
1485 /* Put the values in the appropriate arrays */
1486 push_bondnow (&bond[ftype],¶m);
1488 if (IS_TABULATED(ftype) && param.c[2]!=param.c[0])
1489 gmx_fatal(FARGS,"[ file %s, line %d ]:\n"
1490 " %s table number can not be perturbed %d!=%d",
1491 get_warning_file(),get_warning_line(),
1492 interaction_function[ftype].longname,
1493 (int)(param.c[0]+0.5),(int)(param.c[2]+0.5));
1495 /* Dont add R-B dihedrals where all parameters are zero (no interaction) */
1496 if (ftype==F_RBDIHS) {
1498 for(i=0;i<NRFP(ftype);i++) {
1506 /* Put the values in the appropriate arrays */
1507 add_param_to_list (&bond[ftype],¶m);
1509 /* Push additional torsions from FF for ftype==9 if we have them.
1510 * We have already checked that the A/B states do not differ in this case,
1511 * so we do not have to double-check that again, or the vsite stuff.
1512 * In addition, those torsions cannot be automatically perturbed.
1514 if(bDef && ftype==F_PDIHS)
1516 for(i=1;i<nparam_defA;i++)
1518 /* Advance pointer! */
1520 for(j=0; (j<NRFPA(ftype)+NRFPB(ftype)); j++)
1521 param.c[j] = param_defA->c[j];
1522 /* And push the next term for this torsion */
1523 push_bondnow (&bond[ftype],¶m);
1530 void push_vsitesn(directive d,t_params bondtype[],t_params bond[],
1531 t_atoms *at,t_atomtype atype,char *line)
1534 int type,ftype,j,n,ret,nj,a;
1536 double *weight=NULL,weight_tot;
1539 /* default force parameters */
1540 for(j=0; (j<MAXATOMLIST); j++)
1541 param.a[j] = NOTSET;
1542 for(j=0; (j<MAXFORCEPARAM); j++)
1546 ret = sscanf(ptr,"%d%n",&a,&n);
1549 gmx_fatal(FARGS,"[ file %s, line %d ]:\n"
1550 " Expected an atom index in section \"%s\"",
1551 get_warning_file(),get_warning_line(),
1556 ret = sscanf(ptr,"%d%n",&type,&n);
1558 ftype = ifunc_index(d,type);
1563 ret = sscanf(ptr,"%d%n",&a,&n);
1568 srenew(weight,nj+20);
1576 /* Here we use the A-state mass as a parameter.
1577 * Note that the B-state mass has no influence.
1579 weight[nj] = at->atom[atc[nj]].m;
1583 ret = sscanf(ptr,"%lf%n",&(weight[nj]),&n);
1586 gmx_fatal(FARGS,"[ file %s, line %d ]:\n"
1587 " No weight or negative weight found for vsiten constructing atom %d (atom index %d)",
1588 get_warning_file(),get_warning_line(),
1592 gmx_fatal(FARGS,"Unknown vsiten type %d",type);
1594 weight_tot += weight[nj];
1600 gmx_fatal(FARGS,"[ file %s, line %d ]:\n"
1601 " Expected more than one atom index in section \"%s\"",
1602 get_warning_file(),get_warning_line(),
1605 if (weight_tot == 0)
1606 gmx_fatal(FARGS,"[ file %s, line %d ]:\n"
1607 " The total mass of the construting atoms is zero",
1608 get_warning_file(),get_warning_line());
1610 for(j=0; j<nj; j++) {
1611 param.a[1] = atc[j];
1613 param.c[1] = weight[j]/weight_tot;
1614 /* Put the values in the appropriate arrays */
1615 add_param_to_list (&bond[ftype],¶m);
1622 void push_mol(int nrmols,t_molinfo mols[],char *pline,int *whichmol,
1629 if (sscanf(pline,"%s%d",type,&copies) != 2) {
1634 /* search moleculename */
1635 for (i=0; ((i<nrmols) && strcasecmp(type,*(mols[i].name))); i++)
1642 gmx_fatal(FARGS,"No such moleculetype %s",type);
1645 void init_block2(t_block2 *b2, int natom)
1650 snew(b2->nra,b2->nr);
1652 for(i=0; (i<b2->nr); i++)
1656 void done_block2(t_block2 *b2)
1661 for(i=0; (i<b2->nr); i++)
1669 void push_excl(char *line, t_block2 *b2)
1673 char base[STRLEN],format[STRLEN];
1675 if (sscanf(line,"%d",&i)==0)
1678 if ((1 <= i) && (i <= b2->nr))
1682 fprintf(debug,"Unbound atom %d\n",i-1);
1687 strcpy(format,base);
1688 strcat(format,"%d");
1689 n=sscanf(line,format,&j);
1691 if ((1 <= j) && (j <= b2->nr)) {
1693 srenew(b2->a[i],++(b2->nra[i]));
1694 b2->a[i][b2->nra[i]-1]=j;
1695 /* also add the reverse exclusion! */
1696 srenew(b2->a[j],++(b2->nra[j]));
1697 b2->a[j][b2->nra[j]-1]=i;
1701 gmx_fatal(FARGS,"Invalid Atomnr j: %d, b2->nr: %d\n",j,b2->nr);
1706 void b_to_b2(t_blocka *b, t_block2 *b2)
1711 for(i=0; (i<b->nr); i++)
1712 for(j=b->index[i]; (j<b->index[i+1]); j++) {
1714 srenew(b2->a[i],++b2->nra[i]);
1715 b2->a[i][b2->nra[i]-1]=a;
1719 void b2_to_b(t_block2 *b2, t_blocka *b)
1725 for(i=0; (i<b2->nr); i++) {
1727 for(j=0; (j<b2->nra[i]); j++)
1728 b->a[nra+j]=b2->a[i][j];
1731 /* terminate list */
1735 static int icomp(const void *v1, const void *v2)
1737 return (*((atom_id *) v1))-(*((atom_id *) v2));
1740 void merge_excl(t_blocka *excl, t_block2 *b2)
1748 else if (b2->nr != excl->nr) {
1749 gmx_fatal(FARGS,"DEATH HORROR: b2->nr = %d, while excl->nr = %d",
1753 fprintf(debug,"Entering merge_excl\n");
1755 /* First copy all entries from excl to b2 */
1758 /* Count and sort the exclusions */
1760 for(i=0; (i<b2->nr); i++) {
1761 if (b2->nra[i] > 0) {
1762 /* remove double entries */
1763 qsort(b2->a[i],(size_t)b2->nra[i],(size_t)sizeof(b2->a[i][0]),icomp);
1765 for(j=1; (j<b2->nra[i]); j++)
1766 if (b2->a[i][j]!=b2->a[i][k-1]) {
1767 b2->a[i][k]=b2->a[i][j];
1775 srenew(excl->a,excl->nra);
1780 int add_atomtype_decoupled(t_symtab *symtab,t_atomtype at,
1781 t_nbparam ***nbparam,t_nbparam ***pair)
1787 /* Define an atom type with all parameters set to zero (no interactions) */
1790 /* Type for decoupled atoms could be anything,
1791 * this should be changed automatically later when required.
1793 atom.ptype = eptAtom;
1794 for (i=0; (i<MAXFORCEPARAM); i++)
1797 nr = add_atomtype(at,symtab,&atom,"decoupled",¶m,-1,0.0,0.0,0.0,0);
1799 /* Add space in the non-bonded parameters matrix */
1800 realloc_nb_params(at,nbparam,pair);
1805 static void convert_pairs_to_pairsQ(t_params *plist,
1806 real fudgeQQ,t_atoms *atoms)
1812 /* Copy the pair list to the pairQ list */
1813 plist[F_LJC14_Q] = plist[F_LJ14];
1814 /* Empty the pair list */
1815 plist[F_LJ14].nr = 0;
1816 plist[F_LJ14].param = NULL;
1817 param = plist[F_LJC14_Q].param;
1818 for(i=0; i<plist[F_LJC14_Q].nr; i++) {
1821 param[i].c[0] = fudgeQQ;
1822 param[i].c[1] = atoms->atom[param[i].a[0]].q;
1823 param[i].c[2] = atoms->atom[param[i].a[1]].q;
1829 static void generate_LJCpairsNB(t_molinfo *mol,int nb_funct,t_params *nbp)
1838 atom = mol->atoms.atom;
1840 ntype = sqrt(nbp->nr);
1842 for (i=0; i<MAXATOMLIST; i++)
1843 param.a[i] = NOTSET;
1844 for (i=0; i<MAXFORCEPARAM; i++)
1845 param.c[i] = NOTSET;
1847 /* Add a pair interaction for all non-excluded atom pairs */
1849 for(i=0; i<n; i++) {
1850 for(j=i+1; j<n; j++) {
1852 for(k=excl->index[i]; k<excl->index[i+1]; k++) {
1853 if (excl->a[k] == j)
1857 if (nb_funct != F_LJ)
1858 gmx_fatal(FARGS,"Can only generate non-bonded pair interactions for Van der Waals type Lennard-Jones");
1861 param.c[0] = atom[i].q;
1862 param.c[1] = atom[j].q;
1863 param.c[2] = nbp->param[ntype*atom[i].type+atom[j].type].c[0];
1864 param.c[3] = nbp->param[ntype*atom[i].type+atom[j].type].c[1];
1865 add_param_to_list(&mol->plist[F_LJC_PAIRS_NB],¶m);
1871 static void set_excl_all(t_blocka *excl)
1875 /* Get rid of the current exclusions and exclude all atom pairs */
1877 excl->nra = nat*nat;
1878 srenew(excl->a,excl->nra);
1880 for(i=0; i<nat; i++) {
1882 for(j=0; j<nat; j++)
1885 excl->index[nat] = k;
1888 static void decouple_atoms(t_atoms *atoms,int atomtype_decouple,
1889 int couple_lam0,int couple_lam1)
1893 for(i=0; i<atoms->nr; i++) {
1894 if (couple_lam0 != ecouplamVDWQ)
1895 atoms->atom[i].q = 0.0;
1896 if (couple_lam0 == ecouplamNONE)
1897 atoms->atom[i].type = atomtype_decouple;
1898 if (couple_lam1 != ecouplamVDWQ)
1899 atoms->atom[i].qB = 0.0;
1900 if (couple_lam1 == ecouplamNONE)
1901 atoms->atom[i].typeB = atomtype_decouple;
1905 void convert_moltype_couple(t_molinfo *mol,int atomtype_decouple,real fudgeQQ,
1906 int couple_lam0,int couple_lam1,
1907 bool bCoupleIntra,int nb_funct,t_params *nbp)
1909 convert_pairs_to_pairsQ(mol->plist,fudgeQQ,&mol->atoms);
1910 if (!bCoupleIntra) {
1911 generate_LJCpairsNB(mol,nb_funct,nbp);
1912 set_excl_all(&mol->excls);
1914 decouple_atoms(&mol->atoms,atomtype_decouple,couple_lam0,couple_lam1);