Remove unnecessary config.h includes
[alexxy/gromacs.git] / src / gromacs / mdlib / mdatom.c
index 2f50372cb534c4d2ec91321067f35e2ebb041427..ea59275ec10e2143156eaaf95a5ab72b11285dfc 100644 (file)
@@ -1,49 +1,49 @@
-/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
+/*
+ * This file is part of the GROMACS molecular simulation package.
  *
- *
- *                This source code is part of
- *
- *                 G   R   O   M   A   C   S
- *
- *          GROningen MAchine for Chemical Simulations
- *
- *                        VERSION 3.2.0
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
  * of the License, or (at your option) any later version.
  *
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
  *
- * For more info, check our website at http://www.gromacs.org
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
  *
- * And Hey:
- * GROwing Monsters And Cloning Shrimps
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
  */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "typedefs.h"
-#include "mdatoms.h"
-#include "smalloc.h"
-#include "main.h"
-#include "qmmm.h"
-#include "mtop_util.h"
-#include "gmx_omp_nthreads.h"
+#include "gmxpre.h"
+
+#include <math.h>
+
+#include "gromacs/legacyheaders/typedefs.h"
+#include "gromacs/legacyheaders/mdatoms.h"
+#include "gromacs/utility/smalloc.h"
+#include "gromacs/legacyheaders/qmmm.h"
+#include "gromacs/topology/mtop_util.h"
+#include "gromacs/legacyheaders/gmx_omp_nthreads.h"
 
 #define ALMOST_ZERO 1e-30
 
@@ -82,6 +82,10 @@ t_mdatoms *init_mdatoms(FILE *fp, gmx_mtop_t *mtop, gmx_bool bFreeEnergy)
             {
                 md->nChargePerturbed++;
             }
+            if (atom->typeB != atom->type)
+            {
+                md->nTypePerturbed++;
+            }
         }
 
         tmA += atom->m;
@@ -105,26 +109,29 @@ t_mdatoms *init_mdatoms(FILE *fp, gmx_mtop_t *mtop, gmx_bool bFreeEnergy)
 
 void atoms2md(gmx_mtop_t *mtop, t_inputrec *ir,
               int nindex, int *index,
-              int start, int homenr,
+              int homenr,
               t_mdatoms *md)
 {
+    gmx_bool              bLJPME;
     gmx_mtop_atomlookup_t alook;
     int                   i;
     t_grpopts            *opts;
     gmx_groups_t         *groups;
     gmx_molblock_t       *molblock;
 
+    bLJPME = EVDW_PME(ir->vdwtype);
+
     opts = &ir->opts;
 
     groups = &mtop->groups;
 
     molblock = mtop->molblock;
 
-    /* Index==NULL indicates particle decomposition,
-     * unless we have an empty DD node, so also check for homenr and start.
-     * This should be signaled properly with an extra parameter or nindex==-1.
+    /* Index==NULL indicates no DD (unless we have a DD node with no
+     * atoms), so also check for homenr. This should be
+     * signaled properly with an extra parameter or nindex==-1.
      */
-    if (index == NULL && (homenr > 0 || start > 0))
+    if (index == NULL && (homenr > 0))
     {
         md->nr = mtop->natoms;
     }
@@ -145,9 +152,21 @@ void atoms2md(gmx_mtop_t *mtop, t_inputrec *ir,
         srenew(md->massT, md->nalloc);
         srenew(md->invmass, md->nalloc);
         srenew(md->chargeA, md->nalloc);
+        if (bLJPME)
+        {
+            srenew(md->sqrt_c6A, md->nalloc);
+            srenew(md->sigmaA, md->nalloc);
+            srenew(md->sigma3A, md->nalloc);
+        }
         if (md->nPerturbed)
         {
             srenew(md->chargeB, md->nalloc);
+            if (bLJPME)
+            {
+                srenew(md->sqrt_c6B, md->nalloc);
+                srenew(md->sigmaB, md->nalloc);
+                srenew(md->sigma3B, md->nalloc);
+            }
         }
         srenew(md->typeA, md->nalloc);
         if (md->nPerturbed)
@@ -216,6 +235,7 @@ void atoms2md(gmx_mtop_t *mtop, t_inputrec *ir,
     {
         int      g, ag, molb;
         real     mA, mB, fac;
+        real     c6, c12;
         t_atom  *atom;
 
         if (index == NULL)
@@ -298,13 +318,43 @@ void atoms2md(gmx_mtop_t *mtop, t_inputrec *ir,
         {
             md->invmass[i]    = 1.0/mA;
         }
-        md->chargeA[i]  = atom->q;
-        md->typeA[i]    = atom->type;
+        md->chargeA[i]      = atom->q;
+        md->typeA[i]        = atom->type;
+        if (bLJPME)
+        {
+            c6                = mtop->ffparams.iparams[atom->type*(mtop->ffparams.atnr+1)].lj.c6;
+            c12               = mtop->ffparams.iparams[atom->type*(mtop->ffparams.atnr+1)].lj.c12;
+            md->sqrt_c6A[i]   = sqrt(c6);
+            if (c6 == 0.0 || c12 == 0)
+            {
+                md->sigmaA[i] = 1.0;
+            }
+            else
+            {
+                md->sigmaA[i] = pow(c12/c6, 1.0/6.0);
+            }
+            md->sigma3A[i]    = 1/(md->sigmaA[i]*md->sigmaA[i]*md->sigmaA[i]);
+        }
         if (md->nPerturbed)
         {
+            md->bPerturbed[i] = PERTURBED(*atom);
             md->chargeB[i]    = atom->qB;
             md->typeB[i]      = atom->typeB;
-            md->bPerturbed[i] = PERTURBED(*atom);
+            if (bLJPME)
+            {
+                c6                = mtop->ffparams.iparams[atom->typeB*(mtop->ffparams.atnr+1)].lj.c6;
+                c12               = mtop->ffparams.iparams[atom->typeB*(mtop->ffparams.atnr+1)].lj.c12;
+                md->sqrt_c6B[i]   = sqrt(c6);
+                if (c6 == 0.0 || c12 == 0)
+                {
+                    md->sigmaB[i] = 1.0;
+                }
+                else
+                {
+                    md->sigmaB[i] = pow(c12/c6, 1.0/6.0);
+                }
+                md->sigma3B[i]    = 1/(md->sigmaB[i]*md->sigmaB[i]*md->sigmaB[i]);
+            }
         }
         md->ptype[i]    = atom->ptype;
         if (md->cTC)
@@ -371,7 +421,6 @@ void atoms2md(gmx_mtop_t *mtop, t_inputrec *ir,
 
     gmx_mtop_atomlookup_destroy(alook);
 
-    md->start  = start;
     md->homenr = homenr;
     md->lambda = 0;
 }