Merge branch release-5-0
authorMark Abraham <mark.j.abraham@gmail.com>
Thu, 9 Apr 2015 08:41:01 +0000 (10:41 +0200)
committerMark Abraham <mark.j.abraham@gmail.com>
Thu, 9 Apr 2015 08:43:17 +0000 (10:43 +0200)
Change-Id: Ice890f6d9b0235bc2f07e5c73ee2264a32f18a86

1  2 
CMakeLists.txt
cmake/gmxTestCXX11.cmake
docs/manual/forcefield.tex
src/gromacs/gmxana/gmx_hbond.c
src/gromacs/gmxlib/txtdump.c
src/gromacs/gmxpreprocess/toputil.c
src/gromacs/mdlib/coupling.cpp

diff --combined CMakeLists.txt
index abc899722eb5b874dd1dfbd711f6a6a44e03a67f,4a2650bb7d30b93a4d78c55870ca0880d01f54a6..79e7f1ef2fa0c4f11af6ac40d0c554c2e100cf24
@@@ -48,28 -48,75 +48,28 @@@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CM
  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  
 -# PROJECT_VERSION should have the following structure:
 -# VERSION-dev[-SUFFIX] where the VERSION should have the for: vMajor.vMinor.vPatch
 -#
 -# The "-dev" suffix is important to keep because it makes possible to distinguish
 -# between a build from official release and a build from git release branch on a
 -# machine with no git.
 -#
 -# NOTE: when releasing the "-dev" suffix needs to be stripped off!
 -# REGRESSIONTEST_VERSION and REGRESSIONTEST_BRANCH should always be
 -# defined.
 -set(PROJECT_VERSION "5.0.5-dev")
 -# If this is a released tarball, "-dev" will not be present in
 -# PROJECT_VERSION, and REGRESSIONTEST_VERSION specifies the version
 -# number of the regressiontest tarball against which the code tarball
 -# can be tested. This will be the version of the last patch release.
 -set(REGRESSIONTEST_VERSION "5.0.5-dev")
 -# The MD5 checksum of the regressiontest tarball. Only used if "-dev"
 -# is not present in the PROJECT_VERSION
 -set(REGRESSIONTEST_MD5SUM "81e8ff1600495ce2a57706dca9d73482")
 -# If this is not a released tarball, "-dev" will be present in
 -# PROJECT_VERSION, and REGRESSIONTEST_BRANCH specifies the name of the
 -# gerrit.gromacs.org branch whose HEAD can test this code, *if* this
 -# code contains all recent fixes from the corresponding code branch.
 -set(REGRESSIONTEST_BRANCH "refs/heads/release-5-0")
 -
 -set(CUSTOM_VERSION_STRING ""
 -    CACHE STRING "Custom version string (if empty, use hard-coded default)")
 -mark_as_advanced(CUSTOM_VERSION_STRING)
 -if (CUSTOM_VERSION_STRING)
 -    set(PROJECT_VERSION ${CUSTOM_VERSION_STRING})
 -endif()
 -set(LIBRARY_SOVERSION 0)
 -set(LIBRARY_VERSION ${LIBRARY_SOVERSION}.0.0)
 -# It is a bit irritating, but this has to be set separately for now!
 -SET(CPACK_PACKAGE_VERSION_MAJOR "5")
 -SET(CPACK_PACKAGE_VERSION_MINOR "0")
 -#SET(CPACK_PACKAGE_VERSION_PATCH "0")
 -
 -# The numerical gromacs version. It is 40600 for 4.6.0.
 -# The #define GMX_VERSION in gromacs/version.h is set to this value.
 -math(EXPR NUM_VERSION
 -    "${CPACK_PACKAGE_VERSION_MAJOR}*10000 + ${CPACK_PACKAGE_VERSION_MINOR}*100")
 -if(CPACK_PACKAGE_VERSION_PATCH)
 -    math(EXPR NUM_VERSION
 -         "${NUM_VERSION} + ${CPACK_PACKAGE_VERSION_PATCH}")
 -endif()
 -
 -# The API version tracks the numerical Gromacs version (for now).
 -# It is potentially different from the Gromacs version in the future, if
 -# the programs/libraries diverge from the presumably more stable API.
 -# The #define GMX_API_VERSION in version.h is set to this value to
 -# provide backward compatibility of software written against the Gromacs API.
 -set(API_VERSION ${NUM_VERSION})
 +# Set up common version variables, as well as general information about
 +# the build tree (whether the build is from a source package or from a git
 +# repository).  Also declares a few functions that will be used for generating
 +# version info files later.
 +include(gmxVersionInfo)
  
  if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND UNIX)
      set(CMAKE_INSTALL_PREFIX "/usr/local/gromacs" CACHE STRING "Installation prefix (installation will need write permissions here)" FORCE)
  endif()
  
  include(gmxBuildTypeReference)
 +include(gmxBuildTypeProfile)
  include(gmxBuildTypeTSAN)
  include(gmxBuildTypeASAN)
  include(gmxBuildTypeReleaseWithAssert)
  
  if(NOT CMAKE_BUILD_TYPE)
 -    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Reference RelWithAssert." FORCE)
 +    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Reference RelWithAssert Profile." FORCE)
      # There's no need to offer a user the choice of ThreadSanitizer
      # Set the possible values of build type for cmake-gui
      set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
 -        "MinSizeRel" "RelWithDebInfo" "Reference" "RelWithAssert")
 +        "MinSizeRel" "RelWithDebInfo" "Reference" "RelWithAssert" "Profile")
  endif()
  if(CMAKE_CONFIGURATION_TYPES)
      # Add appropriate GROMACS-specific build types for the Visual
          "List of configuration types"
          FORCE)
  endif()
 -set(build_types_with_explicit_flags RELEASE DEBUG RELWITHDEBINFO RELWITHASSERT MINSIZEREL)
 +set(build_types_with_explicit_flags RELEASE DEBUG RELWITHDEBINFO RELWITHASSERT MINSIZEREL PROFILE)
  
 -enable_language(C)
 -enable_language(CXX)
  set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON)
  
 -set(CPACK_PACKAGE_NAME "gromacs")
 -set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
 -set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
 -set(CPACK_PACKAGE_VENDOR "gromacs.org")
 -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Gromacs - a toolkit for high-performance molecular simulation")
 -set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/admin/InstallWelcome.txt")
 -# Its GPL/LGPL, so they do not have to agree to a license for mere usage, but some installers require this...
 -set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
 -set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/admin/InstallInfo.txt")
 -set(CPACK_SOURCE_IGNORE_FILES "\\\\.isreposource$;\\\\.git/;\\\\.gitignore$;\\\\.gitattributes;")
 -set(CPACK_PROJECT_CONFIG_FILE "${CMAKE_SOURCE_DIR}/CPackInit.cmake")
 -# CPack source archives include only the directories we list here.
 -# This variable is a list of pairs of names of source and destination
 -# directories. Most of these are used for content GROMACS generates as
 -# part of the configuration or build.
 -set(CPACK_SOURCE_INSTALLED_DIRECTORIES "${CMAKE_SOURCE_DIR};/;${CMAKE_BINARY_DIR}/src/programs/completion;src/programs/completion;${CMAKE_BINARY_DIR}/docs/man/man1;docs/man/man1;${CMAKE_BINARY_DIR}/docs/man/man7;docs/man/man7;${CMAKE_BINARY_DIR}/docs/old-html/final;docs/old-html/final;${CMAKE_BINARY_DIR}/docs/install-guide/final;/")
 -set(CPACK_PACKAGE_CONTACT "gmx-users@gromacs.org")
 -set(CPACK_GMX_BUILD_HELP "${GMX_BUILD_HELP}") #Works even though GMX_BUILD_HELP is defined later because it is off by default.
 -
 -#must come after all cpack settings!
 -include(CPack)
 -
  # Set a default valgrind suppression file.
  # This unfortunately needs to duplicate information from CTest to work as
  # expected...
@@@ -94,12 -165,14 +94,12 @@@ set(MEMORYCHECK_SUPPRESSIONS_FIL
      "File that contains suppressions for the memory checker")
  include(CTest)
  
 -set(SOURCE_IS_GIT_REPOSITORY OFF)
 -set(SOURCE_IS_SOURCE_DISTRIBUTION OFF)
 -if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
 -    set(SOURCE_IS_GIT_REPOSITORY ON)
 -endif()
 -if(NOT EXISTS "${CMAKE_SOURCE_DIR}/admin/.isreposource")
 -    set(SOURCE_IS_SOURCE_DISTRIBUTION ON)
 -endif()
 +include(gmxCPackUtilities)
 +gmx_cpack_init()
 +
 +# Variables that accumulate stuff influencing the installed headers
 +set(INSTALLED_HEADER_INCLUDE_DIRS "")
 +set(INSTALLED_HEADER_DEFINITIONS "")
  
  ########################################################################
  # Check and warn if cache generated on a different host is being reused
