Remove unnecessary config.h includes
[alexxy/gromacs.git] / src / gromacs / mdlib / mdebin.c
index cd25c50709cb7a4c64f25e2376c01dc1b668e6d9..84f24ac4380c9883748b43785edce1ef277c4d83 100644 (file)
@@ -1,64 +1,64 @@
-/* -*- 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) 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 "gmxpre.h"
 
-#include <string.h>
 #include <float.h>
-#include "typedefs.h"
-#include "string2.h"
-#include "mdebin.h"
-#include "smalloc.h"
-#include "physics.h"
+#include <stdlib.h>
+#include <string.h>
+
+#include "gromacs/legacyheaders/typedefs.h"
+#include "gromacs/legacyheaders/mdebin.h"
+#include "gromacs/math/units.h"
 #include "gromacs/fileio/enxio.h"
-#include "vec.h"
-#include "disre.h"
-#include "main.h"
-#include "network.h"
-#include "names.h"
-#include "orires.h"
-#include "constr.h"
-#include "mtop_util.h"
-#include "xvgr.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/legacyheaders/disre.h"
+#include "gromacs/legacyheaders/network.h"
+#include "gromacs/legacyheaders/names.h"
+#include "gromacs/legacyheaders/orires.h"
+#include "gromacs/legacyheaders/constr.h"
+#include "gromacs/topology/mtop_util.h"
+#include "gromacs/fileio/xvgr.h"
 #include "gromacs/fileio/gmxfio.h"
-#include "macros.h"
-#include "mdrun.h"
+#include "gromacs/legacyheaders/macros.h"
+#include "gromacs/legacyheaders/mdrun.h"
 #include "mdebin_bar.h"
 
+#include "gromacs/pbcutil/pbc.h"
+#include "gromacs/utility/smalloc.h"
 
 static const char *conrmsd_nm[] = { "Constr. rmsd", "Constr.2 rmsd" };
 
@@ -223,6 +223,10 @@ t_mdebin *init_mdebin(ener_file_t       fp_ene,
         {
             md->bEner[i] = EEL_FULL(ir->coulombtype);
         }
+        else if (i == F_LJ_RECIP)
+        {
+            md->bEner[i] = EVDW_PME(ir->vdwtype);
+        }
         else if (i == F_LJ14)
         {
             md->bEner[i] = b14;
@@ -543,7 +547,7 @@ t_mdebin *init_mdebin(ener_file_t       fp_ene,
     {
         ni = groups->grps[egcTC].nm_ind[i];
         sprintf(buf, "T-%s", *(groups->grpname[ni]));
-        grpnms[i] = strdup(buf);
+        grpnms[i] = gmx_strdup(buf);
     }
     md->itemp = get_ebin_space(md->ebin, md->nTC, (const char **)grpnms,
                                unit_temp_K);
@@ -561,9 +565,9 @@ t_mdebin *init_mdebin(ener_file_t       fp_ene,
                     for (j = 0; (j < md->nNHC); j++)
                     {
                         sprintf(buf, "Xi-%d-%s", j, bufi);
-                        grpnms[2*(i*md->nNHC+j)] = strdup(buf);
+                        grpnms[2*(i*md->nNHC+j)] = gmx_strdup(buf);
                         sprintf(buf, "vXi-%d-%s", j, bufi);
-                        grpnms[2*(i*md->nNHC+j)+1] = strdup(buf);
+                        grpnms[2*(i*md->nNHC+j)+1] = gmx_strdup(buf);
                     }
                 }
                 md->itc = get_ebin_space(md->ebin, md->mde_n,
@@ -576,9 +580,9 @@ t_mdebin *init_mdebin(ener_file_t       fp_ene,
                         for (j = 0; (j < md->nNHC); j++)
                         {
                             sprintf(buf, "Xi-%d-%s", j, bufi);
-                            grpnms[2*(i*md->nNHC+j)] = strdup(buf);
+                            grpnms[2*(i*md->nNHC+j)] = gmx_strdup(buf);
                             sprintf(buf, "vXi-%d-%s", j, bufi);
-                            grpnms[2*(i*md->nNHC+j)+1] = strdup(buf);
+                            grpnms[2*(i*md->nNHC+j)+1] = gmx_strdup(buf);
                         }
                     }
                     md->itcb = get_ebin_space(md->ebin, md->mdeb_n,
@@ -592,9 +596,9 @@ t_mdebin *init_mdebin(ener_file_t       fp_ene,
                     ni   = groups->grps[egcTC].nm_ind[i];
                     bufi = *(groups->grpname[ni]);
                     sprintf(buf, "Xi-%s", bufi);
-                    grpnms[2*i] = strdup(buf);
+                    grpnms[2*i] = gmx_strdup(buf);
                     sprintf(buf, "vXi-%s", bufi);
-                    grpnms[2*i+1] = strdup(buf);
+                    grpnms[2*i+1] = gmx_strdup(buf);
                 }
                 md->itc = get_ebin_space(md->ebin, md->mde_n,
                                          (const char **)grpnms, unit_invtime);
@@ -608,7 +612,7 @@ t_mdebin *init_mdebin(ener_file_t       fp_ene,
         {
             ni = groups->grps[egcTC].nm_ind[i];
             sprintf(buf, "Lamb-%s", *(groups->grpname[ni]));
-            grpnms[i] = strdup(buf);
+            grpnms[i] = gmx_strdup(buf);
         }
         md->itc = get_ebin_space(md->ebin, md->mde_n, (const char **)grpnms, "");
     }
@@ -624,11 +628,11 @@ t_mdebin *init_mdebin(ener_file_t       fp_ene,
         {
             ni = groups->grps[egcACC].nm_ind[i];
             sprintf(buf, "Ux-%s", *(groups->grpname[ni]));
-            grpnms[3*i+XX] = strdup(buf);
+            grpnms[3*i+XX] = gmx_strdup(buf);
             sprintf(buf, "Uy-%s", *(groups->grpname[ni]));
-            grpnms[3*i+YY] = strdup(buf);
+            grpnms[3*i+YY] = gmx_strdup(buf);
             sprintf(buf, "Uz-%s", *(groups->grpname[ni]));
-            grpnms[3*i+ZZ] = strdup(buf);
+            grpnms[3*i+ZZ] = gmx_strdup(buf);
         }
         md->iu = get_ebin_space(md->ebin, 3*md->nU, (const char **)grpnms, unit_vel);
         sfree(grpnms);
@@ -729,7 +733,7 @@ static void print_lambda_vector(t_lambda *fep, int i,
     if (Nsep > 1)
     {
         /* and add the closing parenthesis */
