Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / mdlib / shellfc.c
index 4bcc5cc6f74f6776ba345759e860b06978ab0eb5..ce00047a385e027f53baf857f9d1c25cd3b244df 100644 (file)
@@ -1,62 +1,66 @@
 /*
+ * 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
- *
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2008, 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-2008, 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.
+ *
+ * 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:
- * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
+ * 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 "gmxpre.h"
+
+#include "gromacs/legacyheaders/shellfc.h"
 
+#include <stdlib.h>
 #include <string.h>
-#include "typedefs.h"
-#include "smalloc.h"
-#include "gmx_fatal.h"
-#include "vec.h"
-#include "txtdump.h"
-#include "mdrun.h"
-#include "partdec.h"
-#include "mdatoms.h"
-#include "vsite.h"
-#include "network.h"
-#include "names.h"
-#include "constr.h"
-#include "domdec.h"
-#include "partdec.h"
-#include "physics.h"
-#include "copyrite.h"
-#include "shellfc.h"
-#include "mtop_util.h"
-#include "chargegroup.h"
-#include "macros.h"
 
+#include "gromacs/legacyheaders/chargegroup.h"
+#include "gromacs/legacyheaders/constr.h"
+#include "gromacs/legacyheaders/domdec.h"
+#include "gromacs/legacyheaders/force.h"
+#include "gromacs/legacyheaders/macros.h"
+#include "gromacs/legacyheaders/mdatoms.h"
+#include "gromacs/legacyheaders/mdrun.h"
+#include "gromacs/legacyheaders/names.h"
+#include "gromacs/legacyheaders/network.h"
+#include "gromacs/legacyheaders/txtdump.h"
+#include "gromacs/legacyheaders/typedefs.h"
+#include "gromacs/legacyheaders/vsite.h"
+#include "gromacs/legacyheaders/types/commrec.h"
+#include "gromacs/math/units.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/pbcutil/mshift.h"
+#include "gromacs/pbcutil/pbc.h"
+#include "gromacs/topology/mtop_util.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/smalloc.h"
 
 typedef struct {
     int     nnucl;
@@ -277,6 +281,7 @@ gmx_shellfc_t init_shell_flexcon(FILE *fplog,
 
     if (nshell == 0 && nflexcon == 0)
     {
+        /* We're not doing shells or flexible constraints */
         return NULL;
     }
 
@@ -523,6 +528,12 @@ gmx_shellfc_t init_shell_flexcon(FILE *fplog,
             {
                 fprintf(fplog, "\nNOTE: there all shells that are connected to particles outside thier own charge group, will not predict shells positions during the run\n\n");
             }
+            /* Prediction improves performance, so we should implement either:
+             * 1. communication for the atoms needed for prediction
+             * 2. prediction using the velocities of shells; currently the
+             *    shell velocities are zeroed, it's a bit tricky to keep
+             *    track of the shell displacements and thus the velocity.
+             */
             shfc->bPredict = FALSE;
         }
     }