@@@ -172,25 -245,30 +172,25 @@@ endif(
  set(REQUIRED_CUDA_COMPUTE_CAPABILITY 2.0)
  include(gmxManageGPU)
  
 -if(GMX_CPU_ACCELERATION)
 -    # Stay compatible with old Jenkins command line options for specific SIMD acceleration
 -    set(GMX_SIMD "${GMX_CPU_ACCELERATION}" CACHE STRING "SIMD instruction set level and compiler optimization" FORCE)
 -    message("You set GMX_CPU_ACCELERATION, which is deprecated, and will be removed in a later version of GROMACS. It is replaced by GMX_SIMD. For now, copying the value from GMX_CPU_ACCELERATION to GMX_SIMD.")
 -    # TODO remove all references to GMX_CPU_ACCELERATION in master branch
 -endif()
 -
 -if(NOT GMX_TARGET_MIC)
 -    include(gmxDetectSimd)
 -    gmx_detect_simd(GMX_SUGGESTED_SIMD)
 -else()
 -    set(GMX_SUGGESTED_SIMD "None")
 -endif()
 +include(gmxDetectSimd)
 +gmx_detect_simd(GMX_SUGGESTED_SIMD)
  
  gmx_option_multichoice(
      GMX_SIMD
      "SIMD instruction set for CPU kernels and compiler optimization"
      "${GMX_SUGGESTED_SIMD}"
 -    None SSE2 SSE4.1 AVX_128_FMA AVX_256 AVX2_256 IBM_QPX Sparc64_HPC_ACE Reference)
 +    None SSE2 SSE4.1 AVX_128_FMA AVX_256 AVX2_256 AVX_512F AVX_512ER MIC ARM_NEON ARM_NEON_ASIMD IBM_QPX IBM_VMX IBM_VSX Sparc64_HPC_ACE Reference)
 +
 +if(GMX_TARGET_MIC)
 +    set(GMX_FFT_LIBRARY_DEFAULT "mkl")
 +else()
 +    set(GMX_FFT_LIBRARY_DEFAULT "fftw3")
 +endif()
  
  gmx_option_multichoice(
      GMX_FFT_LIBRARY
      "FFT library"
 -    "fftw3"
 +    "${GMX_FFT_LIBRARY_DEFAULT}"
      fftw3 mkl "fftpack[built-in]")
  gmx_dependent_option(
      GMX_BUILD_OWN_FFTW
@@@ -226,6 -304,12 +226,6 @@@ option(GMX_OPENMP "Enable OpenMP-based 
  
  option(GMX_USE_TNG "Use the TNG library for trajectory I/O" ON)
  
 -option(GMX_GIT_VERSION_INFO "Generate git version information" ${SOURCE_IS_GIT_REPOSITORY})
 -mark_as_advanced(GMX_GIT_VERSION_INFO)
 -
 -if(UNIX)
 -    option(GMX_SYMLINK_OLD_BINARY_NAMES "Create symbolic links for pre-5.0 binary names" ON)
 -endif()
  option(GMX_BUILD_MDRUN_ONLY "Build and install only the mdrun binary" OFF)
  
  option(GMX_CYCLE_SUBCOUNTERS "Enable cycle subcounters to get a more detailed cycle timings" OFF)
@@@ -296,18 -380,20 +296,18 @@@ if(GMX_SIMD STREQUAL "AVX_256
  endif()
  
  
 -
 -set(PKG_CFLAGS "")
  if(GMX_DOUBLE)
      add_definitions(-DGMX_DOUBLE)
 -    set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_DOUBLE")
 +    list(APPEND INSTALLED_HEADER_DEFINITIONS "-DGMX_DOUBLE")
      if(GMX_RELAXED_DOUBLE_PRECISION)
          add_definitions(-DGMX_RELAXED_DOUBLE_PRECISION)
      endif()
  endif()
  if(GMX_SOFTWARE_INVSQRT)
 -  set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_SOFTWARE_INVSQRT")
 +    list(APPEND INSTALLED_HEADER_DEFINITIONS "-DGMX_SOFTWARE_INVSQRT")
  endif()
  
 -if(WIN32 AND NOT CYGWIN)
 +if(WIN32)
      list(APPEND GMX_EXTRA_LIBRARIES "wsock32")
      add_definitions(-DGMX_HAVE_WINSOCK)
  endif()
@@@ -328,7 -414,6 +328,6 @@@ check_include_files(io.h         HAVE_I
  check_include_files(sched.h      HAVE_SCHED_H)
  
  check_include_files(regex.h      HAVE_POSIX_REGEX)
- check_include_file_cxx(regex     HAVE_CXX11_REGEX)
  # TODO: It could be nice to inform the user if no regex support is found,
  # as selections won't be fully functional.
  
@@@ -346,12 -431,10 +345,12 @@@ check_function_exists(syscon
  check_function_exists(rsqrt             HAVE_RSQRT)
  check_function_exists(rsqrtf            HAVE_RSQRTF)
  check_function_exists(sqrtf             HAVE_SQRTF)
 +check_function_exists(nice              HAVE_NICE)
  
  include(CheckLibraryExists)
  check_library_exists(m sqrt "" HAVE_LIBM)
  check_library_exists(rt clock_gettime "" HAVE_CLOCK_GETTIME)
 +check_library_exists(m feenableexcept "" HAVE_FEENABLEEXCEPT)
  
  include(TestSchedAffinity)
  test_sched_affinity(HAVE_SCHED_AFFINITY)
  include(TestBigEndian)
  test_big_endian(GMX_INTEGER_BIG_ENDIAN)
  
 +set(GMX_USE_NICE 0)
 +if (HAVE_UNISTD_H AND HAVE_NICE)
 +    set(GMX_USE_NICE 1)
 +endif()
 +
  # Management of GROMACS options for specific toolchains should go
  # here. Because the initial settings for some of the main options have
  # already happened, but things like library detection and MPI compiler
@@@ -395,6 -473,11 +394,11 @@@ include(gmxManageSharedLibraries
  # Find external packages                                               #
  ########################################################################
  
+ # TNG wants zlib if it is available. And static libxml2 might have a dependency
+ find_package(ZLIB QUIET)
+ include(gmxTestZLib)
+ gmx_test_zlib(HAVE_ZLIB)
  # Unconditionally find the package, as it is also required for unit
  # tests. This exports LIBXML2_FOUND, which we should not use because
  # it does not tell us that linking will succeed. Instead, we test that
@@@ -452,6 -535,7 +456,6 @@@ tmpi_enable_cxx(
  if(GMX_THREAD_MPI)
      # enable MPI functions
      tmpi_enable()
 -    set(GMX_MPI 1)
      set(MPI_IN_PLACE_EXISTS 1)
  endif()
  # If atomics are manually disabled a define is needed because atomics.h doesn't depend on config.h
@@@ -468,19 -552,35 +472,19 @@@ if(CYGWIN
      set(GMX_CYGWIN 1)
  endif()
  
 -if(WIN32 AND NOT CYGWIN)
 +if(WIN32)
      set(GMX_NATIVE_WINDOWS 1)
      # This makes windows.h not declare min/max as macros that would break
      # C++ code using std::min/std::max.
      add_definitions(-DNOMINMAX)
  endif()
  
 -# only bother with finding git and using version.h if the source is a git repo
 -if(GMX_GIT_VERSION_INFO)
 -    if (NOT SOURCE_IS_GIT_REPOSITORY)
 -        message(FATAL_ERROR
 -            "Cannot generate git version information from source tree not under git. "
 -            "Set GMX_GIT_VERSION_INFO=OFF to proceed.")
 -    endif()
 -    # We need at least git v1.5.3 be able to parse git's date output. If not
 -    # found or the version is too small, we can't generate version information.
 -    find_package(Git)
 -
 -    if(NOT GIT_FOUND OR GIT_VERSION_STRING VERSION_LESS "1.5.3")
 -        message(FATAL_ERROR
 -            "No compatible git version found (>= 1.5.3 required). "
 -            "Won't be able to generate development version information. "
 -            "Set GMX_GIT_VERSION_INFO=OFF to proceed.")
 -    endif()
 -endif()
 -
  # Detect boost unless GMX_EXTERNAL_BOOST is explicitly OFF
  # Used for default if GMX_EXTERNAL_BOOST is not defined (first CMake pass)
  if(NOT DEFINED GMX_EXTERNAL_BOOST OR GMX_EXTERNAL_BOOST)
 +    if(DEFINED Boost_INCLUDE_DIR)
 +        set(Boost_FIND_QUIETLY TRUE)
 +    endif()
      find_package(Boost 1.44.0)
      if(Boost_FOUND AND Boost_VERSION VERSION_LESS "104400")
          set(Boost_FOUND FALSE)
@@@ -513,13 -613,12 +517,6 @@@ if (GMX_BUILD_UNITTESTS AND NOT HAVE_LI
          "Either set GMX_BUILD_UNITTESTS=OFF or tell CMake how to find a working version of libxml2.")
  endif()
  
- if(GMX_USE_TNG AND NOT GMX_EXTERNAL_TNG)
-     # TNG wants zlib if it is available
-     find_package(ZLIB QUIET)
-     include(gmxTestZLib)
-     gmx_test_zlib(HAVE_ZLIB)
- endif()
 -########################################################################
 -# Generate development version info for cache
 -########################################################################
 -# set(GEN_VERSION_INFO_INTERNAL "ON")
 -# include(gmxGenerateVersionString)
--
  ########################################################################
  # Our own GROMACS tests
  ########################################################################
@@@ -529,6 -628,10 +526,6 @@@ include_directories(BEFORE ${CMAKE_SOUR
  include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src/external/thread_mpi/include)
  # Required for config.h, maybe should only be set in src/CMakeLists.txt
  include_directories(BEFORE ${CMAKE_BINARY_DIR}/src)
 -# Required for gmx_header_config_gen.h to be found before installation
 -include_directories(BEFORE ${CMAKE_BINARY_DIR}/src/gromacs/utility)
 -# Required for now to make old code compile
 -include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src/gromacs/legacyheaders)
  
  include(gmxTestInlineASM)
  gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
@@@ -592,6 -695,8 +589,8 @@@ if(GMX_CXX11
      set(EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS} ${GMX_CXX11_FLAGS}")
  endif()
  
+ # Now we can test for CXX11_REGEX include file
+ check_include_file_cxx(regex     HAVE_CXX11_REGEX)
  
  include(gmxTestXDR)
  gmx_test_xdr(GMX_SYSTEM_XDR)
@@@ -604,12 -709,11 +603,12 @@@ endif(
  # Process SIMD instruction settings
  ##################################################
  # This checks what flags to add in order to
 -# support the SIMD instructions we need, and sets
 -# correct defines for the SIMD instructions supported.
 -include(gmxTestSimd)
 -gmx_test_simd()
 -
 +# support the SIMD instructions we need, it sets
 +# correct defines for the SIMD instructions supported,
 +# and adds advanced options to control accuracy
 +# for SIMD math operations.
 +include(gmxManageSimd)
 +gmx_manage_simd()
  
  # Process QM/MM Settings
  if(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
@@@ -639,14 -743,15 +638,14 @@@ include(gmxManageLinearAlgebraLibraries
  set(GMX_USE_PLUGINS OFF)
  
  if(GMX_LOAD_PLUGINS)
 -  if(CYGWIN OR NOT WIN32)
 +  if(NOT WIN32)
      # Native Windows does not have, nor need dlopen
 -    # Note that WIN32 is set with Cygwin, but Cygwin needs dlopen to use plug-ins
      include(gmxTestdlopen)
      gmx_test_dlopen(HAVE_DLOPEN)
    endif()
  
    # so, should we use plug-ins?
 -  if((WIN32 AND NOT CYGWIN) OR (HAVE_DLOPEN AND BUILD_SHARED_LIBS))
 +  if(WIN32 OR (HAVE_DLOPEN AND BUILD_SHARED_LIBS))
      if(NOT VMD_QUIETLY)
        MESSAGE(STATUS "Using dynamic plugins (e.g VMD-supported file formats)")
      endif()
@@@ -677,8 -782,7 +676,8 @@@ option(GMX_NACL "Configure for Native C
  if (GMX_NACL)
    list(APPEND GMX_EXTRA_LIBRARIES nosys)
    set(GMX_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lnosys")
 -  set(GMX_NO_NICE 1)
 +  # TODO: Is this still necessary with the check for its presence?
 +  set(GMX_USE_NICE 0)
    set(GMX_NO_RENAME 1)
  endif()
  mark_as_advanced(GMX_NACL)
@@@ -689,18 -793,14 +688,18 @@@ if(GMX_FAHCORE
    include_directories(${COREWRAP_INCLUDE_DIR})
  endif()
  
 -option(GMX_BUILD_HELP "Build man pages, HTML help, and completions automatically (requires that compiled binaries can be executed on the build host)" OFF)
 +# Value of GMX_BUILD_HELP=AUTO tries to generate things, but will only
 +# produce warnings if that fails.
 +set(build_help_default AUTO)
 +if (SOURCE_IS_SOURCE_DISTRIBUTION OR CMAKE_CROSSCOMPILING)
 +    set(build_help_default OFF)
 +endif()
 +gmx_option_trivalue(GMX_BUILD_HELP "Build completions automatically (requires that compiled binaries can be executed on the build host) and install man pages if built (requires building the 'man' target manually)" ${build_help_default})
  mark_as_advanced(GMX_BUILD_HELP)
 -if (GMX_BUILD_HELP AND SOURCE_IS_SOURCE_DISTRIBUTION AND
 -    "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
 -
 +if (GMX_BUILD_HELP AND SOURCE_IS_SOURCE_DISTRIBUTION AND BUILD_IS_INSOURCE)
      message(FATAL_ERROR
 -        "Rebuilding HTML and man pages is not supported for in-source "
 -        "builds from a source distribution. "
 +        "Rebuilding shell completions or man pages is not supported for "
 +        "in-source builds from a source distribution. "
          "Set GMX_BUILD_HELP=OFF or do an out-of-source build to proceed.")
  endif()
  
@@@ -732,6 -832,7 +731,6 @@@ else(
      set(GMX_EXE_LINKER_FLAGS ${GMX_EXE_LINKER_FLAGS} ${OpenMP_LINKER_FLAGS})
      set(GMX_SHARED_LINKER_FLAGS ${GMX_SHARED_LINKER_FLAGS} ${OpenMP_SHARED_LINKER_FLAGS})
  endif()
 -set(PKG_CFLAGS "${PKG_CFLAGS} ${OpenMP_C_FLAGS}")
  
  ########################################################################
  # Specify install locations
@@@ -748,20 -849,16 +747,20 @@@ mark_as_advanced(GMX_LIB_INSTALL_DIR GM
  
  # These variables are used internally to provide a central location for
  # customizing the install locations.
 -set(LIB_INSTALL_DIR  ${GMX_LIB_INSTALL_DIR})
 -set(BIN_INSTALL_DIR  bin)
 -set(DATA_INSTALL_DIR share/${GMX_DATA_INSTALL_DIR})
 -set(MAN_INSTALL_DIR  share/man)
 -set(INCL_INSTALL_DIR include)
 -
 -# These variables get written into config.h for use in finding the data
 +set(LIB_INSTALL_DIR       ${GMX_LIB_INSTALL_DIR})
 +set(BIN_INSTALL_DIR       bin)
 +# This variable also gets written into config.h for use in finding the data
  # directories.
 -set(GMXLIB_SEARCH_DIR share/${GMX_DATA_INSTALL_DIR}/top)
 -set(GMXLIB_FALLBACK   ${CMAKE_INSTALL_PREFIX}/${DATA_INSTALL_DIR}/top)
 +set(DATA_INSTALL_DIR      share/${GMX_DATA_INSTALL_DIR})
 +set(MAN_INSTALL_DIR       share/man)
 +# If the nesting level wrt. the installation root is changed,
 +# gromacs-config.cmake.cmakein needs to be adapted.
 +set(CMAKE_INSTALL_DIR     share/cmake)
 +# TODO: Make GMXRC adapt if this is changed
 +set(PKGCONFIG_INSTALL_DIR ${LIB_INSTALL_DIR}/pkgconfig)
 +set(INCL_INSTALL_DIR      include)
 +
 +list(APPEND INSTALLED_HEADER_INCLUDE_DIRS ${INCL_INSTALL_DIR})
  
  # Binary and library suffix options
  include(gmxManageSuffixes)
@@@ -808,14 -905,15 +807,14 @@@ install(FILES COPYING DESTINATION ${DAT
  
  if(GMX_EXTERNAL_BOOST)
      include_directories(${Boost_INCLUDE_DIRS})
 -    set(PKG_CFLAGS "${PKG_CFLAGS} -I${Boost_INCLUDE_DIRS}")
 +    list(APPEND INSTALLED_HEADER_INCLUDE_DIRS ${Boost_INCLUDE_DIRS})
  else()
      include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src/external/boost)
 +    list(APPEND INSTALLED_HEADER_INCLUDE_DIRS ${INCL_INSTALL_DIR}/gromacs/external/boost)
 +    list(APPEND INSTALLED_HEADED_DEFINITIONS "-DBOOST_NO_TYPEID")
      # typeid not supported for minimal internal version
      # (would add significant amount of code)
      add_definitions(-DBOOST_NO_TYPEID)
 -    # TODO: Propagate the above settings to the installed CMakeFiles.txt template
 -    # (from share/template/)
 -    set(PKG_CFLAGS "${PKG_CFLAGS} -DBOOST_NO_TYPEID -I${CMAKE_INSTALL_PREFIX}/${INCL_INSTALL_DIR}/gromacs/external/boost")
      if (NOT GMX_BUILD_MDRUN_ONLY)
          install(DIRECTORY ${CMAKE_SOURCE_DIR}/src/external/boost/boost
                  DESTINATION ${INCL_INSTALL_DIR}/gromacs/external/boost
@@@ -858,8 -956,6 +857,8 @@@ if (BUILD_TESTING
      add_subdirectory(tests)
  endif()
  
 +gmx_cpack_write_config()
 +
  # Issue a warning if NVIDIA GPUs were detected, but CUDA was not found.
  # Don't bother the user after the first configure pass.
  if ((CUDA_NOTFOUND_AUTO AND GMX_DETECT_GPU_AVAILABLE) AND NOT GMX_GPU_DETECTION_DONE)
diff --combined cmake/gmxTestCXX11.cmake
index 41e84c1d4eb9552633fdf873fae6a0ac2850604e,1c9ffbe6cfc5412b840b99a7b7698af2180e89ff..9dc57647be99f4884f6a5253fe3748990fd142f7
@@@ -1,7 -1,7 +1,7 @@@
  #
  # This file is part of the GROMACS molecular simulation package.
  #
- # Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ # Copyright (c) 2012,2013,2014,2015, 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.
@@@ -34,7 -34,7 +34,7 @@@
  
  include(CheckCXXSourceCompiles)
  MACRO(GMX_TEST_CXX11 VARIABLE FLAG)
 -    if(WIN32)
 +    if(WIN32 AND NOT MINGW)
          set(CXX11_FLAG "/Qstd=c++0x")
      elseif(CYGWIN)
          set(CXX11_FLAG "-std=gnu++0x") #required for strdup
@@@ -45,7 -45,7 +45,7 @@@
      if(NOT CXXFLAG_STD_CXX0X)
          set(CXX11_FLAG "")
      endif()
-     set(CMAKE_REQUIRED_DEFINITIONS "${CXX11_FLAG}")
+     set(CMAKE_REQUIRED_FLAGS "${CXX11_FLAG}")
      check_cxx_source_compiles(
  "#include <vector>
  #include <memory>
@@@ -59,7 -59,6 +59,7 @@@ struct VarList 
    typedef VarList<Tail...> VarListTail;
    typedef std::pair<Head, typename VarListTail::ListType> ListType;
  };
 +class a { explicit operator bool() {return true;} };
  int main() {
    typedef std::unique_ptr<int> intPointer;
    intPointer p(new int(10));
@@@ -69,7 -68,7 +69,7 @@@
    v2.push_back(A());  //requires default move constructor
    v2.push_back(A(new int(5))); //detects bug in ICC
  }" ${VARIABLE})
-     set(CMAKE_REQUIRED_DEFINITIONS "")
+     set(CMAKE_REQUIRED_FLAGS "")
      if(${VARIABLE})
          set(${FLAG} ${CXX11_FLAG})
      endif()
index 94c84ffeaf1c30499d5f06556f2108b32dbe24b6,13e7e6b33ba8271ba2ba8d148213c832a2e15e6e..7e835ae7fb3c15b492697991ea5ac6afa4b7f7f1
@@@ -1,7 -1,7 +1,7 @@@
  %
  % This file is part of the GROMACS molecular simulation package.
  %
 -% Copyright (c) 2013,2014, by the GROMACS development team, led by
 +% Copyright (c) 2013,2014,2015, 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.
@@@ -252,19 -252,16 +252,16 @@@ respectively
  \subsection{Modified non-bonded interactions}
  \label{sec:mod_nb_int}
  In {\gromacs}, the non-bonded potentials can be
- modified by a shift function. The purpose of this is to replace the
+ modified by a shift function, also called a force-switch function,
+ since it switches the force to zero at the cut-off.
+ The purpose of this is to replace the
  truncated forces by forces that are continuous and have continuous
  derivatives at the \normindex{cut-off} radius. With such forces the
- timestep integration produces much smaller errors and there are no
- such complications as creating charges from dipoles by the truncation
- procedure. In fact, by using shifted forces there is no need for
- charge groups in the construction of neighbor lists. However, the
- shift function produces a considerable modification of the Coulomb
- potential. Unless the ``missing'' long-range potential is properly
- calculated and added (through the use of PPPM, Ewald, or PME), the
- effect of such modifications must be carefully evaluated.  The
- modification of the Lennard-Jones dispersion and repulsion is only
- minor, but it does remove the noise caused by cut-off effects.
+ time integration produces smaller errors. But note that for
+ Lennard-Jones interactions these errors are usually smaller than other errors,
+ such as integration errors at the repulsive part of the potential.
+ For Coulomb interactions we advise against using a shifted potential
+ and for use of a reaction field or a proper long-range method such as PME.
   
  There is {\em no} fundamental difference between a switch function
  (which multiplies the potential with a function) and a shift function
@@@ -273,11 -270,11 +270,11 @@@ function is a special case of the shif
  the {\em force function} $F(r)$, related to the electrostatic or
  van der Waals force acting on particle $i$ by particle $j$ as:
  \beq
- \ve{F}_i = c F(r_{ij}) \frac{\rvij}{r_{ij}}
+ \ve{F}_i = c \, F(r_{ij}) \frac{\rvij}{r_{ij}}
  \eeq
  For pure Coulomb or Lennard-Jones interactions
- $F(r)=F_\alpha(r)=r^{-(\alpha+1)}$.
- The shifted force $F_s(r)$ can generally be written as:
+ $F(r) = F_\alpha(r) = \alpha \, r^{-(\alpha+1)}$.
+ The switched force $F_s(r)$ can generally be written as:
  \beq
  \begin{array}{rcl}
  \vspace{2mm}
@@@ -288,17 -285,13 +285,13 @@@ F_s(r)~=&~0             & r_c \le 
  \end{array}
  \eeq
  When $r_1=0$ this is a traditional shift function, otherwise it acts as a 
- switch function. The corresponding shifted coulomb potential then reads:
+ switch function. The corresponding shifted potential function then reads:
  \beq
- V_s(r_{ij}) = f \Phi_s (r_{ij}) q_i q_j
- \eeq
- where $\Phi(r)$ is the potential function 
- \beq
- \Phi_s(r) =  \int^{\infty}_r~F_s(x)\, dx
+ V_s(r) =  \int^{\infty}_r~F_s(x)\, dx
  \eeq
  
- The {\gromacs} shift function should be smooth at the boundaries, therefore
- the following boundary conditions are imposed on the shift function:
+ The {\gromacs} force switch function should be smooth at the boundaries, therefore
+ the following boundary conditions are imposed on the switch function:
  \beq
  \begin{array}{rcl}
  S(r_1)          &=&0            \\
@@@ -316,9 -309,9 +309,9 @@@ boundary condition at $r_c$
  \beq
  \begin{array}{rcl}
  \vspace{2mm}
- A &~=~& -\displaystyle
+ A &~=~& -\alpha \, \displaystyle
          \frac{(\alpha+4)r_c~-~(\alpha+1)r_1} {r_c^{\alpha+2}~(r_c-r_1)^2} \\
- B &~=~& \displaystyle
+ B &~=~& \alpha \, \displaystyle
          \frac{(\alpha+3)r_c~-~(\alpha+1)r_1}{r_c^{\alpha+2}~(r_c-r_1)^3}
  \end{array}
  \eeq
@@@ -328,42 -321,20 +321,20 @@@ F_s(r) = \frac{\alpha}{r^{\alpha+1}} + 
  \eeq
  and the potential function reads:
  \beq
\Phi(r) = \frac{1}{r^\alpha} - \frac{A}{3} (r-r_1)^3 - \frac{B}{4} (r-r_1)^4 - C
V_s(r) = \frac{1}{r^\alpha} - \frac{A}{3} (r-r_1)^3 - \frac{B}{4} (r-r_1)^4 - C
  \eeq
  where 
  \beq
  C =  \frac{1}{r_c^\alpha} - \frac{A}{3} (r_c-r_1)^3 - \frac{B}{4} (r_c-r_1)^4
  \eeq
  
- When $r_1$ = 0, the modified Coulomb force function is
- \beq
-  F_s(r) = \frac{1}{r^2} - \frac{5 r^2}{r_c^4} + \frac{4 r^3}{r_c^5}
- \eeq
- which is identical to the {\em \index{parabolic force}} 
- function recommended to be used as a short-range function in 
- conjunction with a \swapindex{Poisson}{solver} 
- for the long-range part~\cite{Berendsen93a}.
- The modified Coulomb potential function is:
- \beq
- \Phi(r) = \frac{1}{r} - \frac{5}{3r_c} + \frac{5r^3}{3r_c^4} - \frac{r^4}{r_c^5}
- \eeq
- See also \figref{shift}.
- \begin{figure}
- \centerline{\includegraphics[width=10cm]{plots/shiftf}}
- \caption[The Coulomb Force, Shifted Force and Shift Function
- $S(r)$,.]{The Coulomb Force, Shifted Force and Shift Function $S(r)$,
- using r$_1$ = 2 and r$_c$ = 4.} 
- \label{fig:shift}
- \end{figure}
  \subsection{Modified short-range interactions with Ewald summation}
  When Ewald summation\index{Ewald sum} or \seeindex{particle-mesh
  Ewald}{PME}\index{Ewald, particle-mesh} is used to calculate the
  long-range interactions, the 
- short-range Coulomb potential must also be modified, similar to the
- switch function above. In this case the short range potential is given
- by:
+ short-range Coulomb potential must also be modified. Here the potential
+ is switched to (nearly) zero at the cut-off, instead of the force.
In this case the short range potential is given by:
  \beq
  V(r) = f \frac{\mbox{erfc}(\beta r_{ij})}{r_{ij}} q_i q_j,
  \eeq
@@@ -1087,12 -1058,9 +1058,12 @@@ radius. The force acts towards the cent
  \beq
    d_g(\ve{r}_i;\ve{R}_i) = |\ve{r}_i-\ve{R}_i|
  \eeq
 -{\bfseries Cylinder} ($g=2$): The particle is kept in a cylinder of given radius
 -parallel to the $z$-axis. The force from the flat-bottomed potential acts
 -towards the axis of the cylinder. The $z$-component of the force is zero.
 +{\bfseries Cylinder} ($g=6,7,8$): The particle is kept in a cylinder of given radius
 +parallel to the $x$ ($g=6$), $y$ ($g=7$), or $z$-axis ($g=8$). For backwards compatibility, setting
 +$g=2$ is mapped to $g=8$ in the code so that old {\tt .tpr} files and topologies work.  
 +The force from the flat-bottomed potential acts towards the axis of the cylinder. 
 +The component of the force parallel to the cylinder axis is zero.
 +For a cylinder aligned along the $z$-axis:
  \beq
   d_g(\ve{r}_i;\ve{R}_i) = \sqrt{ (x_i-X_i)^2 + (y_i - Y_i)^2 }
  \eeq
@@@ -1810,42 -1778,27 +1781,42 @@@ after taking the derivative, we {\em ca
  
  \subsubsection{Constraints}
  \label{subsubsec:constraints}
 -\newcommand{\clam}{C_{\lambda}}
  The constraints are formally part of the Hamiltonian, and therefore
  they give a contribution to the free energy. In {\gromacs} this can be
  calculated using the \normindex{LINCS} or the \normindex{SHAKE} algorithm.
 -If we have a number of constraint equations $g_k$:
 +If we have $k = 1 \ldots K$ constraint equations $g_k$ for LINCS, then
  \beq
 -g_k     =       \ve{r}_{k} - d_{k}
 +g_k     =       |\ve{r}_{k}| - d_{k}
  \eeq
 -where $\ve{r}_k$ is the distance vector between two particles and 
 -$d_k$ is the constraint distance between the two particles, we can write
 -this using a $\LAM$-dependent distance as
 +where $\ve{r}_k$ is the displacement vector between two particles and 
 +$d_k$ is the constraint distance between the two particles. We can express
 +the fact that the constraint distance has a $\LAM$ dependency by
  \beq
 -g_k     =       \ve{r}_{k} - \left(\LL d_{k}^A + \LAM d_k^B\right)
 +d_k     =       \LL d_{k}^A + \LAM d_k^B
  \eeq
 -the contribution $\clam$ 
 -to the Hamiltonian using Lagrange multipliers $\lambda$:
 +
 +Thus the $\LAM$-dependent constraint equation is
 +\beq
 +g_k     =       |\ve{r}_{k}| - \left(\LL d_{k}^A + \LAM d_k^B\right).
 +\eeq
 +
 +The (zero) contribution $G$ to the Hamiltonian from the constraints
 +(using Lagrange multipliers $\lambda_k$, which are logically distinct
 +from the free-energy $\LAM$) is
  \bea
 -\clam           &=&     \sum_k \lambda_k g_k    \\
 -\dvdl{\clam}    &=&     \sum_k \lambda_k \left(d_k^B-d_k^A\right)
 +G           &=&     \sum^K_k \lambda_k g_k    \\
 +\dvdl{G}    &=&     \frac{\partial G}{\partial d_k} \dvdl{d_k} \\
 +            &=&     - \sum^K_k \lambda_k \left(d_k^B-d_k^A\right)
  \eea
  
 +For SHAKE, the constraint equations are
 +\beq
 +g_k     =       \ve{r}_{k}^2 - d_{k}^2
 +\eeq
 +with $d_k$ as before, so
 +\bea
 +\dvdl{G}    &=&     -2 \sum^K_k \lambda_k \left(d_k^B-d_k^A\right)
 +\eea
  
  \subsection{Soft-core interactions\index{soft-core interactions}}
  \begin{figure}
@@@ -2027,7 -1980,7 +1998,7 @@@ used in the neighbor searching
  For both Coulomb and van der Waals interactions there are interaction
  type selectors (termed {\tt vdwtype} and {\tt coulombtype}) and two
  parameters, for a total of six non-bonded interaction parameters. See
 -\secref{mdpopt} for a complete description of these parameters.
 +the User Guide for a complete description of these parameters.
  
  The neighbor searching (NS) can be performed using a single-range, or a twin-range 
  approach. Since the former is merely a special case of the latter, we will 
@@@ -2989,7 -2942,7 +2960,7 @@@ coarse-graining~\cite{wang_jpcb10}.  A 
  % LocalWords:  fc ravdisre nstdisreout dipolar lll ccc orientational MSD const
  % LocalWords:  orire fitgrp nstorireout Drude intra Noskov et al fecalc coulrf
  % LocalWords:  polarizabilities parameterized sigeps Ek sc softcore GROMOS NBF
 -% LocalWords:  hydrogens alkane vdwtype coulombtype mdpopt rlist rcoulomb rvdw
 +% LocalWords:  hydrogens alkane vdwtype coulombtype rlist rcoulomb rvdw
  % LocalWords:  nstlist virial funcparm VdW jk jl fvsite fd vsites lcr vsitetop
  % LocalWords:  vsite lclllll lcl parameterize parameterization enercorr avcsix
  % LocalWords:  pcorr ecorr totalcoulomb dir fourierspacing ewald rtol Darden gz
index f9e8fb89c662140db8fa9f98c5b8a31d357c8676,d02c9c1116cbb946f2b564a0af92f4116b360c58..a125cf2e21d9e8098365bf218155f69ec4b30131
   * 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 <math.h>
 +#include "gmxpre.h"
  
 -/*#define HAVE_NN_LOOPS*/
 +#include "config.h"
  
 -#include "gromacs/commandline/pargs.h"
 -#include "copyrite.h"
 -#include "sysstuff.h"
 -#include "txtdump.h"
 -#include "physics.h"
 -#include "macros.h"
 -#include "gmx_fatal.h"
 -#include "index.h"
 -#include "gromacs/utility/smalloc.h"
 -#include "vec.h"
 -#include "xvgr.h"
 -#include "gstat.h"
 -#include "gromacs/utility/cstringutil.h"
 -#include "pbc.h"
 -#include "correl.h"
 -#include "gmx_ana.h"
 -#include "geminate.h"
 +#include <math.h>
  
 -#include "gromacs/fileio/futil.h"
 +#include "gromacs/commandline/pargs.h"
 +#include "gromacs/correlationfunctions/autocorr.h"
 +#include "gromacs/correlationfunctions/crosscorr.h"
 +#include "gromacs/correlationfunctions/expfit.h"
 +#include "gromacs/correlationfunctions/integrate.h"
  #include "gromacs/fileio/matio.h"
  #include "gromacs/fileio/tpxio.h"
  #include "gromacs/fileio/trxio.h"
 +#include "gromacs/fileio/xvgr.h"
 +#include "gromacs/gmxana/geminate.h"
 +#include "gromacs/gmxana/gmx_ana.h"
 +#include "gromacs/legacyheaders/copyrite.h"
 +#include "gromacs/legacyheaders/macros.h"
 +#include "gromacs/legacyheaders/txtdump.h"
 +#include "gromacs/legacyheaders/viewit.h"
 +#include "gromacs/math/units.h"
 +#include "gromacs/math/vec.h"
 +#include "gromacs/pbcutil/pbc.h"
 +#include "gromacs/topology/index.h"
 +#include "gromacs/utility/cstringutil.h"
 +#include "gromacs/utility/fatalerror.h"
 +#include "gromacs/utility/futil.h"
  #include "gromacs/utility/gmxomp.h"
 +#include "gromacs/utility/smalloc.h"
 +#include "gromacs/utility/snprintf.h"
 +
 +#include "geminate.h"
 +
 +/*#define HAVE_NN_LOOPS*/
  
  typedef short int t_E;
  typedef int t_EEst;
@@@ -1188,7 -1183,7 +1188,7 @@@ static void add_dh(t_donors *ddd, int i
  {
      int i;
  
 -    if (ISDON(datable[id]) || !datable)
 +    if (!datable || ISDON(datable[id]))
      {
          if (ddd->dptr[id] == NOTSET)   /* New donor */
          {
@@@ -1417,6 -1412,7 +1417,7 @@@ static void reset_nhbonds(t_donors *ddd
  }
  
  void pbc_correct_gem(rvec dx, matrix box, rvec hbox);
+ void pbc_in_gridbox(rvec dx, matrix box);
  
  static void build_grid(t_hbdata *hb, rvec x[], rvec xshell,
                         gmx_bool bBox, matrix box, rvec hbox,
                          {
                              copy_rvec(x[ad[i]], xtemp);
                          }
-                         pbc_correct_gem(x[ad[i]], box, hbox);
-                     }
-                     for (m = DIM-1; m >= 0; m--)
-                     {
-                         if (TRUE || !hb->bGem)
+                         pbc_in_gridbox(x[ad[i]], box);
+                         for (m = DIM-1; m >= 0; m--)
+                         {   /* determine grid index of atom */
+                             grididx[m] = x[ad[i]][m]*invdelta[m];
+                             grididx[m] = (grididx[m]+ngrid[m]) % ngrid[m];
+                         }
+                         if (hb->bGem)
                          {
-                             /* put atom in the box */
-                             while (x[ad[i]][m] < 0)
-                             {
-                                 rvec_inc(x[ad[i]], box[m]);
-                             }
-                             while (x[ad[i]][m] >= box[m][m])
-                             {
-                                 rvec_dec(x[ad[i]], box[m]);
-                             }
+                             copy_rvec(xtemp, x[ad[i]]); /* copy back */
                          }
-                         /* determine grid index of atom */
-                         grididx[m] = x[ad[i]][m]*invdelta[m];
-                         grididx[m] = (grididx[m]+ngrid[m]) % ngrid[m];
-                     }
-                     if (hb->bGem)
-                     {
-                         copy_rvec(xtemp, x[ad[i]]); /* copy back */
                      }
                      gx = grididx[XX];
                      gy = grididx[YY];
                      gz = grididx[ZZ];
@@@ -1753,6 -1738,29 +1743,29 @@@ void pbc_correct_gem(rvec dx, matrix bo
      }
  }
  
+ void pbc_in_gridbox(rvec dx, matrix box)
+ {
+     int      m;
+     gmx_bool bDone = FALSE;
+     while (!bDone)
+     {
+         bDone = TRUE;
+         for (m = DIM-1; m >= 0; m--)
+         {
+             if (dx[m] < 0)
+             {
+                 bDone = FALSE;
+                 rvec_inc(dx, box[m]);
+             }
+             if (dx[m] >= box[m][m])
+             {
+                 bDone = FALSE;
+                 rvec_dec(dx, box[m]);
+             }
+         }
+     }
+ }
  /* Added argument r2cut, changed contact and implemented
   * use of second cut-off.
   * - Erik Marklund, June 29, 2006
@@@ -2234,7 -2242,7 +2247,7 @@@ static void do_hblife(const char *fn, t
          integral += x1;
      }
      integral *= dt;
 -    gmx_ffclose(fp);
 +    xvgrclose(fp);
      printf("%s lifetime = %.2f ps\n", bContact ? "Contact" : "HB", integral);
      printf("Note that the lifetime obtained in this manner is close to useless\n");
      printf("Use the -ac option instead and check the Forward lifetime\n");
@@@ -2379,10 -2387,9 +2392,10 @@@ static real compute_weighted_rates(int 
  static void smooth_tail(int n, real t[], real c[], real sigma_c[], real start,
                          const output_env_t oenv)
  {
 -    FILE *fp;
 -    real  e_1, fitparm[4];
 -    int   i;
 +    FILE  *fp;
 +    real   e_1;
 +    double fitparm[4];
 +    int    i;
  
      e_1 = exp(-1);
      for (i = 0; (i < n); i++)
          fitparm[0] = 10;
      }
      fitparm[1] = 0.95;
 -    do_lmfit(n, c, sigma_c, 0, t, start, t[n-1], oenv, bDebugMode(), effnEXP2, fitparm, 0);
 +    do_lmfit(n, c, sigma_c, 0, t, start, t[n-1], oenv, bDebugMode(),
 +             effnEXP2, fitparm, 0);
  }
  
  void analyse_corr(int n, real t[], real ct[], real nt[], real kt[],
@@@ -2550,16 -2556,13 +2563,16 @@@ static void parallel_print(int *data, i
  
  static void normalizeACF(real *ct, real *gt, int nhb, int len)
  {
 -    real ct_fac, gt_fac;
 +    real ct_fac, gt_fac = 0;
      int  i;
  
      /* Xu and Berne use the same normalization constant */
  
      ct_fac = 1.0/ct[0];
 -    gt_fac = (nhb == 0) ? 0 : 1.0/(real)nhb;
 +    if (nhb != 0)
 +    {
 +        gt_fac = 1.0/(real)nhb;
 +    }
  
      printf("Normalization for c(t) = %g for gh(t) = %g\n", ct_fac, gt_fac);
      for (i = 0; i < len; i++)
@@@ -3274,7 -3277,7 +3287,7 @@@ static void do_hbac(const char *fn, t_h
                  fprintf(fp, "%10g  %10g  %10g  %10g  %10g\n",
                          hb->time[j]-hb->time[0], ct[j], cct[j], ght[j], kt[j]);
              }
 -            gmx_ffclose(fp);
 +            xvgrclose(fp);
  
              analyse_corr(nn, hb->time, ct, ght, kt, NULL, NULL, NULL,
                           fit_start, temp, smooth_tail_start, oenv);
@@@ -3329,31 -3332,21 +3342,31 @@@ static void init_hbframe(t_hbdata *hb, 
      /*set_hb(hb->hbmap[i][j]->h[m],nframes-hb->hbmap[i][j]->n0,HB_NO);*/
  }
  
 -static void analyse_donor_props(const char *fn, t_hbdata *hb, int nframes, real t,
 -                                const output_env_t oenv)
 +static FILE *open_donor_properties_file(const char        *fn,
 +                                        t_hbdata          *hb,
 +                                        const output_env_t oenv)
  {
 -    static FILE *fp    = NULL;
 -    const char  *leg[] = { "Nbound", "Nfree" };
 -    int          i, j, k, nbound, nb, nhtot;
 +    FILE       *fp    = NULL;
 +    const char *leg[] = { "Nbound", "Nfree" };
  
 -    if (!fn)
 +    if (!fn || !hb)
      {
 -        return;
 +        return NULL;
      }
 -    if (!fp)
 +
 +    fp = xvgropen(fn, "Donor properties", output_env_get_xvgr_tlabel(oenv), "Number", oenv);
 +    xvgr_legend(fp, asize(leg), leg, oenv);
 +
 +    return fp;
 +}
 +
 +static void analyse_donor_properties(FILE *fp, t_hbdata *hb, int nframes, real t)
 +{
 +    int i, j, k, nbound, nb, nhtot;
 +
 +    if (!fp || !hb)
      {
 -        fp = xvgropen(fn, "Donor properties", output_env_get_xvgr_tlabel(oenv), "Number", oenv);
 -        xvgr_legend(fp, asize(leg), leg, oenv);
 +        return;
      }
      nbound = 0;
      nhtot  = 0;
@@@ -3403,7 -3396,7 +3416,7 @@@ static void dump_hbmap(t_hbdata *hb
          for (i = 0; i < isize[grp]; i++)
          {
              fprintf(fp, (i%15) ? " " : "\n");
 -            fprintf(fp, " %4u", index[grp][i]+1);
 +            fprintf(fp, " %4d", index[grp][i]+1);
          }
          fprintf(fp, "\n");
          /*
                  {
                      for (j = 0; (j < hb->d.nhydro[i]); j++)
                      {
 -                        fprintf(fp, " %4u %4u", hb->d.don[i]+1,
 +                        fprintf(fp, " %4d %4d", hb->d.don[i]+1,
                                  hb->d.hydro[i][j]+1);
                      }
                      fprintf(fp, "\n");
                  if (hb->a.grp[i] == grp)
                  {
                      fprintf(fp, (i%15 && !first) ? " " : "\n");
 -                    fprintf(fp, " %4u", hb->a.acc[i]+1);
 +                    fprintf(fp, " %4d", hb->a.acc[i]+1);
                      first = FALSE;
                  }
              }
                      sprintf(as, "%s", mkatomname(atoms, aaa));
                      if (bContact)
                      {
 -                        fprintf(fp, " %6u %6u\n", ddd+1, aaa+1);
 +                        fprintf(fp, " %6d %6d\n", ddd+1, aaa+1);
                          if (fplog)
                          {
                              fprintf(fplog, "%12s  %12s\n", ds, as);
                      {
                          hhh = hb->d.hydro[i][m];
                          sprintf(hs, "%s", mkatomname(atoms, hhh));
 -                        fprintf(fp, " %6u %6u %6u\n", ddd+1, hhh+1, aaa+1);
 +                        fprintf(fp, " %6d %6d %6d\n", ddd+1, hhh+1, aaa+1);
                          if (fplog)
                          {
                              fprintf(fplog, "%12s  %12s  %12s\n", ds, hs, as);
@@@ -3556,41 -3549,40 +3569,41 @@@ int gmx_hbond(int argc, char *argv[]
  
          /*    "It is also possible to analyse specific hydrogen bonds with",
                "[TT]-sel[tt]. This index file must contain a group of atom triplets",
 -              "Donor Hydrogen Acceptor, in the following way:[PAR]",
 +              "Donor Hydrogen Acceptor, in the following way::",
 +           "",
 +           "[ selected ]",
 +           "     20    21    24",
 +           "     25    26    29",
 +           "      1     3     6",
 +           "",
 +           "Note that the triplets need not be on separate lines.",
 +           "Each atom triplet specifies a hydrogen bond to be analyzed,",
 +           "note also that no check is made for the types of atoms.[PAR]",
           */
 -        "[TT]",
 -        "[ selected ][BR]",
 -        "     20    21    24[BR]",
 -        "     25    26    29[BR]",
 -        "      1     3     6[BR]",
 -        "[tt][BR]",
 -        "Note that the triplets need not be on separate lines.",
 -        "Each atom triplet specifies a hydrogen bond to be analyzed,",
 -        "note also that no check is made for the types of atoms.[PAR]",
 -
 -        "[BB]Output:[bb][BR]",
 -        "[TT]-num[tt]:  number of hydrogen bonds as a function of time.[BR]",
 -        "[TT]-ac[tt]:   average over all autocorrelations of the existence",
 -        "functions (either 0 or 1) of all hydrogen bonds.[BR]",
 -        "[TT]-dist[tt]: distance distribution of all hydrogen bonds.[BR]",
 -        "[TT]-ang[tt]:  angle distribution of all hydrogen bonds.[BR]",
 -        "[TT]-hx[tt]:   the number of n-n+i hydrogen bonds as a function of time",
 -        "where n and n+i stand for residue numbers and i ranges from 0 to 6.",
 -        "This includes the n-n+3, n-n+4 and n-n+5 hydrogen bonds associated",
 -        "with helices in proteins.[BR]",
 -        "[TT]-hbn[tt]:  all selected groups, donors, hydrogens and acceptors",
 -        "for selected groups, all hydrogen bonded atoms from all groups and",
 -        "all solvent atoms involved in insertion.[BR]",
 -        "[TT]-hbm[tt]:  existence matrix for all hydrogen bonds over all",
 -        "frames, this also contains information on solvent insertion",
 -        "into hydrogen bonds. Ordering is identical to that in [TT]-hbn[tt]",
 -        "index file.[BR]",
 -        "[TT]-dan[tt]: write out the number of donors and acceptors analyzed for",
 -        "each timeframe. This is especially useful when using [TT]-shell[tt].[BR]",
 -        "[TT]-nhbdist[tt]: compute the number of HBonds per hydrogen in order to",
 -        "compare results to Raman Spectroscopy.",
 -        "[PAR]",
 +
 +        "[BB]Output:[bb]",
 +        "",
 +        " * [TT]-num[tt]:  number of hydrogen bonds as a function of time.",
 +        " * [TT]-ac[tt]:   average over all autocorrelations of the existence",
 +        "   functions (either 0 or 1) of all hydrogen bonds.",
 +        " * [TT]-dist[tt]: distance distribution of all hydrogen bonds.",
 +        " * [TT]-ang[tt]:  angle distribution of all hydrogen bonds.",
 +        " * [TT]-hx[tt]:   the number of n-n+i hydrogen bonds as a function of time",
 +        "   where n and n+i stand for residue numbers and i ranges from 0 to 6.",
 +        "   This includes the n-n+3, n-n+4 and n-n+5 hydrogen bonds associated",
 +        "   with helices in proteins.",
 +        " * [TT]-hbn[tt]:  all selected groups, donors, hydrogens and acceptors",
 +        "   for selected groups, all hydrogen bonded atoms from all groups and",
 +        "   all solvent atoms involved in insertion.",
 +        " * [TT]-hbm[tt]:  existence matrix for all hydrogen bonds over all",
 +        "   frames, this also contains information on solvent insertion",
 +        "   into hydrogen bonds. Ordering is identical to that in [TT]-hbn[tt]",
 +        "   index file.",
 +        " * [TT]-dan[tt]: write out the number of donors and acceptors analyzed for",
 +        "   each timeframe. This is especially useful when using [TT]-shell[tt].",
 +        " * [TT]-nhbdist[tt]: compute the number of HBonds per hydrogen in order to",
 +        "   compare results to Raman Spectroscopy.",
 +        "",
          "Note: options [TT]-ac[tt], [TT]-life[tt], [TT]-hbn[tt] and [TT]-hbm[tt]",
          "require an amount of memory proportional to the total numbers of donors",
          "times the total number of acceptors in the selected group(s)."
          { "-smooth", FALSE, etREAL, {&smooth_tail_start},
            "If >= 0, the tail of the ACF will be smoothed by fitting it to an exponential function: y = A exp(-x/[GRK]tau[grk])" },
          { "-dump",  FALSE, etINT, {&nDump},
 -          "Dump the first N hydrogen bond ACFs in a single [TT].xvg[tt] file for debugging" },
 +          "Dump the first N hydrogen bond ACFs in a single [REF].xvg[ref] file for debugging" },
          { "-max_hb", FALSE, etREAL, {&maxnhb},
            "Theoretical maximum number of hydrogen bonds used for normalizing HB autocorrelation function. Can be useful in case the program estimates it wrongly" },
          { "-merge", FALSE, etBOOL, {&bMerge},
      };
      t_filenm    fnm[] = {
          { efTRX, "-f",   NULL,     ffREAD  },
 -        { efTPX, NULL,   NULL,     ffREAD  },
 +        { efTPR, NULL,   NULL,     ffREAD  },
          { efNDX, NULL,   NULL,     ffOPTRD },
          /*    { efNDX, "-sel", "select", ffOPTRD },*/
          { efXVG, "-num", "hbnum",  ffWRITE },
      int                   grp, nabin, nrbin, bin, resdist, ihb;
      char                **leg;
      t_hbdata             *hb, *hbptr;
 -    FILE                 *fp, *fpins = NULL, *fpnhb = NULL;
 +    FILE                 *fp, *fpins = NULL, *fpnhb = NULL, *donor_properties = NULL;
      t_gridcell         ***grid;
      t_ncell              *icell, *jcell, *kcell;
      ivec                  ngrid;
      npargs = asize(pa);
      ppa    = add_acf_pargs(&npargs, pa);
  
 -    if (!parse_common_args(&argc, argv, PCA_CAN_TIME | PCA_TIME_UNIT | PCA_BE_NICE, NFILE, fnm, npargs,
 +    if (!parse_common_args(&argc, argv, PCA_CAN_TIME | PCA_TIME_UNIT, NFILE, fnm, npargs,
                             ppa, asize(desc), desc, asize(bugs), bugs, &oenv))
      {
          return 0;
      hb = mk_hbdata(bHBmap, opt2bSet("-dan", NFILE, fnm), bMerge || bContact, bGem, gemmode);
  
      /* get topology */
 -    read_tpx_top(ftp2fn(efTPX, NFILE, fnm), &ir, box, &natoms, NULL, NULL, NULL, &top);
 +    read_tpx_top(ftp2fn(efTPR, NFILE, fnm), &ir, box, &natoms, NULL, NULL, NULL, &top);
  
      snew(grpnames, grNR);
      snew(index, grNR);
      /*if (bSelected)
         snew(donors[gr0D], dons[gr0D].nrd);*/
  
 +    donor_properties = open_donor_properties_file(opt2fn_null("-don", NFILE, fnm), hb, oenv);
 +
      if (bHBmap)
      {
          printf("Making hbmap structure...");
  #pragma omp barrier
  #pragma omp single
                  {
 -                    if (hb != NULL)
 -                    {
 -                        analyse_donor_props(opt2fn_null("-don", NFILE, fnm), hb, k, t, oenv);
 -                    }
 +                    analyse_donor_properties(donor_properties, hb, k, t);
                  }
  
  #pragma omp single
      free_grid(ngrid, &grid);
  
      close_trj(status);
 +
 +    if (donor_properties)
 +    {
 +        xvgrclose(donor_properties);
 +    }
 +
      if (fpnhb)
      {
 -        gmx_ffclose(fpnhb);
 +        xvgrclose(fpnhb);
      }
  
      /* Compute maximum possible number of different hbonds */
          aver_nhb  += hb->nhb[i];
          aver_dist += hb->ndist[i];
      }
 -    gmx_ffclose(fp);
 +    xvgrclose(fp);
      aver_nhb  /= nframes;
      aver_dist /= nframes;
      /* Print HB distance distribution */
          {
              fprintf(fp, "%10g %10g\n", (i+0.5)*rbin, rdist[i]/(rbin*(real)sum));
          }
 -        gmx_ffclose(fp);
 +        xvgrclose(fp);
      }
  
      /* Print HB angle distribution */
          {
              fprintf(fp, "%10g %10g\n", (i+0.5)*abin, adist[i]/(abin*(real)sum));
          }
 -        gmx_ffclose(fp);
 +        xvgrclose(fp);
      }
  
      /* Print HB in alpha-helix */
              }
              fprintf(fp, "\n");
          }
 -        gmx_ffclose(fp);
 +        xvgrclose(fp);
      }
      if (!bNN)
      {
                      gmx_fatal(FARGS, "Could not initiate t_gemParams params.");
                  }
              }
 -            gemstring = strdup(gemType[hb->per->gemtype]);
 +            gemstring = gmx_strdup(gemType[hb->per->gemtype]);
              do_hbac(opt2fn("-ac", NFILE, fnm), hb, nDump,
                      bMerge, bContact, fit_start, temp, r2cut > 0, smooth_tail_start, oenv,
                      gemstring, nThreads, NN, bBallistic, bGemFit);
          {
              t_matrix mat;
              int      id, ia, hh, x, y;
 +            mat.flags = mat.y0 = 0;
  
              if ((nframes > 0) && (hb->nrhb > 0))
              {
              if (USE_THIS_GROUP(j) )
              {
                  sprintf(buf, "Donors %s", grpnames[j]);
 -                legnames[i++] = strdup(buf);
 +                legnames[i++] = gmx_strdup(buf);
                  sprintf(buf, "Acceptors %s", grpnames[j]);
 -                legnames[i++] = strdup(buf);
 +                legnames[i++] = gmx_strdup(buf);
              }
          }
          if (i != nleg)
              }
              fprintf(fp, "\n");
          }
 -        gmx_ffclose(fp);
 +        xvgrclose(fp);
      }
  
      return 0;
index 20e3f3d8f3bcd601c02153392603199947c8e48b,e21493372b6822593fd07530f702cd00e4b05ba1..0732b9dc891d02134ff1442bfbebce86ba3f5117
   * 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"
  
  /* This file is completely threadsafe - please keep it that way! */
  
 +#include "gromacs/legacyheaders/txtdump.h"
 +
  #include <stdio.h>
 -#include "typedefs.h"
 -#include "types/commrec.h"
 -#include "names.h"
 -#include "txtdump.h"
 -#include "vec.h"
 -#include "macros.h"
 -
 -#include "gmx_fatal.h"
 +#include <stdlib.h>
 +
 +#include "gromacs/legacyheaders/macros.h"
 +#include "gromacs/legacyheaders/names.h"
 +#include "gromacs/legacyheaders/typedefs.h"
 +#include "gromacs/legacyheaders/types/commrec.h"
 +#include "gromacs/math/vec.h"
 +#include "gromacs/utility/fatalerror.h"
  #include "gromacs/utility/smalloc.h"
  
  int pr_indent(FILE *fp, int n)
@@@ -634,17 -634,8 +634,17 @@@ static void pr_pull_coord(FILE *fp, in
      fprintf(fp, "pull-coord %d:\n", c);
      PI("group[0]", pcrd->group[0]);
      PI("group[1]", pcrd->group[1]);
 +    if (pcrd->eGeom == epullgDIRRELATIVE)
 +    {
 +        PI("group[2]", pcrd->group[2]);
 +        PI("group[3]", pcrd->group[3]);
 +    }
 +    PS("type", EPULLTYPE(pcrd->eType));
 +    PS("geometry", EPULLGEOM(pcrd->eGeom));
 +    pr_ivec(fp, indent, "dim", pcrd->dim, DIM, TRUE);
      pr_rvec(fp, indent, "origin", pcrd->origin, DIM, TRUE);
      pr_rvec(fp, indent, "vec", pcrd->vec, DIM, TRUE);
 +    PS("start", EBOOL(pcrd->bStart));
      PR("init", pcrd->init);
      PR("rate", pcrd->rate);
      PR("k", pcrd->k);
@@@ -764,12 -755,12 +764,12 @@@ static void pr_pull(FILE *fp, int inden
  {
      int g;
  
 -    PS("pull-geometry", EPULLGEOM(pull->eGeom));
 -    pr_ivec(fp, indent, "pull-dim", pull->dim, DIM, TRUE);
 -    PR("pull-r1", pull->cyl_r1);
 -    PR("pull-r0", pull->cyl_r0);
 +    PR("pull-cylinder-r", pull->cylinder_r);
      PR("pull-constr-tol", pull->constr_tol);
 -    PS("pull-print-reference", EBOOL(pull->bPrintRef));
 +    PS("pull-print-COM1", EBOOL(pull->bPrintCOM1));
 +    PS("pull-print-COM2", EBOOL(pull->bPrintCOM2));
 +    PS("pull-print-ref-value", EBOOL(pull->bPrintRefValue));
 +    PS("pull-print-components", EBOOL(pull->bPrintComp));
      PI("pull-nstxout", pull->nstxout);
      PI("pull-nstfout", pull->nstfout);
      PI("pull-ngroups", pull->ngroup);
@@@ -973,7 -964,7 +973,7 @@@ void pr_inputrec(FILE *fp, int indent, 
          PR("gb-obc-beta", ir->gb_obc_beta);
          PR("gb-obc-gamma", ir->gb_obc_gamma);
          PR("gb-dielectric-offset", ir->gb_dielectric_offset);
-         PS("sa-algorithm", ESAALGORITHM(ir->gb_algorithm));
+         PS("sa-algorithm", ESAALGORITHM(ir->sa_algorithm));
          PR("sa-surface-tension", ir->sa_surface_tension);
  
          /* Options for weak coupling algorithms */
          PR("wall-ewald-zfac", ir->wall_ewald_zfac);
  
          /* COM PULLING */
 -        PS("pull", EPULLTYPE(ir->ePull));
 -        if (ir->ePull != epullNO)
 +        PS("pull", EBOOL(ir->bPull));
 +        if (ir->bPull)
          {
              pr_pull(fp, indent, ir->pull);
          }
@@@ -1420,7 -1411,7 +1420,7 @@@ void pr_ilist(FILE *fp, int indent, con
                  j++;
                  for (k = 0; k < interaction_function[ftype].nratoms; k++)
                  {
 -                    (void) fprintf(fp, " %u", *(iatoms++));
 +                    (void) fprintf(fp, " %d", *(iatoms++));
                  }
                  (void) fprintf(fp, "\n");
                  i += 1+interaction_function[ftype].nratoms;
@@@ -1563,13 -1554,13 +1563,13 @@@ static void low_pr_blocka(FILE *fp, in
          for (i = 0; i <= block->nr; i++)
          {
              (void) pr_indent(fp, indent+INDENT);
 -            (void) fprintf(fp, "%s->index[%d]=%u\n",
 +            (void) fprintf(fp, "%s->index[%d]=%d\n",
                             title, bShowNumbers ? i : -1, block->index[i]);
          }
          for (i = 0; i < block->nra; i++)
          {
              (void) pr_indent(fp, indent+INDENT);
 -            (void) fprintf(fp, "%s->a[%d]=%u\n",
 +            (void) fprintf(fp, "%s->a[%d]=%d\n",
                             title, bShowNumbers ? i : -1, block->a[i]);
          }
      }
@@@ -1650,7 -1641,7 +1650,7 @@@ void pr_blocka(FILE *fp, int indent, co
                          (void) fprintf(fp, "\n");
                          size = pr_indent(fp, indent+INDENT);
                      }
 -                    size += fprintf(fp, "%u", block->a[j]);
 +                    size += fprintf(fp, "%d", block->a[j]);
                  }
                  (void) fprintf(fp, "}\n");
                  start = end;
index ff567c8ea23070a10f1a68c98e1615f43ea6bab5,e18ac4974d2d9b8190c7d1e87f4c3775cc9ef448..4cbcc05525a137e9b96b058295075b1861246ff2
@@@ -3,7 -3,7 +3,7 @@@
   *
   * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
   * Copyright (c) 2001-2004, The GROMACS development team.
-  * Copyright (c) 2012,2014, by the GROMACS development team, led by
+  * Copyright (c) 2012,2014,2015, 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.
   * 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 "toputil.h"
  
  #include <assert.h>
  #include <math.h>
  #include <string.h>
  
 +#include "gromacs/gmxpreprocess/gpp_atomtype.h"
 +#include "gromacs/gmxpreprocess/topdirs.h"
 +#include "gromacs/legacyheaders/macros.h"
 +#include "gromacs/topology/block.h"
 +#include "gromacs/topology/symtab.h"
 +#include "gromacs/utility/fatalerror.h"
  #include "gromacs/utility/smalloc.h"
 -#include "sysstuff.h"
 -#include "macros.h"
 -#include "topdirs.h"
 -#include "toputil.h"
 -#include "symtab.h"
 -#include "gmx_fatal.h"
 -#include "gpp_atomtype.h"
  
  /* UTILITIES */
  
@@@ -62,7 -63,7 +62,7 @@@ void set_p_string(t_param *p, const cha
          }
          else
          {
-             gmx_fatal(FARGS, "Increase MAXSLEN in include/grompp-impl.h to at least %d,"
+             gmx_fatal(FARGS, "Increase MAXSLEN in the grompp code to at least %d,"
                        " or shorten your definition of bonds like %s to at most %d",
                        strlen(s)+1, s, MAXSLEN-1);
          }
index 311ead52fe88fa245d78ba1eaf32d7fb601c658e,2025ec9193c33f88830be94125ec749c27689957..d0169dcdc28d4af97d65db9e4a2e5d454520ac33
   * 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 <assert.h>
  
 -#include "typedefs.h"
 -#include "types/commrec.h"
 -#include "gromacs/utility/smalloc.h"
 -#include "update.h"
 -#include "vec.h"
 -#include "macros.h"
 -#include "physics.h"
 -#include "names.h"
 -#include "gmx_fatal.h"
 -#include "txtdump.h"
 -#include "nrnb.h"
 +#include <algorithm>
 +
 +#include "gromacs/legacyheaders/gmx_omp_nthreads.h"
 +#include "gromacs/legacyheaders/macros.h"
 +#include "gromacs/legacyheaders/mdrun.h"
 +#include "gromacs/legacyheaders/names.h"
 +#include "gromacs/legacyheaders/nrnb.h"
 +#include "gromacs/legacyheaders/txtdump.h"
 +#include "gromacs/legacyheaders/typedefs.h"
 +#include "gromacs/legacyheaders/update.h"
 +#include "gromacs/legacyheaders/types/commrec.h"
 +#include "gromacs/math/units.h"
 +#include "gromacs/math/vec.h"
  #include "gromacs/random/random.h"
 -#include "update.h"
 -#include "mdrun.h"
 +#include "gromacs/utility/fatalerror.h"
 +#include "gromacs/utility/smalloc.h"
  
  #define NTROTTERPARTS 3
  
@@@ -95,7 -94,7 +95,7 @@@ static void NHC_trotter(t_grpopts *opts
  {
      /* general routine for both barostat and thermostat nose hoover chains */
  
 -    int           i, j, mi, mj, jmax;
 +    int           i, j, mi, mj;
      double        Ekin, Efac, reft, kT, nd;
      double        dt;
      t_grp_tcstat *tcstat;
          {
              iQinv = &(MassQ->QPinv[i*nh]);
              nd    = 1.0; /* THIS WILL CHANGE IF NOT ISOTROPIC */
 -            reft  = max(0.0, opts->ref_t[0]);
 +            reft  = std::max<real>(0, opts->ref_t[0]);
              Ekin  = sqr(*veta)/MassQ->Winv;
          }
          else
              iQinv  = &(MassQ->Qinv[i*nh]);
              tcstat = &ekind->tcstat[i];
              nd     = opts->nrdf[i];
 -            reft   = max(0.0, opts->ref_t[i]);
 +            reft   = std::max<real>(0, opts->ref_t[i]);
              if (bEkinAveVel)
              {
                  Ekin = 2*trace(tcstat->ekinf)*tcstat->ekinscalef_nhc;
@@@ -230,9 -229,9 +230,9 @@@ static void boxv_trotter(t_inputrec *ir
  
      real   pscal;
      double alpha;
 -    int    i, j, d, n, nwall;
 -    real   T, GW, vol;
 -    tensor Winvm, ekinmod, localpres;
 +    int    nwall;
 +    real   GW, vol;
 +    tensor ekinmod, localpres;
  
      /* The heat bath is coupled to a separate barostat, the last temperature group.  In the
         2006 Tuckerman et al paper., the order is iL_{T_baro} iL {T_part}
@@@ -376,8 -375,8 +376,8 @@@ void parrinellorahman_pcoupl(FILE *fplo
           * The pressure and compressibility always occur as a product,
           * therefore the pressure unit drops out.
           */
 -        maxl = max(box[XX][XX], box[YY][YY]);
 -        maxl = max(maxl, box[ZZ][ZZ]);
 +        maxl = std::max(box[XX][XX], box[YY][YY]);
 +        maxl = std::max(maxl, box[ZZ][ZZ]);
          for (d = 0; d < DIM; d++)
          {
              for (n = 0; n < DIM; n++)
@@@ -534,7 -533,7 +534,7 @@@ void berendsen_pcoupl(FILE *fplog, gmx_
  {
      int     d, n;
      real    scalar_pressure, xy_pressure, p_corr_z;
 -    char   *ptr, buf[STRLEN];
 +    char    buf[STRLEN];
  
      /*
       *  Calculate the scaling matrix mu
@@@ -647,25 -646,12 +647,25 @@@ void berendsen_pscale(t_inputrec *ir, m
                        t_nrnb *nrnb)
  {
      ivec   *nFreeze = ir->opts.nFreeze;
 -    int     n, d, g = 0;
 +    int     n, d;
 +    int     nthreads gmx_unused;
 +
 +#ifndef __clang_analyzer__
 +    // cppcheck-suppress unreadVariable
 +    nthreads = gmx_omp_nthreads_get(emntUpdate);
 +#endif
  
      /* Scale the positions */
 +#pragma omp parallel for num_threads(nthreads) schedule(static)
      for (n = start; n < start+nr_atoms; n++)
      {
 -        if (cFREEZE)
 +        int g;
 +
 +        if (cFREEZE == NULL)
 +        {
 +            g = 0;
 +        }
 +        else
          {
              g = cFREEZE[n];
          }
@@@ -720,9 -706,9 +720,9 @@@ void berendsen_tcoupl(t_inputrec *ir, g
  
          if ((opts->tau_t[i] > 0) && (T > 0.0))
          {
 -            reft                    = max(0.0, opts->ref_t[i]);
 +            reft                    = std::max<real>(0, opts->ref_t[i]);
              lll                     = sqrt(1.0 + (dt/opts->tau_t[i])*(reft/T-1.0));
 -            ekind->tcstat[i].lambda = max(min(lll, 1.25), 0.8);
 +            ekind->tcstat[i].lambda = std::max<real>(std::min<real>(lll, 1.25), 0.8);
          }
          else
          {
@@@ -757,12 -743,14 +757,14 @@@ void andersen_tcoupl(t_inputrec *ir, gm
          }
          if (randomize[gc])
          {
-             if (ir->etc == etcANDERSEN)
+             if (ir->etc == etcANDERSENMASSIVE)
              {
+                 /* Randomize particle always */
                  bRandomize = TRUE;
              }
              else
              {
+                 /* Randomize particle probabilistically */
                  double uniform[2];
  
                  gmx_rng_cycle_2uniform(step*2, ng, ir->andersen_seed, RND_SEED_ANDERSEN, uniform);
@@@ -795,7 -783,7 +797,7 @@@ void nosehoover_tcoupl(t_grpopts *opts
  
      for (i = 0; (i < opts->ngtc); i++)
      {
 -        reft     = max(0.0, opts->ref_t[i]);
 +        reft     = std::max<real>(0, opts->ref_t[i]);
          oldvxi   = vxi[i];
          vxi[i]  += dt*MassQ->Qinv[i]*(ekind->tcstat[i].Th - reft);
          xi[i]   += dt*(oldvxi + vxi[i])*0.5;
@@@ -834,14 -822,16 +836,14 @@@ void trotter_update(t_inputrec *ir, gmx
                      t_extmass *MassQ, int **trotter_seqlist, int trotter_seqno)
  {
  
 -    int             n, i, j, d, ntgrp, ngtc, gc = 0;
 +    int             n, i, d, ngtc, gc = 0;
      t_grp_tcstat   *tcstat;
      t_grpopts      *opts;
      gmx_int64_t     step_eff;
 -    real            ecorr, pcorr, dvdlcorr;
 -    real            bmass, qmass, reft, kT, dt, nd;
 -    tensor          dumpres, dumvir;
 +    real            dt;
      double         *scalefac, dtc;
      int            *trotter_seq;
 -    rvec            sumv = {0, 0, 0}, consk;
 +    rvec            sumv = {0, 0, 0};
      gmx_bool        bCouple;
  
      if (trotter_seqno <= ettTSEQ2)
  
  extern void init_npt_masses(t_inputrec *ir, t_state *state, t_extmass *MassQ, gmx_bool bInit)
  {
 -    int           n, i, j, d, ntgrp, ngtc, nnhpres, nh, gc = 0;
 -    t_grp_tcstat *tcstat;
 +    int           n, i, j, d, ngtc, nh;
      t_grpopts    *opts;
 -    real          ecorr, pcorr, dvdlcorr;
 -    real          bmass, qmass, reft, kT, dt, ndj, nd;
 -    tensor        dumpres, dumvir;
 +    real          reft, kT, ndj, nd;
  
      opts    = &(ir->opts); /* just for ease of referencing */
      ngtc    = ir->opts.ngtc;
 -    nnhpres = state->nnhpres;
      nh      = state->nhchainlength;
  
      if (ir->eI == eiMD)
          {
              if ((opts->tau_t[i] > 0) && (opts->ref_t[i] > 0))
              {
 -                reft = max(0.0, opts->ref_t[i]);
 +                reft = std::max<real>(0, opts->ref_t[i]);
                  nd   = opts->nrdf[i];
                  kT   = BOLTZ*reft;
                  for (j = 0; j < nh; j++)
              }
              else
              {
 -                reft = 0.0;
                  for (j = 0; j < nh; j++)
                  {
                      MassQ->Qinv[i*nh+j] = 0.0;
  
  int **init_npt_vars(t_inputrec *ir, t_state *state, t_extmass *MassQ, gmx_bool bTrotter)
  {
 -    int           n, i, j, d, ntgrp, ngtc, nnhpres, nh, gc = 0;
 -    t_grp_tcstat *tcstat;
 +    int           i, j, nnhpres, nh;
      t_grpopts    *opts;
 -    real          ecorr, pcorr, dvdlcorr;
 -    real          bmass, qmass, reft, kT, dt, ndj, nd;
 -    tensor        dumpres, dumvir;
 +    real          bmass, qmass, reft, kT;
      int         **trotter_seq;
  
      opts    = &(ir->opts); /* just for ease of referencing */
 -    ngtc    = state->ngtc;
      nnhpres = state->nnhpres;
      nh      = state->nhchainlength;
  
      /* barostat temperature */
      if ((ir->tau_p > 0) && (opts->ref_t[0] > 0))
      {
 -        reft = max(0.0, opts->ref_t[0]);
 +        reft = std::max<real>(0, opts->ref_t[0]);
          kT   = BOLTZ*reft;
          for (i = 0; i < nnhpres; i++)
          {
  
  real NPT_energy(t_inputrec *ir, t_state *state, t_extmass *MassQ)
  {
 -    int     i, j, nd, ndj, bmass, qmass, ngtcall;
 -    real    ener_npt, reft, eta, kT, tau;
 +    int     i, j;
 +    real    nd, ndj;
 +    real    ener_npt, reft, kT;
      double *ivxi, *ixi;
      double *iQinv;
 -    real    vol, dbaro, W, Q;
 +    real    vol;
      int     nh = state->nhchainlength;
  
      ener_npt = 0;
              ivxi  = &state->nhpres_vxi[i*nh];
              ixi   = &state->nhpres_xi[i*nh];
              iQinv = &(MassQ->QPinv[i*nh]);
 -            reft  = max(ir->opts.ref_t[0], 0); /* using 'System' temperature */
 +            reft  = std::max<real>(ir->opts.ref_t[0], 0.0); /* using 'System' temperature */
              kT    = BOLTZ * reft;
  
              for (j = 0; j < nh; j++)
              iQinv = &(MassQ->Qinv[i*nh]);
  
              nd   = ir->opts.nrdf[i];
 -            reft = max(ir->opts.ref_t[i], 0);
 +            reft = std::max<real>(ir->opts.ref_t[i], 0);
              kT   = BOLTZ * reft;
  
 -            if (nd > 0)
 +            if (nd > 0.0)
              {
                  if (IR_NVT_TROTTER(ir))
                  {
                              }
                              else
                              {
 -                                ndj = 1;
 +                                ndj = 1.0;
                              }
                              ener_npt += ndj*ixi[j]*kT;
                          }
@@@ -1639,7 -1637,7 +1641,7 @@@ void update_annealing_target_temp(t_grp
              case  eannPERIODIC:
                  /* calculate time modulo the period */
                  pert  = opts->anneal_time[i][npoints-1];
 -                n     = t / pert;
 +                n     = static_cast<int>(t / pert);
                  thist = t - n*pert; /* modulo time */
                  /* Make sure rounding didn't get us outside the interval */
                  if (fabs(thist-pert) < GMX_REAL_EPS*100)