Merge gromacs-4-6 into master
[alexxy/gromacs.git] / src / gromacs / gmxpreprocess / vsite_parm.c
index d2caced0a6341e98677b128932969c39373b6c5b..d0688eff9012c264760e13454c2f910aefc7f771 100644 (file)
@@ -317,6 +317,30 @@ static real get_angle(int nrang, t_mybonded angles[],
   return angle;
 }
 
+static char *get_atomtype_name_AB(t_atom *atom,gpp_atomtype_t atype)
+{
+    char *name;
+
+    name = get_atomtype_name(atom->type,atype);
+
+    /* When using the decoupling option, atom types are changed
+     * to decoupled for the non-bonded interactions, but the virtual
+     * sites constructions should be based on the "normal" interactions.
+     * So we return the state B atom type name if the state A atom
+     * type is the decoupled one. We should actually check for the atom
+     * type number, but that's not passed here. So we check for
+     * the decoupled atom type name. This should not cause trouble
+     * as this code is only used for topologies with v-sites without
+     * parameters generated by pdb2gmx.
+     */
+    if (strcmp(name,"decoupled") == 0)
+    {
+        name = get_atomtype_name(atom->typeB,atype);
+    }
+
+    return name;
+}
+
 static gmx_bool calc_vsite3_param(gpp_atomtype_t atype,
                              t_param *param, t_atoms *at,
                              int nrbond, t_mybonded *bonds,
@@ -336,14 +360,14 @@ static gmx_bool calc_vsite3_param(gpp_atomtype_t atype,
     for (i=0; i<4; i++)
       fprintf(debug,"atom %u type %s ",
              param->a[i]+1,
-             get_atomtype_name(at->atom[param->a[i]].type,atype));
+             get_atomtype_name_AB(&at->atom[param->a[i]],atype));
     fprintf(debug,"\n");
   }
   bXH3 = 
-    ( (gmx_strncasecmp(get_atomtype_name(at->atom[param->AK].type,atype),"MNH",3)==0) &&
-      (gmx_strncasecmp(get_atomtype_name(at->atom[param->AL].type,atype),"MNH",3)==0) ) ||
-    ( (gmx_strncasecmp(get_atomtype_name(at->atom[param->AK].type,atype),"MCH3",4)==0) &&
-      (gmx_strncasecmp(get_atomtype_name(at->atom[param->AL].type,atype),"MCH3",4)==0) );
+    ( (gmx_strncasecmp(get_atomtype_name_AB(&at->atom[param->AK],atype),"MNH",3)==0) &&
+      (gmx_strncasecmp(get_atomtype_name_AB(&at->atom[param->AL],atype),"MNH",3)==0) ) ||
+    ( (gmx_strncasecmp(get_atomtype_name_AB(&at->atom[param->AK],atype),"MCH3",4)==0) &&
+      (gmx_strncasecmp(get_atomtype_name_AB(&at->atom[param->AL],atype),"MCH3",4)==0) );
   
   bjk = get_bond_length(nrbond, bonds, param->AJ, param->AK);
   bjl = get_bond_length(nrbond, bonds, param->AJ, param->AL);
@@ -484,14 +508,14 @@ static gmx_bool calc_vsite3out_param(gpp_atomtype_t atype,
     int i;
     for (i=0; i<4; i++)
       fprintf(debug,"atom %u type %s ",
-             param->a[i]+1,get_atomtype_name(at->atom[param->a[i]].type,atype));
+             param->a[i]+1,get_atomtype_name_AB(&at->atom[param->a[i]],atype));
     fprintf(debug,"\n");
   }
   bXH3 = 
-    ( (gmx_strncasecmp(get_atomtype_name(at->atom[param->AK].type,atype),"MNH",3)==0) &&
-      (gmx_strncasecmp(get_atomtype_name(at->atom[param->AL].type,atype),"MNH",3)==0) ) ||
-    ( (gmx_strncasecmp(get_atomtype_name(at->atom[param->AK].type,atype),"MCH3",4)==0) &&
-      (gmx_strncasecmp(get_atomtype_name(at->atom[param->AL].type,atype),"MCH3",4)==0) );
+    ( (gmx_strncasecmp(get_atomtype_name_AB(&at->atom[param->AK],atype),"MNH",3)==0) &&
+      (gmx_strncasecmp(get_atomtype_name_AB(&at->atom[param->AL],atype),"MNH",3)==0) ) ||
+    ( (gmx_strncasecmp(get_atomtype_name_AB(&at->atom[param->AK],atype),"MCH3",4)==0) &&
+      (gmx_strncasecmp(get_atomtype_name_AB(&at->atom[param->AL],atype),"MCH3",4)==0) );
   
   /* check if construction parity must be swapped */  
   bSwapParity = ( param->C1 == -1 );