-        str += sprintf(str, ")");
+        sprintf(str, ")");
     }
 }
 
@@ -785,7 +789,7 @@ extern FILE *open_dhdl(const char *filename, const t_inputrec *ir,
         bufplace = sprintf(buf, "T = %g (K) ",
                            ir->opts.ref_t[0]);
     }
-    if (ir->efep != efepSLOWGROWTH)
+    if ((ir->efep != efepSLOWGROWTH) && (ir->efep != efepEXPANDED))
     {
         if ( (fep->init_lambda >= 0)  && (n_lambda_terms == 1 ))
         {
@@ -821,7 +825,7 @@ extern FILE *open_dhdl(const char *filename, const t_inputrec *ir,
         nsets += 1;   /*add fep state for expanded ensemble */
     }
 
-    if (fep->bPrintEnergy)
+    if (fep->edHdLPrintEnergy != edHdLPrintEnergyNO)
     {
         nsets += 1;  /* add energy to the dhdl as well */
     }
@@ -842,14 +846,23 @@ extern FILE *open_dhdl(const char *filename, const t_inputrec *ir,
     {
         /* state for the fep_vals, if we have alchemical sampling */
         sprintf(buf, "%s", "Thermodynamic state");
-        setname[s] = strdup(buf);
+        setname[s] = gmx_strdup(buf);
         s         += 1;
     }
 
-    if (fep->bPrintEnergy)
+    if (fep->edHdLPrintEnergy != edHdLPrintEnergyNO)
     {
-        sprintf(buf, "%s (%s)", "Energy", unit_energy);
-        setname[s] = strdup(buf);
+        switch (fep->edHdLPrintEnergy)
+        {
+            case edHdLPrintEnergyPOTENTIAL:
+                sprintf(buf, "%s (%s)", "Potential Energy", unit_energy);
+                break;
+            case edHdLPrintEnergyTOTAL:
+            case edHdLPrintEnergyYES:
+            default:
+                sprintf(buf, "%s (%s)", "Total Energy", unit_energy);
+        }
+        setname[s] = gmx_strdup(buf);
         s         += 1;
     }
 
@@ -875,7 +888,7 @@ extern FILE *open_dhdl(const char *filename, const t_inputrec *ir,
                     sprintf(buf, "%s %s = %.4f", dhdl, efpt_singular_names[i],
                             lam);
                 }
-                setname[s] = strdup(buf);
+                setname[s] = gmx_strdup(buf);
                 s         += 1;
             }
         }
@@ -896,7 +909,7 @@ extern FILE *open_dhdl(const char *filename, const t_inputrec *ir,
             nsetsbegin = 0;
         }
 
-        if (fep->bPrintEnergy)
+        if (fep->edHdLPrintEnergy != edHdLPrintEnergyNO)
         {
             nsetsbegin += 1;
         }
@@ -922,14 +935,14 @@ extern FILE *open_dhdl(const char *filename, const t_inputrec *ir,
                         ir->simtempvals->temperatures[s-(nsetsbegin)],
                         unit_temp_K);
             }
