Clean up cshake() and resolve old issues
[alexxy/gromacs.git] / src / gromacs / mdlib / clincs.c
index 86071ea9584cb74fb08abba93286e708de556be7..a239df22bbd01651742355e87b5001424d5fd80d 100644 (file)
@@ -1,59 +1,61 @@
-/* -*- 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.
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 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.
  *
- * 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
+ * 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.
  */
 /* This file is completely threadsafe - keep it that way! */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "gmxpre.h"
 
 #include <math.h>
-#include "main.h"
-#include "constr.h"
-#include "copyrite.h"
-#include "physics.h"
-#include "vec.h"
-#include "pbc.h"
-#include "smalloc.h"
-#include "mdrun.h"
-#include "nrnb.h"
-#include "domdec.h"
-#include "partdec.h"
-#include "mtop_util.h"
-#include "gmxfio.h"
-#include "gmx_omp_nthreads.h"
-#include "gmx_omp.h"
+#include <stdlib.h>
+
+#include "gromacs/fileio/gmxfio.h"
+#include "gromacs/legacyheaders/constr.h"
+#include "gromacs/legacyheaders/copyrite.h"
+#include "gromacs/legacyheaders/domdec.h"
+#include "gromacs/legacyheaders/gmx_omp_nthreads.h"
+#include "gromacs/legacyheaders/mdrun.h"
+#include "gromacs/legacyheaders/nrnb.h"
+#include "gromacs/legacyheaders/types/commrec.h"
+#include "gromacs/math/units.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/pbcutil/pbc.h"
+#include "gromacs/topology/block.h"
+#include "gromacs/topology/mtop_util.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/gmxomp.h"
+#include "gromacs/utility/smalloc.h"
 
 typedef struct {
     int    b0;         /* first constraint for this thread */
@@ -530,10 +532,6 @@ static void do_lincs(rvec *x, rvec *xp, matrix box, t_pbc *pbc,
     {
         nlocat = dd_constraints_nlocalatoms(cr->dd);
     }
-    else if (PARTDECOMP(cr))
-    {
-        nlocat = pd_constraints_nlocalatoms(cr->pd);
-    }
     else
     {
         nlocat = NULL;
@@ -620,8 +618,7 @@ static void do_lincs(rvec *x, rvec *xp, matrix box, t_pbc *pbc,
 
     for (iter = 0; iter < lincsd->nIter; iter++)
     {
-        if ((lincsd->bCommIter && DOMAINDECOMP(cr) && cr->dd->constraints) ||
-            PARTDECOMP(cr))
+        if ((lincsd->bCommIter && DOMAINDECOMP(cr) && cr->dd->constraints))
         {
 #pragma omp barrier
 #pragma omp master
@@ -629,11 +626,7 @@ static void do_lincs(rvec *x, rvec *xp, matrix box, t_pbc *pbc,
                 /* Communicate the corrected non-local coordinates */
                 if (DOMAINDECOMP(cr))
                 {
-                    dd_move_x_constraints(cr->dd, box, xp, NULL);
-                }
-                else
-                {
-                    pd_move_x_constraints(cr, xp, NULL);
+                    dd_move_x_constraints(cr->dd, box, xp, NULL, FALSE);
                 }
             }
         }
@@ -654,6 +647,7 @@ static void do_lincs(rvec *x, rvec *xp, matrix box, t_pbc *pbc,
             dlen2 = 2*len2 - norm2(dx);
             if (dlen2 < wfac*len2 && (nlocat == NULL || nlocat[b]))
             {
+                /* not race free - see detailed comment in caller */
                 *warn = b;
             }
             if (dlen2 > 0)
@@ -1203,13 +1197,9 @@ void set_lincs(t_idef *idef, t_mdatoms *md,
         }
         start = 0;
     }
-    else if (PARTDECOMP(cr))
-    {
-        pd_get_constraint_range(cr->pd, &start, &natoms);
-    }
     else
     {
-        start  = md->start;
+        start  = 0;
         natoms = md->homenr;
     }
     at2con = make_at2con(start, natoms, idef->il, idef->iparams, bDynamics,
@@ -1468,46 +1458,9 @@ static void cconerr(gmx_domdec_t *dd,
     *imax      = im;
 }
 
-static void dump_conf(gmx_domdec_t *dd, struct gmx_lincsdata *li,
-                      t_blocka *at2con,
-                      char *name, gmx_bool bAll, rvec *x, matrix box)
-{
-    char  str[STRLEN];
-    FILE *fp;
-    int   ac0, ac1, i;
-
-    dd_get_constraint_range(dd, &ac0, &ac1);
-
-    sprintf(str, "%s_%d_%d_%d.pdb", name, dd->ci[XX], dd->ci[YY], dd->ci[ZZ]);
-    fp = gmx_fio_fopen(str, "w");
-    fprintf(fp, "CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f P 1           1\n",
-            10*norm(box[XX]), 10*norm(box[YY]), 10*norm(box[ZZ]),
-            90.0, 90.0, 90.0);
-    for (i = 0; i < ac1; i++)
-    {
-        if (i < dd->nat_home || (bAll && i >= ac0 && i < ac1))
-        {
-            fprintf(fp, "%-6s%5u  %-4.4s%3.3s %c%4d    %8.3f%8.3f%8.3f%6.2f%6.2f\n",
-                    "ATOM", ddglatnr(dd, i), "C", "ALA", ' ', i+1,
-                    10*x[i][XX], 10*x[i][YY], 10*x[i][ZZ],
-                    1.0, i < dd->nat_tot ? 0.0 : 1.0);
-        }
-    }
-    if (bAll)
-    {
-        for (i = 0; i < li->nc; i++)
-        {
-            fprintf(fp, "CONECT%5d%5d\n",
-                    ddglatnr(dd, li->bla[2*i]),
-                    ddglatnr(dd, li->bla[2*i+1]));
-        }
-    }
-    gmx_fio_fclose(fp);
-}
-
 gmx_bool constrain_lincs(FILE *fplog, gmx_bool bLog, gmx_bool bEner,
                          t_inputrec *ir,
-                         gmx_large_int_t step,
+                         gmx_int64_t step,
                          struct gmx_lincsdata *lincsd, t_mdatoms *md,
                          t_commrec *cr,
                          rvec *x, rvec *xprime, rvec *min_proj,
@@ -1620,6 +1573,7 @@ gmx_bool constrain_lincs(FILE *fplog, gmx_bool bLog, gmx_bool bEner,
         {
             real dt_2, dvdl = 0;
 
+            /* TODO This should probably use invdt, so that sd integrator scaling works properly */
             dt_2 = 1.0/(ir->delta_t*ir->delta_t);
             for (i = 0; (i < lincsd->nc); i++)
             {