@@ -537,18 +548,11 @@ void make_local_shells(t_commrec *cr, t_mdatoms *md,
     int           a0, a1, *ind, nshell, i;
     gmx_domdec_t *dd = NULL;
 
-    if (PAR(cr))
+    if (DOMAINDECOMP(cr))
     {
-        if (DOMAINDECOMP(cr))
-        {
-            dd = cr->dd;
-            a0 = 0;
-            a1 = dd->nat_home;
-        }
-        else
-        {
-            pd_at_range(cr, &a0, &a1);
-        }
+        dd = cr->dd;
+        a0 = 0;
+        a1 = dd->nat_home;
     }
     else
     {
@@ -580,6 +584,7 @@ void make_local_shells(t_commrec *cr, t_mdatoms *md,
             {
                 shell[nshell] = shfc->shell_gl[ind[i]];
             }
+
             /* With inter-cg shells we can no do shell prediction,
              * so we do not need the nuclei numbers.
              */
@@ -640,7 +645,7 @@ static void do_1pos3(rvec xnew, rvec xold, rvec f, rvec step)
     xnew[ZZ] = zo+dz;
 }
 
-static void directional_sd(FILE *log, rvec xold[], rvec xnew[], rvec acc_dir[],
+static void directional_sd(rvec xold[], rvec xnew[], rvec acc_dir[],
                            int start, int homenr, real step)
 {
     int  i;
@@ -651,7 +656,7 @@ static void directional_sd(FILE *log, rvec xold[], rvec xnew[], rvec acc_dir[],
     }
 }
 
-static void shell_pos_sd(FILE *log, rvec xcur[], rvec xnew[], rvec f[],
+static void shell_pos_sd(rvec xcur[], rvec xnew[], rvec f[],
                          int ns, t_shell s[], int count)
 {
     const real step_scale_min       = 0.8,
@@ -748,7 +753,7 @@ static void decrease_step_size(int nshell, t_shell s[])
     }
 }
 
-static void print_epot(FILE *fp, gmx_large_int_t mdstep, int count, real epot, real df,
+static void print_epot(FILE *fp, gmx_int64_t mdstep, int count, real epot, real df,
                        int ndir, real sf_dir)
 {
     char buf[22];
@@ -833,7 +838,7 @@ static void dump_shells(FILE *fp, rvec x[], rvec f[], real ftol, int ns, t_shell
 static void init_adir(FILE *log, gmx_shellfc_t shfc,
                       gmx_constr_t constr, t_idef *idef, t_inputrec *ir,
                       t_commrec *cr, int dd_ac1,
-                      gmx_large_int_t step, t_mdatoms *md, int start, int end,
+                      gmx_int64_t step, t_mdatoms *md, int start, int end,
                       rvec *x_old, rvec *x_init, rvec *x,
                       rvec *f, rvec *acc_dir,
                       gmx_bool bMolPBC, matrix box,
@@ -887,11 +892,11 @@ static void init_adir(FILE *log, gmx_shellfc_t shfc,
             }
         }
     }
-    constrain(log, FALSE, FALSE, constr, idef, ir, NULL, cr, step, 0, md,
+    constrain(log, FALSE, FALSE, constr, idef, ir, NULL, cr, step, 0, 1.0, md,
               x, xnold-start, NULL, bMolPBC, box,
               lambda[efptBONDED], &(dvdlambda[efptBONDED]),
               NULL, NULL, nrnb, econqCoord, FALSE, 0, 0);
-    constrain(log, FALSE, FALSE, constr, idef, ir, NULL, cr, step, 0, md,
+    constrain(log, FALSE, FALSE, constr, idef, ir, NULL, cr, step, 0, 1.0, md,
               x, xnew-start, NULL, bMolPBC, box,
               lambda[efptBONDED], &(dvdlambda[efptBONDED]),
               NULL, NULL, nrnb, econqCoord, FALSE, 0, 0);
@@ -908,18 +913,16 @@ static void init_adir(FILE *log, gmx_shellfc_t shfc,
     }
 
     /* Project the acceleration on the old bond directions */
-    constrain(log, FALSE, FALSE, constr, idef, ir, NULL, cr, step, 0, md,
+    constrain(log, FALSE, FALSE, constr, idef, ir, NULL, cr, step, 0, 1.0, md,
               x_old, xnew-start, acc_dir, bMolPBC, box,
               lambda[efptBONDED], &(dvdlambda[efptBONDED]),
               NULL, NULL, nrnb, econqDeriv_FlexCon, FALSE, 0, 0);
 }
 
 int relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
-                        gmx_large_int_t mdstep, t_inputrec *inputrec,
+                        gmx_int64_t mdstep, t_inputrec *inputrec,
                         gmx_bool bDoNS, int force_flags,
-                        gmx_bool bStopCM,
                         gmx_localtop_t *top,
-                        gmx_mtop_t* mtop,
                         gmx_constr_t constr,
                         gmx_enerdata_t *enerd, t_fcdata *fcd,
                         t_state *state, rvec f[],
@@ -932,7 +935,7 @@ int relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
                         t_forcerec *fr,
                         gmx_bool bBornRadii,
                         double t, rvec mu_tot,
-                        int natoms, gmx_bool *bConverged,
+                        gmx_bool *bConverged,
                         gmx_vsite_t *vsite,
                         FILE *fp_field)
 {
@@ -947,7 +950,7 @@ int relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
     char       sbuf[22];
     gmx_bool   bCont, bInit;
     int        nat, dd_ac0, dd_ac1 = 0, i;
-    int        start = md->start, homenr = md->homenr, end = start+homenr, cg0, cg1;
+    int        start = 0, homenr = md->homenr, end = start+homenr, cg0, cg1;
     int        nflexcon, g, number_steps, d, Min = 0, count = 0;
 #define  Try (1-Min)             /* At start Try = 1 */
 
@@ -991,34 +994,31 @@ int relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
         force[i] = shfc->f[i];
     }
 
-    /* With particle decomposition this code only works
-     * when all particles involved with each shell are in the same cg.
-     */
-
     if (bDoNS && inputrec->ePBC != epbcNONE && !DOMAINDECOMP(cr))
     {
         /* This is the only time where the coordinates are used
          * before do_force is called, which normally puts all
          * charge groups in the box.
          */
-        if (PARTDECOMP(cr))
+        if (inputrec->cutoff_scheme == ecutsVERLET)
         {
-            pd_cg_range(cr, &cg0, &cg1);
+            put_atoms_in_box_omp(fr->ePBC, state->box, md->homenr, state->x);
         }
         else
         {
             cg0 = 0;
             cg1 = top->cgs.nr;
+            put_charge_groups_in_box(fplog, cg0, cg1, fr->ePBC, state->box,
+                                     &(top->cgs), state->x, fr->cg_cm);
         }
-        put_charge_groups_in_box(fplog, cg0, cg1, fr->ePBC, state->box,
-                                 &(top->cgs), state->x, fr->cg_cm);
+
         if (graph)
         {
             mk_mshift(fplog, graph, fr->ePBC, state->box, state->x);
         }
     }
 
-    /* After this all coordinate arrays will contain whole molecules */
+    /* After this all coordinate arrays will contain whole charge groups */
     if (graph)
     {
         shift_self(graph, state->box, state->x);
@@ -1062,7 +1062,7 @@ int relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
     {
         pr_rvecs(debug, 0, "x b4 do_force", state->x + start, homenr);
     }
-    do_force(fplog, cr, inputrec, mdstep, nrnb, wcycle, top, mtop, groups,
+    do_force(fplog, cr, inputrec, mdstep, nrnb, wcycle, top, groups,
              state->box, state->x, &state->hist,
              force[Min], force_vir, md, enerd, fcd,
              state->lambda, graph,
@@ -1133,9 +1133,9 @@ int relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
     {
         if (vsite)
         {
-            construct_vsites(fplog, vsite, pos[Min], nrnb, inputrec->delta_t, state->v,
+            construct_vsites(vsite, pos[Min], inputrec->delta_t, state->v,
                              idef->iparams, idef->il,
-                             fr->ePBC, fr->bMolPBC, graph, cr, state->box);
+                             fr->ePBC, fr->bMolPBC, cr, state->box);
         }
 
         if (nflexcon)
@@ -1145,12 +1145,12 @@ int relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
                       x_old-start, state->x, pos[Min], force[Min], acc_dir-start,
                       fr->bMolPBC, state->box, state->lambda, &dum, nrnb);
 
-            directional_sd(fplog, pos[Min], pos[Try], acc_dir-start, start, end,
+            directional_sd(pos[Min], pos[Try], acc_dir-start, start, end,
                            fr->fc_stepsize);
         }
 
         /* New positions, Steepest descent */
-        shell_pos_sd(fplog, pos[Min], pos[Try], force[Min], nshell, shell, count);
+        shell_pos_sd(pos[Min], pos[Try], force[Min], nshell, shell, count);
 
         /* do_force expected the charge groups to be in the box */
         if (graph)
@@ -1165,7 +1165,7 @@ int relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
         }
         /* Try the new positions */
         do_force(fplog, cr, inputrec, 1, nrnb, wcycle,
-                 top, mtop, groups, state->box, pos[Try], &state->hist,
+                 top, groups, state->box, pos[Try], &state->hist,
                  force[Try], force_vir,
                  md, enerd, fcd, state->lambda, graph,
                  fr, vsite, mu_tot, t, fp_field, NULL, bBornRadii,