-            setname[s] = strdup(buf);
+            setname[s] = gmx_strdup(buf);
             s++;
         }
         if (write_pV)
         {
             np                     = sprintf(buf, "pV (%s)", unit_energy);
-            setname[nsetsextend-1] = strdup(buf);  /* the first entry after
-                                                      nsets */
+            setname[nsetsextend-1] = gmx_strdup(buf);  /* the first entry after
+                                                          nsets */
         }
 
         xvgr_legend(fp, nsetsextend, (const char **)setname, oenv);
@@ -1204,9 +1217,19 @@ void upd_mdebin(t_mdebin       *md,
                 fprintf(md->fp_dhdl, " %4d", state->fep_state);
             }
             /* total energy (for if the temperature changes */
-            if (fep->bPrintEnergy)
+
+            if (fep->edHdLPrintEnergy != edHdLPrintEnergyNO)
             {
-                store_energy = enerd->term[F_ETOT];
+                switch (fep->edHdLPrintEnergy)
+                {
+                    case edHdLPrintEnergyPOTENTIAL:
+                        store_energy = enerd->term[F_EPOT];
+                        break;
+                    case edHdLPrintEnergyTOTAL:
+                    case edHdLPrintEnergyYES:
+                    default:
+                        store_energy = enerd->term[F_ETOT];
+                }
                 fprintf(md->fp_dhdl, " %#.8g", store_energy);
             }
 
@@ -1297,7 +1320,7 @@ static void pprint(FILE *log, const char *s, t_mdebin *md)
     fprintf(log, "\n");
 }
 
-void print_ebin_header(FILE *log, gmx_large_int_t steps, double time, real lambda)
+void print_ebin_header(FILE *log, gmx_int64_t steps, double time, real lambda)
 {
     char buf[22];
 
@@ -1308,7 +1331,7 @@ void print_ebin_header(FILE *log, gmx_large_int_t steps, double time, real lambd
 
 void print_ebin(ener_file_t fp_ene, gmx_bool bEne, gmx_bool bDR, gmx_bool bOR,
                 FILE *log,
-                gmx_large_int_t step, double time,
+                gmx_int64_t step, double time,
                 int mode, gmx_bool bCompact,
                 t_mdebin *md, t_fcdata *fcd,
                 gmx_groups_t *groups, t_grpopts *opts)
@@ -1431,7 +1454,6 @@ void print_ebin(ener_file_t fp_ene, gmx_bool bEne, gmx_bool bDR, gmx_bool bOR,
 
                 /* do the actual I/O */
                 do_enx(fp_ene, &fr);
-                gmx_fio_check_file_position(enx_file_pointer(fp_ene));
                 if (fr.nre)
                 {
                     /* We have stored the sums, so reset the sum history */
@@ -1525,7 +1547,7 @@ void print_ebin(ener_file_t fp_ene, gmx_bool bEne, gmx_bool bDR, gmx_bool bOR,
                             nj = groups->grps[egcENER].nm_ind[j];
                             sprintf(buf, "%s-%s", *(groups->grpname[ni]),
                                     *(groups->grpname[nj]));
-                            md->print_grpnms[n++] = strdup(buf);
+                            md->print_grpnms[n++] = gmx_strdup(buf);
                         }
                     }
                 }